<x-filament-panels::page>
    <div class="space-y-6">
        {{-- Stats widgets --}}
        @if (method_exists($this, 'getHeaderWidgets'))
            <x-filament-widgets::widgets
                :widgets="$this->getVisibleHeaderWidgets()"
                :columns="1"
            />
        @endif

        {{-- Purpose box --}}
        <div class="rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-800 dark:bg-gray-900">
            <div class="text-sm text-gray-700 dark:text-gray-200">
                <p class="font-medium">Purpose</p>
                <p class="mt-1">
                    This page exists to recover from broken workspace ownership state (e.g. a workspace with zero owners due to manual DB edits).
                    Actions here require break-glass mode, active workspace recovery support access, and full audit logging.
                </p>
                <p class="mt-3 text-warning-700 dark:text-warning-300">
                    {{ $this->recoveryBoundarySummary() }}
                </p>
            </div>
        </div>

        {{-- Workspace table --}}
        {{ $this->table }}

        {{-- Recent break-glass and support-access actions --}}
        @php
            $recentActions = $this->getRecentRecoveryGovernanceActions();
        @endphp

        <x-filament::section>
            <x-slot name="heading">
                Recent recovery governance actions
            </x-slot>

            <x-slot name="description">
                Last 10 break-glass and support-access audit log entries.
            </x-slot>

            @if (empty($recentActions))
                <div class="rounded-lg border border-dashed border-gray-300 px-4 py-6 text-center text-sm text-gray-500 dark:border-white/15 dark:text-gray-400">
                    No break-glass or support-access actions recorded yet.
                </div>
            @else
                <div class="divide-y divide-gray-200 dark:divide-white/10">
                    @foreach ($recentActions as $entry)
                        <div class="flex items-center justify-between gap-4 px-1 py-3">
                            <div class="min-w-0 flex-1">
                                <div class="truncate text-sm font-medium text-gray-950 dark:text-white">
                                    {{ $entry['action'] }}
                                </div>
                                <div class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">
                                    by {{ $entry['actor'] }}
                                    @if ($entry['workspace'])
                                        &middot; Workspace: {{ $entry['workspace'] }}
                                    @endif
                                </div>
                            </div>
                            <div class="shrink-0 text-xs text-gray-500 dark:text-gray-400">
                                {{ $entry['recorded_at'] }}
                            </div>
                        </div>
                    @endforeach
                </div>
            @endif
        </x-filament::section>
    </div>
</x-filament-panels::page>
