<!--

    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.

-->
<md-dialog class="tb-entity-alias-dialog" style="width: 600px;" aria-label="{{ (vm.isAdd ? 'alias.add' : 'alias.edit') | translate  }}">
    <form name="theForm" ng-submit="vm.save()">
        <md-toolbar>
            <div class="md-toolbar-tools">
                <h2>{{ (vm.isAdd ? 'alias.add' : 'alias.edit') | translate  }}</h2>
                <span flex></span>
                <md-button class="md-icon-button" ng-click="vm.cancel()">
                    <ng-md-icon icon="close" aria-label="{{ 'dialog.close' | translate }}"></ng-md-icon>
                </md-button>
            </div>
        </md-toolbar>
        <md-progress-linear class="md-warn" md-mode="indeterminate" ng-disabled="!$root.loading" ng-show="$root.loading"></md-progress-linear>
        <span style="min-height: 5px;" flex="" ng-show="!$root.loading"></span>
        <md-dialog-content>
            <div class="md-dialog-content">
                <fieldset ng-disabled="$root.loading">
                    <div flex layout="column">
                        <div layout="row">
                            <md-input-container flex class="md-block">
                                <label translate>alias.name</label>
                                <input required name="aliasName"
                                       ng-model="vm.alias.alias"
                                       aria-label="{{ 'alias.name' | translate }}">
                                <div ng-messages="theForm.aliasName.$error">
                                    <div ng-message="required" translate>alias.name-required</div>
                                    <div ng-message="duplicateAliasName" translate>alias.duplicate-alias</div>
                                </div>
                            </md-input-container>
                            <section class="tb-resolve-multiple-switch" layout="column" layout-align="start center">
                                <label class="tb-small resolve-multiple-label" translate>alias.resolve-multiple</label>
                                <md-switch class="resolve-multiple-switch" ng-model="vm.alias.filter.resolveMultiple"
                                           aria-label="{{ 'alias.resolve-multiple' | translate }}">
                                </md-switch>
                            </section>
                        </div>
                        <tb-entity-filter
                            ng-model="vm.alias.filter"
                            allowed-entity-types="vm.allowedEntityTypes"
                            the-form="theForm">
                        </tb-entity-filter>
                        <div class="tb-error-messages" ng-messages="theForm.$error" role="alert">
                            <div translate ng-message="entityFilter" class="tb-error-message">alias.entity-filter-no-entity-matched</div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </md-dialog-content>
        <md-dialog-actions layout="row">
            <span flex></span>
            <md-button ng-disabled="$root.loading || theForm.$invalid || !theForm.$dirty" type="submit" class="md-raised md-primary">
                {{ (vm.isAdd ? 'action.add' : 'action.save') | translate }}
            </md-button>
            <md-button ng-disabled="$root.loading" ng-click="vm.cancel()" style="margin-right:20px;">{{ 'action.cancel' | translate }}</md-button>
        </md-dialog-actions>
    </form>
</md-dialog>
