<!--

    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-details-buttons xs:flex xs:flex-col">
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'open')"
          [class.!hidden]="isEdit || isDetailsPage">
    {{'common.open-details-page' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'manageUsers')"
          [class.!hidden]="isEdit || isPublic">
    {{'customer.manage-users' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'manageAssets')"
          [class.!hidden]="isEdit">
    {{'customer.manage-assets' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'manageDevices')"
          [class.!hidden]="isEdit">
    {{'customer.manage-devices' | translate }}
  </button>
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'manageDashboards')"
          [class.!hidden]="isEdit">
    {{'customer.manage-dashboards' | translate }}
  </button>
  @if (edgesSupportEnabled()) {
    <button mat-raised-button color="primary"
            [disabled]="(isLoading$ | async)"
            (click)="onEntityAction($event, 'manageEdges')"
            [class.!hidden]="isEdit">
      {{'customer.manage-edges' | translate }}
    </button>
  }
  <button mat-raised-button color="primary"
          [disabled]="(isLoading$ | async)"
          (click)="onEntityAction($event, 'delete')"
          [class.!hidden]="hideDelete() || isEdit || isPublic">
    {{'customer.delete' | translate }}
  </button>
  <div class="flex flex-row xs:flex-col">
    <button mat-raised-button
            ngxClipboard
            (cbOnSuccess)="onCustomerIdCopied($event)"
            [cbContent]="entity?.id?.id"
            [class.!hidden]="isEdit">
      <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
      <span translate>customer.copyId</span>
    </button>
  </div>
</div>
<div class="mat-padding flex flex-col">
  <form [formGroup]="entityForm">
    <fieldset [class.!hidden]="isPublic" [disabled]="(isLoading$ | async) || !isEdit" style="min-width: 0;">
      <mat-form-field class="mat-block" appearance="outline">
        <mat-label translate>customer.title</mat-label>
        <input matInput formControlName="title" required/>
        @if (entityForm.get('title').hasError('required')) {
          <mat-error>{{ 'customer.title-required' | translate }}</mat-error>
        }
        @if (entityForm.get('title').hasError('maxlength')) {
          <mat-error>{{ 'customer.title-max-length' | translate }}</mat-error>
        }
      </mat-form-field>
      <tb-contact [parentForm]="entityForm" [isEdit]="isEdit"></tb-contact>
      <div formGroupName="additionalInfo" class="flex flex-col">
        @if (entity?.id) {
          <section class="tb-default-dashboard flex flex-1 flex-col">
            <section class="flex flex-1 flex-col gt-sm:flex-row">
              <tb-dashboard-autocomplete
                class="flex-1"
                label="{{ 'dashboard.home-dashboard' | translate }}"
                formControlName="homeDashboardId"
                appearance="outline"
                [dashboardsScope]="'customer'"
                [customerId]="entity?.id.id"
                [selectFirstDashboard]="false">
              </tb-dashboard-autocomplete>
              <mat-checkbox class="flex-1" formControlName="homeDashboardHideToolbar">
                {{ 'dashboard.home-dashboard-hide-toolbar' | translate }}
              </mat-checkbox>
            </section>
          </section>
        }
        <mat-form-field class="mat-block" appearance="outline">
          <mat-label translate>customer.description</mat-label>
          <textarea matInput formControlName="description" cdkTextareaAutosize cdkAutosizeMinRows="1" rows="1"></textarea>
        </mat-form-field>
      </div>
    </fieldset>
  </form>
</div>
