<!--

    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-container">
  @if (label) {
    <label class="tb-title" [class]="{'tb-error': !disabled && (required && linkType === ScadaSymbolLinkType.none), 'tb-required': !disabled && required}">{{label}}</label>
  }
  <div class="tb-scada-symbol-select-container" [class]="{disabled: disabled && linkType === ScadaSymbolLinkType.none}">
    <div class="tb-scada-symbol-container">
      @if (linkType !== ScadaSymbolLinkType.none && scadaSymbolUrl) {
        <img class="tb-scada-symbol-preview" [src]="scadaSymbolUrl | image: {preview: true} | async">
      } @else {
        <div class="tb-no-symbol">{{ (disabled ? 'scada.no-symbol' : 'scada.no-symbol-selected') | translate }}</div>
      }
    </div>
    @if (linkType !== ScadaSymbolLinkType.none && !disabled) {
      <div class="tb-scada-symbol-info-container">
        @if (linkType === ScadaSymbolLinkType.resource) {
          <div class="tb-resource-scada-symbol-container" [class]="{loading: loadingImageResource}">
            @if (!loadingImageResource) {
              <div class="tb-scada-symbol-title">
                {{ imageResource.title | customTranslate }}
              </div>
            } @else {
              <mat-spinner [diameter]="80" strokeWidth="4"></mat-spinner>
            }
          </div>
        }
        @if (linkType === ScadaSymbolLinkType.content) {
          <div class="tb-resource-scada-symbol-container">
            <div class="tb-scada-symbol-title">
              {{ scadaSymbolMetadata.title | customTranslate }}
            </div>
          </div>
        }
        @if (linkType === ScadaSymbolLinkType.resource && !disabled) {
          <button
            class="tb-scada-symbol-clear-btn"
            type="button"
            mat-icon-button
            matTooltip="{{ 'scada.clear-symbol' | translate }}"
            matTooltipPosition="above"
            (click)="clearSymbol()">
            <mat-icon>close</mat-icon>
          </button>
        }
      </div>
    }
    @if (linkType === ScadaSymbolLinkType.none && !disabled) {
      <div class="tb-scada-symbol-select-buttons-container">
        <button mat-stroked-button
                type="button"
                color="primary"
                class="tb-scada-symbol-select-button"
                (click)="openGallery($event)">
          <tb-icon matButtonIcon>filter</tb-icon>
          <span translate>scada.browse-symbol-from-gallery</span>
        </button>
      </div>
    }
  </div>
</div>

