@props([
    'options' => [],
    'name' => null,
    'placeholder' => '',
    'selected' => null,
    'id' => null
])

@php
    $livewireModel = $attributes->get('wire:model', $attributes->get('wire:model.defer'));
    $name = $attributes->get('name', $livewireModel);
    $id = $attributes->get('id', $name);
    $options = is_array($options) ? collect($options) : $options;
@endphp

<select id="{{ $id }}" name="{{ $name }}" {{ $attributes->merge(['class' => 'form-select']) }}>
    @if(!empty($placeholder))
        <option value="">{{ $placeholder }}</option>
    @endif
    @foreach($options as $key => $value)
        <option value="{{ $key }}" {{ (string) $key === (string) old($name, $selected) ? 'selected' : '' }}>
            {{ $value }}
        </option>
    @endforeach
</select>
