<?php
require_once __DIR__ . '/includes/functions.php';
$settings = getSettings();
$exhibitors = getData('exhibitors');

// Build unique countries list for filter
$countries = [];
foreach ($exhibitors as $ex) {
    if (!empty($ex['country']) && !in_array($ex['country'], $countries)) {
        $countries[] = $ex['country'];
    }
}
sort($countries);

$pageTitle = $settings['seo_exhibitors_title'];
$pageDesc = $settings['seo_exhibitors_desc'];

include __DIR__ . '/includes/header.php';
?>

<section class="page-hero">
    <div class="container">
        <span class="section-label">Who Exhibits</span>
        <h1 class="section-title">Past Exhibitors</h1>
        <nav class="breadcrumb-nav mt-2">
            <a href="<?php echo BASE_URL; ?>/index.php">Home</a>
            <span>/</span>
            Exhibitors
        </nav>
    </div>
</section>

<section class="section">
    <div class="container">
        <?php if (!empty($exhibitors)): ?>
        <div data-filter-container>
            <!-- Filter Tabs -->
            <div class="filter-tabs reveal">
                <button class="filter-tab active" data-filter-btn="all">All</button>
                <?php foreach ($countries as $country): ?>
                <button class="filter-tab" data-filter-btn="<?php echo e($country); ?>"><?php echo e($country); ?></button>
                <?php endforeach; ?>
            </div>

            <!-- Exhibitor Grid -->
            <div class="row g-4 reveal">
                <?php foreach ($exhibitors as $ex):
                    $logoPath = !empty($ex['logo']) ? UPLOADS_URL . '/logos/' . $ex['logo'] : '';
                    $hasLogo = !empty($ex['logo']) && file_exists(UPLOADS_PATH . '/logos/' . $ex['logo']);
                ?>
                <div class="col-lg-3 col-md-4 col-6" data-filter-item="<?php echo e($ex['country'] ?? ''); ?>">
                    <div class="exhibitor-card">
                        <?php if ($hasLogo): ?>
                        <img src="<?php echo $logoPath; ?>" alt="<?php echo e($ex['company_name'] ?? $ex['name'] ?? ''); ?>" class="exhibitor-logo">
                        <?php else: ?>
                        <div class="exhibitor-logo" style="display:flex;align-items:center;justify-content:center;background:var(--bg-light);border-radius:4px;">
                            <span style="font-family:var(--font-heading);font-size:0.75rem;color:var(--text-secondary);text-transform:uppercase;"><?php echo e($ex['company_name'] ?? $ex['name'] ?? 'Exhibitor'); ?></span>
                        </div>
                        <?php endif; ?>
                        <div class="exhibitor-name"><?php echo e($ex['company_name'] ?? $ex['name'] ?? ''); ?></div>
                        <div class="exhibitor-country"><?php echo e($ex['country'] ?? ''); ?></div>

                        <!-- Hover Overlay -->
                        <?php if (!empty($ex['website'])): ?>
                        <div class="exhibitor-hover">
                            <span style="font-family:var(--font-heading);font-size:0.8rem;text-transform:uppercase;text-align:center;"><?php echo e($ex['company_name'] ?? $ex['name'] ?? ''); ?></span>
                            <a href="<?php echo e($ex['website']); ?>" target="_blank" style="color:#fff;font-size:0.78rem;text-decoration:underline;" onclick="event.stopPropagation();">Visit Website →</a>
                        </div>
                        <?php else: ?>
                        <div class="exhibitor-hover">
                            <span style="font-family:var(--font-heading);font-size:0.8rem;text-transform:uppercase;text-align:center;"><?php echo e($ex['company_name'] ?? $ex['name'] ?? ''); ?></span>
                            <span style="font-size:0.72rem;opacity:0.8;"><?php echo e($ex['country'] ?? ''); ?></span>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
        <?php else: ?>
        <div class="empty-state reveal">
            <span class="empty-state-icon">🏢</span>
            <h3 style="font-family:var(--font-heading);font-size:1.1rem;text-transform:uppercase;color:var(--text-dark);margin-bottom:0.5rem;">Exhibitors Coming Soon</h3>
            <p style="max-width:400px;margin:0 auto 1.5rem;">Our exhibitor list is being updated. Be among the first to secure your spot at Ethiopia Food Expo 2026.</p>
            <a href="<?php echo BASE_URL; ?>/register.php" class="btn-green">Book a Stand</a>
        </div>
        <?php endif; ?>
    </div>
</section>

<section class="cta-banner">
    <div class="container reveal">
        <span class="section-label" style="color:rgba(255,255,255,0.7);border-left-color:rgba(255,255,255,0.4);">Join Industry Leaders</span>
        <h2 class="cta-title">Exhibit Alongside Industry Leaders</h2>
        <p class="cta-sub">Position your brand alongside the biggest names in food and beverage from around the world.</p>
        <a href="<?php echo BASE_URL; ?>/register.php" class="btn-white">Book a Stand Now</a>
    </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
