{{--
    A dropdown filter inside a filter bar.

        <x-filter.select name="status" :selected="$filters['status']"
                         placeholder="Any status"
                         :options="['active' => 'Active', 'disabled' => 'Disabled']" />

    The placeholder is the unfiltered state ("Any status"), never an empty
    option — so a glance at the row tells you whether the filter is doing
    anything.

    Enum-backed filters should be fed from the enum's options() method, so the
    list, the labels and the validation rule cannot drift apart.
--}}
@props([
    'name',
    'options' => [],
    'selected' => null,
    'placeholder' => 'Any',
    'label' => null,
])

@php
    $current = old($name, $selected);
    $isSet = $current !== null && $current !== '';
@endphp

<label for="filter-{{ $name }}" class="visually-hidden">{{ $label ?? $placeholder }}</label>

<select id="filter-{{ $name }}"
        name="{{ $name }}"
        {{ $attributes->merge(['class' => 'form-select ams-filter-select'.($isSet ? ' border-primary' : '')]) }}
        data-ams-filter-select>
    <option value="">{{ $placeholder }}</option>

    @foreach ($options as $optionValue => $optionLabel)
        <option value="{{ $optionValue }}" @selected((string) $current === (string) $optionValue)>
            {{ $optionLabel }}
        </option>
    @endforeach
</select>
