<x-filament-panels::page>
    @php
        $scope = $this->appliedScope();
        $registerStates = $this->availableRegisterStates();
    @endphp

    <x-filament::section>
        <div class="flex flex-col gap-3">
            <div class="inline-flex w-fit items-center gap-2 rounded-full border border-primary-200 bg-primary-50 px-3 py-1 text-xs font-medium text-primary-700 dark:border-primary-700/60 dark:bg-primary-950/40 dark:text-primary-300">
                <x-filament::icon icon="heroicon-o-clipboard-document-check" class="h-3.5 w-3.5" />
                Decision register
            </div>

            <div class="space-y-1">
                <h1 class="text-2xl font-semibold tracking-tight text-gray-950 dark:text-white">
                    Decision register
                </h1>

                <p class="max-w-3xl text-sm leading-6 text-gray-600 dark:text-gray-300">
                    This workspace register shows the current exception and accepted-risk decisions that need follow-through without opening a second approval lane.
                </p>
            </div>

            <div class="flex flex-wrap gap-2 text-sm text-gray-600 dark:text-gray-300">
                @if (filled($scope['workspace_label'] ?? null))
                    <span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-xs font-medium text-gray-700 dark:bg-gray-800 dark:text-gray-200">
                        Workspace: {{ $scope['workspace_label'] }}
                    </span>
                @endif

                <span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-xs font-medium text-gray-700 dark:bg-gray-800 dark:text-gray-200">
                    Scope: {{ $scope['register_state_label'] ?? 'Open decisions' }}
                </span>

                <span class="inline-flex items-center rounded-full bg-gray-100 px-3 py-1 text-xs font-medium text-gray-700 dark:bg-gray-800 dark:text-gray-200">
                    Visible rows: {{ $scope['visible_count'] ?? 0 }}
                </span>

                @if (filled($scope['tenant_label'] ?? null))
                    <span class="inline-flex items-center rounded-full bg-warning-50 px-3 py-1 text-xs font-medium text-warning-700 dark:bg-warning-500/10 dark:text-warning-300">
                        Environment: {{ $scope['tenant_label'] }}
                    </span>
                @endif
            </div>

            @if ($this->hasTenantPrefilter())
                @include('filament.partials.workspace-hub-environment-filter-chip', [
                    'label' => $scope['tenant_label'] ?? null,
                    'clearUrl' => $this->pageUrl(['environment_id' => null, 'register_state' => 'open']),
                ])
            @endif

            <div class="flex flex-wrap gap-2">
                @foreach ($registerStates as $registerState)
                    <a
                        href="{{ $this->pageUrl(['register_state' => $registerState['key']]) }}"
                        class="inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-sm font-medium transition {{ $this->isActiveRegisterState($registerState['key']) ? 'border-primary-300 bg-primary-50 text-primary-700 dark:border-primary-700/60 dark:bg-primary-950/40 dark:text-primary-300' : 'border-gray-200 text-gray-700 hover:border-gray-300 dark:border-gray-700 dark:text-gray-200 dark:hover:border-gray-600' }}"
                    >
                        {{ $registerState['label'] }}
                        <span class="rounded-full bg-black/5 px-2 py-0.5 text-xs dark:bg-white/10">{{ $registerState['count'] }}</span>
                    </a>
                @endforeach
            </div>

        </div>
    </x-filament::section>

    {{ $this->table }}
</x-filament-panels::page>
