<!--

    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' layout-align="center" layout-gt-sm='row' layout-align-gt-sm="start center">
	   <tb-entity-alias-select
							  tb-required="true"
							  alias-controller="aliasController"
							  ng-model="entityAlias"
							  on-create-entity-alias="onCreateEntityAlias({event: event, alias: alias})">
	   </tb-entity-alias-select>
	   <section flex layout='column'>
		   <section flex layout='column' layout-align="center" style="padding-left: 4px;">
			   <md-chips flex
						 id="timeseries_datakey_chips"
						 ng-required="true"
						 ng-model="timeseriesDataKeys" md-autocomplete-snap
						 md-transform-chip="transformTimeseriesDataKeyChip($chip)"
						 md-require-match="false">
					  <md-autocomplete
							md-no-cache="true"
							id="timeseries_datakey"
							md-selected-item="selectedTimeseriesDataKey"
							md-search-text="timeseriesDataKeySearchText"
							md-items="item in dataKeysSearch(timeseriesDataKeySearchText, types.dataKeyType.timeseries)"
							md-item-text="item.name"
							md-min-length="0"
							placeholder="{{'datakey.timeseries' | translate }}"
							md-menu-class="tb-timeseries-datakey-autocomplete">
							<span md-highlight-text="timeseriesDataKeySearchText" md-highlight-flags="^i">{{item}}</span>
							<md-not-found>
							  <div class="tb-not-found">
								  <div class="tb-no-entries" ng-if="!textIsNotEmpty(timeseriesDataKeySearchText)">
									  <span translate>entity.no-keys-found</span>
								  </div>
								  <div ng-if="textIsNotEmpty(timeseriesDataKeySearchText)">
									  <span translate translate-values='{ key: "{{timeseriesDataKeySearchText | truncate:true:6:&apos;...&apos;}}" }'>entity.no-key-matching</span>
									  <span>
											<a translate ng-click="createKey($event, '#timeseries_datakey_chips')">entity.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 ng-if="!$chip.postFuncBody">{{$chip.name}}</strong>
								  <strong ng-if="$chip.postFuncBody">f({{$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>
			   <md-chips flex ng-if="widgetType === types.widgetType.latest.value"
                         id="attribute_datakey_chips"
                         ng-required="true"
                         ng-model="attributeDataKeys" md-autocomplete-snap
                         md-transform-chip="transformAttributeDataKeyChip($chip)"
                         md-require-match="false">
					  <md-autocomplete
							md-no-cache="true"
							id="attribute_datakey"
							md-selected-item="selectedAttributeDataKey"
							md-search-text="attributeDataKeySearchText"
							md-items="item in dataKeysSearch(attributeDataKeySearchText, types.dataKeyType.attribute)"
							md-item-text="item.name"
							md-min-length="0"
							placeholder="{{'datakey.attributes' | translate }}"
							md-menu-class="tb-attribute-datakey-autocomplete">
							<span md-highlight-text="attributeDataKeySearchText" md-highlight-flags="^i">{{item}}</span>
						    <md-not-found>
							  <div class="tb-not-found">
								  <div class="tb-no-entries" ng-if="!textIsNotEmpty(attributeDataKeySearchText)">
									  <span translate>entity.no-keys-found</span>
								  </div>
								  <div ng-if="textIsNotEmpty(attributeDataKeySearchText)">
									  <span translate translate-values='{ key: "{{attributeDataKeySearchText | truncate:true:6:&apos;...&apos;}}" }'>entity.no-key-matching</span>
									  <span>
											<a translate ng-click="createKey($event, '#attribute_datakey_chips')">entity.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 ng-if="!$chip.postFuncBody">{{$chip.name}}</strong>
									  <strong ng-if="$chip.postFuncBody">f({{$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>
		   </section>
		   <div class="tb-error-messages" ng-messages="ngModelCtrl.$error" role="alert">
			    <div translate ng-message="entityKeys" ng-if="widgetType === types.widgetType.timeseries.value" class="tb-error-message">datakey.timeseries-required</div>
				<div translate ng-message="entityKeys" ng-if="widgetType === types.widgetType.latest.value" class="tb-error-message">datakey.timeseries-or-attributes-required</div>
			</div>
	   </section>
</section>
