@php
    $farmaciaActive = request()->routeIs('products.*', 'pos.*');
    $clinicaActive = request()->routeIs('clients.*', 'clinica.*');
@endphp

<nav x-data="{ open: false }" class="relative z-50 border-b border-teal-200/80 bg-white/95 shadow-md shadow-slate-200/30 backdrop-blur-md dark:border-teal-300/60 dark:bg-white/95 dark:shadow-slate-300/25">
    <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">
                <div class="shrink-0 flex items-center">
                    <a href="{{ route('dashboard') }}">
                        <x-application-logo class="block h-9 w-auto fill-current text-gray-800 dark:text-gray-200" />
                    </a>
                </div>

                <div class="hidden space-x-1 sm:-my-px sm:ms-6 sm:flex sm:items-center">
                    <x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
                        {{ __('Panel') }}
                    </x-nav-link>

                    @if (auth()->user()->can('inventory.view') || auth()->user()->can('pos.use'))
                        <x-dropdown align="left" width="56">
                            <x-slot name="trigger">
                                <button type="button" class="inline-flex items-center rounded-lg px-3 py-2 text-sm font-semibold leading-5 transition duration-150 ease-in-out focus:outline-none focus:ring-2 focus:ring-teal-400/50 {{ $farmaciaActive ? 'bg-gradient-to-r from-cyan-500/15 to-teal-500/15 text-teal-800 ring-1 ring-teal-400/40 dark:from-cyan-500/10 dark:to-teal-500/10 dark:text-teal-200' : 'text-slate-600 hover:bg-teal-50/80 hover:text-teal-800 dark:text-slate-300 dark:hover:bg-teal-950/40 dark:hover:text-teal-200' }}">
                                    {{ __('Farmacia / POS') }}
                                    <svg class="ms-1 h-4 w-4 fill-current" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" /></svg>
                                </button>
                            </x-slot>
                            <x-slot name="content">
                                @can('inventory.view')
                                    <x-dropdown-link :href="route('products.index')">{{ __('Productos e inventario') }}</x-dropdown-link>
                                @endcan
                                @can('pos.use')
                                    <x-dropdown-link :href="route('pos.index')">{{ __('Punto de venta') }}</x-dropdown-link>
                                @endcan
                            </x-slot>
                        </x-dropdown>
                    @endif

                    @can('clients.view')
                        <x-dropdown align="left" width="56">
                            <x-slot name="trigger">
                                <button type="button" class="inline-flex items-center rounded-lg px-3 py-2 text-sm font-semibold leading-5 transition duration-150 ease-in-out focus:outline-none focus:ring-2 focus:ring-violet-400/50 {{ $clinicaActive ? 'bg-gradient-to-r from-violet-500/15 to-fuchsia-500/10 text-violet-900 ring-1 ring-violet-400/40 dark:from-violet-500/10 dark:to-fuchsia-500/10 dark:text-violet-200' : 'text-slate-600 hover:bg-violet-50/80 hover:text-violet-900 dark:text-slate-300 dark:hover:bg-violet-950/40 dark:hover:text-violet-200' }}">
                                    {{ __('Clínica') }}
                                    <svg class="ms-1 h-4 w-4 fill-current" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" /></svg>
                                </button>
                            </x-slot>
                            <x-slot name="content">
                                <x-dropdown-link :href="route('clinica.hub')">{{ __('Buscar expediente (código)') }}</x-dropdown-link>
                                <x-dropdown-link :href="route('clients.index')">{{ __('Clientes y pacientes') }}</x-dropdown-link>
                                @can('appointments.view')
                                    <x-dropdown-link :href="route('clinica.appointments.index')">{{ __('Citas') }}</x-dropdown-link>
                                @endcan
                            </x-slot>
                        </x-dropdown>
                    @endcan
                </div>
            </div>

            <div class="hidden sm:flex sm:items-center sm:ms-6">
                <x-dropdown align="right" width="48">
                    <x-slot name="trigger">
                        <button class="inline-flex items-center gap-1 rounded-xl bg-gradient-to-r from-teal-600 to-emerald-600 px-4 py-2 text-sm font-semibold leading-4 text-white shadow-md shadow-teal-600/30 transition hover:from-teal-700 hover:to-emerald-700 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-teal-400 focus:ring-offset-2 dark:focus:ring-offset-slate-900">
                            <div>{{ Auth::user()->name }}</div>
                            <div class="ms-1">
                                <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
                                    <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
                                </svg>
                            </div>
                        </button>
                    </x-slot>

                    <x-slot name="content">
                        <x-dropdown-link :href="route('profile.edit')">
                            {{ __('Profile') }}
                        </x-dropdown-link>

                        <form method="POST" action="{{ route('logout') }}">
                            @csrf
                            <x-dropdown-link :href="route('logout')"
                                    onclick="event.preventDefault();
                                                this.closest('form').submit();">
                                {{ __('Log Out') }}
                            </x-dropdown-link>
                        </form>
                    </x-slot>
                </x-dropdown>
            </div>

            <div class="-me-2 flex items-center sm:hidden">
                <button @click="open = ! open" class="inline-flex items-center justify-center rounded-xl p-2 text-teal-700 transition hover:bg-teal-100 hover:text-teal-900 focus:outline-none focus:ring-2 focus:ring-teal-400 dark:text-teal-300 dark:hover:bg-teal-950 dark:hover:text-teal-100">
                    <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>

    <div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden">
        <div class="pt-2 pb-3 space-y-1">
            <x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
                {{ __('Panel') }}
            </x-responsive-nav-link>
            @can('inventory.view')
                <x-responsive-nav-link :href="route('products.index')" :active="request()->routeIs('products.*')">
                    {{ __('Farmacia: productos') }}
                </x-responsive-nav-link>
            @endcan
            @can('pos.use')
                <x-responsive-nav-link :href="route('pos.index')" :active="request()->routeIs('pos.*')">
                    {{ __('Farmacia: POS') }}
                </x-responsive-nav-link>
            @endcan
            @can('clients.view')
                <x-responsive-nav-link :href="route('clinica.hub')" :active="request()->routeIs('clinica.hub', 'clinica.search')">
                    {{ __('Clínica: buscar expediente') }}
                </x-responsive-nav-link>
                <x-responsive-nav-link :href="route('clients.index')" :active="request()->routeIs('clients.*')">
                    {{ __('Clínica: clientes') }}
                </x-responsive-nav-link>
            @endcan
            @can('appointments.view')
                <x-responsive-nav-link :href="route('clinica.appointments.index')" :active="request()->routeIs('clinica.*')">
                    {{ __('Clínica: citas') }}
                </x-responsive-nav-link>
            @endcan
        </div>

        <div class="pt-4 pb-1 border-t border-teal-200/80 dark:border-teal-800/60">
            <div class="px-4">
                <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 class="mt-3 space-y-1">
                <x-responsive-nav-link :href="route('profile.edit')">
                    {{ __('Profile') }}
                </x-responsive-nav-link>

                <form method="POST" action="{{ route('logout') }}">
                    @csrf
                    <x-responsive-nav-link :href="route('logout')"
                            onclick="event.preventDefault();
                                        this.closest('form').submit();">
                        {{ __('Log Out') }}
                    </x-responsive-nav-link>
                </form>
            </div>
        </div>
    </div>
</nav>
