{#
/**
 * @file
 * Theme override for a select element.
 *
 * Available variables:
 * - attributes: HTML attributes for the <select> tag.
 * - options: The <option> element children.
 *
 * @see template_preprocess_select()
 */
#}
{% set classes = [
  'mt-1',
  'block',
  'w-full',
  'rounded-md',
  'shadow-sm',
  'focus:border-indigo-500',
  'focus:ring-indigo-500',
  'text-xs',
  'md:text-sm',
  'lg:text-base',
  'text-gray-500',
  'py-2',
  'px-2',
  'md:py-4',
  'border-gray-400',
] %}

{% apply spaceless %}
  <select{{ attributes.addClass(classes) }}>
    {% for option in options %}
      {% if option.type == 'optgroup' %}
        <optgroup label="{{ option.label }}">
          {% for sub_option in option.options %}
            <option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
          {% endfor %}
        </optgroup>
      {% elseif option.type == 'option' %}
        <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
      {% endif %}
    {% endfor %}
  </select>
{% endapply %}
