<!--

    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 tb-slide-toggle stroked" [formGroup]="actionButtonConfigForm">
  <mat-expansion-panel class="tb-settings"
                       [expanded]="actionButtonConfigForm.get('enabled').value">
    <mat-expansion-panel-header class="fill-width flex flex-row flex-wrap">
      <mat-panel-title class="max-w-60% flex-full">
        <div tb-hint-tooltip-icon="{{ sliderHint }}" class="tb-form-row no-border no-padding">
          <mat-slide-toggle class="mat-slide flex items-stretch justify-center" formControlName="enabled" (click)="$event.stopPropagation()">
            {{ actionTitle }}
          </mat-slide-toggle>
        </div>
      </mat-panel-title>
    </mat-expansion-panel-header>
    <ng-template matExpansionPanelContent class="tb-extension-panel">
      <div class="flex flex-row xs:flex-col gt-xs:gap-2">
        @if (!hideButtonText) {
          <mat-form-field class="mat-block flex-1" appearance="outline">
            <mat-label translate>notification.button-text</mat-label>
            <input matInput formControlName="text" required>
            @if (actionButtonConfigForm.get('text').hasError('required')) {
              <mat-error>{{ 'notification.button-text-required' | translate }}</mat-error>
            }
            @if (actionButtonConfigForm.get('text').hasError('maxlength')) {
              <mat-error>{{ 'notification.button-text-max-length' | translate :
                {length: actionButtonConfigForm.get('text').getError('maxlength').requiredLength}
                }}</mat-error>
            }
          </mat-form-field>
        }
      </div>
      <div class="grid gt-sm:grid-cols-3 gt-sm:gap-4">
        <mat-form-field class="mat-block" appearance="outline">
          <mat-label translate>notification.action-type</mat-label>
          <mat-select formControlName="linkType">
            @for (actionButtonLinkType of actionButtonLinkTypes; track actionButtonLinkType) {
              <mat-option [value]="actionButtonLinkType">
                {{ actionButtonLinkTypeTranslateMap.get(actionButtonLinkType) | translate }}
              </mat-option>
            }
          </mat-select>
        </mat-form-field>
        @if (actionButtonConfigForm.get('linkType').value === actionButtonLinkType.LINK) {
          <mat-form-field class="gt-sm:col-span-2" appearance="outline">
            <mat-label translate>notification.link</mat-label>
            <input matInput formControlName="link" required>
            @if (actionButtonConfigForm.get('link').hasError('required')) {
              <mat-error>{{ 'notification.link-required' | translate }}</mat-error>
            }
            @if (actionButtonConfigForm.get('link').hasError('maxlength')) {
              <mat-error>{{ 'notification.link-max-length' | translate :
                {length: actionButtonConfigForm.get('link').getError('maxlength').requiredLength}
                }}</mat-error>
            }
          </mat-form-field>
        } @else {
          <tb-dashboard-autocomplete
            required
            appearance="outline"
            formControlName="dashboardId">
          </tb-dashboard-autocomplete>
          <tb-dashboard-state-autocomplete
            appearance="outline"
            [dashboardId]="actionButtonConfigForm.get('dashboardId').value"
            formControlName="dashboardState">
          </tb-dashboard-state-autocomplete>
        }
      </div>
      @if (actionButtonConfigForm.get('linkType').value === actionButtonLinkType.DASHBOARD) {
        <mat-slide-toggle formControlName="setEntityIdInState" class="toggle">
          {{ 'notification.set-entity-from-notification' | translate }}
        </mat-slide-toggle>
      }
    </ng-template>
  </mat-expansion-panel>
</div>
