# =============================================================================
# BASE DEVELOPMENT COMMANDS - Rustelo Framework
# =============================================================================
# Core development commands for any Rustelo-based project

# Start development server with hot reload
dev:
    @echo "🚀 Starting development server..."
    cargo leptos watch

# Start development server with custom port
dev-port port="3030":
    @echo "🚀 Starting development server on port {{port}}..."
    LEPTOS_SITE_ADDR="127.0.0.1:{{port}}" cargo leptos watch

# Start development server with CSS watching
dev-full:
    @echo "🚀 Starting full development environment..."
    @just css-watch &
    cargo leptos watch

# Watch CSS files for changes
css-watch:
    @echo "👁️ Watching CSS files..."
    @if [ -f "package.json" ]; then npm run watch:css; else echo "⚠️  No package.json found, skipping CSS watch"; fi

# Build CSS files
css-build:
    @echo "🎨 Building CSS files..."
    @if [ -f "package.json" ]; then npm run build:css; else echo "⚠️  No package.json found, skipping CSS build"; fi

# Setup project dependencies and tools
setup:
    @echo "📦 Setting up project dependencies and tools..."
    @if [ -f "package.json" ]; then echo "📦 Installing npm dependencies..." && npm install; else echo "ℹ️  No package.json found, skipping npm install"; fi
    @echo "🦀 Installing cargo-leptos..."
    cargo install cargo-leptos

# Install development dependencies
dev-deps:
    @echo "📦 Installing development dependencies..."
    @if [ -f "package.json" ]; then echo "📦 Installing npm dependencies..." && npm install; else echo "ℹ️  No package.json found, skipping npm install"; fi
    @echo "🦀 Installing cargo-leptos..."
    cargo install cargo-leptos
    
# =============================================================================
# BUILD COMMANDS
# =============================================================================

# Build project for development
build:
    @echo "🔨 Building project..."
    cargo leptos build

# Build project for production
build-prod:
    @echo "🔨 Building for production..."
    cargo leptos build --release

# Clean build artifacts
clean:
    @echo "🧹 Cleaning build artifacts..."
    cargo clean
    rm -rf pkg/
    rm -rf dist/

# =============================================================================
# TEST COMMANDS
# =============================================================================

# Run all tests
test:
    @echo "🧪 Running tests..."
    cargo test

# Run tests with coverage
test-coverage:
    @echo "🧪 Running tests with coverage..."
    cargo tarpaulin --out Html

# Run end-to-end tests
test-e2e:
    @echo "🧪 Running e2e tests..."
    cd end2end && npm test

# Run tests in watch mode
test-watch:
    @echo "🧪 Running tests in watch mode..."
    cargo watch -x test