<?php

require_once __DIR__ . '/_cms_helpers.php';

$sectionConfig =
    ecms_get_section_config('program');

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

$lang =
    $lang ?? 'en';

$programItems =
    ec_safe_array(
        $sessions
        ?? $program
        ?? []
    );

?>

<section
    data-cms-section="program"
    class="ecms-managed-section ec-program-wrap ec-section-shell ec-section-anchor"
    id="program">

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

        <div>

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

                <i class="fa fa-calendar-days"></i>

                <?= $lang === 'ar'
                    ? 'البرنامج العلمي'
                    : 'Scientific Program' ?>

            </div>

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

                <?= $lang === 'ar'
                    ? 'جدول الجلسات والفعاليات العلمية'
                    : 'Conference Sessions & Scientific Timeline' ?>

            </div>

            <div class="ec-program-desc">

                <?= $lang === 'ar'
                    ? 'استكشف الجلسات العلمية وورش العمل والمحاضرات الرئيسية ضمن تجربة زمنية احترافية حديثة.'
                    : 'Explore keynote sessions, workshops, and scholarly activities within a modern professional timeline experience.'
                ?>

            </div>

        </div>

    </div>

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

        <div class="alert alert-light border rounded-4 shadow-sm p-5 text-center">

            <i class="fa fa-calendar fa-3x text-primary mb-4"></i>

            <h4 class="fw-bold">

                <?= $lang === 'ar'
                    ? 'سيتم نشر البرنامج قريباً'
                    : 'Program schedule will be announced soon' ?>

            </h4>

        </div>

    <?php else: ?>

        <div class="ec-program-timeline">

            <?php foreach ($programItems as $index => $item): ?>

                <?php

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

                $desc =
                    $lang === 'ar'
                    ? ($item['description_ar'] ?? $item['description_en'] ?? '')
                    : ($item['description_en'] ?? $item['description_ar'] ?? '');

                $speaker =
                    $item['speaker']
                    ?? $item['speaker_name']
                    ?? '';

                $location =
                    $item['location']
                    ?? $item['hall']
                    ?? '';

                $time =
                    $item['time']
                    ?? $item['session_time']
                    ?? '';

                ?>

                <div class="ec-program-item">

                    <div class="ec-program-marker">

                        <div class="ec-program-dot">

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

                        </div>

                    </div>

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

                        <div class="ec-program-card-top">

                            <div class="ec-program-time">

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

                                <?= pcb_h($time ?: '09:00 AM') ?>

                            </div>

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

                                <?= $lang === 'ar'
                                    ? 'جلسة علمية'
                                    : 'Scientific Session' ?>

                            </div>

                        </div>

                        <div class="ec-program-card-title">

                            <?= pcb_h($title) ?>

                        </div>

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

                            <div class="ec-program-card-desc">

                                <?= pcb_h(
                                    mb_substr(
                                        strip_tags($desc),
                                        0,
                                        320
                                    )
                                ) ?>

                            </div>

                        <?php endif; ?>

                        <div class="ec-program-meta">

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

                                <span>

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

                                    <?= pcb_h($speaker) ?>

                                </span>

                            <?php endif; ?>

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

                                <span>

                                    <i class="fa fa-location-dot"></i>

                                    <?= pcb_h($location) ?>

                                </span>

                            <?php endif; ?>

                            <span>

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

                                <?= $lang === 'ar'
                                    ? 'مفتوحة للحضور'
                                    : 'Open Attendance' ?>

                            </span>

                        </div>

                    </div>

                </div>

            <?php endforeach; ?>

        </div>

    <?php endif; ?>

</section>
