d-breadcrumbs as |breadcrumb|
  breadcrumb.item active=true
    = t 'models.plural.user'

.ui.container
  h3.ui.top.attached.header
    .ui.right.floated.icon.buttons
      /= push-action type='edit' action='editUsersContext'
      = push-action type='new' action='newUser' description='Add user'
    = t 'models.plural.user'
    span &nbsp;
    span.between-brackets= users.length
  table.ui.unstackable.table
    thead
      tr
        th= t 'attributes.user.nickname'
        th= t 'attributes.user.email'
        th= t 'models.plural.organization'
        th.actions
      tr
        td.unpadded
          .ui.mini.right.action.left.icon.input
            i.filter.icon
            = input value=nickname_filter
            if nickname_filter
              button.ui.icon.button click='clear_nickname_filter'
                i.close.icon
        td.unpadded
          .ui.mini.right.action.left.icon.input
            i.filter.icon
            = input value=email_filter
            if email_filter
              button.ui.icon.button click='clear_email_filter'
                i.close.icon
        td
          = ui-dropdown class='fluid search selection' selected=organization_filter onChange=(action 'set_organization_filter') fullTextSearch=true as |execute mapper|
              .default.text= t 'action.select_model' modelPath='models.organization'
              i.dropdown.icon
              .menu
                .item data-value='{{map-value mapper null}}' --
                each possible_organizations as |organization|
                  .item data-value='{{map-value mapper organization}}'
                    if organization.logo
                      img src=organization.logo_url.small
                    = organization.name
        td
          if organization_filter
            button.ui.mini.icon.button click="action 'set_organization_filter' null"
              i.close.icon

    tbody
      /each model as |user|
      each (sort-by 'nickname' users) as |user|
        tr
          td= link-to user.nickname 'user.show' user
          td= user.email
          td.comma-separated-items
            each (sort-by 'name' user.organizations) as |organization|
              if (eq organization_filter organization)
                strong= link-to organization.name 'organization.show' organization
              else
                = link-to organization.name 'organization.show' organization
          td.actions= push-action type='edit' action='editUser' model=user
  br
  br
