<!--

    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 flex layout='row' layout-align="start center">
	   <tb-device-alias-select flex="40"
							  tb-required="true"
							  device-aliases="deviceAliases"
							  ng-model="deviceAlias"
							  on-create-device-alias="onCreateDeviceAlias({event: event, alias: alias})">
	   </tb-device-alias-select>
	   <section flex="120" layout='column'>
		   <section flex layout='row' layout-align="start center">
			   <md-chips flex style="padding-left: 4px;"
						 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>device.no-keys-found</span>
								  </div>
								  <div ng-if="textIsNotEmpty(timeseriesDataKeySearchText)">
									  <span translate translate-values='{ key: "{{timeseriesDataKeySearchText | truncate:true:6:&apos;...&apos;}}" }'>device.no-key-matching</span>
									  <span>
											<a translate ng-click="createKey($event, '#timeseries_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">
							<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>
							  {{$chip.label}}:
							  <strong ng-if="!$chip.postFuncBody">{{$chip.name}}</strong>
							  <strong ng-if="$chip.postFuncBody">f({{$chip.name}})</strong>
							</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" style="padding-left: 4px;"
                         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>device.no-keys-found</span>
								  </div>
								  <div ng-if="textIsNotEmpty(attributeDataKeySearchText)">
									  <span translate translate-values='{ key: "{{attributeDataKeySearchText | truncate:true:6:&apos;...&apos;}}" }'>device.no-key-matching</span>
									  <span>
											<a translate ng-click="createKey($event, '#attribute_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">
							<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>
							  {{$chip.label}}:
							  <strong ng-if="!$chip.postFuncBody">{{$chip.name}}</strong>
							  <strong ng-if="$chip.postFuncBody">f({{$chip.name}})</strong>
							</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="deviceKeys" ng-if="widgetType === types.widgetType.timeseries.value" class="tb-error-message">datakey.timeseries-required</div>
				<div translate ng-message="deviceKeys" ng-if="widgetType === types.widgetType.latest.value" class="tb-error-message">datakey.timeseries-or-attributes-required</div>
			</div>
	   </section>
</section>
