<!--

    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 class="tb-form-panel no-padding no-border">
  <div class="tb-form-table tb-map-data-layers">
    <div class="tb-form-table-header no-padding-right">
      <div class="tb-form-table-header-cell tb-source-header" translate>widgets.maps.data-layer.source</div>
      @if (['trips', 'markers'].includes(dataLayerType)) {
        <div class="tb-form-table-header-cell tb-x-pos-header">
          {{ (mapType === MapType.geoMap ? 'widgets.maps.data-layer.marker.latitude-key' : 'widgets.maps.data-layer.marker.x-pos-key') | translate }}
        </div>
      }
      @if (['trips', 'markers'].includes(dataLayerType)) {
        <div class="tb-form-table-header-cell tb-y-pos-header">
          {{ (mapType === MapType.geoMap ? 'widgets.maps.data-layer.marker.longitude-key' : 'widgets.maps.data-layer.marker.y-pos-key') | translate }}
        </div>
      }
      @if (dataLayerType === 'polygons') {
        <div class="tb-form-table-header-cell tb-key-header" translate>widgets.maps.data-layer.polygon.polygon-key</div>
      }
      @if (dataLayerType === 'circles') {
        <div class="tb-form-table-header-cell tb-key-header" translate>widgets.maps.data-layer.circle.circle-key</div>
      }
      @if (dataLayerType === 'polylines') {
        <div class="tb-form-table-header-cell tb-key-header" translate>widgets.maps.data-layer.polyline.polyline-key</div>
      }
      <div class="tb-form-table-header-cell tb-actions-header"></div>
    </div>
    @if (dataLayersFormArray().controls.length) {
      <div class="tb-form-table-body tb-drop-list max-h-64 overflow-y-auto"
           cdkDropList cdkDropListOrientation="vertical"
           [cdkDropListDisabled]="!dragEnabled"
           (cdkDropListDropped)="layerDrop($event)">
        @for (dataLayerControl of dataLayersFormArray().controls; track trackByDataLayer($index, dataLayerControl)) {
          <div cdkDrag [cdkDragDisabled]="!dragEnabled"
               class="tb-draggable-form-table-row"
               >
            <tb-map-data-layer-row class="flex-1"
                                   [mapType]="mapType"
                                   [dataLayerType]="dataLayerType"
                                   [context]="context"
                                   [formControl]="dataLayerControl"
                                   (dataLayerRemoved)="removeDataLayer($index)">
            </tb-map-data-layer-row>
            <div class="tb-form-table-row-cell-buttons">
              <button [class.tb-hidden]="!dragEnabled"
                      mat-icon-button
                      type="button"
                      cdkDragHandle
                      matTooltip="{{ 'action.drag' | translate }}"
                      matTooltipPosition="above">
                <mat-icon>drag_indicator</mat-icon>
              </button>
            </div>
          </div>
        }
      </div>
    } @else {
      <span class="tb-prompt flex items-center justify-center">{{ noDataLayersText | translate }}</span>
    }
  </div>
  <div>
    <button type="button" mat-stroked-button color="primary" (click)="addDataLayer()">
      {{ addDataLayerText | translate }}
    </button>
  </div>
</div>
