<?php
$user = current_user();
$panelType = $panelType ?? 'vendor';
$groups = function_exists('ph_panel_groups') ? ph_panel_groups($panelType) : [];
$pageTitle = $pageTitle ?? ucfirst($panelType) . ' Dashboard';
$displayPageTitle = trim((string)preg_replace('/\s*\|.*$/', '', $pageTitle));
$panelDirectory = $panelType === 'affiliate' ? 'member' : $panelType;
$panelLabels = [
    'vendor' => ['Vendor Workspace', 'Products, orders, sales and shop operations', 'vendor/index.php'],
    'customer' => ['Customer Account', 'Orders, wallet, rewards and support', 'customer/dashboard.php'],
    'affiliate' => ['Marketing Member', 'Shop, referrals, team and commissions', 'member/index.php'],
];
$panelInfo = $panelLabels[$panelType] ?? [ucfirst($panelType) . ' Panel', 'Account workspace', $panelDirectory . '/index.php'];
$menuGroups = $groups;
$menuBasePath = $panelDirectory;
$sidebarTitle = $panelInfo[0];
$sidebarContext = $panelInfo[1];
$sidebarHome = url($panelInfo[2]);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="theme-color" content="#0B5FFF">
    <title><?= e($pageTitle . ' | ' . APP_NAME) ?></title>
    <link rel="icon" href="<?= asset('brand/favicon.svg') ?>">
    <link rel="stylesheet" href="<?= admin_asset('css/bootstrap.min.css') ?>">
    <link rel="stylesheet" href="<?= admin_asset('css/icons.css') ?>">
    <link rel="stylesheet" href="<?= asset('css/bootstrap-icons.min.css') ?>">
    <link rel="stylesheet" href="<?= admin_asset('css/app.css') ?>">
    <link rel="stylesheet" href="<?= asset('css/purchase-haat.css') ?>">
</head>
<body class="account-body bg-light">
<div class="panel-shell account-shell d-flex" data-account-shell>
    <?php require ROOT_PATH . '/app/Layouts/account_sidebar.php'; ?>
    <section class="admin-content account-content flex-grow-1">
        <header class="admin-topbar account-topbar">
            <div class="account-topbar-left">
                <button class="account-menu-toggle" type="button" data-account-sidebar-toggle aria-label="Open navigation" aria-controls="accountSidebar"><i class="bi bi-list"></i></button>
                <div class="account-page-heading">
                    <div class="account-breadcrumb"><a href="<?= e($sidebarHome) ?>"><?= e($sidebarTitle) ?></a><i class="bi bi-chevron-right"></i><span><?= e($displayPageTitle) ?></span></div>
                    <h1><?= e($displayPageTitle) ?></h1>
                </div>
            </div>
            <div class="account-topbar-actions">
                <a class="account-action-btn d-none d-md-inline-flex" href="<?= url('public/index.php') ?>" target="_blank" rel="noopener"><i class="bi bi-box-arrow-up-right"></i><span>View Site</span></a>
                <?php if ($panelType === 'vendor'): ?><a class="account-icon-btn" href="<?= url('vendor/notifications.php') ?>" title="Notifications" aria-label="Notifications"><i class="bi bi-bell"></i></a><?php endif; ?>
                <div class="dropdown">
                    <button class="account-user-menu" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <span class="account-avatar"><?= e(strtoupper(substr((string)($user['name'] ?? 'U'), 0, 1))) ?></span>
                        <span class="account-user-copy d-none d-sm-flex"><strong><?= e($user['name'] ?? ucfirst($panelType)) ?></strong><small><?= e($sidebarTitle) ?></small></span>
                        <i class="bi bi-chevron-down"></i>
                    </button>
                    <div class="dropdown-menu dropdown-menu-end account-user-dropdown">
                        <div class="account-user-dropdown-head"><strong><?= e($user['name'] ?? ucfirst($panelType)) ?></strong><small><?= e($user['email'] ?? '') ?></small></div>
                        <a class="dropdown-item" href="<?= e($sidebarHome) ?>"><i class="bi bi-speedometer2"></i> Dashboard</a>
                        <a class="dropdown-item" href="<?= url('public/index.php') ?>" target="_blank" rel="noopener"><i class="bi bi-box-arrow-up-right"></i> View website</a>
                        <div class="dropdown-divider"></div>
                        <form method="post" action="<?= url('public/logout.php') ?>"><?= csrf_field() ?><button class="dropdown-item text-danger" type="submit"><i class="bi bi-box-arrow-right"></i> Logout</button></form>
                    </div>
                </div>
            </div>
        </header>
        <main class="account-main">
            <?= install_notice_html() ?>
            <?php if ($msg = flash('success')): ?><div class="alert alert-success account-alert"><i class="bi bi-check-circle-fill"></i><span><?= e($msg) ?></span></div><?php endif; ?>
            <?php if ($msg = flash('error')): ?><div class="alert alert-danger account-alert"><i class="bi bi-exclamation-triangle-fill"></i><span><?= e($msg) ?></span></div><?php endif; ?>
