@props([
    'boundRolesUser' => null,
    'variant' => 'badge',
])

@php
    use App\Enums\AdminRoleStatus;
    use App\Models\User;

    $user = $boundRolesUser ?? filament()->auth()->user();
@endphp
@if ($user instanceof User)
    @php
        $roleNames = $user->adminRoles()
            ->where('core_roles.status', AdminRoleStatus::Enabled->value)
            ->orderBy('core_roles.sort_order')
            ->orderBy('core_roles.id')
            ->pluck('core_roles.display_name')
            ->filter(fn (mixed $name): bool => filled($name))
            ->map(fn (mixed $name): string => (string) $name)
            ->values()
            ->all();
    @endphp
    @if ($roleNames !== [])
        @if ($variant === 'badge')
            <div class="mt-1.5 flex flex-wrap gap-1">
                @foreach ($roleNames as $roleName)
                    <span
                        class="inline-flex items-center rounded-full bg-primary-50 px-2 py-0.5 text-xs font-medium text-primary-700 ring-1 ring-inset ring-primary-200 dark:bg-primary-950 dark:text-primary-300 dark:ring-primary-800"
                    >
                        {{ $roleName }}
                    </span>
                @endforeach
            </div>
        @else
            @php
                $rolesText = implode((string) __('dberp.admin.bound_roles_separator'), $roleNames);
            @endphp
            <span
                class="max-w-[min(10rem,40vw)] shrink-0 truncate rounded-full bg-primary-50 px-2 py-0.5 text-xs font-medium text-primary-700 ring-1 ring-inset ring-primary-200 dark:bg-primary-950 dark:text-primary-300 dark:ring-primary-800"
                title="{{ $rolesText }}"
            >
                {{ $rolesText }}
            </span>
        @endif
    @endif
@endif
