<!--
  #%L
  thinkbig-ui-operations-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%
  -->
<card-layout flex header-css="filter-header">
    <header-section tba-card-filter-header transclude-to="head" 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" filter-model-options="{debounce:1000}">

    </header-section>
    <body-section transclude-to="body">
        <md-tabs flex md-selected="vm.tabMetadata.selectedIndex" md-align-tabs="top" layout-fill md-dynamic-height>

            <md-tab ng-repeat="tab in vm.tabs" ng-disabled="tab.disabled" md-on-select="vm.onTabSelected(tab)" flex>
                <md-tab-label>{{tab.title}}</md-tab-label>
                <md-tab-body>
                    <md-divider></md-divider>
                    <div ng-show="vm.viewType == 'list'">
                        <div ng-if="vm.showProgress" class="md-list-table-progress">
                            <md-progress-linear md-mode="indeterminate"></md-progress-linear>
                            <br/><br/>
                        </div>
                        <md-list flex layout-fill ng-show="vm.loading == false" class="list-item-table">
                            <md-list-item dir-paginate="alert in tab.data.content|itemsPerPage:vm.paginationData.rowsPerPage" pagination-id="vm.paginationId(tab)" total-items="tab.data.total"
                                          current-page="tab.currentPage">
                                <div layout="row" layout-fill>
                                    <div flex="15" layout="column" style="overflow:hidden; text-overflow:ellipsis;" class="item-column  md-list-item-text" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">
                                            {{alert.level}}
                                        </span>
                                        <span class="column-title column-title-bottom">Level</span>
                                    </div>

                                    <div flex="15" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.state }}</span>
                                        <span class="column-title column-title-bottom">State</span>
                                    </div>

                                    <div flex="20" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.createdTime | date: 'MMM d, yyyy HH:mm:ss'}}</span>
                                        <span class="column-title column-title-bottom">Start Time</span>
                                    </div>

                                    <div flex="50" layout="column" hide show-gt-xs show-lg show-xl show-sm show-md class="item-column  md-list-item-text" ng-click="vm.alertDetails($event,alert)">
                                        <span class="item-title">{{alert.description }}</span>
                                        <span class="column-title column-title-bottom">Description</span>
                                    </div>
                                </div>
                                <md-divider ng-if="!$last"></md-divider>

                            </md-list-item>
                            <md-item ng-show="vm.showProgress == false && tab.data.content.length == 0" style="padding:10px">
                                No results found
                            </md-item>
                            <md-divider></md-divider>
                        </md-list>
                    </div>

                    <div ng-show="vm.viewType == 'table'">
                        <md-table-container>
                            <table md-table md-progress="vm.deferred.promise">
                                <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange">
                                    <tr md-row>
                                        <th md-column name="Level">Level</th>
                                        <th md-column name="State">State</th>
                                        <th md-column name="Start Time" md-order-by="startTime" hide show-gt-sm>Start Time</th>
                                        <th md-column name="Description">Description</th>
                                    </tr>
                                </thead>
                                <tbody md-body>
                                    <tr md-row ng-repeat="alert in tab.data.content" ng-click="vm.alertDetails($event,alert)">
                                        <td md-cell>{{alert.level}}</td>
                                        <td md-cell>{{alert.state}}</td>
                                        <td md-cell hide show-gt-sm>{{alert.createdTime | date:'MMM d, yyyy HH:mm:ss'}}</td>
                                        <td md-cell>{{alert.description}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </md-table-container>
                        <div ng-if="vm.showProgress == false && tab.data.content.length == 0" layout="column" layout-align="center center">
                            No results found
                        </div>
                        <md-divider></md-divider>
                    </div>

                    <dir-pagination-controls pagination-id="vm.paginationId(tab)"
                                             auto-hide="false"
                                             max-size="5"
                                             direction-links="true"
                                             boundary-links="false"
                                             template-url="js/common/dir-pagination/dirPagination.tpl.html"
                                             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-tab-body>
            </md-tab>
        </md-tabs>
    </body-section>
</card-layout>
