name: 'Install OS Dependencies'
description: 'Installs OS-specific dependencies for E2E tests'

inputs:
  os:
    description: 'Operating system (Linux, macOS, Windows)'
    required: true

runs:
  using: "composite"
  steps:
    - name: Install Linux Dependencies
      if: inputs.os == 'Linux'
      shell: bash
      run: |
        # Add Wine repository key
        wget -qO - https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/xUbuntu_22.04/Release.key | sudo apt-key add -

        # Install yq binary
        wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 && chmod a+x /usr/local/bin/yq

        # Update package lists
        sudo apt-get update || true

        # Install required packages
        sudo apt-get install -y \
          build-essential \
          clang \
          libdbus-1-dev \
          libgtk-3-dev \
          libnotify-dev \
          libasound2-dev \
          libcap-dev \
          libcups2-dev \
          libxtst-dev \
          libxss1 \
          libnss3-dev \
          curl \
          gperf \
          bison \
          python3-dbusmock \
          openjdk-8-jre \
          ca-certificates \
          libpng++-dev \
          gcc-12-aarch64-linux-gnu \
          g++-12-aarch64-linux-gnu \
          jq \
          icnsutils \
          graphicsmagick \
          tzdata \
          xsel \
          xvfb \
          x11-utils \
          libgtk-3-0 \
          libnss3 \
          libasound2t64 \
          dbus \
          dbus-x11 \
          libxtst6

    - name: Install macOS Dependencies
      if: inputs.os == 'macOS'
      shell: bash
      run: |
        brew install nss
        jq '.mac.target=["zip"]' electron-builder.json | \
        jq '.mac.gatekeeperAssess=false' > /tmp/electron-builder.json && \
        cp /tmp/electron-builder.json .

    - name: Install Windows Dependencies
      if: inputs.os == 'Windows'
      shell: bash
      run: |
        choco install yq --version 4.15.1 -y
        choco install vcredist-all -y
        npm i -g node-gyp
        ELECTRON_VERSION=$(jq -r .devDependencies.electron package.json)
        node-gyp install
        node-gyp install --devdir="C:\Users\runneradmin\.electron-gyp" --target=$ELECTRON_VERSION --dist-url="https://electronjs.org/headers"
        node-gyp install --devdir="C:\Users\runneradmin\.electron-gyp" --target=$ELECTRON_VERSION --dist-url="https://electronjs.org/headers" --arch arm64
        npm install mochawesome-report-generator
