<!--

    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.

-->
<section class="tb-widget-settings" [formGroup]="markersSettingsFormGroup">
  <fieldset class="fields-group">
    <legend class="group-title" translate>widgets.maps.markers-settings</legend>
    <section class="!flex flex-row xs:flex-col gt-xs:gap-2">
      <mat-form-field class="flex-1">
        <mat-label translate>widgets.maps.marker-offset-x</mat-label>
        <input matInput type="number" formControlName="markerOffsetX">
      </mat-form-field>
      <mat-form-field class="flex-1">
        <mat-label translate>widgets.maps.marker-offset-y</mat-label>
        <input matInput type="number" formControlName="markerOffsetY">
      </mat-form-field>
    </section>
    <tb-js-func [class.!hidden]="provider !== mapProvider.image"
                formControlName="posFunction"
                withModules
                minHeight="100px"
                [globalVariables]="functionScopeVariables"
                [functionArgs]="['origXPos', 'origYPos', 'data', 'dsData', 'dsIndex', 'aspect']"
                functionTitle="{{ 'widgets.maps.position-function' | translate }}"
                helpId="widget/lib/map-legacy/position_fn">
    </tb-js-func>
    <mat-checkbox formControlName="draggableMarker">
      {{ 'widgets.maps.draggable-marker' | translate }}
    </mat-checkbox>
    <fieldset class="fields-group fields-group-slider">
      <legend class="group-title" translate>widgets.maps.label</legend>
      <mat-expansion-panel class="tb-settings" [expanded]="markersSettingsFormGroup.get('showLabel').value">
        <mat-expansion-panel-header class="flex-wrap">
          <mat-panel-title>
            <mat-slide-toggle formControlName="showLabel" (click)="$event.stopPropagation()">
              {{ 'widgets.maps.show-label' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
          <mat-panel-description class="justify-end xs:!hidden" translate>
            widget-config.advanced-settings
          </mat-panel-description>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <mat-slide-toggle formControlName="useLabelFunction" class="slide-block">
            {{ 'widgets.maps.use-label-function' | translate }}
          </mat-slide-toggle>
          <tb-html [class.!hidden]="markersSettingsFormGroup.get('useLabelFunction').value"
                   formControlName="label"
                   minHeight="100px"
                   label="{{ 'widgets.maps.label-pattern' | translate }}">
          </tb-html>
          <tb-js-func [class.!hidden]="!markersSettingsFormGroup.get('useLabelFunction').value"
                      formControlName="labelFunction"
                      withModules
                      [globalVariables]="functionScopeVariables"
                      [functionArgs]="['data', 'dsData', 'dsIndex']"
                      functionTitle="{{ 'widgets.maps.label-function' | translate }}"
                      helpId="widget/lib/map-legacy/label_fn">
          </tb-js-func>
        </ng-template>
      </mat-expansion-panel>
    </fieldset>
    <fieldset class="fields-group fields-group-slider">
      <legend class="group-title" translate>widgets.maps.tooltip</legend>
      <mat-expansion-panel class="tb-settings" [expanded]="markersSettingsFormGroup.get('showTooltip').value">
        <mat-expansion-panel-header class="flex-wrap">
          <mat-panel-title>
            <mat-slide-toggle formControlName="showTooltip" (click)="$event.stopPropagation()">
              {{ 'widgets.maps.show-tooltip' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
          <mat-panel-description class="justify-end xs:!hidden" translate>
            widget-config.advanced-settings
          </mat-panel-description>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <mat-form-field class="mat-block">
            <mat-label translate>widgets.maps.show-tooltip-action</mat-label>
            <mat-select required formControlName="showTooltipAction">
              @for (action of showTooltipActions; track action) {
                <mat-option [value]="action">
                  {{showTooltipActionTranslations.get(action) | translate}}
                </mat-option>
              }
            </mat-select>
          </mat-form-field>
          <mat-slide-toggle formControlName="autocloseTooltip" class="slide-block">
            {{ 'widgets.maps.auto-close-tooltips' | translate }}
          </mat-slide-toggle>
          <mat-slide-toggle formControlName="useTooltipFunction" class="slide-block">
            {{ 'widgets.maps.use-tooltip-function' | translate }}
          </mat-slide-toggle>
          <tb-html [class.!hidden]="markersSettingsFormGroup.get('useTooltipFunction').value"
                   formControlName="tooltipPattern"
                   minHeight="100px"
                   label="{{ 'widgets.maps.tooltip-pattern' | translate }}">
          </tb-html>
          <tb-js-func [class.!hidden]="!markersSettingsFormGroup.get('useTooltipFunction').value"
                      formControlName="tooltipFunction"
                      withModules
                      [globalVariables]="functionScopeVariables"
                      [functionArgs]="['data', 'dsData', 'dsIndex']"
                      functionTitle="{{ 'widgets.maps.tooltip-function' | translate }}"
                      helpId="widget/lib/map-legacy/tooltip_fn">
          </tb-js-func>
          <section class="flex flex-row xs:flex-col gt-xs:gap-2">
            <mat-form-field class="flex-1">
              <mat-label translate>widgets.maps.tooltip-offset-x</mat-label>
              <input matInput type="number" formControlName="tooltipOffsetX">
            </mat-form-field>
            <mat-form-field class="flex-1">
              <mat-label translate>widgets.maps.tooltip-offset-y</mat-label>
              <input matInput type="number" formControlName="tooltipOffsetY">
            </mat-form-field>
          </section>
        </ng-template>
      </mat-expansion-panel>
    </fieldset>
    <fieldset class="fields-group">
      <legend class="group-title" translate>widgets.maps.color</legend>
      <tb-color-input
        formControlName="color"
        icon="format_color_fill"
        label="{{ 'widgets.maps.color' | translate }}" openOnInput colorClearButton>
      </tb-color-input>
      <mat-expansion-panel class="tb-settings" [expanded]="markersSettingsFormGroup.get('useColorFunction').value">
        <mat-expansion-panel-header class="flex-wrap">
          <mat-panel-title>
            <mat-slide-toggle formControlName="useColorFunction" (click)="$event.stopPropagation()">
              {{ 'widgets.maps.use-color-function' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
          <mat-panel-description class="justify-end xs:!hidden" translate>
            widget-config.advanced-settings
          </mat-panel-description>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <tb-js-func formControlName="colorFunction"
                      withModules
                      [globalVariables]="functionScopeVariables"
                      [functionArgs]="['data', 'dsData', 'dsIndex']"
                      functionTitle="{{ 'widgets.maps.color-function' | translate }}"
                      helpId="widget/lib/map-legacy/color_fn">
          </tb-js-func>
        </ng-template>
      </mat-expansion-panel>
    </fieldset>
    <fieldset class="fields-group fields-group-slider">
      <legend class="group-title" translate>widgets.maps.marker-image</legend>
      <mat-expansion-panel class="tb-settings" expanded>
        <mat-expansion-panel-header class="flex-wrap">
          <mat-panel-title>
            <mat-slide-toggle formControlName="useMarkerImageFunction" (click)="$event.stopPropagation()">
              {{ 'widgets.maps.use-marker-image-function' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
          <mat-panel-description class="justify-end xs:!hidden" translate>
            widget-config.advanced-settings
          </mat-panel-description>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <tb-gallery-image-input [class.!hidden]="markersSettingsFormGroup.get('useMarkerImageFunction').value"
                                  label="{{ 'widgets.maps.custom-marker-image' | translate }}"
                                  formControlName="markerImage">
          </tb-gallery-image-input>
          <mat-form-field [class.!hidden]="markersSettingsFormGroup.get('useMarkerImageFunction').value"
                          class="mat-block">
            <mat-label translate>widgets.maps.custom-marker-image-size</mat-label>
            <input matInput type="number" min="1" formControlName="markerImageSize">
          </mat-form-field>
          <tb-js-func [class.!hidden]="!markersSettingsFormGroup.get('useMarkerImageFunction').value"
                      formControlName="markerImageFunction"
                      withModules
                      [globalVariables]="functionScopeVariables"
                      [functionArgs]="['data', 'images', 'dsData', 'dsIndex']"
                      functionTitle="{{ 'widgets.maps.marker-image-function' | translate }}"
                      helpId="widget/lib/map-legacy/marker_image_fn">
          </tb-js-func>
          <tb-multiple-gallery-image-input [class.!hidden]="!markersSettingsFormGroup.get('useMarkerImageFunction').value"
                                           label="{{ 'widgets.maps.marker-images' | translate }}"
                                           formControlName="markerImages">
          </tb-multiple-gallery-image-input>
        </ng-template>
      </mat-expansion-panel>
    </fieldset>
  </fieldset>
</section>
