@php
    $state = is_array($state ?? null) ? $state : [];

    $surface = array_key_exists('renderExpectations', $state)
        ? $state
        : \App\Filament\Support\NormalizedSettingsSurface::build(
            $state,
            ($state['context'] ?? 'policy') === 'policy' ? 'policy' : 'policy_version'
        );

    $warnings = is_array($surface['warnings'] ?? null) ? $surface['warnings'] : [];
    $settingsTable = is_array($surface['settingsTable'] ?? null) ? $surface['settingsTable'] : null;
    $settingsTableRows = is_array($settingsTable['rows'] ?? null) ? $settingsTable['rows'] : [];
    $blocks = is_array($surface['blocks'] ?? null) ? $surface['blocks'] : [];
    $emptyState = is_array($surface['emptyState'] ?? null) ? $surface['emptyState'] : null;
@endphp

<div
    class="space-y-4"
    data-shared-detail-family="normalized-settings"
    data-shared-normalized-settings-host="{{ $surface['hostKind'] ?? 'unknown' }}"
    data-shared-normalized-settings-variant="{{ $surface['variant'] ?? 'standard_blocks' }}"
>
    @if ($warnings !== [])
        <div class="rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-800" data-shared-zone="warnings">
            <div class="font-semibold">Warnings</div>
            <ul class="mt-1 list-disc space-y-1 pl-5">
                @foreach ($warnings as $warning)
                    <li>{{ $warning }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    @if ($settingsTableRows !== [])
        @include('filament.infolists.entries.normalized-settings.catalog-table', [
            'settingsTable' => $settingsTable,
            'context' => $surface['context'] ?? 'policy',
            'recordId' => $surface['recordId'] ?? null,
        ])
    @endif

    @if ($blocks !== [])
        @include('filament.infolists.entries.normalized-settings.standard-blocks', [
            'blocks' => $blocks,
            'policyType' => $surface['policyType'] ?? null,
        ])
    @endif

    @if ($settingsTableRows === [] && $blocks === [] && $emptyState !== null)
        <div class="rounded-lg border border-dashed border-gray-300 bg-white px-6 py-8 text-center dark:border-white/15 dark:bg-gray-900/40" data-shared-zone="empty">
            <p class="text-sm font-medium text-gray-900 dark:text-white">{{ $emptyState['title'] ?? 'No settings available.' }}</p>
            <p class="mt-1 text-sm text-gray-600 dark:text-gray-300">{{ $emptyState['message'] ?? 'No normalized settings payload is available for this host.' }}</p>
        </div>
    @endif
</div>