@php
    $languages = $availableLanguages ?? collect();
    $current = $currentLanguage ?? null;
@endphp

@if ($languages->count() > 1)
    <div class="dropdown topnav-dropdown-item erp-toolbar-action">
        <button type="button" class="topnav-icon-btn erp-lang-btn" data-bs-toggle="dropdown"
            aria-expanded="false" title="{{ __('languages.switcher') }}"
            aria-label="{{ __('languages.switcher') }}">
            <i class="fe fe-globe" aria-hidden="true"></i>
            <span class="erp-lang-code">{{ $current?->code ?? app()->getLocale() }}</span>
        </button>
        <ul class="dropdown-menu dropdown-menu-end shadow-sm">
            @foreach ($languages as $language)
                <li>
                    <form method="POST" action="{{ route('locale.switch', $language->code) }}" class="m-0">
                        @csrf
                        <button type="submit"
                                @class(['dropdown-item', 'active' => $current?->id === $language->id])>
                            <span class="text-uppercase small text-muted me-2">{{ $language->code }}</span>
                            {{ $language->native_name ?? $language->name }}
                        </button>
                    </form>
                </li>
            @endforeach
        </ul>
    </div>
@endif
