<?php
/**
 * Shared layout for the event organizer portal. Modeled on
 * app/Views/admin/layouts/main.php's lighter sidebar shell — NOT the
 * full staff layouts/main.php (built around staff's many role-gated
 * modules, wrong precedent for a one-page "My Events" portal). Unlike
 * the admin layout, this one DOES read tenant branding (primary_color/
 * hotel_name) since organizers, unlike Super Admin, are tenant-scoped —
 * same branding source the public pages already use.
 */
$tenant         = service('tenantContext')->hasTenant() ? service('tenantContext')->getTenant() : null;
$primaryColor   = safe_hex_color($tenant->primary_color ?? null, '#4f46e5');
$hotelName      = $tenant->hotel_name ?? 'MaxYields PMS';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= esc($pageTitle ?? 'Dashboard') ?> · <?= esc($hotelName) ?> Organizer Portal</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <style>
        :root { --brand: <?= $primaryColor ?>; }
        * { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
        body { background-color: #f4f6f8; }
        .org-shell { min-height: 100vh; }
        .org-sidebar {
            width: 240px; flex-shrink: 0; background: #16182b; color: #fff;
            min-height: 100vh; position: sticky; top: 0; align-self: flex-start;
        }
        .org-sidebar .brand { padding: 1.25rem 1.25rem 1rem; display: flex; align-items: center; gap: 0.6rem; }
        .org-sidebar .brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
        .org-sidebar .brand-text { font-weight: 800; font-size: 0.98rem; letter-spacing: -0.01em; }
        .org-sidebar .brand-sub { font-size: 0.7rem; color: rgba(255,255,255,0.5); }
        .org-nav { padding: 0.5rem 0.75rem; }
        .org-nav .nav-link { color: rgba(255,255,255,0.72); border-radius: 8px; padding: 0.55rem 0.75rem; font-size: 0.88rem; font-weight: 500; display: flex; align-items: center; gap: 0.65rem; margin-bottom: 0.15rem; }
        .org-nav .nav-link i { font-size: 1rem; width: 1.1rem; text-align: center; }
        .org-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,0.06); }
        .org-nav .nav-link.active { color: #fff; background: var(--brand); }
        .org-topbar { background: #fff; border-bottom: 1px solid #eef0f3; padding: 0.85rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
        .org-main { flex: 1; min-width: 0; }
        .card { border: none; border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06); }
        .card-header { background-color: #fff; border-bottom: 1px solid #eef0f3; font-weight: 600; }
        .btn { border-radius: 8px; font-weight: 500; }
        .btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 85%, black); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 85%, black); }
        .btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
        .form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--brand) 18%, transparent); }
        .table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; background: #f9fafb; font-weight: 700; border-bottom-width: 1px; }
        <?= $this->renderSection('styles') ?>
    </style>
</head>
<body>
<div class="org-shell d-flex">
    <aside class="org-sidebar d-flex flex-column">
        <div class="brand">
            <div class="brand-mark"><i class="bi bi-buildings-fill"></i></div>
            <div>
                <div class="brand-text"><?= esc($hotelName) ?></div>
                <div class="brand-sub">Organizer Portal</div>
            </div>
        </div>
        <nav class="org-nav flex-grow-1">
            <a class="nav-link <?= ($activeNav ?? '') === 'dashboard' ? 'active' : '' ?>" href="<?= site_url('organizer/dashboard') ?>">
                <i class="bi bi-calendar-event"></i> My Events
            </a>
        </nav>
        <div class="p-3 border-top border-white border-opacity-10">
            <div class="text-white small fw-semibold"><?= esc(session('organizerName')) ?></div>
            <div class="text-white-50" style="font-size: 0.75rem;"><?= esc(session('organizerEmail')) ?></div>
            <a class="btn btn-outline-light btn-sm w-100 mt-2" href="<?= site_url('organizer/logout') ?>">
                <i class="bi bi-box-arrow-right"></i> Log out
            </a>
        </div>
    </aside>

    <div class="org-main">
        <div class="org-topbar">
            <h1 class="h5 mb-0 fw-bold"><?= esc($pageTitle ?? 'Dashboard') ?></h1>
            <span class="badge bg-light text-dark border"><i class="bi bi-person-badge me-1"></i>Event Organizer</span>
        </div>

        <div class="container-fluid py-4 px-4">
            <?php if (session()->getFlashdata('success')): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <?= esc(session()->getFlashdata('success')) ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>
            <?php if (session()->getFlashdata('error')): ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <?= esc(session()->getFlashdata('error')) ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <?= $this->renderSection('content') ?>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<?= $this->renderSection('scripts') ?>
</body>
</html>
