{% extends "forms/field.html.twig" %}

{% block global_attributes %}
    data-grav-selectize="{{ (field.selectize is defined ? field.selectize : {})|json_encode()|e('html_attr') }}"
    data-grav-field="select"
    {{ parent() }}
{% endblock %}

{% block input %}
    <div class="form-input-wrapper {{ field.size }}">
        {% set input_value = value is iterable ? value|join(',') : value|string %}
        <select
                value="{{ input_value }}"
                name="{{ (scope ~ field.name)|fieldName }}"
                data-select-observe
                {% block input_attributes %}
                    {% if field.classes is defined %}class="{{ field.classes }}" {% endif %}
                    {% if field.id is defined %}id="{{ field.id }}" {% endif %}
                    {% if field.style is defined %}style="{{ field.style }}" {% endif %}
                    {% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
                    {% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
                    {% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
                    {% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
                    {% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}
                    {% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}
                    {% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
                    {% if field.validate.pattern %}pattern="{{ field.validate.pattern }}"{% endif %}
                    {% if field.validate.message %}title="{{ field.validate.message|t }}"
                    {% elseif field.title is defined %}title="{{ field.title|t }}" {% endif %}
                {% endblock %}
        >
            {% if field.placeholder %}<option value="" disabled selected>{{ field.placeholder|t|raw }}</option>{% endif %}

            {% if value is defined %}
                <option selected="selected" value="{{ value }}">{{ value }}</option>
            {% endif %}
        </select>

        {% if field.default %}
            <div><p class="notice warning">It is advised not to use a <strong>default</strong> option with the selectunique field. Currently default value set to `{{ field.default }}`</p></div>
        {% endif %}
    </div>
{% endblock %}
