<x-filament-panels::page>
    @php
        $summary = $this->coverageSummary();
        $basis = $this->basisRunSummary();
    @endphp

    <x-filament::section>
        <div class="grid gap-4 xl:grid-cols-[minmax(0,1.8fr)_minmax(0,1fr)]">
            <div class="space-y-4">
                <div class="space-y-2">
                    <div class="text-lg font-semibold text-gray-900 dark:text-white">
                        ManagedEnvironment coverage truth
                    </div>

                    <div class="text-sm text-gray-600 dark:text-gray-300">
                        This report shows which supported inventory types are currently covered for the active tenant, which ones still need follow-up, and what the statement is based on.
                    </div>
                </div>

                <div class="grid gap-3 sm:grid-cols-3">
                    <div class="rounded-2xl border border-gray-200 bg-white px-4 py-4 shadow-sm dark:border-gray-800 dark:bg-gray-900/60">
                        <div class="text-xs font-medium uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400">
                            Covered types
                        </div>

                        <div class="mt-2 text-2xl font-semibold text-gray-950 dark:text-white">
                            {{ $summary['succeededTypes'] ?? 0 }} / {{ $summary['supportedTypes'] ?? 0 }}
                        </div>

                        <div class="mt-2 text-sm text-gray-600 dark:text-gray-300">
                            Current supported types with a successful basis result.
                        </div>
                    </div>

                    <div class="rounded-2xl border border-gray-200 bg-white px-4 py-4 shadow-sm dark:border-gray-800 dark:bg-gray-900/60">
                        <div class="text-xs font-medium uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400">
                            Need follow-up
                        </div>

                        <div class="mt-2 text-2xl font-semibold text-gray-950 dark:text-white">
                            {{ $summary['followUpTypes'] ?? 0 }}
                        </div>

                        <div class="mt-2 text-sm text-gray-600 dark:text-gray-300">
                            @if (filled($summary['topFollowUpLabel'] ?? null))
                                Highest-priority type: {{ $summary['topFollowUpLabel'] }}.
                            @else
                                No follow-up types are currently highlighted.
                            @endif
                        </div>
                    </div>

                    <div class="rounded-2xl border border-gray-200 bg-white px-4 py-4 shadow-sm dark:border-gray-800 dark:bg-gray-900/60">
                        <div class="text-xs font-medium uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400">
                            Observed items
                        </div>

                        <div class="mt-2 text-2xl font-semibold text-gray-950 dark:text-white">
                            {{ $summary['observedItems'] ?? 0 }}
                        </div>

                        <div class="mt-2 text-sm text-gray-600 dark:text-gray-300">
                            {{ $summary['observedTypes'] ?? 0 }} supported types currently have observed inventory rows.
                        </div>
                    </div>
                </div>

                @if (filled($summary['topFollowUpGuidance'] ?? null))
                    <div class="rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-100">
                        {{ $summary['topFollowUpGuidance'] }}
                    </div>
                @endif
            </div>

            <div class="rounded-2xl border border-gray-200 bg-white px-4 py-4 shadow-sm dark:border-gray-800 dark:bg-gray-900/60">
                <div class="space-y-3">
                    <div class="flex flex-wrap items-start justify-between gap-3">
                        <div class="space-y-1">
                            <div class="text-xs font-medium uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400">
                                Coverage basis
                            </div>

                            <div class="text-base font-semibold text-gray-950 dark:text-white">
                                {{ $basis['title'] ?? 'No current coverage basis' }}
                            </div>
                        </div>

                        @if (filled($basis['badgeLabel'] ?? null))
                            <x-filament::badge :color="$basis['badgeColor'] ?? 'gray'" size="sm">
                                {{ $basis['badgeLabel'] }}
                            </x-filament::badge>
                        @endif
                    </div>

                    <div class="text-sm text-gray-600 dark:text-gray-300">
                        {{ $basis['body'] ?? 'No current coverage basis is available.' }}
                    </div>

                    <div class="flex flex-wrap items-center gap-3">
                        @if (filled($basis['runUrl'] ?? null))
                            <x-filament::link :href="$basis['runUrl']" size="sm">
                                Open basis run
                            </x-filament::link>
                        @endif

                        @if (filled($basis['historyUrl'] ?? null))
                            <x-filament::link :href="$basis['historyUrl']" size="sm">
                                Inventory sync history
                            </x-filament::link>
                        @endif

                        @if (filled($basis['inventoryItemsUrl'] ?? null))
                            <x-filament::link :href="$basis['inventoryItemsUrl']" size="sm">
                                Open inventory items
                            </x-filament::link>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </x-filament::section>

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