<!--

    Copyright © 2016-2023 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-details-buttons">
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'open')"
          [fxShow]="!isEdit">
    {{'rulechain.open-rulechain' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'export')"
          [fxShow]="!isEdit">
    {{'rulechain.export' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'setRoot')"
          [fxShow]="!isEdit && ((!entity?.root && ruleChainScope === 'tenant') || (!isEdgeRootRuleChain() && ruleChainScope === 'edge'))">
    {{'rulechain.set-root' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'setEdgeTemplateRoot')"
          [fxShow]="!isEdit && !entity?.root && ruleChainScope === 'edges'">
    {{'rulechain.set-edge-template-root-rulechain' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'setAutoAssignToEdge')"
          [fxShow]="!isEdit && isNotAutoAssignToEdgeRuleChain() && ruleChainScope === 'edges'">
    {{'rulechain.set-auto-assign-to-edge' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'unsetAutoAssignToEdge')"
          [fxShow]="!isEdit && isAutoAssignToEdgeRuleChain() && ruleChainScope === 'edges'">
    {{'rulechain.unset-auto-assign-to-edge' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'unassignFromEdge')"
          [fxShow]="!isEdit && !isEdgeRootRuleChain() && ruleChainScope === 'edge'">
    {{'edge.unassign-from-edge' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'delete')"
          [fxShow]="!hideDelete() && !isEdit && ruleChainScope !== 'edge'">
    {{'rulechain.delete' | translate }}
  </button>
  <div fxLayout="row">
    <button mat-raised-button
            ngxClipboard
            (cbOnSuccess)="onRuleChainIdCopied($event)"
            [cbContent]="entity?.id?.id"
            [fxShow]="!isEdit">
      <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
      <span translate>rulechain.copyId</span>
    </button>
  </div>
</div>
<div class="mat-padding" fxLayout="column">
  <form [formGroup]="entityForm">
    <fieldset [disabled]="(isLoading$ | async) || !isEdit">
      <mat-form-field class="mat-block">
        <mat-label translate>rulechain.name</mat-label>
        <input matInput formControlName="name" required>
        <mat-error *ngIf="entityForm.get('name').hasError('required')">
          {{ 'rulechain.name-required' | translate }}
        </mat-error>
        <mat-error *ngIf="entityForm.get('name').hasError('maxlength')">
          {{ 'rulechain.name-max-length' | translate }}
        </mat-error>
      </mat-form-field>
      <mat-checkbox fxFlex formControlName="debugMode" style="padding-bottom: 16px;">
        {{ 'rulechain.debug-mode' | translate }}
      </mat-checkbox>
      <div formGroupName="additionalInfo">
        <mat-form-field class="mat-block">
          <mat-label translate>rulechain.description</mat-label>
          <textarea matInput formControlName="description" rows="2"></textarea>
        </mat-form-field>
      </div>
    </fieldset>
  </form>
</div>
