<!--
* 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.
-->
<!-- kafka config-->
<form class="form-horizontal" name="table_data_from" novalidate>
  <div class="modal-header">
    <div class="box-header">
      <h3 class="box-title">Streaming Table</h3>
      <h5 class="" style="">Map Streaming Schema to Table</h5>
      <div class="box-tools pull-right">
        <button type="button" class="btn btn-box-tool" ng-click="cancel()"><i class="fa fa-times"></i></button>
      </div>
    </div>
  </div>
  <div class="modal-body streaming-source">
    <div class="row has-error text-center" ng-if="streaming.errMsg">
      <small class="help-block">{{streaming.errMsg}}</small>
    </div>
    <div class="row">
      <div class="col-xs-5">
        <div class="text-info" ng-if="tableConfig.streamingSourceType.kafka === tableData.source_type">
          Please input topic record sample, or automatically get it from <i class="fa fa-file-text" style="cursor: pointer;" ng-click="getTemplate()"></i>
        </div>
        <div style="margin-bottom: 10px;">
          <span class="label label-info">JSON</span>
        </div>
        <div class="col-xs-12" style="border:1px solid #ddd;" ui-ace="{useWrapMode: true, mode:'json'}" ng-model="streaming.template"></div>
      </div>

      <div class="col-xs-1" style="margin-top:300px;text-align:center;">
        <button type="button" class="btn btn-primary" ng-click="getTableData()">
          <i class="fa fa-angle-double-right fa-5" style="font-size:2em;"></i>
        </button>
      </div>

      <div class="col-xs-6" ng-show="tableData">

        <div class="form-group required">
          <label for="tableName" class="col-sm-3 control-label font-color-default">Table Name</label>
          <div class="col-sm-6">
            <input type="text" class="form-control" id="tableName" ng-model="tableData.name" name="tableName" placeholder="Input Table Name eg. database.table" required>
            <small class="help-block" ng-show="table_data_from.tableName.$error.required && table_data_from.tableName.$dirty">
              Table Name is empty.
            </small>
          </div>
          <div class="form-group col-sm-3">
            <div class="checkbox">
              <label>
                <input type="checkbox" ng-model="streaming.lambda">
                Lambda
              </label>
            </div>
          </div>
        </div>

        <div class="form-group required">
          <label for="TSColumn" class="col-sm-3 control-label font-color-default">TSColumn</label>
          <div class="col-sm-6">
            <select chosen ng-model="streaming.TSColumnSelected" ng-options="TSColumn as TSColumn for TSColumn in streaming.TSColumnArr" data-placeholder="select a column name" style="width: 120px !important;" class="chosen-select" ng-change="updateTSColumn(TSColumn)"></select>
          </div>
        </div>

        <div>
          <table class="table table-hover table-bordered">
            <tr>
              <th></th>
              <th>Column</th>
              <th>Type</th>
              <th>Mapping</th>
              <th width="15%">Comment</th>
            </tr>
            <tr ng-repeat="column in tableData.columns">
              <td>
                <i class="fa fa-minus" style="margin-top:10px;cursor:pointer;" ng-click="removeColumn($index)"></i>
              </td>
              <td>{{column.name}}</td>
              <td>
                <select chosen ng-model="column.datatype" ng-options="datatype as datatype for datatype in streaming.dataTypeArr" data-placeholder="select a column type" style="width: 120px !important;" class="chosen-select" ng-change="updateTSColumnOption(column)">
                </select>
              </td>
              <td>{{column.field_mapping}}</td>
              <td>
                {{column.comment}}
                <label ng-if="isDerived(column)" class="badge badge-info">derived time dimension</label>
              </td>
            </tr>
            <tr>
              <td>
                <i class="fa fa-plus" style="margin-top:10px;cursor:pointer;" ng-click="addColumn()"></i>
              </td>
              <td>
                <input type="text" class="form-control" ng-model="additionalColumn.name" name="additionalColumnName" placeholder="Input Column Name" ng-change="initFieldMapping()" />
              </td>
              <td>
                <select chosen ng-model="additionalColumn.datatype" ng-options="datatype as datatype for datatype in streaming.dataTypeArr" data-placeholder="select a column type" style="width: 120px !important;" class="chosen-select">
                </select>
              </td>
              <td>
                <input type="text" class="form-control" ng-model="additionalColumn.field_mapping" name="additionalColumnFieldMapping" placeholder="Input Column Mapping Info" />
              </td>
              <td>
                <input type="text" class="form-control" ng-model="additionalColumn.comment" name="additionalColumnComment" placeholder="Input Column Comments" />
              </td>
            </tr>
            <tr ng-if="additionalColumn.error">
              <td colspan="5" class="text-center" style="color: #b94a48">{{additionalColumn.error}}</td>
            </tr>
          </table>
        </div>
      </div>

    </div>
  </div>
  <div class="modal-footer">
    <div class="row">
      <div class="col-sm-4 col-sm-offset-8">
        <button class="btn btn-prev" ng-click="previewStep()">
          <i class="ace-icon fa fa-arrow-left"></i> Prev
        </button>
        <button id="nextButton" class="btn btn-primary"  ng-click="saveStreamingSource()">
          Submit
        </button>
      </div>
    </div>
  </div>
</form>