<?php
/**
 * Event speakers/artists component
 */
if (!defined('ABSPATH')) exit;

// Get speaker settings - force enable if component is being rendered
$em_speaker_heading = $event_settings['em_speaker_heading'] ?? 'Keynote Speakers';
$em_speaker_name = $event_settings['em_speaker_name'] ?? array();
$em_speaker_speciality = $event_settings['em_speaker_speciality'] ?? array();

// Only show if have speaker data
if (empty($em_speaker_name) || empty(array_filter($em_speaker_name))) {
    return;
}

// Check if magazine layout
$layout_preference = $event_settings['em_layout_preference'] ?? 'default';
$rounded_class = ($layout_preference === 'magazine') ? 'em-rounded-2xl' : '';
$container_classes = ($layout_preference === 'magazine') ? 'em-space-y-3 em-grid em-grid-cols-1 sm:em-grid-cols-2 md:em-grid-cols-3 em-gap-6' : 'em-space-y-3';
?>
<div class="em-bg-white em-p-5 em-border em-border-slate-200 em-shadow-sm em-h-full em-flex em-flex-col <?php echo esc_attr($rounded_class); ?>">
    <h2 class="em-text-lg em-font-bold em-text-slate-900 em-mb-4"><?php echo esc_html($em_speaker_heading); ?></h2>
    <?php ?>
    <div class="<?php echo esc_attr($container_classes); ?>">
        <?php
        $speaker_count = 0;
        $max_speakers = 1; // Free version: Limited to 1 speaker (upgrade to Pro for unlimited)

        foreach ($em_speaker_name as $key => $name) {
            if ($speaker_count >= $max_speakers) break;
            if (empty(trim($name))) continue;

            $speciality = $em_speaker_speciality[$key] ?? '';
            $avatar = isset($event_settings['em_speaker_avatar'][$key]) ? $event_settings['em_speaker_avatar'][$key] : '';
            $speaker_count++;
            ?>
            <div class="em-flex em-items-center em-gap-3">
                <?php if (!empty($avatar)): ?>
                    <img src="<?php echo esc_url($avatar); ?>" alt="<?php echo esc_attr($name); ?>" class="em-w-10 em-h-10 em-rounded-full em-object-cover">
                <?php else: ?>
                    <div class="em-w-10 em-h-10 em-rounded-full em-bg-indigo-100 em-text-indigo-600 em-flex em-items-center em-justify-center em-font-bold em-text-sm">
                        <?php echo esc_html(strtoupper(substr($name, 0, 2))); ?>
                    </div>
                <?php endif; ?>
                <div>
                    <h4 class="em-font-semibold em-text-slate-800 em-text-sm"><?php echo esc_html($name); ?></h4>
                    <p class="em-text-xs em-text-slate-500"><?php echo esc_html($speciality ?: 'Industry Expert'); ?></p>
                </div>
            </div>
            <?php
        }

        // Placeholder speakers removed in free version
        ?>
    </div>
</div>
