<!--

    Copyright © 2016-2018 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.

-->
<div ng-form="manageWidgetActionsForm" class="tb-manage-widget-actions md-whiteframe-z1 toolbarsContainer" layout="column">
    <md-toolbar class="md-table-toolbar md-default" ng-show="vm.query.search === null">
        <div class="md-toolbar-tools">
            <span translate>widget-config.actions</span>
            <span flex></span>
            <md-button class="md-icon-button" ng-click="vm.addAction($event)">
                <md-icon>add</md-icon>
                <md-tooltip md-direction="top">
                    {{ 'widget-config.add-action' | translate }}
                </md-tooltip>
            </md-button>
            <md-button class="md-icon-button" ng-click="vm.enterFilterMode($event)">
                <md-icon>search</md-icon>
                <md-tooltip md-direction="top">
                    {{ 'action.search' | translate }}
                </md-tooltip>
            </md-button>
        </div>
    </md-toolbar>
    <md-toolbar class="md-table-toolbar md-default" ng-show="vm.query.search != null">
        <div class="md-toolbar-tools">
            <md-button class="md-icon-button" aria-label="{{ 'action.search' | translate }}">
                <md-icon aria-label="{{ 'action.search' | translate }}" class="material-icons">search</md-icon>
                <md-tooltip md-direction="top">
                    {{ 'widget-config.search-actions' | translate }}
                </md-tooltip>
            </md-button>
            <md-input-container flex>
                <label>&nbsp;</label>
                <input ng-model="vm.query.search" class="searchInput" name="querySearchInput" placeholder="{{ 'widget-config.search-actions' | translate }}"/>
            </md-input-container>
            <md-button class="md-icon-button" aria-label="Close" ng-click="vm.exitFilterMode()">
                <md-icon aria-label="Close" class="material-icons">close</md-icon>
                <md-tooltip md-direction="top">
                    {{ 'action.close' | translate }}
                </md-tooltip>
            </md-button>
        </div>
    </md-toolbar>
    <md-table-container>
        <table md-table>
            <thead md-head md-order="vm.query.order" md-on-reorder="vm.onReorder">
            <tr md-row>
                <th md-column md-order-by="actionSourceName"><span translate>widget-config.action-source</span></th>
                <th md-column md-order-by="name"><span translate>widget-config.action-name</span></th>
                <th md-column md-order-by="icon"><span translate>widget-config.action-icon</span></th>
                <th md-column md-order-by="typeName"><span translate>widget-config.action-type</span></th>
                <th md-column><span>&nbsp</span></th>
            </tr>
            </thead>
            <tbody md-body>
                <tr md-row ng-repeat="action in vm.actions">
                    <td md-cell>{{action.actionSourceName}}</td>
                    <td md-cell>{{action.name}}</td>
                    <td md-cell>
                        <md-icon aria-label="{{ 'widget-config.action-icon' | translate }}" class="material-icons">{{action.icon}}</md-icon>
                    </td>
                    <td md-cell>{{action.typeName}}</td>
                    <td md-cell class="tb-action-cell">
                        <md-button class="md-icon-button" aria-label="{{ 'action.edit' | translate }}"
                                   ng-click="vm.editAction($event, action)">
                            <md-icon aria-label="{{ 'action.edit' | translate }}" class="material-icons">edit</md-icon>
                            <md-tooltip md-direction="top">
                                {{ 'widget-config.edit-action' | translate }}
                            </md-tooltip>
                        </md-button>
                        <md-button class="md-icon-button" aria-label="{{'action.delete' | translate}}" ng-click="vm.deleteAction($event, action)">
                            <md-icon aria-label="Delete" class="material-icons">delete</md-icon>
                            <md-tooltip md-direction="top">
                                {{ 'widget-config.delete-action' | translate }}
                            </md-tooltip>
                        </md-button>
                    </td>
                </tr>
            </tbody>
        </table>
    </md-table-container>
    <md-table-pagination md-limit="vm.query.limit" md-limit-options="[10, 15, 20]"
                         md-page="vm.query.page" md-total="{{vm.actionsCount}}"
                         md-on-paginate="vm.onPaginate" md-page-select>
    </md-table-pagination>
</div>
