<!--

    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 (!textMode) {
  <fieldset class="tb-help-popup-button-container">
    <div #toggleHelpButton
         class="tb-toggle-help-popup-button"
         matTooltip="{{ helpIconTooltip }}"
         matTooltipPosition="above"
         (click)="toggleHelp()">
      <button mat-icon-button
              [disabled]="disabled()"
              color="primary"
              class="tb-help-popup-button"
              [class]="helpIconButtonClass"
              type="button">
        <tb-icon matButtonIcon>{{popoverVisible ? helpOpenedIcon : helpIcon}}</tb-icon>
        @if (popoverVisible && !popoverReady) {
          <div class="tb-help-popup-button-loading absolute inset-0 flex items-center justify-center">
            <mat-spinner mode="indeterminate" diameter="20" strokeWidth="2"></mat-spinner>
          </div>
        }
      </button>
    </div>
  </fieldset>
}
@if (textMode) {
  <fieldset class="tb-help-popup-button-container">
    <div #toggleHelpTextButton
         class="tb-toggle-help-popup-text-button"
         (click)="toggleHelp()">
      <button mat-button
              [disabled]="disabled()"
              type="button"
              color="primary"
              class="tb-help-popup-text-button"
            [class]="{'mat-mdc-outlined-button mdc-button--outlined': popoverVisible && popoverReady,
                      'hint-button': hintMode}">
        <span>
          @if (triggerSafeHtml) {
            <span [style]="triggerStyle" [innerHTML]="triggerSafeHtml"></span>
          }
          @if ((!popoverVisible || popoverReady)) {
            <mat-icon
            [class]="hintMode ? 'tb-mat-12' : 'tb-mat-16'">open_in_new</mat-icon>
          }
          @if (popoverVisible && !popoverReady) {
            <mat-spinner mode="indeterminate" [diameter]="hintMode ? 12 : 16" strokeWidth="2"></mat-spinner>
          }
        </span>
      </button>
    </div>
  </fieldset>
}
