<div class="card-hoverable <%= 'current-session' if identity_session.id == @current_session&.id %>">
  <div class="session-header">
    <div class="session-icon">
      <% if identity_session.os_info&.include?("Mac") || identity_session.os_info&.include?("macOS") %>
        <%= inline_icon("apple", size: 32) %>
      <% elsif identity_session.os_info&.include?("iOS") || identity_session.os_info&.include?("iPhone") || identity_session.os_info&.include?("iPad") %>
        <%= inline_icon("apple", size: 32) %>
      <% elsif identity_session.os_info&.include?("Windows") %>
        <%= inline_icon("windows", size: 32) %>
      <% elsif identity_session.os_info&.include?("Android") %>
        <%= inline_icon("google", size: 32) %>
      <% elsif identity_session.os_info&.include?("Linux") %>
        <%= inline_icon("terminal", size: 32) %>
      <% else %>
        <%= inline_icon("web", size: 32) %>
      <% end %>
    </div>
    <div class="session-info">
      <div class="session-device">
        <%= identity_session.device_info || t("identity_sessions.unknown_device") %>
        <% if identity_session.id == @current_session&.id %>
          <span class="current-badge"><%= t "identity_sessions.current" %></span>
        <% end %>
      </div>
      <div class="session-os"><%= identity_session.os_info || t("identity_sessions.unknown_os") %></div>
    </div>
  </div>

  <div class="session-details">
    <div>
      <span class="detail-label"><%= t "identity_sessions.ip" %></span>
      <span><%= identity_session.ip || t("identity_sessions.unknown") %></span>
    </div>
    <div>
      <span class="detail-label"><%= t "identity_sessions.created_at" %></span>
      <span><%= identity_session.created_at.strftime("%b %d, %Y at %l:%M %p") %></span>
    </div>
    <div>
      <span class="detail-label"><%= t "identity_sessions.last_seen" %></span>
      <span><%= time_ago_in_words(identity_session.last_seen || identity_session.created_at) %> ago</span>
    </div>
    <div>
      <span class="detail-label"><%= t "identity_sessions.expires_at" %></span>
      <span><%= identity_session.expires_at.strftime("%b %d, %Y") %></span>
    </div>
    <% if identity_session.login_attempt %>
      <div>
        <span class="detail-label"><%= t "identity_sessions.auth_type" %></span>
        <span class="<%= 'backup-code-method' if identity_session.login_attempt.authenticated_with_backup_code %>">
          <% auth_methods = [] %>
          <% auth_methods << t("auth_type.email") if identity_session.login_attempt.authenticated_with_email || identity_session.login_attempt.authenticated_with_legacy_email %>
          <% auth_methods << t("auth_type.totp") if identity_session.login_attempt.authenticated_with_totp %>
          <% auth_methods << t("auth_type.webauthn") if identity_session.login_attempt.authenticated_with_webauthn %>
          <% auth_methods << t("auth_type.backup_code") if identity_session.login_attempt.authenticated_with_backup_code %>
          <%= auth_methods.join(", ") %>
        </span>
      </div>
    <% end %>
  </div>

  <% if identity_session.id != @current_session&.id %>
    <button class="danger small-btn"
            hx-delete="<%= identity_session_path(identity_session) %>"
            hx-target="#sessions-container"
            hx-confirm="<%= t "identity_sessions.terminate_confirmation" %>">
      <%= t "identity_sessions.terminate" %> <%= inline_icon("door-leave", size: 16) %>
    </button>
  <% end %>
</div>
