<!--

    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]="doughnutWidgetSettingsForm">
  <div class="tb-form-panel">
    <div class="tb-form-panel-title" translate>widgets.doughnut.doughnut-card-style</div>
    <tb-image-cards-select rowHeight="{{ horizontal ? '8:5' : '5:4' }}"
                           [cols]="{columns: 2,
                                    breakpoints: {
                                      'lt-sm': 1
                                    }}"
                           label="{{ 'widgets.doughnut.layout' | translate }}" formControlName="layout">
      <tb-image-cards-select-option *ngFor="let layout of doughnutLayouts"
                                    [value]="layout"
                                    [image]="doughnutLayoutImageMap.get(layout)">
        {{ doughnutLayoutTranslationMap.get(layout) | translate }}
      </tb-image-cards-select-option>
    </tb-image-cards-select>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="autoScale">
        {{ 'widgets.doughnut.auto-scale' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="clockwise">
        {{ 'widgets.doughnut.clockwise-layout' | translate }}
      </mat-slide-toggle>
    </div>
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="sortSeries">
        {{ 'widgets.doughnut.sort-series' | translate }}
      </mat-slide-toggle>
    </div>
    <div [fxShow]="totalEnabled" class="tb-form-row space-between">
      <div>{{ 'widgets.doughnut.central-total-value' | translate }}</div>
      <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
        <tb-font-settings formControlName="totalValueFont"
                          [previewText]="valuePreviewFn">
        </tb-font-settings>
        <tb-color-settings formControlName="totalValueColor" settingsKey="{{'widgets.doughnut.central-total-value' | translate }}">
        </tb-color-settings>
      </div>
    </div>
    <div class="tb-form-panel tb-slide-toggle">
      <mat-expansion-panel class="tb-settings" [expanded]="doughnutWidgetSettingsForm.get('showLegend').value" [disabled]="!doughnutWidgetSettingsForm.get('showLegend').value">
        <mat-expansion-panel-header fxLayout="row wrap">
          <mat-panel-title>
            <mat-slide-toggle class="mat-slide" formControlName="showLegend" (click)="$event.stopPropagation()"
                              fxLayoutAlign="center">
              {{ 'widget-config.legend' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <div class="tb-form-row space-between">
            <div>{{ 'legend.position' | translate }}</div>
            <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
              <mat-select formControlName="legendPosition">
                <mat-option *ngFor="let pos of doughnutLegendPositions" [value]="pos">
                  {{ doughnutLegendPositionTranslationMap.get(pos) | translate }}
                </mat-option>
              </mat-select>
            </mat-form-field>
          </div>
          <div class="tb-form-row space-between">
            <div>{{ 'widgets.doughnut.legend-label' | translate }}</div>
            <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
              <tb-font-settings formControlName="legendLabelFont"
                                previewText="Wind power">
              </tb-font-settings>
              <tb-color-input asBoxInput
                              colorClearButton
                              formControlName="legendLabelColor">
              </tb-color-input>
            </div>
          </div>
          <div class="tb-form-row space-between">
            <div>{{ 'widgets.doughnut.legend-value' | translate }}</div>
            <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
              <tb-font-settings formControlName="legendValueFont"
                                [previewText]="valuePreviewFn">
              </tb-font-settings>
              <tb-color-input asBoxInput
                              colorClearButton
                              formControlName="legendValueColor">
              </tb-color-input>
            </div>
          </div>
        </ng-template>
      </mat-expansion-panel>
    </div>
    <div class="tb-form-panel tb-slide-toggle">
      <mat-expansion-panel class="tb-settings" [expanded]="doughnutWidgetSettingsForm.get('showTooltip').value" [disabled]="!doughnutWidgetSettingsForm.get('showTooltip').value">
        <mat-expansion-panel-header fxLayout="row wrap">
          <mat-panel-title>
            <mat-slide-toggle class="mat-slide" formControlName="showTooltip" (click)="$event.stopPropagation()"
                              fxLayoutAlign="center">
              {{ 'widgets.doughnut.tooltip' | translate }}
            </mat-slide-toggle>
          </mat-panel-title>
        </mat-expansion-panel-header>
        <ng-template matExpansionPanelContent>
          <div class="tb-form-row space-between column-xs">
            <div>{{ 'widgets.doughnut.tooltip-value' | translate }}</div>
            <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
              <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
                <mat-select formControlName="tooltipValueType">
                  <mat-option *ngFor="let type of doughnutTooltipValueTypes" [value]="type">
                    {{ doughnutTooltipValueTypeTranslationMap.get(type) | translate }}
                  </mat-option>
                </mat-select>
              </mat-form-field>
              <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
                <input matInput formControlName="tooltipValueDecimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}">
                <div matSuffix fxHide.lt-md translate>widget-config.decimals-suffix</div>
              </mat-form-field>
              <tb-font-settings formControlName="tooltipValueFont"
                                [previewText]="tooltipValuePreviewFn">
              </tb-font-settings>
              <tb-color-input asBoxInput
                              colorClearButton
                              formControlName="tooltipValueColor">
              </tb-color-input>
            </div>
          </div>
          <div class="tb-form-row space-between">
            <div>{{ 'widgets.doughnut.tooltip-background-color' | translate }}</div>
            <tb-color-input asBoxInput
                            colorClearButton
                            formControlName="tooltipBackgroundColor">
            </tb-color-input>
          </div>
          <div class="tb-form-row space-between">
            <div>{{ 'widgets.doughnut.tooltip-background-blur' | translate }}</div>
            <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
              <input matInput formControlName="tooltipBackgroundBlur" type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
              <div matSuffix>px</div>
            </mat-form-field>
          </div>
        </ng-template>
      </mat-expansion-panel>
    </div>
    <div class="tb-form-row space-between">
      <div>{{ 'widgets.background.background' | translate }}</div>
      <tb-background-settings formControlName="background">
      </tb-background-settings>
    </div>
  </div>
</ng-container>
