.PHONY: help dev build preview check test test-unit test-e2e lint \
	db-push db-generate db-migrate db-studio \
	install docker-build docker-up docker-down docker-logs clean

help: ## List all targets
	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2}'

dev: ## Start dev server
	pnpm dev

build: ## Production build
	pnpm build

preview: ## Preview production build
	pnpm preview

check: ## Svelte type checking
	pnpm check

test: ## Run all tests (unit + e2e)
	pnpm test

test-unit: ## Run unit tests only
	pnpm test:unit

test-e2e: ## Run e2e tests only
	pnpm test:e2e

lint: ## Run linter
	pnpm lint

db-push: ## Push schema to DB
	pnpm db:push

db-generate: ## Generate migrations
	pnpm db:generate

db-migrate: ## Run migrations
	pnpm db:migrate

db-studio: ## Open Drizzle Studio
	pnpm db:studio

install: ## Install dependencies
	pnpm install

docker-build: ## Build Docker image
	docker build -t crumbs .

docker-up: ## Start containers
	docker compose up -d

docker-down: ## Stop containers
	docker compose down

docker-logs: ## Tail container logs
	docker compose logs -f

clean: ## Remove build artifacts and test DBs
	rm -rf build .svelte-kit node_modules/.vite
	rm -f data/test-crumbs.db
