<!-- #region Select [C:2] [TYPE Component] [SEMANTICS select, dropdown, form, atom, option] -->
<!-- @ingroup UI -->
<!-- @BRIEF Standardized select dropdown component with label and Tailwind styling. -->
<!-- @LAYER UI -->
<!--
@SEMANTICS: select, dropdown, form-field, ui-atom
@PURPOSE:   Standardized dropdown selection component.
@LAYER     Atom
@RELATION  DEPENDS_ON -> [EXT:frontend:Utils]

@UX_STATE: Idle -> Current value is selectable from the provided options.
@UX_STATE: Disabled -> Native disabled state prevents selection changes.
-->

<script lang="ts">
  // [SECTION: IMPORTS]
  import { cn } from "$lib/utils.js";
  // [/SECTION: IMPORTS]

  // Deterministic ID counter (hydration-safe, no Math.random)
  let _selectSeq = 0;

  // [SECTION: PROPS]
  let {
    label = "",
    value = $bindable(""),
    options = [],
    disabled = false,
    id: externalId = undefined,
    class: className = "",
    ...rest
  } = $props();

  const assignId = () => externalId ?? `select-${++_selectSeq}`;
  let id = $state(assignId());
</script>

<!-- [SECTION: TEMPLATE] -->
<div class="flex flex-col gap-1.5 w-full">
  {#if label}
    <label for={id} class="text-sm font-medium text-text">
      {label}
    </label>
  {/if}

  <select
    {id}
    {disabled}
    bind:value
    class={cn(
      "flex h-10 w-full rounded-md border border-border-strong bg-surface-card px-3 py-2 text-sm text-text ring-offset-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
      className,
    )}
    {...rest}
  >
    {#each options as option}
      <option value={option.value}>{option.label}</option>
    {/each}
  </select>
</div>
<!-- [/SECTION: TEMPLATE] -->

<!-- #endregion Select -->
