{% import "macros/buttons.html" as buttons %}
{% import "macros/forms.html" as forms %}
{% import "macros/modal.html" as modal %}
{% import "macros/icons.html" as icons %}

{% extends "admin/webhooks/logs/list.html" %}

{% block head_title_content %}Webhook log · {{ super() }}{% endblock %}

{% set open_modal = true %}

{% block modal %}
  {% call modal.header() %}
    {% call modal.title() %}{{ webhook_log.created_at.strftime('%x %X') }}{% endcall %}
  {% endcall %}
  {% call modal.body() %}
    <div>
      <ul>
        <li class="flex items-center justify-between py-3 border-b border-slate-200">
          <div class="text-sm whitespace-nowrap">Attempt</div>
          <div class="text-sm font-medium text-slate-800 ml-2 truncate">{{ webhook_log.attempt }}</div>
        </li>
        <li class="flex items-center justify-between py-3 border-b border-slate-200">
          <div class="text-sm whitespace-nowrap">Success</div>
          <div class="text-sm font-medium text-slate-800 ml-2 truncate">
            {% 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 %}
          </div>
        </li>
      </ul>
    </div>
    {% if webhook_log.response %}
    <div class="mt-6">
      <div class="text-sm font-semibold text-slate-800">Response</div>
      <pre class="relative overflow-scroll p-1 bg-slate-100 rounded border border-slate-300">{{ webhook_log.response | trim }}</pre>
    </div>
    {% endif %}
    {% if webhook_log.error_message %}
    <div class="mt-6">
      <div class="text-sm font-semibold text-slate-800">Error message</div>
      <pre class="relative overflow-scroll p-1 bg-slate-100 rounded border border-slate-300">{{ webhook_log.error_message | trim }}</pre>
    </div>
    {% endif %}
    <div class="mt-6">
      <div class="text-sm font-semibold text-slate-800">Request payload</div>
      <pre class="relative overflow-scroll p-1 bg-slate-100 rounded border border-slate-300">{{ webhook_log.payload_dict | tojson(indent=4) | trim }}</pre>
    </div>
  {% endcall %}
  {% call modal.footer() %}
    <button type="button" class="btn-sm border-slate-200 hover:border-slate-300 text-slate-600" _="install CloseModalButton()">Close</button>
  {% endcall %}
{% endblock %}
