<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div ng-controller="UsersTableController as vm">
    <md-progress-linear md-mode="indeterminate" ng-if="vm.loading"></md-progress-linear>
    <card-layout header-css="filter-header" class="centered" ng-if="!vm.loading">
        <header-section tba-card-filter-header  flex layout card-title="vm.cardTitle" page-name="{{vm.pageName}}" view-type="vm.viewType" sort-options="vm.sortOptions"
                        on-selected-option="vm.selectedTableOption" filter-model="vm.filter">
        </header-section>
        <body-section>
            <div ng-show="vm.viewType == 'list'">
                <md-list flex layout-fill class="list-item-table">
                    <md-list-item class="md-secondary" dir-paginate="user in vm.users |orderBy:vm.paginationData.sort |filter:vm.filter |itemsPerPage:vm.paginationData.rowsPerPage"
                                  pagination-id="vm.pageName" ng-class="{disabled: !user.enabled}">
                        <div layout="row" layout-fill>
                            <div flex="30" layout="column" class="item-column md-list-item-text" ng-click="vm.userDetails(user)" title="{{vm.getDisplayName(user)}}">
                                <span class="item-title" title="{{vm.getDisplayName(user)}}">
                                    {{vm.getDisplayName(user)}}
                                </span>
                                <span class="column-title column-title-bottom">
                                    <span ng-if="!user.enabled">
                                        <ng-md-icon icon="block" size="20" hide-xs></ng-md-icon>
                                    </span>
                                    Display Name
                                </span>
                            </div>
                            <div flex="40" layout="column" class="item-column md-list-item-text">
                                <span class="item-title">{{user.email}}</span>
                                <span class="column-title column-title-bottom">Email Address</span>
                            </div>
                            <div flex="30" layout="column" class="item-column md-list-item-text">
                                <span class="item-title">{{vm.getGroupTitles(user).join(', ')}}</span>
                                <span class="column-title column-title-bottom">Groups</span>
                            </div>
                        </div>
                        <md-divider ng-if="!$last"></md-divider>
                    </md-list-item>
                    <md-list-item ng-show="vm.loading == false && vm.users.length == 0" class="md-list-item with-padding">
                        No results found
                    </md-list-item >
                    <md-divider></md-divider>
                    <md-list-item layout-align="end center" layout-row class="pagination-list-item">
                        <dir-pagination-controls pagination-id="vm.pageName" auto-hide="false" max-size="5" direction-links="true" boundary-links="false"
                                                 template-url="js/vendor/dirPagination/dirPagination.tpl.html" current-page="vm.currentPage" on-page-change="vm.onPaginationChange(newPageNumber)"
                                                 label="Rows per page" rows-per-page="vm.paginationData.rowsPerPage" rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                                 class="pagination-row">
                        </dir-pagination-controls>
                    </md-list-item>
                </md-list>
            </div>
            <div ng-show="vm.viewType == 'table'">
                <md-table-container>
                    <table md-table>
                        <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange" >
                        <tr md-row>
                            <th md-column name="Display Name" md-order-by="displayName">Display Name</th>
                            <th md-column name="System Name" md-order-by="email">Email Address</th>
                            <th md-column name="State" md-order-by="enabled">Status</th>
                            <th md-column name="Groups" md-order-by="groups">Groups</th>
                        </tr>
                        </thead>
                        <tbody md-body>
                        <tr md-row
                            ng-repeat="user in vm.users |orderBy:vm.paginationData.sort |filter:vm.filter |limitTo:vm.paginationData.rowsPerPage: (vm.currentPage - 1) * vm.paginationData.rowsPerPage"
                            ng-click="vm.userDetails(user)">
                            <td md-cell>{{vm.getDisplayName(user)}}</td>
                            <td md-cell>{{user.email}}</td>
                            <td md-cell>
                                <span ng-class="{enabled: user.enabled, disabled: !user.enabled}">
                                    <ng-md-icon icon="check_circle" size="20" ng-if="user.enabled"></ng-md-icon>
                                    <ng-md-icon icon="block" size="20" ng-if="!user.enabled"></ng-md-icon>
                                    <span ng-if="user.enabled">Active</span>
                                    <span ng-if="!user.enabled">Disabled</span>
                                </span>
                            </td>
                            <td md-cell>{{vm.getGroupTitles(user).join(', ')}}</td>
                        </tr>
                        </tbody>
                    </table>
                </md-table-container>
                <md-table-pagination md-limit="vm.paginationData.rowsPerPage" md-page="vm.currentPage" md-total="{{vm.data.length}}" md-on-paginate="vm.onPaginationChange"></md-table-pagination>
            </div>
        </body-section>
    </card-layout>
</div>
