{% import "macros/datatable.html" as datatable %}

{% macro created_at_column(webhook_log) %}
  {{ webhook_log.created_at.strftime('%x %X') }}
{% endmacro %}

{% macro event_column(webhook_log) %}
  {{ webhook_log.event }}
{% endmacro %}

{% macro success_column(webhook_log) %}
{% if webhook_log.success %}
{{ icons.check('w-4 h-4 text-green-500') }}
{% else %}
{{ icons.x_mark('w-4 h-4 text-red-500') }}
{% endif %}
{% endmacro %}

{% macro attempt_column(webhook_log) %}
  {{ webhook_log.attempt }}
{% endmacro %}

{% macro error_column(webhook_log) %}
  {% if webhook_log.error_type %}
    <code class="p-0.5 bg-slate-100 rounded border border-slate-300">{{ webhook_log.error_type }}</code>
  {% else %}
    —
  {% endif %}
{% endmacro %}

{% macro actions_column(webhook_log) %}
<div class="flex justify-end">
  <a
    class="btn-xs border-slate-200 hover:border-slate-300"
    href="{{ url_for('dashboard.webhooks:log', id=webhook_log.webhook_id, log_id=webhook_log.id) }}"
    hx-boost="true"
    hx-target="#modal"
    _="install OpenModal"
  >
    Details
  </a>
</div>
{% endmacro %}

{{
  datatable.datatable(
    webhook_logs,
    count,
    datatable_query_parameters,
    "Webhook logs",
    columns | map("get_column_macro") | list,
  )
}}
