<%= render 'shared/settings_nav' %>

<%= params[:status].to_s.titleize %> Users

<% if can?(:create, User.new(account: current_account)) %> <%= link_to new_user_path, class: 'btn btn-primary btn-md gap-2', data: { turbo_frame: 'modal' } do %> <%= svg_icon('plus', class: 'w-6 h-6') %> New User <% end %> <% end %>
<% @users.each do |user| %> <% end %>
Name Email Role Last session
<%= user.full_name %> <%= user.email %> <%= user.role %> <%= user.last_sign_in_at ? l(user.last_sign_in_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) : '-' %> <% if can?(:update, user) %> <%= link_to edit_user_path(user), class: 'btn btn-outline btn-xs', title: 'Edit', data: { turbo_frame: 'modal' } do %> Edit <% end %> <% end %> <% if params[:status].blank? && can?(:destroy, user) && user != current_user %> <%= button_to user_path(user), method: :delete, class: 'btn btn-outline btn-error btn-xs', title: 'Delete', data: { turbo_confirm: 'Are you sure?' } do %> Remove <% end %> <% end %> <% if params[:status].present? && can?(:manage, user) && user != current_user %> <%= button_to user_path(user), method: :put, params: { user: { archived_at: nil } }, class: 'btn btn-outline btn-secondary btn-xs', title: 'Unarchive', data: { turbo_confirm: 'Are you sure?' } do %> Unarchive <% end %> <% end %>
<% view_archived_html = capture do %> <% if current_account.users.archived.exists? %>
<% if params[:status] == 'archived' %> View Active <% else %> View Archived <% end %>
<% end %> <% end %> <% if @pagy.pages > 1 %> <%= render 'shared/pagination', pagy: @pagy, items_name: 'users', left_additional_html: view_archived_html %> <% else %>
<%= view_archived_html %>
<% end %>