{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-reward-promotion" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_form }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-reward-promotion" class="form-horizontal">
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-reward-type">{{ entry_reward }}</label>
            <div class="col-sm-10">
              <select name="reward_setting_id" id="input-reward" class="form-control">
                {% for reward in rewards %}
                {% if reward.reward_setting_id == reward_setting_id %}
                <option value="{{ reward.reward_setting_id }}" selected="selected">{{ reward.reward_setting_name }}</option>
                {% else %}
                <option value="{{ reward.reward_setting_id }}">{{ reward.reward_setting_name }}</option>
                {% endif %}
                {% endfor %}
              </select>
              <p />
              <fieldset id="fldreward">
                <b>{{ text_rs_point }}: </b><label id="lblpoint"></label><br> 
                <b>{{ text_rs_start_date }}: </b><label id="lblstartdate"></label><br> 
                <b>{{ text_rs_end_date }}: </b><label id="lblenddate"></label><br> 
              </fieldset>
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-point">{{ entry_point }}</label>
            <div class="col-sm-10">
              <input type="text" name="point" value="{{ point }}" placeholder="{{ entry_point }}" id="input-point" class="form-control" />
              {% if error_point %}
              <div class="text-danger">{{ error_point }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-start-date">{{ entry_start_date }}</label>
            <div class="col-sm-3">
              <div class="input-group date">
                <input type="text" name="start_date" value="{{ start_date }}" 
                placeholder="{{ entry_start_date }}" data-date-format="YYYY-MM-DD" 
                id="input-date-start" class="form-control"
                {% set currentDateTime = "now"|date("Y-m-d") %}
                {% if reward_promotion_setting_id and start_date <= currentDateTime %}
                readonly
                {% endif %}
                />
                <span class="input-group-btn">
                <button type="button" class="btn btn-default"
                {% if reward_promotion_setting_id and start_date <= currentDateTime %}
                disabled
                {% endif %}
                ><i class="fa fa-calendar"></i></button>
                </span></div>
                {% if error_start_date %}
                <div class="text-danger">{{ error_start_date }}</div>
                {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-end-date">{{ entry_end_date }}</label>
            <div class="col-sm-3">
              <div class="input-group date">
                <input type="text" name="end_date" value="{{ end_date }}" placeholder="{{ entry_end_date }}" data-date-format="YYYY-MM-DD" id="input-end_date" class="form-control" />
                <span class="input-group-btn">
                <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                </span></div>
                {% if error_end_date %}
                <div class="text-danger">{{ error_end_date }}</div>
                {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-10">
              <select name="status" id="input-status" class="form-control">
                {% if status %}
                <option value="0">{{ text_disabled }}</option>
                <option value="1" selected="selected">{{ text_enabled }}</option>
                {% else %}
                <option value="0" selected="selected">{{ text_disabled }}</option>
                <option value="1">{{ text_enabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
  <script type="text/javascript"><!--
$('.date').datetimepicker({
	language: '{{ datepicker }}',
	pickTime: false
});
$('#input-reward').on('change', function() {
  var value = $('#input-reward').val();
  $.ajax({
		url: 'index.php?route=reward/reward_promotion/reward&user_token={{ user_token }}&reward_setting_id=' + this.value,
		dataType: 'json',
		beforeSend: function() {
			$('#fldreward').after('<i class="fa fa-circle-o-notch fa-spin"></i>');
		},
		complete: function() {
			$('.fa-spin').remove();
		},
		success: function(json) {
      	$('#lblpoint').html(json['point']);
        $('#lblstartdate').html(json['start_date']);
        $('#lblenddate').html(json['end_date']); 
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
})
$('#input-reward').trigger('change');
//--></script>
</div>
{{ footer }} 