<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  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.
  #L%
  -->
<div>

  <card-layout header-css="filter-header" class="centered">

    <header-section>
      <div layout="row" layout-align="center start">
        <div class="card-title">Import Template</div>
        <span flex></span>
        <ng-md-icon icon="file_upload" style="fill:#F08C38;padding-right:16px;" size="30"></ng-md-icon>
      </div>
    </header-section>


    <body-section>


      <div layout="column" flex class="md-padding">

        <div>
          <div class="item-title">Import one of the following from another environment:</div>
        </div>

        <div class="layout-padding-indent">
          <md-list flex layout-fill class="list-item-table list-condensed">

            <md-list-item>
              <div layout="row" layout-fill>
                <div flex="20" class="md-list-item-text hint">
                  Type
                </div>
                <div flex="10" class="md-list-item-text hint">
                  File type
                </div>
                <div flex="60" class="md-list-item-text hint">
                  Description
                </div>

              </div>
            </md-list-item>


            <md-list-item>
              <div layout="row" layout-fill>
                <div flex="20" class="md-list-item-text ">
                  NiFi template
                </div>
                <div flex="10" class="md-list-item-text ">
                  XML
                </div>
                <div flex="60" class="md-list-item-text ">
                  Imports a NiFi template
                </div>
              </div>
            </md-list-item>
            <md-list-item>
              <div layout="row" layout-fill>
                <div flex="20" class="md-list-item-text ">
                  Kylo template bundle
                </div>
                <div flex="10" class="md-list-item-text ">
                  ZIP
                </div>
                <div flex="60" class="md-list-item-text ">
                  Imports Kylo configuration and NiFi template
                </div>
              </div>
            </md-list-item>
          </md-list>
        </div>

        <div fex layout="column" layout-align="start start" style="padding-top:15px;"
             class="layout-padding-indent">
          <upload-file upload-file-model="vm.templateFile"></upload-file>
          <md-input-container class="condensed-no-float md-block layout-padding-bottom">
            <md-checkbox ng-model="vm.overwrite" aria-label="Overwrite if exists">
              Overwrite
            </md-checkbox>
            <div class="hint" style="margin-top:-10px">
              Replace any template with same name
            </div>
          </md-input-container>
          <md-input-container class="condensed-no-float md-block layout-padding-bottom"
                              ng-if="vm.xmlType == true">
            <md-checkbox ng-model="vm.createReusableFlow" aria-label="Create a reusable flow (callable by other flows)">
              Create Reusable Flow
            </md-checkbox>
            <div class="hint" style="margin-top:-10px">
              Flow will be created in NiFi under the "reusable_templates" process group
            </div>
          </md-input-container>
          <md-input-container class="condensed-no-float md-block layout-padding-bottom"
                              ng-if="vm.verifyToCreateConnectingReusableTemplate == true">
            <md-checkbox ng-model="vm.createConnectingReusableTemplate" aria-label="Import Reusable Flow">
              Import Connecting Reusable Flow
            </md-checkbox>
            <div class="hint" style="margin-top:-10px">
              This template contains a common flow shared by other templates. Overwrite?
            </div>
          </md-input-container>

          <div layout="row" class="layout-padding-top">
            <md-button class="md-raised md-primary" ng-click="vm.importTemplate();" ng-if="vm.templateFile != null"
                       ng-disabled="vm.importInProgress">
              Import Template
            </md-button>
            <span flex="5"></span>
            <md-progress-circular md-mode="indeterminate" ng-if="vm.importInProgress" ></md-progress-circular>
          </div>
        </div>
      </div>


      <div ng-if="vm.importResult != null" class="layout-padding-indent layout-padding-top-bottom">
        <div layout="row">
          <ng-md-icon icon="{{vm.importResultIcon}}"
                      style="fill:{{vm.importResultIconColor}}"></ng-md-icon>
          <span style="padding-left:15px;">{{vm.message}}</span>
          <span flex></span>
        </div>
        <md-list class="padding-left" ng-repeat="(severity,errors)  in vm.errorMap">
          <md-subheader class="md-warn" ng-if="errors.length >0">Errors</md-subheader>
          <md-list-item class="md-2-line" ng-repeat="error in errors track by $index">
            <div class="md-list-item-text">
              <div ng-if="error.processorName != null && error.processorName != '' "
                   style="color:grey">Processor: {{::error.processorName}}
              </div>
              <div class="md-warn-text">{{::error.message}}</div>
            </div>
            <md-divider ng-if="!$last"></md-divider>
          </md-list-item>
        </md-list>

        <!-- reorder -->

        <div ng-if="!vm.xmlType && vm.showReorderList">
          <thinkbig-template-order template-id="vm.importResult.templateId" template-name="vm.importResult.templateName" add-as-new="false" add-save-btn="true"></thinkbig-template-order>
        </div>


      </div>
</div>
</body-section>
</card-layout>
</div>
