<!--

    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]="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 fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle formControlName="showCircle" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.maps.show-circle' | 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-datasources-key-autocomplete fxFlex
                                         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 fxLayout="row wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="showCircleLabel" (click)="$event.stopPropagation()"
                                  fxLayoutAlign="center">
                  {{ 'widgets.maps.show-circle-label' | 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="useCircleLabelFunction" class="slide-block">
                {{ 'widgets.maps.use-circle-label-function' | translate }}
              </mat-slide-toggle>
              <tb-html [fxShow]="!circleSettingsFormGroup.get('useCircleLabelFunction').value"
                       formControlName="circleLabel"
                       minHeight="100px"
                       label="{{ 'widgets.maps.circle-label-pattern' | translate }}">
              </tb-html>
              <tb-js-func [fxShow]="circleSettingsFormGroup.get('useCircleLabelFunction').value"
                          formControlName="circleLabelFunction"
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-label-function' | translate }}"
                          helpId="widget/lib/map/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 fxLayout="row wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="showCircleTooltip" (click)="$event.stopPropagation()"
                                  fxLayoutAlign="center">
                  {{ 'widgets.maps.show-circle-tooltip' | 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-form-field fxFlex class="mat-block">
                <mat-label translate>widgets.maps.show-tooltip-action</mat-label>
                <mat-select required formControlName="showCircleTooltipAction">
                  <mat-option *ngFor="let action of showTooltipActions" [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 [fxShow]="!circleSettingsFormGroup.get('useCircleTooltipFunction').value"
                       formControlName="circleTooltipPattern"
                       minHeight="100px"
                       label="{{ 'widgets.maps.circle-tooltip-pattern' | translate }}">
              </tb-html>
              <tb-js-func [fxShow]="circleSettingsFormGroup.get('useCircleTooltipFunction').value"
                          formControlName="circleTooltipFunction"
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-tooltip-function' | translate }}"
                          helpId="widget/lib/map/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 fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px">
            <tb-color-input
              fxFlex
              formControlName="circleFillColor"
              icon="format_color_fill"
              label="{{ 'widgets.maps.circle-fill-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <mat-form-field fxFlex class="mat-block">
              <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 fxLayout="row wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useCircleFillColorFunction" (click)="$event.stopPropagation()"
                                  fxLayoutAlign="center">
                  {{ 'widgets.maps.use-circle-fill-color-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="circleFillColorFunction"
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-fill-color-function' | translate }}"
                          helpId="widget/lib/map/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 fxLayout="column" fxLayout.gt-xs="row" fxLayoutGap.gt-xs="8px">
            <tb-color-input
              fxFlex
              formControlName="circleStrokeColor"
              icon="format_color_fill"
              label="{{ 'widgets.maps.stroke-color' | translate }}" openOnInput colorClearButton>
            </tb-color-input>
            <mat-form-field fxFlex class="mat-block">
              <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 fxFlex class="mat-block">
              <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 fxLayout="row wrap">
              <mat-panel-title>
                <mat-slide-toggle formControlName="useCircleStrokeColorFunction" (click)="$event.stopPropagation()"
                                  fxLayoutAlign="center">
                  {{ 'widgets.maps.use-circle-stroke-color-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="circleStrokeColorFunction"
                          [globalVariables]="functionScopeVariables"
                          [functionArgs]="['data', 'dsData', 'dsIndex']"
                          functionTitle="{{ 'widgets.maps.circle-stroke-color-function' | translate }}"
                          helpId="widget/lib/map/polygon_color_fn">
              </tb-js-func>
            </ng-template>
          </mat-expansion-panel>
        </fieldset>
      </ng-template>
    </mat-expansion-panel>
  </fieldset>
</section>
