<!--

    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-font-settings-panel" [formGroup]="fontFormGroup">
  <div class="tb-font-settings-title" translate>widgets.widget-font.font-settings</div>
  <div class="tb-form-row no-border no-padding">
    <div class="fixed-title-width" translate>widgets.widget-font.size</div>
    @if (!autoScale) {
      <div class="flex flex-1 flex-row items-center justify-start gap-3">
        <mat-form-field appearance="outline" class="number flex-1" subscriptSizing="dynamic">
          <input matInput type="number" min="0" formControlName="size" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
        <tb-css-unit-select class="flex-1" formControlName="sizeUnit"></tb-css-unit-select>
      </div>
    }
    @if (autoScale) {
      <div class="tb-font-settings-auto" translate>widgets.widget-font.auto</div>
    }
  </div>
  <div class="tb-form-row no-border no-padding">
    <div class="fixed-title-width" translate>widgets.widget-font.font-family</div>
    <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
      <input matInput #familyInput
             formControlName="family" placeholder="{{ 'widget-config.set' | translate }}"
             [matAutocomplete]="familyAutocomplete">
      @if (fontFormGroup.get('family').value) {
        <button
          type="button"
          matSuffix mat-icon-button aria-label="Clear"
          (click)="clearFamily()">
          <mat-icon class="material-icons">close</mat-icon>
        </button>
      }
      <mat-autocomplete
        #familyAutocomplete="matAutocomplete"
        class="tb-autocomplete"
        panelWidth="fit-content">
        @for (family of filteredFontFamilies | async; track family) {
          <mat-option [value]="family">
            <span [innerHTML]="family | highlight:familySearchText:true:'ig'"></span>
          </mat-option>
        }
      </mat-autocomplete>
    </mat-form-field>
  </div>
  <div class="tb-form-row no-border no-padding">
    <div class="fixed-title-width" translate>widgets.widget-font.font-weight</div>
    <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
      <mat-select formControlName="weight" placeholder="{{ 'widget-config.set' | translate }}">
        <mat-option [value]="null">
        </mat-option>
        @for (weight of fontWeightsList; track weight) {
          <mat-option [value]="weight">
            {{ fontWeightTranslationsMap.has(weight) ? (fontWeightTranslationsMap.get(weight) | translate) : weight }}
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
  </div>
  <div class="tb-form-row no-border no-padding">
    <div class="fixed-title-width" translate>widgets.widget-font.font-style</div>
    <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
      <mat-select formControlName="style" placeholder="{{ 'widget-config.set' | translate }}">
        <mat-option [value]="null">
        </mat-option>
        @for (style of fontStylesList; track style) {
          <mat-option [value]="style">
            {{ fontStyleTranslationsMap.get(style) | translate }}
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
  </div>
  @if (!disabledLineHeight) {
    <div class="tb-form-row no-border no-padding">
      <div class="fixed-title-width" translate>widgets.widget-font.line-height</div>
      @if (!autoScale) {
        <mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
          <input matInput formControlName="lineHeight" placeholder="{{ 'widget-config.set' | translate }}">
        </mat-form-field>
      }
      @if (autoScale) {
        <div class="tb-font-settings-auto" translate>widgets.widget-font.auto</div>
      }
    </div>
  }
  <mat-divider></mat-divider>
  <div class="tb-form-row no-border no-padding font-preview">
    <div class="fixed-title-width" translate>widgets.widget-font.preview</div>
    <div class="preview-text flex-1" [style]="previewStyle" [innerHTML]="previewText | safe:'html'"></div>
  </div>
  <div class="tb-font-settings-panel-buttons">
    @if (clearButton) {
      <button
        mat-button
        type="button"
        (click)="clearFont()"
        [disabled]="clearDisabled()">
        {{ 'action.clear' | translate }}
      </button>
    }
    @if (clearButton) {
      <span class="flex-1"></span>
    }
    <button mat-button
            color="primary"
            type="button"
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button
            color="primary"
            type="button"
            (click)="applyFont()"
            [disabled]="fontFormGroup.invalid || !fontFormGroup.dirty">
      {{ 'action.apply' | translate }}
    </button>
  </div>
</div>
