@props([ 'optionsConfig' => [], // config('witness_statement.generation_options') 'selected' => [], // array 'statement' => null, // WitnessStatement (for `requires` checks) 'disabled' => false, ]) @php // Only options that materially affect the CONTENTS of the generated pack. // Delivery choices (post/email) belong to the post-generation sending flow. $deliveryKeys = ['send_post', 'send_email']; $packOptions = collect($optionsConfig)->reject(fn ($o) => in_array($o['key'], $deliveryKeys, true)); $requiresMet = function ($requires) use ($statement) { if (! $requires) { return true; } return match ($requires) { 'claim.bankDetail' => (bool) $statement?->claim?->bankDetail, default => true, }; }; @endphp
merge(['class' => 'witness-pack-options']) }}> Statement pack contents
@foreach($packOptions as $option) @php $permitted = empty($option['permission']) || auth()->user()?->can($option['permission']); $available = $requiresMet($option['requires'] ?? null); $isOn = (bool) ($selected[$option['key']] ?? false); @endphp {{-- Hide options the user can't use; explain the ones merely unavailable. --}} @if($permitted)
@endif @endforeach