{% load crispy_forms_field %}
{% load crispy_extra %}

{% if field.is_hidden %}
    {{ field }}
{% else %}
    {% if field|is_checkbox and tag != "td" %}
        <div class="">
        {% if label_class %}
            <div class="{{ field_class }}">
        {% endif %}
    {% endif %}
    <{% if tag %}{{ tag }}{% else %}fieldset{% endif %} id="div_{{ field.auto_id }}" class="{% if field|is_checkbox and form_show_labels %}form-control{% else %}fieldset{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
        {% if field.label and not field|is_checkbox and form_show_labels %}
            {% if field.use_fieldset %}<fieldset class="fieldset"{% if field.aria_describedby %} aria-describedby="{{ field.aria_describedby }}"{% endif %}>{% endif %}
            <{% if field.use_fieldset %}legend{% else %}label{% endif %}
                {% if field.id_for_label %}for="{{ field.id_for_label }}"{% endif %} class="fieldset-legend{% if label_class %} {{ label_class }}{% endif %}{% if field.field.required %} requiredField{% endif %}">
                {{ field.label }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
            </{% if field.use_fieldset %}legend{% else %}label{% endif %}>
        {% endif %}

        {% if field|is_checkboxselectmultiple or field|is_radioselect %}
            {% include 'crispy-daisyui/layout/radio_checkbox_select.html' %}
        {% endif %}

        {% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
            {% if field|is_checkbox and form_show_labels %}
                    {% if field.errors %}
                        {% crispy_field field 'class' 'checkbox checkbox-error' %}
                    {% else %}
                        {% crispy_field field 'class' 'checkbox' %}
                    {% endif %}
                <label for="{{ field.id_for_label }}" class="label{% if field.field.required %} requiredField{% endif %}">
                    {{ field.label }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
                </label>
                {% include 'crispy-daisyui/layout/help_text_and_errors.html' %}
            {% else %}
                {% if field_class %}<div class="{{ field_class }}">{% endif %}
                    {% if field|is_file %}
                        {% include 'crispy-daisyui/layout/field_file.html' %}
                    {% elif field|is_select %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'select-error w-full' %}
                        {% else %}
                            {% crispy_field field 'class' '' %}
                        {% endif %}
                    {% elif field|is_checkbox %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'checkbox checkbox-error w-full' %}
                        {% else %}
                            {% crispy_field field 'class' 'checkbox w-full' %}
                        {% endif %}
                    {% elif field|is_input %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'input input-error w-full' %}
                        {% else %}
                            {% crispy_field field 'class' 'input w-full' %}
                    {% endif %}
                    {% elif field|is_textarea %}
                        {% if field.errors %}
                            {% crispy_field field 'class' 'textarea textarea-error w-full' %}
                        {% else %}
                            {% crispy_field field 'class' 'textarea w-full' %}
                    {% endif %}
                    {% elif field.errors %}
                        {% crispy_field field 'class' 'input input-error w-full' %}
                    {% else %}
                        {% crispy_field field 'class' 'input w-full' %}
                    {% endif %}
                    {% if not field|is_file %}
                        {% include 'crispy-daisyui/layout/help_text_and_errors.html' %}
                    {% endif %}
                {% if field_class %}</div>{% endif %}
            {% endif %}
        {% endif %}
        {% if field.use_fieldset and field.label and form_show_labels %}</fieldset>{% endif %}
    </{% if tag %}{{ tag }}{% else %}fieldset{% endif %}>
    {% if field|is_checkbox and tag != "td" %}
        {% if label_class %}
            </div>
        {% endif %}
        </div>
    {% endif %}
{% endif %}
