<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you 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 id="texera-workspace">
  <ul
    nz-menu
    id="result-buttons"
    [ngClass]="{'shadow':  !width}">
    <li
      nz-menu-item
      (click)="closePanel()"
      *ngIf="width"
      nz-tooltip="Close Result Panel{{operatorTitle ? ': ' + operatorTitle : ''}}">
      <span
        nz-icon
        nzType="minus"></span>
    </li>
    <li
      nz-menu-divider
      id="divider"></li>
    <li
      nz-menu-item
      (click)="openPanel()"
      *ngIf="!width"
      nz-tooltip="Open Result Panel{{operatorTitle ? ': ' + operatorTitle : ''}}">
      <span
        nz-icon
        nzType="border"></span>
    </li>
  </ul>
</div>

<div
  id="result-container"
  cdkDrag
  cdkDragBoundary="texera-workspace"
  nz-resizable
  [nzMinWidth]="300"
  [nzMinHeight]="250"
  [nzMaxWidth]="window.innerWidth"
  [nzMaxHeight]="window.innerHeight"
  [style.width.px]="width"
  [style.height.px]="height"
  (nzResize)="onResize($event)"
  [cdkDragFreeDragPosition]="dragPosition"
  (cdkDragStarted)="handleStartDrag()"
  (cdkDragEnded)="handleEndDrag($event)">
  <ul
    nz-menu
    id="panel-button"
    [ngClass]="{'shadow':  !width}">
    <button
      nz-button
      nzType="text"
      (click)="resetPanelPosition()"
      *ngIf="width">
      <span
        nz-icon
        nzType="enter"></span>
    </button>
    <li
      nz-menu-item
      (click)="closePanel()"
      *ngIf="width">
      <span
        nz-icon
        nzType="minus"></span>
    </li>
  </ul>
  <div
    id="content"
    *ngIf="width">
    <h4
      id="title"
      cdkDragHandle>
      Result Panel{{operatorTitle ? ': ' + operatorTitle : ''}}
    </h4>
    <nz-tabs
      class="result-content"
      [nzSize]="'small'"
      [nzTabPosition]="'left'">
      <div *ngIf="frameComponentConfigs.size === 0">
        <nz-tab nzTitle="Result">
          <div style="text-align: center">
            <h4>No results available to display.</h4>
          </div>
        </nz-tab>
      </div>
      <div *ngFor="let config of frameComponentConfigs | keyvalue">
        <nz-tab nzTitle="{{config.key}}">
          <div
            #dynamicComponent
            class="result-content">
            <ng-container
              *ngComponentOutlet="config.value.component;inputs: config.value.componentInputs"></ng-container>
          </div>
        </nz-tab>
      </div>
    </nz-tabs>
  </div>
  <nz-resize-handles
    *ngIf="width"
    [nzDirections]="isPanelDocked() ? ['right'] : ['right', 'bottom', 'bottomRight']"></nz-resize-handles>
</div>
