services:
  frontend-test:
    image: node:20-bookworm
    working_dir: /app
    volumes:
      - .:/app
      - app-test-node-modules:/app/node_modules
    command: sh -lc "npm ci && npm run test:run"
    profiles:
      - test

  frontend-dev:
    container_name: cc-app-dev
    image: cc-app-dev:latest
    build:
      context: .
      dockerfile: Dockerfile
      args:
        # app-dev is served by nginx on the app host; browser API calls must stay
        # same-origin and pass through Dockerfile's /__ccapi proxy. The proxy
        # strips that prefix before forwarding, preserving mixed backend routes
        # such as /api/exam, /me/bootstrap, and /database/timetable.
        # Supabase is likewise routed same-origin via Dockerfile's /__supabase
        # proxy -> dev Supabase .94 (no CORS, browser-network-agnostic). The
        # leading-slash URL is resolved against window.location.origin in
        # supabaseClient.ts. Provide the matching .94 anon key as a build arg
        # (VITE_SUPABASE_ANON_KEY) so it pairs with the .94 backend.
        # .env.dev still points at the LAN API/Supabase for local Vite/dev tooling.
        VITE_API_BASE: /__ccapi
        VITE_API_URL: /__ccapi
        VITE_SUPABASE_URL: /__supabase
        VITE_APP_NAME: ${VITE_APP_NAME:-Classroom Copilot}
        VITE_APP_HMR_URL: ${VITE_APP_HMR_URL:-}
        VITE_DEV: ${VITE_DEV:-false}
        VITE_FRONTEND_SITE_URL: ${VITE_FRONTEND_SITE_URL:-}
        VITE_SEARCH_URL: ${VITE_SEARCH_URL:-}
        VITE_SUPABASE_ANON_KEY: ${VITE_SUPABASE_ANON_KEY:-}
        VITE_SUPER_ADMIN_EMAIL: ${VITE_SUPER_ADMIN_EMAIL:-}
        VITE_TLSYNC_URL: ${VITE_TLSYNC_URL:-}
        VITE_WHISPERLIVE_URL: ${VITE_WHISPERLIVE_URL:-}
    env_file:
      - .env.dev
    ports:
      - "13000:3000"
    networks:
      - kevlarai-network
    restart: unless-stopped

volumes:
  app-test-node-modules:

networks:
  kevlarai-network:
    external: true
    name: kevlarai-network
