@props([ 'name', 'options' => [], 'selected' => '', 'placeholder' => 'Pilih', 'searchable' => false, 'required' => false, 'class' => '', 'xModel' => null // Optional: if we want to bind it to a parent x-data property ]) @php $normalizedOptions = []; if (is_array($options) || $options instanceof \Illuminate\Support\Collection) { $optionsArray = $options instanceof \Illuminate\Support\Collection ? $options->toArray() : $options; $isSequential = empty($optionsArray) || array_keys($optionsArray) === range(0, count($optionsArray) - 1); foreach ($optionsArray as $key => $value) { if (is_array($value) && isset($value['value'])) { $normalizedOptions[] = ['value' => (string) $value['value'], 'label' => (string) ($value['label'] ?? $value['value'])]; } elseif (is_object($value) && isset($value->value)) { $normalizedOptions[] = ['value' => (string) $value->value, 'label' => (string) ($value->label ?? $value->value)]; } elseif ($isSequential) { $normalizedOptions[] = ['value' => (string) $value, 'label' => (string) $value]; } else { $normalizedOptions[] = ['value' => (string) $key, 'label' => (string) $value]; } } } $oldInputName = $name; if (str_ends_with($name, '[]')) { $oldInputName = substr($name, 0, -2); } $defaultValue = old($oldInputName, $selected); if (is_array($defaultValue)) { $defaultValue = reset($defaultValue) ?: ''; } @endphp