{% load widget_tweaks %}

<div class="form-group">
    {% for hidden_field in form.hidden_fields %}
        {{ hidden_field }}
    {% endfor %}
    
    {% if form.non_field_errors %}
        <div class="alert alert-danger" role="alert">
            {% for error in form.non_field_errors %}
                {{ error }}
            {% endfor %}
        </div>
    {% endif %}
    
    {% for field in form.visible_fields %}
        {% comment %} <h4>{{field.errors}}</h4> {% endcomment %}
        
            {% if field.field.choices %}
            
                <div class="form-group mb-3">
                    <label for="{{ field.id_for_label }}" class="mb-2">{{ field.label }}</label>
                    <select class="form-select {% if field.errors %}is-invalid{% endif %}" name="{{ field.html_name }}">
                        <option value="" {% if not field.value %}selected{% endif %}>---------</option>
                        {% for value, label in field.field.choices %}
                            <option value="{{ value }}" {% if field.value == value %}selected{% endif %}>{{ label }}</option>
                        {% endfor %}
                    </select>
                    {% if field.help_text %}
                        <small class="form-text text-muted">{{ field.help_text }}</small>
                    {% endif %}
                    
                </div>
            {% elif field.field.widget.input_type == 'checkbox' %}
            
                <div class="form-group mb-3">
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="{{ field.id_for_label }}" name="{{ field.html_name }}" {% if field.value %}checked{% endif %}>
                        <label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label_tag }}</label>
                    </div>
                    {% if field.help_text %}
                        <small class="form-text text-muted">{{ field.help_text }}</small>
                    {% endif %}
                    
                </div>
            {% elif field.field.widget.input_type == 'date' %}
                <div class="form-group mb-3">
                    <label for="{{ field.id_for_label }}" class="mb-2">{{ field.label }}</label>
                    {% render_field field class=" form-control datepicker" %}
                    {% if field.help_text %}
                        <small class="form-text text-muted">{{ field.help_text }}</small>
                    {% endif %}
                    
                </div>
            {% else %}
                <div class="form-group mb-3 {% if field.errors %}is-invalid{% endif %}">
                    <label for="{{ field.id_for_label }}" class="mb-2">{{ field.label }}</label>
                    
                    {% render_field field class="form-control" placeholder=field.label aria-describedby="{{ field.id_for_label }}Feedback" %}
                    
                    {% if field.help_text %}
                        <small class="form-text text-muted">{{ field.help_text }}</small>
                    {% endif %}
                    
                    
                </div>
            {% endif %}
            {% if field.errors %}
                <div id="{{ field.id_for_label }}Feedback" class="invalid-feedback">
                    {% for error in field.errors %}
                        <p>{{ error }}</p>
                    {% endfor %}
                </div>
            {% endif %}
            
            

                    
    {% endfor %}
</div>
