#!/bin/bash
# Quick Vite dev server status check

echo "╔════════════════════════════════════════════════════════════╗"
echo "║           Vite Dev Server Status Check (Port 8021)        ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""

# Check Docker container
echo "📦 Docker Container Status:"
if docker ps --filter "name=igny8_frontend" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -q igny8_frontend; then
    docker ps --filter "name=igny8_frontend" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
else
    echo "   ❌ Container 'igny8_frontend' not found or not running"
fi
echo ""

# Check port
echo "🔌 Port 8021 Status:"
if netstat -tuln 2>/dev/null | grep -q ":8021" || ss -tuln 2>/dev/null | grep -q ":8021"; then
    echo "   ✅ Port 8021 is listening"
    netstat -tuln 2>/dev/null | grep ":8021" || ss -tuln 2>/dev/null | grep ":8021"
else
    echo "   ❌ Port 8021 is not listening"
fi
echo ""

# Test HTTP response
echo "🌐 HTTP Response Test:"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8021/ 2>/dev/null)
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "304" ]; then
    echo "   ✅ Server responding (HTTP $HTTP_CODE)"
else
    echo "   ❌ Server not responding (HTTP $HTTP_CODE or connection failed)"
fi
echo ""

# Check recent logs
echo "📋 Recent Container Logs (last 10 lines):"
docker logs igny8_frontend --tail 10 2>/dev/null || echo "   ⚠️  Could not fetch logs"
echo ""

echo "════════════════════════════════════════════════════════════"

