h2 Users

table class="data" id="users"
  thead
    tr
      th Name
      th = current_user.field_label("email")
      th Role
      - if can?(:manage, :groups)
        th Permission Groups
      th colspan="2"
        - if can?(:create, Invitation) and can?(:see, :multiple_users)
          = link_to_unless_current 'Invite a New User',
                                   new_provider_admin_account_invitation_path,
                                   class: 'action add'

  tbody
    - @users.each do |user|
      tr id=(dom_id(user))
        td
          - if can? :manage, user
            - if current_user == user
              = link_to user.display_name,
                edit_provider_admin_user_personal_details_path(origin: 'users'),
                title: 'Personal Details'
            - else
              = link_to user.display_name,
                edit_provider_admin_account_user_path(user),
                title: 'Edit'
          - else
            = user.username
        td = user.email
        td = user.role

        - if can?(:manage, :groups)
          td
            - if user.admin?
              | Unlimited Access
            - else
              = user.admin_sections.any? ? AdminSection.labels(user.admin_sections) : '-'

        td.operations
          - if can? :destroy, user
            = fancy_button_to 'Delete', provider_admin_account_user_path(user),
              class: 'action delete', method: :delete,
              data: { confirm: "Are you sure you want to delete this user?" }
        td.operations
          - if can? :manage, user
            - if current_user == user
              = link_to 'Personal Details',
                edit_provider_admin_user_personal_details_path(origin: 'users'),
                title: 'Personal Details', class: 'action edit'
            - else
              = link_to 'Edit', edit_provider_admin_account_user_path(user),
                title: 'Edit', class: 'action edit'

= will_paginate @users
