<% content_for :title, @integration.name %>

<%= @integration.name %> <% if @integration.revoked? %><%= t(".revoked") %><% end %>

<% unless @integration.revoked? %>
<%= link_to t(".edit"), edit_admin_integration_path(@integration), class: "btn-secondary" %> <%= button_to t(".revoke"), admin_integration_path(@integration), method: :delete, class: "btn-danger", form: { data: { turbo_confirm: t(".revoke_confirm", name: @integration.name) } } %>
<% end %>

<%= t(".token") %>

<%= t(".hint") %>
<%= @integration.token_hint %>…
<%= t(".scopes") %>
<%= @integration.scopes.map { ApiToken::SCOPES[_1] }.to_sentence %>
<%= t(".aircraft") %>
<%= Aircraft.where(id: Array(@integration.aircraft_ids)).order(:tail_number).pluck(:tail_number).join(", ").presence || "—" %>
<%= t(".created") %>
<%= fmt_time(@integration.created_at) %> · <%= @integration.user.display_name %>
<%= t(".last_used") %>
<%= @integration.last_used_at ? "#{fmt_time(@integration.last_used_at)} · #{@integration.last_used_ip}" : t(".never") %>

<%= t(".webhook") %>

<% if @endpoint %>
<%= t(".url") %>
<%= @endpoint.url %> <% unless @endpoint.enabled %><%= t(".paused") %><% end %>
<%= t(".events") %>
<%= @endpoint.events.map { WebhookEndpoint::EVENTS[_1] }.to_sentence %>
<% unless @integration.revoked? %>
<%= button_to t(".new_secret"), new_secret_admin_integration_path(@integration), class: "btn-secondary btn-sm", form: { data: { turbo: false, turbo_confirm: t(".new_secret_confirm") } } %>
<% end %> <% else %>

<%= t(".no_webhook") %>

<% end %>
<% if @deliveries.any? %>

<%= t(".recent_deliveries") %>

<% @deliveries.each do |d| %><% end %>
<%= t(".when") %><%= t(".event") %><%= t(".result") %>
<%= fmt_time(d.created_at) %><%= d.event %> "badge-green", "failed" => "badge-red" }.fetch(d.status, "badge-gray") %>"><%= t(".status.#{d.status}") %> <%= d.response_status %> <%= d.last_error %> <% if d.attempts > 1 %>· <%= t(".attempts", count: d.attempts) %><% end %>
<% end %>