{% macro text_input(field, list='', css_classes='') -%}
    <div class="form-group">
        <input type="text"
                {% if css_classes %}
               class="{{ css_classes }}"
                {% else %}
               class="form-control"
                {% endif %}
               placeholder="{{ field.label }}"
                {% if list %}
               list="{{ list }}"
                {% endif %}
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               maxlength="{{ field.field.max_length }}"
               {% if field.field.required %}required{% endif %}>
        {% if list %}
            <datalist id="{{ list }}">
            </datalist>
        {% endif %}
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if field.help_text %}
                <br/>
            {% endif %}
        </small>
    </div>
{% endmacro %}

{% macro textarea_input(field) -%}
    <div class="form-group">
        <textarea type="text"
                  class="form-control"
                  placeholder="{{ field.label }}"
                  aria-describedby="{{ field.id_for_label }}_help"
                  name="{{ field.html_name }}"
                  id="{{ field.id_for_label }}"
                  rows="4"
                  maxlength="{{ field.field.max_length }}"
                  {% if field.field.required %}required{% endif %}
        >{% if field.value() != None %}{{ field.value() }}{% endif %}</textarea>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if field.help_text %}
                <br/>{{ field.help_text() }}
            {% endif %}
        </small>
    </div>
{% endmacro %}

{% macro number_input(field, type='', step_size='0.01') -%}
    <div class="form-group">
        <input type="number"
               class="form-control"
               placeholder="{{ field.label }}"
               step="{{ step_size }}"
               min="{{ field.field.min_value }}"
               max="{{ field.field.max_value }}"
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               {% if field.field.required %}required{% endif %}>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if type %}
                {{ field.label }} in {{ type }}
            {% endif %}
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if field.help_text %}
                <br/>{{ field.help_text() }}
            {% endif %}
        </small>
    </div>
{% endmacro %}


{% macro file_input(field, multiple=False) -%}
    <div class="form-group">
        <label for="{{ field.id_for_label }}">
            {{ field.label }}
        </label>
        <input type="file"
               {% if multiple %}multiple{% endif %}
               class="form-control-file"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               {% if field.field.required %}required{% endif %}>
    </div>
{% endmacro %}

{% macro image_deletion_input(existing_images) -%}
    <div class="card-group">
        {% for image in existing_images %}
            <div class="col-12 col-xs-12 col-md-6 col-lg-6 col-xl-3 p-1">
                <div class="card w-100" style="width: 18rem;">
                    <input type="checkbox" id="image{{ image.id }}" name="deleteImages"
                           value="{{ image.id }}">
                    <label for="image{{ image.id }}">
                        <img class="img-fluid" src="{{ image.file.url }}" alt="Item default image">
                    </label>
                </div>
            </div>
        {% endfor %}
    </div>
{% endmacro %}

{% macro checkbox_input(field) -%}
    <div class="form-check">
        <input type="checkbox"
               class="form-check-input"
               placeholder="{{ field.label }}"
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               maxlength="{{ field.field.max_length }}"
               {% if field.field.required %}required{% endif %}>
        <label id="{{ field.id_for_label }}" class="form-check-label" for="{{ field.id_for_label }}">
            {{ field.label }}
        </label>
    </div>
{% endmacro %}

{% macro checkbox_input_for_choice_fields(field) -%}
    <div class="form-check">
        <ul>
            {% for choice_value, choice_label in field.field.choices %}
                <li>
                    <input type="checkbox"
                           class="custom-control-input"
                           aria-describedby="{{ choice_label }}_help"
                           name="{{ field.html_name }}"
                           id="{{ choice_label }}_{{ loop.index }}"
                           value="{{ choice_value }}"
                           {% if field.value() and choice_value in field.value() %}checked{% endif %}
                    >
                    <label class="custom-control-label" for="{{ choice_label }}_{{ loop.index }}">
                        {{ choice_label }}
                    </label>
                </li>
            {% endfor %}
        </ul>
    </div>
{% endmacro %}

{% macro select_input(field, multiple=False) -%}
    <div class="">
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        <select
                {% if multiple %}multiple{% endif %}
                class="form-control"
                id="{{ field.id_for_label }}"
                name="{{ field.html_name }}">
            {% for option in field %}
                {{ option }}
            {% endfor %}
        </select>
    </div>
{% endmacro %}

{% macro password_input(field, list='', css_classes='') -%}
    {% if field.help_text %}
        <br/>
    {% endif %}
    <div class="form-group">
        <input type="password"
                {% if css_classes %}
               class="{{ css_classes }}"
                {% else %}
               class="form-control"
                {% endif %}
               placeholder="{{ field.label }}"
                {% if list %}
               list="{{ list }}"
                {% endif %}
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               maxlength="{{ field.field.max_length }}"
               {% if field.field.required %}required{% endif %}>
        {% if list %}
            <datalist id="{{ list }}">
            </datalist>
        {% endif %}
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
        </small>
    </div>
{% endmacro %}

{% macro telephone_input(field, type='', step_size='0.01') -%}
    <div class="form-group">
        <input type="tel"
               class="form-control"
               placeholder="{{ field.label }}"
               step="{{ step_size }}"
               min="{{ field.field.min_value }}"
               max="{{ field.field.max_value }}"
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               {% if field.field.required %}required{% endif %}>
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if type %}
                {{ field.label }} in {{ type }}
            {% endif %}
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if field.help_text %}
                <br/>{{ field.help_text() }}
            {% endif %}
        </small>
    </div>
{% endmacro %}

{% macro email_input(field, list='', css_classes='') -%}
    <div class="form-group">
        <input type="email"
                {% if css_classes %}
               class="{{ css_classes }}"
                {% else %}
               class="form-control"
                {% endif %}
               placeholder="{{ field.label }}"
                {% if list %}
               list="{{ list }}"
                {% endif %}
               aria-describedby="{{ field.id_for_label }}_help"
               name="{{ field.html_name }}"
               id="{{ field.id_for_label }}"
               {% if field.value() != None %}value="{{ field.value() }}"{% endif %}
               maxlength="{{ field.field.max_length }}"
               {% if field.field.required %}required{% endif %}>
        {% if list %}
            <datalist id="{{ list }}">
            </datalist>
        {% endif %}
        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
        <small id="{{ field.id_for_label }}_help" class="form-text text-muted">
            {% if field.errors %}
                <ul>
                    {% for error in field.errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if field.help_text %}
                <br/>
            {% endif %}
        </small>
    </div>
{% endmacro %}