@props([
    'optionsConfig' => [],   // config('witness_statement.generation_options')
    'selected' => [],        // array<key,bool>
    'statement' => null,     // WitnessStatement (for `requires` checks)
    'disabled' => false,
])

@php
    $requiresMet = function ($requires) use ($statement) {
        if (! $requires) {
            return true;
        }
        return match ($requires) {
            'claim.bankDetail' => (bool) $statement?->claim?->bankDetail,
            default => true,
        };
    };
@endphp

<div {{ $attributes->merge(['class' => 'witness-generation-options']) }}>
    <p class="text-muted small mb-2">Include the following with the Witness Statement:</p>
    <div class="d-flex flex-column gap-1">
        @foreach($optionsConfig as $option)
            @php
                $permitted = empty($option['permission']) || auth()->user()?->can($option['permission']);
                $available = $requiresMet($option['requires'] ?? null);
                $isOn = (bool) ($selected[$option['key']] ?? false);
            @endphp
            @if($permitted)
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" role="switch"
                           id="gen-opt-{{ $option['key'] }}"
                           wire:click="toggleOption('{{ $option['key'] }}')"
                           @checked($isOn)
                           @disabled($disabled || ! $available)>
                    <label class="form-check-label small" for="gen-opt-{{ $option['key'] }}">
                        {{ $option['label'] }}
                        @unless($available)
                            <span class="text-muted fst-italic">— unavailable (missing bank details)</span>
                        @endunless
                    </label>
                </div>
            @endif
        @endforeach
    </div>
</div>
