{{!
 * 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 class="col-md-12">
  <div class="form-group">
    <label>File Configurations</label>
    <span class="glyphicon glyphicon-info-sign info-icon" data-info="fileConfigs"></span>
    <button class="btn btn-primary btn-xs pull-right" {{action "showNewConfigFileModal"}}>
      <span class="glyphicon glyphicon-plus"></span>
    </button>
    <button class="btn btn-primary btn-xs pull-right" style="margin-right: 5px;" {{action "showFileConfigUploadModal"}}>
      <span class="glyphicon glyphicon-open"></span>
    </button>
    <div class="panel panel-default">
      <table class="table table-hover table-custom-bordered table-custom-striped table-custom-action">
        <thead>
          <tr>
            <th>Source File</th>
            <th>Properties</th>
            <th>Destination File</th>
            <th>Type</th>
            <th>Scope</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {{#each serviceDef.fileConfigs as |file|}}
            <tr>
              <td>
                {{#if file.srcFile}}
                  {{file.srcFile}}
                {{else}}
                  <span>N/A</span>
                {{/if}}
              </td>
              <td>
                {{#if file.props}}
                  <a href="#" {{action "showFileConfigPropertyViewer" file.props}}>View Properties</a>
                {{else}}
                  <span>N/A</span>
                {{/if}}
              </td>
              <td>{{file.destFile}}</td>
              <td>{{file.type}}</td>
              <td>{{file.formattedScope}}</td>
              <td class="align-center">
                <span class="glyphicon glyphicon-remove remove-icon" {{action "removeFileConfiguration" file}}></span>
              </td>
            </tr>
          {{else}}
            <tr class="align-center">
              <td colspan="6">No data available</td>
            </tr>
          {{/each}}
        </tbody>
      </table>
    </div>
  </div>
</div>

<div class="modal fade deploy-service-modal" tabindex="-1" role="dialog" id="addFileConfigModal">
  <div class="modal-dialog" role="document" style="width: 500px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title bold-text">Add File Configuration</h4>
      </div>
      <div class="modal-body">
        {{#if parseError}}
          <div class="alert alert-danger alert-dismissible" role="alert">
            <strong>{{parseError}}</strong>
          </div>
        {{/if}}
        <div class="form-group">
          <label class="required">Type</label>
          <div>
            <label class="radio-inline">
              <input type="radio" name="type" value="TEMPLATE" checked={{eq currentFileConfig.type "TEMPLATE"}} onchange={{action "configTypeChanged" "TEMPLATE"}}>TEMPLATE
            </label>
            <label class="radio-inline">
              <input type="radio" name="type" value="HADOOP_XML" checked={{eq currentFileConfig.type "HADOOP_XML"}} onchange={{action "configTypeChanged" "HADOOP_XML"}}>HADOOP_XML
            </label>
          </div>
        </div>
        <div class="form-group">
          <label class={{unless isConfigTypeHadoopXml "required"}}>Source File</label>
          {{input type="text" class="form-control" value=currentFileConfig.srcFile}}
        </div>
        {{#if isConfigTypeHadoopXml}}
          <div class="form-group">
            <label>Properties</label> <span>(Source File and/or Properties are required)</span>
            {{textarea class="form-control" rows="15" value=fileConfigProps placeholder="Configuration file properties here..."}}
          </div>
        {{/if}}
        <div class="form-group">
          <label class="required">Destination File</label>
          {{input type="text" class="form-control" value=currentFileConfig.destFile}}
        </div>
        <div class="form-group">
          <label class="required">Scope</label>
          <div>
            <label class="radio-inline">
              <input type="radio" name="scope" value="service" checked={{eq currentFileConfig.scope "service"}} onchange={{action "configScopeChanged" "service"}}>Service
            </label>
            {{#if isNonEmptyComponents}}
              <label class="radio-inline">
                <input type="radio" name="scope" value="component" checked={{eq currentFileConfig.scope "component"}} onchange={{action "configScopeChanged" "component"}}>Component
              </label>
            {{/if}}
          </div>
        </div>
        {{#if (eq currentFileConfig.scope "component")}}
          <div class="form-group">
            <select class="form-control" onchange={{action "scopeComponentChanged" value="target.value"}}>
              {{#each componentNames as |name|}}
                <option value="{{name}}" selected={{eq currentFileConfig.componentName name}}>{{name}}</option>
              {{/each}}
            </select>
          </div>
        {{/if}}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" {{action "addNewFileConfig"}} disabled={{unless isValidCurrentFileConfig "disabled"}}>Add</button>
      </div>
    </div>
  </div>
</div>

{{upload-config
  dialogId="service_file_config_upload_modal"
  title="Upload File Configurations"
  configJson=fileConfigJson
  uploadConfig="uploadFileConfig"
}}

{{fileconfig-viewer-dialog dialogId="file_config_properties_viewer" props=propertyViewer}}
