<!--

    Copyright © 2016-2020 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-content class="md-padding tb-link" layout="column">
    <fieldset ng-disabled="$root.loading || !isEdit || isReadOnly">
        <label translate class="tb-title no-padding" ng-class="{'tb-required': required}">rulenode.link-labels</label>
        <md-chips id="link_label_chips"
                  ng-required="true"
                  readonly="$root.loading || !isEdit || isReadOnly"
                  ng-model="labels" md-autocomplete-snap
                  md-transform-chip="transformLinkLabelChip($chip)"
                  md-require-match="!allowCustom">
            <md-autocomplete
                    id="link_label"
                    md-no-cache="true"
                    md-selected-item="selectedLabel"
                    md-search-text="labelSearchText"
                    md-items="item in labelsSearch(labelSearchText)"
                    md-item-text="item.name"
                    md-min-length="0"
                    placeholder="{{'rulenode.link-label' | translate }}"
                    md-menu-class="tb-link-label-autocomplete">
                <span md-highlight-text="labelSearchText" md-highlight-flags="^i">{{item}}</span>
                <md-not-found>
                    <div class="tb-not-found">
                        <div class="tb-no-entries" ng-if="!labelSearchText || !labelSearchText.length">
                            <span translate>rulenode.no-link-labels-found</span>
                        </div>
                        <div ng-if="labelSearchText && labelSearchText.length">
                            <span translate translate-values='{ label: "{{labelSearchText | truncate:true:6:&apos;...&apos;}}" }'>rulenode.no-link-label-matching</span>
                            <span ng-if="allowCustom">
                                <a translate ng-click="createLinkLabel($event, '#link_label_chips')">rulenode.create-new-link-label</a>
                            </span>
                        </div>
                    </div>
                </md-not-found>
            </md-autocomplete>
            <md-chip-template>
                <span>{{$chip.name}}</span>
            </md-chip-template>
        </md-chips>
        <div class="tb-error-messages" ng-messages="ngModelCtrl.$error" role="alert">
            <div translate ng-message="linkLabels" class="tb-error-message">rulenode.link-labels-required</div>
        </div>
    </fieldset>
</md-content>
