<!--

    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 (simpleList) {
  <ng-container *ngTemplateOutlet="referencesList; context:{entriesList: referencedEntitiesList, showDetailsLink: true}"></ng-container>
} @else {
  @if (contentReady) {
    <ul class="tb-references">
      @for (entry of referencedEntitiesEntries; track entry) {
        @if (isSystem(entry[0])) {
          <li class="tb-entities-container tb-primary-fill">
            <div class="tb-entities-title">{{ 'image.system-entities' | translate }}</div>
            <ng-container *ngTemplateOutlet="referencesList; context:{entriesList: entry[1].entities, showDetailsLink: true}"></ng-container>
          </li>
        } @else {
          <li class="tb-entities-container tb-primary-fill">
            <div class="tb-entities-title">
              {{ 'tenant.tenant' | translate }} <a class="tb-reference" [routerLink]="entry[1].tenantDetailsUrl">{{ entry[1].tenantName }}</a> {{ 'image.entities' | translate }}
            </div>
            <ng-container *ngTemplateOutlet="referencesList; context:{entriesList: entry[1].entities, showDetailsLink: false}"></ng-container>
          </li>
        }
      }
    </ul>
  } @else {
    <mat-spinner [diameter]="32" strokeWidth="2"></mat-spinner>
  }
}
<ng-template #referencesList let-entriesList="entriesList" let-showDetailsLink="showDetailsLink">
  <table class="tb-entities-list-table">
    @for (referencedEntity of entriesList; track referencedEntity) {
      <tr>
        <td class="tb-entity-type">{{ referencedEntity.typeName }}</td>
        <td class="tb-entity-name">
          @if (showDetailsLink) {
            <a class="tb-reference" [routerLink]="referencedEntity.detailsUrl">{{ referencedEntity.entity.name }}</a>
          }
          @if (!showDetailsLink) {
            <span>{{ referencedEntity.entity.name }}</span>
          }
        </td>
      </tr>
    }
  </table>
</ng-template>
