<!--

    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]="circleSettingsFormGroup">
  <fieldset class="fields-group fields-group-slider">
    <legend class="group-title" translate>widgets.maps.circle-settings</legend>
    <mat-expansion-panel class="tb-settings" [expanded]="circleSettingsFormGroup.get('showCircle').value">
      <mat-expansion-panel-header class="flex-wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="showCircle" (click)="$event.stopPropagation()">
            {{ 'widgets.maps.show-circle' | 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-datasources-key-autocomplete required
                                         [datasources]="widget?.config?.datasources"
                                         label="widgets.maps.circle-key-name"
                                         formControlName="circleKeyName">
        </tb-datasources-key-autocomplete>
        <mat-checkbox formControlName="editableCircle">
          {{ 'widgets.maps.enable-circle-edit' | translate }}
        </mat-checkbox>
        <fieldset class="fields-group fields-group-slider">
          <legend class="group-title" translate>widgets.maps.circle-label</legend>
          <mat-expansion-panel class="tb-settings" [expanded]="circleSettingsFormGroup.get('showCircleLabel').value">
            <mat-expansion-panel-header class="flex-wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="showCircleLabel" (click)="$event.stopPropagation()">
                  {{ 'widgets.maps.show-circle-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="useCircleLabelFunction" class="slide-block">
                {{ 'widgets.maps.use-circle-label-function' | translate }}
              </mat-slide-toggle>
              <tb-html [class.!hidden]="circleSettingsFormGroup.get('useCircleLabelFunction').value"
                       formControlName="circleLabel"
                       minHeight="100px"
                       label="{{ 'widgets.maps.circle-label-pattern' | translate }}">
              </tb-html>
              <tb-js-func [class.!hidden]="!circleSettingsFormGroup.get('useCircleLabelFunction').value"
                          formControlName="circleLabelFunction"
                          withModules
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-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.circle-tooltip</legend>
          <mat-expansion-panel class="tb-settings" [expanded]="circleSettingsFormGroup.get('showCircleTooltip').value">
            <mat-expansion-panel-header class="flex-wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="showCircleTooltip" (click)="$event.stopPropagation()">
                  {{ 'widgets.maps.show-circle-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="flex-1">
                <mat-label translate>widgets.maps.show-tooltip-action</mat-label>
                <mat-select required formControlName="showCircleTooltipAction">
                  @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="autoCloseCircleTooltip" class="slide-block">
                {{ 'widgets.maps.auto-close-circle-tooltips' | translate }}
              </mat-slide-toggle>
              <mat-slide-toggle formControlName="useCircleTooltipFunction" class="slide-block">
                {{ 'widgets.maps.use-circle-tooltip-function' | translate }}
              </mat-slide-toggle>
              <tb-html [class.!hidden]="circleSettingsFormGroup.get('useCircleTooltipFunction').value"
                       formControlName="circleTooltipPattern"
                       minHeight="100px"
                       label="{{ 'widgets.maps.circle-tooltip-pattern' | translate }}">
              </tb-html>
              <tb-js-func [class.!hidden]="!circleSettingsFormGroup.get('useCircleTooltipFunction').value"
                          formControlName="circleTooltipFunction"
                          withModules
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-tooltip-function' | translate }}"
                          helpId="widget/lib/map-legacy/polygon_tooltip_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
        <fieldset class="fields-group">
          <legend class="group-title" translate>widgets.maps.circle-fill-color</legend>
          <section class="!flex flex-col gt-xs:flex-row gt-xs:gap-2">
            <tb-color-input
              class="flex-1"
              formControlName="circleFillColor"
              icon="format_color_fill"
              label="{{ 'widgets.maps.circle-fill-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <mat-form-field class="flex-1">
              <mat-label translate>widgets.maps.circle-fill-color-opacity</mat-label>
              <input matInput type="number" min="0" max="1" formControlName="circleFillColorOpacity">
            </mat-form-field>
          </section>
          <mat-expansion-panel class="tb-settings" [expanded]="circleSettingsFormGroup.get('useCircleFillColorFunction').value">
            <mat-expansion-panel-header class="flex-wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useCircleFillColorFunction" (click)="$event.stopPropagation()">
                  {{ 'widgets.maps.use-circle-fill-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="circleFillColorFunction"
                          withModules
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-fill-color-function' | translate }}"
                          helpId="widget/lib/map-legacy/polygon_color_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
        <fieldset class="fields-group">
          <legend class="group-title" translate>widgets.maps.circle-stroke</legend>
          <section class="!flex flex-col gt-xs:flex-row gt-xs:gap-2">
            <tb-color-input
              class="flex-1"
              formControlName="circleStrokeColor"
              icon="format_color_fill"
              label="{{ 'widgets.maps.stroke-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <mat-form-field class="flex-1">
              <mat-label translate>widgets.maps.stroke-opacity</mat-label>
              <input matInput type="number" min="0" max="1" formControlName="circleStrokeOpacity">
            </mat-form-field>
            <mat-form-field class="flex-1">
              <mat-label translate>widgets.maps.stroke-weight</mat-label>
              <input matInput type="number" min="0" formControlName="circleStrokeWeight">
            </mat-form-field>
          </section>
          <mat-expansion-panel class="tb-settings" [expanded]="circleSettingsFormGroup.get('useCircleStrokeColorFunction').value">
            <mat-expansion-panel-header class="flex-wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useCircleStrokeColorFunction" (click)="$event.stopPropagation()">
                  {{ 'widgets.maps.use-circle-stroke-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="circleStrokeColorFunction"
                          withModules
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-stroke-color-function' | translate }}"
                          helpId="widget/lib/map-legacy/polygon_color_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
</section>
