<!--

    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="mobile-layout-container">
  <div class="header flex items-center gap-2">
    <div class="title-section">
      <span tbTruncateWithTooltip class="title-container" translate>mobile.pages</span>
      <mat-slide-toggle class="whitespace-nowrap xs:!hidden" [formControl]="showHiddenPages">{{ 'mobile.show-hidden-pages' | translate }}</mat-slide-toggle>
    </div>
    <span class="flex-1"></span>
    @if (!readonly) {
      <button class="tb-mobile-layout-button lt-lg:!hidden"
              mat-stroked-button
              color="primary"
              (click)="hideAll()">
        <tb-icon matButtonIcon>visibility_off</tb-icon>
        <div tbTruncateWithTooltip>{{ 'mobile.hide-all-pages' | translate }}</div>
      </button>
      <button class="tb-mobile-layout-button lt-lg:!hidden"
              mat-stroked-button
              color="primary"
              (click)="resetToDefault()">
        <tb-icon matButtonIcon>mdi:broom</tb-icon>
        <div tbTruncateWithTooltip>{{ 'mobile.reset-to-default-pages' | translate }}</div>
      </button>
      <button type="button"
              mat-stroked-button
              class="tb-box-button gt-md:!hidden"
              matTooltip="{{ 'mobile.hide-all-pages' | translate }}"
              matTooltipPosition="above"
              (click)="hideAll()">
        <tb-icon color="primary" matButtonIcon>visibility_off</tb-icon>
      </button>
      <button type="button"
              mat-stroked-button
              class="tb-box-button gt-md:!hidden"
              matTooltip="{{ 'mobile.reset-to-default-pages' | translate }}"
              matTooltipPosition="above"
              (click)="resetToDefault()">
        <tb-icon color="primary" matButtonIcon>mdi:broom</tb-icon>
      </button>
    }
<!--    <div tb-help="mobileLayout"></div>-->
  </div>
  <div #mobilePagesContainer class="tb-drop-list tb-mobile-items-container"
       cdkDropList
       cdkDropListOrientation="vertical"
       (cdkDropListDropped)="mobileItemDrop($event)"
       [cdkDropListDisabled]="!dragEnabled">
    @for (menuItemControl of visibleMobilePagesControls(); track trackByMenuItem($index, menuItemControl);) {
      <div class="tb-mobile-item-row-container">
        <div cdkDrag [cdkDragDisabled]="!dragEnabled"
             class="tb-draggable tb-mobile-item-row">
          @if (isCustom(menuItemControl)) {
            <div class="tb-mobile-item-label">
              {{ 'mobile.custom-page' | translate }}
            </div>
          }
          @if (dragEnabled) {
            <button cdkDragHandle
                    mat-icon-button
                    matTooltip="{{ 'action.drag' | translate }}"
                    matTooltipPosition="above"
                    class="tb-mat-40 tb-drag-handle">
              <tb-icon>drag_indicator</tb-icon>
            </button>
          }
          <tb-mobile-menu-item-row style="flex: 1; min-width: 0;"
                                   [formControl]="menuItemControl"
                                   [maxIconNameBlockWidth]="maxIconNameBlockWidth"
                                   [hideItems]="hideItems$"
                                   (pageRemoved)="removeCustomPage($index)">
          </tb-mobile-menu-item-row>
        </div>
        @if (!$last && !readonly) {
          <button (click)="addCustomMobilePage($index)"
                  class="tb-add-mobile-item-button"
                  [class.divider]="showMenuDivider($index)"
                  mat-button
                  matTooltip="{{ 'mobile.add-specific-page' | translate }}"
                  matTooltipPosition="above"
                  color="primary">
            <div class="tb-add-mobile-label-container tb-primary-fill">
              <mat-icon class="tb-mat-18" color="primary">add</mat-icon>
              @if (showMenuDivider($index)) {
                <span class="tb-mobile-divider-label">{{ getDividerLabel($index) | translate }}</span>
              }
            </div>
          </button>
        }
      </div>
    }
  </div>
  @if (!readonly) {
    <button (click)="addCustomMobilePage()"
            mat-button color="primary" class="tb-primary-fill" style="min-height: 52px;">
      <mat-icon color="primary">add</mat-icon>
      <span translate>mobile.add-specific-page</span>
    </button>
  }
</div>
