<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Bootstrap dan session
|--------------------------------------------------------------------------
*/

$bootstrapFile = __DIR__ . '/bootstrap.php';

if (is_file($bootstrapFile)) {
    require_once $bootstrapFile;
}

if (session_status() === PHP_SESSION_NONE) {
    session_name('USERSESSID');
    session_start();
}

if (!function_exists('e')) {
    function e($value)
    {
        return htmlspecialchars(
            (string) $value,
            ENT_QUOTES,
            'UTF-8'
        );
    }
}

/*
|--------------------------------------------------------------------------
| Informasi halaman
|--------------------------------------------------------------------------
*/

$siteName = isset($siteName)
    ? (string) $siteName
    : 'Platform Online';

$pageTitle = 'Syarat & Ketentuan';
$activeMenu = 'promo';

$isLoggedIn = !empty($_SESSION['user_id']);

$username = isset($_SESSION['username'])
    ? (string) $_SESSION['username']
    : 'Pengunjung';

/*
|--------------------------------------------------------------------------
| Koneksi database PDO
|--------------------------------------------------------------------------
*/

$databaseFile = __DIR__ . '/config/database.php';

if (!isset($pdo) || !($pdo instanceof PDO)) {
    if (!is_file($databaseFile)) {
        http_response_code(500);

        exit(
            'File koneksi database tidak ditemukan: ' .
            e($databaseFile)
        );
    }

    require_once $databaseFile;
}

if (!isset($pdo) || !($pdo instanceof PDO)) {
    http_response_code(500);

    exit(
        'Koneksi PDO $pdo tidak tersedia dari config/database.php.'
    );
}

$pdo->setAttribute(
    PDO::ATTR_ERRMODE,
    PDO::ERRMODE_EXCEPTION
);

$pdo->setAttribute(
    PDO::ATTR_DEFAULT_FETCH_MODE,
    PDO::FETCH_ASSOC
);

/*
|--------------------------------------------------------------------------
| Helper
|--------------------------------------------------------------------------
*/

function termsFormatDate($value)
{
    if (empty($value)) {
        return '-';
    }

    $timestamp = strtotime((string) $value);

    if ($timestamp === false) {
        return '-';
    }

    $monthNames = [
        1 => 'Januari',
        2 => 'Februari',
        3 => 'Maret',
        4 => 'April',
        5 => 'Mei',
        6 => 'Juni',
        7 => 'Juli',
        8 => 'Agustus',
        9 => 'September',
        10 => 'Oktober',
        11 => 'November',
        12 => 'Desember',
    ];

    $day = date('j', $timestamp);
    $month = $monthNames[(int) date('n', $timestamp)];
    $year = date('Y', $timestamp);

    return $day . ' ' . $month . ' ' . $year;
}

function termsSafeSlug($value)
{
    $value = strtolower(trim((string) $value));

    if (
        $value === '' ||
        !preg_match('/^[a-z0-9][a-z0-9\-]{0,169}$/', $value)
    ) {
        return '';
    }

    return $value;
}

/*
|--------------------------------------------------------------------------
| Ambil promo berdasarkan slug
|--------------------------------------------------------------------------
*/

$promoSlug = termsSafeSlug(
    $_GET['promo'] ?? ''
);

$selectedPromo = null;
$pageError = '';

if ($promoSlug !== '') {
    try {
        $promoStatement = $pdo->prepare(
            'SELECT
                id,
                title,
                slug,
                category,
                badge_text,
                short_description,
                description,
                image_url,
                mobile_image_url,
                button_label,
                button_url,
                terms_url,
                requires_login,
                audience,
                is_featured,
                is_active,
                start_at,
                end_at,
                updated_at
             FROM promos
             WHERE slug = :slug
               AND is_active = 1
             LIMIT 1'
        );

        $promoStatement->execute([
            ':slug' => $promoSlug,
        ]);

        $selectedPromo = $promoStatement->fetch();

        if (!$selectedPromo) {
            $pageError =
                'Promo yang dipilih tidak ditemukan atau sudah tidak aktif.';
        }
    } catch (Throwable $exception) {
        error_log(
            'TERMS PROMO ERROR: ' .
            $exception->getMessage()
        );

        $pageError =
            'Detail promo belum dapat dimuat dari database.';
    }
}

/*
|--------------------------------------------------------------------------
| Ambil bagian syarat dan ketentuan
|--------------------------------------------------------------------------
*/

$termsSections = [];
$termsLastUpdated = null;

try {
    $scope = $selectedPromo
        ? 'PROMO'
        : 'GENERAL';

    $referenceSlug = $selectedPromo
        ? (string) $selectedPromo['slug']
        : null;

    $sectionStatement = $pdo->prepare(
        'SELECT
            id,
            scope,
            reference_slug,
            section_title,
            section_content,
            icon_text,
            is_open_default,
            sort_order,
            updated_at
         FROM terms_content
         WHERE is_active = 1
           AND (
                (
                    scope = :general_scope
                    AND reference_slug IS NULL
                )
                OR
                (
                    scope = :current_scope
                    AND reference_slug = :reference_slug
                )
           )
         ORDER BY
            CASE
                WHEN scope = :current_scope_order THEN 0
                ELSE 1
            END,
            sort_order ASC,
            id ASC'
    );

    $sectionStatement->execute([
        ':general_scope' => 'GENERAL',
        ':current_scope' => $scope,
        ':reference_slug' => $referenceSlug,
        ':current_scope_order' => $scope,
    ]);

    $termsSections = $sectionStatement->fetchAll();

    foreach ($termsSections as $section) {
        $updatedAt = $section['updated_at'] ?? null;

        if (
            $updatedAt !== null &&
            (
                $termsLastUpdated === null ||
                strtotime((string) $updatedAt) >
                    strtotime((string) $termsLastUpdated)
            )
        ) {
            $termsLastUpdated = $updatedAt;
        }
    }
} catch (Throwable $exception) {
    error_log(
        'TERMS CONTENT ERROR: ' .
        $exception->getMessage()
    );

    if ($pageError === '') {
        $pageError =
            'Isi syarat dan ketentuan belum dapat dimuat.';
    }
}

/*
|--------------------------------------------------------------------------
| Fallback jika tabel belum berisi data
|--------------------------------------------------------------------------
*/

if (empty($termsSections)) {
    $termsSections = [
        [
            'id' => 1,
            'section_title' => 'Ketentuan Umum',
            'section_content' =>
                "Dengan menggunakan layanan ini, pengguna dianggap telah membaca, memahami, dan menyetujui seluruh syarat yang berlaku.\n\nPengguna wajib memberikan data yang benar dan bertanggung jawab atas keamanan akun masing-masing.",
            'icon_text' => '◆',
            'is_open_default' => 1,
        ],
        [
            'id' => 2,
            'section_title' => 'Akun dan Keamanan',
            'section_content' =>
                "Satu pengguna hanya diperbolehkan memiliki akun sesuai kebijakan website.\n\nPassword, kode verifikasi, dan informasi akun tidak boleh dibagikan kepada pihak lain.",
            'icon_text' => '✓',
            'is_open_default' => 0,
        ],
        [
            'id' => 3,
            'section_title' => 'Promo dan Bonus',
            'section_content' =>
                "Setiap promo dapat memiliki syarat, periode, batas minimum, batas maksimum, serta ketentuan penggunaan yang berbeda.\n\nBonus dapat dibatalkan apabila ditemukan pelanggaran, penyalahgunaan, data tidak sesuai, atau aktivitas yang tidak wajar.",
            'icon_text' => '★',
            'is_open_default' => 0,
        ],
        [
            'id' => 4,
            'section_title' => 'Perubahan Ketentuan',
            'section_content' =>
                "Website berhak memperbarui syarat dan ketentuan sewaktu-waktu. Perubahan akan berlaku sejak dipublikasikan pada halaman ini.",
            'icon_text' => '!',
            'is_open_default' => 0,
        ],
    ];

    $termsLastUpdated = date('Y-m-d H:i:s');
}

/*
|--------------------------------------------------------------------------
| Judul dinamis
|--------------------------------------------------------------------------
*/

$displayTitle = $selectedPromo
    ? 'Syarat Promo'
    : 'Syarat & Ketentuan';

$displaySubtitle = $selectedPromo
    ? (string) $selectedPromo['title']
    : 'Ketentuan penggunaan layanan dan program promosi';

/*
|--------------------------------------------------------------------------
| Header
|--------------------------------------------------------------------------
*/

require __DIR__ . '/includes/header.php';

?>

<style>
/*
|--------------------------------------------------------------------------
| Halaman terms casino
|--------------------------------------------------------------------------
*/

.terms-page {
    position: relative;

    width: 100%;
    min-height: calc(100vh - 70px);

    padding: 12px 9px 28px;

    overflow: hidden;

    background:
        radial-gradient(
            circle at 50% -6%,
            rgba(0, 139, 255, 0.27),
            transparent 285px
        ),
        radial-gradient(
            circle at 108% 43%,
            rgba(255, 179, 0, 0.11),
            transparent 190px
        ),
        linear-gradient(
            180deg,
            #031431 0%,
            #020a1c 55%,
            #010610 100%
        );
}

.terms-page::before,
.terms-page::after {
    position: absolute;

    width: 190px;
    height: 190px;

    content: "";

    border-radius: 50%;

    filter: blur(38px);

    pointer-events: none;
}

.terms-page::before {
    top: 130px;
    left: -160px;

    background:
        rgba(0, 126, 255, 0.20);
}

.terms-page::after {
    right: -165px;
    bottom: 175px;

    background:
        rgba(255, 178, 0, 0.12);
}

.terms-shell {
    position: relative;
    z-index: 2;

    width: 100%;
    max-width: 540px;

    margin: 0 auto;
}

/*
|--------------------------------------------------------------------------
| Breadcrumb
|--------------------------------------------------------------------------
*/

.terms-breadcrumb {
    display: flex;

    align-items: center;

    margin-bottom: 9px;

    gap: 5px;

    color: #758ba7;

    font-size: 7px;
}

.terms-breadcrumb a {
    color: #8fd5ff;

    text-decoration: none;
}

.terms-breadcrumb span {
    color: #ffc943;
}

/*
|--------------------------------------------------------------------------
| Header halaman
|--------------------------------------------------------------------------
*/

.terms-heading {
    display: grid;

    justify-items: center;

    margin-bottom: 11px;

    text-align: center;
}

.terms-crown {
    margin-bottom: -4px;

    color: #ffd451;

    font-size: 29px;
    line-height: 1;

    text-shadow:
        0 1px 0 #fff5ac,
        0 3px 0 #713600,
        0 0 10px rgba(255, 194, 39, 0.65);
}

.terms-heading h1 {
    margin: 0;

    color: #ffd450;

    background:
        linear-gradient(
            180deg,
            #fff9ba 0%,
            #ffd451 36%,
            #e58b00 72%,
            #fff09a 100%
        );

    background-clip: text;
    -webkit-background-clip: text;

    font-size: clamp(24px, 7vw, 34px);
    font-weight: 1000;

    letter-spacing: -0.035em;

    -webkit-text-fill-color: transparent;

    filter:
        drop-shadow(0 2px 0 #713600)
        drop-shadow(0 5px 6px rgba(0, 0, 0, 0.72));
}

.terms-heading p {
    max-width: 430px;

    margin: 6px 0 0;

    color: #96aac5;

    font-size: 9px;
    line-height: 1.5;
}

.terms-state {
    display: inline-flex;

    min-height: 24px;

    align-items: center;

    margin-top: 8px;
    padding: 0 9px;

    gap: 5px;

    border:
        1px solid rgba(70, 222, 150, 0.25);

    border-radius: 999px;

    color: #a9dec4;

    background:
        rgba(4, 48, 32, 0.56);

    font-size: 7px;
    font-weight: 850;
}

.terms-state i {
    width: 5px;
    height: 5px;

    border-radius: 50%;

    background: #50e39a;

    box-shadow:
        0 0 6px rgba(80, 227, 154, 0.70);
}

/*
|--------------------------------------------------------------------------
| Promo hero
|--------------------------------------------------------------------------
*/

.terms-promo-card {
    position: relative;

    margin-bottom: 10px;

    overflow: hidden;

    border:
        1px solid rgba(255, 198, 48, 0.42);

    border-radius: 15px;

    background: #06142c;

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 8px 22px rgba(0, 0, 0, 0.34);
}

.terms-promo-image {
    display: block;

    width: 100%;
    aspect-ratio: 16 / 7.6;

    object-fit: cover;
}

.terms-promo-overlay {
    position: absolute;

    inset: 0;

    display: flex;

    align-items: flex-end;

    padding: 12px;

    background:
        linear-gradient(
            180deg,
            transparent 25%,
            rgba(1, 7, 18, 0.40) 52%,
            rgba(1, 7, 18, 0.97) 100%
        );
}

.terms-promo-copy {
    width: 100%;
}

.terms-promo-badge {
    display: inline-flex;

    min-height: 21px;

    align-items: center;

    padding: 0 8px;

    border:
        1px solid rgba(255, 236, 157, 0.72);

    border-radius: 999px;

    color: #341c00;

    background:
        linear-gradient(
            180deg,
            #fff29b,
            #ffc62e
        );

    font-size: 7px;
    font-weight: 1000;
}

.terms-promo-copy h2 {
    margin: 7px 0 0;

    color: #ffffff;

    font-size: 19px;
    font-weight: 1000;

    line-height: 1.1;

    text-shadow:
        0 2px 2px rgba(0, 0, 0, 0.90);
}

.terms-promo-copy p {
    margin: 5px 0 0;

    color: #d3deeb;

    font-size: 8px;
    line-height: 1.45;
}

/*
|--------------------------------------------------------------------------
| Ringkasan
|--------------------------------------------------------------------------
*/

.terms-summary {
    display: grid;

    margin-bottom: 10px;
    padding: 10px;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 6px;

    border:
        1px solid rgba(0, 159, 255, 0.27);

    border-radius: 12px;

    background:
        linear-gradient(
            180deg,
            rgba(8, 37, 78, 0.95),
            rgba(2, 16, 38, 0.98)
        );

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 5px 14px rgba(0, 0, 0, 0.25);
}

.terms-summary-item {
    display: grid;

    min-width: 0;
    min-height: 48px;

    align-content: center;
    justify-items: center;

    padding: 5px;

    border:
        1px solid rgba(255, 255, 255, 0.06);

    border-radius: 9px;

    background:
        rgba(0, 0, 0, 0.14);

    text-align: center;
}

.terms-summary-item small {
    color: #7890ad;

    font-size: 6px;
}

.terms-summary-item strong {
    margin-top: 2px;

    overflow: hidden;

    max-width: 100%;

    color: #ffffff;

    font-size: 7px;
    font-weight: 1000;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.terms-summary-item strong.is-gold {
    color: #ffd34e;
}

/*
|--------------------------------------------------------------------------
| Notice
|--------------------------------------------------------------------------
*/

.terms-notice {
    display: grid;

    margin-bottom: 10px;
    padding: 10px;

    grid-template-columns:
        31px
        minmax(0, 1fr);

    align-items: center;

    gap: 8px;

    border:
        1px solid rgba(255, 193, 42, 0.26);

    border-radius: 11px;

    background:
        linear-gradient(
            90deg,
            rgba(92, 51, 3, 0.33),
            rgba(4, 22, 48, 0.91)
        );
}

.terms-notice-icon {
    display: grid;

    width: 31px;
    height: 31px;

    place-items: center;

    border:
        1px solid #ffd04b;

    border-radius: 50%;

    color: #ffd04b;

    background: #281700;

    font-size: 13px;
    font-weight: 1000;
}

.terms-notice strong {
    display: block;

    color: #ffffff;

    font-size: 8px;
}

.terms-notice p {
    margin: 3px 0 0;

    color: #9eb1c8;

    font-size: 7px;
    line-height: 1.5;
}

/*
|--------------------------------------------------------------------------
| Accordion terms
|--------------------------------------------------------------------------
*/

.terms-section-heading {
    display: flex;

    align-items: center;
    justify-content: space-between;

    margin:
        12px
        1px
        7px;
}

.terms-section-heading h2 {
    margin: 0;

    color: #ffffff;

    font-size: 12px;
}

.terms-section-heading small {
    color: #758ba7;

    font-size: 7px;
}

.terms-accordion {
    display: grid;

    gap: 7px;
}

.terms-item {
    overflow: hidden;

    border:
        1px solid rgba(0, 159, 255, 0.24);

    border-radius: 12px;

    background:
        linear-gradient(
            180deg,
            rgba(8, 34, 72, 0.97),
            rgba(2, 14, 33, 0.99)
        );

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 4px 11px rgba(0, 0, 0, 0.23);
}

.terms-item[open] {
    border-color:
        rgba(255, 197, 42, 0.44);

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 6px 14px rgba(0, 0, 0, 0.30),
        0 0 9px rgba(255, 185, 23, 0.10);
}

.terms-item summary {
    display: grid;

    min-height: 49px;

    grid-template-columns:
        31px
        minmax(0, 1fr)
        25px;

    align-items: center;

    padding: 7px 9px;

    gap: 8px;

    color: #ffffff;

    cursor: pointer;
    list-style: none;
}

.terms-item summary::-webkit-details-marker {
    display: none;
}

.terms-item-icon {
    display: grid;

    width: 31px;
    height: 31px;

    place-items: center;

    border:
        1px solid rgba(255, 206, 72, 0.44);

    border-radius: 9px;

    color: #ffd24c;

    background:
        linear-gradient(
            180deg,
            rgba(255, 198, 40, 0.13),
            rgba(105, 53, 0, 0.08)
        );

    font-size: 12px;
    font-weight: 1000;
}

.terms-item-title {
    overflow: hidden;

    color: #ffffff;

    font-size: 10px;
    font-weight: 1000;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.terms-item-arrow {
    display: grid;

    width: 25px;
    height: 25px;

    place-items: center;

    border-radius: 8px;

    color: #8fd5ff;
    background: rgba(255, 255, 255, 0.05);

    font-size: 17px;

    transition:
        transform 160ms ease;
}

.terms-item[open] .terms-item-arrow {
    color: #ffd24c;

    transform: rotate(90deg);
}

.terms-item-content {
    padding:
        0
        12px
        13px
        52px;

    border-top:
        1px solid rgba(255, 255, 255, 0.05);

    color: #a9bad0;

    font-size: 8px;
    line-height: 1.7;

    white-space: pre-line;
}

/*
|--------------------------------------------------------------------------
| Error
|--------------------------------------------------------------------------
*/

.terms-error {
    margin-bottom: 10px;
    padding: 9px 10px;

    border:
        1px solid rgba(255, 77, 77, 0.38);

    border-radius: 10px;

    color: #ffd6d6;
    background:
        rgba(102, 12, 17, 0.48);

    font-size: 8px;
    line-height: 1.45;
}

/*
|--------------------------------------------------------------------------
| Action
|--------------------------------------------------------------------------
*/

.terms-actions {
    display: grid;

    margin-top: 12px;

    grid-template-columns:
        repeat(2, minmax(0, 1fr));

    gap: 7px;
}

.terms-button {
    display: flex;

    min-height: 40px;

    align-items: center;
    justify-content: center;

    padding: 0 10px;

    border:
        1px solid rgba(0, 166, 255, 0.40);

    border-radius: 9px;

    color: #ffffff;

    background:
        linear-gradient(
            180deg,
            rgba(11, 63, 117, 0.92),
            rgba(3, 26, 59, 0.98)
        );

    font-size: 8px;
    font-weight: 1000;

    text-decoration: none;

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 4px 10px rgba(0, 0, 0, 0.25);
}

.terms-button--gold {
    border-color: #ffe17f;

    color: #301700;

    background:
        linear-gradient(
            180deg,
            #fff08c,
            #ffc32d 50%,
            #d87700
        );

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.62),
        0 3px 0 #572900,
        0 0 8px rgba(255, 183, 20, 0.28);
}

.terms-footer-note {
    margin: 12px 0 0;

    color: #627894;

    font-size: 7px;
    line-height: 1.5;

    text-align: center;
}

@media (max-width: 390px) {
    .terms-page {
        padding-right: 7px;
        padding-left: 7px;
    }

    .terms-item-content {
        padding-left: 49px;
    }
}

@media (max-width: 340px) {
    .terms-summary {
        grid-template-columns: 1fr;
    }

    .terms-actions {
        grid-template-columns: 1fr;
    }
}
</style>

<section class="terms-page">
    <div class="terms-shell">

        <nav
            class="terms-breadcrumb"
            aria-label="Breadcrumb"
        >
            <a href="index.php">
                Home
            </a>

            <span>›</span>

            <a href="promo.php">
                Promo
            </a>

            <span>›</span>

            <strong>
                Syarat
            </strong>
        </nav>

        <header class="terms-heading">
            <span
                class="terms-crown"
                aria-hidden="true"
            >
                ♛
            </span>

            <h1>
                <?= e($displayTitle); ?>
            </h1>

            <p>
                <?= e($displaySubtitle); ?>
            </p>

            <span class="terms-state">
                <i></i>

                <?php if ($isLoggedIn): ?>
                    Dibuka sebagai <?= e($username); ?>
                <?php else: ?>
                    Dapat dibaca tanpa login
                <?php endif; ?>
            </span>
        </header>

        <?php if ($pageError !== ''): ?>

            <div class="terms-error">
                <?= e($pageError); ?>
            </div>

        <?php endif; ?>

        <?php if ($selectedPromo): ?>

            <article class="terms-promo-card">

                <picture>
                    <?php if (
                        !empty($selectedPromo['mobile_image_url'])
                    ): ?>
                        <source
                            media="(max-width: 480px)"
                            srcset="<?= e($selectedPromo['mobile_image_url']); ?>"
                        >
                    <?php endif; ?>

                    <img
                        class="terms-promo-image"
                        src="<?= e($selectedPromo['image_url']); ?>"
                        alt="<?= e($selectedPromo['title']); ?>"
                        onerror="
                            this.onerror = null;
                            this.src =
                                'assets/images/promo/promo-default.svg';
                        "
                    >
                </picture>

                <div class="terms-promo-overlay">
                    <div class="terms-promo-copy">

                        <span class="terms-promo-badge">
                            <?= e($selectedPromo['badge_text']); ?>
                        </span>

                        <h2>
                            <?= e($selectedPromo['title']); ?>
                        </h2>

                        <p>
                            <?= e($selectedPromo['short_description']); ?>
                        </p>

                    </div>
                </div>

            </article>

        <?php endif; ?>

        <section class="terms-summary">

            <div class="terms-summary-item">
                <small>
                    Status akses
                </small>

                <strong>
                    <?= $isLoggedIn
                        ? 'MEMBER'
                        : 'PENGUNJUNG'; ?>
                </strong>
            </div>

            <div class="terms-summary-item">
                <small>
                    Jenis ketentuan
                </small>

                <strong class="is-gold">
                    <?= $selectedPromo
                        ? 'PROMO'
                        : 'UMUM'; ?>
                </strong>
            </div>

            <div class="terms-summary-item">
                <small>
                    Diperbarui
                </small>

                <strong>
                    <?= e(
                        termsFormatDate(
                            $termsLastUpdated
                        )
                    ); ?>
                </strong>
            </div>

        </section>

        <section class="terms-notice">

            <span class="terms-notice-icon">
                !
            </span>

            <div>
                <strong>
                    Bacalah seluruh ketentuan sebelum menggunakan layanan
                </strong>

                <p>
                    Penggunaan akun, transaksi, bonus, dan program
                    promosi dianggap sebagai persetujuan terhadap
                    ketentuan yang berlaku.
                </p>
            </div>

        </section>

        <div class="terms-section-heading">
            <h2>
                Rincian Ketentuan
            </h2>

            <small>
                <?= count($termsSections); ?> bagian
            </small>
        </div>

        <section class="terms-accordion">

            <?php foreach ($termsSections as $index => $section): ?>

                <details
                    class="terms-item"
                    <?= !empty($section['is_open_default']) ||
                        $index === 0
                        ? 'open'
                        : ''; ?>
                >
                    <summary>

                        <span class="terms-item-icon">
                            <?= e(
                                $section['icon_text'] ??
                                '◆'
                            ); ?>
                        </span>

                        <span class="terms-item-title">
                            <?= e(
                                $section['section_title'] ??
                                'Ketentuan'
                            ); ?>
                        </span>

                        <span class="terms-item-arrow">
                            ›
                        </span>

                    </summary>

                    <div class="terms-item-content"><?= e(
                        $section['section_content'] ??
                        ''
                    ); ?></div>

                </details>

            <?php endforeach; ?>

        </section>

        <div class="terms-actions">

            <a
                class="terms-button"
                href="promo.php"
            >
                KEMBALI KE PROMO
            </a>

            <?php if ($isLoggedIn): ?>

                <a
                    class="terms-button terms-button--gold"
                    href="account.php"
                >
                    BUKA AKUN
                </a>

            <?php else: ?>

                <a
                    class="terms-button terms-button--gold"
                    href="register.php"
                >
                    DAFTAR SEKARANG
                </a>

            <?php endif; ?>

        </div>

        <p class="terms-footer-note">
            Ketentuan dapat diperbarui sewaktu-waktu.
            Versi terbaru selalu ditampilkan pada halaman ini.
        </p>

    </div>
</section>

<?php require __DIR__ . '/includes/footer.php'; ?>
