{{ 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 required">
            <label class="col-sm-2 control-label">{{ entry_reward }}</label>
            <div class="col-sm-10">
                <select name="reward_setting_id" id="input-reward_setting_id" class="form-control" >
                  {% for reward in rewards %}
                  {% if reward.reward_setting_id == reward_setting_id %}
                  <option value="{{ reward.reward_setting_id }}" selected="selected">{{ reward.title }}</option>
                  {% else %}
                  <option value="{{ reward.reward_setting_id }}">{{  reward.title }}</option>
                  {% endif %}
                  {% endfor %}
                </select>
            </div>
            </div>
            <div class="form-group required">
                  <label class="col-sm-2 control-label">{{ entry_used_point }}:</label>
                  <div class="col-sm-10">
                      <label id="lblUsedPoint">{{point}} </label>  
                  </div>
                </div>    
                <div class="form-group required">
                  <label class="col-sm-2 control-label">{{ entry_value }}:</label>
                  <div class="col-sm-10">
                    <label id="lblValue">{{value}} </label>  
                  </div>
                </div>            
                <div class="form-group required">
                  <label class="col-sm-2 control-label">{{ entry_expiry_date }}:</label>
                  <div class="col-sm-3">                 
                     <label id="lblExpiredDate"></label>  
                  </div>
                </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 }} 