<!--
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="interpreterHead"
     ng-class="(bundleOrder.length > 1) ? '' : 'heliumHead'">
  <div class="header">
    <div class="row">
      <div class="col-md-12">
        <h3 class="new_h3">
          Helium
        </h3>
        <div class="pull-right heliumLearnMore">
          <a target="_blank"
             rel="noopener noreferrer"
             class="helium-repo-btn"
             ng-href="https://zeppelin.apache.org/helium_packages.html"
             tooltip-placement="bottom" uib-tooltip="Learn more">
            <i class="icon-question" ng-style="{color: 'black'}"></i>
          </a>
          <button tabindex="0" role="button"
                  ng-repeat="pkgTypes in allPackageTypes"
                  class="btn btn-default btn-sm heliumRepoBtn helium-popover"
                  ng-class="($parent.pkgListByType === pkgTypes) ? 'heliumRepoBtnToggled' : ''"
                  ng-click="$parent.pkgListByType = pkgTypes">
            <i class="fa fa-cube"></i>
            {{pkgTypes}}
          </button>
        </div>
      </div>
    </div>
    <div ng-show="bundleOrder.length > 1"
         class="row heliumBundleOrder">
      <p>Bundle package display order (drag and drop to reorder)</p>
      <div class="col-md-12">
        <div class="sortable-row btn-group"
             as-sortable="bundleOrderListeners"
             data-ng-model="bundleOrder">
          <div class="btn-group" data-ng-repeat="pkgName in bundleOrder"
               as-sortable-item>
            <button class="btn btn-default btn-sm heliumVisIconButton"
                 ng-bind-html='defaultPackages[pkgName].pkg.icon'
                 as-sortable-item-handle>
            </button>
          </div>
        </div>
        <div class="saveLink"
             ng-show="bundleOrderChanged"
             ng-click="saveBundleOrder()">
          save
        </div>
      </div>
    </div>
    <div class="pull-right row localPkgInfo">
      <div class="col-md-12">
        <p>* Local registry package's name is gray colored.</p>
      </div>
    </div>
  </div>
</div>

<div class="box width-full heliumPackageContainer">
  <div class="row"
       style="padding-bottom: 15px"
       ng-if="getPackageSize(defaultPackages, pkgListByType) === 0">
    <div class="col-md-12 gray40-message">
      <em>Currently there is no available package to be listed</em>
    </div>
  </div>
  <div ng-repeat="(types, defaultPackages) in allTypesOfPkg">
    <div class="row heliumPackageList"
         ng-repeat="pkgSearchResult in defaultPackages.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage))"
         ng-show="$parent.pkgListByType === pkgSearchResult.pkg.type">
      <div class="col-md-12">
        <div class="heliumPackageHead">
          <div class="heliumPackageIcon"
               ng-if="pkgSearchResult.pkg.type !== 'INTERPRETER'"
               ng-bind-html=pkgSearchResult.pkg.icon></div>
          <div class="heliumPackageIcon"
               ng-if="pkgSearchResult.pkg.type === 'INTERPRETER'"
               ng-bind-html=intpDefaultIcon></div>
          <div class="heliumPackageName">
            <span ng-if="hasNpmLink(pkgSearchResult)">
              <a target="_blank" rel="noopener noreferrer" href="https://www.npmjs.com/package/{{pkgSearchResult.pkg.name}}">{{pkgSearchResult.pkg.name}}</a>
            </span>
            <span ng-if="!hasNpmLink(pkgSearchResult) && !hasMavenLink(pkgSearchResult)" ng-class="{'heliumLocalPackage': isLocalPackage(pkgSearchResult)}">
              {{pkgSearchResult.pkg.name}}
            </span>
            <span ng-if="hasMavenLink(pkgSearchResult)">
              <a target="_blank"
                 rel="noopener noreferrer"
                 href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22{{pkgSearchResult.pkg.artifact.split('@')[0]}}%22%20AND%20v%3A%22{{pkgSearchResult.pkg.artifact.split('@')[1]}}%22">
                 {{pkgSearchResult.pkg.name}}
              </a>
            </span>
            <span class="heliumType">{{pkgSearchResult.pkg.type}}</span>
          </div>
          <div ng-show="!pkgSearchResult.enabled"
               ng-click="enable(pkgSearchResult.pkg.name, pkgSearchResult.pkg.artifact, pkgSearchResult.pkg.type, pkgSearchResult.pkg.groupId, pkgSearchResult.pkg.description)"
               class="btn btn-success btn-xs"
               style="float:right">Enable</div>
          <div ng-show="pkgSearchResult.enabled"
               ng-click="disable(pkgSearchResult.pkg.name, pkgSearchResult.pkg.artifact)"
               ng-if="pkgSearchResult.pkg.type !== 'INTERPRETER'"
               class="btn btn-info btn-xs"
               style="float:right">Disable</div>
          <div ng-show="configExists(pkgSearchResult)"
               ng-click="toggleConfigButton(pkgSearchResult)"
               ng-class="getConfigButtonClass(pkgSearchResult)"
               class="btn btn-default btn-xs spellConfigButton"
               style="float:right; margin-right:5px;">Config</div>
        </div>
        <div ng-class="{heliumPackageDisabledArtifact: !pkgSearchResult.enabled, heliumPackageEnabledArtifact: pkgSearchResult.enabled}">
          {{pkgSearchResult.pkg.artifact}}
          <span ng-show="pkgSearchResults[pkgSearchResult.pkg.name].length > 0"
                ng-click="toggleVersions(pkgSearchResult.pkg.name)">
            versions
          </span>
        </div>
        <ul class="heliumPackageVersions"
            ng-show="showVersions[pkgSearchResult.pkg.name]">
          <li class="heliumPackageDisabledArtifact"
              ng-repeat="pkgSearchResult in pkgSearchResults[pkgSearchResult.pkg.name]">
            {{pkgSearchResult.pkg.artifact}} -
            <span ng-click="enable(pkgSearchResult.pkg.name, pkgSearchResult.pkg.artifact, pkgSearchResult.pkg.type, pkgSearchResult.pkg.groupId)"
                  style="margin-left:3px;cursor:pointer;text-decoration: underline;color:#3071a9">
              enable
            </span>
          </li>
        </ul>
        <div class="heliumPackageDescription" ng-bind-html="getDescriptionText(pkgSearchResult)"></div>
        <div ng-if="pkgSearchResult.pkg.type === 'SPELL' && pkgSearchResult.pkg.spell"
             class="spellInfo">
          <div>
            <span class="spellInfoDesc">MAGIC</span>
            <span class="spellInfoValue">{{pkgSearchResult.pkg.spell.magic}} </span>
          </div>
          <div>
            <span class="spellInfoDesc">USAGE</span>
            <pre class="spellUsage">{{pkgSearchResult.pkg.spell.usage}} </pre>
          </div>
        </div>

        <!--start: config-->
        <div class="heliumConfig" ng-if="configOpened(pkgSearchResult)">
          <h5>Configuration</h5>
          <table class="heliumConfigTable table table-striped">
            <tr>
              <th>Name</th>
              <th>Type</th>
              <th>Description</th>
              <th>Value</th>
            </tr>
            <tr>
            </tr>
            <tr data-ng-repeat="cfg in defaultPackageConfigs[pkgSearchResult.pkg.name]">
              <td style="vertical-align: middle;">{{cfg.name}}</td>
              <td style="vertical-align: middle;">{{cfg.type}}</td>
              <td style="vertical-align: middle;">{{cfg.description}}</td>
              <td>
                <div class="input-group">
                  <input type="text" class="form-control" style="border-radius: 5px;"
                         data-ng-model="cfg.value" placeholder="{{cfg.defaultValue}}" />
                </div>
              </td>
            </tr>
          </table>

          <div>
            <button class="btn btn-primary"
                    ng-click="saveConfig(pkgSearchResult)">Save</button>
            <button class="btn btn-default"
                    ng-click="toggleConfigButton(pkgSearchResult)">Close</button>
          </div>
        </div>
        <!--end: config-->

      </div>
    </div>
    <div class="text-center" style="margin-top: 20px;" ng-if="getPackageSize(defaultPackages, pkgListByType) !== 0">
      <ul uib-pagination boundary-links="true" total-items="defaultPackages.length"
                  ng-model="$parent.currentPage" class="pagination-sm"
                  ng-show="$parent.pkgListByType === types"
                  max-size="maxSize"
                  items-per-page="itemsPerPage"
                  ng-class="{'hide-first-boundaries': $parent.currentPage == 1, 'hide-last-boundaries': $parent.currentPage >= defaultPackages.length/itemsPerPage}"
                  previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></ul>
    </div>
  </div>
</div>
