#!/bin/bash
set -e
echo "🚀 Setting up Chandra & Sons Website..."
echo ""

# Check PHP
if ! command -v php &> /dev/null; then echo "❌ PHP not found. Please install PHP 8.2+"; exit 1; fi
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
echo "✅ PHP $PHP_VERSION found"

# Install Composer dependencies
echo "📦 Installing PHP dependencies..."
composer install --no-dev --optimize-autoloader

# Install NPM dependencies
echo "📦 Installing Node dependencies..."
npm install

# Build assets
echo "🎨 Building frontend assets..."
npm run build

# Setup .env
if [ ! -f .env ]; then
    cp .env.example .env
    echo "📄 .env file created from .env.example"
fi

# Generate app key
php artisan key:generate

# Create storage link
php artisan storage:link

echo ""
echo "✅ Dependencies installed!"
echo ""
echo "Next steps:"
echo "  1. Edit .env with your database credentials"
echo "  2. Run: php artisan migrate --seed"
echo "  3. Run: php artisan serve"
echo "  4. Visit: http://localhost:8000/en"
echo "  5. Admin panel: http://localhost:8000/admin"
echo "     Email: admin@chandrasons.com"
echo "     Password: Admin@1234"
