<!--

    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.

-->
@if (entity) {
  <mat-tab #transportType="matTab" label="{{ 'device-profile.transport-configuration' | translate }}">
    @if (transportType.isActive) {
      <div class="mat-padding" [formGroup]="detailsForm">
        <mat-form-field class="mat-block" appearance="outline">
          <mat-label translate>device-profile.transport-type</mat-label>
          <mat-select formControlName="transportType" required>
            @for (type of deviceTransportTypes; track type) {
              <mat-option [value]="type">
                {{deviceTransportTypeTranslations.get(type) | translate}}
              </mat-option>
            }
          </mat-select>
          @if (detailsForm.get('transportType').value) {
            <mat-hint>
              {{deviceTransportTypeHints.get(detailsForm.get('transportType').value) | translate}}
            </mat-hint>
          }
          @if (detailsForm.get('transportType').hasError('required')) {
            <mat-error>
              {{ 'device-profile.transport-type-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
        <div formGroupName="profileData">
          <tb-device-profile-transport-configuration
            formControlName="transportConfiguration"
            [isAdd]="isTransportTypeChanged">
          </tb-device-profile-transport-configuration>
        </div>
      </div>
    }
  </mat-tab>
  @if (authUser.authority === authorities.TENANT_ADMIN && !isEdit) {
    <mat-tab label="{{ 'entity.type-calculated-fields' | translate }}" #calculatedFieldsTab="matTab">
      <tb-calculated-fields-table [active]="calculatedFieldsTab.isActive" [entityId]="entity.id" [entityName]="entity.name" [ownerId]="entity.tenantId"/>
    </mat-tab>
  }

  @if (hasOldRules || authUser.authority === authorities.TENANT_ADMIN && !isEdit) {
    <mat-tab #alarmRules="matTab" label="{{'alarm-rule.alarm-rules-tab' | translate }}">
      <section class="flex flex-col h-full">
        @if (hasOldRules && !isEdit) {
          <div class="flex flex-row items-center justify-start" style="padding: 16px 16px 0;">
            <tb-toggle-select [(ngModel)]="alarmRulesOldVersion" appearance="fill">
              <tb-toggle-option [value]="false">{{ 'alarm-rule.alarm-rules-actual' | translate }}</tb-toggle-option>
              <tb-toggle-option [value]="true">{{ 'alarm-rule.alarm-rules-old' | translate }}</tb-toggle-option>
            </tb-toggle-select>
          </div>
        }
        @if (alarmRulesOldVersion || isEdit) {
          @if (alarmRules.isActive) {
            <div class="mat-padding" [formGroup]="detailsForm">
              <div formGroupName="profileData">
                <tb-device-profile-alarms formControlName="alarms" [deviceProfileId]="entity.id"></tb-device-profile-alarms>
              </div>
            </div>
          }
        } @else {
          <div class="relative h-full">
            <tb-alarm-rules-table [active]="alarmRules.isActive"
                                  [entityId]="entity.id"
                                  [entityName]="entity.name"
                                  [ownerId]="entity.tenantId">
            </tb-alarm-rules-table>
          </div>
        }
      </section>
    </mat-tab>
  }

  <mat-tab #deviceProvisioning="matTab" label="{{ 'device-profile.device-provisioning' | translate }}">
    @if (deviceProvisioning.isActive) {
      <div class="mat-padding" [formGroup]="detailsForm">
        <div formGroupName="profileData">
          <tb-device-profile-provision-configuration formControlName="provisionConfiguration">
          </tb-device-profile-provision-configuration>
        </div>
      </div>
    }
  </mat-tab>
  @if (!isEdit) {
    <mat-tab #auditLogsTab="matTab" label="{{ 'audit-log.audit-logs' | translate }}">
      <tb-audit-log-table detailsMode="true" [active]="auditLogsTab.isActive" [auditLogMode]="auditLogModes.ENTITY" [entityId]="entity.id"></tb-audit-log-table>
    </mat-tab>
  }
  @if (authUser.authority === authorities.TENANT_ADMIN && !isEdit) {
    <mat-tab label="{{ 'version-control.version-control' | translate }}" #versionControlTab="matTab">
      <tb-version-control detailsMode="true" singleEntityMode="true"
                          (versionRestored)="entitiesTableConfig.updateData()"
                          [active]="versionControlTab.isActive"
                          [entityId]="entity.id"
                          [entityName]="entity.name"
                          [externalEntityId]="entity.externalId || entity.id">
      </tb-version-control>
    </mat-tab>
  }
}
@if (false) {
  <mat-tab
    label="{{'device-profile.profile-configuration' | translate }}" #deviceProfile="matTab">
    <div class="mat-padding" [formGroup]="detailsForm">
      <div formGroupName="profileData">
        <tb-device-profile-configuration
          formControlName="configuration">
        </tb-device-profile-configuration>
      </div>
    </div>
  </mat-tab>
}
