<!--

    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]="markerClusteringSettingsFormGroup">
  <fieldset class="fields-group fields-group-slider">
    <legend class="group-title" translate>widgets.maps.markers-clustering-settings</legend>
    <mat-expansion-panel class="tb-settings" [expanded]="markerClusteringSettingsFormGroup.get('useClusterMarkers').value">
      <mat-expansion-panel-header class="flex-wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="useClusterMarkers" (click)="$event.stopPropagation()">
            {{ 'widgets.maps.use-map-markers-clustering' | 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="zoomOnClick" class="slide-block">
          {{ 'widgets.maps.zoom-on-cluster-click' | translate }}
        </mat-slide-toggle>
        <section class="flex flex-row xs:flex-col gt-xs:gap-2">
          <mat-form-field class="flex-1">
            <mat-label translate>widgets.maps.max-cluster-zoom</mat-label>
            <input matInput type="number" min="0" max="18" step="1" formControlName="maxZoom">
          </mat-form-field>
          <mat-form-field class="flex-1">
            <mat-label translate>widgets.maps.max-cluster-radius-pixels</mat-label>
            <input matInput type="number" min="0" formControlName="maxClusterRadius">
          </mat-form-field>
        </section>
        <section class="flex-gap-xs flex flex-col gap-2 xs:gap-4 gt-xs:flex-row">
          <mat-slide-toggle formControlName="animate" class="slide-block flex-1">
            {{ 'widgets.maps.cluster-zoom-animation' | translate }}
          </mat-slide-toggle>
          <mat-slide-toggle formControlName="showCoverageOnHover" class="slide-block flex-1">
            {{ 'widgets.maps.show-markers-bounds-on-cluster-mouse-over' | translate }}
          </mat-slide-toggle>
        </section>
        <mat-slide-toggle formControlName="spiderfyOnMaxZoom" class="slide-block">
          {{ 'widgets.maps.spiderfy-max-zoom-level' | translate }}
        </mat-slide-toggle>
        <fieldset class="fields-group">
          <legend class="group-title" translate>widgets.maps.load-optimization</legend>
          <mat-slide-toggle formControlName="chunkedLoading" class="flex-gap-xs large">
            {{ 'widgets.maps.cluster-chunked-loading' | translate }}
          </mat-slide-toggle>
          <mat-slide-toggle formControlName="removeOutsideVisibleBounds" class="slide-block">
            {{ 'widgets.maps.cluster-markers-lazy-load' | translate }}
          </mat-slide-toggle>
        </fieldset>
        <fieldset class="fields-group fields-group-slider">
          <legend class="group-title" translate>widgets.maps.clustering-markers</legend>
          <mat-expansion-panel class="tb-settings" [expanded]="markerClusteringSettingsFormGroup.get('useIconCreateFunction').value">
            <mat-expansion-panel-header class="flex-wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useIconCreateFunction" (click)="$event.stopPropagation()">
                  {{ 'widgets.maps.use-icon-create-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="clusterMarkerFunction"
                          withModules
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'childCount']"
                          functionTitle="{{ 'widgets.maps.marker-color-function' | translate }}"
                          helpId="widget/lib/map-legacy/clustering_color_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
</section>
