<nav x-data="{ open: false }" class="bg-white dark:bg-gray-800 border-b border-gray-100 dark:border-gray-700">
    <!-- Primary Navigation Menu -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="flex justify-between h-16">
            <div class="flex">
                <!-- Logo -->
                <div class="shrink-0 flex items-center">
                    <a href="{{ route('dashboard') }}" class="flex items-center space-x-2">
                        <i class="fas fa-wallet text-2xl text-indigo-600 dark:text-indigo-400"></i>
                        <span class="font-bold text-xl text-gray-900 dark:text-white hidden sm:block">MyMoney</span>
                    </a>
                </div>

                <!-- Navigation Links -->
                <div class="hidden space-x-1 lg:-my-px lg:ms-8 lg:flex">
                    <x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
                        <i class="fas fa-chart-pie me-1.5"></i>
                        {{ __('Dashboard') }}
                    </x-nav-link>

                    <x-nav-link :href="route('accounts.index')" :active="request()->routeIs('accounts.*')">
                        <i class="fas fa-university me-1.5"></i>
                        {{ __('Accounts') }}
                    </x-nav-link>

                    <x-nav-link :href="route('transactions.index')" :active="request()->routeIs('transactions.*')">
                        <i class="fas fa-exchange-alt me-1.5"></i>
                        {{ __('Transactions') }}
                    </x-nav-link>

                    <x-nav-link :href="route('budgets.index')" :active="request()->routeIs('budgets.*')">
                        <i class="fas fa-calculator me-1.5"></i>
                        {{ __('Budgets') }}
                    </x-nav-link>

                    <x-nav-link :href="route('goals.index')" :active="request()->routeIs('goals.*')">
                        <i class="fas fa-bullseye me-1.5"></i>
                        {{ __('Goals') }}
                    </x-nav-link>

                    <!-- More Dropdown -->
                    <div class="hidden lg:flex lg:items-center">
                        <x-dropdown align="left" width="48">
                            <x-slot name="trigger">
                                <button class="inline-flex items-center px-3 py-2 text-sm font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200">
                                    {{ __('More') }}
                                    <svg class="ms-1 h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                                    </svg>
                                </button>
                            </x-slot>
                            <x-slot name="content">
                                <x-dropdown-link :href="route('recurring-transactions.index')">
                                    <i class="fas fa-redo me-2 w-4"></i>{{ __('Recurring') }}
                                </x-dropdown-link>
                                <x-dropdown-link :href="route('transfers.index')">
                                    <i class="fas fa-arrow-right-arrow-left me-2 w-4"></i>{{ __('Transfers') }}
                                </x-dropdown-link>
                                <x-dropdown-link :href="route('categories.index')">
                                    <i class="fas fa-tags me-2 w-4"></i>{{ __('Categories') }}
                                </x-dropdown-link>
                                <x-dropdown-link :href="route('reports.index')">
                                    <i class="fas fa-chart-bar me-2 w-4"></i>{{ __('Reports') }}
                                </x-dropdown-link>
                                <x-dropdown-link :href="route('imports.index')">
                                    <i class="fas fa-file-import me-2 w-4"></i>{{ __('Import') }}
                                </x-dropdown-link>
                            </x-slot>
                        </x-dropdown>
                    </div>
                </div>
            </div>

            <!-- Right Side -->
            <div class="hidden lg:flex lg:items-center lg:ms-6 space-x-3">
                <!-- Quick Add Button -->
                <a href="{{ route('transactions.create') }}"
                   class="inline-flex items-center px-3 py-2 bg-indigo-600 hover:bg-indigo-700 text-white text-sm font-medium rounded-lg transition">
                    <i class="fas fa-plus me-1.5"></i>
                    <span class="hidden xl:inline">Add Transaction</span>
                </a>

                <!-- Notifications -->
                <div x-data="{ open: false }" class="relative">
                    <button @click="open = !open" class="relative p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
                        <i class="fas fa-bell text-lg"></i>
                        @php
                            $unreadCount = auth()->user()->userNotifications()->unread()->count();
                        @endphp
                        @if($unreadCount > 0)
                            <span class="absolute top-0 right-0 inline-flex items-center justify-center px-1.5 py-0.5 text-xs font-bold leading-none text-white transform translate-x-1/2 -translate-y-1/2 bg-red-500 rounded-full">
                                {{ $unreadCount > 9 ? '9+' : $unreadCount }}
                            </span>
                        @endif
                    </button>

                    <div x-show="open" @click.away="open = false" x-cloak
                         class="absolute right-0 mt-2 w-80 bg-white dark:bg-gray-800 rounded-lg shadow-lg ring-1 ring-black ring-opacity-5 z-50">
                        <div class="p-3 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
                            <h3 class="font-semibold text-gray-900 dark:text-white">Notifications</h3>
                            <a href="{{ route('notifications.index') }}" class="text-sm text-indigo-600 hover:text-indigo-800">View all</a>
                        </div>
                        <div class="max-h-64 overflow-y-auto">
                            @forelse(auth()->user()->userNotifications()->latest()->limit(5)->get() as $notification)
                                <a href="{{ route('notifications.mark-read', $notification) }}"
                                   class="block px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700 {{ !$notification->read_at ? 'bg-indigo-50 dark:bg-indigo-900/20' : '' }}">
                                    <p class="text-sm text-gray-900 dark:text-white">{{ $notification->title }}</p>
                                    <p class="text-xs text-gray-500 dark:text-gray-400 mt-1">{{ $notification->created_at->diffForHumans() }}</p>
                                </a>
                            @empty
                                <p class="text-center text-gray-500 dark:text-gray-400 py-4">No notifications</p>
                            @endforelse
                        </div>
                    </div>
                </div>

                <!-- Settings Dropdown -->
                <x-dropdown align="right" width="48">
                    <x-slot name="trigger">
                        <button class="inline-flex items-center px-3 py-2 border border-transparent text-sm font-medium rounded-lg text-gray-500 dark:text-gray-400 bg-white dark:bg-gray-800 hover:text-gray-700 dark:hover:text-gray-200 focus:outline-none transition">
                            <div class="w-8 h-8 bg-indigo-100 dark:bg-indigo-900 rounded-full flex items-center justify-center me-2">
                                <span class="text-indigo-600 dark:text-indigo-400 font-semibold text-sm">
                                    {{ substr(Auth::user()->name, 0, 1) }}
                                </span>
                            </div>
                            <span class="hidden xl:block">{{ Auth::user()->name }}</span>
                            <svg class="ms-1 h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                            </svg>
                        </button>
                    </x-slot>

                    <x-slot name="content">
                        <x-dropdown-link :href="route('profile.edit')">
                            <i class="fas fa-user me-2 w-4"></i>{{ __('Profile') }}
                        </x-dropdown-link>
                        <x-dropdown-link :href="route('settings.index')">
                            <i class="fas fa-cog me-2 w-4"></i>{{ __('Settings') }}
                        </x-dropdown-link>

                        <div class="border-t border-gray-100 dark:border-gray-700"></div>

                        <!-- Authentication -->
                        <form method="POST" action="{{ route('logout') }}">
                            @csrf
                            <x-dropdown-link :href="route('logout')"
                                    onclick="event.preventDefault(); this.closest('form').submit();">
                                <i class="fas fa-sign-out-alt me-2 w-4"></i>{{ __('Log Out') }}
                            </x-dropdown-link>
                        </form>
                    </x-slot>
                </x-dropdown>
            </div>

            <!-- Mobile Hamburger -->
            <div class="-me-2 flex items-center lg:hidden">
                <button @click="open = ! open" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none transition">
                    <svg class="h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24">
                        <path :class="{'hidden': open, 'inline-flex': ! open }" class="inline-flex" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
                        <path :class="{'hidden': ! open, 'inline-flex': open }" class="hidden" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            </div>
        </div>
    </div>

    <!-- Mobile Navigation Menu -->
    <div :class="{'block': open, 'hidden': ! open}" class="hidden lg:hidden">
        <div class="pt-2 pb-3 space-y-1">
            <x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
                <i class="fas fa-chart-pie me-2"></i>{{ __('Dashboard') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('accounts.index')" :active="request()->routeIs('accounts.*')">
                <i class="fas fa-university me-2"></i>{{ __('Accounts') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('transactions.index')" :active="request()->routeIs('transactions.*')">
                <i class="fas fa-exchange-alt me-2"></i>{{ __('Transactions') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('budgets.index')" :active="request()->routeIs('budgets.*')">
                <i class="fas fa-calculator me-2"></i>{{ __('Budgets') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('goals.index')" :active="request()->routeIs('goals.*')">
                <i class="fas fa-bullseye me-2"></i>{{ __('Goals') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('recurring-transactions.index')" :active="request()->routeIs('recurring-transactions.*')">
                <i class="fas fa-redo me-2"></i>{{ __('Recurring') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('transfers.index')" :active="request()->routeIs('transfers.*')">
                <i class="fas fa-arrow-right-arrow-left me-2"></i>{{ __('Transfers') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('categories.index')" :active="request()->routeIs('categories.*')">
                <i class="fas fa-tags me-2"></i>{{ __('Categories') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('reports.index')" :active="request()->routeIs('reports.*')">
                <i class="fas fa-chart-bar me-2"></i>{{ __('Reports') }}
            </x-responsive-nav-link>
            <x-responsive-nav-link :href="route('imports.index')" :active="request()->routeIs('imports.*')">
                <i class="fas fa-file-import me-2"></i>{{ __('Import') }}
            </x-responsive-nav-link>
        </div>

        <!-- Mobile Settings Options -->
        <div class="pt-4 pb-1 border-t border-gray-200 dark:border-gray-700">
            <div class="px-4 flex items-center">
                <div class="w-10 h-10 bg-indigo-100 dark:bg-indigo-900 rounded-full flex items-center justify-center me-3">
                    <span class="text-indigo-600 dark:text-indigo-400 font-semibold">
                        {{ substr(Auth::user()->name, 0, 1) }}
                    </span>
                </div>
                <div>
                    <div class="font-medium text-base text-gray-800 dark:text-gray-200">{{ Auth::user()->name }}</div>
                    <div class="font-medium text-sm text-gray-500">{{ Auth::user()->email }}</div>
                </div>
            </div>

            <div class="mt-3 space-y-1">
                <x-responsive-nav-link :href="route('profile.edit')">
                    <i class="fas fa-user me-2"></i>{{ __('Profile') }}
                </x-responsive-nav-link>
                <x-responsive-nav-link :href="route('settings.index')">
                    <i class="fas fa-cog me-2"></i>{{ __('Settings') }}
                </x-responsive-nav-link>
                <x-responsive-nav-link :href="route('notifications.index')">
                    <i class="fas fa-bell me-2"></i>{{ __('Notifications') }}
                </x-responsive-nav-link>

                <!-- Authentication -->
                <form method="POST" action="{{ route('logout') }}">
                    @csrf
                    <x-responsive-nav-link :href="route('logout')"
                            onclick="event.preventDefault(); this.closest('form').submit();">
                        <i class="fas fa-sign-out-alt me-2"></i>{{ __('Log Out') }}
                    </x-responsive-nav-link>
                </form>
            </div>
        </div>
    </div>
</nav>
