<!--

    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.

-->
<mat-expansion-panel class="label-widget-label flex-1" [formGroup]="labelWidgetLabelFormGroup" [(expanded)]="expanded">
  <mat-expansion-panel-header>
    <div class="flex flex-1 flex-row items-center justify-start">
      <mat-panel-title>
        <div class="flex flex-1 flex-row items-center justify-start">
          {{ labelWidgetLabelFormGroup.get('pattern').value }}
        </div>
      </mat-panel-title>
      <span class="flex-1"></span>
      @if (!disabled) {
        <button mat-icon-button style="min-width: 40px;"
                type="button"
                (click)="removeLabel.emit()"
                matTooltip="{{ 'action.remove' | translate }}"
                matTooltipPosition="above">
          <mat-icon>delete</mat-icon>
        </button>
      }
    </div>
  </mat-expansion-panel-header>
  <ng-template matExpansionPanelContent>
    <div class="flex flex-col gap-2">
      <mat-divider></mat-divider>
      <section class="tb-widget-settings flex flex-col">
        <mat-form-field style="padding-bottom: 16px;" appearance="outline">
          <mat-label translate>widgets.label-widget.label-pattern</mat-label>
          <input required matInput formControlName="pattern">
          @if (labelWidgetLabelFormGroup.get('pattern').hasError('required')) {
            <mat-error>
              {{ 'widgets.label-widget.label-pattern-required' | translate }}
            </mat-error>
          }
          <mat-hint [innerHTML]="'widgets.label-widget.label-pattern-hint' | translate | safe: 'html'"></mat-hint>
        </mat-form-field>
        <fieldset class="fields-group">
          <legend class="group-title" translate>widgets.label-widget.label-position</legend>
          <section class="flex flex-row xs:flex-col gt-xs:gap-2 mt-2">
            <mat-form-field class="flex-1" appearance="outline">
              <mat-label translate>widgets.label-widget.x-pos</mat-label>
              <input matInput type="number" min="0" max="100" formControlName="x">
            </mat-form-field>
            <mat-form-field class="flex-1" appearance="outline">
              <mat-label translate>widgets.label-widget.y-pos</mat-label>
              <input matInput type="number" min="0" max="100" formControlName="y">
            </mat-form-field>
          </section>
        </fieldset>
        <tb-color-input
          formControlName="backgroundColor"
          appearance="outline"
          icon="format_color_fill"
          label="{{ 'widgets.label-widget.background-color' | translate }}" openOnInput colorClearButton>
        </tb-color-input>
        <fieldset class="fields-group">
          <legend class="group-title" translate>widgets.label-widget.font-settings</legend>
          <tb-widget-font formControlName="font" sizeTitle="widgets.widget-font.relative-font-size"></tb-widget-font>
        </fieldset>
      </section>
    </div>
  </ng-template>
</mat-expansion-panel>
