{% extends "admin_base" %}
{% block title %}{% if admin_detail_title %}{{ admin_detail_title }}{% endif %} — {{ resource.title | default(value=resource_key) }} #{{ entry.id }}{% endblock %}
{% block breadcrumb %}
  <span class="admin-topbar__sep">/</span>
  <a href="{{ admin_prefix }}/{{ resource.key }}/list">{{ resource.title | default(value=resource_key) }}</a>
  <span class="admin-topbar__sep">/</span>
  <span>{% if admin_detail_breadcrumb %}{{ admin_detail_breadcrumb }}{% endif %} #{{ entry.id }}</span>
{% endblock %}
{% block content %}
  {% block detail_header %}
  <div class="admin-page__header" data-admin-auto-init>
    <div>
      <h1 class="admin-page__title">{% if admin_detail_title %}{{ admin_detail_title }}{% endif %} — {{ resource.title | default(value=resource_key) }}</h1>
      <p class="admin-page__subtitle">{% if admin_detail_entry_label %}{{ admin_detail_entry_label }}{% endif %} #{{ entry.id }}</p>
    </div>
    {% block detail_actions %}
    <div class="admin-page__actions">
      <a href="{{ admin_prefix }}/{{ resource.key }}/list" class="btn btn-secondary btn-sm">{% if admin_detail_btn_list %}{{ admin_detail_btn_list }}{% endif %}</a>
      {% set_global can_modify = false %}
      {% if current_user %}
        {% if current_user.is_superuser %}
          {% set_global can_modify = true %}
        {% else %}
          {% for groupe in current_user.groupes %}
            {% for perm in groupe.permissions %}
              {% if perm.resource_key == resource.key and perm.can_update %}
                {% set_global can_modify = true %}
              {% endif %}
            {% endfor %}
          {% endfor %}
        {% endif %}
      {% endif %}
      {% if current_user and can_modify %}
      {% set has_password = false %}
      {% for key, value in entry %}{% if key == "password" or key == "password_hash" %}{% set_global has_password = true %}{% endif %}{% endfor %}
      {% if has_password %}
      <form method="post" action="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/reset-password" class="admin-form--inline admin-btn--hide-mobile">
        {% csrf %}
        <button type="submit" class="btn btn-secondary btn-sm admin-btn--hide-mobile">
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
          {% if admin_detail_btn_reset_password %}{{ admin_detail_btn_reset_password }}{% else %}Réinitialiser le mot de passe{% endif %}
        </button>
      </form>
      {% endif %}
      <a href="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/edit" class="btn btn-primary btn-sm admin-btn--hide-mobile">{% if admin_detail_btn_edit %}{{ admin_detail_btn_edit }}{% endif %}</a>
      <form method="post" action="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/delete" class="admin-form--inline admin-btn--hide-mobile">
          {% csrf %}
          <button type="submit" class="btn btn-sm btn-danger"
            data-confirm-delete="{% if admin_detail_confirm_delete %}{{ admin_detail_confirm_delete }}{% endif %}">
                {% if admin_list_btn_delete %}{{ admin_list_btn_delete }}{% endif %}
          </button>
      </form>
      <div class="admin-menu admin-btn--show-mobile">
        <button class="admin-menu__trigger" type="button" aria-haspopup="true" aria-expanded="false">
          <svg viewBox="0 0 24 24" fill="currentColor" width="16" height="16">
            <circle cx="12" cy="5" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="12" cy="19" r="1.5"/>
          </svg>
        </button>
        <div class="admin-menu__dropdown">
          <a href="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/edit" class="admin-menu__item">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
            {% if admin_detail_btn_edit %}{{ admin_detail_btn_edit }}{% endif %}
          </a>
          {% if has_password %}
          <div class="admin-menu__separator"></div>
          <form method="post" action="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/reset-password">
            {% csrf %}
            <button type="submit" class="admin-menu__item">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
              {% if admin_detail_btn_reset_password %}{{ admin_detail_btn_reset_password }}{% else %}Réinitialiser{% endif %}
            </button>
          </form>
          {% endif %}
          <div class="admin-menu__separator"></div>
          <form method="post" action="{{ admin_prefix }}/{{ resource.key }}/{{ entry.id }}/delete">
            {% csrf %}
            <button type="submit" class="admin-menu__item admin-menu__item--danger"
              data-confirm-delete="{% if admin_detail_confirm_delete %}{{ admin_detail_confirm_delete }}{% endif %}">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14H6L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4h6v2"/></svg>
              {% if admin_list_btn_delete %}{{ admin_list_btn_delete }}{% endif %}
            </button>
          </form>
        </div>
      </div>
      {% endif %}
    </div>
    {% endblock %}
  </div>
  {% endblock %}
  {% block detail_table %}
  <div class="admin-card">
    <div class="admin-table__wrapper">
      <table class="admin-table">
        <tbody>
          <tr>
            <td class="admin-table__key">id</td>
            <td><span class="admin-badge--id">#{{ entry.id }}</span></td>
          </tr>
          {% for key, value in entry %}
            {% if key != "id" %}
            <tr>
              <td class="admin-table__key">{{ key }}</td>
              <td>
                {% if key == "password" or key == "password_hash" %}
                  <span class="admin-badge--id">••••••••</span>
                {% elif value == true %}
                  <span class="admin-badge admin-badge--green">{% if admin_list_bool_true %}{{ admin_list_bool_true }}{% endif %}</span>
                {% elif value == false %}
                  <span class="admin-badge admin-badge--neutral">{% if admin_list_bool_false %}{{ admin_list_bool_false }}{% endif %}</span>
                {% elif value %}
                  {% if value is string %}{{ value | escape }}{% else %}{{ value }}{% endif %}
                {% else %}
                  <span class="admin-text--muted">—</span>
                {% endif %}
              </td>
            </tr>
            {% endif %}
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  {% endblock %}
  {% if m2m_fields is defined and m2m_fields %}
  {% for field in m2m_fields %}
  <div class="admin-card mt-sm">
    <div class="admin-card__header">
      <span class="admin-card__title">{{ field.label }}</span>
    </div>
    <div class="admin-card__body">
      <div class="admin-m2m__choices admin-m2m__choices--readonly">
        {% if field.selected | length > 0 %}
          {% for choice in field.choices %}
            {% if choice[0] in field.selected %}
              <span class="admin-badge admin-badge--neutral">{{ choice[1] }}</span>
            {% endif %}
          {% endfor %}
        {% else %}
          <span class="admin-text--muted">—</span>
        {% endif %}
      </div>
    </div>
  </div>
  {% endfor %}
  {% endif %}
  <script {% csp %} src="{{ "js/admin/admin-actions.js" | runique_static }}"></script>
  <script {% csp %} src="{{ "js/admin/admin-kebab.js" | runique_static }}"></script>
{% endblock %}
