<div class="grid">
  <%= render Components::Backend::Card.new(title: "program: #{@program.name}") do %>
    <%= render Components::Backend::Item.new(icon: "⭠", href: backend_programs_path) do %>
      <b>back to programs</b>
    <% end %>
    <hr>
    <div class="section">
      <div class="section-header"><h3>details</h3></div>
      <div class="section-content">
        <% if @program.description.present? %>
          <p><%= @program.description %></p>
        <% end %>
        <div class="detail-row">
          <span class="detail-label">owner</span>
          <span class="detail-value">
            <% if @program.owner_identity.present? %>
              <%= render Components::UserMention.new(@program.owner_identity) %>
            <% else %>
              <i>HQ</i>
            <% end %>
          </span>
        </div>
        <div class="detail-row">
          <span class="detail-label">status</span>
          <span class="detail-value"><span class="badge <%= @program.active? ? 'success' : 'danger' %>"><%= @program.active? ? "active" : "inactive" %></span></span>
        </div>
        <div class="detail-row">
          <span class="detail-label">trust</span>
          <span class="detail-value"><%= @program.trust_level.to_s.titleize %></span>
        </div>
        <div class="detail-row">
          <span class="detail-label">scopes</span>
          <span class="detail-value"><code><%= @program.scopes.presence || "none" %></code></span>
        </div>
        <div class="detail-row">
          <span class="detail-label">users</span>
          <span class="detail-value"><%= @identities_count %></span>
        </div>
        <% if @program.onboarding_scenario.present? %>
          <div class="detail-row">
            <span class="detail-label">onboarding</span>
            <span class="detail-value"><%= @program.onboarding_scenario.titleize %></span>
          </div>
        <% end %>
      </div>
    </div>
    <hr>
    <div class="section">
      <div class="section-header"><h3>credentials</h3></div>
      <div class="section-content lowered">
        <div class="form-row">
          <label>client id</label>
          <input type="text" value="<%= @program.uid %>" readonly onclick="this.select()" data-click-to-copy autocomplete="off">
        </div>
        <div class="form-row">
          <label>secret</label>
          <input type="text" value="<%= @program.secret %>" readonly onclick="this.select()" data-click-to-copy autocomplete="off">
        </div>
        <div class="form-row">
          <label>api key</label>
          <input type="text" value="<%= @program.program_key %>" readonly onclick="this.select()" data-click-to-copy autocomplete="off">
        </div>
      </div>
    </div>
    <% if @program.redirect_uri.present? %>
      <div class="section">
        <div class="section-header"><h3>redirect uris</h3></div>
        <div class="section-content">
          <% @program.redirect_uri.split.each do |uri| %>
            <div class="detail-row">
              <span class="detail-value"><code><%= uri %></code></span>
              <%= link_to "auth →", oauth_authorization_path(client_id: @program.uid, redirect_uri: uri, response_type: 'code', scope: @program.scopes), target: '_blank' %>
            </div>
          <% end %>
        </div>
      </div>
    <% end %>
    <hr>
    <%= render Components::Backend::Item.new(icon: "✎", href: edit_backend_program_path(@program)) do %>
      <b>edit program</b>
    <% end %>
    <%= render Components::Backend::Item.new(icon: "⭢", href: oauth_application_path(@program), target: "_blank") do %>
      <b>oauth app</b>
    <% end %>
    <%= link_to backend_program_path(@program), method: :delete, data: { confirm: "delete this program and all associated data?" }, class: "item" do %>
      <figure class="icon">✕</figure>
      <span class="text"><b>delete program</b></span>
    <% end %>
  <% end %>
</div>
