<?php

require_once __DIR__ . '/_cms_helpers.php';

$lang =
    $lang ?? 'en';

$currentSection =
    $currentSection ?? [];

?>

<section
    data-cms-section="members"
    id="members"
    class="ecms-managed-section ec-section-shell ec-section-anchor <?= pcb_h($currentSection['theme_name'] ?? '') ?>">

    <div class="container">

        <div class="proceedings-header">

            <div>

                <div class="ec-ieee-badge mb-4">
                    <i class="fa fa-users"></i>
                    <?= pcb_h($lang === 'ar' ? 'اللجان والمشاركون' : 'Committees & Members') ?>
                </div>

                <h2 class="section-title">
                    <?= pcb_h(
                        $lang === 'ar'
                            ? ($currentSection['title_ar'] ?? 'اللجان العلمية والتنظيمية')
                            : ($currentSection['title_en'] ?? 'Scientific & Organizing Committees')
                    ) ?>
                </h2>

                <p class="pcb-section-text mt-4">
                    <?= pcb_h(
                        $lang === 'ar'
                            ? ($currentSection['subtitle_ar'] ?? 'يتم عرض أعضاء اللجان والمشاركين في تنظيم المؤتمر.')
                            : ($currentSection['subtitle_en'] ?? 'Conference committees and organizing members are displayed here.')
                    ) ?>
                </p>

            </div>

        </div>

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

    <?php foreach ($groupedCommittees as $committeeType => $members): ?>

        <div class="mb-5">

            <div class="type-pill mb-4">

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

                <?= pcb_h(
                    t(
                        'committee.' .
                        strtolower((string)$committeeType),

                        (string)$committeeType
                    )
                ) ?>

            </div>

            <div class="row g-4">

                <?php foreach ($members as $m): ?>

                    <?php

                    $memberName = $lang === 'ar'
                        ? (($m['full_name_ar'] ?? '') ?: ($m['full_name_en'] ?? ''))
                        : (($m['full_name_en'] ?? '') ?: ($m['full_name_ar'] ?? ''));

                    $memberTitle = $lang === 'ar'
                        ? (($m['title_ar'] ?? '') ?: ($m['title_en'] ?? ''))
                        : (($m['title_en'] ?? '') ?: ($m['title_ar'] ?? ''));

                    $memberAff = $lang === 'ar'
                        ? (($m['affiliation_ar'] ?? '') ?: ($m['affiliation_en'] ?? ''))
                        : (($m['affiliation_en'] ?? '') ?: ($m['affiliation_ar'] ?? ''));

                    ?>

                    <div class="col-lg-3 col-md-4 col-sm-6">

                        <div class="cardx p-4 h-100 text-center">

                            <?php if (!empty($m['image_path'])): ?>

                                <img
                                    src="/easychair/<?= pcb_h($m['image_path']) ?>"
                                    class="avatar mx-auto mb-3"
                                    alt=""
                                >

                            <?php else: ?>

                                <div class="noavatar mx-auto mb-3">

                                    <?= strtoupper(
                                        mb_substr(
                                            $memberName ?: 'C',
                                            0,
                                            1
                                        )
                                    ) ?>

                                </div>

                            <?php endif; ?>

                            <h5 class="fw-bold mb-2">

                                <?= pcb_h($memberName) ?>

                            </h5>

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

                                <div class="text-primary fw-semibold mb-2">

                                    <?= pcb_h($memberTitle) ?>

                                </div>

                            <?php endif; ?>

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

                                <div class="text-muted small">

                                    <?= pcb_h($memberAff) ?>

                                </div>

                            <?php endif; ?>

                        </div>

                    </div>

                <?php endforeach; ?>

            </div>

        </div>

    <?php endforeach; ?>

<?php else: ?>

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

        <?= pcb_h(
            $lang === 'ar'
                ? 'لا توجد بيانات لجان متاحة حالياً.'
                : 'No committee data available yet.'
        ) ?>

    </div>

<?php endif; ?>

    </div>

</section>
