<!--

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

-->
<section layout='column'>
    <md-autocomplete id="device-autocomplete"
                     md-input-name="device_alias"
                     ng-required="tbRequired"
                     ng-model="deviceAlias"
                     md-selected-item="deviceAlias"
                     md-search-text="deviceAliasSearchText"
                     md-items="item in deviceAliasSearch(deviceAliasSearchText)"
                     md-item-text="item.alias"
                     tb-keydown="deviceAliasEnter($event)"
                     tb-keypress="deviceAliasEnter($event)"
                     md-min-length="0"
                     placeholder="{{ 'device.device-alias' | translate }}"
                     md-menu-class="tb-device-alias-autocomplete">
        <md-item-template>
            <span md-highlight-text="deviceAliasSearchText" md-highlight-flags="^i">{{item.alias}}</span>
        </md-item-template>
        <md-not-found>
            <div class="tb-not-found">
                <div class="tb-no-entries" ng-if="!textIsNotEmpty(deviceAliasSearchText)">
                    <span translate>device.no-aliases-found</span>
                </div>
                <div ng-if="textIsNotEmpty(deviceAliasSearchText)">
                    <span translate translate-values='{ alias: "{{deviceAliasSearchText | truncate:true:6:&apos;...&apos;}}" }'>device.no-alias-matching</span>
                    <span>
                        <a translate ng-click="createDeviceAlias($event, deviceAliasSearchText)">device.create-new-alias</a>
                    </span>
                </div>
            </div>
        </md-not-found>
    </md-autocomplete>
    <div class="tb-error-messages" ng-messages="ngModelCtrl.$error" role="alert">
        <div translate ng-message="deviceAlias" class="tb-error-message">device.alias-required</div>
    </div>
</section>
