{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-reward" 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-member-reward" class="form-horizontal">
        <fieldset>
           <legend>Member Info</legend>
           <div class="form-group">
               <label class="col-sm-2 control-label">{{ entry_phone_no }}:</label>
               <div class="col-sm-10">
                  <label>{{phone_no}} </label>  
               </div>
           </div>
           <div class="form-group">
               <label class="col-sm-2 control-label">{{ entry_email }}:</label>
               <div class="col-sm-10">
                  <label>{{email}} </label>
               </div>
           </div>
           <div class="form-group">
              <label class="col-sm-2 control-label">{{ entry_tier_level }}:</label>
              <div class="col-sm-10">
              <label>  {{tier_level}} </label>
              </div>
            </div>
        </fieldset>
        <fieldset>
           <legend>Reward Info</legend>
            <div class="form-group">
              <label class="col-sm-2 control-label">{{ entry_reward_name }}</label>
              <div class="col-sm-10">
                  <label>{{ reward_name }} </label>  
              </div>
            </div>
            <div class="form-group">
               <label class="col-sm-2 control-label">{{ entry_used_point }}:</label>
                <div class="col-sm-10">
                      <label>{{used_point}} </label>  
                </div>
            </div>    
            <div class="form-group">
                <label class="col-sm-2 control-label">{{ entry_value }}:</label>
                <div class="col-sm-10">
                    <label>{{value}} </label>  
                </div>
            </div>   
            <div class="form-group">
                <label class="col-sm-2 control-label">{{ entry_redemption_date }}:</label>
                <div class="col-sm-10">
                    <label>{{redemption_date == '' ? 'N/A': redemption_date}} </label>  
                </div>
            </div>                    
            <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-expiry_date">{{ entry_expiry_date }}</label>
            <div class="col-sm-3">
              <div class="input-group date">
                <input type="text" name="expiry_date" value="{{ expiry_date }}" placeholder="{{ entry_expiry_date }}" data-date-format="YYYY-MM-DD" id="input-expiry_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_expiry_date %}
                <div class="text-danger">{{ error_expiry_date}}</div>
                {% endif %}
              </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-order_no">{{ entry_order_no }}</label>
            <div class="col-sm-10">
              <input type="text" name="order_no" value="{{ order_no }}" placeholder="{{ entry_order_no }}" id="input-order_no" class="form-control" />
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-is_redeemed">{{ entry_redeemed }}</label>
            <div class="col-sm-10">
              <select name="is_redeemed" id="input-is_redeemed" class="form-control">
                {% if is_redeemed %}
                <option value="0">{{ text_no }}</option>
                <option value="1" selected="selected">{{ text_yes }}</option>
                {% else %}
                <option value="0" selected="selected">{{ text_no }}</option>
                <option value="1">{{ text_yes }}</option>
                {% endif %}
              </select>
              {% if error_redeemed %}
                  <div class="text-danger">{{ error_redeemed}}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-is_cancelled">{{ entry_cancelled}}</label>
            <div class="col-sm-10">
              <select name="is_cancelled" id="input-is_cancelled" class="form-control">
                {% if is_cancelled %}
                <option value="0">{{ text_no }}</option>
                <option value="1" selected="selected">{{ text_yes }}</option>
                {% else %}
                <option value="0" selected="selected">{{ text_no }}</option>
                <option value="1">{{ text_yes }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
<style type="text/css">
label{
    display: block;
    width: 100%;
    height: 36px;
    padding: 8px 13px;
    font-size: 13px;
    color: #555;
}
</style>
<script type="text/javascript">
$('.date').datetimepicker({
	language: '{{ datepicker }}',
	pickTime: false
});

 $('#input-reward_setting_id').on('change', function() {
    var value = $('#input-reward_setting_id').val();
      $.ajax({
      url: 'index.php?route=member/member/reward&user_token={{ user_token }}&reward_setting_id=' + this.value,
      dataType: 'json',
      beforeSend: function() {
        $('#input-reward_setting_id').after('<i class="fa fa-circle-o-notch fa-spin"></i>');
      },
      complete: function() {
        $('.fa-spin').remove();
      },
      success: function(json) {
          $('#lblUsedPoint').html(json['point']);
          $('#lblValue').html(json['value']);
          var newDate = addDaysToCurrentDate (json['expiry']);
          $('#lblExpiredDate').html(newDate);
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
	    });
 });

$('#input-reward_setting_id').trigger('change');

  function addDaysToCurrentDate(daysToAdd) {
    const currentDate = new Date();
    const newDate = new Date(currentDate.getTime() + (daysToAdd * 24 * 60 * 60 * 1000));
    return newDate.toLocaleDateString();
  }
</script>

</div>
{{ footer }} 