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

    $view = is_string($card['view'] ?? null) && trim($card['view']) !== '' ? trim($card['view']) : null;
    $items = is_array($card['items'] ?? null) ? $card['items'] : [];
    $emptyState = is_array($card['emptyState'] ?? null) ? $card['emptyState'] : null;
    $action = is_array($card['action'] ?? null) ? $card['action'] : null;
    $eyebrow = match ($card['kind'] ?? null) {
        'guidance' => 'Guidance',
        'lifecycle' => 'Lifecycle',
        'timing' => 'Timing',
        'metadata' => 'Metadata',
        default => 'Supporting detail',
    };
@endphp

<div class="space-y-2" @if (filled($card['kind'] ?? null)) data-supporting-group-kind="{{ $card['kind'] }}" @endif>
    <div class="text-[11px] font-semibold uppercase tracking-[0.18em] text-gray-500 dark:text-gray-400">
        {{ $eyebrow }}
    </div>

    <x-filament::section
        :heading="$card['title'] ?? 'Supporting detail'"
        :description="$card['description'] ?? null"
    >
        @if ($action !== null && filled($action['url'] ?? null))
            <x-slot name="afterHeader">
                @if (($action['openInNewTab'] ?? false) === true)
                    <x-filament::link
                        :href="$action['url']"
                        :icon="$action['icon'] ?? null"
                        size="sm"
                        target="_blank"
                        rel="noreferrer noopener"
                    >
                        {{ $action['label'] }}
                    </x-filament::link>
                @else
                    <x-filament::link
                        :href="$action['url']"
                        :icon="$action['icon'] ?? null"
                        size="sm"
                    >
                        {{ $action['label'] }}
                    </x-filament::link>
                @endif
            </x-slot>
        @endif

        <div>
            @if ($view !== null)
                {!! view($view, is_array($card['viewData'] ?? null) ? $card['viewData'] : [])->render() !!}
            @elseif ($items !== [])
                @include('filament.infolists.entries.enterprise-detail.section-items', [
                    'items' => $items,
                    'variant' => 'supporting',
                ])
            @elseif ($emptyState !== null)
                @include('filament.infolists.entries.enterprise-detail.empty-state', ['state' => $emptyState])
            @endif
        </div>
    </x-filament::section>
</div>
