# Toggle & Popup Components - Build System
# =========================================

# Default target
.PHONY: all
all: build

# Install dependencies
.PHONY: install
install:
	npm install

# Build the components
.PHONY: build
build: install
	npm run build

# Watch for changes and rebuild
.PHONY: watch
watch: install
	npm run watch

# Clean the dist directory
.PHONY: clean
clean:
	rm -rf dist/*
	rm -rf node_modules

# Serve the demo with browser-sync (hot reload)
.PHONY: serve
serve:
	npx browser-sync start \
		--server \
		--files "demo/**/*.html, dist/**/*.js" \
		--startPath "demo/index.html" \
		--no-notify

# Build and serve (development mode)
.PHONY: dev
dev: build serve

# Serve with watch mode in background (full dev experience)
.PHONY: dev-watch
dev-watch: install
	@echo "Starting development server with hot reload..."
	@echo "Building initial bundle..."
	npm run build
	@echo ""
	@echo "Starting browser-sync and rollup watch..."
	@npx concurrently \
		"npx rollup -c -w" \
		"npx browser-sync start --server --files 'demo/**/*.html, dist/**/*.js' --startPath 'demo/index.html' --no-notify"

# Quick serve (assumes already built)
.PHONY: demo
demo:
	npx browser-sync start \
		--server \
		--files "demo/**/*.html, dist/**/*.js" \
		--startPath "demo/index.html" \
		--no-notify

# Help
.PHONY: help
help:
	@echo "Toggle & Popup Components - Available targets:"
	@echo ""
	@echo "  make install    - Install npm dependencies"
	@echo "  make build      - Build all component bundles"
	@echo "  make watch      - Watch for changes and rebuild"
	@echo "  make serve      - Start browser-sync server"
	@echo "  make dev        - Build then serve (recommended)"
	@echo "  make dev-watch  - Build, watch, and serve concurrently"
	@echo "  make demo       - Quick serve (assumes pre-built)"
	@echo "  make clean      - Remove dist and node_modules"
	@echo "  make help       - Show this help message"
	@echo ""
	@echo "Typical workflow:"
	@echo "  1. make dev     - Build and launch demo in browser"
	@echo ""
	@echo "For continuous development:"
	@echo "  1. make dev-watch - Watches files and auto-rebuilds"
