#!/bin/bash
# Quick Server Status Check

echo "╔════════════════════════════════════════════════════════════╗"
echo "║         SkyArtShop Server Quick Status                    ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""

# Check if PM2 process is running
if pm2 list | grep -q "skyartshop.*online"; then
    echo "✅ Server Status: ONLINE"
    
    # Get uptime
    UPTIME=$(pm2 jlist | grep -A 20 "\"name\":\"skyartshop\"" | grep "pm_uptime" | cut -d':' -f2 | cut -d',' -f1)
    if [ ! -z "$UPTIME" ]; then
        SECONDS=$(($(date +%s) - $UPTIME / 1000))
        HOURS=$((SECONDS / 3600))
        MINUTES=$(((SECONDS % 3600) / 60))
        echo "⏱️  Uptime: ${HOURS}h ${MINUTES}m"
    fi
    
    # Check if responding
    if curl -s -o /dev/null -w "%{http_code}" http://localhost:5000 | grep -q "200"; then
        echo "🌐 Website: Responding on http://localhost:5000"
    else
        echo "⚠️  Website: Not responding (check logs)"
    fi
    
else
    echo "❌ Server Status: OFFLINE"
    echo ""
    echo "Start the server with:"
    echo "  ./manage-server.sh start"
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Quick Commands:"
echo "  Status:  ./manage-server.sh status"
echo "  Logs:    ./manage-server.sh logs"
echo "  Restart: ./manage-server.sh restart"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
