#!/bin/bash

echo "Checking LiveView Setup for AI Debug..."
echo "======================================="

# Check if Phoenix server is running
echo -n "1. Phoenix Server Status: "
if pgrep -f "beam.*phx.server" > /dev/null; then
    echo "✅ Running"
else
    echo "❌ Not running"
    echo "   Run: cd /Users/og/src/ai-debug-local-mcp/core && mix phx.server"
fi

# Check if the page is accessible
echo -n "2. Page Accessibility: "
if curl -s -o /dev/null -w "%{http_code}" http://localhost:4001/validate | grep -q "200"; then
    echo "✅ Accessible (HTTP 200)"
else
    echo "❌ Not accessible"
fi

# Check for JavaScript assets
echo -n "3. JavaScript Assets: "
if [ -f "/Users/og/src/ai-debug-local-mcp/core/priv/static/assets/app.js" ]; then
    echo "✅ Found"
    # Check if LiveSocket is configured
    if grep -q "LiveSocket" "/Users/og/src/ai-debug-local-mcp/core/priv/static/assets/app.js"; then
        echo "   ✅ LiveSocket configured"
    else
        echo "   ❌ LiveSocket not found in app.js"
    fi
else
    echo "❌ Not found - run: mix assets.deploy"
fi

# Check WebSocket endpoint
echo -n "4. WebSocket Endpoint: "
if grep -q 'socket "/live"' "/Users/og/src/ai-debug-local-mcp/core/lib/ai_debug_web/endpoint.ex" 2>/dev/null; then
    echo "✅ Configured"
else
    echo "⚠️  Could not verify (check endpoint.ex)"
fi

echo ""
echo "Troubleshooting Tips:"
echo "===================="
echo "1. If assets are missing: cd core && mix assets.deploy"
echo "2. If server is not running: cd core && mix phx.server"
echo "3. Check browser console for JavaScript errors"
echo "4. Ensure WebSocket connections are not blocked"