@props([ 'name', 'id' => null, 'label' => null, 'labelledBy' => null, 'placeholder' => 'Select an option', 'options' => [], 'value' => '', 'required' => false, 'withFlags' => false, 'searchable' => false, 'searchPlaceholder' => 'Search', ]) @php $fieldId = $id ?? $name; $listId = $fieldId . '-listbox'; $menuOptions = $options; if ($placeholder && ! collect($menuOptions)->contains(fn (array $option): bool => ($option['value'] ?? '') === '')) { array_unshift($menuOptions, ['value' => '', 'label' => $placeholder]); } $selectedOption = collect($menuOptions)->first( fn (array $option): bool => (string) ($option['value'] ?? '') === (string) $value, ); $selectedLabel = $selectedOption['label'] ?? $placeholder; $selectedFlag = $selectedOption['flag'] ?? null; $showFlags = $withFlags || collect($menuOptions)->contains(fn (array $option): bool => ! empty($option['flag'])); @endphp
class(['custom-select', 'custom-select--flags' => $showFlags]) }} data-custom-select data-placeholder="{{ $placeholder }}" @if ($showFlags) data-custom-select-flags @endif @if ($searchable) data-custom-select-search @endif > @if ($label) {{ $label }} @endif