<!--

    Copyright © 2016-2026 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.

-->
<div [formGroup]="dataSourceFormGroup" class="tb-form-table-row tb-map-data-source-row">
  <div class="tb-source-field">
    <mat-form-field class="tb-ds-type-field tb-inline-field" appearance="outline" subscriptSizing="dynamic">
      <mat-select formControlName="dsType">
        @for (type of datasourceTypes; track type) {
          <mat-option [value]="type">
            {{ datasourceTypesTranslations.get(type) | translate }}
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
    @if (dataSourceFormGroup.get('dsType').value === DatasourceType.device) {
      <tb-entity-autocomplete
        class="tb-device-field"
        required
        inlineField
        placeholder="{{ 'device.select-device' | translate }}"
        [entityType]="EntityType.DEVICE"
        formControlName="dsDeviceId">
      </tb-entity-autocomplete>
    }
    @if (dataSourceFormGroup.get('dsType').value === DatasourceType.entity) {
      <tb-entity-alias-select
        class="tb-entity-alias-field"
        inlineField
        tbRequired
        [aliasController]="context.aliasController"
        formControlName="dsEntityAliasId"
        [callbacks]="context.callbacks">
      </tb-entity-alias-select>
    }
  </div>
  <tb-filter-select
    class="tb-filter-field"
    inlineField
    [aliasController]="context.aliasController"
    formControlName="dsFilterId"
    [callbacks]="context.callbacks">
  </tb-filter-select>
  <div class="tb-form-table-row-cell-buttons">
    <div class="tb-remove-button">
      <button type="button"
              mat-icon-button
              (click)="dataSourceRemoved.emit()"
              matTooltip="{{ 'widgets.maps.data-layer.remove-datasource' | translate }}"
              matTooltipPosition="above">
        <mat-icon>delete</mat-icon>
      </button>
    </div>
  </div>
</div>
