%= render 'shared/turbo_drawer', title: @webhook_event.event_type, close_after_submit: false do %>
<% if @webhook_event.status == 'error' %>
<% last_attempt = @webhook_attempts.select { |e| SendWebhookRequest::AUTOMATED_RETRY_RANGE.cover?(e.attempt) }.max_by(&:attempt) %>
<% if SendWebhookRequest::AUTOMATED_RETRY_RANGE.cover?(last_attempt&.attempt) %>
-
<%= svg_icon('clock', class: 'w-4 h-4 shrink-0') %>
<%= t('next_attempt_in_time_in_words', time_in_words: distance_of_time_in_words(Time.current, last_attempt.created_at + (2**last_attempt.attempt).minutes)) %>
<% end %>
<% end %>
<% if @webhook_attempts.present? %>
<% @webhook_attempts.each do |webhook_attempt| %>
-
<%= svg_icon(webhook_attempt.success? ? 'check' : 'x', class: 'w-4 h-4 shrink-0') %>
<%= l(webhook_attempt.created_at.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>
<%= Rack::Utils::HTTP_STATUS_CODES[webhook_attempt.response_status_code] %>
<% if webhook_attempt.response_status_code.positive? %>
(<%= webhook_attempt.response_status_code %>)
<% end %>
<% unless webhook_attempt.success? %>
<%= webhook_attempt.response_body.presence || Rack::Utils::HTTP_STATUS_CODES[webhook_attempt.response_status_code] %>
<% end %>
<% end %>
<% else %>
-
<%= svg_icon('clock', class: 'w-4 h-4 shrink-0') %>
<%= l(@webhook_event.created_at.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>
<% end %>
<% unless @webhook_event.status == 'pending' %>
<%= button_to button_title(title: t('resend'), disabled_with: 'sending', icon: svg_icon('rotate', class: 'w-4 h-4'), icon_disabled: svg_icon('loader', class: 'w-4 h-4 animate-spin')), resend_settings_webhook_event_path(@webhook_url.id, @webhook_event.uuid), class: 'absolute right-4 top-3 btn btn-neutral btn-sm text-white', method: :post %>
<% end %>
<% if @data %>
<% response = JSON.pretty_generate({ event_type: @webhook_event.event_type, timestamp: @webhook_event.created_at.as_json, data: @data }) %>
<%= render 'shared/clipboard_copy', icon: 'copy', text: response, class: 'btn btn-ghost text-white', icon_class: 'w-6 h-6 text-white', copy_title: t('copy'), copied_title: t('copied') %>
<%== HighlightCode.call(response, 'JSON', theme: 'base16.dark') %>
<% end %>
<% end %>