# Talks — Makefile unique pour build, run, gestion des présentations
# Variables : SITE_BASE, SLUG, FROM, TO

NPM ?= npm
NODE ?= node

.DEFAULT_GOAL := help

.PHONY: help install sync run build clean test \
	create-presentation delete-presentation clone-presentation rename-presentation \
	dev-portal dev-slides

help:
	@echo "Talks — commandes principales"
	@echo ""
	@echo "  make run              Sync, build tous les decks, VitePress dev + watch (sources = vérité)"
	@echo "  make build            sync + vitepress build → dist-portal + build chaque dist-<slug>/"
	@echo "  make sync             Régénère le portail depuis slides/*/meta.json"
	@echo "  make clean            Supprime dist-portal, dist-*, .slide-wip, cache VitePress, artifacts"
	@echo "  make test             Tests Node + Playwright"
	@echo ""
	@echo "Présentations (slugs : a-z 0-9 -) :"
	@echo "  make create-presentation SLUG=mon-talk"
	@echo "  make delete-presentation SLUG=mon-talk"
	@echo "  make clone-presentation FROM=src TO=dst"
	@echo "  make rename-presentation FROM=old TO=new"
	@echo ""
	@echo "  make install          npm install"
	@echo "  make dev-portal       Portail seul (sync + VitePress dev, base=/ ; pas de build decks)"
	@echo "  make dev-slides SLUG=…  slidev interactif sur un deck"
	@echo ""
	@echo "Sous-chemin (Pages) : make sync build SITE_BASE=/mon-repo/"

install:
	$(NPM) install

sync:
	SITE_BASE=$(SITE_BASE) $(NODE) tools/sync-portal.mjs

run:
	$(NPM) run start

build: sync
	SITE_BASE=$(SITE_BASE) $(NPM) run build

clean:
	rm -rf dist-portal .slide-wip portal/.vitepress/cache artifacts
	@sh -c 'for d in dist-*; do [ -d "$$d" ] && rm -rf "$$d"; done' || true

create-presentation:
	@test -n "$(SLUG)" || (echo "usage: make create-presentation SLUG=mon-talk"; exit 1)
	$(NODE) tools/presentation-cli.mjs create $(SLUG)

delete-presentation:
	@test -n "$(SLUG)" || (echo "usage: make delete-presentation SLUG=mon-talk"; exit 1)
	$(NODE) tools/presentation-cli.mjs delete $(SLUG)

clone-presentation:
	@test -n "$(FROM)" && test -n "$(TO)" || (echo "usage: make clone-presentation FROM=a TO=b"; exit 1)
	$(NODE) tools/presentation-cli.mjs clone $(FROM) $(TO)

rename-presentation:
	@test -n "$(FROM)" && test -n "$(TO)" || (echo "usage: make rename-presentation FROM=a TO=b"; exit 1)
	$(NODE) tools/presentation-cli.mjs rename $(FROM) $(TO)

dev-portal:
	$(NPM) run dev:portal

SLUG ?= kubernetes-operators
dev-slides:
	slidev slides/$(SLUG)/slides.md --open

test:
	$(NPM) run test
