<?php
/**
 * Content Migration Script
 * Moves hardcoded HTML from landing.php to the database for all 32 pages.
 */

try {
    $pdo = require __DIR__ . '/../config/database.php';
    echo "Connected to database.\n";

    $stmt = $pdo->query("SELECT sl.id, l.name as location_name FROM seo_landings sl JOIN locations l ON sl.location_id = l.id");
    $landings = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo "Migrating content for " . count($landings) . " pages.\n";

    $updateStmt = $pdo->prepare("UPDATE seo_landings SET content_json = ? WHERE id = ?");

    foreach ($landings as $l) {
        $loc = $l['location_name'];
        
        // Default HTML Template
        $html = "
<section class='section'>
    <div class='grid grid-2' style='align-items:center; gap:64px'>
        <div class='reveal'>
            <h2>Why Founders in {$loc} Choose Go Legal</h2>
            <p class='lead'>Registering a business with CAC shouldn't take weeks of chasing agents. We've simplified the entire process into 3 digital steps.</p>
            <ul class='list-clean' style='margin-top:32px; line-height:2.5'>
                <li>✅ <strong>Expert Document Review</strong>: We audit your application to prevent rejections.</li>
                <li>✅ <strong>No Office Visits</strong>: Complete everything from your home or office in {$loc}.</li>
                <li>✅ <strong>Digital Delivery</strong>: Get your certificate and TIN delivered to your email.</li>
                <li>✅ <strong>Flat-Rate Pricing</strong>: No hidden fees, no \"negotiation\" with agents.</li>
            </ul>
        </div>
        <div class='reveal'>
            <div class='card glass' style='padding:48px; border:none; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); color:#fff'>
                <h3 style='color:#fff; margin-top:0'>Ready to start?</h3>
                <p style='color:rgba(255,255,255,0.7); margin-bottom:32px'>Join 200+ businesses already registered and protected. It takes less than 5 minutes to submit your details.</p>
                <div style='background:rgba(255,255,255,0.1); padding:24px; border-radius:12px; border: 1px solid rgba(255,255,255,0.2)'>
                    <div style='color:rgba(255,255,255,0.5); text-transform:uppercase; font-size:12px; font-weight:700; margin-bottom:8px'>All-Inclusive Bundle</div>
                    <div style='font-size:32px; font-weight:800; margin-bottom:16px'>Instant Processing</div>
                    <ul class='list-clean' style='color:rgba(255,255,255,0.8); margin-bottom:24px; font-size:14px'>
                        <li>✓ CAC Official Filing Fees</li>
                        <li>✓ Name Reservation</li>
                        <li>✓ Professional Document Prep</li>
                        <li>✓ Digital Delivery</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</section>

<section class='section' id='how-it-works' style='background:#f8fafc; border-radius:24px; padding:64px; margin-top:64px'>
    <h2 style='text-align:center; margin-bottom:48px'>How it Works in {$loc}</h2>
    <div class='grid grid-3'>
        <div class='reveal'>
            <div style='font-size:24px; font-weight:800; color:var(--primary); margin-bottom:16px'>01</div>
            <h3>Pick Service</h3>
            <p class='muted'>Select your registration type and provide your preferred business names.</p>
        </div>
        <div class='reveal'>
            <div style='font-size:24px; font-weight:800; color:var(--primary); margin-bottom:16px'>02</div>
            <h3>Upload Docs</h3>
            <p class='muted'>Submit your ID and director details securely through our portal.</p>
        </div>
        <div class='reveal'>
            <div style='font-size:24px; font-weight:800; color:var(--primary); margin-bottom:16px'>03</div>
            <h3>Get Registered</h3>
            <p class='muted'>We handle the CAC filing and deliver your certificate once approved.</p>
        </div>
    </div>
</section>
        ";

        $updateStmt->execute([trim($html), $l['id']]);
    }

    echo "Migration complete. All pages are now editable.\n";

} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}
