h1 = ExternalUser.model_name.human(count: 2)

= render(layout: 'shared/form_filters') do |f|
  .row.px-3
    .form-group
      = f.label(:name_cont, t('activerecord.attributes.external_user.name'), class: 'sr-only')
      = f.search_field(:name_cont, class: 'form-control', placeholder: t('activerecord.attributes.external_user.name'))
    .form-group
      = f.label(:email_cont, t('activerecord.attributes.external_user.email'), class: 'sr-only')
      = f.search_field(:email_cont, class: 'form-control', placeholder: t('activerecord.attributes.external_user.email'))
    .form-group
      = f.label(:external_id_cont, t('activerecord.attributes.external_user.external_id'), class: 'sr-only')
      = f.search_field(:external_id_cont, class: 'form-control', placeholder: t('activerecord.attributes.external_user.external_id'))
  .row.px-3
    .form-group
      = f.label(:role_eq, t('activerecord.attributes.external_user.role'), class: 'sr-only')
      = f.select(:role_eq, User::ROLES.map { |role| [t("users.roles.#{role}"), role] }, { include_blank: true }, class: 'form-control', prompt: t('activerecord.attributes.external_user.role'))
    .form-group
      = f.label(:consumer_id_eq, t('activerecord.attributes.external_user.consumer'), class: 'sr-only')
      = f.collection_select(:consumer_id_eq, Consumer.with_external_users, :id, :name, class: 'form-control', prompt: t('activerecord.attributes.external_user.consumer'))
.table-responsive
  table.table
    thead
      tr
        th = t('activerecord.attributes.external_user.name')
        th = t('activerecord.attributes.external_user.consumer')
        th = t('shared.actions')
    tbody
      - @users.each do |user|
        tr
          td = link_to_if(policy(user).show?, user.displayname, user)
          td = link_to_if(user.consumer.present? && policy(user.consumer).show?, user.consumer, user.consumer)
          td = link_to(t('shared.show'), user) if policy(user).show?

= render('shared/pagination', collection: @users)
