<?php
// Script untuk download dan host CSS/JS lokal
// Jalankan sekali untuk download assets

echo "<h2>Downloading Assets for Production</h2>";

// Create assets directory if not exists
if (!is_dir('assets/css')) {
    mkdir('assets/css', 0755, true);
}
if (!is_dir('assets/js')) {
    mkdir('assets/js', 0755, true);
}

// Download Tailwind CSS
echo "<p>Downloading Tailwind CSS...</p>";
$tailwind_url = 'https://cdn.tailwindcss.com/3.4.0/tailwind.min.css';
$tailwind_content = file_get_contents($tailwind_url);
if ($tailwind_content) {
    file_put_contents('assets/css/tailwind.min.css', $tailwind_content);
    echo "<p style='color: green;'>✓ Tailwind CSS downloaded</p>";
} else {
    echo "<p style='color: red;'>✗ Failed to download Tailwind CSS</p>";
}

// Download Font Awesome CSS
echo "<p>Downloading Font Awesome CSS...</p>";
$fa_url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css';
$fa_content = file_get_contents($fa_url);
if ($fa_content) {
    file_put_contents('assets/css/fontawesome.min.css', $fa_content);
    echo "<p style='color: green;'>✓ Font Awesome CSS downloaded</p>";
} else {
    echo "<p style='color: red;'>✗ Failed to download Font Awesome CSS</p>";
}

// Download Font Awesome fonts
echo "<p>Downloading Font Awesome fonts...</p>";
$fa_fonts = [
    'fa-solid-900.woff2' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/webfonts/fa-solid-900.woff2',
    'fa-regular-400.woff2' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/webfonts/fa-regular-400.woff2',
    'fa-brands-400.woff2' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/webfonts/fa-brands-400.woff2'
];

if (!is_dir('assets/webfonts')) {
    mkdir('assets/webfonts', 0755, true);
}

foreach ($fa_fonts as $filename => $url) {
    $font_content = file_get_contents($url);
    if ($font_content) {
        file_put_contents('assets/webfonts/' . $filename, $font_content);
        echo "<p style='color: green;'>✓ Downloaded $filename</p>";
    } else {
        echo "<p style='color: red;'>✗ Failed to download $filename</p>";
    }
}

echo "<h3>Assets Download Complete!</h3>";
echo "<p>Now update your HTML files to use local assets instead of CDN.</p>";
