#!/usr/bin/env bash
set -euo pipefail

# Helper script to start the Playwright Chrome container via Docker
# Usage: ./bin/e2e-start.sh
#
# Starts a browserless/chrome container that Playwright connects to remotely.
# The container runs Chrome with DevTools Protocol on port 9222.

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"

echo "Starting Chrome container for Playwright e2e tests..."
echo "Using docker-compose.chrome.yml"

cd "$PROJECT_DIR"

# Check if colima is needed (no Docker Desktop)
if ! docker info >/dev/null 2>&1; then
  echo "Docker daemon not accessible. Have you started colima or Docker Desktop?"
  echo "  colima start"
  exit 1
fi

docker compose -f docker-compose.chrome.yml up -d

echo ""
echo "Chrome container started! Check status:"
echo "  docker compose -f docker-compose.chrome.yml ps"
echo ""
echo "Run tests:"
echo "  make playwright"