<!--

    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="gpio-item flex-1" [formGroup]="gpioItemFormGroup" [(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">
          <div>
            <span>{{ gpioItemFormGroup.value.label || 'Undefined' }} (</span><small>pin:</small>
            <span>{{ numberText(gpioItemFormGroup.value.pin, 0) }}) - [</span><small>row:</small>
            <span>{{ numberText(gpioItemFormGroup.value.row, -1) }}) - [</span><small>col:</small>
            <span>{{ numberText(gpioItemFormGroup.value.col, -1) }}]</span>
          </div>
          @if (hasColor) {
            <div class="tb-color-preview" style="margin-left: 6px;">
              <div class="tb-color-result" [style.background]="gpioItemFormGroup.get('color').value"></div>
            </div>
          }
        </div>
      </mat-panel-title>
      <span class="flex-1"></span>
      @if (!disabled) {
        <button mat-icon-button style="min-width: 40px;"
                type="button"
                (click)="removeGpioItem.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">
        <section class="flex flex-row xs:flex-col gt-xs:gap-2 gt-xs:items-center gt-xs:justify-start">
          <mat-form-field class="mat-block flex=1" appearance="outline">
            <mat-label translate>widgets.gpio.pin</mat-label>
            <input required matInput type="number" min="1" step="1" formControlName="pin">
          </mat-form-field>
          <mat-form-field class="mat-block flex-1" appearance="outline">
            <mat-label translate>widgets.gpio.label</mat-label>
            <input required matInput formControlName="label">
          </mat-form-field>
        </section>
        <section class="flex flex-row xs:flex-col gt-xs:gap-2 gt-xs:items-center gt-xs:justify-start">
          <mat-form-field class="mat-block flex-1" appearance="outline">
            <mat-label translate>widgets.gpio.row</mat-label>
            <input required matInput type="number" min="0" step="1" formControlName="row">
          </mat-form-field>
          <mat-form-field class="mat-block flex-1" appearance="outline">
            <mat-label translate>widgets.gpio.column</mat-label>
            <input required matInput type="number" min="0" max="1" step="1" formControlName="col">
          </mat-form-field>
        </section>
        @if (hasColor) {
          <tb-color-input
            required
            appearance="outline"
            formControlName="color"
            icon="format_color_fill"
            label="{{ 'widgets.gpio.color' | translate }}" openOnInput colorClearButton>
          </tb-color-input>
        }
      </section>
    </div>
  </ng-template>
</mat-expansion-panel>
