<!--

    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-mobile-page-item-row-component-container">
  <div class="tb-mobile-page-item-row-component">
    <div class="tb-form-row" [formGroup]="mobilePageRowForm">
      <div class="tb-mobile-page-item-start-block">
        <ng-content select=".tb-custom-menu-item-row-prefix"></ng-content>
        <div class="tb-mobile-page-item-icon-name-block" [style.width]="iconNameBlockWidth">
          <mat-slide-toggle matTooltip="{{ (mobilePageRowForm.get('visible').value ? 'mobile.visible' : 'mobile.hidden') | translate }}"
                            matTooltipPosition="above"
                            formControlName="visible"></mat-slide-toggle>
          <tb-material-icon-select asBoxInput
                                   color="#305680"
                                   formControlName="icon">
          </tb-material-icon-select>
          <div tbTruncateWithTooltip> {{ itemName }} </div>
        </div>
      </div>
      <div class="tb-mobile-page-item-input-block xs:!hidden">
        <mat-form-field class="tb-suffix-absolute flex" appearance="outline" subscriptSizing="dynamic">
          <input matInput [required]="isCustomMenuItem" formControlName="label" placeholder="{{ itemNamePlaceholder }}">
          @if (mobilePageRowForm.get('label').hasError('required') && mobilePageRowForm.get('label').touched) {
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      matTooltip="{{ 'mobile.page-name-required' | translate }}"
                      class="tb-error">
              warning
            </mat-icon>
          }
          @if (mobilePageRowForm.get('label').hasError('pattern') && mobilePageRowForm.get('label').touched) {
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      matTooltip="{{ 'mobile.page-name-cannot-contain-only-spaces' | translate }}"
                      class="tb-error">
              warning
            </mat-icon>
          }
          @if (mobilePageRowForm.get('label').hasError('maxlength') && mobilePageRowForm.get('label').touched) {
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      matTooltip="{{ 'mobile.page-name-max-length' | translate }}"
                      class="tb-error">
              warning
            </mat-icon>
          }
        </mat-form-field>
        @if (isCustomMenuItem) {
          <mat-form-field class="tb-mobile-page-item-info flex" appearance="outline" subscriptSizing="dynamic">
            <input matInput readonly [placeholder]="itemInfo">
          </mat-form-field>
        }
      </div>
    </div>
    @if (!disabled) {
      <button type="button"
              mat-icon-button
              #editButton
              (click)="edit($event, editButton)"
              matTooltip="{{ 'mobile.edit-page' | translate }}"
              matTooltipPosition="above">
        <mat-icon>edit</mat-icon>
      </button>
      @if (isDefaultMenuItem) {
        <button mat-icon-button
                [disabled]="!isCleanupEnabled"
                matTooltip="{{ 'mobile.reset-to-page-default' | translate }}"
                matTooltipPosition="above"
                (click)="cleanup()">
          <tb-icon>mdi:broom</tb-icon>
        </button>
      }
      @if (isCustomMenuItem) {
        <button mat-icon-button
                matTooltip="{{ 'mobile.delete-page' | translate }}"
                matTooltipPosition="above"
                (click)="delete()">
          <mat-icon>delete</mat-icon>
        </button>
      }
    }
  </div>
</div>
