{% load i18n %}

<!---->
{% if form.errors %}
<div class="not-prose toast toast-top toast-end z-10 top-20 lg:top-24">
  <ol class="grid gap-4 max-w-2xl mx-auto">
    {% for field, errors in form.errors.items %}
    <li class="alert alert-soft alert-error">
      <div class="tooltip tooltip-error" data-tip="{% trans 'Error' %}">
        <i data-lucide="x-circle" class="size-4 lg:size-6"></i>
        <span class="sr-only">{% trans 'Error' %}</span>
      </div>

      <div>{{ errors }}</div>
    </li>
    {% endfor %}
  </ol>
</div>
{% endif %}

<!---->
{{ form }}

<script>
  // Style containers and labels
  document
    .querySelectorAll("form > div")
    .forEach((e) => e.classList.add("fieldset"));
  document
    .querySelectorAll("form > div > label")
    .forEach((e) => e.classList.add("fieldset-legend"));
  document
    .querySelectorAll("form > div > .helptext")
    .forEach((e) => e.classList.add("fieldset-label"));

  // Style inputs
  document
    .querySelectorAll("form > div > input")
    .forEach((e) => e.classList.add("input", "w-full", "validator"));
  document
    .querySelectorAll("form > div > input[type=checkbox]")
    .forEach((e) => {
      e.classList.remove("input", "w-full");
      e.classList.add("checkbox", "checked:checkbox-primary");
    });
  document.querySelectorAll("form > div > input[type=radio]").forEach((e) => {
    e.classList.remove("input", "w-full");
    e.classList.add("radio", "checked:radio-primary");
  });
  document.querySelectorAll("form > div > input[type=file]").forEach((e) => {
    e.classList.remove("input");
    e.classList.add("file-input");
  });
  document
    .querySelectorAll("form > div > textarea")
    .forEach((e) => e.classList.add("textarea", "w-full", "validator"));
  document
    .querySelectorAll("form > div > select")
    .forEach((e) => e.classList.add("select", "w-full", "validator"));

  // Style error lists
  document
    .querySelectorAll("form > div > .errorlist")
    .forEach((e) => e.classList.add("validator-hint", "text-error", "visible"));
</script>
