<?php
$title = $title ?? app_name();
$currentUser = auth_user();
$activeNav = $activeNav ?? 'dashboard';

$breadcrumbs = match ($activeNav) {
    'purchases' => [
        ['label' => 'Dashboard', 'url' => url('/dashboard')],
        ['label' => 'Pilih Paket', 'url' => null],
    ],
    'upload' => [
        ['label' => 'Dashboard', 'url' => url('/dashboard')],
        ['label' => 'Upload Bukti', 'url' => null],
    ],
    'status' => [
        ['label' => 'Dashboard', 'url' => url('/dashboard')],
        ['label' => 'Status Pembelian', 'url' => null],
    ],
    default => [
        ['label' => 'Dashboard', 'url' => null],
    ],
};
?>
<!doctype html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Dashboard client">
    <title><?= e($title) ?> - <?= e(app_name()) ?></title>
    <link rel="stylesheet" href="<?= e(asset('/assets/app.css')) ?>">
</head>
<body>
<div class="page-shell client-shell">
    <aside class="client-sidebar" aria-label="Navigasi client">
        <div class="client-sidebar-brand">
            <a class="brand" href="<?= e(url('/dashboard')) ?>">
                <?php if ($logo = company_logo()): ?>
                    <span class="brand-logo" aria-hidden="true">
                        <img src="<?= e(url('/media?path=' . rawurlencode($logo))) ?>" alt="" loading="lazy">
                    </span>
                <?php else: ?>
                    <span class="brand-mark" aria-hidden="true"></span>
                <?php endif; ?>
                <span><?= e(company_name()) ?></span>
            </a>
            <p class="client-sidebar-note">Kelola pembelian paket dan status transaksi kamu dari satu tempat.</p>
        </div>

        <nav class="client-sidebar-nav">
            <a class="client-sidebar-link <?= e($activeNav === 'dashboard' ? 'client-sidebar-link-active' : '') ?>" href="<?= e(url('/dashboard')) ?>">Dashboard</a>
            <a class="client-sidebar-link <?= e($activeNav === 'purchases' ? 'client-sidebar-link-active' : '') ?>" href="<?= e(url('/dashboard/purchases')) ?>">Pilih Paket</a>
            <a class="client-sidebar-link <?= e($activeNav === 'upload' ? 'client-sidebar-link-active' : '') ?>" href="<?= e(url('/dashboard/upload')) ?>">Upload Bukti</a>
            <a class="client-sidebar-link <?= e($activeNav === 'status' ? 'client-sidebar-link-active' : '') ?>" href="<?= e(url('/dashboard/status')) ?>">Status Pembelian</a>
        </nav>

        <div class="client-sidebar-footer">
            <div class="client-user-card">
                <span class="client-user-label">Masuk sebagai</span>
                <strong><?= e($currentUser['nama'] ?? 'Client') ?></strong>
                <span><?= e($currentUser['role'] ?? 'client') ?></span>
            </div>
            <form class="logout-form" action="<?= e(url('/logout')) ?>" method="post">
                <?= csrf() ?>
                <button class="button-secondary client-logout-button" type="submit">Logout</button>
            </form>
        </div>
    </aside>

    <main class="client-main">
        <header class="client-page-header">
            <div>
                <span class="client-page-kicker">Panel Client</span>
                <nav class="client-breadcrumbs" aria-label="Breadcrumb">
                    <?php foreach ($breadcrumbs as $index => $crumb): ?>
                        <?php if (($crumb['url'] ?? null) !== null): ?>
                            <a class="client-breadcrumb" href="<?= e($crumb['url']) ?>"><?= e($crumb['label']) ?></a>
                        <?php else: ?>
                            <span class="client-breadcrumb-current"><?= e($crumb['label']) ?></span>
                        <?php endif; ?>
                        <?php if ($index < count($breadcrumbs) - 1): ?>
                            <span class="client-breadcrumb-separator" aria-hidden="true">/</span>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </nav>
                <h1 class="client-page-title"><?= e($title) ?></h1>
            </div>
            <div class="client-page-meta">
                <span class="client-page-meta-label">Status akun</span>
                <strong><?= e($currentUser['role'] ?? 'client') ?></strong>
            </div>
        </header>

        <?= $content ?>

        <footer class="client-footer">
            <div>
                <strong><?= e(company_name()) ?></strong>
                <p>Langkah cepat: pilih paket, upload bukti, lalu pantau status pembelian.</p>
            </div>
            <span class="client-footer-note">Sidebar layout aktif</span>
        </footer>
    </main>
</div>
</body>
</html>
