<?php

$title = 'Homepage CMS Builder';

$sections =
    $sections ?? [];

?>

<div class="container-fluid py-4">

    <div class="d-flex justify-content-between align-items-center mb-4">

        <div>

            <h1 class="fw-bold mb-1">
                Homepage CMS Builder
            </h1>

            <div class="text-muted">
                Manage homepage sections visibility and ordering
            </div>

        </div>

    </div>

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

        <div class="alert alert-warning rounded-4">

            No homepage sections found.

        </div>

    <?php else: ?>

        <div class="row g-4">

            <?php foreach ($sections as $s): ?>

                <div class="col-xl-4 col-lg-6">

                    <div class="card border-0 shadow-lg rounded-4 h-100">

                        <div class="card-body p-4">

                            <div class="d-flex justify-content-between mb-3">

                                <div>

                                    <h4 class="fw-bold text-capitalize">

<?php
$lang =
    $_SESSION['lang']
    ?? 'en';

$title =
    $lang === 'ar'
        ? (
            $s['title_ar']
            ?: $s['section_title_ar']
            ?: $s['section_key']
        )
        : (
            $s['title_en']
            ?: $s['section_title_en']
            ?: $s['section_key']
        );
?>

<?= htmlspecialchars((string)$title) ?>                                        

                                    </h4>

                                    <div class="small text-muted">

                                        Theme:
                                        <?= htmlspecialchars(
                                            (string)(
                                                $s['theme_name']
                                                ?? ''
                                            )
                                        ) ?>

                                    </div>

                                </div>

                                <span class="badge bg-<?=
                                    !empty($s['enabled'])
                                        ? 'success'
                                        : 'secondary'
                                ?>">

                                    <?=
                                        !empty($s['enabled'])
                                            ? 'Enabled'
                                            : 'Disabled'
                                    ?>

                                </span>

                            </div>

                            <div class="small text-muted mb-4">

                                Sort Order:
                                <?= (int)(
                                    $s['sort_order']
                                    ?? 0
                                ) ?>

                            </div>

                            <div class="d-flex gap-2 flex-wrap">

                                <a
                                    href="/easychair/admin/conference-home-builder/toggle?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm <?= !empty($s['enabled'])
                                        ? 'btn-dark'
                                        : 'btn-success'
                                    ?> rounded-pill">

                                    <?= !empty($s['enabled'])
                                        ? 'Disable'
                                        : 'Enable'
                                    ?>

                                </a>

                                <a
                                    href="/easychair/admin/conference-home-builder/up?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm btn-outline-primary rounded-pill">

                                    ↑

                                </a>

                                <a
                                    href="/easychair/admin/conference-home-builder/down?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm btn-outline-primary rounded-pill">

                                    ↓

                                </a>

                            </div>

                        </div>

                    </div>

                </div>

            <?php endforeach; ?>

        </div>

    <?php endif; ?>

</div>
