name: 'Screenshot'
description: 'Capture a full-page screenshot with Agent Media Tools'
inputs:
  url:
    description: 'URL to screenshot'
    required: true
  output:
    description: 'Output filename'
    required: false
    default: 'screenshot.png'
  api-key:
    description: 'Agent Media Tools API key'
    required: true
  width:
    description: 'Viewport width'
    required: false
    default: '1280'
runs:
  using: 'composite'
  steps:
    - env:
        AMT_API_KEY: ${{ inputs.api-key }}
        INPUT_URL: ${{ inputs.url }}
        OUTPUT_FILE: ${{ inputs.output }}
        VIEWPORT_WIDTH: ${{ inputs.width }}
      run: |
        [[ "$VIEWPORT_WIDTH" =~ ^[0-9]+$ ]] || { echo "width must be numeric" >&2; exit 2; }
        payload=$(node -e 'process.stdout.write(JSON.stringify({url:process.env.INPUT_URL,width:Number(process.env.VIEWPORT_WIDTH),full_page:true}))')
        curl --fail-with-body --show-error --silent --retry 2 -X POST "https://agentmediatools.com/api/screenshot" \
          -H "Authorization: Bearer $AMT_API_KEY" \
          -H "Content-Type: application/json" \
          --data "$payload" \
          -o "$OUTPUT_FILE"
        echo "✅ Screenshot saved to $OUTPUT_FILE"
      shell: bash
