<!--

    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.

-->
<div class="tb-form-panel no-padding no-border" [formGroup]="appearanceFormGroup">
  <tb-image-cards-select rowHeight="3:1"
                         [cols]="{columns:  2,
                                    breakpoints: {
                                      'lt-sm': 1
                                    }}"
    label="{{ 'widgets.button.layout' | translate }}" formControlName="type">
    @for (type of widgetButtonTypes; track type) {
      <tb-image-cards-select-option
        [value]="type"
        [image]="widgetButtonTypeImageMap.get(type)">
        {{ widgetButtonTypeTranslationMap.get(type) | translate }}
      </tb-image-cards-select-option>
    }
  </tb-image-cards-select>
  @if (withAutoScale) {
    <div class="tb-form-row">
      <mat-slide-toggle class="mat-slide" formControlName="autoScale">
        {{ 'widgets.button.auto-scale' | translate }}
      </mat-slide-toggle>
    </div>
  }
  <div class="tb-form-row">
    <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showLabel">
      {{ 'widgets.button.label' | translate }}
    </mat-slide-toggle>
    <tb-string-pattern-autocomplete class="flex-1"
                                    appearance="outline"
                                    brackets="curly"
                                    subscriptSizing="dynamic"
                                    predefinedValuesButton="true"
                                    [disabled]="!appearanceFormGroup.get('showLabel').value"
                                    [predefinedValues]="predefinedValues"
                                    placeholderText="{{ 'widget-config.set' | translate }}"
                                    formControlName="label"
    ></tb-string-pattern-autocomplete>
  </div>
  <div class="tb-form-row">
    <mat-slide-toggle class="mat-slide fixed-title-width" formControlName="showIcon">
      {{ 'widgets.button.icon' | translate }}
    </mat-slide-toggle>
    <div class="flex flex-1 flex-row items-center justify-start gap-2">
      <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
        <input matInput type="number" min="0" formControlName="iconSize" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
      <tb-css-unit-select class="flex-1" formControlName="iconSizeUnit"></tb-css-unit-select>
      <tb-material-icon-select asBoxInput
                               iconClearButton
                               formControlName="icon">
      </tb-material-icon-select>
    </div>
  </div>
  @if (withBorderRadius) {
    <div class="tb-form-row">
      <div class="fixed-title-width">{{ 'widgets.button.border-radius' | translate }}</div>
      <tb-css-size-input flex formControlName="borderRadius"></tb-css-size-input>
    </div>
  }
  <div class="tb-form-row space-between column-xs">
    <div>{{ 'widgets.button.color-palette' | translate }}</div>
    <div class="flex flex-row items-center justify-start gap-3">
      <div class="flex flex-row items-center justify-start gap-2">
        <div translate>widgets.button.main</div>
        <tb-color-input asBoxInput
                        formControlName="mainColor">
        </tb-color-input>
      </div>
      <mat-divider vertical></mat-divider>
      <div class="flex flex-row items-center justify-start gap-2">
        <div translate>widgets.button.background</div>
        <tb-color-input asBoxInput
                        formControlName="backgroundColor">
        </tb-color-input>
      </div>
    </div>
  </div>
  <div class="tb-form-panel stroked" formGroupName="customStyle">
    <mat-expansion-panel class="tb-settings">
      <mat-expansion-panel-header class="flex flex-row flex-wrap">
        <mat-panel-title>
          <div class="tb-form-panel-title" translate>widgets.button.custom-styles</div>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        @for (state of widgetButtonStates; track state) {
          <div class="tb-form-row space-between">
            <div>{{ widgetButtonStateTranslationMap.get(state) | translate }}</div>
            <tb-widget-button-custom-style
              [state]="state"
              [appearance]="appearanceFormGroup.value"
              [borderRadius]="borderRadius"
              [autoScale]="autoScale"
              [formControlName]="state">
            </tb-widget-button-custom-style>
          </div>
        }
      </ng-template>
    </mat-expansion-panel>
  </div>
</div>
