<?php

require_once __DIR__ . '/_cms_helpers.php';

$sectionConfig =
    ecms_get_section_config('themes');

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

$lang =
    $lang ?? 'en';

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

?>

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

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

        <div>

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

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

                <?= $lang === 'ar'
                    ? 'المحاور البحثية'
                    : 'Research Tracks' ?>

            </div>

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

                <?= $lang === 'ar'
                    ? 'المجالات العلمية ومحاور المؤتمر'
                    : 'Conference Themes & Research Domains' ?>

            </div>

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

                <?= $lang === 'ar'
                    ? 'يغطي المؤتمر مجموعة واسعة من المجالات العلمية والاتجاهات البحثية الحديثة ضمن تجربة أكاديمية عالمية احترافية.'
                    : 'The conference covers diverse scientific domains and emerging research trends within a world-class scholarly experience.'
                ?>

            </div>

        </div>

    </div>

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

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

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

            <h4 class="fw-bold">

                <?= $lang === 'ar'
                    ? 'سيتم الإعلان عن المحاور قريباً'
                    : 'Research tracks will be announced soon' ?>

            </h4>

        </div>

    <?php else: ?>

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

            <?php foreach ($themes as $index => $theme): ?>

                <?php

                $title =
                    $lang === 'ar'
                    ? ($theme['name_ar'] ?? $theme['title_ar'] ?? $theme['name_en'] ?? '')
                    : ($theme['name_en'] ?? $theme['title_en'] ?? $theme['name_ar'] ?? '');

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

                $icons = [
                    'fa-brain',
                    'fa-microchip',
                    'fa-robot',
                    'fa-shield-halved',
                    'fa-database',
                    'fa-chart-line',
                    'fa-code',
                    'fa-network-wired',
                    'fa-earth-americas',
                    'fa-flask'
                ];

                $icon =
                    $icons[$index % count($icons)];

                ?>

                <div class="ec-theme-card-v2">

                    <div class="ec-theme-glow"></div>

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

                        <div class="ec-theme-icon-v2">

                            <i class="fa <?= pcb_h($icon) ?>"></i>

                        </div>

                        <div class="ec-theme-number">

                            <?= str_pad(
                                (string)($index + 1),
                                2,
                                '0',
                                STR_PAD_LEFT
                            ) ?>

                        </div>

                    </div>

                    <div class="ec-theme-title-v2">

                        <?= pcb_h($title) ?>

                    </div>

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

                        <div class="ec-theme-desc-v2">

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

                        </div>

                    <?php endif; ?>

                    <div class="ec-theme-tags-v2">

                        <span>

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

                            <?= $lang === 'ar'
                                ? 'بحث علمي'
                                : 'Research' ?>

                        </span>

                        <span>

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

                            <?= $lang === 'ar'
                                ? 'مناقشات'
                                : 'Discussions' ?>

                        </span>

                    </div>

                    <div class="ec-theme-footer-v2">

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

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

                            <?= $lang === 'ar'
                                ? 'استقبال أبحاث'
                                : 'Accepting Papers' ?>

                        </div>

                    </div>

                </div>

            <?php endforeach; ?>

        </div>

    <?php endif; ?>

</section>
