<!--

    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.

-->
<section flex layout='column' style="padding-left: 4px;">
   <md-chips flex
			     id="function_datakey_chips"
	   			 ng-required="true"
	             ng-model="funcDataKeys" md-autocomplete-snap
	             md-transform-chip="transformDataKeyChip($chip)"
	             md-require-match="false">    
		      <md-autocomplete 
		    		md-no-cache="false"
		    		id="dataKey"
					md-selected-item="selectedDataKey"
					md-search-text="dataKeySearchText"
					md-items="item in dataKeysSearch(dataKeySearchText)"
					md-item-text="item.name"
					md-min-length="0"
		            placeholder="{{ 'datakey.function-types' | translate }}"
					md-menu-class="tb-func-datakey-autocomplete">
		            <span md-highlight-text="dataKeySearchText" md-highlight-flags="^i">{{item}}</span>
				    <md-not-found>
						<div class="tb-not-found">
							<div class="tb-no-entries" ng-if="!textIsNotEmpty(dataKeySearchText)">
								<span translate>device.no-keys-found</span>
							</div>
							<div ng-if="textIsNotEmpty(dataKeySearchText)">
								<span translate translate-values='{ key: "{{dataKeySearchText | truncate:true:6:&apos;...&apos;}}" }'>device.no-key-matching</span>
								<span>
		          					<a translate ng-click="createKey($event, '#function_datakey_chips')">device.create-new-key</a>
						  		</span>
							</div>
						</div>
				    </md-not-found>
			  </md-autocomplete>
		      <md-chip-template>
				  <div layout="row" layout-align="start center" class="tb-attribute-chip">
					  <div class="tb-color-preview" ng-click="showColorPicker($event, $chip, $index)" style="margin-right: 5px;">
						  <div class="tb-color-result" ng-style="{background: $chip.color}"></div>
					  </div>
					  <div layout="row" flex>
						  <div class="tb-chip-label">
							  {{$chip.label}}
						  </div>
						  <div class="tb-chip-separator">: </div>
						  <div class="tb-chip-label">
							  <strong>{{$chip.name}}</strong>
						  </div>
					  </div>
					  <md-button ng-click="editDataKey($event, $chip, $index)" class="md-icon-button tb-md-32">
						  <md-icon aria-label="edit" class="material-icons tb-md-20">edit</md-icon>
					  </md-button>
				  </div>
		      </md-chip-template>
	</md-chips>
	<div class="tb-error-messages" ng-messages="ngModelCtrl.$error" role="alert">
		<div translate ng-message="funcTypes" class="tb-error-message">datakey.function-types-required</div>
	</div>
</section>
