#!/bin/bash

# Run Playwright tests with video recording
# Usage: ./scripts/test-with-video.sh [test-file] [headed]
# 
# Examples:
#   ./scripts/test-with-video.sh tests/auth/login.spec.js
#   ./scripts/test-with-video.sh tests/auth/login.spec.js headed

TEST_FILE="${1:-tests/}"
HEADED_FLAG=""

if [ "$2" = "headed" ]; then
  HEADED_FLAG="--headed"
fi

echo "🎥 Running Playwright tests with video recording..."
echo "   Test: $TEST_FILE"
echo "   Mode: $([ -n "$HEADED_FLAG" ] && echo "Headed (visible)" || echo "Headless")"
echo ""

# Run tests (video is configured in playwright.config.js)
npx playwright test "$TEST_FILE" --project=chromium $HEADED_FLAG

echo ""
echo "✅ Tests complete!"
echo ""
echo "📂 Videos saved in: test-results/"
echo ""

# List videos if any were created
if ls test-results/*/video.webm 2>/dev/null 1>&2; then
  echo "🎬 Videos created:"
  ls -lh test-results/*/video.webm
  echo ""
  echo "To view videos:"
  echo "  1. Open Finder: open test-results/"
  echo "  2. Or play directly:"
  for video in test-results/*/video.webm; do
    echo "     open \"$video\""
  done
else
  echo "ℹ️  No videos found"
  echo ""
  echo "Video is configured in playwright.config.js:"
  echo "  - video: 'on' (always record)"
  echo "  - video: 'retain-on-failure' (only failed tests)"
fi

