@props([
    'title',
    'description' => null,
    'items' => [],
    'badgeColor' => 'gray',
    'emptyMessage' => null,
    'showCount' => false,
])

@php
    $dotClasses = match ($badgeColor) {
        'primary' => 'bg-primary-500',
        'success' => 'bg-success-500',
        'warning' => 'bg-warning-500',
        'danger' => 'bg-danger-500',
        'info' => 'bg-info-500',
        default => 'bg-gray-400',
    };

    $hintClasses = match ($badgeColor) {
        'primary' => 'text-primary-600 dark:text-primary-400',
        'success' => 'text-success-600 dark:text-success-400',
        'warning' => 'text-warning-600 dark:text-warning-400',
        'danger' => 'text-danger-600 dark:text-danger-400',
        'info' => 'text-info-600 dark:text-info-400',
        default => 'text-gray-500 dark:text-gray-400',
    };
@endphp

<x-filament::section>
    <x-slot name="heading">
        <div class="flex items-center gap-2">
            <span>{{ $title }}</span>

            <x-filament::badge :color="$badgeColor" size="sm">
                {{ count($items) }}
            </x-filament::badge>
        </div>
    </x-slot>

    @if (filled($description))
        <p class="mb-3 text-sm text-gray-500 dark:text-gray-400">
            {{ $description }}
        </p>
    @endif

    <div class="space-y-1">
        @forelse ($items as $item)
            <a
                href="{{ $item['url'] }}"
                class="group flex items-start justify-between gap-3 rounded-xl px-3 py-3 transition hover:bg-gray-50 dark:hover:bg-white/5"
            >
                <div class="min-w-0 flex-1">
                    <div class="flex items-start gap-2">
                        <span class="mt-1.5 h-2 w-2 flex-none rounded-full {{ $dotClasses }}"></span>

                        <div class="min-w-0">
                            <div class="truncate text-sm font-medium text-gray-950 dark:text-white">
                                {{ $item['title'] }}
                            </div>

                            @if (filled($item['amount'] ?? null))
                                <div class="mt-1 text-xs {{ $hintClasses }}">
                                    {{ $item['amount'] }}
                                </div>
                            @endif
                        </div>
                    </div>
                </div>

                @if ($showCount && array_key_exists('count', $item))
                    <x-filament::badge :color="$badgeColor" size="sm">
                        {{ $item['count'] }}
                    </x-filament::badge>
                @else
                    <span class="shrink-0 text-xs font-medium text-gray-400 transition group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300">
                        {{ __('dberp.widgets.workbench_shared.view') }}
                    </span>
                @endif
            </a>
        @empty
            <div class="rounded-xl border border-dashed border-gray-300 px-3 py-6 text-sm text-gray-500 dark:border-white/10 dark:text-gray-400">
                {{ $emptyMessage ?? __('dberp.widgets.workbench_shared.default_empty') }}
            </div>
        @endforelse
    </div>
</x-filament::section>