{% load i18n %}
<div class="container px-md-3 py-3 column-gap-5">
  <div class="tw-text-3xl fw-bold font-monospace tw-w-full mb-3">
    {% spaceless %}
    <div>{% translate 'Accounts' %}<span>
      <a class="text-decoration-none tw-text-2xl p-1 category-action"
                role="button"
                data-bs-toggle="tooltip"
                data-bs-title="{% translate "Add" %}"
                hx-get="{% url 'account_add' %}"
                hx-target="#generic-offcanvas">
            <i class="fa-solid fa-circle-plus fa-fw"></i></a>
    </span></div>
    {% endspaceless %}
  </div>

  <div class="card">
    <div class="card-body table-responsive">
      {% if accounts %}
      <c-config.search></c-config.search>
      <table class="table table-hover text-nowrap">
        <thead>
          <tr>
            <th scope="col" class="col-auto"></th>
            <th scope="col" class="col">{% translate 'Name' %}</th>
            <th scope="col" class="col">{% translate 'Group' %}</th>
            <th scope="col" class="col">{% translate 'Currency' %}</th>
            <th scope="col" class="col">{% translate 'Exchange Currency' %}</th>
            <th scope="col" class="col">{% translate 'Is Asset' %}</th>
            <th scope="col" class="col">{% translate 'Archived' %}</th>
          </tr>
        </thead>
        <tbody>
          {% for account in accounts %}
          <tr class="account">
            <td class="col-auto">
              <div class="btn-group" role="group" aria-label="{% translate 'Actions' %}">
                <a class="btn btn-secondary btn-sm"
                      role="button"
                      data-bs-toggle="tooltip"
                      data-bs-title="{% translate "Edit" %}"
                      hx-get="{% url 'account_edit' pk=account.id %}"
                      hx-target="#generic-offcanvas">
                  <i class="fa-solid fa-pencil fa-fw"></i></a>
                <a class="btn btn-secondary btn-sm text-danger"
                        role="button"
                        data-bs-toggle="tooltip"
                        data-bs-title="{% translate "Delete" %}"
                        hx-delete="{% url 'account_delete' pk=account.id %}"
                        hx-trigger='confirmed'
                        data-bypass-on-ctrl="true"
                        data-title="{% translate "Are you sure?" %}"
                        data-text="{% translate "You won't be able to revert this!" %}"
                        data-confirm-text="{% translate "Yes, delete it!" %}"
                        _="install prompt_swal"><i class="fa-solid fa-trash fa-fw"></i></a>
                {% if not account.owner %}
                <a class="btn btn-secondary btn-sm text-primary"
                 role="button"
                 data-bs-toggle="tooltip"
                 data-bs-title="{% translate "Take ownership" %}"
                 hx-get="{% url 'account_take_ownership' pk=account.id %}">
                <i class="fa-solid fa-crown fa-fw"></i></a>
                {% endif %}
                {% if user == account.owner %}
                <a class="btn btn-secondary btn-sm text-primary"
                 role="button"
                 hx-target="#generic-offcanvas"
                 hx-swap="innerHTML"
                 data-bs-toggle="tooltip"
                 data-bs-title="{% translate "Share" %}"
                 hx-get="{% url 'account_share_settings' pk=account.id %}">
                <i class="fa-solid fa-share fa-fw"></i></a>
                {% endif %}
              </div>
            </td>
            <td class="col">{{ account.name }}</td>
            <td class="col">{{ account.group.name }}</td>
            <td class="col">{{ account.currency }}</td>
            <td class="col">{% if account.exchange_currency %}{{ account.exchange_currency }}{% else %}-{% endif %}</td>
            <td class="col">{% if account.is_asset %}<i class="fa-solid fa-solid fa-check text-success"></i>{% endif %}</td>
            <td class="col">{% if account.is_archived %}<i class="fa-solid fa-solid fa-check text-success"></i>{% endif %}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <c-msg.empty title="{% translate "No accounts" %}" remove-padding></c-msg.empty>
      {% endif %}
    </div>
  </div>
</div>
