@extends('layouts.store', ['title' => $title ?? 'لوحة التحكم | RaseedNow', 'accountMode' => true])

@php
    $accountUser = auth()->user();
    $walletBalance = ($accountUser?->wallet?->balance_minor ?? 0) / 100;
    $avatarLetter = mb_strtoupper(mb_substr($accountUser?->display_name ?: $accountUser?->name ?: 'U', 0, 1));
    $navItems = [
        ['route' => 'account.dashboard', 'label' => 'لوحة التحكم', 'mobile' => 'الرئيسية', 'icon' => 'M4 4h6v6H4V4Zm10 0h6v6h-6V4ZM4 14h6v6H4v-6Zm10 0h6v6h-6v-6Z'],
        ['route' => 'account.orders', 'label' => 'طلباتي', 'mobile' => 'طلباتي', 'icon' => 'M7 4h10l2 4v12H5V8l2-4Zm-2 4h14M9 13h6m-6 4h4'],
        ['route' => 'account.tickets', 'label' => 'التذاكر', 'mobile' => 'الدعم', 'icon' => 'M4 5h16v11H8l-4 4V5Zm5 5h6m-6 4h4'],
        ['route' => 'account.wallet', 'label' => 'المحفظة', 'mobile' => 'الرصيد', 'icon' => 'M4 7h16v12H4V7Zm0 4h16M16 15h2'],
        ['route' => 'account.notifications', 'label' => 'الإشعارات', 'mobile' => 'الإشعارات', 'icon' => 'M18 8a6 6 0 1 0-12 0c0 7-3 8-3 8h18s-3-1-3-8ZM10 20h4'],
        ['route' => 'account.favorites', 'label' => 'المفضلة', 'mobile' => 'المفضلة', 'icon' => 'M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.6l-1-1a5.5 5.5 0 1 0-7.8 7.8l1 1L12 21l7.8-7.6 1-1a5.5 5.5 0 0 0 0-7.8Z'],
        ['route' => 'account.profile', 'label' => 'الملف الشخصي', 'mobile' => 'حسابي', 'icon' => 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm7 9a7 7 0 0 0-14 0'],
    ];
@endphp

@section('content')
    <section class="kd-shell">
        <aside class="kd-side-nav" aria-label="قائمة لوحة التحكم">
            @foreach($navItems as $item)
                <a href="{{ route($item['route']) }}" @class(['is-active' => request()->routeIs($item['route'])]) title="{{ $item['label'] }}">
                    <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="{{ $item['icon'] }}" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
                    <span>{{ $item['label'] }}</span>
                </a>
            @endforeach
            <form method="POST" action="{{ route('logout') }}">
                @csrf
                <button type="submit" title="تسجيل الخروج">
                    <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M15 3h4v18h-4M10 17l5-5-5-5M15 12H3" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
                    <span>خروج</span>
                </button>
            </form>
        </aside>

        <div class="kd-mobile-head">
            <button type="button" data-rn-sidebar-open aria-label="فتح القائمة">
                <svg viewBox="0 0 24 24" fill="none"><path d="M4 7h16M4 12h16M4 17h16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
            </button>
            <a href="{{ route('account.wallet') }}" class="kd-balance-pill">{{ number_format($walletBalance, 2) }} ج.م <b>+</b></a>
            <span class="kd-avatar">{{ $avatarLetter }}</span>
        </div>

        <div class="kd-content">
            @if(session('status'))
                <div class="kd-alert success">{{ session('status') }}</div>
            @endif
            @if($errors->any())
                <div class="kd-alert danger">{{ $errors->first() }}</div>
            @endif

            @yield('account_content')
        </div>
    </section>

    <nav class="kd-bottom-nav" aria-label="قائمة لوحة التحكم للموبايل">
        @foreach(collect($navItems)->take(6) as $item)
            <a href="{{ route($item['route']) }}" @class(['is-active' => request()->routeIs($item['route'])])>
                <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="{{ $item['icon'] }}" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
                <span>{{ $item['mobile'] }}</span>
            </a>
        @endforeach
    </nav>
@endsection
