{% macro render_file_field(field, label=None, label_visible=True, right_url=None, right_label=None, right_message=None, multiple=False) -%}
<div class="da-form-group {% if field.errors %}da-group-has-error{% endif %} {{ kwargs.pop('class_', '') }}">
  {%- if label_visible %}
  {% if not label %}{% set label=field.label.text %}{% endif %}
  <label class="form-label" for="{{ field.id }}">{{ label|safe }}</label>
  {% endif %}
  <input alt="{{ word('You can upload a file here') }}" type="file" class="form-control" name="{{ field.id }}" id="{{ field.id }}"{% if multiple %} multiple{% endif %}/>
  {% for e in field.errors %}
  <div class="invalid-feedback d-block">{{ e }}</div>
  {% endfor %}
</div>
{%- endmacro %}
{% macro render_field(field, type=None, label=None, label_visible=True, right_url=None, right_label=None, right_message=None, prelabel=None) %}
<div class="da-form-group {% if field.errors %}da-group-has-error{% endif %} {{ kwargs.pop('class_', '') }}">
  {%- if field.type != 'HiddenField' and label_visible %}
  {%- if not label %}{% set label=field.label.text %}{% endif %}
  <label class="form-label" for="{{ field.id }}">{{ label|safe }}</label>
  {%- endif %}
  {%- if prelabel %}
  <div class="input-group">
    <div class="input-group-text">
      {{ prelabel }}
    </div>
    {{ field(class_='form-control', **kwargs) }}
  </div>
  {%- else %}
  {{ field(class_='form-control', **kwargs) }}
  {%- endif %}
  {%- if field.errors %}
  {%- for e in field.errors %}
  <div class="invalid-feedback d-block">{{ e }}</div>
  {%- endfor %}
  {%- endif %}
  {%- if right_message %}
  <div class="form-text">
    {{ right_message|safe }}
  </div>
  {%- endif %}  
</div>
{%- endmacro %}

{% macro render_addon_field(field, label=None, label_visible=True, right_url=None, right_label=None, right_message=None, extra=None, extra_class=None) %}
{%- if not extra_class %}{% set extra_class='' %}{% endif %}
<div class="input-group {% if field.errors %}da-group-has-error{% endif %} {{ kwargs.pop('class_', '') }}{{ extra_class }}">
  {%- if field.type != 'HiddenField' and label_visible %}
  {%- if not label %}{% set label=field.label.text %}{% endif %}
  <span class="input-group-text">
  {{ label|safe }}
  </span>
  {%- endif %}
  {{ field(class_='form-control', **kwargs) }}
  {%- if extra %}
  {{ extra|safe }}
  {%- endif %}
</div>
{%- if field.errors %}
{%- for e in field.errors %}
<div class="invalid-feedback d-block">{{ e }}</div>
{%- endfor %}
{%- endif %}
{%- if right_message %}
{{ right_message|safe }}
{%- endif %}  
{%- endmacro %}

{% macro render_checkbox_field(field, label=None) %}
{%- if not label %}{% set label=field.label.text %}{% endif %}
<div class="da-form-group">
  <div class="form-check">
    <input class="form-check-input" id="{{ field.id }}" name="{{ field.id }}" type="checkbox" value="y"{% if field.default %}checked="checked"{% endif %} />
    <label class="form-check-label" for="{{ field.id }}">{{ label }}</label>
  </div>
</div>
{% endmacro %}
 
{% macro render_radio_field(field) -%}
    {%- for value, label, checked in field.iter_choices() %}
<div class="da-form-group">
  <div class="form-check">
    <input class="form-check-input" type="radio" name="{{ field.id }}" id="{{ field.id }}" value="{{ value }}"{% if checked %} checked{% endif %}>
    <label class="form-check-label" for="{{ field.id }}">{{ label }}</label>
  </div>
</div>
    {%- endfor %}
{%- endmacro %}

{% macro render_select_field(field) %}
<div class="da-form-group {% if field.errors %}da-group-has-error{% endif %} {{ kwargs.pop('class_', '') }}">
  <label class="form-label" for="{{ field.id }}">{{ field.label.text }}</label>
  <select class="form-select" name="{{ field.id }}" id="{{ field.id }}">
  {%- for value, name, checked in field.iter_choices() %}
    <option value="{{ value }}"{% if checked %} selected="selected"{% endif %}>{{ name }}</option>
  {%- endfor %}
  </select>
  {%- if field.errors %}
  {%- for e in field.errors %}
  <div class="invalid-feedback d-block">{{ e }}</div>
  {%- endfor %}
  {%- endif %}
</div>
{%- endmacro %}

{% macro render_multiselect_field(field, undernote=None) %}
<div class="da-form-group {% if field.errors %}da-group-has-error{% endif %} {{ kwargs.pop('class_', '') }}">
  <label class="form-label" for="{{ field.id }}">{{ field.label.text }}</label>
  <select multiple class="form-select" name="{{ field.id }}" id="{{ field.id }}" name="{{ field.id }}">
  {%- for value, name, checked in field.iter_choices() %}
    <option value="{{ value }}"{% if checked %} selected="selected"{% endif %}>{{ name }}</option>
  {%- endfor %}
  </select>
  {%- if field.errors %}
  {%- for e in field.errors %}
  <div class="invalid-feedback d-block">{{ e }}</div>
  {%- endfor %}
  {%- endif %}
  {%- if undernote %}
  <div class="form-text">{{ undernote }}</div>
  {%- endif %}
</div>
{%- endmacro %}

{% macro render_submit_field(field, label=None, id=None, tabindex=None, class=None, title=None, style=None, data=None) %}
    {%- if not class %}{% set class="btn " + config['BUTTON_STYLE'] + "primary " + config['BUTTON_CLASS'] %}{% endif %}
    {%- if not label %}{% set label=field.label.text %}{% endif %}<button type="submit" name="{{ field.id }}" {% if id %}id="{{ id }}" {% endif %}class="{{ class }}" value="{{ label }}"{% if tabindex %} tabindex="{{ tabindex }}"{% endif %}{% if title %} title="{{ title }}"{% endif %}{% if style %} style="{{ style }}"{% endif %}{% if data %}{% for key in data %} data-{{ key }}="{{ data[key] }}"{% endfor %}{% endif %}>{{label}}</button>
{%- endmacro %}

{% macro myrender_hidden_field(field, value="") -%}
    <input type="hidden" name="{{ field.id }}" id="{{ field.id }}" value="{{value}}">
{%- endmacro %}
