<x-filament-panels::page>
    @php
        $environmentFilterChip = $this->environmentFilterChip();
        $reviewPayload = $this->latestReviewConsumptionPayload();
    @endphp

    <x-filament::section>
        <div class="flex flex-col gap-3">
            <div class="text-lg font-semibold text-gray-900 dark:text-gray-100">
                {{ __('localization.review.customer_safe_review_workspace') }}
            </div>

            <div class="text-sm text-gray-600 dark:text-gray-300">
                {{ __('localization.review.customer_workspace_intro') }}
            </div>

            <div class="text-sm text-gray-600 dark:text-gray-300">
                {{ __('localization.review.customer_workspace_canonical_note') }}
            </div>

            <div class="rounded-md border border-amber-100 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:border-amber-900/40 dark:bg-amber-950/30 dark:text-amber-200">
                {{ __('localization.review.customer_workspace_non_certification_disclosure') }}
            </div>

            @if ($environmentFilterChip !== null)
                @include('filament.partials.workspace-hub-environment-filter-chip', [
                    'label' => $environmentFilterChip['label'],
                    'clearUrl' => $environmentFilterChip['clear_url'],
                ])
            @endif
        </div>
    </x-filament::section>

    @if ($reviewPayload)
        @php
            $latest = $reviewPayload['latest'];
            $decision = $reviewPayload['decision'];
            $acceptedRisks = $reviewPayload['accepted_risks'];
            $evidenceBasis = $reviewPayload['evidence_basis'];
        @endphp

        <x-filament::section :heading="__('localization.review.latest_released_review')">
            <div class="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
                <div class="flex flex-col gap-3">
                    <div>
                        <div class="text-base font-semibold text-gray-950 dark:text-white">
                            {{ $latest['review_label'] }}
                        </div>
                        <div class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                            {{ __('localization.review.published_date', ['date' => $latest['published_label']]) }}
                        </div>
                    </div>

                    <div class="flex flex-wrap items-center gap-2">
                        <x-filament::badge :color="$latest['status_color']">
                            {{ $latest['status_label'] }}
                        </x-filament::badge>
                        <x-filament::badge :color="$latest['package_color']">
                            {{ $latest['package_badge_label'] }}
                        </x-filament::badge>
                    </div>

                    <div class="text-xs font-medium uppercase text-gray-500 dark:text-gray-400">
                        {{ __('localization.review.review_pack') }}
                    </div>

                    <p class="max-w-3xl text-sm text-gray-600 dark:text-gray-300">
                        {{ $latest['package_description'] }}
                    </p>
                </div>

                <div class="flex flex-wrap gap-2 lg:justify-end">
                    @if ($latest['primary_action_url'])
                        <x-filament::button
                            tag="a"
                            :href="$latest['primary_action_url']"
                            :icon="$latest['primary_action_icon']"
                            target="_blank"
                        >
                            {{ $latest['primary_action_label'] }}
                        </x-filament::button>
                    @endif

                    @if ($latest['secondary_action_url'])
                        <x-filament::button
                            tag="a"
                            :href="$latest['secondary_action_url']"
                            color="gray"
                            icon="heroicon-o-arrow-top-right-on-square"
                        >
                            {{ $latest['secondary_action_label'] }}
                        </x-filament::button>
                    @endif
                </div>
            </div>
        </x-filament::section>

        <div class="grid gap-4 lg:grid-cols-3">
            <x-filament::section :heading="__('localization.review.decision_summary')">
                <div class="flex flex-col gap-3">
                    <x-filament::badge :color="$decision['color']">
                        {{ $decision['label'] }}
                    </x-filament::badge>

                    <p class="text-sm text-gray-600 dark:text-gray-300">
                        {{ $decision['summary'] }}
                    </p>

                    <p class="text-sm font-medium text-gray-800 dark:text-gray-100">
                        {{ $decision['next_action'] }}
                    </p>

                    @foreach ($decision['entries'] as $entry)
                        <div class="border-t border-gray-200 pt-3 text-sm dark:border-white/10">
                            <div class="font-medium text-gray-950 dark:text-white">
                                {{ $entry['title'] }}
                            </div>
                            <div class="mt-1 text-gray-600 dark:text-gray-300">
                                {{ $entry['summary'] }}
                            </div>
                            <div class="mt-1 text-gray-500 dark:text-gray-400">
                                {{ $entry['next_action'] }}
                            </div>
                        </div>
                    @endforeach
                </div>
            </x-filament::section>

            <x-filament::section :heading="__('localization.review.accepted_risks')">
                <div class="flex flex-col gap-3">
                    @forelse ($acceptedRisks['entries'] as $risk)
                        <div class="text-sm">
                            <div class="flex flex-wrap items-center gap-2">
                                <span class="font-medium text-gray-950 dark:text-white">{{ $risk['title'] }}</span>
                                <x-filament::badge color="gray" size="sm">
                                    {{ $risk['state_label'] }}
                                </x-filament::badge>
                            </div>
                            <div class="mt-1 text-gray-600 dark:text-gray-300">
                                {{ $risk['summary'] }}
                            </div>
                        </div>
                    @empty
                        <p class="text-sm text-gray-600 dark:text-gray-300">
                            {{ $acceptedRisks['empty_state'] }}
                        </p>
                    @endforelse
                </div>
            </x-filament::section>

            <x-filament::section :heading="__('localization.review.evidence_basis')">
                <div class="flex flex-col gap-3">
                    <x-filament::badge :color="$evidenceBasis['color']">
                        {{ $evidenceBasis['label'] }}
                    </x-filament::badge>

                    <p class="text-sm text-gray-600 dark:text-gray-300">
                        {{ $evidenceBasis['summary'] }}
                    </p>
                </div>
            </x-filament::section>
        </div>
    @endif

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