{% macro form_field_label(field) %}
<label class="block text-sm font-medium mb-1" for="{{ field.id }}">
  {{ _(field.label) }}
  {% if field.flags.required %}
    <span class="text-rose-500">*</span>
  {% endif %}
</label>
{% endmacro %}

{% macro form_field_errors(field) %}
  {% if field.errors %}
      {% for error in field.errors %}
        <div class="text-xs mt-1 text-red-500">{{ error | e }}</div>
      {% endfor %}
    {% endif %}
{% endmacro %}

{% macro form_standard_field(field) %}
{{ form_field_label(field) }}
{{ field(class="form-input w-full") }}
{% endmacro %}

{% macro form_checkbox_field(field) %}
<label class="block text-sm font-medium mb-1" for="{{ field.id }}">
  {{ field.label }}
  {% if field.flags.required %}
    <span class="text-rose-500">*</span>
  {% endif %}
  {{ field(class="form-checkbox") }}
</label>
{% endmacro %}

{% macro form_select_field(field) %}
{{ form_field_label(field) }}
{{ field(class="form-select w-full") }}
{% endmacro %}

{% macro form_address_field(field) %}
<div class="space-y-2">
  {{ form_field_label(field) }}
  {{ form_field(field.line1) }}
  {{ form_field(field.line2) }}
  <div class="grid grid-cols-2 gap-2">
    {{ form_field(field.postal_code) }}
    {{ form_field(field.city) }}
  </div>
  {{ form_field(field.state) }}
  {{ form_select_field(field.country) }}
</div>
{% endmacro %}

{% macro form_field(field) %}
<div>
  {% if field.type == "BooleanField" %}
    {{ form_checkbox_field(field) }}
    {{ form_field_errors(field) }}
  {% elif field.type == "SelectField" %}
    {{ form_select_field(field) }}
    {{ form_field_errors(field) }}
  {% elif field.type == "AddressFormField" %}
    {{ form_address_field(field) }}
  {% else %}
    {{ form_standard_field(field) }}
    {{ form_field_errors(field) }}
  {% endif %}
</div>
{% endmacro %}

{% macro form_csrf_token(form) %}
  {% if form.csrf_token %}
    {{ form.csrf_token }}
    {{ form_field_errors(form.csrf_token) }}
  {% endif %}
{% endmacro %}
