<!--

    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.

-->
<ng-container [formGroup]="flotKeySettingsFormGroup">
  <div class="tb-form-panel">
    <mat-slide-toggle class="mat-slide" formControlName="hideDataByDefault">
      {{ 'widgets.chart.data-is-hidden-by-default' | translate }}
    </mat-slide-toggle>
    <mat-slide-toggle class="mat-slide" formControlName="disableDataHiding">
      {{ 'widgets.chart.disable-data-hiding' | translate }}
    </mat-slide-toggle>
    <mat-slide-toggle class="mat-slide" formControlName="removeFromLegend">
      {{ 'widgets.chart.remove-from-legend' | translate }}
    </mat-slide-toggle>
    <mat-slide-toggle class="mat-slide" formControlName="excludeFromStacking">
      {{ 'widgets.chart.exclude-from-stacking' | translate }}
    </mat-slide-toggle>
  </div>
  <div class="tb-form-panel tb-slide-toggle">
    <mat-expansion-panel class="tb-settings" [expanded]="flotKeySettingsFormGroup.get('showLines').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle class="mat-slide" formControlName="showLines" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.chart.show-line' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxFlex="40" fxLayoutAlign="end center" fxHide.xs translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row space-between">
          <div>{{ 'widgets.chart.line-width' | translate }}</div>
          <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
            <input matInput formControlName="lineWidth" type="number" min="0" placeholder="{{ 'widget-config.set' | translate }}">
            <span matSuffix>px</span>
          </mat-form-field>
        </div>
        <mat-slide-toggle class="mat-slide" formControlName="fillLines">
          {{ 'widgets.chart.fill-line' | translate }}
        </mat-slide-toggle>
        <div [fxShow]="flotKeySettingsFormGroup.get('fillLines').value" class="tb-form-row space-between">
          <div>{{ 'widgets.chart.fill-line-opacity' | translate }}</div>
          <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
            <input matInput formControlName="fillLinesOpacity" type="number" min="0" max="1" step="0.1" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
      </ng-template>
    </mat-expansion-panel>
  </div>
  <div class="tb-form-panel tb-slide-toggle">
    <mat-expansion-panel class="tb-settings" [expanded]="flotKeySettingsFormGroup.get('showPoints').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle class="mat-slide" formControlName="showPoints" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.chart.show-points' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
        <mat-panel-description fxFlex="40" fxLayoutAlign="end center" fxHide.xs translate>
          widget-config.advanced-settings
        </mat-panel-description>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row space-between">
          <div>{{ 'widgets.chart.points-line-width' | translate }}</div>
          <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
            <input matInput formControlName="showPointsLineWidth" type="number" min="0" placeholder="{{ 'widget-config.set' | translate }}">
            <span matSuffix>px</span>
          </mat-form-field>
        </div>
        <div class="tb-form-row space-between">
          <div>{{ 'widgets.chart.points-radius' | translate }}</div>
          <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
            <input matInput formControlName="showPointsRadius" type="number" min="0" placeholder="{{ 'widget-config.set' | translate }}">
            <span matSuffix>px</span>
          </mat-form-field>
        </div>
        <div class="tb-form-row space-between">
          <div>{{ 'widgets.chart.point-shape' | translate }}</div>
          <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="showPointShape">
              <mat-option [value]="'circle'">
                {{ 'widgets.chart.point-shape-circle' | translate }}
              </mat-option>
              <mat-option [value]="'cross'">
                {{ 'widgets.chart.point-shape-cross' | translate }}
              </mat-option>
              <mat-option [value]="'diamond'">
                {{ 'widgets.chart.point-shape-diamond' | translate }}
              </mat-option>
              <mat-option [value]="'square'">
                {{ 'widgets.chart.point-shape-square' | translate }}
              </mat-option>
              <mat-option [value]="'triangle'">
                {{ 'widgets.chart.point-shape-triangle' | translate }}
              </mat-option>
              <mat-option [value]="'custom'">
                {{ 'widgets.chart.point-shape-custom' | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
        </div>
        <tb-js-func [fxShow]="flotKeySettingsFormGroup.get('showPointShape').value === 'custom'"
                    formControlName="pointShapeFormatter"
                    [globalVariables]="functionScopeVariables"
                    [functionArgs]="['ctx', 'x', 'y', 'radius', 'shadow']"
                    functionTitle="{{ 'widgets.chart.point-shape-draw-function' | translate }}"
                    helpId="widget/lib/flot/point_shape_format_fn">
        </tb-js-func>
      </ng-template>
    </mat-expansion-panel>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.chart.tooltip-settings</div>
    <tb-js-func
      formControlName="tooltipValueFormatter"
      [globalVariables]="functionScopeVariables"
      [functionArgs]="['value', 'latestData']"
      functionTitle="{{ 'widgets.chart.tooltip-value-format-function' | translate }}"
      helpId="widget/lib/flot/tooltip_value_format_fn">
    </tb-js-func>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.chart.vertical-axis</div>
    <mat-slide-toggle class="mat-slide" formControlName="showSeparateAxis">
      {{ 'widgets.chart.show-separate-axis' | translate }}
    </mat-slide-toggle>
    <div class="tb-form-row">
      <div class="fixed-title-width" translate>widgets.chart.axis-title</div>
      <mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic">
        <input matInput formControlName="axisTitle" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div translate>widgets.chart.min-scale-value</div>
      <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
        <input matInput formControlName="axisMin" type="number" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div translate>widgets.chart.max-scale-value</div>
      <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
        <input matInput formControlName="axisMax" type="number" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.chart.axis-position' | translate }}</div>
      <mat-form-field appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="axisPosition">
          <mat-option [value]="'left'">
            {{ 'widgets.chart.axis-position-left' | translate }}
          </mat-option>
          <mat-option [value]="'right'">
            {{ 'widgets.chart.axis-position-right' | translate }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </div>
    <div class="tb-form-panel stroked">
      <div class="tb-form-panel-title" translate>widgets.chart.ticks</div>
      <div class="tb-form-row space-between">
        <div translate>widget-config.decimals-short</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="axisTickDecimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between">
        <div translate>widgets.chart.tick-step-size</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="axisTickSize" type="number" min="0" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
      </div>
      <tb-js-func
        formControlName="axisTicksFormatter"
        [globalVariables]="functionScopeVariables"
        [functionArgs]="['value']"
        functionTitle="{{ 'widgets.chart.ticks-formatter-function' | translate }}"
        helpId="widget/lib/flot/ticks_formatter_fn">
      </tb-js-func>
    </div>
  </div>
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" fxLayout="row" fxLayoutAlign="space-between center">
      <div translate>widgets.chart.thresholds</div>
      <button mat-stroked-button
              color="primary"
              type="button" (click)="addThreshold()">
        <span translate>widgets.chart.add-threshold</span>
      </button>
    </div>
    <div *ngIf="thresholdsFormArray().length" class="tb-control-list tb-drop-list" cdkDropList cdkDropListOrientation="vertical"
         (cdkDropListDropped)="thresholdDrop($event)" fxLayout="column" fxLayoutGap="12px">
      <div cdkDrag class="tb-draggable" *ngFor="let thresholdControl of thresholdsFormArray().controls; trackBy: trackByThreshold;
                 let $index = index;">
        <tb-flot-threshold [formControl]="thresholdControl"
                           [expanded]="thresholdControl.new"
                           [aliasController]="aliasController"
                           (removeThreshold)="removeThreshold($index)">
        </tb-flot-threshold>
      </div>
    </div>
  </div>
  <div class="tb-form-panel tb-slide-toggle" formGroupName="comparisonSettings">
    <div class="tb-form-panel-title" translate>widgets.chart.comparison-settings</div>
    <mat-expansion-panel class="tb-settings" [expanded]="flotKeySettingsFormGroup.get('comparisonSettings.showValuesForComparison').value"
                         [disabled]="!flotKeySettingsFormGroup.get('comparisonSettings.showValuesForComparison').value">
      <mat-expansion-panel-header fxLayout="row wrap">
        <mat-panel-title>
          <mat-slide-toggle class="mat-slide" formControlName="showValuesForComparison" (click)="$event.stopPropagation()"
                            fxLayoutAlign="center">
            {{ 'widgets.chart.show-values-for-comparison' | translate }}
          </mat-slide-toggle>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div class="tb-form-row">
          <div class="fixed-title-width" translate>widgets.chart.comparison-values-label</div>
          <mat-form-field fxFlex appearance="outline" subscriptSizing="dynamic">
            <input matInput formControlName="comparisonValuesLabel" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
        <div class="tb-form-row space-between">
          <div>{{ 'widgets.chart.comparison-line-color' | translate }}</div>
          <tb-color-input asBoxInput
                          formControlName="color">
          </tb-color-input>
        </div>
      </ng-template>
    </mat-expansion-panel>
  </div>
</ng-container>
