<?php
/**
 * Agentic Square - Premium Dynamic Front-End Hero Engine
 * CodeCanyon Execution Core Template Architecture
 */

// Hydrate banner structural properties from standard tracking context layout blocks securely
try {
    $bannerQuery = $pdo->query("SELECT * FROM banner_settings WHERE id = 1 LIMIT 1");
    $bannerData  = $bannerQuery->fetch(PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
    // Graceful fallback container array if query errors out to maintain framework operations
    $bannerData = [];
}

function banner_metric_value(?string $value, string $fallback): string
{
    $value = trim((string)$value);

    if ($value === '') {
        $value = $fallback;
    }

    $value = preg_replace('/^\$\s*/', currency_symbol(), $value);
    $value = preg_replace('/^USD\s+/i', get_site_currency() . ' ', $value);

    return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}

// Map variables with accurate production failover contexts
$tagline       = !empty($bannerData['tagline']) ? htmlspecialchars($bannerData['tagline'], ENT_QUOTES, 'UTF-8') : 'Next-Gen AI Script Ecosystem';
$heading       = !empty($bannerData['heading']) ? $bannerData['heading'] : 'Deploy, & Sell <br> AI Tools <br> On a Global Scale';
$subheading    = !empty($bannerData['subheading']) ? htmlspecialchars($bannerData['subheading'], ENT_QUOTES, 'UTF-8') : 'The premier decentralized digital product repository.';

$btn1_text     = !empty($bannerData['btn1_text']) ? htmlspecialchars($bannerData['btn1_text'], ENT_QUOTES, 'UTF-8') : 'Explore Catalog';
$btn1_url      = !empty($bannerData['btn1_url']) ? htmlspecialchars($bannerData['btn1_url'], ENT_QUOTES, 'UTF-8') : '#recent-items';
$btn2_text     = !empty($bannerData['btn2_text']) ? htmlspecialchars($bannerData['btn2_text'], ENT_QUOTES, 'UTF-8') : 'Become an Author';
$btn2_url      = !empty($bannerData['btn2_url']) ? htmlspecialchars($bannerData['btn2_url'], ENT_QUOTES, 'UTF-8') : 'dashboard.php';

$stat1_value   = banner_metric_value($bannerData['stat1_value'] ?? '', currency_symbol() . '2.4M+');
$stat1_label   = !empty($bannerData['stat1_label']) ? htmlspecialchars($bannerData['stat1_label'], ENT_QUOTES, 'UTF-8') : 'Author Revenues';
$stat2_value   = !empty($bannerData['stat2_value']) ? htmlspecialchars($bannerData['stat2_value'], ENT_QUOTES, 'UTF-8') : '45k+';
$stat2_label   = !empty($bannerData['stat2_label']) ? htmlspecialchars($bannerData['stat2_label'], ENT_QUOTES, 'UTF-8') : 'Verified Scripts';
$stat3_value   = !empty($bannerData['stat3_value']) ? htmlspecialchars($bannerData['stat3_value'], ENT_QUOTES, 'UTF-8') : '99.8%';
$stat3_label   = !empty($bannerData['stat3_label']) ? htmlspecialchars($bannerData['stat3_label'], ENT_QUOTES, 'UTF-8') : 'Instant Fulfillment';

$card_tag      = !empty($bannerData['card_tag']) ? htmlspecialchars($bannerData['card_tag'], ENT_QUOTES, 'UTF-8') : 'Top Trending Now';
$card_category = !empty($bannerData['card_category']) ? htmlspecialchars($bannerData['card_category'], ENT_QUOTES, 'UTF-8') : 'SaaS Automation Engine';
$card_rating   = !empty($bannerData['card_rating']) ? htmlspecialchars($bannerData['card_rating'], ENT_QUOTES, 'UTF-8') : '4.9';
$card_reviews  = isset($bannerData['card_reviews']) ? (int)$bannerData['card_reviews'] : 120;
$card_title    = !empty($bannerData['card_title']) ? htmlspecialchars($bannerData['card_title'], ENT_QUOTES, 'UTF-8') : 'Autonomous Agent Workflow Builder';
$card_dev_name = !empty($bannerData['card_dev_name']) ? htmlspecialchars($bannerData['card_dev_name'], ENT_QUOTES, 'UTF-8') : '@pixels_studio';
$card_price    = isset($bannerData['card_price']) ? format_currency($bannerData['card_price']) : format_currency(49.00);

// Match fallback links dynamically if upload paths do not populate
$card_banner_img = !empty($bannerData['card_banner_img']) ? htmlspecialchars($bannerData['card_banner_img'], ENT_QUOTES, 'UTF-8') : 'https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?auto=format&fit=crop&w=600&q=80';
$card_dev_img    = !empty($bannerData['card_dev_img']) ? htmlspecialchars($bannerData['card_dev_img'], ENT_QUOTES, 'UTF-8') : 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?auto=format&fit=crop&w=100&q=80';
?>

<section class="banner relative pt-36 pb-24 md:pt-48 md:pb-36 flex items-center min-h-screen">
    <div class="absolute top-1/4 left-1/4 w-96 h-96 bg-nftAccentPurple/10 rounded-full blur-[120px] pointer-events-none"></div>
    <div class="absolute top-1/2 right-1/4 w-[500px] h-[500px] bg-nftAccentCyan/10 rounded-full blur-[150px] pointer-events-none"></div>
    
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10 w-full">
        <div class="grid grid-cols-1 lg:grid-cols-12 gap-12 items-center">
            
            <div class="lg:col-span-7 space-y-6 text-center lg:text-left">
                <span class="inline-block bg-gradient-to-r from-nftAccentPurple/20 to-nftAccentCyan/20 border border-nftAccentCyan/30 text-nftAccentCyan text-xs uppercase tracking-widest font-bold px-4 py-1.5 rounded-full">
                    <i class="fa-solid fa-robot mr-1.5 animate-pulse"></i> <?php echo $tagline; ?>
                </span>
                <h1 class="text-4xl sm:text-5xl md:text-6xl font-extrabold tracking-tight leading-[1.1] text-white">
                    <?php echo $heading; ?>
                </h1>
                <p class="text-nftTextGray text-base sm:text-lg max-w-xl mx-auto lg:mx-0 leading-relaxed">
                    <?php echo $subheading; ?>
                </p>
                <div class="flex flex-wrap justify-center lg:justify-start gap-4 pt-4">
                    <a href="<?php echo $btn1_url; ?>" class="btn-gradient px-8 py-3.5 rounded-full font-semibold shadow-xl transition-all">
                        <?php echo $btn1_text; ?>
                    </a>
                    <a href="<?php echo $btn2_url; ?>" class="bg-slate-900 border border-slate-800 hover:border-nftAccentCyan px-8 py-3.5 rounded-full font-semibold text-white transition-all duration-300">
                        <?php echo $btn2_text; ?>
                    </a>
                </div>

                <div class="grid grid-cols-3 gap-6 pt-10 border-t border-slate-800/80 max-w-md mx-auto lg:mx-0">
                    <div>
                        <h3 class="text-2xl sm:text-3xl font-extrabold"><?php echo $stat1_value; ?></h3>
                        <p class="text-xs text-nftTextGray mt-1"><?php echo $stat1_label; ?></p>
                    </div>
                    <div>
                        <h3 class="text-2xl sm:text-3xl font-extrabold"><?php echo $stat2_value; ?></h3>
                        <p class="text-xs text-nftTextGray mt-1"><?php echo $stat2_label; ?></p>
                    </div>
                    <div>
                        <h3 class="text-2xl sm:text-3xl font-extrabold"><?php echo $stat3_value; ?></h3>
                        <p class="text-xs text-nftTextGray mt-1"><?php echo $stat3_label; ?></p>
                    </div>
                </div>
            </div>

            <div class="lg:col-span-5 flex justify-center relative">
                <div class="glass-card w-full max-w-sm rounded-3xl p-5 border border-slate-800/80 shadow-2xl relative">
                    <div class="relative overflow-hidden rounded-2xl aspect-[4/3] mb-5">
                        <img src="<?php echo $card_banner_img; ?>" alt="Spotlight Product Visual Asset" class="w-full h-full object-cover">
                        <div class="absolute top-3 right-3 bg-slate-950/80 backdrop-blur-md text-[11px] font-bold px-3 py-1.5 rounded-lg border border-slate-800 text-nftAccentCyan">
                            <i class="fa-solid fa-bolt mr-1"></i> <?php echo $card_tag; ?>
                        </div>
                    </div>
                    <div class="flex items-center justify-between mb-2">
                        <span class="text-[11px] font-bold uppercase tracking-wider text-nftAccentPurple"><?php echo $card_category; ?></span>
                        <div class="flex items-center text-amber-400 text-xs">
                            <i class="fa-solid fa-star mr-1"></i> <?php echo $card_rating; ?> <span class="text-nftTextGray ml-1">(<?php echo $card_reviews; ?> reviews)</span>
                        </div>
                    </div>
                    <h2 class="text-xl font-bold tracking-wide hover:text-nftAccentCyan cursor-pointer transition-colors"><?php echo $card_title; ?></h2>
                    
                    <div class="flex items-center justify-between mt-4 pt-4 border-t border-slate-800/60">
                        <div class="flex items-center space-x-2">
                            <img src="<?php echo $card_dev_img; ?>" alt="Certified Merchant" class="w-8 h-8 rounded-full border border-nftAccentCyan object-cover">
                            <div>
                                <p class="text-[10px] text-nftTextGray uppercase">Developer</p>
                                <p class="text-xs font-semibold text-slate-200"><?php echo $card_dev_name; ?></p>
                            </div>
                        </div>
                        <div class="text-right">
                            <p class="text-[10px] text-nftTextGray uppercase">Commercial License</p>
                            <p class="text-lg font-extrabold text-nftAccentCyan"><?php echo htmlspecialchars($card_price, ENT_QUOTES, 'UTF-8'); ?></p>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</section>
