@php
    $user = auth()->user();
    $initials = collect(preg_split('/\s+/u', trim($user->name)) ?: [])
        ->filter()
        ->take(2)
        ->map(fn (string $part) => mb_strtoupper(mb_substr($part, 0, 1)))
        ->implode('');
    $profileUrl = $user->can('update', $user)
        ? \App\Filament\Resources\Users\UserResource::getUrl('edit', ['record' => $user])
        : \App\Filament\Resources\Users\UserResource::getUrl();
@endphp

<x-filament::dropdown placement="bottom-end" teleport>
    <x-slot name="trigger">
        <button type="button" class="tp-admin-user-control" aria-label="{{ __('filament-panels::layout.actions.open_user_menu.label') }}">
            <span class="tp-admin-avatar" aria-hidden="true">{{ $initials }}</span>
            <x-filament::icon icon="heroicon-m-chevron-down" class="tp-admin-user-chevron" />
        </button>
    </x-slot>

    <x-filament::dropdown.header icon="heroicon-o-user-circle">
        <span class="tp-admin-user-name">{{ $user->name }}</span>
        <span class="tp-admin-user-email">{{ $user->email }}</span>
    </x-filament::dropdown.header>

    <x-filament::dropdown.list>
        <x-filament::dropdown.list.item :href="$profileUrl" tag="a" icon="heroicon-o-user-circle">
            {{ __('customer.profile') }}
        </x-filament::dropdown.list.item>
        <form method="POST" action="{{ filament()->getLogoutUrl() }}">
            @csrf
            <x-filament::dropdown.list.item type="submit" icon="heroicon-o-arrow-left-on-rectangle">
                {{ __('ui.sign_out') }}
            </x-filament::dropdown.list.item>
        </form>
    </x-filament::dropdown.list>
</x-filament::dropdown>
