# ARM estándar · atajos. `make demo` corre todo en local, sin GCP.
PUERTO ?= 8080
PY := backend/.venv/bin/python

.PHONY: demo instalar pruebas dev-api dev-front grabar diseno limpiar

# Demo local: almacén en memoria, datos ficticios, agente simulado y login de demo.
# La app queda en http://localhost:8080 y el chat de demo en http://localhost:8080/demo/whatsapp
demo: backend/.venv frontend/node_modules frontend/dist/index.html
	cd backend && ENTORNO=local ALMACEN=memoria MODO_DEMO=1 AGENTE_SIMULADO=1 \
	  .venv/bin/uvicorn app.main:app --host 127.0.0.1 --port $(PUERTO)

instalar: backend/.venv frontend/node_modules

backend/.venv: backend/requirements.txt backend/requirements-dev.txt
	@if command -v uv >/dev/null 2>&1; then \
	  uv venv -q -p 3.12 backend/.venv && uv pip install -q -p backend/.venv/bin/python -r backend/requirements-dev.txt; \
	else \
	  python3 -m venv backend/.venv && backend/.venv/bin/pip install -q -r backend/requirements-dev.txt; \
	fi
	@touch backend/.venv

frontend/node_modules: frontend/package.json
	cd frontend && npm install --no-audit --no-fund
	@touch frontend/node_modules

frontend/dist/index.html: $(shell find frontend/src -type f 2>/dev/null) frontend/index.html
	cd frontend && npm run build

# Pruebas: backend (pytest), lógica del front (node --test) y que el front compile.
pruebas: backend/.venv frontend/node_modules
	cd backend && .venv/bin/python -m pytest -q
	cd frontend && npm test && npm run build

# Desarrollo con recarga: en una terminal `make dev-api`, en otra `make dev-front` (Vite en 5173).
dev-api: backend/.venv
	cd backend && ENTORNO=local ALMACEN=memoria MODO_DEMO=1 AGENTE_SIMULADO=1 .venv/bin/uvicorn app.main:app --reload --port $(PUERTO)

dev-front: frontend/node_modules
	cd frontend && npm run dev

# Graba los clips del reel con la demo corriendo (ver demo/grabaciones/README.md).
grabar:
	cd demo && npm install --no-audit --no-fund && node grabar.mjs

# Verifica las pantallas contra el estándar de diseño (con la demo corriendo): shell, riel,
# pila, responsive y colores fuera de tokens. Skill: .claude/skills/diseno-ui-ux-santa-ia.
SKILL_DISENO := .claude/skills/diseno-ui-ux-santa-ia/scripts
diseno:
	cd demo && npm install --no-audit --no-fund >/dev/null
	PW=$(CURDIR)/demo/node_modules/playwright node $(SKILL_DISENO)/verificar-shell.mjs http://localhost:$(PUERTO) \
	  demo/capturas-diseno $(SKILL_DISENO)/selectores/arm-estandar.json
	python3 -I $(SKILL_DISENO)/revisar-colores.py frontend/src --tokens tokens.css --tokens tokens-datos.css

limpiar:
	rm -rf backend/.venv frontend/node_modules frontend/dist demo/node_modules demo/cuadros demo/capturas-diseno
