.DEFAULT_GOAL := help
.PHONY: help install dev build generate check-orval-compat fmt fmt-check lint lint-fix typecheck test check verify

help: ## Show available frontend commands.
	@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf "%-12s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

install: ## Install frontend dependencies from the lockfile.
	pnpm install --frozen-lockfile

dev: ## Start the Vite development server.
	pnpm run dev

build: ## Build the static frontend.
	pnpm run build

generate: ## Generate API client, query hooks, schemas, and MSW handlers.
	@if [ "$${API_PREPARED:-0}" != "1" ]; then $(MAKE) -C ../api bundle; fi
	pnpm run generate

check-orval-compat: ## Generate and type-check the OpenAPI 3.2 compatibility fixture in a temporary directory.
	pnpm run check:orval-compat

fmt: ## Format frontend source and configuration.
	pnpm run fmt

fmt-check: ## Check frontend formatting.
	pnpm run fmt:check

lint: ## Run TypeScript and CSS lint checks.
	pnpm run lint

lint-fix: ## Apply safe ESLint fixes.
	pnpm exec eslint . --fix --max-warnings=0

typecheck: ## Check strict TypeScript types.
	pnpm run typecheck

test: ## Run frontend unit tests.
	pnpm run test

check: ## Run formatting, lint, type, test, and build checks.
	pnpm run check

verify: ## Regenerate the API client and run all frontend checks.
	$(MAKE) generate
	$(MAKE) check
