<!--

    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]="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 fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="useClusterMarkers" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.maps.use-map-markers-clustering' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxLayoutAlign="end center" fxHide.xs 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 fxLayout="row" fxLayout.xs="column" fxLayoutGap.gt-xs="8px">
          <mat-form-field fxFlex class="mat-block">
            <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 fxFlex class="mat-block">
            <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" fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap="8px" fxLayoutGap.xs="16px">
          <mat-slide-toggle fxFlex formControlName="animate" class="slide-block">
            {{ 'widgets.maps.cluster-zoom-animation' | translate }}
          </mat-slide-toggle>
          <mat-slide-toggle fxFlex formControlName="showCoverageOnHover" class="slide-block">
            {{ '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 fxLayout="row wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useIconCreateFunction" (click)="$event.stopPropagation()"
                                  fxLayoutAlign="center">
                  {{ 'widgets.maps.use-icon-create-function' | translate }}
                </mat-slide-toggle>
              </mat-panel-title>
              <mat-panel-description fxLayoutAlign="end center" fxHide.xs translate>
                widget-config.advanced-settings
              </mat-panel-description>
            </mat-expansion-panel-header>
            <ng-template matExpansionPanelContent>
              <tb-js-func formControlName="clusterMarkerFunction"
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'childCount']"
                          functionTitle="{{ 'widgets.maps.marker-color-function' | translate }}"
                          helpId="widget/lib/map/clustering_color_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
</section>
