<?php
$controller_name = $controller->_get->toString('controller');
$action_name = $controller->_get->toString('action');

// Dashboard
$isScriptDashboard = in_array($controller_name, array('pjAdmin')) && in_array($action_name, array('pjActionIndex'));

// Bookings
$isScriptBookingsController = in_array($controller_name, array('pjAdminOrders'));
$isScriptBookings = $isScriptBookingsController && in_array($action_name, array('pjActionIndex', 'pjActionCreate', 'pjActionUpdate'));

// Clients
$isScriptClientsController       = in_array($controller_name, array('pjAdminClients'));

// Products
$isScriptProductsController       = in_array($controller_name, array('pjAdminProducts'));
$isScriptProducts = $isScriptProductsController && in_array($action_name, array('pjActionIndex', 'pjActionCreate', 'pjActionUpdate'));
$isScriptProductStock = $isScriptProductsController && in_array($action_name, array('pjActionStock'));
$isScriptProductImport = $isScriptProductsController && in_array($action_name, array('pjActionImportProduct'));

// Categories
$isScriptCategoriesController     = in_array($controller_name, array('pjAdminCategories'));

// Reports
$isScriptReportsController     = in_array($controller_name, array('pjAdminReports'));

// Vouchers
$isScriptVouchersController     = in_array($controller_name, array('pjAdminVouchers'));

// Payments
$isScriptPaymentsController = in_array($controller_name, array('pjPayments'));

// Settings
// $isScriptOptionsController = in_array($controller_name, array('pjAdminOptions')) && !in_array($action_name, array('pjActionPreview', 'pjActionInstall'));
$isScriptProfile = $controller_name == 'pjAdminProfile' && $action_name == 'pjActionIndex';
$isScriptOptionsController =
    $controller_name == 'pjAdminOptions'
    && in_array($action_name, array(
        'pjActionBooking',
        'pjActionBookingForm',
        'pjActionShippingTax',
        'pjActionTerm',
        'pjActionNotifications',
        'pjActionInvoiceTemplate',
        'pjActionPreviewInvoiceTemplate',
        'pjActionResetInvoiceTemplate'
    ));
// Invoices
$isScriptInvoiceController = in_array($controller_name, array('pjInvoice'));
$isScriptInvoiceTemplate = $controller_name == 'pjAdminOptions' && in_array($action_name, array('pjActionInvoiceTemplate', 'pjActionPreviewInvoiceTemplate', 'pjActionResetInvoiceTemplate'));

$isScriptOptionsBooking         = $isScriptOptionsController && in_array($action_name, array('pjActionBooking'));
$isScriptOptionsBookingForm     = $isScriptOptionsController && in_array($action_name, array('pjActionBookingForm'));
$isScriptOptionsShippingTax     = $isScriptOptionsController && in_array($action_name, array('pjActionShippingTax'));
$isScriptOptionsTerm            = $isScriptOptionsController && in_array($action_name, array('pjActionTerm'));
$isScriptOptionsNotifications   = $isScriptOptionsController && in_array($action_name, array('pjActionNotifications'));

// Appearance
$isScriptOptionsPreview         = in_array($controller_name, array('pjAdminOptions')) && $action_name === 'pjActionPreview';
$isScriptOptionsGrid            = in_array($controller_name, array('pjAdminOptions')) && $action_name === 'pjActionGrid';
$isScriptImageSettings          = in_array($controller_name, array('pjBaseOptions')) && $action_name === 'pjActionImages';
$isScriptVisualBranding         = in_array($controller_name, array('pjBaseOptions')) && $action_name === 'pjActionVisual';
$isScriptAppearance             = $isScriptOptionsPreview || $isScriptOptionsGrid || $isScriptImageSettings || $isScriptVisualBranding;


// Permissions - Dashboard
$hasAccessScriptDashboard = pjAuth::factory('pjAdmin', 'pjActionIndex')->hasAccess();

// Permissions - Bookings
$hasAccessScriptBookings            = pjAuth::factory('pjAdminOrders')->hasAccess();
$hasAccessScriptBookingsIndex       = pjAuth::factory('pjAdminOrders', 'pjActionIndex')->hasAccess();

// Permissions - Clients
$hasAccessScriptClients        = pjAuth::factory('pjAdminClients')->hasAccess();
$hasAccessScriptClientsIndex   = pjAuth::factory('pjAdminClients', 'pjActionIndex')->hasAccess();

// Permissions - Products
$hasAccessScriptProducts  = pjAuth::factory('pjAdminProducts')->hasAccess();
$hasAccessScriptProductsIndex  = pjAuth::factory('pjAdminProducts', 'pjActionIndex')->hasAccess();
$hasAccessScriptStockIndex  = pjAuth::factory('pjAdminProducts', 'pjActionStock')->hasAccess();
$hasAccessScriptProductImport  = pjAuth::factory('pjAdminProducts', 'pjActionImportProduct')->hasAccess();

// Permissions - Categories
$hasAccessScriptCategories            = pjAuth::factory('pjAdminCategories', 'pjActionIndex')->hasAccess();

// Permissions - Reports
$hasAccessScriptReports                = pjAuth::factory('pjAdminReports', 'pjActionIndex')->hasAccess();

// Permissions - Vouchers
$hasAccessScriptVouchers                = pjAuth::factory('pjAdminVouchers', 'pjActionIndex')->hasAccess();

// Permissions - Settings
$hasAccessScriptProfile                 = pjAuth::factory('pjAdminProfile', 'pjActionIndex')->hasAccess();
$hasAccessScriptOptions                 = pjAuth::factory('pjAdminOptions')->hasAccess();
$hasAccessScriptOptionsBooking          = pjAuth::factory('pjAdminOptions', 'pjActionBooking')->hasAccess();
$hasAccessScriptOptionsBookingForm      = pjAuth::factory('pjAdminOptions', 'pjActionBookingForm')->hasAccess();
$hasAccessScriptOptionsShippingTax      = pjAuth::factory('pjAdminOptions', 'pjActionShippingTax')->hasAccess();
$hasAccessScriptOptionsTerm             = pjAuth::factory('pjAdminOptions', 'pjActionTerm')->hasAccess();
$hasAccessScriptOptionsNotifications    = pjAuth::factory('pjAdminOptions', 'pjActionNotifications')->hasAccess();

// Permissions - Payments
$hasAccessScriptPayments = pjAuth::factory('pjPayments', 'pjActionIndex')->hasAccess();

// Permissions - Invoices
$hasAccessScriptInvoices = pjAuth::factory('pjInvoice')->hasAccess();

// Permissions - Display
$hasAccessScriptPreview = pjAuth::factory('pjAdminOptions', 'pjActionPreview')->hasAccess();
$hasAccessScriptVisual = pjAuth::factory('pjBaseOptions', 'pjActionVisual')->hasAccess();
$hasAccessScriptGrid = pjAuth::factory('pjAdminOptions', 'pjActionGrid')->hasAccess();
$hasAccessScriptImages = pjAuth::factory('pjBaseOptions', 'pjActionIndex')->hasAccess();

?>

<?php if ($hasAccessScriptDashboard): ?>
    <li<?php echo $isScriptDashboard ? ' class="active"' : NULL; ?>>
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdmin&amp;action=pjActionIndex"><i class="fa fa-th-large"></i> <span class="nav-label"><?php __('plugin_base_menu_dashboard'); ?></span></a>
        </li>
    <?php endif; ?>

    <?php if ($hasAccessScriptBookingsIndex || $hasAccessScriptInvoices): ?>
        <li<?php echo $isScriptBookings || $isScriptInvoiceController ? ' class="active"' : NULL; ?>>
            <a href="#"><i class="fa fa-list"></i> <span class="nav-label"><?php __('menuOrders'); ?></span><span class="fa arrow"></span></a>
            <ul class="nav nav-second-level collapse">
                <?php if ($hasAccessScriptBookingsIndex): ?>
                    <li<?php echo $isScriptBookings ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOrders&amp;action=pjActionIndex"><i class="fa fa-list-ul"></i> <?php $lbl = __('menuAllOrders', true);
                                                                                                                                                                                                                    echo !empty($lbl) && $lbl !== 'menuAllOrders' ? htmlspecialchars($lbl) : 'All orders'; ?></a></li>
                    <?php endif; ?>
                    <?php if ($hasAccessScriptInvoices): ?>
                        <li<?php echo $isScriptInvoiceController ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjInvoice&amp;action=pjActionInvoices"><i class="fa fa-file-text-o"></i> <?php __('plugin_invoice_menu_invoices'); ?></a></li>
                        <?php endif; ?>
            </ul>
            </li>
        <?php endif; ?>

        <?php if ($hasAccessScriptClientsIndex): ?>
            <li<?php echo $isScriptClientsController ? ' class="active"' : NULL; ?>>
                <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminClients&amp;action=pjActionIndex"><i class="fa fa-user"></i> <span class="nav-label"><?php __('menuClients'); ?></span></a>
                </li>
            <?php endif; ?>

            <?php if ($hasAccessScriptProductsIndex || $hasAccessScriptStockIndex || $hasAccessScriptProductImport || $hasAccessScriptCategories): ?>
                <li<?php echo $isScriptProducts || $isScriptProductStock || $isScriptProductImport || $isScriptCategoriesController ? ' class="active"' : NULL; ?>>
                    <a href="#"><i class="fa fa-cube"></i> <span class="nav-label"><?php __('menuProducts'); ?></span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">

                        <?php if ($hasAccessScriptProductsIndex): ?>
                            <li<?php echo $isScriptProducts ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionIndex"><i class="fa fa-cube"></i> <?php __('menuProductsList'); ?></a></li>
                            <?php endif; ?>

                            <?php if ($hasAccessScriptProductImport): ?>
                            <li<?php echo $isScriptProductImport ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionImportProduct"><i class="fa fa-upload"></i> <?php __('menuProductImport'); ?></a></li>
                            <?php endif; ?>

                            <?php if ($hasAccessScriptStockIndex): ?>
                                <li<?php echo $isScriptProductStock ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionStock"><i class="fa fa-archive"></i> <?php __('menuProductStock'); ?></a></li>
                                <?php endif; ?>

                                <?php if ($hasAccessScriptCategories): ?>
                                    <li<?php echo $isScriptCategoriesController ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminCategories&amp;action=pjActionIndex"><i class="fa fa-folder-o"></i> <?php __('menuCategories'); ?></a></li>
                                    <?php endif; ?>
                    </ul>
                    </li>
                <?php endif; ?>

                <?php if ($hasAccessScriptVouchers): ?>
                    <li<?php echo $isScriptVouchersController ? ' class="active"' : NULL; ?>>
                        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminVouchers&amp;action=pjActionIndex"><i class="fa fa-gift"></i> <span class="nav-label"><?php __('menuVouchers'); ?></span></a>
                        </li>
                    <?php endif; ?>

                    <?php if ($hasAccessScriptReports): ?>
                        <li<?php echo $isScriptReportsController ? ' class="active"' : NULL; ?>>
                            <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminReports&amp;action=pjActionIndex"><i class="fa fa-files-o"></i> <span class="nav-label"><?php __('menuReports'); ?></span></a>
                            </li>
                        <?php endif; ?>

                        <?php if ($hasAccessScriptProfile || $hasAccessScriptOptionsBooking || $hasAccessScriptPayments || $hasAccessScriptOptionsBookingForm || $hasAccessScriptOptionsShippingTax || $hasAccessScriptOptionsNotifications || $hasAccessScriptOptionsTerm || $hasAccessScriptInvoices): ?>
                            <li<?php echo $isScriptProfile || $isScriptOptionsController || $isScriptPaymentsController ? ' class="active"' : NULL; ?>>
                                <a href="#"><i class="fa fa-cog"></i> <span class="nav-label"><?php __('menuSettings'); ?></span><span class="fa arrow"></span></a>
                                <ul class="nav nav-second-level collapse">
                                    <?php if ($hasAccessScriptProfile): ?>
                                        <li<?php echo $isScriptProfile ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProfile&amp;action=pjActionIndex"><i class="fa fa-building"></i> <?php $lbl = __('menuProfile', true);
                                                                                                                                                                                                                                                $companyLbl = __('admin_menu_company_profile', true);
                                                                                                                                                                                                                                                echo !empty($companyLbl) && $companyLbl !== 'admin_menu_company_profile' ? htmlspecialchars($companyLbl) : (!empty($lbl) && $lbl !== 'menuProfile' ? htmlspecialchars($lbl) : 'Company profile'); ?></a></li>
                                        <?php endif; ?>

                                    <?php if ($hasAccessScriptOptionsBooking): ?>
                                        <li<?php echo $isScriptOptionsBooking ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionBooking"><i class="fa fa-sliders"></i> <?php $lbl = __('settingsTabOrderSettings', true);
                                                                                                                                                                                                                                                echo !empty($lbl) && $lbl !== 'settingsTabOrderSettings' ? htmlspecialchars($lbl) : 'Order settings'; ?></a></li>
                                        <?php endif; ?>

                                        <?php if ($hasAccessScriptPayments): ?>
                                            <li<?php echo $isScriptPaymentsController ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjPayments&amp;action=pjActionIndex"><i class="fa fa-credit-card"></i> <?php __('settingsTabPayments'); ?></a></li>
                                            <?php endif; ?>

                                            <?php if ($hasAccessScriptOptionsBookingForm): ?>
                                                <li<?php echo $isScriptOptionsBookingForm ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionBookingForm"><i class="fa fa-wpforms"></i> <?php __('settingsTabCheckoutForm'); ?></a></li>
                                                <?php endif; ?>

                                                <?php if ($hasAccessScriptOptionsShippingTax): ?>
                                                    <li<?php echo $isScriptOptionsShippingTax ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionShippingTax"><i class="fa fa-truck"></i> <?php __('settingsTabShippingTax'); ?></a></li>
                                                    <?php endif; ?>

                                                    <?php if ($hasAccessScriptOptionsTerm): ?>
                                                        <li<?php echo $isScriptOptionsTerm ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionTerm"><i class="fa fa-file-text-o"></i> <?php __('settingsTabTerms'); ?></a></li>
                                                        <?php endif; ?>

                                                        <?php if ($hasAccessScriptOptionsNotifications): ?>
                                                            <li<?php echo $isScriptOptionsNotifications ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionNotifications"><i class="fa fa-envelope-o"></i> <?php __('settingsTabNotifications'); ?></a></li>
                                                            <?php endif; ?>

                                                            <?php if ($hasAccessScriptInvoices): ?>
                                                                <li<?php echo $isScriptInvoiceTemplate ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionInvoiceTemplate"><i class="fa fa-file-text-o"></i> <?php __('plugin_invoice_template'); ?></a></li>
                                                                <?php endif; ?>

                                </ul>
                                </li>
                            <?php endif; ?>

                            <?php if ($hasAccessScriptVisual || $hasAccessScriptGrid || $hasAccessScriptPreview || $hasAccessScriptImages): ?>
                                <li<?php echo $isScriptAppearance ? ' class="active"' : NULL; ?>>
                                    <a href="#"><i class="fa fa-paint-brush"></i> <span class="nav-label"><?php $lbl = __('menuAppearance', true);
                                                                                                            echo !empty($lbl) && $lbl !== 'menuAppearance' ? htmlspecialchars($lbl) : 'Display'; ?></span><span class="fa arrow"></span></a>
                                    <ul class="nav nav-second-level collapse">
                                        <?php if ($hasAccessScriptGrid): ?>
                                            <li<?php echo $isScriptOptionsGrid ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionGrid"><i class="fa fa-th-large"></i> <?php $lbl = __('menuProductDisplay', true);
                                                                                                                                                                                                                                                echo !empty($lbl) && $lbl !== 'menuProductDisplay' ? htmlspecialchars($lbl) : 'Product Display'; ?></a></li>
                                            <?php endif; ?>
                                            <?php if ($hasAccessScriptImages): ?>
                                                <li<?php echo $isScriptImageSettings ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjBaseOptions&amp;action=pjActionImages"><i class="fa fa-image"></i> <?php $lbl = __('menuSystemImages', true);
                                                                                                                                                                                                                                                    echo !empty($lbl) && $lbl !== 'menuSystemImages' ? htmlspecialchars($lbl) : 'Images'; ?></a></li>
                                                <?php endif; ?>
                                                <?php // Sprint 1 (2026-05-02): Theme & Colors moved from Install to Appearance 
                                                ?>
                                                <?php if ($hasAccessScriptPreview): ?>
                                                    <li<?php echo $isScriptOptionsPreview ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionPreview"><i class="fa fa-eye"></i> <?php $lbl = __('menuThemeColors', true);
                                                                                                                                                                                                                                                        echo !empty($lbl) && $lbl !== 'menuThemeColors' && $lbl !== 'Theme & Colors' ? htmlspecialchars($lbl) : 'Preview'; ?></a></li>
                                                    <?php endif; ?>
                                                    <?php if ($hasAccessScriptVisual): ?>
                                                        <?php if (!isset($tpl['option_arr']['o_hide_page']) || $tpl['option_arr']['o_hide_page'] == 'No'): ?>
                                                            <li<?php echo $isScriptVisualBranding ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjBaseOptions&amp;action=pjActionVisual"><i class="fa fa-magic"></i> <?php __('plugin_base_menu_visual_branding'); ?></a></li>
                                                            <?php endif; ?>
                                                        <?php endif; ?>
                                    </ul>
                                    </li>
                                <?php endif; ?>
