{% load i18n rest_framework %}

{% translate "None" as none_choice %}

<div class="mb-4">
  <div class="form-check">
    <input
      type="radio"
      name="{{ field.name }}"
      class="form-check-input"
      id="{{ field.name }}"
      {% if field.required %}required{% endif %}
      {% if not field.value %}checked{% endif %}
    />
    {% if field.label %}
      <label
        class="form-label{% if style.hide_label %} sr-only{% endif %}"
        for="{{ field.name }}"
      >
        {% if field.allow_null or field.allow_blank %}
          {{ none_choice }}
        {% else %}
          {{ field.label }}
        {% endif %}
        {% if field.required %}<span class="text-danger">*</span>{% endif %}
      </label>
    {% endif %}
  </div>

  {% for key, text in field.choices|items %}
    <div class="form-check">
      <input type="radio" name="{{ field.name }}" class="form-check-input"
      id="{{ field.name }}" value="{{ key }}" {% if key|as_string == field.value|as_string %}checked{% endif %} />

      {% if field.label %}
        <label
          for="{{ field.name }}"
          class="form-label{% if style.hide_label %} sr-only{% endif %}"
        >
          {{ text }}
        </label>
      {% endif %}
    </div>
  {% endfor %}

    {% if field.help_text %}
      <small class="d-block text-muted">{{ field.help_text|safe }}</small>
    {% endif %}

    {% if field.errors %}
      <div class="mt-3"></div>
      {% for error in field.errors %}
        <div role="alert" class="alert alert-danger mb-3">
          <p class="mb-0">{{ error }}</p>
        </div>
      {% endfor %}
    {% endif %}
</div>
