#!/usr/bin/env bash
# docker-test.sh — Build and run bill-tracker in Docker for testing
# Usage: ./scripts/docker-test.sh
# Access: http://localhost:3036

set -euo pipefail
cd "$(dirname "$0")/.."

docker stop bill-tracker 2>/dev/null || true
docker rm bill-tracker 2>/dev/null || true
rm -rf dist node_modules/.vite 2>/dev/null

docker build --no-cache -t bill-tracker:local .

docker run -d --name bill-tracker -p 3036:3000 --restart unless-stopped \
  -e INIT_ADMIN_USER=admin \
  -e INIT_ADMIN_PASS=admin123 \
  -e INIT_TEST_USER=testuser \
  -e INIT_TEST_PASS=testpass123 \
  -e INIT_REGULAR_USER=regularuser \
  -e INIT_REGULAR_PASS=regularpass123 \
  -e CSRF_HTTP_ONLY=false \
  -e CSRF_SAME_SITE=lax \
  -v /tmp/bill-tracker-test/data:/data \
  bill-tracker:local

echo "✓ Running on http://localhost:3036"