<!--

    Copyright © 2016-2023 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 class="tb-widget-settings" [formGroup]="providerSettingsFormGroup">
  <tb-gallery-image-input label="{{ 'widgets.maps.image-map-background' | translate }}"
                  formControlName="mapImageUrl">
  </tb-gallery-image-input>
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.maps.image-map-background-from-entity-attribute</legend>
    <section fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px">
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.maps.image-url-source-entity-alias</mat-label>
        <input matInput type="text"
               placeholder="{{ 'entity.entity-alias' | translate }}"
               #entityAliasInput
               (focusin)="onEntityAliasFocus()"
               formControlName="imageEntityAlias"
               [matAutocomplete]="entityAliasAutocomplete">
        <button *ngIf="providerSettingsFormGroup.get('imageEntityAlias').value && !providerSettingsFormGroup.get('imageEntityAlias').disabled"
                type="button"
                matSuffix mat-icon-button aria-label="Clear"
                (click)="clearEntityAlias()">
          <mat-icon class="material-icons">close</mat-icon>
        </button>
        <mat-autocomplete
          class="tb-autocomplete"
          #entityAliasAutocomplete="matAutocomplete">
          <mat-option *ngFor="let entityAlias of filteredEntityAliases | async" [value]="entityAlias">
            <span [innerHTML]="entityAlias | highlight:aliasSearchText"></span>
          </mat-option>
        </mat-autocomplete>
      </mat-form-field>
      <mat-form-field fxFlex class="mat-block">
        <mat-label translate>widgets.maps.image-url-source-entity-attribute</mat-label>
        <input matInput type="text"
               placeholder="{{ 'entity.key-name' | translate }}"
               #keyInput
               (focusin)="onKeyFocus()"
               formControlName="imageUrlAttribute"
               [matAutocomplete]="keyAutocomplete">
        <button *ngIf="providerSettingsFormGroup.get('imageUrlAttribute').value && !providerSettingsFormGroup.get('imageUrlAttribute').disabled"
                type="button"
                matSuffix mat-icon-button aria-label="Clear"
                (click)="clearKey()">
          <mat-icon class="material-icons">close</mat-icon>
        </button>
        <mat-autocomplete
          class="tb-autocomplete"
          #keyAutocomplete="matAutocomplete">
          <mat-option *ngFor="let key of filteredKeys | async" [value]="key">
            <span [innerHTML]="key | highlight:keySearchText"></span>
          </mat-option>
        </mat-autocomplete>
      </mat-form-field>
    </section>
  </fieldset>
</section>
