@props([ 'id', 'name', 'options' => [], 'value' => null, 'placeholder' => null, 'disabled' => false, 'required' => false, 'selectAttributes' => [], 'triggerIcon' => null, 'triggerPrefix' => null, 'maxHeight' => null, ]) @php $placeholder = $placeholder ?? __('kview-ui-core::ui.common.select'); $selectAttributeBag = new \Illuminate\View\ComponentAttributeBag($selectAttributes); $selectedValue = (string) old($name, $value ?? ''); $normalizedOptions = collect($options) ->map(function ($option, $key) { if (is_array($option)) { $value = (string) ($option['value'] ?? (is_string($key) ? $key : ($option['label'] ?? ''))); return [ 'value' => $value, 'label' => (string) ($option['label'] ?? $value), 'meta' => $option['meta'] ?? null, 'icon' => $option['icon'] ?? null, 'disabled' => (bool) ($option['disabled'] ?? false), ]; } $value = is_string($key) ? (string) $key : (string) $option; return [ 'value' => $value, 'label' => (string) $option, 'meta' => null, 'icon' => null, 'disabled' => false, ]; }) ->values(); $selectedOption = $normalizedOptions->firstWhere('value', $selectedValue); $selectedLabel = $selectedOption['label'] ?? $placeholder; $menuId = $id.'_menu'; @endphp