<div class="space-y-6">
    <div class="animate-rise">
        <h1 class="text-2xl font-bold tracking-tight text-ink">{{ __('security.blocks_title') }}</h1>
        <p class="mt-1 max-w-[65ch] text-sm text-muted">{{ __('security.blocks_lead') }}</p>
    </div>

    {{-- Aktive Sperren --}}
    <div class="overflow-hidden rounded-lg border border-line bg-surface shadow-xs animate-rise [animation-delay:60ms]">
        <div class="border-b border-line px-5 py-4">
            <h2 class="text-sm font-semibold text-ink">{{ __('security.blocks_active') }}</h2>
        </div>
        @if ($active->isEmpty())
            <p class="px-5 py-6 text-sm text-muted">{{ __('security.blocks_empty') }}</p>
        @else
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b border-line bg-surface-2 text-left text-xs font-semibold text-muted">
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_ip') }}</th>
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_blocked') }}</th>
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_expires') }}</th>
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_attempts') }}</th>
                            <th class="px-4 py-3 text-right font-semibold">{{ __('security.col_actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($active as $block)
                            <tr wire:key="active-{{ $block->uuid }}" class="border-b border-line last:border-0 hover:bg-surface-hover">
                                <td class="px-4 py-3 font-mono text-body">{{ $block->ip }}</td>
                                <td class="px-4 py-3 font-mono text-xs text-muted">{{ $block->blocked_at->local()->isoFormat('DD.MM. HH:mm') }}</td>
                                <td class="px-4 py-3 font-mono text-xs text-muted">{{ $block->expires_at->local()->isoFormat('DD.MM. HH:mm') }}</td>
                                <td class="px-4 py-3 font-mono text-xs text-muted">{{ $block->attempts }}</td>
                                <td class="px-4 py-3 text-right">
                                    {{-- Oeffnet ConfirmReleaseBlock statt hier selbst
                                         freizugeben — Bestaetigung im Modal, nie ein
                                         nativer Browser-Dialog (R23). --}}
                                    <button type="button"
                                            x-on:click="$dispatch('openModal', { component: 'confirm-release-block', arguments: { uuid: '{{ $block->uuid }}' } })"
                                            class="inline-flex items-center gap-1.5 rounded-md border border-line px-2.5 py-1.5 text-xs font-semibold text-muted hover:border-accent-border hover:text-accent-text">
                                        <x-ui.icon name="unlock" class="size-4" />{{ __('security.release') }}
                                    </button>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif
    </div>

    {{-- Fruehere Sperren: abgelaufen von selbst oder vorzeitig aufgehoben. --}}
    <div class="overflow-hidden rounded-lg border border-line bg-surface shadow-xs animate-rise [animation-delay:120ms]">
        <div class="border-b border-line px-5 py-4">
            <h2 class="text-sm font-semibold text-ink">{{ __('security.blocks_history') }}</h2>
        </div>
        @if ($history->isEmpty())
            <p class="px-5 py-6 text-sm text-muted">{{ __('security.blocks_history_empty') }}</p>
        @else
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b border-line bg-surface-2 text-left text-xs font-semibold text-muted">
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_ip') }}</th>
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_blocked') }}</th>
                            <th class="px-4 py-3 font-semibold">{{ __('security.col_status') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($history as $block)
                            <tr wire:key="history-{{ $block->uuid }}" class="border-b border-line last:border-0">
                                <td class="px-4 py-3 font-mono text-body">{{ $block->ip }}</td>
                                <td class="px-4 py-3 font-mono text-xs text-muted">{{ $block->blocked_at->local()->isoFormat('DD.MM. HH:mm') }}</td>
                                <td class="px-4 py-3">
                                    @if ($block->released_at)
                                        <x-ui.badge status="active">{{ __('security.status_released') }}</x-ui.badge>
                                    @else
                                        <x-ui.badge status="info">{{ __('security.status_expired') }}</x-ui.badge>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif
    </div>
</div>
