<nav
    x-data="{ mobileMenuOpen: false }"
    class="fixed top-0 inset-x-0 z-50 bg-primary"
    data-test="main-navigation"
>
    <div class="max-w-[1200px] mx-auto px-4">
        <div class="flex items-center justify-between h-16">
            <!-- Logo - Left on desktop -->
            <div class="shrink-0 hidden md:block">
                <a href="{{ route('home') }}" class="flex items-center" wire:navigate>
                    <x-logo size="md" class="logo-badge" />
                </a>
            </div>

            <!-- Mobile: Hamburger + Centered Logo + Language -->
            <div class="flex items-center justify-between w-full md:hidden">
                <!-- Hamburger Button -->
                <button
                    @click="mobileMenuOpen = !mobileMenuOpen"
                    class="p-2 text-off-white hover:text-cta focus:outline-none min-h-[44px] min-w-[44px] flex items-center justify-center"
                    :aria-expanded="mobileMenuOpen"
                    aria-label="{{ __('Toggle navigation menu') }}"
                    data-test="mobile-menu-button"
                >
                    <svg x-show="!mobileMenuOpen" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
                    </svg>
                    <svg x-show="mobileMenuOpen" x-cloak class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>

                <!-- Centered Logo on Mobile -->
                <a href="{{ route('home') }}" class="flex items-center" wire:navigate>
                    <x-logo size="sm" class="logo-badge" />
                </a>

                <!-- Language Toggle on Mobile -->
                <div class="min-w-[44px]">
                    <x-language-toggle />
                </div>
            </div>

            <!-- Desktop Navigation Links -->
            <div class="hidden md:flex md:items-center md:gap-6">
                <a
                    href="{{ route('home') }}"
                    @class([
                        'text-off-white hover:text-cta transition-colors py-2',
                        'border-b-2 border-cta' => request()->routeIs('home'),
                    ])
                    wire:navigate
                    data-test="nav-home"
                >
                    {{ __('navigation.home') }}
                </a>
                <a
                    href="{{ route('about') }}"
                    @class([
                        'text-off-white hover:text-cta transition-colors py-2',
                        'border-b-2 border-cta' => request()->routeIs('about'),
                    ])
                    wire:navigate
                    data-test="nav-about"
                >
                    {{ __('navigation.about') }}
                </a>
                <a
                    href="{{ route('booking') }}"
                    @class([
                        'text-off-white hover:text-cta transition-colors py-2',
                        'border-b-2 border-cta' => request()->routeIs('booking*'),
                    ])
                    wire:navigate
                    data-test="nav-booking"
                >
                    {{ __('navigation.booking') }}
                </a>
                <a
                    href="{{ route('posts.index') }}"
                    @class([
                        'text-off-white hover:text-cta transition-colors py-2',
                        'border-b-2 border-cta' => request()->routeIs('posts*'),
                    ])
                    wire:navigate
                    data-test="nav-posts"
                >
                    {{ __('navigation.posts') }}
                </a>

                @auth
                    @php
                        $dashboardRoute = auth()->user()->isAdmin() ? route('admin.dashboard') : route('client.dashboard');
                    @endphp
                    <a
                        href="{{ $dashboardRoute }}"
                        @class([
                            'text-off-white hover:text-cta transition-colors py-2',
                            'border-b-2 border-cta' => request()->routeIs('*.dashboard'),
                        ])
                        wire:navigate
                        data-test="nav-dashboard"
                    >
                        {{ __('navigation.dashboard') }}
                    </a>
                    <form method="POST" action="{{ route('logout') }}" class="inline">
                        @csrf
                        <button
                            type="submit"
                            class="text-off-white hover:text-cta transition-colors py-2"
                            data-test="nav-logout"
                        >
                            {{ __('navigation.logout') }}
                        </button>
                    </form>
                @else
                    <a
                        href="{{ route('login') }}"
                        @class([
                            'text-off-white hover:text-cta transition-colors py-2',
                            'border-b-2 border-cta' => request()->routeIs('login'),
                        ])
                        wire:navigate
                        data-test="nav-login"
                    >
                        {{ __('navigation.login') }}
                    </a>
                @endauth
            </div>

            <!-- Desktop Language Toggle -->
            <div class="hidden md:block">
                <x-language-toggle />
            </div>
        </div>
    </div>

    <!-- Mobile Menu -->
    <div
        x-show="mobileMenuOpen"
        x-trap.inert.noscroll="mobileMenuOpen"
        x-transition:enter="transition ease-out duration-200"
        x-transition:enter-start="opacity-0 -translate-y-1"
        x-transition:enter-end="opacity-100 translate-y-0"
        x-transition:leave="transition ease-in duration-150"
        x-transition:leave-start="opacity-100 translate-y-0"
        x-transition:leave-end="opacity-0 -translate-y-1"
        x-cloak
        @click.away="mobileMenuOpen = false"
        @keydown.escape.window="mobileMenuOpen = false"
        class="md:hidden bg-primary border-t border-cta/20"
        role="dialog"
        aria-modal="true"
        aria-label="{{ __('Mobile navigation menu') }}"
        data-test="mobile-menu"
    >
        <div class="px-4 py-3 space-y-1">
            <a
                href="{{ route('home') }}"
                @class([
                    'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                    'bg-active border-s-2 border-cta' => request()->routeIs('home'),
                ])
                wire:navigate
                @click="mobileMenuOpen = false"
                data-test="mobile-nav-home"
            >
                {{ __('navigation.home') }}
            </a>
            <a
                href="{{ route('about') }}"
                @class([
                    'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                    'bg-active border-s-2 border-cta' => request()->routeIs('about'),
                ])
                wire:navigate
                @click="mobileMenuOpen = false"
                data-test="mobile-nav-about"
            >
                {{ __('navigation.about') }}
            </a>
            <a
                href="{{ route('booking') }}"
                @class([
                    'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                    'bg-active border-s-2 border-cta' => request()->routeIs('booking*'),
                ])
                wire:navigate
                @click="mobileMenuOpen = false"
                data-test="mobile-nav-booking"
            >
                {{ __('navigation.booking') }}
            </a>
            <a
                href="{{ route('posts.index') }}"
                @class([
                    'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                    'bg-active border-s-2 border-cta' => request()->routeIs('posts*'),
                ])
                wire:navigate
                @click="mobileMenuOpen = false"
                data-test="mobile-nav-posts"
            >
                {{ __('navigation.posts') }}
            </a>

            @auth
                @php
                    $dashboardRoute = auth()->user()->isAdmin() ? route('admin.dashboard') : route('client.dashboard');
                @endphp
                <a
                    href="{{ $dashboardRoute }}"
                    @class([
                        'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                        'bg-active border-s-2 border-cta' => request()->routeIs('*.dashboard'),
                    ])
                    wire:navigate
                    @click="mobileMenuOpen = false"
                    data-test="mobile-nav-dashboard"
                >
                    {{ __('navigation.dashboard') }}
                </a>
                <form method="POST" action="{{ route('logout') }}">
                    @csrf
                    <button
                        type="submit"
                        class="w-full text-start px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center"
                        data-test="mobile-nav-logout"
                    >
                        {{ __('navigation.logout') }}
                    </button>
                </form>
            @else
                <a
                    href="{{ route('login') }}"
                    @class([
                        'block px-3 py-3 text-off-white hover:text-cta hover:bg-primary-light rounded-md min-h-[44px] flex items-center',
                        'bg-active border-s-2 border-cta' => request()->routeIs('login'),
                    ])
                    wire:navigate
                    @click="mobileMenuOpen = false"
                    data-test="mobile-nav-login"
                >
                    {{ __('navigation.login') }}
                </a>
            @endauth
        </div>
    </div>
</nav>
