<!--
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 id="{{paragraph.id}}_control" class="control" ng-show="!asIframe">
  <span class="numbering"
        ng-if="paragraph.config.numbering">
    Paragraph<span ng-bind-html="paragraph.number"></span> |
  </span>
  <span>
    <span ng-show="paragraph.runtimeInfos.jobUrl.values.length == 1">
      <a href="{{paragraph.runtimeInfos.jobUrl.values[0].jobUrl}}" target="_blank" rel="noopener noreferrer" style="text-decoration: none;"
         tooltip-placement="top" uib-tooltip="{{paragraph.runtimeInfos.jobUrl.tooltip}}" >
        <span class="fa fa-tasks"></span>
        {{paragraph.runtimeInfos.jobUrl.label}}
      </a>
    </span>
    <span class="dropdown" ng-show="paragraph.runtimeInfos.jobUrl.values.length > 1">
      <span style="cursor:pointer;color:#3071A9" tooltip-placement="top" uib-tooltip="{{paragraph.runtimeInfos.jobUrl.tooltip}}"
            data-toggle="dropdown" type="button">
        <span class="fa fa-tasks"></span>
        {{paragraph.runtimeInfos.jobUrl.label}}
      </span>
      <ul class="dropdown-menu" role="menu" style="width:200px;z-index:1002">
        <li ng-class="{'option-disabled': !noteOperationsAllowed()}" ng-repeat="value in paragraph.runtimeInfos.jobUrl.values">
          <a ng-if="value.jobLabel === undefined" href="{{value['jobUrl']}}" target="_blank" rel="noopener noreferrer"><span class="fa fa-external-link-square"></span> Jobs #{{$index}}</a>
          <a ng-if="value.jobLabel !== undefined" href="{{value['jobUrl']}}" target="_blank" rel="noopener noreferrer"><span class="fa fa-external-link-square"></span> {{value['jobLabel']}} </a>
        </li>
      </ul>
    </span>
  </span>
  <span>
    {{paragraph.status}}
  </span>

  <span ng-if="paragraph.status === 'RUNNING' && paragraph.executor !== 'SPELL'">
    {{getProgress()}}%
  </span>

  <!-- Run / Cancel button -->
  <span ng-if="!revisionView">
    <span class="icon-control-play" style="cursor:pointer;color:#3071A9"
          tooltip-placement="top" uib-tooltip="Run this paragraph (Shift+Enter)"
          ng-click="runParagraphFromButton(getEditorValue())"
          ng-class="{'item-disable' : isNoteRunning}"
          ng-show="paragraph.status!='RUNNING' && paragraph.status!='PENDING' && paragraph.config.enabled"></span>
    <span class="icon-control-pause" style="cursor:pointer;color:#CD5C5C"
          tooltip-placement="top" uib-tooltip="Cancel (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+C)"
          ng-click="cancelParagraph(paragraph)"
          ng-class="{'item-disable' : paragraph.status!='RUNNING'}"
          ng-show="paragraph.status=='RUNNING' || paragraph.status=='PENDING'"></span>
    <span class="{{paragraph.config.editorHide ? 'icon-size-fullscreen' : 'icon-size-actual'}}" style="cursor:pointer" tooltip-placement="top"
          uib-tooltip="{{(paragraph.config.editorHide ? 'Show' : 'Hide')}} editor (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+E)"
          ng-click="toggleEditor(paragraph)"></span>
    <span class="{{paragraph.config.tableHide ? 'icon-notebook' : 'icon-book-open'}}" style="cursor:pointer" tooltip-placement="top"
          uib-tooltip="{{(paragraph.config.tableHide ? 'Show' : 'Hide')}} output (Ctrl+{{ (isMac ? 'Option' : 'Alt') }}+O)"
          ng-click="toggleOutput(paragraph)"></span>
    <span class="dropdown navbar-right">
      <span class="icon-settings" style="cursor:pointer"
            data-toggle="dropdown"
            type="button">
      </span>

      <ul class="dropdown-menu dropdown-menu-right" role="menu" style="width:270px;z-index:1002">
        <li ng-controller="clipboardCtrl" ng-click="$event.stopPropagation()" style="text-align:center;margin-top:4px;">
          <a  ngclipboard
              ngclipboard-success="complete($event)"
              ngclipboard-error="clipError($event)"
              data-clipboard-text="{{paragraph.id}}"
              tooltip-placement="top"
              uib-tooltip="{{tooltip}}">
            <span>{{paragraph.id}}</span>
          </a>
        </li>
        <li role="separator" class="divider"></li>
        <li style="padding-top:8px"
            ng-if="paragraph.config.runOnSelectionChange == true || paragraph.config.runOnSelectionChange == false">
          <span ng-if="paragraph.config.runOnSelectionChange == true" class="fa fa-toggle-on shortcut-icon" style="padding:3px 8px 8px 20px"></span>
          <span ng-if="paragraph.config.runOnSelectionChange == false" class="fa fa-toggle-off shortcut-icon" style="padding:3px 8px 8px 20px"></span>Run on selection change
          <form style="display:inline; float:right">
            <input type="checkbox"
                   style="width:16px; margin-right:20px"
                   tooltip-placement="top" uib-tooltip="Even if you uncheck this, still can run the paragraph by pressing Enter"
                   ng-checked="{{paragraph.config.runOnSelectionChange}}"
                   ng-click="turnOnAutoRun(paragraph)"/>
          </form>
        </li>
        <li>
          <a ng-click="$event.stopPropagation()" class="dropdown">
            <span style="margin-top: 2px;" class="fa fa-arrows-h shortcut-icon"></span>
            <select style="margin-left:5px;float: right" ng-model="paragraph.config.colWidth"
                    class="selectpicker"
                    ng-change="changeColWidth(paragraph, paragraph.config.colWidth)"
                    ng-options="col for col in colWidthOption"></select>
            Width
          </a>
        </li>
        <li>
          <a ng-click="$event.stopPropagation()" class="dropdown">
            <span class="fa fa-text-height shortcut-icon"></span>
            <select style="margin-left:5px;float: right" ng-model="paragraph.config.fontSize"
                  class="selectpicker"
                  ng-change="changeFontSize(paragraph, paragraph.config.fontSize)"
                  ng-options="s for s in fontSizeOption"></select>
             Font size
          </a>
        </li>
        <li>
          <a ng-click="moveUp(paragraph)" ng-hide="$first" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-arrow-up shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+K</span>
            Move up
          </a>
        </li>
        <li>
          <a ng-click="moveDown(paragraph)" ng-hide="$last" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-arrow-down shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+J</span>
            Move down
          </a>
        </li>
        <li>
          <a ng-click="insertNew('below')" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-plus shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+B</span>
            Insert new
          </a>
        </li>
        <li>
          <a ng-click="runAllToThis(paragraph)" ng-hide="$first" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-action-redo shortcut-icon"
                  style="position: relative; transform: rotate(-90deg); left: -4px;">
            </span>
            <span class="shortcut-keys">Ctrl+Shift+Up</span>
            Run all above
          </a>
        </li>
        <li>
          <a ng-click="runAllFromThis(paragraph)" ng-hide="$last" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-action-undo shortcut-icon"
                  style="position: relative; transform: rotate(-90deg); left: -4px;">
            </span>
            <span class="shortcut-keys">Ctrl+Shift+Down</span>
             Run all below
          </a>
        </li>
        <li>
          <a ng-click="copyParagraph(getEditorValue())" ng-class="{'item-disable' : isNoteRunning}">
            <span class="fa fa-copy shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+Shift+C</span>
            Clone paragraph
          </a>
        </li>
        <li>
          <!-- paragraph handler -->
          <a ng-click="hideTitle(paragraph)"
             ng-show="paragraph.config.title"><span class="fa fa-font shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+T</span>
            Hide title
          </a>
          <a ng-click="showTitle(paragraph)"
             ng-show="!paragraph.config.title"><span class="fa fa-font shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+T</span>
            Show title
          </a>
        </li>
        <li>
          <a ng-click="hideLineNumbers(paragraph)"
             ng-show="paragraph.config.lineNumbers"><span class="fa fa-list-ol shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+M</span>
            Hide line numbers
          </a>
          <a ng-click="showLineNumbers(paragraph)"
             ng-show="!paragraph.config.lineNumbers"><span class="fa fa-list-ol shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+M</span>
            Show line numbers
          </a>
        </li>
        <li>
          <a ng-click="toggleEnableDisable(paragraph)" ng-class="{'item-disable' : isNoteRunning}">
            <span class="icon-control-play shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+R</span>
            {{paragraph.config.enabled ? "Disable" : "Enable"}} run
          </a>
        </li>
        <li>
          <a ng-click="goToSingleParagraph()"><span class="icon-share-alt shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+W</span>
            Link this paragraph
          </a>
        </li>
        <li>
          <a ng-click="clearParagraphOutput(paragraph)" ng-class="{'item-disable' : isNoteRunning}">
            <span class="fa fa-eraser shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+L</span>
            Clear output
          </a>
        </li>
        <li>
          <!-- remove paragraph -->
          <a ng-click="removeParagraph(paragraph)" ng-if="note.paragraphs.length > 1" ng-class="{'item-disable' : isNoteRunning}">
            <span class="fa fa-times shortcut-icon"></span>
            <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+D</span>
            Remove
          </a>
        </li>
      </ul>
    </span>
  </span>
</div>
