<?php

require_once __DIR__ . '/_cms_helpers.php';
require_once BASE_PATH . '/app/helpers/media_helper.php';

$sectionConfig =
    ecms_get_section_config('speakers');

if (empty($sectionConfig['enabled'])) {
    return;
}

$speakers =
    ec_safe_array($speakers ?? []);

$lang =
    $lang ?? 'en';

$currentSection =
    $currentSection ?? [];

$sectionBackground =
    $currentSection['background_image']
    ?? $conference['homepage_banner']
    ?? $conference['banner_path']
    ?? $conference['featured_image']
    ?? '';

?>

<section
data-cms-section="speakers"
id="speakers"

class="
ecms-managed-section
ec-speakers-wrap
ec-section-shell
ec-section-anchor

<?= pcb_h(
$currentSection['theme_name']
?? ''
) ?>

<?= pcb_h(
$currentSection['custom_css_class']
?? ''
) ?>
"

<?php if(!empty($sectionBackground)): ?>

style="
background-image:
linear-gradient(
rgba(7,15,35,.90),
rgba(7,15,35,.92)
),
url('<?= pcb_h(
ec_media_url($sectionBackground)
) ?>');

background-size:cover;
background-position:center;
"

<?php endif; ?>

>

<div class="container">

<div class="ec-speakers-top">

<div>

<div class="ec-ieee-badge mb-4">

<i class="fa fa-microphone-lines"></i>

<?= pcb_h(
$lang === 'ar'
? 'المتحدثون الرئيسيون'
: 'Keynote Speakers'
) ?>

</div>

<h2 class="section-title text-white">

<?= pcb_h(
$lang === 'ar'
? 'خبراء وباحثون من جامعات ومؤسسات عالمية'
: 'Experts & Researchers from International Institutions'
) ?>

</h2>

<p class="pcb-section-text text-light mt-4">

<?= pcb_h(
$lang === 'ar'
? 'يستضيف المؤتمر نخبة من الباحثين والخبراء والمتخصصين من مختلف الجامعات والمؤسسات الدولية.'
: 'The conference hosts distinguished experts, researchers, and specialists from international universities and institutions.'
) ?>

</p>

</div>

<div class="proceeding-meta">

<span>

<i class="fa fa-user-group"></i>

<?= count($speakers) ?>

<?= pcb_h(
$lang === 'ar'
? 'متحدث'
: 'Speakers'
) ?>

</span>

<span>

<i class="fa fa-earth-americas"></i>

<?= pcb_h(
$lang === 'ar'
? 'خبرات عالمية'
: 'Global Experts'
) ?>

</span>

</div>

</div>

<?php if(empty($speakers)): ?>

<div class="alert alert-light rounded-4 shadow-sm">

<?= pcb_h(
$lang === 'ar'
? 'لا يوجد متحدثون حالياً'
: 'No speakers available yet'
) ?>

</div>

<?php else: ?>

<div class="ec-speakers-grid">

<?php foreach($speakers as $sp): ?>

<?php

$name =
    $sp['full_name']
    ?? '';

$title =
    $lang === 'ar'
    ? (
        $sp['title_ar']
        ?? $sp['title_en']
        ?? ''
    )
    : (
        $sp['title_en']
        ?? $sp['title_ar']
        ?? ''
    );

$bio =
    $lang === 'ar'
    ? (
        $sp['bio_ar']
        ?? $sp['bio_en']
        ?? ''
    )
    : (
        $sp['bio_en']
        ?? $sp['bio_ar']
        ?? ''
    );

$institution =
    $sp['institution_name']
    ?? '';

$photo =
    $sp['photo_path']
    ?? '';

?>

<div class="ec-speaker-card">

<div class="ec-speaker-cover"></div>

<div class="ec-speaker-image-wrap">

<?php if(!empty($photo)): ?>

<img
src="<?= pcb_h(
ec_media_url($photo)
) ?>"
class="ec-speaker-image"
alt="<?= pcb_h($name) ?>">

<?php else: ?>

<div class="ec-speaker-placeholder">

<i class="fa fa-user"></i>

</div>

<?php endif; ?>

</div>

<div class="ec-speaker-content">

<div class="ec-speaker-badge">

<i class="fa fa-award"></i>

<?= pcb_h(
$lang === 'ar'
? 'متحدث رئيسي'
: 'Keynote Speaker'
) ?>

</div>

<div class="ec-speaker-name">

<?= pcb_h($name) ?>

</div>

<?php if(!empty($title)): ?>

<div class="ec-speaker-title">

<?= pcb_h($title) ?>

</div>

<?php endif; ?>

<?php if(!empty($institution)): ?>

<div class="ec-speaker-institution">

<i class="fa fa-building-columns"></i>

<?= pcb_h($institution) ?>

</div>

<?php endif; ?>

<?php if(!empty($bio)): ?>

<div class="ec-speaker-bio">

<?= pcb_h(
mb_substr(
strip_tags($bio),
0,
220
)
) ?>

</div>

<?php endif; ?>

<div class="ec-speaker-footer">

<div class="ec-speaker-status">

<span class="ec-speaker-status-dot"></span>

<?= pcb_h(
$lang === 'ar'
? 'جلسة مباشرة'
: 'Live Session'
) ?>

</div>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

<?php endif; ?>

</div>

</section>
