{% load djblets_forms djblets_utils %}

{% if field.is_hidden %}
{{field}}
{% else %}
{%  with field|form_field_has_label_first as label_first %}
{%   definevar "post_field_html" spaceless %}
{%    if field.help_text %}
<div class="rb-c-form-field__help">
 <span>{{field.help_text|safe}}</span>
</div>
{%    endif %}
{%    if form.disabled_reasons|default:''|contains:field.name %}
<div class="rb-c-form-field__disabled-reason">{{form.disabled_reasons|getitem:field.name|safe}}</div>
{%    endif %}
{%   enddefinevar %}

<div class="rb-c-form-row{% if extra_field_classes %} {{extra_field_classes}}{% endif %}{% if field.name %} field-{{field.name}}{% endif %}"
     {% if field.name %}id="row-{{field.name}}"{% endif %}>
 <div class="rb-c-form-field{% if not label_first %} -has-input-first{% endif %}{% if field.errors %} -has-errors{% endif %}{% if field.field.required %} -is-required{% endif %}">
{%   if field.errors %}
  <div class="rb-c-form-field__errors">
   {{field.errors}}
  </div>
{%   endif %}
{%   if label_first %}
{%    if field.label %}
  <label class="rb-c-form-field__label" for="{{field|form_field_id}}">{{field.label}}:</label>
{%    endif %}
  <div class="rb-c-form-field__input">
   {{field}}
   {{post_field_html}}
  </div>
{%   else %}
  <div class="rb-c-form-field__input">
   {{field}}
   <label class="rb-c-form-field__label" for="{{field|form_field_id}}">{{field.label}}</label>
  </div>
  {{post_field_html}}
{%   endif %}
 </div>
</div>
{%  endwith %}
{% endif %}
