#!/bin/bash

# Quick Start Development Mode
# Run this anytime to check status or start development

echo "╔══════════════════════════════════════════════╗"
echo "║  Sky Art Shop - Development Mode            ║"
echo "╚══════════════════════════════════════════════╝"
echo ""

# Check if backend is running
if pm2 list | grep -q "skyartshop.*online"; then
    echo "✅ Backend: Running on http://localhost:5000"
    echo "   📁 Serving from: /media/pts/Website/SkyArtShop/website/"
    echo "   🔄 Watch mode: Enabled (auto-restart on backend changes)"
else
    echo "❌ Backend: Not running"
    echo "   Starting now..."
    cd /media/pts/Website/SkyArtShop/backend
    NODE_ENV=development pm2 start server.js --name skyartshop --watch
    sleep 2
fi

echo ""

# Check nginx status
if systemctl is-active --quiet nginx; then
    echo "⚠️  Nginx: Running (should be disabled for development)"
    echo "   Run: sudo systemctl stop nginx"
else
    echo "✅ Nginx: Stopped (correct for development)"
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🌐 Access Your Site:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "  Homepage:         http://localhost:5000/"
echo "  Admin Login:      http://localhost:5000/admin/login.html"
echo "  Admin Dashboard:  http://localhost:5000/admin/dashboard.html"
echo "  Health Check:     http://localhost:5000/health"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✨ Making Changes:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "  1. Edit files in: /media/pts/Website/SkyArtShop/website/"
echo "  2. Refresh browser (F5 or Ctrl+R)"
echo "  3. See changes immediately!"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🛠️  Useful Commands:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "  pm2 status                    - Check backend status"
echo "  pm2 logs skyartshop           - View live logs"
echo "  pm2 restart skyartshop        - Restart backend"
echo "  ./test-instant-changes.sh     - Test instant changes"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

# Test connection
echo ""
echo "🧪 Testing connection..."
if curl -s http://localhost:5000/health > /dev/null 2>&1; then
    echo "✅ Server responding correctly!"
else
    echo "❌ Server not responding. Check logs: pm2 logs skyartshop"
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⚠️  Important Notes:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "  ✅ ONLY http://localhost:5000 is active"
echo "  ❌ http://localhost (port 80) is DISABLED"
echo "  🔒 Nginx and Apache are stopped for development"
echo ""
echo "  Run ./verify-localhost.sh to verify anytime"
echo ""
echo "Ready to develop! 🚀"
