.PHONY: setup-env install dev build clean help

setup-env:
	@if [ ! -f .env.local ]; then \
		cp .env.example .env.local; \
		echo "✅ Created .env.local from .env.example"; \
	else \
		echo "✅ .env.local already exists"; \
	fi

install: setup-env
	@echo "📦 Installing frontend dependencies..."
	pnpm install

dev: setup-env
	@if command -v pnpm >/dev/null 2>&1; then \
		pnpm run dev; \
	elif command -v node >/dev/null 2>&1 && [ -f node_modules/next/dist/bin/next ]; then \
		node node_modules/next/dist/bin/next dev; \
	else \
		echo "❌ pnpm is not on PATH and the local Next.js binary is missing. Run make install first."; \
		exit 1; \
	fi

build:
	pnpm run build

clean:
	rm -rf node_modules .next

help:
	@echo "Frontend targets:"
	@echo "  make setup-env  - Create .env.local from .env.example"
	@echo "  make install    - Install Node dependencies (pnpm install)"
	@echo "  make dev        - Start Next.js dev server (:3000)"
	@echo "  make build      - Production build"
	@echo "  make clean      - Remove node_modules and .next"
