<?php
/**
 * Asset Availability Checker
 * Run this to check which assets are missing
 */

echo "<!DOCTYPE html>\n";
echo "<html><head><meta charset='UTF-8'><title>Asset Check</title>";
echo "<style>body{font-family:Arial,sans-serif;max-width:800px;margin:50px auto;padding:20px;}";
echo ".missing{color:#dc3545;}.found{color:#28a745;}.section{margin:20px 0;padding:15px;background:#f5f5f5;border-radius:5px;}";
echo "h2{color:#333;border-bottom:2px solid #007bff;padding-bottom:10px;}";
echo ".command{background:#2d2d2d;color:#f8f8f2;padding:15px;border-radius:5px;margin:10px 0;font-family:monospace;}";
echo "</style></head><body>";

echo "<h1>🔍 Hotspot Assets Check</h1>";

$baseDir = __DIR__;
$missingFiles = [];
$foundFiles = [];

// Required CSS files
$cssFiles = [
    'css/fontawesome.min.css' => 'Font Awesome Icons',
    'css/inter-font.css' => 'Inter Font CSS (already created)'
];

// Required JS files
$jsFiles = [
    'js/jquery.min.js' => 'jQuery Library',
    'js/sweetalert2.min.js' => 'SweetAlert2 Library',
    'js/tailwind.min.js' => 'Tailwind CSS Framework'
];

// Required Font files
$fontFiles = [
    'fonts/Inter-Regular.woff2' => 'Inter Font - Regular',
    'fonts/Inter-Medium.woff2' => 'Inter Font - Medium',
    'fonts/Inter-SemiBold.woff2' => 'Inter Font - Semi Bold',
    'fonts/Inter-Bold.woff2' => 'Inter Font - Bold',
    'fonts/Inter-ExtraBold.woff2' => 'Inter Font - Extra Bold'
];

function checkFiles($files, $baseDir, &$missing, &$found) {
    foreach ($files as $file => $desc) {
        $fullPath = $baseDir . '/' . $file;
        if (file_exists($fullPath)) {
            $size = filesize($fullPath);
            $sizeKB = round($size / 1024, 2);
            $found[] = ['file' => $file, 'desc' => $desc, 'size' => $sizeKB . ' KB'];
        } else {
            $missing[] = ['file' => $file, 'desc' => $desc];
        }
    }
}

echo "<div class='section'>";
echo "<h2>📁 CSS Files</h2>";
checkFiles($cssFiles, $baseDir, $missingFiles, $foundFiles);
echo "</div>";

echo "<div class='section'>";
echo "<h2>📜 JavaScript Files</h2>";
checkFiles($jsFiles, $baseDir, $missingFiles, $foundFiles);
echo "</div>";

echo "<div class='section'>";
echo "<h2>🔤 Font Files</h2>";
checkFiles($fontFiles, $baseDir, $missingFiles, $foundFiles);
echo "</div>";

// Summary
echo "<div class='section'>";
echo "<h2>📊 Summary</h2>";
echo "<p><strong class='found'>✅ Found:</strong> " . count($foundFiles) . " files</p>";
echo "<p><strong class='missing'>❌ Missing:</strong> " . count($missingFiles) . " files</p>";
echo "</div>";

// Show found files
if (!empty($foundFiles)) {
    echo "<div class='section'>";
    echo "<h2 class='found'>✅ Available Files</h2>";
    echo "<ul>";
    foreach ($foundFiles as $file) {
        echo "<li class='found'><strong>{$file['file']}</strong> - {$file['desc']} ({$file['size']})</li>";
    }
    echo "</ul>";
    echo "</div>";
}

// Show missing files
if (!empty($missingFiles)) {
    echo "<div class='section'>";
    echo "<h2 class='missing'>❌ Missing Files</h2>";
    echo "<ul>";
    foreach ($missingFiles as $file) {
        echo "<li class='missing'><strong>{$file['file']}</strong> - {$file['desc']}</li>";
    }
    echo "</ul>";
    
    echo "<h3>🚀 Quick Fix:</h3>";
    echo "<p>Run the asset download script to get all missing files:</p>";
    echo "<div class='command'>cd " . str_replace('/', '\\', $baseDir) . "<br>";
    echo "php download_assets.php</div>";
    
    echo "<p><strong>Or visit:</strong> <a href='download_assets.php' target='_blank'>download_assets.php</a></p>";
    echo "</div>";
} else {
    echo "<div class='section' style='background:#d4edda;border:2px solid #28a745;'>";
    echo "<h2 class='found'>🎉 All Assets Available!</h2>";
    echo "<p>All required CSS, JavaScript, and font files are present.</p>";
    echo "<p>Your hotspot login page is ready to use!</p>";
    echo "</div>";
}

echo "</body></html>";
