@props(['header'])
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ app()->getLocale() === 'ar' ? 'rtl' : 'ltr' }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>POS</title>
        <link rel="icon" href="data:,">

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
        @if(app()->getLocale() === 'ar')
        <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap" rel="stylesheet">
        @elseif(app()->getLocale() === 'bn')
        <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Bengali:wght@400;500;600;700&display=swap" rel="stylesheet">
        @endif

        <!-- Bootstrap CDN -->
        @if(app()->getLocale() === 'ar')
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.rtl.min.css">
        @else
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
        @endif
        <!-- Bootstrap Icons -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
        <!-- Searchable select dropdowns -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/css/tom-select.bootstrap5.min.css">

        <style>
            :root { --brand: #0dcaee; --brand-dark: #0aa8c8; }
            body { background: #f0f4f8; }
            @if(app()->getLocale() === 'ar') body { font-family: 'Cairo', sans-serif; } @endif
            @if(app()->getLocale() === 'bn') body { font-family: 'Noto Sans Bengali', sans-serif; } @endif
            .navbar-brand { font-weight: 700; letter-spacing: .5px; font-size: 1.1rem; }
            .main-navbar { background: linear-gradient(135deg, #0dcaee 0%, #0a9fc0 100%); box-shadow: 0 2px 12px rgba(13,202,238,.35); }
            .main-navbar .nav-link { color: rgba(255,255,255,.9) !important; font-size: .875rem; font-weight: 500; padding: .45rem .75rem !important; border-radius: 6px; transition: background .2s; }
            .main-navbar .nav-link:hover, .main-navbar .nav-link.active { background: rgba(255,255,255,.18); color: #fff !important; }
            .main-navbar .dropdown-menu { border: none; box-shadow: 0 8px 24px rgba(0,0,0,.12); border-radius: 10px; margin-top: 6px; }
            .main-navbar .dropdown-item { font-size: .85rem; padding: .45rem 1rem; border-radius: 6px; }
            .main-navbar .dropdown-item:hover { background: #e8f9fd; color: #0aa8c8; }
            .main-navbar .dropdown-item i { width: 18px; }
            .main-navbar .nav-divider { border-left: 1px solid rgba(255,255,255,.3); height: 20px; margin: auto .5rem; }
            .navbar-toggler { border-color: rgba(255,255,255,.4); }
            .navbar-toggler-icon { filter: invert(1); }
            .badge-dot { width:8px;height:8px;border-radius:50%;display:inline-block;background:#28a745;margin-left:3px;vertical-align:middle; }
            .page-content { padding: 1.5rem 0; }
            .ts-wrapper {
                width: 100%;
            }
            .ts-wrapper .ts-control {
                min-height: calc(2.25rem + 2px);
            }
            .ts-dropdown {
                z-index: 2100;
            }
        </style>
    </head>
    <body>
        <nav class="navbar navbar-expand-lg main-navbar">
            <div class="container-fluid px-3">
                <a class="navbar-brand text-white" href="{{ route('dashboard') }}">
                    <i class="bi bi-shop me-2"></i>Dubai Resturant
                </a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbar" aria-controls="mainNavbar" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="mainNavbar">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0 gap-1">
                        <li class="nav-item">
                            <a class="nav-link{{ request()->routeIs('dashboard') ? ' active' : '' }}" href="{{ route('dashboard') }}">
                                <i class="bi bi-speedometer2 me-1"></i>{{ __('app.dashboard') }}
                            </a>
                        </li>
                        @can('sales.view')
                        <li class="nav-item">
                            <a class="nav-link{{ request()->routeIs('sales.*') ? ' active' : '' }}" href="{{ route('sales.index') }}">
                                <i class="bi bi-cart3 me-1"></i>{{ __('app.sales') }}
                            </a>
                        </li>
                        @endcan
                        @can('purchases.view')
                        <li class="nav-item">
                            <a class="nav-link{{ request()->routeIs('purchases.*') ? ' active' : '' }}" href="{{ route('purchases.index') }}">
                                <i class="bi bi-box-seam me-1"></i>{{ __('app.purchases') }}
                            </a>
                        </li>
                        @endcan
                        @can('expenses.view')
                        <li class="nav-item">
                            <a class="nav-link{{ request()->routeIs('expenses.*') ? ' active' : '' }}" href="{{ route('expenses.index') }}">
                                <i class="bi bi-receipt me-1"></i>{{ __('app.expenses') }}
                            </a>
                        </li>
                        @endcan
                        @can('bank-withdrawals.view')
                        <li class="nav-item">
                            <a class="nav-link{{ request()->routeIs('bank-withdrawals.*') ? ' active' : '' }}" href="{{ route('bank-withdrawals.index') }}">
                                <i class="bi bi-bank me-1"></i>{{ __('app.bank_withdrawals') }}
                            </a>
                        </li>
                        @endcan
                        <!-- HR Dropdown -->
                        @canany(['employees.view', 'rosters.view', 'employee-payments.view'])
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle{{ request()->routeIs('employees.*','rosters.*','employee-payments.*') ? ' active' : '' }}" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-people me-1"></i>{{ __('app.employees') }}
                            </a>
                            <ul class="dropdown-menu">
                                @can('employees.view')
                                <li><a class="dropdown-item" href="{{ route('employees.index') }}"><i class="bi bi-person-badge me-1"></i>{{ __('app.employees') }}</a></li>
                                @endcan
                                @can('rosters.view')
                                <li><a class="dropdown-item" href="{{ route('rosters.index') }}"><i class="bi bi-calendar3 me-1"></i>{{ __('app.rosters') }}</a></li>
                                @endcan
                                @can('employee-payments.view')
                                <li><a class="dropdown-item" href="{{ route('employee-payments.index') }}"><i class="bi bi-cash-coin me-1"></i>{{ __('app.employee_payments') }}</a></li>
                                @endcan
                            </ul>
                        </li>
                        @endcanany
                        <!-- Customers Dropdown -->
                        @canany(['customers.view', 'customer-ledgers.view'])
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle{{ request()->routeIs('customers.*','customer-ledgers.*') ? ' active' : '' }}" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-person-lines-fill me-1"></i>{{ __('app.customers') }}
                            </a>
                            <ul class="dropdown-menu">
                                @can('customers.view')
                                <li><a class="dropdown-item" href="{{ route('customers.index') }}"><i class="bi bi-person-check me-1"></i>{{ __('app.customers') }}</a></li>
                                @endcan
                                @can('customer-ledgers.view')
                                <li><a class="dropdown-item" href="{{ route('customer-ledgers.index') }}"><i class="bi bi-journal-text me-1"></i>{{ __('app.customer_dues') }}</a></li>
                                @endcan
                            </ul>
                        </li>
                        @endcanany
                        <!-- Reports Dropdown -->
                        @canany(['reports.view', 'shareholder-reports.view'])
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle{{ request()->routeIs('reports.*') ? ' active' : '' }}" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-bar-chart-line me-1"></i>{{ __('app.reports') }}
                            </a>
                            <ul class="dropdown-menu">
                                @can('reports.view')
                                <li><a class="dropdown-item" href="{{ route('reports.daily') }}"><i class="bi bi-calendar-day me-1"></i>{{ __('app.daily_income') }}</a></li>
                                <li><a class="dropdown-item" href="{{ route('reports.monthly') }}"><i class="bi bi-calendar-month me-1"></i>{{ __('app.monthly_profit_loss') }}</a></li>
                                <li><a class="dropdown-item" href="{{ route('reports.vendor') }}"><i class="bi bi-truck me-1"></i>{{ __('app.vendor_report') }}</a></li>
                                @endcan
                                @can('shareholder-reports.view')
                                <li><a class="dropdown-item" href="{{ route('reports.shareholders') }}"><i class="bi bi-person-workspace me-1"></i>{{ __('app.shareholder_report') }}</a></li>
                                @endcan
                            </ul>
                        </li>
                        @endcanany
                        <!-- Settings Dropdown -->
                        @canany(['items.view', 'currencies.view', 'sale-sources.view', 'expense-categories.view', 'vendors.view', 'shareholders.view', 'users.view', 'roles.view'])
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle{{ request()->routeIs('users.*','roles.*','currencies.*','items.*','vendors.*','shareholders.*','settings.*') ? ' active' : '' }}" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-gear me-1"></i>{{ __('app.settings') }}
                            </a>
                            <ul class="dropdown-menu">
                                @can('items.view')
                                <li><a class="dropdown-item" href="{{ route('items.index') }}"><i class="bi bi-archive me-1"></i>{{ __('app.items_stock') }}</a></li>
                                @endcan
                                @can('currencies.view')
                                <li><a class="dropdown-item" href="{{ route('currencies.index') }}"><i class="bi bi-currency-exchange me-1"></i>{{ __('app.currency') }}</a></li>
                                @endcan
                                @can('sale-sources.view')
                                <li><a class="dropdown-item" href="{{ route('settings.sale-sources.index') }}"><i class="bi bi-tags me-1"></i>{{ __('app.sale_sources') }}</a></li>
                                @endcan
                                @can('expense-categories.view')
                                <li><a class="dropdown-item" href="{{ route('settings.expense-categories.index') }}"><i class="bi bi-folder2-open me-1"></i>{{ __('app.expense_categories') }}</a></li>
                                @endcan
                                @canany(['vendors.view', 'shareholders.view'])
                                <li><hr class="dropdown-divider"></li>
                                @endcanany
                                @can('vendors.view')
                                <li><a class="dropdown-item" href="{{ route('vendors.index') }}"><i class="bi bi-truck me-1"></i>{{ __('app.vendors') }}</a></li>
                                @endcan
                                @can('shareholders.view')
                                <li><a class="dropdown-item" href="{{ route('shareholders.index') }}"><i class="bi bi-person-workspace me-1"></i>{{ __('app.shareholders') }}</a></li>
                                @endcan
                                @canany(['users.view', 'roles.view'])
                                <li><hr class="dropdown-divider"></li>
                                @endcanany
                                @can('users.view')
                                <li><a class="dropdown-item" href="{{ route('users.index') }}"><i class="bi bi-people-fill me-1"></i>{{ __('app.users') }}</a></li>
                                @endcan
                                @can('roles.view')
                                <li><a class="dropdown-item" href="{{ route('roles.index') }}"><i class="bi bi-shield-lock me-1"></i>{{ __('app.roles_permissions') }}</a></li>
                                @endcan
                            </ul>
                        </li>
                        @endcanany
                    </ul>

                    <ul class="navbar-nav ms-auto mb-2 mb-lg-0 gap-1 align-items-center">
                        <!-- Language -->
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-translate me-1"></i>{{ strtoupper(app()->getLocale()) }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item{{ app()->getLocale() == 'en' ? ' active' : '' }}" href="{{ route('locale.switch', 'en') }}">🇺🇸 English</a></li>
                                <li><a class="dropdown-item{{ app()->getLocale() == 'bn' ? ' active' : '' }}" href="{{ route('locale.switch', 'bn') }}">🇧🇩 বাংলা</a></li>
                                <li><a class="dropdown-item{{ app()->getLocale() == 'ar' ? ' active' : '' }}" href="{{ route('locale.switch', 'ar') }}">🇸🇦 العربية</a></li>
                            </ul>
                        </li>
                        <!-- User -->
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle d-flex align-items-center gap-1" href="#" data-bs-toggle="dropdown">
                                <span class="bg-white text-primary rounded-circle d-inline-flex align-items-center justify-content-center fw-bold" style="width:28px;height:28px;font-size:.8rem;">
                                    {{ strtoupper(substr(Auth::user()->name, 0, 1)) }}
                                </span>
                                <span class="d-none d-lg-inline">{{ Auth::user()->name }}</span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li class="px-3 py-2 small text-muted">{{ Auth::user()->email }}</li>
                                <li><hr class="dropdown-divider my-1"></li>
                                <li><a class="dropdown-item" href="{{ route('profile.edit') }}"><i class="bi bi-person-circle me-1"></i>{{ __('app.profile') }}</a></li>
                                <li>
                                    <form method="POST" action="{{ route('logout') }}">
                                        @csrf
                                        <button type="submit" class="dropdown-item text-danger"><i class="bi bi-box-arrow-right me-1"></i>{{ __('app.logout') }}</button>
                                    </form>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

        <main class="container-fluid px-4 page-content">
            @if(session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    {{ session('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            @endif
            @if(session('error'))
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    {{ session('error') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            @endif

            @if($errors->any())
                <div class="alert alert-danger">
                    <ul class="mb-0">
                        @foreach($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            @isset($header)
                <div class="mb-4 d-flex align-items-center gap-2">
                    <h1 class="h4 mb-0 fw-bold">{{ $header }}</h1>
                </div>
            @endisset

            {{ $slot }}
        </main>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/js/tom-select.complete.min.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function () {
                document.querySelectorAll('select').forEach(function (el) {
                    if (el.dataset.searchableInit === '1' || el.dataset.noSearch === '1') {
                        return;
                    }

                    new TomSelect(el, {
                        create: false,
                        allowEmptyOption: true,
                        maxOptions: 500,
                        hidePlaceholder: false,
                    });

                    el.dataset.searchableInit = '1';
                });
            });
        </script>
    </body>
</html>
