<?php
session_start();

require_once __DIR__ . '/../includes/helpers.php';
require_once __DIR__ . '/../includes/layout.php';

if (!isset($_SESSION['authenticated'])) {
    redirect(page_url('signin'));
}

$userId = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : null;
$userContext = current_user_context();
$displayName = trim((string) ($userContext['display_name'] ?? 'Expense user'));
if ($displayName === '') {
    $displayName = trim((string) ($userContext['email'] ?? 'Expense user'));
}

$workspace = trim((string) ($userContext['view_mini'] ?? 'GT'));
if ($workspace === '') {
    $workspace = 'GT';
}

$profileAvatar = trim((string) ($userContext['avatar_url'] ?? asset_url('images/img1.jpg')));
$profileEmail = trim((string) ($userContext['email'] ?? ''));
$organizations = current_user_organizations($userId ?? 0);
$currentOrganizationId = current_organization_id($userId ?? 0);
$currentRequestUri = trim((string) ($_SERVER['REQUEST_URI'] ?? ''));
if ($currentRequestUri === '') {
    $currentRequestUri = page_url('admin');
}

$trialText = trim((string) ($userContext['trial_text'] ?? 'Trial expires in 12 days.'));
$organization = current_organization($userId ?? 0);
$organizationName = trim((string) ($organization['organization_name'] ?? 'Your Organization'));
$orgLocation = trim((string) ($organization['organization_location'] ?? 'India'));

$sidebarItems = [
    ['icon' => 'fa-solid fa-house', 'label' => 'Home', 'href' => page_url('admin'), 'active' => true],
    ['icon' => 'fa-solid fa-compass', 'label' => 'Trips', 'href' => page_url('trips')],
    ['icon' => 'fa-regular fa-file-lines', 'label' => 'Reports', 'href' => page_url('reports')],
    ['icon' => 'fa-solid fa-folder-open', 'label' => 'Advances', 'href' => page_url('advances')],
    ['icon' => 'fa-solid fa-money-check-dollar', 'label' => 'Batch Payments', 'href' => route_url('advancepayments/gettingstarted/')],
    ['icon' => 'fa-regular fa-credit-card', 'label' => 'Corporate Cards', 'href' => page_url('cards')],
    ['icon' => 'fa-solid fa-vault', 'label' => 'Petty Cash Accounts', 'href' => page_url('organization')],
    ['icon' => 'fa-regular fa-calendar-check', 'label' => 'Budgets', 'href' => page_url('analytics')],
    ['icon' => 'fa-solid fa-chart-column', 'label' => 'Analytics', 'href' => page_url('analytics')],
    ['icon' => 'fa-solid fa-gear', 'label' => 'Settings', 'href' => page_url('admin_settings')],
];

$gettingStartedCards = [
    [
        'icon' => 'fa-solid fa-sliders',
        'title' => 'Expense Categories',
        'description' => 'Add and manage categories to categorize expenses and track business spend',
        'action' => 'Manage',
        'href' => page_url('my_settings', 'navType=preferences&dialog=expense-category'),
        'tone' => '',
        'helper' => '',
    ],
    [
        'icon' => 'fa-regular fa-window-restore',
        'title' => 'Preferences',
        'description' => 'Choose preferences and configure settings for each module based on organizational needs',
        'action' => 'Configure',
        'href' => page_url('admin_settings'),
        'tone' => '',
        'helper' => '',
    ],
    [
        'icon' => 'fa-solid fa-circle-exclamation',
        'title' => 'Policies',
        'description' => 'Create policies to define spending limits, mileage reimbursements, and per diem allowances.',
        'action' => 'Setup',
        'href' => page_url('organization'),
        'tone' => '',
        'helper' => '',
    ],
    [
        'icon' => 'fa-regular fa-credit-card',
        'title' => 'Corporate Cards',
        'description' => 'Connect and assign corporate cards to users and set up automatic import of card transactions',
        'action' => 'Configure',
        'href' => page_url('cards'),
        'tone' => '',
        'helper' => '',
    ],
    [
        'icon' => 'fa-regular fa-circle-user',
        'title' => 'Users',
        'description' => 'Invite users to this organization and assign roles that give them access to the necessary modules',
        'action' => 'Invite',
        'href' => page_url('organization'),
        'tone' => '',
        'helper' => 'Create departments',
    ],
    [
        'icon' => 'fa-solid fa-plug-circle-bolt',
        'title' => 'Integrations',
        'description' => 'Setup seamless integrations with other applications for added benefits',
        'action' => 'Connect',
        'href' => page_url('organization'),
        'tone' => '',
        'helper' => 'Connect to Xero',
    ],
];

$doMoreCards = [
    ['icon' => 'fa-regular fa-calendar-check', 'title' => 'Budgets', 'description' => 'Create and enforce budgets', 'href' => page_url('analytics')],
    ['icon' => 'fa-solid fa-link', 'title' => 'Links And Buttons', 'description' => 'Create buttons and redirect links', 'href' => page_url('admin_settings')],
    ['icon' => 'fa-solid fa-briefcase', 'title' => 'Report Automation', 'description' => 'Automate expense reporting', 'href' => page_url('reports')],
    ['icon' => 'fa-regular fa-window-maximize', 'title' => 'Modules', 'description' => 'Create new modules', 'href' => page_url('organization')],
    ['icon' => 'fa-solid fa-code-branch', 'title' => 'Workflow', 'description' => 'Automate process workflows', 'href' => page_url('organization')],
    ['icon' => 'fa-solid fa-bars-staggered', 'title' => 'Page Layouts', 'description' => 'Customize layout of forms', 'href' => page_url('admin_settings')],
];

$footerColumns = [
    'OTHER ZOHO APPS' => [
        ['label' => 'Accounting Software', 'href' => 'https://b2llab.in/website/'],
        ['label' => 'Ecommerce Software', 'href' => 'https://b2lmobitech.in/website/index.php'],
        ['label' => 'End-to-end Billing Solution', 'href' => 'https://b2llab.in/website/fieldservice.php'],
        ['label' => 'Invoice Software', 'href' => 'https://b2lmobitech.in/website/index.php'],
        ['label' => 'Inventory Management', 'href' => 'https://www.fieldcloud.in/Website/index.php'],
        ['label' => 'Payroll Software', 'href' => 'https://b2lmobitech.in/'],
        ['label' => 'HR Software', 'href' => 'https://b2lmobitech.in/'],
        ['label' => 'CRM & Other Apps', 'href' => 'https://b2lmobitech.in/'],
    ],
    'HELP & SUPPORT' => [
        ['label' => 'Contact Support', 'href' => 'https://fieldcloud.in/contactus.php'],
        ['label' => 'Request a Feature', 'href' => 'https://b2lmobitech.in/website/index.php'],
        ['label' => 'Help Documentation', 'href' => 'https://b2llab.in/website/'],
        ['label' => 'Register for Webinar', 'href' => 'https://b2lmobitech.in/'],
        ['label' => 'FAQ', 'href' => 'https://b2lmobitech.in/website/index.php'],
    ],
    'QUICK LINKS' => [
        ['label' => 'Features', 'href' => 'https://www.fieldcloud.in/Website/index.php'],
        ['label' => 'Integrations', 'href' => 'https://b2lmobitech.in/'],
        ['label' => 'Mobile Apps', 'href' => 'https://b2lmobitech.in/'],
        ['label' => 'Resources', 'href' => 'https://b2llab.in/website/'],
        ['label' => 'Essential Business Guides', 'href' => 'https://b2llab.in/website/'],
        ['label' => "What's New?", 'href' => 'https://b2lmobitech.in/website/index.php'],
    ],
];

render_header('Admin Dashboard | Expense', 'dashboard-page admin-dashboard-page');
?>
<div class="dashboard-shell admin-shell">
    <aside class="dashboard-sidebar admin-sidebar">
        <div class="sidebar-brand">
            <img src="<?= e(asset_url('images/b2l-logo.png')) ?>" alt="B2L Mobitech" class="sidebar-brand-logo">
        </div>

        <nav class="sidebar-nav" aria-label="Primary">
            <?php foreach ($sidebarItems as $item): ?>
                <a class="sidebar-link<?= !empty($item['active']) ? ' is-active' : '' ?>" href="<?= e($item['href']) ?>">
                    <i class="<?= e($item['icon']) ?>" aria-hidden="true"></i>
                    <span><?= e($item['label']) ?></span>
                </a>
            <?php endforeach; ?>
        </nav>

        <a class="sidebar-admin-switch" href="<?= e(page_url('dashboard')) ?>">
            <i class="fa-solid fa-user" aria-hidden="true"></i>
            <span>Switch to My View</span>
        </a>

        <button type="button" class="sidebar-collapse" aria-label="Collapse sidebar">
            <i class="fa-solid fa-arrow-left-long"></i>
        </button>
    </aside>

    <div class="dashboard-main admin-main">
        <header class="dashboard-topbar admin-topbar">
            <label class="dashboard-search">
                <i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
                <input type="search" placeholder="Search in Expenses ( / )" aria-label="Search in Expenses">
            </label>

            <div class="topbar-right">
                <div class="admin-topbar-trial"><?= e($trialText) ?> <a href="#">Upgrade Now</a></div>

                <button type="button" class="view-pill admin-view-pill" data-topbar-drawer-open="organizations" aria-expanded="false">
                    <span class="view-stack">
                        <span class="view-mini"><?= e($workspace) ?></span>
                        <strong>Admin View</strong>
                    </span>
                    <i class="fa-solid fa-chevron-down" aria-hidden="true"></i>
                </button>
                <span class="topbar-divider" aria-hidden="true"></span>

                <div class="topbar-quick-add" data-quick-add>
                    <button type="button" class="topbar-square primary" data-quick-add-toggle aria-haspopup="true" aria-expanded="false" aria-label="Quick add">
                        <i class="fa-solid fa-plus" aria-hidden="true"></i>
                    </button>
                    <div class="quick-add-menu" data-quick-add-menu aria-hidden="true">
                        <div class="quick-add-menu-header">QUICK ADD</div>
                        <a class="quick-add-menu-item" href="<?= e(route_url('trips/new/')) ?>">
                            <span class="quick-add-menu-icon"><i class="fa-solid fa-suitcase" aria-hidden="true"></i></span>
                            <span>Trip</span>
                        </a>
                        <a class="quick-add-menu-item" href="<?= e(route_url('expenses/new/')) ?>">
                            <span class="quick-add-menu-icon"><i class="fa-regular fa-credit-card" aria-hidden="true"></i></span>
                            <span>Expense</span>
                        </a>
                        <a class="quick-add-menu-item" href="<?= e(route_url('reports/new/')) ?>">
                            <span class="quick-add-menu-icon"><i class="fa-regular fa-file-lines" aria-hidden="true"></i></span>
                            <span>Report</span>
                        </a>
                        <a class="quick-add-menu-item" href="<?= e(route_url('advances/new/')) ?>">
                            <span class="quick-add-menu-icon"><i class="fa-solid fa-folder-open" aria-hidden="true"></i></span>
                            <span>Advance</span>
                        </a>
                    </div>
                </div>

                <button type="button" class="topbar-icon" data-topbar-drawer-open="users" aria-expanded="false" aria-label="Delegates">
                    <i class="fa-solid fa-user-group" aria-hidden="true"></i>
                </button>

                <button type="button" class="topbar-icon" data-topbar-drawer-open="notifications" aria-expanded="false" aria-label="Notifications">
                    <i class="fa-solid fa-bell" aria-hidden="true"></i>
                </button>

                <a class="topbar-icon topbar-icon-link" href="<?= e(page_url('admin_settings')) ?>" aria-label="Settings">
                    <i class="fa-solid fa-gear" aria-hidden="true"></i>
                </a>

                <button type="button" class="avatar-button" data-topbar-drawer-open="profile" aria-expanded="false" aria-label="Open profile menu">
                    <img src="<?= e($profileAvatar) ?>" alt="" class="avatar-image">
                </button>

                <button type="button" class="topbar-icon topbar-icon--launcher" data-topbar-drawer-open="apps" aria-expanded="false" aria-label="Apps launcher">
                    <span class="topbar-launcher" aria-hidden="true">
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                        <span></span>
                    </span>
                </button>
            </div>
        </header>

        <div class="topbar-drawer topbar-drawer--organizations" data-topbar-drawer="organizations" aria-hidden="true">
            <button type="button" class="topbar-drawer-backdrop" data-topbar-drawer-close aria-label="Close organizations panel"></button>
            <aside class="topbar-drawer-panel" role="dialog" aria-modal="true" aria-label="My Organizations">
                <button type="button" class="topbar-drawer-close" data-topbar-drawer-close aria-label="Close">
                    <i class="fa-solid fa-xmark" aria-hidden="true"></i>
                </button>
                <div class="topbar-drawer-header topbar-drawer-header--between">
                    <h2>My Organizations</h2>
                    <a href="<?= e(page_url('organization')) ?>" class="org-drawer-manage-link"><i class="fa-solid fa-gear" aria-hidden="true"></i><span>Manage</span></a>
                </div>
                <label class="topbar-drawer-search org-drawer-search">
                    <i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
                    <input type="search" data-org-search-input placeholder="Search Organizations" aria-label="Search Organizations">
                </label>
                <div class="org-drawer-list" data-org-drawer-list>
                    <?php foreach ($organizations as $organizationRow): ?>
                        <?php $organizationId = (int) ($organizationRow['id'] ?? 0); ?>
                        <a
                            class="org-drawer-card<?= $organizationId === $currentOrganizationId ? ' is-current' : '' ?>"
                            href="<?= e(page_url('organization', 'action=switch&id=' . $organizationId . '&redirect=' . urlencode($currentRequestUri))) ?>"
                            data-org-drawer-item
                            data-org-name="<?= e(strtolower((string) ($organizationRow['organization_name'] ?? ''))) ?>"
                        >
                            <div class="org-drawer-card-icon"><i class="fa-regular fa-building" aria-hidden="true"></i></div>
                            <div class="org-drawer-card-copy">
                                <strong><?= e((string) ($organizationRow['organization_name'] ?? 'Organization')) ?></strong>
                                <span>Organization ID: <?= e((string) $organizationId) ?></span>
                                <small>TRIAL</small>
                            </div>
                            <?php if ($organizationId === $currentOrganizationId): ?>
                                <div class="org-drawer-card-check"><i class="fa-solid fa-check" aria-hidden="true"></i></div>
                            <?php endif; ?>
                        </a>
                    <?php endforeach; ?>
                </div>
                <div class="org-drawer-empty" data-org-search-empty>No organizations matched your search.</div>
            </aside>
        </div>

        <div class="topbar-drawer topbar-drawer--users" data-topbar-drawer="users" aria-hidden="true">
            <button type="button" class="topbar-drawer-backdrop" data-topbar-drawer-close aria-label="Close delegates panel"></button>
            <aside class="topbar-drawer-panel" role="dialog" aria-modal="true" aria-label="Delegates">
                <button type="button" class="topbar-drawer-close" data-topbar-drawer-close aria-label="Close">
                    <i class="fa-solid fa-xmark" aria-hidden="true"></i>
                </button>
                <div class="topbar-drawer-header">
                    <h2>Delegated To Me</h2>
                </div>
                <div class="topbar-drawer-empty" style="min-height: 180px;">
                    <div class="topbar-drawer-empty-icon">
                        <i class="fa-regular fa-circle-user" aria-hidden="true"></i>
                    </div>
                    <p>0 users</p>
                </div>
            </aside>
        </div>

        <div class="topbar-drawer topbar-drawer--notifications" data-topbar-drawer="notifications" aria-hidden="true">
            <button type="button" class="topbar-drawer-backdrop" data-topbar-drawer-close aria-label="Close notifications panel"></button>
            <aside class="topbar-drawer-panel" role="dialog" aria-modal="true" aria-label="Notifications">
                <button type="button" class="topbar-drawer-close" data-topbar-drawer-close aria-label="Close">
                    <i class="fa-solid fa-xmark" aria-hidden="true"></i>
                </button>
                <div class="topbar-drawer-header">
                    <h2>Notifications</h2>
                    <button type="button" class="topbar-drawer-filter">
                        Unread
                        <i class="fa-solid fa-caret-down" aria-hidden="true"></i>
                    </button>
                </div>
                <div class="topbar-drawer-note-row">
                    <div>
                        <strong>Desktop Notifications</strong>
                        <span>Stay up to date while you work.</span>
                    </div>
                    <a href="#">Enable</a>
                </div>
                <div class="topbar-drawer-empty">
                    <div class="topbar-drawer-empty-icon">
                        <i class="fa-regular fa-bell" aria-hidden="true"></i>
                    </div>
                    <p>Uhh... You don't have any notifications at the moment.</p>
                </div>
            </aside>
        </div>

        <div class="topbar-drawer topbar-drawer--profile" data-topbar-drawer="profile" aria-hidden="true">
            <button type="button" class="topbar-drawer-backdrop" data-topbar-drawer-close aria-label="Close profile panel"></button>
            <aside class="topbar-drawer-panel" role="dialog" aria-modal="true" aria-label="Profile menu">
                <button type="button" class="topbar-drawer-close" data-topbar-drawer-close aria-label="Close">
                    <i class="fa-solid fa-xmark" aria-hidden="true"></i>
                </button>

                <div class="topbar-drawer-card">
                    <img src="<?= e($profileAvatar) ?>" alt="" class="topbar-drawer-avatar">
                    <div>
                        <strong><?= e($displayName) ?></strong>
                        <span><?= e($profileEmail) ?></span>
                        <div class="topbar-drawer-account-links">
                            <a href="<?= e(page_url('admin_settings')) ?>">My Account</a>
                            <span aria-hidden="true">&bull;</span>
                            <a href="<?= e(page_url('logout')) ?>">Sign Out</a>
                        </div>
                    </div>
                </div>

                <div class="topbar-drawer-section">
                    <div class="topbar-drawer-note-row">
                        <div>
                            <strong>Delegated To Me</strong>
                            <span>0 users</span>
                        </div>
                        <a href="#">Open</a>
                    </div>
                </div>

                <div class="topbar-drawer-section">
                    <div class="topbar-drawer-links">
                        <a href="<?= e(route_url('home/gettingstarted/help-documentation/')) ?>"><i class="fa-regular fa-circle-question" aria-hidden="true"></i><span>Help &amp; Support</span></a>
                        <a href="<?= e(route_url('home/gettingstarted/take-a-tour/')) ?>"><i class="fa-regular fa-compass" aria-hidden="true"></i><span>Take a Tour</span></a>
                        <a href="#"><i class="fa-regular fa-comment-dots" aria-hidden="true"></i><span>Share Feedback</span></a>
                        <a href="#"><i class="fa-regular fa-keyboard" aria-hidden="true"></i><span>View Keyboard Shortcuts</span> <span class="topbar-drawer-badge">New</span></a>
                        <a href="#"><i class="fa-regular fa-calendar" aria-hidden="true"></i><span>Webinar</span></a>
                    </div>
                </div>

                <div class="topbar-drawer-section">
                    <div class="topbar-drawer-links">
                        <a href="<?= e(route_url('home/gettingstarted/request-feature/')) ?>"><i class="fa-regular fa-lightbulb" aria-hidden="true"></i><span>Request a Feature</span></a>
                        <a href="<?= e(route_url('home/gettingstarted/request-demo/')) ?>"><i class="fa-regular fa-file-lines" aria-hidden="true"></i><span>Request a Demo</span></a>
                        <a href="#"><i class="fa-regular fa-phone" aria-hidden="true"></i><span>Request a Call</span></a>
                        <a href="<?= e(route_url('support/contact/')) ?>"><i class="fa-solid fa-headphones-simple" aria-hidden="true"></i><span>Contact Support</span></a>
                    </div>
                </div>
            </aside>
        </div>

        <div class="topbar-drawer topbar-drawer--apps" data-topbar-drawer="apps" aria-hidden="true">
            <button type="button" class="topbar-drawer-backdrop" data-topbar-drawer-close aria-label="Close apps panel"></button>
            <aside class="topbar-drawer-panel topbar-drawer-panel--apps" role="dialog" aria-modal="true" aria-label="All B2L Mobitech apps">
                <button type="button" class="topbar-drawer-close" data-topbar-drawer-close aria-label="Close">
                    <i class="fa-solid fa-xmark" aria-hidden="true"></i>
                </button>
                <div class="topbar-drawer-header topbar-drawer-header--apps">
                    <h2>All B2L Mobitech Apps</h2>
                    <button type="button" class="topbar-drawer-search-toggle" aria-label="Search apps">
                        <i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
                    </button>
                </div>
                <label class="topbar-drawer-search">
                    <i class="fa-solid fa-magnifying-glass" aria-hidden="true"></i>
                    <input type="search" data-app-search placeholder="Search apps" aria-label="Search apps">
                </label>

                <section class="topbar-drawer-section" data-app-section>
                    <div class="topbar-drawer-section-label">Finance Apps</div>
                    <div class="topbar-drawer-app-grid">
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-book-bookmark" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Books</strong>
                                <small>Online Accounting Software</small>
                            </span>
                        </a>
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-receipt" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Billing</strong>
                                <small>End-to-end Billing Solution</small>
                            </span>
                        </a>
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-boxes-stacked" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Inventory</strong>
                                <small>Order &amp; Inventory Management Software</small>
                            </span>
                        </a>
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-wallet" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Checkout</strong>
                                <small>One-time and recurring payments software</small>
                            </span>
                        </a>
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-cart-shopping" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Commerce</strong>
                                <small>Ecommerce software</small>
                            </span>
                        </a>
                        <a href="#" class="topbar-app-item" data-app-item>
                            <i class="fa-solid fa-file-invoice-dollar" aria-hidden="true"></i>
                            <span class="topbar-app-item-text">
                                <strong>B2L Mobitech Payroll</strong>
                                <small>Simplified Payroll Management Software</small>
                            </span>
                        </a>
                    </div>
                </section>

                <section class="topbar-drawer-section" data-app-section>
                    <div class="topbar-drawer-section-label">Email and Collaboration</div>
                    <div class="topbar-drawer-app-grid topbar-drawer-app-grid--compact">
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-book"></i><span class="topbar-app-item-text"><strong>Notebook</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-circle-play"></i><span class="topbar-app-item-text"><strong>Meeting</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-diagram-project"></i><span class="topbar-app-item-text"><strong>Projects</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-pen-nib"></i><span class="topbar-app-item-text"><strong>Sign</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-jet-fighter-up"></i><span class="topbar-app-item-text"><strong>Sprints</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-inbox"></i><span class="topbar-app-item-text"><strong>TeamInbox</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-envelope"></i><span class="topbar-app-item-text"><strong>Mail</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-comment-dots"></i><span class="topbar-app-item-text"><strong>Cliq</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-table"></i><span class="topbar-app-item-text"><strong>Sheet</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-clapperboard"></i><span class="topbar-app-item-text"><strong>Show</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-file-lines"></i><span class="topbar-app-item-text"><strong>Writer</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-circle-nodes"></i><span class="topbar-app-item-text"><strong>Connect</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-vault"></i><span class="topbar-app-item-text"><strong>Vault</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-folder-open"></i><span class="topbar-app-item-text"><strong>WorkDrive</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-graduation-cap"></i><span class="topbar-app-item-text"><strong>Learn</strong></span></a>
                    </div>
                </section>

                <section class="topbar-drawer-section" data-app-section>
                    <div class="topbar-drawer-section-label">Help Desk and Customer Support</div>
                    <div class="topbar-drawer-app-grid topbar-drawer-app-grid--compact">
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-headset"></i><span class="topbar-app-item-text"><strong>Desk</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-camera-retro"></i><span class="topbar-app-item-text"><strong>Lens</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-user-shield"></i><span class="topbar-app-item-text"><strong>Assist</strong></span></a>
                    </div>
                </section>

                <section class="topbar-drawer-section" data-app-section>
                    <div class="topbar-drawer-section-label">Human Resources</div>
                    <div class="topbar-drawer-app-grid topbar-drawer-app-grid--compact">
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-users"></i><span class="topbar-app-item-text"><strong>People</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-user-plus"></i><span class="topbar-app-item-text"><strong>Recruit</strong></span></a>
                    </div>
                </section>

                <section class="topbar-drawer-section" data-app-section>
                    <div class="topbar-drawer-section-label">Business Process</div>
                    <div class="topbar-drawer-app-grid topbar-drawer-app-grid--compact">
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-chart-line"></i><span class="topbar-app-item-text"><strong>Analytics</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-cube"></i><span class="topbar-app-item-text"><strong>Creator</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-code-branch"></i><span class="topbar-app-item-text"><strong>Flow</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-circle-half-stroke"></i><span class="topbar-app-item-text"><strong>Qntrl</strong></span></a>
                        <a href="#" class="topbar-app-item topbar-app-item--compact" data-app-item><i class="fa-solid fa-wand-magic-sparkles"></i><span class="topbar-app-item-text"><strong>DataPrep</strong></span></a>
                    </div>
                </section>
            </aside>
        </div>

        <main class="dashboard-content admin-dashboard-content">
            <section class="admin-dashboard-hero-card">
                <div class="admin-dashboard-hero-user">
                    <div class="admin-dashboard-hero-icon">
                        <i class="fa-regular fa-copy" aria-hidden="true"></i>
                    </div>
                    <div>
                        <h1>Hello, <?= e($displayName) ?></h1>
                        <p><?= e($workspace) ?></p>
                    </div>
                </div>
                <div class="admin-dashboard-hero-help">
                    <strong>Zoho Expense <?= e($orgLocation) ?> Helpline : 18005692747</strong>
                    <span>Monday to Friday • 9:00 AM to 7:00 PM</span>
                </div>
            </section>

            <nav class="admin-dashboard-tabs" aria-label="Admin sections">
                <a href="#" class="admin-dashboard-tab">Dashboard</a>
                <a href="#" class="admin-dashboard-tab is-active">Getting Started</a>
                <a href="#" class="admin-dashboard-tab">Announcements</a>
                <a href="#" class="admin-dashboard-tab">Recent Updates</a>
            </nav>

            <section class="admin-dashboard-panel admin-dashboard-panel--welcome">
                <div class="admin-dashboard-panel-icon admin-dashboard-panel-icon--navy">
                    <i class="fa-solid fa-compass-drafting" aria-hidden="true"></i>
                </div>
                <div class="admin-dashboard-panel-copy">
                    <h2>Welcome <?= e($displayName) ?>! You are in Admin View.</h2>
                    <p>Learn to manage organizational business travel and spend for <?= e($organizationName !== '' ? $organizationName : 'your workspace') ?>.</p>
                </div>
            </section>

            <section class="admin-dashboard-panel admin-dashboard-panel--support">
                <div class="admin-dashboard-panel-icon admin-dashboard-panel-icon--amber">
                    <i class="fa-solid fa-headset" aria-hidden="true"></i>
                </div>
                <div class="admin-dashboard-panel-copy">
                    <h2>2 hours of <span>FREE</span> Rapid Setup Assistance!</h2>
                    <p>Our product consultants will help you configure Zoho Expense based on your requirements.</p>
                </div>
                <a class="admin-dashboard-panel-button" href="#">Contact Support</a>
            </section>

            <section class="admin-dashboard-group">
                <header class="admin-dashboard-group-title">Let's get started!</header>
                <div class="admin-dashboard-card-list">
                    <?php foreach ($gettingStartedCards as $card): ?>
                        <article class="admin-admin-card">
                            <div class="admin-admin-card-icon">
                                <i class="<?= e($card['icon']) ?>" aria-hidden="true"></i>
                            </div>
                            <div class="admin-admin-card-copy">
                                <h3><?= e($card['title']) ?></h3>
                                <p><?= e($card['description']) ?></p>
                                <?php if ($card['helper'] !== ''): ?>
                                    <a href="<?= e($card['href']) ?>" class="admin-admin-card-helper"><?= e($card['helper']) ?></a>
                                <?php endif; ?>
                            </div>
                            <a class="admin-admin-card-action" href="<?= e($card['href']) ?>"><?= e($card['action']) ?></a>
                        </article>
                    <?php endforeach; ?>
                </div>
            </section>

            <section class="admin-dashboard-group admin-dashboard-group--do-more">
                <header class="admin-dashboard-do-more-head">
                    <div class="admin-dashboard-do-more-icon">
                        <i class="fa-solid fa-sparkles" aria-hidden="true"></i>
                    </div>
                    <h2>Do more</h2>
                </header>

                <div class="admin-dashboard-do-more-grid">
                    <?php foreach ($doMoreCards as $card): ?>
                        <a class="admin-do-more-card" href="<?= e($card['href']) ?>">
                            <div class="admin-do-more-card-icon">
                                <i class="<?= e($card['icon']) ?>" aria-hidden="true"></i>
                            </div>
                            <div class="admin-do-more-card-copy">
                                <h3><?= e($card['title']) ?></h3>
                                <p><?= e($card['description']) ?></p>
                            </div>
                            <div class="admin-do-more-card-arrow">
                                <i class="fa-solid fa-arrow-right" aria-hidden="true"></i>
                            </div>
                        </a>
                    <?php endforeach; ?>
                </div>
            </section>

            <section class="footer-links footer-links--b2l admin-footer-links">
                <?php foreach ($footerColumns as $title => $links): ?>
                    <article>
                        <h4><?= e($title) ?></h4>
                        <ul>
                            <?php foreach ($links as $link): ?>
                                <?php
                                    $label = (string) ($link['label'] ?? '');
                                    $href = trim((string) ($link['href'] ?? '#'));
                                ?>
                                <li>
                                    <a href="<?= e($href) ?>"<?= str_starts_with($href, 'http') ? ' target="_blank" rel="noopener noreferrer"' : '' ?>><?= e($label) ?></a>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </article>
                <?php endforeach; ?>
            </section>

            <footer class="dashboard-footer admin-dashboard-footer">
                &copy; 2026, Zoho Corporation Pvt. Ltd. All Rights Reserved.
            </footer>
        </main>
    </div>
</div>
<?php render_footer(); ?>
