<!-- Sidebar -->
<aside class="sidebar">
    <div class="sidebar-header">
        <a href="{{ route('dashboard') }}" class="sidebar-brand">
            <i class="fas fa-layer-group"></i>
            <span>Holaxis 360</span>
        </a>
    </div>

    <nav class="sidebar-nav">
        <ul class="nav flex-column">
            <!-- Dashboard (always visible) -->
            <li class="nav-item">
                <a href="{{ route('dashboard') }}" class="nav-link {{ request()->routeIs('dashboard') ? 'active' : '' }}">
                    <i class="fas fa-tachometer-alt"></i>
                    <span>{{ __('Dashboard') }}</span>
                </a>
            </li>

            <!-- POS -->
            @if(\App\Models\ModuleSetting::isActive('pos'))
            @can('access-pos')
            <li class="nav-item">
                <a href="{{ route('pos.index') }}" class="nav-link {{ request()->routeIs('pos.index') ? 'active' : '' }}">
                    <i class="fas fa-cash-register"></i>
                    <span>{{ __('Point of Sale') }}</span>
                </a>
            </li>
            <li class="nav-item">
                <a href="{{ route('pos.sales-history') }}" class="nav-link {{ request()->routeIs('pos.sales-history') ? 'active' : '' }}">
                    <i class="fas fa-history"></i>
                    <span>{{ __('Sales History') }}</span>
                </a>
            </li>
            @endcan
            @endif

            <!-- Sales -->
            @if(\App\Models\ModuleSetting::isActive('sales'))
            @can('view-sales')
            <li class="nav-item">
                <a href="#salesMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-shopping-cart"></i>
                    <span>{{ __('Sales') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('sales.*') ? 'show' : '' }}" id="salesMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ \App\Models\Setting::get('sales_mode') === 'daily' ? route('sales.daily.create') : route('sales.create') }}" 
                               class="nav-link {{ request()->routeIs('sales.create') || request()->routeIs('sales.daily.create') ? 'active' : '' }}">
                                {{ __('New Sale') }}
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('sales.index') }}" class="nav-link {{ request()->routeIs('sales.index') ? 'active' : '' }}">{{ __('Sales History') }}</a>
                        </li>

                        @if(\App\Models\Setting::get('sales_mode') === 'daily')
                        <li class="nav-item">
                            <a href="{{ route('sales.daily.index') }}" class="nav-link {{ request()->routeIs('sales.daily.index') ? 'active' : '' }}">
                                {{ __('Daily Sales History') }}
                            </a>
                        </li>
                        @endif

                        <li class="nav-item">
                            <a href="{{ route('sales.returns.index') }}" class="nav-link {{ request()->routeIs('sales.returns.index') ? 'active' : '' }}">{{ __('Returns') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Products -->
            @if(\App\Models\ModuleSetting::isActive('products'))
            @can('manage-products')
            <li class="nav-item">
                <a href="#productsMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-boxes"></i>
                    <span>{{ __('Products') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('products.*', 'categories.*') ? 'show' : '' }}" id="productsMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('products.index') }}" class="nav-link">{{ __('All Products') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('categories.index') }}" class="nav-link">{{ __('Categories') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('products.barcodes') }}" class="nav-link">{{ __('Print Barcodes') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Inventory -->
            @if(\App\Models\ModuleSetting::isActive('inventory'))
            @can('manage-inventory')
            <li class="nav-item">
                <a href="#inventoryMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-warehouse"></i>
                    <span>{{ __('Inventory') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('inventory.*') ? 'show' : '' }}" id="inventoryMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('inventory.index') }}" class="nav-link">{{ __('Stock Levels') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('inventory.adjustments') }}" class="nav-link">{{ __('Adjustments') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('inventory.transfers') }}" class="nav-link">{{ __('Stock Transfers') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('inventory.low-stock') }}" class="nav-link">{{ __('Low Stock Alerts') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Purchases -->
            @if(\App\Models\ModuleSetting::isActive('purchases'))
            @can('manage-purchases')
            <li class="nav-item">
                <a href="#purchasesMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-truck"></i>
                    <span>{{ __('Purchases') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('purchases.*', 'suppliers.*') ? 'show' : '' }}" id="purchasesMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('purchases.index') }}" class="nav-link">{{ __('Purchase Orders') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('purchase.returns.index') }}" class="nav-link">{{ __('Returns') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Partners -->
            @if(\App\Models\ModuleSetting::isActive('partners'))
            @if(auth()->user()->can('manage-customers') || auth()->user()->can('manage-purchases'))
            <li class="nav-item">
                <a href="#partnersMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-handshake"></i>
                    <span>{{ __('Partners') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('partners.*') ? 'show' : '' }}" id="partnersMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('partners.index') }}" class="nav-link">{{ __('All Partners') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('partners.types') }}" class="nav-link">{{ __('Partner Types') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endif
            @endif

            <!-- Accounting -->
            @if(\App\Models\ModuleSetting::isActive('accounting'))
            @can('manage-accounting')
            <li class="nav-item">
                <a href="#accountingMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-calculator"></i>
                    <span>{{ __('Accounting') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('accounting.*') ? 'show' : '' }}" id="accountingMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('accounting.chart') }}" class="nav-link">{{ __('Chart of Accounts') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.journals') }}" class="nav-link">{{ __('Journal Entries') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.general-ledger') }}" class="nav-link">{{ __('General Ledger') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.partner-ledger') }}" class="nav-link">{{ __('Partner Ledger') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.customer-settlements') }}" class="nav-link">{{ __('Customer Settlements') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.supplier-payments') }}" class="nav-link">{{ __('Supplier Payments') }}</a>
                        </li>

                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Reports -->
            @if(\App\Models\ModuleSetting::isActive('reports'))
            @can('view-reports')
            <li class="nav-item">
                <a href="#reportsMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-chart-bar"></i>
                    <span>{{ __('Reports') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('reports.*') ? 'show' : '' }}" id="reportsMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('reports.daily-sales') }}" class="nav-link">{{ __('Sales Report') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.product-sales') }}" class="nav-link">{{ __('Product Sales') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.customer-credit') }}" class="nav-link">{{ __('Customer Credit') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.inventory') }}" class="nav-link">{{ __('Inventory Report') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.purchases') }}" class="nav-link">{{ __('Purchase Report') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.stock-adjustments') }}" class="nav-link">{{ __('Stock Adjustments') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.partner-statement') }}" class="nav-link">{{ __('Partner Statement') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.payment-collection') }}" class="nav-link">{{ __('Payment Collection') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('accounting.trial-balance') }}" class="nav-link">{{ __('Trial Balance') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.profit-loss') }}" class="nav-link">{{ __('Income Statement') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.stock-by-location') }}" class="nav-link">{{ __('Stock by Location') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.batch-expiry') }}" class="nav-link">{{ __('Batch & Expiry') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.fifo-cost-layers') }}" class="nav-link">{{ __('FIFO Cost Layers') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('reports.adjustments-by-location') }}" class="nav-link">{{ __('Adjustments by Location') }}</a>
                        </li>
                    </ul>
                </div>
            </li>
            @endcan
            @endif

            <!-- Settings (always visible) -->
            @can('manage-settings')
            <li class="nav-item">
                <a href="#settingsMenu" class="nav-link" data-bs-toggle="collapse">
                    <i class="fas fa-cog"></i>
                    <span>{{ __('Settings') }}</span>
                </a>
                <div class="collapse {{ request()->routeIs('settings.*') ? 'show' : '' }}" id="settingsMenu">
                    <ul class="nav flex-column ms-3">
                        <li class="nav-item">
                            <a href="{{ route('settings.general') }}" class="nav-link">{{ __('General') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.branches') }}" class="nav-link">{{ __('Branches') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.locations') }}" class="nav-link">{{ __('Locations') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.units') }}" class="nav-link">{{ __('Units') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.users') }}" class="nav-link">{{ __('Users') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.payment-methods') }}" class="nav-link">{{ __('Payment Methods') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.accounting') }}" class="nav-link">{{ __('Accounting') }}</a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('settings.categories.accounting') }}" class="nav-link">{{ __('Category Accounting') }}</a>
                        </li>
                        @can('manage-roles')
                        <li class="nav-item">
                            <a href="{{ route('settings.roles') }}" class="nav-link">{{ __('Roles & Permissions') }}</a>
                        </li>
                        @endcan
                        <li class="nav-item">
                            <a href="{{ route('settings.modules') }}" class="nav-link">{{ __('Modules') }}</a>
                        </li>
                        @role('super-admin')
                        <li class="nav-item">
                            <a href="{{ route('settings.system') }}" class="nav-link {{ request()->routeIs('settings.system') ? 'active' : '' }}">
                                <i class="fas fa-sync-alt me-1"></i>{{ __('System Update') }}
                            </a>
                        </li>
                        @endrole
                    </ul>
                </div>
            </li>
            @endcan
        </ul>
    </nav>
</aside>
