<?php
$title = 'Homepage Sections CMS';

$currentRole =
    strtolower(
        $_SESSION['role_code']
        ??
        $_SESSION['role']
        ??
        ''
    );

$isSuperAdmin =
    $currentRole === 'super_admin';

$isConferenceChair =
    $currentRole === 'conference_chair';

$isTrackChair =
    $currentRole === 'track_chair';

$showTechnicalCards =
    $isSuperAdmin;

$showGovernanceCards =
    $isSuperAdmin
    ||
    $isConferenceChair;

$showOperationalCards =
    true;

$sections = $sections ?? [];

/*
|--------------------------------------------------------------------------
| Homepage Studio Dashboard Data
|--------------------------------------------------------------------------
| View-only analytics. No DB changes. No controller changes.
*/

$totalSections = count($sections);

$enabledSections = count(
    array_filter(
        $sections,
        fn($s) => !empty($s['enabled'])
    )
);

$disabledSections = $totalSections - $enabledSections;

$registry = [];

$registryPath =
    BASE_PATH .
    '/app/views/partials/_section_registry.php';

if (file_exists($registryPath)) {
    $registry = require $registryPath;
}

$installed =
    array_column(
        $sections,
        'section_key'
    );

$coreSections = [
    'hero',
    'about',
    'members',
    'speakers',
    'sponsors',
    'program',
    'venue',
    'proceedings',
    'cta'
];

$coreInstalled = 0;

foreach ($coreSections as $coreKey) {
    if (in_array($coreKey, $installed, true)) {
        $coreInstalled++;
    }
}

$homepageScore =
    count($coreSections) > 0
        ? round(($coreInstalled / count($coreSections)) * 100)
        : 0;

$quickSections = [
    'hero'        => '🚀 Hero',
    'about'       => 'ℹ️ About',
    'speakers'    => '🎤 Speakers',
    'members'     => '👥 Committees',
    'sponsors'    => '🤝 Sponsors',
    'venue'       => '📍 Venue',
    'program'     => '📅 Program',
    'proceedings' => '📚 Proceedings',
    'cta'         => '📢 Contact'
];

$themeStats = [];
?>


<?php

$totalSections =
    count($sections ?? []);

$enabledSections = 0;
$disabledSections = 0;
$favoriteSections = 0;

$coreCount = 0;
$conferenceCount = 0;
$mediaCount = 0;
$aiCount = 0;
$customCount = 0;

foreach (($sections ?? []) as $s)
{
    if (!empty($s['enabled'])) {
        $enabledSections++;
    } else {
        $disabledSections++;
    }

    $cfg =
        json_decode(
            $s['settings_json']
            ?? '{}',
            true
        );

    if (!empty($cfg['favorite'])) {
        $favoriteSections++;
    }

    $cat =
        ecSectionCategory(
            (string)(
                $s['section_key']
                ?? ''
            )
        );

    switch ($cat)
    {
        case 'core':
            $coreCount++;
            break;

        case 'conference':
            $conferenceCount++;
            break;

        case 'media':
            $mediaCount++;
            break;

        case 'ai':
            $aiCount++;
            break;

        default:
            $customCount++;
    }
}

?>

<?php

$riskWarnings = [];

$missingArabicTitle = 0;
$missingEnglishTitle = 0;
$disabledCount = 0;

foreach (($sections ?? []) as $s)
{
    if (empty($s['enabled'])) {
        $disabledCount++;
    }

    if (
        empty($s['title_ar'])
        &&
        empty($s['section_title_ar'])
    ) {
        $missingArabicTitle++;
    }

    if (
        empty($s['title_en'])
        &&
        empty($s['section_title_en'])
    ) {
        $missingEnglishTitle++;
    }
}

if (!in_array('hero', $installed, true))
{
    $riskWarnings[] =
        'Hero section missing';
}

if (!in_array('cta', $installed, true))
{
    $riskWarnings[] =
        'CTA section missing';
}

if (!in_array('sponsors', $installed, true))
{
    $riskWarnings[] =
        'Sponsors section missing';
}

if ($missingArabicTitle > 0)
{
    $riskWarnings[] =
        $missingArabicTitle .
        ' sections missing Arabic title';
}

if ($missingEnglishTitle > 0)
{
    $riskWarnings[] =
        $missingEnglishTitle .
        ' sections missing English title';
}

if ($disabledCount > 5)
{
    $riskWarnings[] =
        $disabledCount .
        ' sections disabled';
}

$riskScore =
    count($riskWarnings);

$riskLevel =
    'LOW';

$riskClass =
    'success';

if ($riskScore >= 3)
{
    $riskLevel =
        'MEDIUM';

    $riskClass =
        'warning';
}

if ($riskScore >= 6)
{
    $riskLevel =
        'HIGH';

    $riskClass =
        'danger';
}

?>

<?php

function ecSectionCategory(
    string $key
): string
{
    $key =
        strtolower($key);

    $map = [

        'hero'        => 'core',
        'about'       => 'core',
        'members'     => 'conference',
        'speakers'    => 'conference',
        'venue'       => 'conference',
        'program'     => 'conference',
        'proceedings' => 'conference',
        'sponsors'    => 'conference',

        'media'       => 'media',

        'ai_assistant' => 'ai',
        'ai_research'  => 'ai',
        'ai_analytics' => 'ai',

    ];

    return
        $map[$key]
        ?? 'custom';
}
?>

<?php
foreach ($sections as $s) {
    $theme =
        trim(
            (string)(
                $s['theme_name']
                ?? 'default'
            )
        );

    if ($theme === '') {
        $theme = 'default';
    }

    $themeStats[$theme] =
        ($themeStats[$theme] ?? 0) + 1;
}

arsort($themeStats);

$maxThemeCount =
    max($themeStats ?: [1]);

$recommended = [
    'hero',
    'about',
    'members',
    'speakers',
    'sponsors',
    'venue',
    'program',
    'proceedings',
    'cta'
];

$missingRecommended = [];

foreach ($recommended as $r) {
    if (!in_array($r, $installed, true)) {
        $missingRecommended[] = $r;
    }
}
?>

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

<div
class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-3">

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

Homepage Command Center

</h4>

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

<a
href="#compliance-monitor"
class="btn btn-outline-primary rounded-pill">

Compliance

</a>

<a
href="#publish-center"
class="btn btn-outline-primary rounded-pill">

Publish

</a>

<a
href="#seo-analyzer"
class="btn btn-outline-primary rounded-pill">

SEO

</a>

<a
href="#performance-analyzer"
class="btn btn-outline-primary rounded-pill">

Performance

</a>

<a
href="#timeline"
class="btn btn-outline-primary rounded-pill">

Timeline

</a>

<a
href="#gallery"
class="btn btn-outline-primary rounded-pill">

Gallery

</a>

</div>

</div>

</div>

<div
class="alert alert-primary rounded-4 mb-4">

<strong>

Dashboard Mode:

</strong>

<?= htmlspecialchars(
ucwords(
str_replace(
'_',
' ',
$currentRole
)
)
) ?>

</div>

<?php

$db =
    \App\Core\Database::getInstance();

$snapshotCount = 0;

try {

    $stmt =
        $db->prepare("
            SELECT COUNT(*)
            FROM conference_home_templates
            WHERE org_id = ?
        ");

    $stmt->execute([
        (int)($_SESSION['org_id'] ?? 0)
    ]);

    $snapshotCount =
        (int)$stmt->fetchColumn();

} catch (\Throwable $e) {

    $snapshotCount = 0;
}

?>

<div
class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4 class="fw-bold">

<i class="fa fa-camera-retro text-primary"></i>

Homepage Snapshot Manager

</h4>

<div class="text-muted">

Versioned homepage recovery

</div>

</div>

<div>

<span
class="badge bg-primary fs-6">

<?= (int)$snapshotCount ?>

Snapshots

</span>

</div>

</div>

<hr>

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

<a
href="/easychair/admin/conference-home/template/save"
class="btn btn-success rounded-pill">

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

Create Snapshot

</a>

<a
href="/easychair/admin/conference-home/marketplace"
class="btn btn-outline-primary rounded-pill">

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

View Snapshots

</a>

</div>

</div>

</div>

<div id="pageTop"></div>

<?php
/*
|--------------------------------------------------------------------------
| PACK 1071 SAFETY DEFAULTS
|--------------------------------------------------------------------------
| Prevent undefined variable warnings when dashboard cards appear before
| their analytics engines.
*/

$snapshotCount =
    $snapshotCount
    ?? 0;

$englishCoverage =
    $englishCoverage
    ?? 0;

$arabicCoverage =
    $arabicCoverage
    ?? 0;

$accessibilityScore =
    $accessibilityScore
    ?? 0;

$seoScore =
    $seoScore
    ?? 0;

$performanceScore =
    $performanceScore
    ?? 0;

$readinessOverall =
    $readinessOverall
    ?? 0;
?>

<style>
.ec-studio-hero{
    background:linear-gradient(135deg,#020617,#1e3a8a,#2563eb);
    color:#fff;
    border-radius:30px;
    padding:28px;
    box-shadow:0 24px 70px rgba(15,23,42,.18);
    margin-bottom:24px;
}

.ec-studio-quick{
    background:#fff;
    border-radius:24px;
    padding:18px;
    box-shadow:0 12px 35px rgba(15,23,42,.08);
}

.ec-studio-kpi{
    transition:.24s ease;
}

.ec-studio-kpi:hover{
    transform:translateY(-5px);
}

.ec-section-preview{
    height:110px;
    border-radius:20px;
    box-shadow:inset 0 0 0 999px rgba(15,23,42,.18);
    background-size:cover;
    background-position:center;
}

.ec-section-card{
    transition:.24s ease;
}

.ec-section-card:hover{
    transform:translateY(-7px);
    box-shadow:0 24px 60px rgba(15,23,42,.14) !important;
}

.ec-theme-row{
    border:1px solid #e5e7eb;
    border-radius:18px;
    padding:14px;
    background:#fff;
}

.ec-theme-name{
    min-width:180px;
    word-break:normal;
    white-space:normal;
}

.ec-validator-badge{
    display:block;
    width:100%;
    text-align:start;
    padding:9px 12px;
    border-radius:999px;
}

.timeline-list{
max-height:420px;
overflow:auto;
padding-right:6px;
}

.timeline-list::-webkit-scrollbar{
width:8px;
}

.timeline-list::-webkit-scrollbar-thumb{
background:#cbd5e1;
border-radius:999px;

}

.homepage-top-btn{

position:fixed;

right:25px;

bottom:25px;

width:58px;

height:58px;

border-radius:50%;

display:flex;

align-items:center;

justify-content:center;

font-size:22px;

background:#2563eb;

color:#fff;

text-decoration:none;

box-shadow:
0 15px 35px rgba(37,99,235,.35);

z-index:9999;

transition:.25s;
}

.homepage-top-btn:hover{

transform:translateY(-4px);

color:#fff;

background:#1d4ed8;
}

</style>

<div class="ec-studio-hero">

    <div class="d-flex justify-content-between align-items-start flex-wrap gap-3">

        <div>

            <h2 class="fw-bold mb-1">
                <i class="fa fa-layer-group me-2"></i>
                Homepage Sections CMS
            </h2>

            <div class="opacity-75">
                Full enterprise governance for homepage sections
            </div>

        </div>

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

            <a
                href="/easychair/admin/conference-home/sections/create"
                class="btn btn-light rounded-pill px-4 fw-bold">

                <i class="fa fa-plus"></i>
                Add Section

            </a>

            <a
                href="/easychair/admin/conference-home/studio"
                class="btn btn-outline-light rounded-pill px-4 fw-bold">

                <i class="fa fa-wand-magic-sparkles"></i>
                Studio

            </a>

        </div>

    </div>

</div>

<div class="ec-studio-quick mb-4">

    <div class="d-flex justify-content-between align-items-center flex-wrap gap-3">

        <div>

            <h5 class="fw-bold mb-1">
                <i class="fa fa-magic text-primary"></i>
                Quick Install Section
            </h5>

            <div class="text-muted small">
                Install common conference homepage sections in one click.
            </div>

        </div>

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

            <?php foreach ($quickSections as $k => $label): ?>

                <a
                    href="/easychair/admin/conference-home/sections/install?type=<?= urlencode($k) ?>"
                    class="btn btn-outline-primary rounded-pill">

                    <?= htmlspecialchars($label) ?>

                </a>

            <?php endforeach; ?>

        </div>

    </div>

</div>

<div class="row g-3 mb-4">

    <div class="col-lg-3 col-md-6">
        <div class="card border-0 shadow-sm rounded-4 h-100 ec-studio-kpi">
            <div class="card-body text-center">
                <i class="fa fa-layer-group fa-2x text-primary mb-2"></i>
                <h3 class="fw-bold"><?= (int)$totalSections ?></h3>
                <div class="text-muted">Total Sections</div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-md-6">
        <div class="card border-0 shadow-sm rounded-4 h-100 ec-studio-kpi">
            <div class="card-body text-center">
                <i class="fa fa-check-circle fa-2x text-success mb-2"></i>
                <h3 class="fw-bold"><?= (int)$enabledSections ?></h3>
                <div class="text-muted">Enabled</div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-md-6">
        <div class="card border-0 shadow-sm rounded-4 h-100 ec-studio-kpi">
            <div class="card-body text-center">
                <i class="fa fa-eye-slash fa-2x text-danger mb-2"></i>
                <h3 class="fw-bold"><?= (int)$disabledSections ?></h3>
                <div class="text-muted">Disabled</div>
            </div>
        </div>
    </div>

    <div class="col-lg-3 col-md-6">
        <div class="card border-0 shadow-sm rounded-4 h-100 ec-studio-kpi">
            <div class="card-body text-center">
                <i class="fa fa-gauge-high fa-2x text-warning mb-2"></i>
                <h3 class="fw-bold"><?= (int)$homepageScore ?>%</h3>
                <div class="text-muted">Homepage Score</div>
            </div>
        </div>
    </div>

</div>

<div class="row g-4 mb-4">

    <div class="col-xl-8">

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

            <div class="card-body">

                <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">

                    <div>

                        <h5 class="fw-bold mb-1">
                            <i class="fa fa-shield-halved text-primary"></i>
                            Homepage Validator
                        </h5>

                        <div class="text-muted small">
                            Checks which registered homepage sections are already installed for this conference.
                        </div>

                    </div>

                    <span class="badge bg-primary rounded-pill px-3 py-2">
                        <?= (int)$coreInstalled ?> / <?= count($coreSections) ?> core sections
                    </span>

                </div>

                <div class="row g-2">

                    <?php foreach ($registry as $key => $file): ?>

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

                            <?php if (in_array($key, $installed, true)): ?>

                                <span class="badge bg-success ec-validator-badge">
                                    ✓ <?= htmlspecialchars((string)$key) ?>
                                </span>

                            <?php else: ?>

                                <a
                                    href="/easychair/admin/conference-home/sections/install?type=<?= urlencode((string)$key) ?>"
                                    class="badge bg-light text-dark border ec-validator-badge text-decoration-none">
                                    + <?= htmlspecialchars((string)$key) ?>
                                </a>

                            <?php endif; ?>

                        </div>

                    <?php endforeach; ?>

                </div>

            </div>

        </div>

    </div>

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

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

            <div class="card-body">

                <h5 class="fw-bold mb-3">
                    <i class="fa fa-circle-exclamation text-warning"></i>
                    Missing Recommended Sections
                </h5>

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

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

                        <?php foreach($missingRecommended as $r): ?>

                            <a
                                href="/easychair/admin/conference-home/sections/install?type=<?= urlencode($r) ?>"
                                class="btn btn-outline-danger rounded-pill">

                                + <?= htmlspecialchars($r) ?>

                            </a>

                        <?php endforeach; ?>

                    </div>

                <?php else: ?>

                    <div class="alert alert-success rounded-4 mb-0">
                        <i class="fa fa-check-circle"></i>
                        All recommended sections are installed.
                    </div>

                <?php endif; ?>

            </div>

        </div>

    </div>

</div>

<?php

$warnings = [];

if (!in_array('hero', $installed, true))
{
    $warnings[] =
        'Hero section missing';
}

if (!in_array('cta', $installed, true))
{
    $warnings[] =
        'CTA section missing';
}

if (!in_array('sponsors', $installed, true))
{
    $warnings[] =
        'Sponsors section missing';
}

if (!in_array('venue', $installed, true))
{
    $warnings[] =
        'Venue section missing';
}

?>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h5 class="fw-bold">

<i class="fa fa-triangle-exclamation text-warning"></i>

Section Dependency Analyzer

</h5>

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

<?php foreach($warnings as $w): ?>

<div
class="alert alert-warning mt-3 mb-0">

<?= htmlspecialchars($w) ?>

</div>

<?php endforeach; ?>

<?php else: ?>

<div
class="alert alert-success mt-3 mb-0">

All core homepage dependencies satisfied.

</div>

<?php endif; ?>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

    <div class="card-body">

        <h5 class="fw-bold mb-4">
            <i class="fa fa-palette text-primary"></i>
            Theme Distribution
        </h5>

        <?php foreach($themeStats as $theme=>$cnt): ?>

            <?php
            $themeWidth =
                max(
                    8,
                    round(
                        ($cnt / $maxThemeCount) * 100
                    )
                );
            ?>

            <div class="ec-theme-row mb-3">

                <div class="d-flex justify-content-between align-items-center flex-wrap gap-2">

                    <div class="fw-bold ec-theme-name">
                        <?= htmlspecialchars($theme) ?>
                    </div>

                    <div class="badge bg-primary rounded-pill px-3">
                        <?= (int)$cnt ?> Sections
                    </div>

                </div>

                <div class="progress mt-3" style="height:10px;">

                    <div
                        class="progress-bar bg-primary"
                        style="width:<?= (int)$themeWidth ?>%">
                    </div>

                </div>

            </div>

        <?php endforeach; ?>

    </div>

</div>

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

<button
class="btn btn-outline-primary category-filter"
data-category="all">

All

</button>

<button
class="btn btn-outline-primary category-filter"
data-category="core">

Core

</button>

<button
class="btn btn-outline-primary category-filter"
data-category="conference">

Conference

</button>

<button
class="btn btn-outline-primary category-filter"
data-category="media">

Media

</button>

<button
class="btn btn-outline-primary category-filter"
data-category="ai">

AI

</button>

<button
class="btn btn-outline-primary category-filter"
data-category="custom">

Custom

</button>

<?php

try {

    $snapshots =
        $db
        ->query("

            SELECT

            id,
            name,
            created_at

            FROM conference_home_templates

            ORDER BY id DESC

            LIMIT 5

        ")
        ->fetchAll(
            PDO::FETCH_ASSOC
        );

} catch(\Throwable $e) {

    $snapshots = [];

}

?>

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

<hr>

<div class="row g-2">

<?php foreach($snapshots as $snap): ?>

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

<div
class="border rounded-4 p-3">

<div class="fw-bold">

<?= htmlspecialchars(
$snap['name']
) ?>

</div>

<div
class="small text-muted">

<?= htmlspecialchars(
$snap['created_at']
) ?>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

<?php endif; ?>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<div class="row g-3">

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

<input
type="search"
id="sectionSearch"
class="form-control rounded-pill"
placeholder="Search section...">

</div>

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

<select
id="sectionStatusFilter"
class="form-select rounded-pill">

<option value="all">

All Sections

</option>

<option value="enabled">

Enabled

</option>

<option value="disabled">

Disabled

</option>

</select>

</div>

</div>

</div>

</div>

<?php

$favorites = [];

foreach(($sections ?? []) as $s)
{
    $cfg =
        json_decode(
            $s['settings_json']
            ?? '{}',
            true
        );

    if (!empty($cfg['favorite']))
    {
        $favorites[] = $s;
    }
}

?>

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

<?php

$recentSections =
    $sections ?? [];

usort(
    $recentSections,
    function($a, $b)
    {
        return strtotime(
            $b['updated_at']
            ?? $b['created_at']
            ?? ''
        )
        <=>
        strtotime(
            $a['updated_at']
            ?? $a['created_at']
            ?? ''
        );
    }
);

$recentSections =
    array_slice(
        $recentSections,
        0,
        8
    );

?>

<?php

$timelineItems =
    $sections ?? [];

usort(
    $timelineItems,
    function($a,$b)
    {
        return
            strtotime(
                $b['updated_at']
                ?? ''
            )
            <=>
            strtotime(
                $a['updated_at']
                ?? ''
            );
    }
);

$timelineItems =
    array_slice(
        $timelineItems,
        0,
        15
    );

?>

<?php

$dependencyMap = [

    'hero' => [
        'cta',
        'sponsors',
        'speakers'
    ],

    'program' => [
        'proceedings'
    ],

    'venue' => [
        'map'
    ],

    'committee' => [
        'members'
    ],

];

$installedKeys = [];

foreach (($sections ?? []) as $s)
{
    $installedKeys[] =
        strtolower(
            trim(
                (string)(
                    $s['section_key']
                    ?? ''
                )
            )
        );
}

?>

<?php

$lifecycleStats = [

    'draft'     => 0,
    'review'    => 0,
    'published' => 0,
    'archived'  => 0

];

$lifecycleRows = [];

foreach (($sections ?? []) as $s)
{
    $cfg =
        json_decode(
            $s['settings_json']
            ?? '{}',
            true
        );

    $state =
        strtolower(
            trim(
                (string)(
                    $cfg['lifecycle']
                    ?? 'published'
                )
            )
        );

    if (!isset($lifecycleStats[$state]))
    {
        $state = 'published';
    }

    $lifecycleStats[$state]++;

    $lifecycleRows[] = [

        'name' =>
            $s['section_title_en']
            ?: $s['section_key'],

        'state' =>
            $state

    ];
}

?>

<?php

$complianceChecks = [];

$complianceChecks[] =
    $englishCoverage >= 90;

$complianceChecks[] =
    $arabicCoverage >= 90;

$complianceChecks[] =
    $accessibilityScore >= 85;

$complianceChecks[] =
    $seoScore >= 85;

$complianceChecks[] =
    $performanceScore >= 80;

$complianceChecks[] =
    $readinessOverall >= 85;

$passedCompliance =
    count(
        array_filter(
            $complianceChecks
        )
    );

$totalCompliance =
    count(
        $complianceChecks
    );

$complianceScore =
    round(
        (
            $passedCompliance
            /
            max(
                1,
                $totalCompliance
            )
        )
        * 100
    );

$complianceClass =
    'success';

$complianceStatus =
    'READY FOR PUBLICATION';

if ($complianceScore < 90)
{
    $complianceClass =
        'warning';

    $complianceStatus =
        'NEEDS REVIEW';
}

if ($complianceScore < 70)
{
    $complianceClass =
        'danger';

    $complianceStatus =
        'NOT COMPLIANT';
}

?>

<?php

$executiveHealthScore =
    round(

        (

            $complianceScore
            +

            $seoScore
            +

            $performanceScore
            +

            $accessibilityScore
            +

            $readinessOverall

        ) / 5

    );

$executiveHealthClass =
    'success';

$executiveHealthStatus =
    'READY FOR LAUNCH';

if ($executiveHealthScore < 90)
{
    $executiveHealthClass =
        'warning';

    $executiveHealthStatus =
        'REVIEW RECOMMENDED';
}

if ($executiveHealthScore < 70)
{
    $executiveHealthClass =
        'danger';

    $executiveHealthStatus =
        'NOT READY';
}

?>

<?php

$healthChecks = [

'launchChecks' =>
    isset($launchChecks),

'launchScore' =>
    isset($launchScore),

'complianceScore' =>
    isset($complianceScore),

'seoScore' =>
    isset($seoScore),

'accessibilityScore' =>
    isset($accessibilityScore),

'performanceScore' =>
    isset($performanceScore),

'readinessOverall' =>
    isset($readinessOverall)

];

$healthyCount =
    count(
        array_filter(
            $healthChecks
        )
    );

$totalHealthChecks =
    count(
        $healthChecks
    );

$systemHealthScore =
    round(
        (
            $healthyCount
            /
            max(
                1,
                $totalHealthChecks
            )
        )
        * 100
    );

$systemHealthClass =
    $systemHealthScore >= 95
    ? 'success'
    : (
        $systemHealthScore >= 80
        ? 'warning'
        : 'danger'
    );

?>

<?php

$variableInspector = [

'launchScore' =>
    $launchScore ?? null,

'complianceScore' =>
    $complianceScore ?? null,

'seoScore' =>
    $seoScore ?? null,

'performanceScore' =>
    $performanceScore ?? null,

'accessibilityScore' =>
    $accessibilityScore ?? null,

'readinessOverall' =>
    $readinessOverall ?? null,

'englishCoverage' =>
    $englishCoverage ?? null,

'arabicCoverage' =>
    $arabicCoverage ?? null,

'executiveHealthScore' =>
    $executiveHealthScore ?? null,

'systemHealthScore' =>
    $systemHealthScore ?? null

];

?>

<?php

$summaryStrengths = [];

$summaryIssues = [];

if (($seoScore ?? 0) >= 90) {
    $summaryStrengths[] =
        'Excellent SEO';
}

if (($accessibilityScore ?? 0) >= 90) {
    $summaryStrengths[] =
        'Excellent Accessibility';
}

if (($englishCoverage ?? 0) >= 90) {
    $summaryStrengths[] =
        'Complete English Coverage';
}

if (($arabicCoverage ?? 0) >= 90) {
    $summaryStrengths[] =
        'Complete Arabic Coverage';
}

if (($seoScore ?? 0) < 85) {
    $summaryIssues[] =
        'SEO needs improvement';
}

if (($performanceScore ?? 0) < 85) {
    $summaryIssues[] =
        'Performance needs improvement';
}

if (($readinessOverall ?? 0) < 85) {
    $summaryIssues[] =
        'Readiness review required';
}

$executiveSummaryStatus =
    ($executiveHealthScore ?? 0) >= 90
    ? 'READY FOR PUBLICATION'
    : 'REVIEW RECOMMENDED';

?>

<?php

$pipelineStages = [

'Translation Coverage' =>
    isset($englishCoverage),

'Content Quality' =>
    isset($contentQuality),

'Accessibility' =>
    isset($accessibilityScore),

'SEO' =>
    isset($seoScore),

'Performance' =>
    isset($performanceScore),

'Compliance' =>
    isset($complianceScore),

'Executive KPI' =>
    isset($executiveHealthScore),

'Launch Checklist' =>
    isset($launchScore)

];

$pipelineLoaded =
    count(
        array_filter(
            $pipelineStages
        )
    );

$pipelineTotal =
    count(
        $pipelineStages
    );

$pipelineHealth =
    round(
        (
            $pipelineLoaded
            /
            max(
                1,
                $pipelineTotal
            )
        )
        * 100
    );

?>

<?php

$cardRegistry = [

'Executive KPI Dashboard' => true,

'Compliance Monitor' => true,

'Launch Checklist' => true,

'Missing Content Center' => true,

'AI Recommendations' => true,

'Translation Coverage' => true,

'Content Quality Analyzer' => true,

'Accessibility Analyzer' => true,

'SEO Analyzer' => true,

'Performance Analyzer' => true,

'Lifecycle Monitor' => true,

'Dependency Map' => true,

'Governance Timeline' => true,

'Theme Distribution' => true,

'Section Gallery' => true,

'System Health' => true,

'Variable Inspector' => true,

'Analytics Pipeline' => true

];

$totalCards =
    count(
        $cardRegistry
    );

?>


<hr>

<div class="row">

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

<div class="mb-2">

<?= in_array('hero',$installed,true)
? '✓ Hero Present'
: '✗ Hero Missing' ?>

</div>

<div class="mb-2">

<?= in_array('cta',$installed,true)
? '✓ CTA Present'
: '✗ CTA Missing' ?>

</div>

<div class="mb-2">

<?= in_array('sponsors',$installed,true)
? '✓ Sponsors Present'
: '✗ Sponsors Missing' ?>

</div>

</div>

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

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

<?php foreach($riskWarnings as $w): ?>

<div
class="alert alert-warning py-2 mb-2">

<?= htmlspecialchars($w) ?>

</div>

<?php endforeach; ?>

<?php else: ?>

<div
class="alert alert-success">

No homepage risks detected.

</div>

<?php endif; ?>

</div>

</div>

</div>

</div>

<?php

$readinessTotal =
    max(1, count($sections ?? []));

$readinessEnabled =
    $readinessTotal > 0
        ? round(($enabledSections / $readinessTotal) * 100)
        : 0;

$readinessStructure =
    round(
        ($coreInstalled / max(1, count($coreSections))) * 100
    );

$sectionsWithEnglish =
    0;

$sectionsWithArabic =
    0;

$sectionsWithDesign =
    0;

foreach (($sections ?? []) as $s)
{
    if (
        !empty($s['title_en'])
        ||
        !empty($s['section_title_en'])
        ||
        !empty($s['content_en'])
    ) {
        $sectionsWithEnglish++;
    }

    if (
        !empty($s['title_ar'])
        ||
        !empty($s['section_title_ar'])
        ||
        !empty($s['content_ar'])
    ) {
        $sectionsWithArabic++;
    }

    if (
        !empty($s['theme_name'])
        ||
        !empty($s['background_value'])
        ||
        !empty($s['background_image'])
    ) {
        $sectionsWithDesign++;
    }
}

$readinessEnglish =
    round(($sectionsWithEnglish / $readinessTotal) * 100);

$readinessArabic =
    round(($sectionsWithArabic / $readinessTotal) * 100);

$readinessDesign =
    round(($sectionsWithDesign / $readinessTotal) * 100);

$readinessOverall =
    round(
        (
            $readinessEnabled +
            $readinessStructure +
            $readinessEnglish +
            $readinessArabic +
            $readinessDesign
        ) / 5
    );

$readinessClass =
    'success';

if ($readinessOverall < 85) {
    $readinessClass = 'warning';
}

if ($readinessOverall < 65) {
    $readinessClass = 'danger';
}

?>

<?php

$db =
    \App\Core\Database::getInstance();

$snapshotCount = 0;

try {

    $stmt =
        $db->prepare("

            SELECT COUNT(*)

            FROM conference_home_templates

            WHERE org_id=?

        ");

    $stmt->execute([

        $_SESSION['org_id']

    ]);

    $snapshotCount =
        (int)$stmt->fetchColumn();

} catch(\Throwable $e) {

    $snapshotCount = 0;

}

?>

<?php

$totalSectionsForTranslation =
    max(1, count($sections ?? []));

$englishCovered = 0;
$arabicCovered = 0;

$missingEnglish = [];
$missingArabic = [];

foreach (($sections ?? []) as $s)
{
    $sectionName =
        $s['section_title_en']
        ?: $s['section_key'];

    $hasEnglish =
        !empty($s['title_en'])
        ||
        !empty($s['section_title_en'])
        ||
        !empty($s['content_en']);

    $hasArabic =
        !empty($s['title_ar'])
        ||
        !empty($s['section_title_ar'])
        ||
        !empty($s['content_ar']);

    if ($hasEnglish) {
        $englishCovered++;
    } else {
        $missingEnglish[] =
            $sectionName;
    }

    if ($hasArabic) {
        $arabicCovered++;
    } else {
        $missingArabic[] =
            $sectionName;
    }
}

$englishCoverage =
    round(
        ($englishCovered /
        $totalSectionsForTranslation)
        * 100
    );

$arabicCoverage =
    round(
        ($arabicCovered /
        $totalSectionsForTranslation)
        * 100
    );

?>

<?php

$contentQuality = [];

foreach (($sections ?? []) as $s)
{
    $sectionName =
        $s['section_title_en']
        ?: $s['section_key'];

    $content =
        trim(
            ($s['title_en'] ?? '')
            . ' '
            . ($s['subtitle_en'] ?? '')
            . ' '
            . ($s['content_en'] ?? '')
            . ' '
            . ($s['title_ar'] ?? '')
            . ' '
            . ($s['subtitle_ar'] ?? '')
            . ' '
            . ($s['content_ar'] ?? '')
        );

    $length =
        mb_strlen($content);

    $score = 0;
    $label = 'Missing';
    $class = 'danger';

    if ($length > 50) {
        $score = 1;
        $label = 'Weak';
        $class = 'warning';
    }

    if ($length > 200) {
        $score = 2;
        $label = 'Good';
        $class = 'info';
    }

    if ($length > 500) {
        $score = 3;
        $label = 'Excellent';
        $class = 'success';
    }

    $contentQuality[] = [

        'name'  => $sectionName,
        'score' => $score,
        'label' => $label,
        'class' => $class,
        'size'  => $length

    ];
}

?>

<?php

$accessibilityIssues = [];

$totalChecks = 0;
$passedChecks = 0;

foreach (($sections ?? []) as $s)
{
    $totalChecks++;

    $hasTitle =
        !empty($s['title_en'])
        ||
        !empty($s['title_ar'])
        ||
        !empty($s['section_title_en'])
        ||
        !empty($s['section_title_ar']);

    if ($hasTitle) {
        $passedChecks++;
    } else {
        $accessibilityIssues[] =
            ($s['section_key'] ?? 'unknown')
            . ' missing title';
    }

    $totalChecks++;

    $hasContent =
        !empty($s['content_en'])
        ||
        !empty($s['content_ar'])
        ||
        !empty($s['subtitle_en'])
        ||
        !empty($s['subtitle_ar']);

    if ($hasContent) {
        $passedChecks++;
    } else {
        $accessibilityIssues[] =
            ($s['section_key'] ?? 'unknown')
            . ' missing content';
    }

    $totalChecks++;

    $imageOnly =
        !empty($s['background_image'])
        &&
        !$hasContent;

    if (!$imageOnly) {
        $passedChecks++;
    } else {
        $accessibilityIssues[] =
            ($s['section_key'] ?? 'unknown')
            . ' image-only background';
    }
}

$accessibilityScore =
    round(
        ($passedChecks / max(1, $totalChecks))
        * 100
    );

$accessibilityClass =
    'success';

$accessibilityLabel =
    'EXCELLENT';

if ($accessibilityScore < 90)
{
    $accessibilityClass =
        'warning';

    $accessibilityLabel =
        'GOOD';
}

if ($accessibilityScore < 70)
{
    $accessibilityClass =
        'danger';

    $accessibilityLabel =
        'NEEDS IMPROVEMENT';
}

?>

<?php

$seoWarnings = [];

$seoScore = 100;

$seoLeaders = [];

foreach (($sections ?? []) as $s)
{
    $name =
        $s['section_title_en']
        ?: $s['section_key'];

    $title =
        trim(
            ($s['title_en'] ?? '')
            . ' '
            .
            ($s['title_ar'] ?? '')
        );

    $content =
        trim(
            ($s['content_en'] ?? '')
            . ' '
            .
            ($s['content_ar'] ?? '')
            . ' '
            .
            ($s['subtitle_en'] ?? '')
            . ' '
            .
            ($s['subtitle_ar'] ?? '')
        );

    $contentLength =
        mb_strlen($content);

    if (mb_strlen($title) < 5)
    {
        $seoWarnings[] =
            $name .
            ' missing title';

        $seoScore -= 5;
    }

    if ($contentLength < 120)
    {
        $seoWarnings[] =
            $name .
            ' content too short';

        $seoScore -= 3;
    }

    $seoLeaders[] = [

        'name' => $name,

        'length' =>
            $contentLength

    ];
}

usort(
    $seoLeaders,
    function($a,$b)
    {
        return
            $b['length']
            <=>
            $a['length'];
    }
);

$seoLeaders =
    array_slice(
        $seoLeaders,
        0,
        5
    );

$seoScore =
    max(
        0,
        min(
            100,
            $seoScore
        )
    );

$seoClass =
    'success';

if ($seoScore < 90)
{
    $seoClass =
        'warning';
}

if ($seoScore < 70)
{
    $seoClass =
        'danger';
}

?>

<?php

$imageSections = 0;
$heavySections = 0;
$lightSections = 0;

$estimatedWeight = 0;

foreach (($sections ?? []) as $s)
{
    $weight = 0;

    if (!empty($s['background_image']))
    {
        $imageSections++;
        $weight += 300;
    }

    $contentSize =
        mb_strlen(
            ($s['content_en'] ?? '')
            .
            ($s['content_ar'] ?? '')
        );

    if ($contentSize > 1500)
    {
        $weight += 120;
    }

    if (
        !empty($s['theme_name'])
    )
    {
        $weight += 20;
    }

    $estimatedWeight += $weight;

    if ($weight > 300)
    {
        $heavySections++;
    }
    else
    {
        $lightSections++;
    }
}

$performanceScore = 100;

$performanceScore -=
    ($imageSections * 2);

$performanceScore -=
    ($heavySections * 3);

$performanceScore =
    max(
        0,
        min(
            100,
            $performanceScore
        )
    );

$performanceClass =
    'success';

if ($performanceScore < 90)
{
    $performanceClass =
        'warning';
}

if ($performanceScore < 70)
{
    $performanceClass =
        'danger';
}

?>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-pen-ruler text-primary"></i>

Homepage Content Quality Analyzer

</h4>

<div class="table-responsive">

<table class="table align-middle">

<thead>

<tr>

<th>Section</th>
<th>Quality</th>
<th>Characters</th>

</tr>

</thead>

<tbody>

<?php foreach($contentQuality as $q): ?>

<tr>

<td>

<?= htmlspecialchars(
$q['name']
) ?>

</td>

<td>

<span
class="badge bg-<?= $q['class'] ?>">

<?= htmlspecialchars(
$q['label']
) ?>

</span>

</td>

<td>

<?= (int)$q['size'] ?>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-universal-access text-primary"></i>

Homepage Accessibility Analyzer

</h4>

<span
class="badge bg-<?= $accessibilityClass ?> fs-6">

<?= htmlspecialchars(
$accessibilityLabel
) ?>

</span>

</div>

<div class="row align-items-center">

<div class="col-lg-3">

<div
class="rounded-circle bg-<?= $accessibilityClass ?> text-white d-flex align-items-center justify-content-center"
style="
width:110px;
height:110px;
font-size:30px;
font-weight:900;
">

<?= (int)$accessibilityScore ?>%

</div>

</div>

<div class="col-lg-9">

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

<?php foreach($accessibilityIssues as $issue): ?>

<div
class="alert alert-warning py-2 mb-2">

<?= htmlspecialchars($issue) ?>

</div>

<?php endforeach; ?>

<?php else: ?>

<div
class="alert alert-success">

No accessibility issues detected.

</div>

<?php endif; ?>

</div>

</div>

</div>

</div>


<div id="<?= md5('SEO Analyzer') ?>" class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-magnifying-glass-chart text-primary"></i>

Homepage SEO Analyzer

</h4>

<span
class="badge bg-<?= $seoClass ?> fs-6">

SEO

<?= (int)$seoScore ?>%

</span>

</div>

<div class="row">

<div class="col-lg-7">

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

<?php foreach($seoWarnings as $warning): ?>

<div
class="alert alert-warning py-2 mb-2">

<?= htmlspecialchars($warning) ?>

</div>

<?php endforeach; ?>

<?php else: ?>

<div
class="alert alert-success">

No SEO issues detected.

</div>

<?php endif; ?>

</div>

<div class="col-lg-5">

<div class="card bg-light border-0">

<div class="card-body">

<h6 class="fw-bold">

Top SEO Sections

</h6>

<?php foreach($seoLeaders as $leader): ?>

<div class="mb-2">

<i class="fa fa-arrow-trend-up text-success"></i>

<?= htmlspecialchars(
$leader['name']
) ?>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

</div>

</div>

</div>


<div id="performance-analyzer" class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-gauge-high text-primary"></i>

Homepage Performance Analyzer

</h4>

<span
class="badge bg-<?= $performanceClass ?> fs-6">

<?= (int)$performanceScore ?>%

</span>

</div>

<div class="row g-4">

<div class="col-lg-3">

<div class="border rounded-4 p-3 text-center">

<div class="small text-muted">

Image Sections

</div>

<div class="fs-3 fw-bold">

<?= (int)$imageSections ?>

</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3 text-center">

<div class="small text-muted">

Heavy Sections

</div>

<div class="fs-3 fw-bold text-warning">

<?= (int)$heavySections ?>

</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3 text-center">

<div class="small text-muted">

Light Sections

</div>

<div class="fs-3 fw-bold text-success">

<?= (int)$lightSections ?>

</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3 text-center">

<div class="small text-muted">

Estimated Weight

</div>

<div class="fs-4 fw-bold">

<?= round($estimatedWeight / 1024,2) ?>

MB

</div>

</div>

</div>

</div>

<hr>

<?php if($performanceScore >= 90): ?>

<div class="alert alert-success">

Homepage performance looks excellent.

</div>

<?php elseif($performanceScore >= 70): ?>

<div class="alert alert-warning">

Homepage performance is acceptable but can be improved.

</div>

<?php else: ?>

<div class="alert alert-danger">

Homepage may load slowly on mobile devices.

</div>

<?php endif; ?>

</div>

</div>



<?php
$publishStatus =
    'READY FOR PUBLICATION';

$publishClass =
    'success';

if (
    $riskLevel === 'HIGH'
    ||
    $readinessOverall < 70
)
{
    $publishStatus =
        'NOT READY';

    $publishClass =
        'danger';
}
elseif (
    $riskLevel === 'MEDIUM'
    ||
    $readinessOverall < 85
)
{
    $publishStatus =
        'NEEDS REVIEW';

    $publishClass =
        'warning';
}

?>

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

<div class="card-body">

<div class="row align-items-center">

<div class="col-lg-4 text-center">

<div
class="rounded-circle bg-<?= $executiveHealthClass ?> text-white d-inline-flex align-items-center justify-content-center"
style="
width:160px;
height:160px;
font-size:42px;
font-weight:900;
">

<?= $executiveHealthScore ?>%

</div>

</div>

<div class="col-lg-8">

<h3 class="fw-bold">

<i class="fa fa-chart-line text-primary"></i>

Homepage Executive KPI Dashboard

</h3>

<div class="mb-3">

<span
class="badge bg-<?= $executiveHealthClass ?> fs-6">

<?= htmlspecialchars(
$executiveHealthStatus
) ?>

</span>

</div>

<div class="row g-3">

<div class="col-md-4">
Compliance:
<strong><?= $complianceScore ?>%</strong>
</div>

<div class="col-md-4">
SEO:
<strong><?= $seoScore ?>%</strong>
</div>

<div class="col-md-4">
Performance:
<strong><?= $performanceScore ?>%</strong>
</div>

<div class="col-md-4">
Accessibility:
<strong><?= $accessibilityScore ?>%</strong>
</div>

<div class="col-md-4">
Readiness:
<strong><?= $readinessOverall ?>%</strong>
</div>

<div class="col-md-4">
Health:
<strong><?= $executiveHealthScore ?>%</strong>
</div>

</div>

</div>

</div>

</div>

</div>


<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-heart-pulse text-primary"></i>

Homepage System Health

</h4>

<span
class="badge bg-<?= $systemHealthClass ?>">

<?= $systemHealthScore ?>%

</span>

</div>

<div class="row">

<?php foreach($healthChecks as $name=>$ok): ?>

<div class="col-lg-4 mb-2">

<?php if($ok): ?>

<span class="text-success">

✓

</span>

<?php else: ?>

<span class="text-danger">

✗

</span>

<?php endif; ?>

<?= htmlspecialchars($name) ?>

</div>

<?php endforeach; ?>

</div>

<hr>

<div class="row">

<div class="col-md-4">

<strong>

Sections

</strong>

<br>

<?= count($sections ?? []) ?>

</div>

<div class="col-md-4">

<strong>

Variables

</strong>

<br>

<?= $healthyCount ?>

/
<?= $totalHealthChecks ?>

</div>

<div class="col-md-4">

<strong>

Status

</strong>

<br>

<?= $systemHealthScore >= 95
? 'HEALTHY'
: 'CHECK REQUIRED' ?>

</div>

</div>

</div>

</div>

<?php

$launchChecks = [

'Hero Section' =>
    in_array('hero', $installedKeys),

'About Section' =>
    in_array('about', $installedKeys),

'Committee Section' =>
    in_array('committee', $installedKeys),

'Sponsors Section' =>
    in_array('sponsors', $installedKeys),

'Contact Section' =>
    in_array('contact', $installedKeys),

'English Coverage' =>
    $englishCoverage >= 90,

'Arabic Coverage' =>
    $arabicCoverage >= 90,

'Accessibility Pass' =>
    $accessibilityScore >= 85,

'SEO Pass' =>
    $seoScore >= 85,

'Performance Pass' =>
    $performanceScore >= 80,

'Readiness Pass' =>
    $readinessOverall >= 85,

'Compliance Pass' =>
    $complianceScore >= 90

];

$launchPassed =
    count(
        array_filter(
            $launchChecks
        )
    );

$launchTotal =
    count(
        $launchChecks
    );

$launchScore =
    round(
        ($launchPassed / $launchTotal) * 100
    );

?>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-microscope text-primary"></i>

Homepage Variable Inspector

</h4>

<button
class="btn btn-sm btn-outline-primary"
data-bs-toggle="collapse"
data-bs-target="#variableInspector">

Toggle

</button>

</div>

<div
id="variableInspector"
class="collapse">

<div class="table-responsive mt-3">

<table class="table table-sm">

<thead>

<tr>

<th>Variable</th>

<th>Value</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<?php foreach(
$variableInspector
as $name=>$value
): ?>

<tr>

<td>

<?= htmlspecialchars($name) ?>

</td>

<td>

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

</td>

<td>

<?php if($value===null): ?>

<span
class="badge bg-danger">

Missing

</span>

<?php else: ?>

<span
class="badge bg-success">

Loaded

</span>

<?php endif; ?>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-gears text-primary"></i>

Homepage Analytics Pipeline

</h4>

<span
class="badge bg-primary">

<?= $pipelineHealth ?>%

</span>

</div>

<div class="table-responsive">

<table class="table">

<thead>

<tr>

<th>#</th>

<th>Stage</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<?php
$i = 1;
foreach(
$pipelineStages
as $stage=>$loaded
):
?>

<tr>

<td>

<?= $i++ ?>

</td>

<td>

<?= htmlspecialchars(
$stage
) ?>

</td>

<td>

<?php if($loaded): ?>

<span
class="badge bg-success">

Loaded

</span>

<?php else: ?>

<span
class="badge bg-danger">

Missing

</span>

<?php endif; ?>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-table-cells-large text-primary"></i>

Homepage Card Registry

</h4>

<span
class="badge bg-primary">

<?= $totalCards ?>

Cards

</span>

</div>

<hr>

<div class="row g-2">

<?php foreach($cardRegistry as $card => $enabled): ?>

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

<div
class="border rounded-3 p-2">

✓

<a
href="#<?= md5($card) ?>"
class="text-decoration-none">

<?= htmlspecialchars($card) ?>

</a>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold">

<i class="fa fa-sliders text-primary"></i>

Homepage Widget Toggle Center

</h4>

<div class="row g-2 mt-3">

<?php foreach($cardRegistry as $widget=>$enabled): ?>

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

<label
class="border rounded-3 p-2 d-block">

<input
type="checkbox"
checked>

<?= htmlspecialchars($widget) ?>

</label>

</div>

<?php endforeach; ?>

</div>

</div>

</div>




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

<div class="card-body">

<h3 class="fw-bold">

<i class="fa fa-rocket text-success"></i>

Homepage Launch Checklist

</h3>

<div class="row g-2 mt-3">

<?php foreach($launchChecks as $label=>$ok): ?>

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

<div class="border rounded-3 p-2">

<?php if($ok): ?>

<span class="text-success">
✓
</span>

<?php else: ?>

<span class="text-danger">
✗
</span>

<?php endif; ?>

<?= htmlspecialchars($label) ?>

</div>

</div>

<?php endforeach; ?>

</div>

<hr>

<div class="text-center">

<h2>

<?= $launchScore ?>%

</h2>

<?php if($launchScore >= 90): ?>

<span class="badge bg-success fs-6">

READY FOR LAUNCH

</span>

<?php elseif($launchScore >= 70): ?>

<span class="badge bg-warning fs-6">

MINOR ISSUES

</span>

<?php else: ?>

<span class="badge bg-danger fs-6">

NOT READY

</span>

<?php endif; ?>

</div>

</div>

</div>

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

<div class="card-body">

<h3 class="fw-bold">

<i class="fa fa-file-lines text-primary"></i>

Homepage Executive Summary

</h3>

<div class="mt-3">

<span class="badge bg-primary fs-6">

<?= htmlspecialchars(
$executiveSummaryStatus
) ?>

</span>

</div>

<hr>

<div class="row">

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

<h5>

Strengths

</h5>

<ul>

<?php foreach($summaryStrengths as $item): ?>

<li>

<?= htmlspecialchars($item) ?>

</li>

<?php endforeach; ?>

</ul>

</div>

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

<h5>

Attention Required

</h5>

<ul>

<?php foreach($summaryIssues as $item): ?>

<li>

<?= htmlspecialchars($item) ?>

</li>

<?php endforeach; ?>

</ul>

</div>

</div>

</div>

</div>




<div id="compliance-monitor" class="card border-0 shadow-lg rounded-4 mb-4">

<div class="card-body">

<div class="row align-items-center">

<div class="col-lg-8">

<h3 class="fw-bold">

<i class="fa fa-certificate text-primary"></i>

Homepage Compliance Monitor

</h3>

<div class="mt-3">

<span
class="badge bg-<?= $complianceClass ?> fs-6">

<?= htmlspecialchars(
$complianceStatus
) ?>

</span>

</div>

<ul class="mt-4">

<li>
English Coverage:
<?= $englishCoverage ?>%
</li>

<li>
Arabic Coverage:
<?= $arabicCoverage ?>%
</li>

<li>
Accessibility:
<?= $accessibilityScore ?>%
</li>

<li>
SEO:
<?= $seoScore ?>%
</li>

<li>
Performance:
<?= $performanceScore ?>%
</li>

<li>
Readiness:
<?= $readinessOverall ?>%
</li>

</ul>

</div>

<div class="col-lg-4 text-center">

<div
class="rounded-circle bg-<?= $complianceClass ?> text-white d-inline-flex align-items-center justify-content-center"
style="
width:140px;
height:140px;
font-size:32px;
font-weight:900;
">

<?= $complianceScore ?>%

</div>

</div>

</div>

</div>

</div>


<div id="publish-center" class="card border-0 shadow-lg rounded-4 mb-4">

<div class="card-body">

<div class="row align-items-center">

<div class="col-lg-8">

<h3 class="fw-bold">

<i class="fa fa-bullseye text-primary"></i>

Homepage Executive Publish Center

</h3>

<div class="mt-3">

<span
class="badge bg-<?= $publishClass ?> fs-6">

<?= htmlspecialchars($publishStatus) ?>

</span>

</div>

<div class="mt-3 text-muted">

Homepage Readiness:
<strong>

<?= (int)$readinessOverall ?>%

</strong>

</div>

<div class="text-muted">

Risk Level:
<strong>

<?= htmlspecialchars($riskLevel) ?>

</strong>

</div>

</div>

<div class="col-lg-4 text-center">

<div
class="rounded-circle bg-<?= $publishClass ?> text-white d-inline-flex align-items-center justify-content-center"
style="
width:140px;
height:140px;
font-size:28px;
font-weight:900;
">

<?= (int)$readinessOverall ?>%

</div>

</div>

</div>

</div>

</div>


<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<h4 class="fw-bold mb-0">

<i class="fa fa-shield-halved text-primary"></i>

Homepage Change Risk Analyzer

</h4>

<span
class="badge bg-<?= $riskClass ?> fs-6">

Risk:
<?= htmlspecialchars($riskLevel) ?>

</span>

</div>



<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

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

<div>

<h4 class="fw-bold mb-1">

<i class="fa fa-rocket text-primary"></i>

Homepage Publish Readiness

</h4>

<div class="text-muted small">

Measures whether the public conference homepage is ready for visitors.

</div>

</div>

<div
class="rounded-circle d-flex align-items-center justify-content-center bg-<?= $readinessClass ?> text-white"
style="
width:110px;
height:110px;
font-size:30px;
font-weight:900;
">

<?= (int)$readinessOverall ?>%

</div>

</div>

<div class="row g-3">

<?php

$readinessItems = [
    'Enabled Sections' => $readinessEnabled,
    'Core Structure'   => $readinessStructure,
    'English Content'  => $readinessEnglish,
    'Arabic Content'   => $readinessArabic,
    'Design Coverage'  => $readinessDesign,
];

foreach ($readinessItems as $label => $value):

$barClass =
    $value >= 85
        ? 'success'
        : (
            $value >= 65
                ? 'warning'
                : 'danger'
        );

?>

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

<div class="border rounded-4 p-3 h-100">

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

<span class="fw-bold">
<?= htmlspecialchars($label) ?>
</span>

<span class="badge bg-<?= $barClass ?>">
<?= (int)$value ?>%
</span>

</div>

<div class="progress">

<div
class="progress-bar bg-<?= $barClass ?>"
style="width:<?= (int)$value ?>%">

</div>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-language text-primary"></i>

Translation Coverage Analyzer

</h4>

<div class="row g-4">

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

<h6>

English Coverage

</h6>

<div class="progress mb-3">

<div
class="progress-bar bg-success"
style="width:<?= $englishCoverage ?>%">

<?= $englishCoverage ?>%

</div>

</div>

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

<div class="small text-danger">

Missing English:

<?= htmlspecialchars(
implode(', ', $missingEnglish)
) ?>

</div>

<?php endif; ?>

</div>

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

<h6>

Arabic Coverage

</h6>

<div class="progress mb-3">

<div
class="progress-bar bg-info"
style="width:<?= $arabicCoverage ?>%">

<?= $arabicCoverage ?>%

</div>

</div>

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

<div class="small text-danger">

Missing Arabic:

<?= htmlspecialchars(
implode(', ', $missingArabic)
) ?>

</div>

<?php endif; ?>

</div>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-chart-line text-primary"></i>

Homepage Activity Dashboard

</h4>

<div class="row g-3">

<div class="col-lg-3">

<div class="border rounded-4 p-3">

<div class="text-muted">
Total Sections
</div>

<div class="fs-3 fw-bold">
<?= (int)$totalSections ?>
</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3">

<div class="text-muted">
Enabled
</div>

<div class="fs-3 fw-bold text-success">
<?= (int)$enabledSections ?>
</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3">

<div class="text-muted">
Disabled
</div>

<div class="fs-3 fw-bold text-danger">
<?= (int)$disabledSections ?>
</div>

</div>

</div>

<div class="col-lg-3">

<div class="border rounded-4 p-3">

<div class="text-muted">
Favorites
</div>

<div class="fs-3 fw-bold text-warning">
<?= (int)$favoriteSections ?>
</div>

</div>

</div>

</div>

<hr>

<div class="row g-3">

<div class="col-md-2">

<span class="badge bg-primary">

Core

<?= (int)$coreCount ?>

</span>

</div>

<div class="col-md-2">

<span class="badge bg-success">

Conference

<?= (int)$conferenceCount ?>

</span>

</div>

<div class="col-md-2">

<span class="badge bg-info">

Media

<?= (int)$mediaCount ?>

</span>

</div>

<div class="col-md-2">

<span class="badge bg-dark">

AI

<?= (int)$aiCount ?>

</span>

</div>

<div class="col-md-2">

<span class="badge bg-secondary">

Custom

<?= (int)$customCount ?>

</span>

</div>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-arrows-spin text-primary"></i>

Homepage Section Lifecycle Monitor

</h4>

<div class="row g-3 mb-4">

<?php foreach($lifecycleStats as $state=>$count): ?>

<div class="col-lg-3">

<div class="border rounded-4 p-3 text-center">

<div class="small text-muted">

<?= ucfirst($state) ?>

</div>

<div class="fs-3 fw-bold">

<?= (int)$count ?>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

<div class="table-responsive">

<table class="table">

<thead>

<tr>

<th>Section</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<?php foreach($lifecycleRows as $row): ?>

<tr>

<td>

<?= htmlspecialchars(
$row['name']
) ?>

</td>

<td>

<span class="badge bg-secondary">

<?= htmlspecialchars(
ucfirst($row['state'])
) ?>

</span>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-project-diagram text-primary"></i>

Homepage Dependency Map

</h4>

<div class="row">

<?php foreach($dependencyMap as $parent => $children): ?>

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

<div class="border rounded-4 p-3 h-100">

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

<?= htmlspecialchars(
ucfirst($parent)
) ?>

</div>

<?php foreach($children as $child): ?>

<div class="ms-3">

├──

<?= htmlspecialchars(
ucfirst($child)
) ?>

</div>

<?php endforeach; ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-triangle-exclamation text-warning"></i>

Impact Analysis

</h4>

<?php foreach($dependencyMap as $parent => $children): ?>

<?php

if (
    !in_array(
        $parent,
        $installedKeys,
        true
    )
) {
    continue;
}

?>

<div class="mb-3">

<strong>

Removing
<?= ucfirst($parent) ?>

affects:

</strong>

<div class="mt-2">

<?php foreach($children as $child): ?>

<span
class="badge bg-warning text-dark me-1">

<?= htmlspecialchars(
ucfirst($child)
) ?>

</span>

<?php endforeach; ?>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

<div id="timeline" class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h4 class="fw-bold mb-4">

<i class="fa fa-timeline text-primary"></i>

Homepage Governance Timeline

</h4>

<div class="timeline-list">

<?php foreach($timelineItems as $item): ?>

<div
class="d-flex align-items-start gap-3 mb-3">

<div>

<span
class="badge bg-primary">

<?= date(
'H:i',
strtotime(
$item['updated_at']
?? $item['created_at']
)
) ?>

</span>

</div>

<div>

<div class="fw-bold">

<?= htmlspecialchars(

$item['section_title_en']
?: $item['section_key']

) ?>

</div>

<div class="small text-muted">

Updated

<?= htmlspecialchars(
$item['updated_at']
?? ''
) ?>

</div>

</div>

</div>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h5 class="fw-bold">

<i class="fa fa-clock-rotate-left text-primary"></i>

Recently Modified

</h5>

<div class="list-group list-group-flush mt-3">

<?php foreach($recentSections as $r): ?>

<a
href="/easychair/admin/conference-home/sections/edit?id=<?= (int)$r['id'] ?>"
class="list-group-item list-group-item-action border-0">

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

<div>

<strong>

<?= htmlspecialchars(
    $r['section_title_en']
    ?: $r['section_key']
) ?>

</strong>

</div>

<div class="text-muted small">

<?= htmlspecialchars(
    $r['updated_at']
    ?? $r['created_at']
    ?? ''
) ?>

</div>

</div>

</a>

<?php endforeach; ?>

</div>

</div>

</div>

<div class="card border-0 shadow-sm rounded-4 mb-4">

<div class="card-body">

<h5 class="fw-bold">

<i class="fa fa-star text-warning"></i>

Favorite Sections

</h5>

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

<?php foreach($favorites as $f): ?>

<a
href="/easychair/admin/conference-home/sections/edit?id=<?= (int)$f['id'] ?>"
class="btn btn-warning rounded-pill">

<?= htmlspecialchars(
    $f['section_title_en']
    ?: $f['section_key']
) ?>

</a>

<?php endforeach; ?>

</div>

</div>

</div>

<?php endif; ?>

<div class="card border-0 shadow-sm rounded-4 mb-4">

    <div class="card-body">

        <h4 class="fw-bold mb-4">

            <i class="fa fa-th-large text-primary"></i>
            Section Gallery

        </h4>

        <div class="row g-4">

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

                <?php
                $previewStyle = '';

                if (!empty($s['background_image'])) {

                    $previewStyle =
                        "background-image:url('/easychair/uploads/section_backgrounds/" .
                        htmlspecialchars((string)$s['background_image']) .
                        "');";

                } elseif (!empty($s['background_value'])) {

                    $previewStyle =
                        "background:" .
                        htmlspecialchars((string)$s['background_value']) .
                        ";";

                } else {

                    $previewStyle =
                        "background:linear-gradient(135deg,#0f172a,#2563eb);";
                }

                $iconClass =
                    $s['icon_class']
                    ?? 'fa-layer-group';

                $health = 100;

                if (empty($s['theme_name'])) {
                    $health -= 20;
                }

                if (empty($s['section_title_en'])) {
                    $health -= 20;
                }

                if (empty($s['title_en'])) {
                    $health -= 20;
                }

                $hasEnglish =
                    !empty($s['title_en']) ||
                    !empty($s['section_title_en']);

                $hasArabic =
                    !empty($s['title_ar']) ||
                    !empty($s['section_title_ar']);

                $hasTheme =
                    !empty($s['theme_name']);

                $hasIcon =
                    !empty($s['icon_class']);

                $quality = 'Poor';
                $qualityClass = 'danger';

                if ($health >= 90) {
                    $quality = 'Excellent';
                    $qualityClass = 'success';
                } elseif ($health >= 70) {
                    $quality = 'Good';
                    $qualityClass = 'primary';
                } elseif ($health >= 50) {
                    $quality = 'Fair';
                    $qualityClass = 'warning';
                }

                $updated =
                    $s['updated_at']
                    ?? $s['created_at']
                    ?? '';

                $visibility =
                    $s['visibility_mode']
                    ?? 'public';
?>

<?php

$category =
    ecSectionCategory(
        (string)($s['section_key'] ?? '')
    );

?>

<div
class="col-xl-3 col-lg-4 col-md-6 section-card"

data-name="<?= htmlspecialchars(
    strtolower(
        (string)(
            $s['section_title_en']
            ?? $s['section_key']
        )
    )
) ?>"

data-status="<?= !empty($s['enabled'])
    ? 'enabled'
    : 'disabled' ?>"

data-category="<?= htmlspecialchars($category) ?>">

<div class="mt-2">

    <span class="badge bg-secondary">

        <?= htmlspecialchars(
            ucfirst($category)
        ) ?>

    </span>

</div>


                    <div class="card border-0 shadow-sm rounded-4 h-100 ec-ection-card">

                        <div class="card-body">

                            <div
                                class="ec-section-preview mb-3 d-flex align-items-center justify-content-center text-white"
                                style="<?= $previewStyle ?>">

                                <div class="text-center px-2">

                                    <i class="fa <?= htmlspecialchars((string)$iconClass) ?> fa-2x mb-2"></i>

                                    <div class="fw-bold">
                                        <?= htmlspecialchars(
                                            $s['section_title_en']
                                            ?? $s['section_key']
                                            ?? ''
                                        ) ?>
                                    </div>

                                </div>

                            </div>

                            <div class="d-flex justify-content-between gap-2">

                                <div>

                                    <h5 class="fw-bold mb-1">
                                        <?= htmlspecialchars(
                                            $s['section_title_en']
                                            ?? $s['section_key']
                                            ?? ''
                                        ) ?>
                                    </h5>

                                    <div class="text-muted small">
                                        <?= htmlspecialchars(
                                            $s['section_key']
                                            ?? ''
                                        ) ?>
                                    </div>

                                </div>

                                <div>

                                    <?php if(!empty($s['enabled'])): ?>

                                        <span class="badge bg-success">
                                            Live
                                        </span>

                                    <?php else: ?>

                                        <span class="badge bg-secondary">
                                            Hidden
                                        </span>

                                    <?php endif; ?>

                                </div>

                            </div>

                            <hr>

                            <div class="mb-2">
                                <i class="fa fa-palette text-primary"></i>
                                <?= htmlspecialchars($s['theme_name'] ?? 'default') ?>
                            </div>

                            <div class="mb-3">
                                <i class="fa fa-sort-numeric-down"></i>
                                Sort:
                                <?= (int)($s['sort_order'] ?? 0) ?>
                            </div>

                            <div class="mb-3">

                                <div class="small mb-1">
                                    Health Score
                                </div>

                                <div class="progress">

                                    <div
                                        class="progress-bar bg-success"
                                        style="width:<?= (int)$health ?>%">

                                        <?= (int)$health ?>%

                                    </div>

                                </div>

                            </div>

                            <div class="border rounded-4 p-3 mb-3">

                                <div class="fw-bold mb-2">
                                    Content Status
                                </div>

                                <div class="small">

                                    <div>
                                        <?= $hasEnglish ? '✓' : '✗' ?>
                                        English
                                    </div>

                                    <div>
                                        <?= $hasArabic ? '✓' : '✗' ?>
                                        Arabic
                                    </div>

                                    <div>
                                        <?= $hasTheme ? '✓' : '✗' ?>
                                        Theme
                                    </div>

                                    <div>
                                        <?= $hasIcon ? '✓' : '✗' ?>
                                        Icon
                                    </div>

                                </div>

                            </div>

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

                                <span class="badge bg-<?= $qualityClass ?>">
                                    <?= htmlspecialchars($quality) ?>
                                </span>

                                <span class="badge bg-dark">
                                    <?= htmlspecialchars(ucfirst((string)$visibility)) ?>
                                </span>

                            </div>

                            <div class="small text-muted mb-3">
                                <i class="fa fa-clock"></i>
                                <?= htmlspecialchars((string)$updated) ?>
                            </div>

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

<?php

$settings =
    json_decode(
        $s['settings_json']
        ?? '{}',
        true
    );

$isFavorite =
    !empty(
        $settings['favorite']
    );

?>

<a
href="/easychair/admin/conference-home/sections/favorite?id=<?= (int)$s['id'] ?>"
class="btn btn-sm <?= $isFavorite
    ? 'btn-warning'
    : 'btn-outline-warning' ?> rounded-pill">

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

</a>
                                <a
                                    href="/easychair/admin/conference-home/sections/edit?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm btn-warning rounded-pill">

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

                                </a>

                                <a
                                    href="/easychair/admin/conference-home/sections/duplicate?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm btn-info rounded-pill">

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

                                </a>

                                <a
                                    href="/easychair/admin/conference-home/sections/delete?id=<?= (int)$s['id'] ?>"
                                    class="btn btn-sm btn-danger rounded-pill"
                                    onclick="return confirm('Delete section permanently?')">

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

                                </a>

                            </div>

                        </div>

                    </div>

                </div>

            <?php endforeach; ?>

        </div>

    </div>

</div>

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

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

        <div class="table-responsive">

            <table class="table align-middle mb-0">

                <thead class="table-light">

                    <tr>

                        <th>ID</th>

                        <th>Section</th>

                        <th>Theme</th>

                        <th>Sort</th>

                        <th>Status</th>

                        <th width="260">
                            Actions
                        </th>

                    </tr>

                </thead>

                <tbody id="sortable-sections">

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

                        <tr data-id="<?= (int)$s['id'] ?>">

                            <td>

                                <span class="drag-handle me-2" style="cursor:grab">

                                    <i class="fa fa-grip-vertical"></i>

                                </span>

                                <?= (int)$s['id'] ?>

                            </td>

                            <td>

                                <div class="fw-bold">
                                    <?= htmlspecialchars(
                                        $s['section_title_en']
                                        ?? $s['section_key']
                                        ?? ''
                                    ) ?>
                                </div>

                                <div class="small text-muted">
                                    <?= htmlspecialchars(
                                        $s['section_key']
                                        ?? ''
                                    ) ?>
                                </div>

                                <div class="mt-2">

                                    <span class="badge bg-dark">

                                        <?= htmlspecialchars(
                                            $s['section_key']
                                            ?? ''
                                        ) ?>

                                    </span>

                                    <?php if (!empty($s['background_image'])): ?>

                                        <span class="badge bg-success">
                                            Image
                                        </span>

                                    <?php endif; ?>

                                    <?php if (!empty($s['background_value'])): ?>

                                        <span class="badge bg-primary">
                                            Styled
                                        </span>

                                    <?php endif; ?>

                                </div>

                            </td>

                            <td>

                                <span class="badge bg-info">
                                    <?= htmlspecialchars(
                                        $s['theme_name']
                                        ?? 'default'
                                    ) ?>
                                </span>

                            </td>

                            <td>

                                <span class="badge bg-dark">
                                    <?= (int)($s['sort_order'] ?? 0) ?>
                                </span>

                            </td>

                            <td>

                                <?php if (!empty($s['enabled'])): ?>

                                    <span class="badge bg-success">
                                        Enabled
                                    </span>

                                <?php else: ?>

                                    <span class="badge bg-danger">
                                        Disabled
                                    </span>

                                <?php endif; ?>

                            </td>

                            <td>

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

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

                                        <i class="fa fa-arrow-up"></i>

                                    </a>

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

                                        <i class="fa fa-arrow-down"></i>

                                    </a>

                                    <a
                                        href="/easychair/admin/conference-home/sections/edit?id=<?= (int)$s['id'] ?>"
                                        class="btn btn-sm btn-warning rounded-pill">

                                        <i class="fa fa-edit"></i>
                                        Edit

                                    </a>

                                    <button
                                        type="button"
                                        class="btn btn-sm btn-secondary rounded-pill js-toggle-section"
                                        data-id="<?= (int)$s['id'] ?>">

                                        <i class="fa fa-power-off"></i>

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

                                    </button>

                                    <a
                                        href="/easychair/admin/conference-home/sections/duplicate?id=<?= (int)$s['id'] ?>"
                                        class="btn btn-sm btn-info rounded-pill">

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

                                    </a>

                                    <a
                                        href="/easychair/admin/conference-home/sections/delete?id=<?= (int)$s['id'] ?>"
                                        class="btn btn-sm btn-danger rounded-pill"
                                        onclick="return confirm('Delete section permanently?')">

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

                                    </a>

                                </div>

                            </td>

                        </tr>

                    <?php endforeach; ?>

                </tbody>

            </table>

        </div>

    </div>

</div>

</div>

<a
href="#pageTop"
class="homepage-top-btn">

<i class="fa fa-arrow-up"></i>

</a>

<script>
document.querySelectorAll('.js-toggle-section')
.forEach(btn => {

    btn.addEventListener('click', async () => {

        const id =
            btn.dataset.id;

        const fd =
            new FormData();

        fd.append('id', id);

        try {

            const res =
                await fetch(
                    '/easychair/admin/conference-home/sections/toggle-ajax',
                    {
                        method: 'POST',
                        body: fd
                    }
                );

            const json =
                await res.json();

            if (json.success) {

                location.reload();

            } else {

                alert('Toggle failed');

            }

        } catch (e) {

            alert('Request failed');

        }

    });

});
</script>

<script>

const searchBox =
document.getElementById(
'sectionSearch'
);

const filterBox =
document.getElementById(
'sectionStatusFilter'
);

let currentCategory = 'all';

function filterSections()
{
    const keyword =
        (searchBox?.value || '')
        .toLowerCase();

    const status =
        filterBox?.value || 'all';

    document
    .querySelectorAll('.section-card')
    .forEach(card => {

        const name =
            card.dataset.name || '';

        const state =
            card.dataset.status || '';

const category =
    card.dataset.category || '';

        const matchKeyword =
            name.includes(keyword);

        const matchStatus =
            status === 'all'
            || status === state;

const matchCategory =
    currentCategory === 'all'
    || currentCategory === category;

        card.style.display =
    (
        matchKeyword
        &&
        matchStatus
        &&
        matchCategory
    )
    ? ''
    : 'none';
    });
}

searchBox?.addEventListener(
'keyup',
filterSections
);

filterBox?.addEventListener(
'change',
filterSections
);

document
.querySelectorAll(
'.category-filter'
)
.forEach(btn => {

    btn.addEventListener(
        'click',
        () => {

            currentCategory =
                btn.dataset.category;

            filterSections();

        }
    );

});

</script>

<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>

<script>
const sortable =
new Sortable(

    document.getElementById(
        'sortable-sections'
    ),

    {

        animation: 150,

        handle: '.drag-handle',

        onEnd: async () => {

            const ids = [];

            document
            .querySelectorAll(
                '#sortable-sections tr'
            )
            .forEach(row => {

                ids.push(
                    row.dataset.id
                );

            });

            const fd =
                new FormData();

            ids.forEach(id => {
                fd.append(
                    'items[]',
                    id
                );
            });

            try {

                const res =
                    await fetch(

                        '/easychair/admin/conference-home/sections/reorder-ajax',

                        {
                            method: 'POST',
                            body: fd
                        }

                    );

                const json =
                    await res.json();

                if (!json.success) {

                    alert(
                        'Sort failed'
                    );
                }

            } catch (e) {

                alert(
                    'Request failed'
                );
            }

        }

    }

);
</script>
<script>

document
.querySelector(
'.homepage-top-btn'
)
?.addEventListener(
'click',
function(e){

e.preventDefault();

window.scrollTo({

top:0,

behavior:'smooth'

});

}
);

</script>
