<!--

    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-custom-action-pretty" tb-fullscreen [fullscreen]="fullscreen">
  <div class="tb-action-expand-button flex flex-row items-center justify-end" [class.tb-fullscreen-editor]="fullscreen">
    @if (!fullscreen) {
      <button
        class="lt-md:!hidden"
        mat-icon-button
        matTooltip="{{ 'widget.toggle-fullscreen' | translate }}"
        matTooltipPosition="above"
        (click)="fullscreen = true">
        <mat-icon>fullscreen</mat-icon>
      </button>
    }
    @if (fullscreen) {
      <button
        mat-button
        matTooltip="{{ 'widget.toggle-fullscreen' | translate }}"
        matTooltipPosition="above"
        (click)="fullscreen = false">
        <mat-icon>fullscreen_exit</mat-icon>
        <span translate>widget.toggle-fullscreen</span>
      </button>
    }
  </div>
  <div class="tb-custom-action-editor" [class.tb-fullscreen-editor]="fullscreen">
    @if (!fullscreen) {
      <div>
        <tb-custom-action-pretty-resources-tabs [hasCustomFunction]="true"
                                                [helpId]="helpId"
                                                [action]="action" (actionUpdated)="onActionUpdated($event ? true : false)">
        </tb-custom-action-pretty-resources-tabs>
      </div>
    } @else {
      <div class="tb-fullscreen-panel tb-layout-fill flex flex-row">
        <div #leftPanel class="tb-split tb-content left-panel">
          <tb-custom-action-pretty-resources-tabs [hasCustomFunction]="false"
                                                  [helpId]="helpId"
                                                  [action]="action" (actionUpdated)="onActionUpdated($event ? true : false)">
          </tb-custom-action-pretty-resources-tabs>
        </div>
        <div #rightPanel class="tb-split tb-content right-panel">
          <tb-js-func
            [(ngModel)]="action.customFunction"
            (ngModelChange)="onActionUpdated()"
            withModules
            [fillHeight]="true"
            [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
            [disableUndefinedCheck]="true"
            [validationArgs]="[]"
            [editorCompleter]="customPrettyActionEditorCompleter"
            functionTitle="{{ 'widget-action.custom-pretty-function' | translate }}"
            [helpId]="helpId"
            [helpPopupStyle]="{width: '900px'}">
          </tb-js-func>
        </div>
      </div>
    }
  </div>
</div>
