@php
    $tenant = $getRecord();
    $warnings = $tenant->rbac_last_warnings ?? [];
    $canaries = $tenant->rbac_canary_results ?? [];
@endphp

<div class="space-y-3 rounded-md border border-gray-200 bg-white p-4 shadow-sm">
    <div class="text-sm font-semibold text-gray-800">Last RBAC Setup</div>
    <dl class="grid grid-cols-1 gap-3 sm:grid-cols-2">
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Role</dt>
            <dd class="text-sm text-gray-800">
                {{ $tenant->rbac_role_display_name ?? $tenant->rbac_role_definition_id ?? 'n/a' }}
                @if ($tenant->rbac_role_definition_id)
                    <span class="text-xs text-gray-500">(ID: {{ $tenant->rbac_role_definition_id }})</span>
                @endif
            </dd>
        </div>
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Scope</dt>
            <dd class="text-sm text-gray-800">
                {{ $tenant->rbac_scope_mode ?? 'n/a' }}
                @if ($tenant->rbac_scope_id)
                    ({{ $tenant->rbac_scope_id }})
                @endif
            </dd>
        </div>
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Group ID</dt>
            <dd class="text-sm text-gray-800">{{ $tenant->rbac_group_id ?? 'n/a' }}</dd>
        </div>
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Role Assignment</dt>
            <dd class="text-sm text-gray-800">{{ $tenant->rbac_role_assignment_id ?? 'n/a' }}</dd>
        </div>
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Executed at</dt>
            <dd class="text-sm text-gray-800">{{ optional($tenant->rbac_last_setup_at)->toDateTimeString() ?? 'n/a' }}</dd>
        </div>
        <div>
            <dt class="text-xs uppercase tracking-wide text-gray-500">Executed by (user id)</dt>
            <dd class="text-sm text-gray-800">{{ $tenant->rbac_last_setup_by ?? 'n/a' }}</dd>
        </div>
    </dl>

    <div>
        <div class="text-xs uppercase tracking-wide text-gray-500 mb-1">Canaries</div>
        @if (empty($canaries))
            <div class="text-sm text-gray-700">No canary results recorded.</div>
        @else
            <ul class="space-y-1 text-sm">
                @foreach ($canaries as $key => $status)
                    <li class="flex items-center gap-2">
                        <span class="font-semibold text-gray-800">{{ $key }}:</span>
                        <span class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium
                            {{ $status === 'ok' ? 'bg-green-100 text-green-700' : '' }}
                            {{ $status === 'error' ? 'bg-red-100 text-red-700' : '' }}
                            {{ $status === 'pending' ? 'bg-yellow-100 text-yellow-700' : '' }}
                            {{ !in_array($status, ['ok', 'error', 'pending']) ? 'bg-gray-100 text-gray-700' : '' }}
                        ">
                            {{ $status }}
                        </span>
                    </li>
                @endforeach
            </ul>
        @endif
    </div>

    @if (! empty($warnings))
        <div class="rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-800">
            <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
</div>
