<!--

    Copyright © 2016-2017 The Thingsboard Authors

    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.

-->
<span layout-align="center center"
      style="text-transform: uppercase; display: flex;"
      class="md-headline tb-absolute-fill"
      ng-show="vm.noData()">{{vm.noItemsText()}}</span>
<section layout="row" flex style="height: 100%;" flex layout-wrap>
    <div layout="column" style="height: 100%;" flex layout-wrap>
        <md-virtual-repeat-container ng-show="vm.hasData()" tb-scope-element="repeatContainer" id="tb-vertical-container" md-top-index="vm.topIndex" flex>
            <div class="md-padding" layout="column">
                <section layout="row"  md-virtual-repeat="rowItem in vm.itemRows" md-on-demand md-item-size="vm.itemHeight">
                    <div flex ng-repeat="n in [] | range:vm.columns" ng-style="{'height':vm.itemHeight+'px'}" ng-if="rowItem[n]">
                        <md-card ng-class="{'tb-current-item': vm.isCurrentItem(rowItem[n])}"
                                 class="repeated-item tb-card-item" ng-style="{'height':(vm.itemHeight-16)+'px','cursor':'pointer'}"
                                 ng-click="vm.clickItemFunc($event, rowItem[n])">
                            <section layout="row" layout-wrap>
                                <md-card-title layout="row">
                                    <section layout="column" layout-wrap>
                                        <md-checkbox ng-if="vm.isSelectionEnabled(rowItem[n])" ng-click="vm.toggleItemSelection($event, rowItem[n])"
                                                     layout-align="start start" aria-label="{{ 'item.selected' | translate }}" ng-checked="rowItem[n].selected">
                                        </md-checkbox>
                                        <span flex></span>
                                    </section>
                                    <md-card-title-text>
                                        <span class="md-headline">{{vm.getItemTitleFunc(rowItem[n])}}</span>
                                    </md-card-title-text>
                                </md-card-title>
                            </section>
                            <md-card-content flex>
                                <tb-grid-card-content flex grid-ctl="vm" parent-ctl="vm.parentCtl" item-controller="vm.itemCardController" item-template="vm.itemCardTemplate" item="rowItem[n]"></tb-grid-card-content>
                            </md-card-content>
                            <md-card-actions layout="row" layout-align="end end">
                                <md-button ng-if="action.isEnabled(rowItem[n])" ng-disabled="$root.loading" class="md-icon-button md-primary" ng-repeat="action in vm.actionsList"
                                           ng-click="action.onAction($event, rowItem[n])" aria-label="{{ action.name() }}">
                                    <md-tooltip md-direction="top">
                                        {{ action.details( rowItem[n] ) }}
                                    </md-tooltip>
                                    <ng-md-icon icon="{{action.icon}}"></ng-md-icon>
                                </md-button>
                            </md-card-actions>
                        </md-card>
                    </div>
                    <div flex ng-repeat="n in [] | range:vm.columns" ng-style="{'height':vm.itemHeight+'px'}" ng-if="!rowItem[n]">
                    </div>
                </section>
            </div>
        </md-virtual-repeat-container>
    </div>
    <tb-details-sidenav
            header-title="{{vm.getItemTitleFunc(vm.operatingItem())}}"
            header-subtitle="{{vm.itemDetailsText(vm.operatingItem())}}"
            is-read-only="vm.isDetailsReadOnly(vm.operatingItem())"
            is-open="vm.detailsConfig.isDetailsOpen"
            is-edit="vm.detailsConfig.isDetailsEditMode"
            on-close-details="vm.onCloseDetails()"
            on-toggle-details-edit-mode="vm.onToggleDetailsEditMode(vm.detailsForm)"
            on-apply-details="vm.saveItem(vm.detailsForm)"
            the-form="vm.detailsForm">
        <details-buttons>
            <div ng-transclude="detailsButtons"></div>
        </details-buttons>
        <form name="vm.detailsForm">
            <div ng-transclude></div>
        </form>
    </tb-details-sidenav>
</section>

<section layout="row" layout-wrap class="tb-footer-buttons md-fab " layout-align="start end">
    <md-button ng-disabled="$root.loading" ng-show="vm.items.selectedCount > 0" class="tb-btn-footer md-accent md-hue-2 md-fab" ng-repeat="groupAction in vm.groupActionsList"
               ng-click="groupAction.onAction($event, vm.items)" aria-label="{{ groupAction.name() }}">
        <md-tooltip md-direction="top">
            {{ groupAction.details(vm.items.selectedCount) }}
        </md-tooltip>
        <ng-md-icon icon="{{groupAction.icon}}"></ng-md-icon>
    </md-button>
    <md-button ng-disabled="$root.loading" ng-show="vm.topIndex > 0" class="tb-btn-footer md-primary md-hue-1 md-fab" ng-click="vm.moveToTop()" aria-label="{{'grid.scroll-to-top' | translate}}" >
        <md-tooltip md-direction="top">
            {{'grid.scroll-to-top' | translate}}
        </md-tooltip>
        <ng-md-icon icon="arrow_drop_up"></ng-md-icon>
    </md-button>
    <md-button ng-disabled="$root.loading" ng-if="vm.addItemAction.name() && vm.addItemActions.length == 0" class="tb-btn-footer md-accent md-hue-2 md-fab" ng-click="vm.addItemAction.onAction($event)" aria-label="{{ vm.addItemAction.name() }}" >
        <md-tooltip md-direction="top">
            {{ vm.addItemAction.details() }}
        </md-tooltip>
        <ng-md-icon icon="{{ vm.addItemAction.icon }}"></ng-md-icon>
    </md-button>
    <md-fab-speed-dial ng-disabled="$root.loading" ng-if="vm.addItemAction.name() && vm.addItemActions.length > 0" md-open="vm.addItemActionsOpen" class="md-scale" md-direction="up" ng-if="vm.addItemAction.name()">
        <md-fab-trigger>
            <md-button ng-disabled="$root.loading" class="tb-btn-footer md-accent md-hue-2 md-fab" aria-label="{{ vm.addItemAction.name() }}" >
                <md-tooltip md-direction="top">
                    {{ vm.addItemAction.details() }}
                </md-tooltip>
                <ng-md-icon icon="{{ vm.addItemAction.icon }}"></ng-md-icon>
            </md-button>
        </md-fab-trigger>
        <md-fab-actions>
            <md-button ng-disabled="$root.loading" class="md-accent md-hue-2 md-fab" ng-repeat="addItemAction in vm.addItemActions"
                       ng-click="addItemAction.onAction($event)" aria-label="{{ addItemAction.name() }}" >
                <md-tooltip md-direction="top">
                    {{ addItemAction.details() }}
                </md-tooltip>
                <ng-md-icon icon="{{addItemAction.icon}}"></ng-md-icon>
            </md-button>
        </md-fab-actions>
    </md-fab-speed-dial>
</section>