<div class="grid">
  <%= render Components::Backend::Card.new(title: "user: #{@user.display_name}") do %>
    <%= render Components::Backend::Item.new(icon: "⭠", href: backend_users_path) do %>
      <b>back to users</b>
    <% end %>
    <hr>
    <% if @user.orphaned? %>
      <div class="banner warning">
        <h3>⚠ orphaned user</h3>
        <p>this user is not linked to an identity and cannot log in.</p>
      </div>
    <% else %>
      <div class="section">
        <div class="section-header"><h3>linked identity</h3></div>
        <div class="section-content">
          <div class="detail-row">
            <span class="detail-label">name</span>
            <span class="detail-value"><%= @user.first_name %> <%= @user.last_name %></span>
          </div>
          <div class="detail-row">
            <span class="detail-label">email</span>
            <span class="detail-value"><%= @user.email %></span>
          </div>
          <div class="detail-row">
            <span class="detail-label">slack</span>
            <span class="detail-value"><%= @user.slack_id || "not linked" %></span>
          </div>
        </div>
      </div>
    <% end %>
    <div class="section">
      <div class="section-header"><h3>permissions</h3></div>
      <div class="section-content">
        <div class="detail-row">
          <span class="detail-label">roles</span>
          <span class="detail-value"><%= @user.pretty_roles %></span>
        </div>
        <div class="detail-row">
          <span class="detail-label">programs</span>
          <span class="detail-value">
            <% if @user.organized_programs.any? %>
              <%= @user.organized_programs.map(&:name).join(", ") %>
            <% else %>
              <i>none</i>
            <% end %>
          </span>
        </div>
      </div>
    </div>
    <% super_admin_tool do %>
      <hr>
      <%= render Components::Backend::Item.new(icon: "✎", href: edit_backend_user_path(@user)) do %>
        <b>edit user</b>
      <% end %>
      <% if @user.active? %>
        <%= button_to backend_user_path(@user, action: :deactivate), method: :patch, class: "item" do %>
          <figure class="icon">✕</figure>
          <span class="text"><b>deactivate</b> <i>(stops login)</i></span>
        <% end %>
      <% else %>
        <%= button_to backend_user_path(@user, action: :activate), method: :patch, class: "item" do %>
          <figure class="icon">✓</figure>
          <span class="text"><b>activate</b> <i>(allows login)</i></span>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
</div>
