{% load currency_display %}
{% 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 'Automatic Exchange Rates' %}<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 'automatic_exchange_rate_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-header text-body-secondary">
      <button type="button" hx-get="{% url 'automatic_exchange_rate_force_fetch' %}"
              class="btn btn-outline-primary btn-sm">{% trans 'Fetch all' %}</button>
    </div>
    <div class="card-body">
      {% if services %}
        <c-config.search></c-config.search>
        <div class="table-responsive">
          <table class="table table-hover">
            <thead>
            <tr>
              <th scope="col" class="col-auto"></th>
              <th scope="col" class="col-auto"></th>
              <th scope="col" class="col-auto">{% translate 'Name' %}</th>
              <th scope="col" class="col">{% translate 'Service' %}</th>
              <th scope="col" class="col">{% translate 'Targeting' %}</th>
              <th scope="col" class="col">{% translate 'Last fetch' %}</th>
            </tr>
            </thead>
            <tbody>
            {% for service in services %}
              <tr class="services">
                <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 'automatic_exchange_rate_edit' pk=service.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 'automatic_exchange_rate_delete' pk=service.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>
                  </div>
                </td>
                <td class="col-auto">{% if service.is_active %}<i class="fa-solid fa-circle text-success"></i>{% else %}
                  <i class="fa-solid fa-circle text-danger"></i>{% endif %}</td>
                <td class="col-auto">{{ service.name }}</td>
                <td class="col">{{ service.get_service_type_display }}</td>
                <td class="col">{{ service.target_currencies.count }} {% trans 'currencies' %}, {{ service.target_accounts.count }} {% trans 'accounts' %}</td>
                <td class="col">{{ service.last_fetch|date:"SHORT_DATETIME_FORMAT" }}</td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
        </div>
      {% else %}
        <c-msg.empty title="{% translate "No services configured" %}" remove-padding></c-msg.empty>
      {% endif %}
    </div>
  </div>
</div>
