<?php
$billingActiveNav = isset($billingActiveNav) ? (string) $billingActiveNav : 'home';
$currentScript = basename((string) ($_SERVER['PHP_SELF'] ?? ''));
$currentTab = (string) ($_GET['tab'] ?? '');
$gettingStartedActive = $currentScript === 'dashboard.php' && $currentTab === 'getting-started';
$catalogNavs = ['items', 'plans', 'addons', 'coupons', 'pricing_widgets'];
$salesNavs = ['quotes', 'invoices', 'subscriptions', 'delivery_challans', 'credit_notes'];
$paymentNavs = ['payments_received'];
$expenseNavs = ['expenses', 'recurring_expenses'];
$timeTrackingNavs = ['projects', 'timesheet'];
$catalogOpen = in_array($billingActiveNav, $catalogNavs, true);
$salesOpen = in_array($billingActiveNav, $salesNavs, true);
$paymentsOpen = in_array($billingActiveNav, $paymentNavs, true);
$expensesOpen = in_array($billingActiveNav, $expenseNavs, true);
$timeTrackingOpen = in_array($billingActiveNav, $timeTrackingNavs, true);
?>
<aside class="sidebar">
    <div class="sidebar-brand">
        <img class="sidebar-brand-logo" src="/Payslip_Project/images/b2l_mobitech_pvt_ltd_logo.jpg" alt="b2lmobitech logo">
        <span>b2lmobitech</span>
    </div>

    <div class="sidebar-section">
        <a class="sidebar-link sidebar-link--muted <?php echo $gettingStartedActive ? 'is-active' : ''; ?>" href="dashboard.php?tab=getting-started"><i class="fa-solid fa-wand-magic-sparkles"></i><span>Getting Started</span><i class="fa-solid fa-angle-right sidebar-link-caret"></i></a>
    </div>

    <div class="sidebar-section">
        <a class="sidebar-link <?php echo $billingActiveNav === 'home' ? 'is-active' : ''; ?>" href="dashboard.php?tab=dashboard" data-tour="welcome"><i class="fa-solid fa-house"></i><span>Home</span></a>
        <a class="sidebar-link <?php echo $billingActiveNav === 'customers' ? 'is-active' : ''; ?>" href="customers.php" data-tour="customers"><i class="fa-regular fa-user"></i><span>Customers</span><?php if ($billingActiveNav === 'customers'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
        <div class="sidebar-dropdown <?php echo $catalogOpen ? 'is-open is-active' : ''; ?>" data-tour="catalog">
            <a class="sidebar-dropdown-trigger" href="items.php"><i class="fa-solid fa-angle-right sidebar-dropdown-caret"></i><i class="fa-solid fa-box-open"></i><span>Product Catalog</span></a>
            <div class="sidebar-dropdown-menu">
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'items' ? 'is-active' : ''; ?>" href="items.php"><span>Items</span><?php if ($billingActiveNav === 'items'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'plans' ? 'is-active' : ''; ?>" href="plans.php"><span>Plans</span><?php if ($billingActiveNav === 'plans'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'addons' ? 'is-active' : ''; ?>" href="addons.php"><span>Addons</span><?php if ($billingActiveNav === 'addons'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'coupons' ? 'is-active' : ''; ?>" href="coupons.php"><span>Coupons</span><?php if ($billingActiveNav === 'coupons'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'pricing_widgets' ? 'is-active' : ''; ?>" href="pricing_widgets.php"><span>Pricing Widgets</span><?php if ($billingActiveNav === 'pricing_widgets'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
            </div>
        </div>
        <div class="sidebar-dropdown <?php echo $salesOpen ? 'is-open is-active' : ''; ?>" data-tour="sales">
            <a class="sidebar-dropdown-trigger" href="quotes.php"><i class="fa-solid fa-angle-right sidebar-dropdown-caret"></i><i class="fa-solid fa-cart-shopping"></i><span>Sales</span></a>
            <div class="sidebar-dropdown-menu">
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'quotes' ? 'is-active' : ''; ?>" href="quotes.php"><span>Quotes</span><?php if ($billingActiveNav === 'quotes'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'invoices' ? 'is-active' : ''; ?>" href="invoices.php"><span>Invoices</span><?php if ($billingActiveNav === 'invoices'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'subscriptions' ? 'is-active' : ''; ?>" href="subscriptions.php"><span>Subscriptions</span><?php if ($billingActiveNav === 'subscriptions'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'delivery_challans' ? 'is-active' : ''; ?>" href="delivery_challans.php"><span>Delivery Challans</span><?php if ($billingActiveNav === 'delivery_challans'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'credit_notes' ? 'is-active' : ''; ?>" href="credit_notes.php"><span>Credit Notes</span><?php if ($billingActiveNav === 'credit_notes'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
            </div>
        </div>
        <div class="sidebar-dropdown <?php echo $paymentsOpen ? 'is-open is-active' : ''; ?>">
            <a class="sidebar-dropdown-trigger" href="payments_received.php"><i class="fa-solid fa-angle-right sidebar-dropdown-caret"></i><i class="fa-regular fa-credit-card"></i><span>Payments</span></a>
            <div class="sidebar-dropdown-menu">
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'payments_received' ? 'is-active' : ''; ?>" href="payments_received.php"><span>Payments Received</span><?php if ($billingActiveNav === 'payments_received'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
            </div>
        </div>
        <div class="sidebar-dropdown <?php echo $expensesOpen ? 'is-open is-active' : ''; ?>">
            <a class="sidebar-dropdown-trigger" href="expenses.php"><i class="fa-solid fa-angle-right sidebar-dropdown-caret"></i><i class="fa-regular fa-file-lines"></i><span>Expenses</span></a>
            <div class="sidebar-dropdown-menu">
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'expenses' ? 'is-active' : ''; ?>" href="expenses.php"><span>Expenses</span><?php if ($billingActiveNav === 'expenses'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'recurring_expenses' ? 'is-active' : ''; ?>" href="recurring_expenses.php"><span>Recurring Expenses</span><?php if ($billingActiveNav === 'recurring_expenses'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
            </div>
        </div>

        <div class="sidebar-dropdown <?php echo $timeTrackingOpen ? 'is-open is-active' : ''; ?>" data-tour="timetracking">
            <a class="sidebar-dropdown-trigger" href="projects.php"><i class="fa-solid fa-angle-right sidebar-dropdown-caret"></i><i class="fa-regular fa-clock"></i><span>Time Tracking</span></a>
            <div class="sidebar-dropdown-menu">
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'projects' ? 'is-active' : ''; ?>" href="projects.php"><span>Projects</span><?php if ($billingActiveNav === 'projects'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
                <a class="sidebar-sublink <?php echo $billingActiveNav === 'timesheet' ? 'is-active' : ''; ?>" href="timesheet.php"><span>Timesheet</span><?php if ($billingActiveNav === 'timesheet'): ?><i class="fa-solid fa-plus sidebar-inline-plus"></i><?php endif; ?></a>
            </div>
        </div>

        <a class="sidebar-link <?php echo $billingActiveNav === 'events' ? 'is-active' : ''; ?>" href="events.php"><i class="fa-regular fa-calendar"></i><span>Events</span></a>
        <a class="sidebar-link <?php echo $billingActiveNav === 'reports' ? 'is-active' : ''; ?>" href="reports.php"><i class="fa-solid fa-chart-column"></i><span>Reports</span></a>
        <a class="sidebar-link <?php echo $billingActiveNav === 'documents' ? 'is-active' : ''; ?>" href="documents.php"><i class="fa-regular fa-folder-open"></i><span>Documents</span></a>
    </div>

    <div class="sidebar-apps">
        <span>APPS</span>
        <a class="sidebar-link <?php echo $billingActiveNav === 'zoho_payments' ? 'is-active' : ''; ?>" href="zoho_payments.php"><i class="fa-regular fa-credit-card"></i><span>b2lmobitech Payments</span></a>
    </div>
</aside>
