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

    <title>{{ config('app.name', 'Laundry Dashboard') }}</title>

    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>

<body class="font-sans antialiased bg-gray-100">
    <header class="bg-white border-b">
        <div class="max-w-7xl mx-auto px-4 py-3 flex flex-wrap items-center justify-between gap-2">
            <div class="font-extrabold text-lg">
                {{ config('app.name', 'Laundry Dashboard') }}
            </div>

            <nav class="flex flex-wrap gap-2 items-center">
                {{-- رئيسي --}}
                @if(Route::has('dashboard.sales'))
                    <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                       href="{{ route('dashboard.sales') }}">المبيعات</a>
                @endif

                @if(Route::has('purchases.index'))
                    <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                       href="{{ route('purchases.index') }}">المشتريات</a>
                @endif

                @if(Route::has('expenses.index'))
                    <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                       href="{{ route('expenses.index') }}">المصروفات</a>
                @endif

                {{-- ✅ التقارير (موجودة عندك) --}}
                @if(Route::has('dashboard.sales.report'))
                    <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                       href="{{ route('dashboard.sales.report') }}">التقارير</a>
                @endif

                {{-- ✅ الإعدادات (ننشئها: settings.index) --}}
                @if(Route::has('settings.index'))
                    <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                       href="{{ route('settings.index') }}">الإعدادات</a>
                @endif

                {{-- إدارة حسب الصلاحية --}}
                @if(auth()->check() && (auth()->user()->role ?? 'user') === 'admin')
                    @if(Route::has('branches.index'))
                        <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                           href="{{ route('branches.index') }}">إدارة الفروع</a>
                    @endif

                    @if(Route::has('users.index'))
                        <a class="px-3 py-2 rounded-lg border bg-white font-bold text-sm hover:bg-gray-50"
                           href="{{ route('users.index') }}">إدارة المستخدمين</a>
                    @endif
                @endif

                {{-- خروج --}}
                @if(Route::has('logout'))
                    <form method="POST" action="{{ route('logout') }}" class="inline">
                        @csrf
                        <button type="submit"
                                class="px-3 py-2 rounded-lg bg-gray-900 text-white font-extrabold text-sm hover:opacity-95">
                            خروج
                        </button>
                    </form>
                @endif
            </nav>
        </div>

        {{-- شريط فرعي لو الصفحة محتاجته --}}
        @hasSection('subnav')
            <div class="bg-gray-50 border-t">
                <div class="max-w-7xl mx-auto px-4 py-2">
                    @yield('subnav')
                </div>
            </div>
        @endif
    </header>

    <main class="max-w-7xl mx-auto px-4 py-6">
        @isset($slot)
            {{ $slot }}
        @else
            @yield('content')
        @endisset
    </main>
</body>
</html>
