<?php  
if( ! defined( 'ABSPATH' ) ) exit;
global $wpdb, $sync_hotel_coupon_enable, $sync_car_coupon_enable, $sync_restau_coupon_enable; ?>
<h3 class="sync-entries-title">Coupon Settings</h3>
<main class="sync_backend_coupons">
  

<div class="sync_common_settings">
    <div class="sync_settings_enable_coupon hotel">
      <label>Hotel Coupons</label>
      <div>
        <?php
            if ($sync_hotel_coupon_enable==false) {
              ?>
                <input type="checkbox" id="sync_hotel_coupon_switch" value="on" name="sync_hotel_coupon_switch"/>
                
                <br>
              <?php
            }else{
            ?>
            <input type="checkbox" id="sync_hotel_coupon_switch" value="on" checked name="sync_hotel_coupon_switch"/>
            <?php
          }
        ?>
      </div>
    </div>
    <div class="sync_settings_enable_coupon car">
      <label>Car Coupons</label>
      <div>
        <?php
            if ($sync_car_coupon_enable==false) {
              ?>
              <input type="checkbox" id="sync_car_coupon_switch" value="on" name="sync_car_coupon_switch"/>
            <?php
            }else{  
            ?>
              <input type="checkbox" id="sync_car_coupon_switch" value="on" checked name="sync_car_coupon_switch"/>
            <?php
          }
        ?>
      </div>
    </div>
    <div class="sync_settings_enable_coupon restau">
      <label>Restaurant Coupons</label>
      <div>
        <?php
            if ($sync_restau_coupon_enable==false) {
              ?>
              <input type="checkbox" id="sync_restau_coupon_switch" value="on" name="sync_restau_coupon_switch"/>
            <?php
            }else{  
            ?>
              <input type="checkbox" id="sync_restau_coupon_switch" value="on" checked name="sync_restau_coupon_switch"/>
            <?php
          }
        ?>
      </div>
    </div>
    </br>
</div>

  <?php 
    if ($sync_car_coupon_enable == false && $sync_hotel_coupon_enable == false && $sync_restau_coupon_enable == false ) {
  ?>
      <div class="sync-coupon-container" style="display:none;">
  <?php
    } else {
  ?>
    <div class="sync-coupon-container">
  <?php    
    }
  ?>   

  <?php 
    if ($sync_car_coupon_enable == false && $sync_restau_coupon_enable == false && $sync_hotel_coupon_enable == true ) {
  ?>
    <input id="cpn_tab1" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab1"> Hotel Coupons</label>

  <?php
    } if ($sync_car_coupon_enable == true && $sync_hotel_coupon_enable == false && $sync_restau_coupon_enable == false ) {
  ?>
    <input id="cpn_tab2" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab2"> Car Coupons</label>

  <?php
    } if ($sync_car_coupon_enable == false && $sync_hotel_coupon_enable == false && $sync_restau_coupon_enable == true ) {
  ?>
    <input id="cpn_tab2" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab2"> Car Coupons</label>
    
  <?php
    } if ($sync_car_coupon_enable == true && $sync_hotel_coupon_enable == true && $sync_restau_coupon_enable == false ) {
  ?>
    <input id="cpn_tab1" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab1"> Hotel Coupons</label>
    
    <input id="cpn_tab2" type="radio" name="tabs" class="sync_tab" >
    <label for="cpn_tab2"> Car Coupons</label>
    
  <?php
    } if ($sync_car_coupon_enable == true && $sync_hotel_coupon_enable == false && $sync_restau_coupon_enable == true ) {
  ?>
    <input id="cpn_tab2" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab2"> Car Coupons</label>
    
    <input id="cpn_tab3" type="radio" name="tabs" class="sync_tab" >
    <label for="cpn_tab3"> Restaurant Coupons</label>
    
  <?php
    } if ($sync_car_coupon_enable == false && $sync_hotel_coupon_enable == true && $sync_restau_coupon_enable == true ) {
  ?>
    <input id="cpn_tab1" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab1"> Hotel Coupons</label>
    
    <input id="cpn_tab3" type="radio" name="tabs" class="sync_tab" >
    <label for="cpn_tab3"> Restaurant Coupons</label>
    
  <?php
    } if ($sync_car_coupon_enable == true && $sync_hotel_coupon_enable == true && $sync_restau_coupon_enable == true ) {
  ?>
    <input id="cpn_tab1" type="radio" name="tabs" class="sync_tab" checked>
    <label for="cpn_tab1"> Hotel Coupons</label>
    <input id="cpn_tab2" type="radio" name="tabs" class="sync_tab">
    <label for="cpn_tab2"> Car Coupons</label>
    <input id="cpn_tab3" type="radio" name="tabs" class="sync_tab">
    <label for="cpn_tab3"> Restaurant Coupons</label>
  
  <?php }
  ?>
<section id="coupon_tab1" style="display:none;">
  <div class="sync-table-coupons">
    <div class="btn-create-container">
        <br>
        <button class="btn-create-coupon" id="create_coupon">Create Coupon</button>
        <br><br>
    </div>

    <div class="hotel_coupon_form" style="display: none;">
        <br>
        <form id="generate_cpn" method="POST" class="sync_hotel_coupon">
          <div class="cpn_details">
            <div class="title_value">
              <div class="title_div">
                <span for="coupon_title">Title</span>
                <input type="text" id="coupon_title" name="coupon_title" placeholder="Enter Coupon Title" required/>
              </div>
              <div class="value_div">
                <span for="coupon_value">Value</span>
                <input type="number" id="coupon_value" name="coupon_value" value="1" min="1" required/> 
              </div>
            </div>
            <br id="remove_l8r">
            <div class="quantity_expDate">
              <div class="quantity_div">
                <span for="coupon_quantity">Quantity</span>
                <input type="number" id="coupon_quantity" name="coupon_quantity"  value="1" min="1" required/>
              </div>
              <div class="exp_date">
                <span for="date_expire">Expiration Date</span>
                <input required readonly id="date_expire" data-toggle="datepicker" value="<?php echo isset($_POST['date_expire']) ? esc_html($_POST['date_expire']) : '' ?>" name="date_expire"><i class="fa fa-calendar-alt fa-1x calendar"></i>
              </div>
            </div>
          </div>
          <br>
            <div class="generate_code">
              <input type="text" id="coupon_code" name="coupon_code" placeholder="Generate Code" readonly required/>
              <input type="button" value="Generate" class="save-btn btn btn-success" id="generate_code" />
              <input type="hidden" class="coupon_type" name="coupon_type" readonly/>
            </div>
            <br>
            <input type="submit" value="Save" name="save" id="save_btn" class="save-btn btn btn-success"/>
            <input type="button" value="Cancel" name="cancel" id="cancel_btn" class="cancel-btn btn btn-danger"/>
        </form>
        <br>
    </div>
    <table class="table table-striped table-sm" id="coupon_table">
        <thead>
            <tr>
            <th scope="col">Code</th>
            <th scope="col">Title</th>
            <th scope="col">Quantity</th>
            <th scope="col">Value</th>
            <th scope="col" >Date Created</th>
            <th scope="col">Date Expired</th>
            <th scope="col">Status</th>
            <th scope="col">Action</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            
            $table_coupon = $wpdb->prefix . "sync_coupons";
            $coupons = $wpdb->get_results("select * from $table_coupon where coupon_type = 'hotel_coupon' ");
            if (!empty($coupons)) {
                foreach ( $coupons as $key => $value) {
                    $datetime = $value->date_created;
                    $splitTimeStamp = explode(" ",$datetime);
                    $date = $splitTimeStamp[0];
                    $time = $splitTimeStamp[1];
            ?>
                    <tr class="coupon_dtails">
                        <td class="coup_id" scope="row" hidden><?php echo $value->id; ?></td>
                        <td scope="row"><?php echo $value->coupon_code; ?></td>
                        <td><?php echo $value->coupon_title; ?></td>
                        <td><?php echo $value->coupon_quantity; ?></td>
                        <td><?php echo $value->coupon_value; ?></td>
                        <td><?php echo $date." | ".$time; ?></td>
                        <td><?php echo $value->expiration_date; ?></td>
                        <td><?php echo ucfirst($value->coupon_status); ?></td>
                        <?php 
                        if($value->coupon_status == 'expired' || $value->coupon_status == 'used') {
                        ?>
                          <td><button disabled type="button" value="<?php echo $value->id; ?>" class="edit-btn btn btn-success">Edit</button></td>
                        <?php
                        } else {
                        ?>
                          <td><button type="button" value="<?php echo $value->id; ?>" class="edit-btn btn btn-success">Edit</button></td>
                        <?php
                        }
                        ?>
                        
                    </tr>
                <?php
                }
                ?>
                
                <?php    
            }
            ?>
        </tbody>
    </table>
    <?php 

    if (empty($coupons)) {
    ?>
        <h4 style="text-align:center;"> --- No Data --- </h4>
    <?php    
    }
    ?>
  </div>
</section>

<section id="coupon_tab2" style="display:none;">
  <div class="sync-table-coupons">
    <div class="btn-create-container-car">
        <br>
        <button class="btn-create-coupon_car" id="create_coupon">Create Coupon</button>
        <br><br>
    </div>

    <div class="car_coupon_form" style="display: none;">
        <br>
        <form id="generate_cpn_car" method="POST" class="sync_car_coupon">
        <div class="cpn_details">
            <div class="title_value">
              <div class="title_div">
                <label for="coupon_title">Title</label>
                <input type="text" id="coupon_title" name="coupon_title" placeholder="Enter Coupon Title" required/>
              </div>
              <div class="value_div">
                <label for="coupon_value">Value</label>
                <input type="number" id="coupon_value" name="coupon_value" value="1" min="1" required/>
              </div>
            </div>
            <br id="remove_l8r">
            <div class="quantity_expDate">
              <div class="quantity_div">
                <span for="coupon_quantity">Quantity</span>
                <input type="number" id="coupon_quantity" name="coupon_quantity"  value="1" min="1" required/>
              </div>
              <div class="exp_date">
                <span for="date_expire">Expiration Date</span>
                <input required readonly id="date_expire" data-toggle="datepicker" value="<?php echo isset($_POST['date_expire']) ? esc_html($_POST['date_expire']) : '' ?>" name="date_expire"><i class="fa fa-calendar-alt fa-1x calendar"></i>
              </div>
            </div>
          </div>
          <br>
            <div class="generate_code">
              <input type="text" id="coupon_code_car" name="coupon_code_car" placeholder="Generate Code" readonly required/>
              <input type="button" value="Generate" class="save-btn btn btn-success" id="generate_car_code" />
              <input type="hidden" class="coupon_type" name="coupon_type" readonly/>
            </div>
            <br>
            <input type="submit" value="Save" name="save" id="save_btn" class="save-btn btn btn-success"/>
            <input type="button" value="Cancel" name="cancel" id="cancel_btn_car" class="cancel-btn btn btn-danger"/>

        </form>
        <br>
    </div>
    <table class="table table-striped table-sm" id="coupon_table_car">
        <thead>
            <tr>
            <th scope="col">Code</th>
            <th scope="col">Title</th>
            <th scope="col">Quantity</th>
            <th scope="col">Value</th>
            <th scope="col" >Date Created</th>
            <th scope="col">Date Expired</th>
            <th scope="col">Status</th>
            <th scope="col">Action</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            
            $table_coupon = $wpdb->prefix . "sync_coupons";
            $coupons_car = $wpdb->get_results("select * from $table_coupon where coupon_type = 'car_coupon' ");
            if (!empty($coupons_car)) {
                foreach ( $coupons_car as $key => $value_car) {
                    $datetime = $value_car->date_created;
                    $splitTimeStamp = explode(" ",$datetime);
                    $date = $splitTimeStamp[0];
                    $time = $splitTimeStamp[1];
            ?>
                    <tr class="coupon_dtails">
                        <td class="coup_id" scope="row" hidden><?php echo $value->id; ?></td>
                        <td scope="row"><?php echo $value_car->coupon_code; ?></td>
                        <td><?php echo $value_car->coupon_title; ?></td>
                        <td><?php echo $value_car->coupon_quantity; ?></td>
                        <td><?php echo $value_car->coupon_value; ?></td>
                        <td><?php echo $date." | ".$time; ?></td>
                        <td><?php echo $value_car->expiration_date; ?></td>
                        <td><?php echo ucfirst($value_car->coupon_status); ?></td>
                        <?php 
                        if($value_car->coupon_status == 'expired' || $value_car->coupon_status == 'used') {
                        ?>
                          <td><button disabled type="button" value="<?php echo $value_car->id; ?>" class="edit-btn-car btn btn-success">Edit</button></td>
                        <?php
                        } else {
                        ?>
                          <td><button type="button" value="<?php echo $value_car->id; ?>" class="edit-btn-car btn btn-success">Edit</button></td>
                        <?php
                        }
                        ?>
                        
                    </tr>
                <?php
                }
                ?>
                
                <?php    
            }
            ?>
        </tbody>
    </table>
    <?php 

    if (empty($coupons_car)) {
    ?>
        <h4 style="text-align:center;"> --- No Data --- </h4>
    <?php    
    }
    ?>
  </div>
</section>

<section id="coupon_tab3" style="display:none;">
  <div class="sync-table-coupons">
    <div class="btn-create-container-restau">
        <br>
        <button class="btn-create-coupon_restau" id="create_coupon">Create Coupon</button>
        <br><br>
    </div>

    <div class="restau_coupon_form" style="display: none;">
        <br>
        <form id="generate_cpn_restau" method="POST" class="sync_restau_coupon">
        <div class="cpn_details">
            <div class="title_value">
              <div class="title_div">
                <label for="coupon_title">Title</label>
                <input type="text" id="coupon_title" name="coupon_title" placeholder="Enter Coupon Title" required/>
              </div>
              <div class="value_div">
                <label for="coupon_value">Value</label>
                <input type="number" id="coupon_value" name="coupon_value" value="1" min="1" required/>
              </div>
            </div>
            <br id="remove_l8r">
            <div class="quantity_expDate">
              <div class="quantity_div">
                <span for="coupon_quantity">Quantity</span>
                <input type="number" id="coupon_quantity" name="coupon_quantity"  value="1" min="1" required/>
              </div>
              <div class="exp_date">
                <span for="date_expire">Expiration Date</span>
                <input required readonly id="date_expire" data-toggle="datepicker" value="<?php echo isset($_POST['date_expire']) ? esc_html($_POST['date_expire']) : '' ?>" name="date_expire"><i class="fa fa-calendar-alt fa-1x calendar"></i>
              </div>
            </div>
          </div>
          <br>
            <div class="generate_code">
              <input type="text" id="coupon_code_restau" name="coupon_code_restau" placeholder="Generate Code" readonly required/>
              <input type="button" value="Generate" class="save-btn btn btn-success" id="generate_restau_code" />
              <input type="hidden" class="coupon_type" name="coupon_type" readonly/>
            </div>
            <br>
            <input type="submit" value="Save" name="save" id="save_btn" class="save-btn btn btn-success"/>
            <input type="button" value="Cancel" name="cancel" id="cancel_btn_restau" class="cancel-btn btn btn-danger"/>

        </form>
        <br>
    </div>
    <table class="table table-striped table-sm" id="coupon_table_restau">
        <thead>
            <tr>
            <th scope="col">Code</th>
            <th scope="col">Title</th>
            <th scope="col">Quantity</th>
            <th scope="col">Value</th>
            <th scope="col" >Date Created</th>
            <th scope="col">Date Expired</th>
            <th scope="col">Status</th>
            <th scope="col">Action</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            
            $table_coupon = $wpdb->prefix . "sync_coupons";
            $coupons_restau = $wpdb->get_results("select * from $table_coupon where coupon_type = 'restau_coupon' ");
            if (!empty($coupons_restau)) {
                foreach ( $coupons_restau as $key => $value_restau) {
                    $datetime = $value_restau->date_created;
                    $splitTimeStamp = explode(" ",$datetime);
                    $date = $splitTimeStamp[0];
                    $time = $splitTimeStamp[1];
            ?>
                    <tr class="coupon_dtails">
                        <td class="coup_id" scope="row" hidden><?php echo $value->id; ?></td>
                        <td scope="row"><?php echo $value_car->coupon_code; ?></td>
                        <td><?php echo $value_restau->coupon_title; ?></td>
                        <td><?php echo $value_restau->coupon_quantity; ?></td>
                        <td><?php echo $value_restau->coupon_value; ?></td>
                        <td><?php echo $date." | ".$time; ?></td>
                        <td><?php echo $value_restau->expiration_date; ?></td>
                        <td><?php echo ucfirst($value_restau->coupon_status); ?></td>
                        <?php 
                        if($value_restau->coupon_status == 'expired' || $value_restau->coupon_status == 'used') {
                        ?>
                          <td><button disabled type="button" value="<?php echo $value_restau->id; ?>" class="edit-btn-restau btn btn-success">Edit</button></td>
                        <?php
                        } else {
                        ?>
                          <td><button type="button" value="<?php echo $value_restau->id; ?>" class="edit-btn-restau btn btn-success">Edit</button></td>
                        <?php
                        }
                        ?>
                        
                    </tr>
                <?php
                }
                ?>
                
                <?php    
            }
            ?>
        </tbody>
    </table>
    <?php 

    if (empty($coupons_car)) {
    ?>
        <h4 style="text-align:center;"> --- No Data --- </h4>
    <?php    
    }
    ?>
  </div>
</section>

</main>

<div class="modall fade" id="sync_switch_toggle" tabindex="-1" role="dialog" aria-labelledby="sync_switch_toggleLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <p>Switching</p>   
      </div>
      <div class="modal-body">     
          <p class="sync-sure">Are you sure?</p>
      </div>
      <div class="modal-footer">
        <form id="" action="">
          <input type="hidden" name="sync_switch" value="">
          <button type="button" class="btn btn-default sync-cancel-switch" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary btn-ok" >Change</button>
        </form>
      </div>
    </div>
  </div>
</div>

<div class="modall fade sync_coupon_edit" id="sync_coupon_edit" tabindex="-1" role="dialog" aria-labelledby="sync_coupon_editLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <h5>Update Coupon</h5>   
      </div>
      <form id="update_cpn" method="POST" action=""> 
        <div class="modal-body">      
            <input class="cpn_id" name="coupon_id" type="hidden" value="" >
            <label for="coupon_value">Value</label>
            <input type="number" class="coupon_value" id="coupon_value" name="coupon_value" value="" required step=".01"/>
            <p></p>
            <label for="coupon_quantity">Quantity</label>
            <input type="number" class="coupon_quantity" id="coupon_quantity" name="coupon_quantity"  value="" min="1" required/>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-ok sync_color_orange" >Save</button>
            <button type="button" class="btn btn-default sync-cancel-update" data-dismiss="modal">Cancel</button>
          </div>
        </form>
    </div>
  </div>
</div>

<div class="modall fade sync_coupon_car_edit" id="sync_coupon_car_edit" tabindex="-1" role="dialog" aria-labelledby="sync_coupon_car_editLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <h5>Update Coupon</h5>   
      </div>
      <form id="update_car_cpn" method="POST" action=""> 
        <div class="modal-body">      
            <input class="cpn_id" name="coupon_id" type="hidden" value="" >
            <label for="coupon_value">Value</label>
            <input type="number" class="coupon_value" id="coupon_value" name="coupon_value" value="" required step=".01"/>
            <p></p>
            <label for="coupon_quantity">Quantity</label>
            <input type="number" class="coupon_quantity" id="coupon_quantity" name="coupon_quantity"  value="" min="1" required/>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-ok sync_color_orange" >Save</button>
            <button type="button" class="btn btn-default sync-cancel-update " data-dismiss="modal">Cancel</button>
          </div>
        </form>
    </div>
  </div>
</div>

<div class="modall fade sync_coupon_restau_edit" id="sync_coupon_restau_edit" tabindex="-1" role="dialog" aria-labelledby="sync_coupon_restau_editLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <h5>Update Coupon</h5>   
      </div>
      <form id="update_restau_cpn" method="POST" action=""> 
        <div class="modal-body">      
            <input class="cpn_id" name="coupon_id" type="hidden" value="" >
            <label for="coupon_value">Value</label>
            <input type="number" class="coupon_value" id="coupon_value" name="coupon_value" value="" required step=".01"/>
            <p></p>
            <label for="coupon_quantity">Quantity</label>
            <input type="number" class="coupon_quantity" id="coupon_quantity" name="coupon_quantity"  value="" min="1" required/>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-ok sync_color_orange" >Save</button>
            <button type="button" class="btn btn-default sync-cancel-update " data-dismiss="modal">Cancel</button>
          </div>
        </form>
    </div>
  </div>
</div>

<script>

jQuery(document).ready(function() {

  var hotel_tab = jQuery(".sync-coupon-container #cpn_tab1:checked").length > 0;
  var car_tab = jQuery(".sync-coupon-container #cpn_tab2:checked").length > 0;
  var restau_tab = jQuery(".sync-coupon-container #cpn_tab3:checked").length > 0;
 
  if (hotel_tab == true) {
    jQuery(".coupon_type").val("hotel_coupon");
  }
  if (car_tab == true) {
    jQuery(".coupon_type").val("car_coupon");
  }
  if (restau_tab == true) {
    jQuery(".coupon_type").val("restau_coupon");
  }
  
  jQuery(".sync-coupon-container .sync_tab").click(function() {

    hotel_tab = jQuery(".sync-coupon-container #cpn_tab1:checked").length > 0;
    car_tab = jQuery(".sync-coupon-container #cpn_tab2:checked").length > 0;
    restau_tab = jQuery(".sync-coupon-container #cpn_tab3:checked").length > 0;

    console.log(hotel_tab);
    console.log(car_tab);
    console.log(restau_tab);

    if (hotel_tab == true) {
      jQuery(".coupon_type").val("hotel_coupon");
    }
    else if (car_tab == true) {
      jQuery(".coupon_type").val("car_coupon");
    }
    else if (restau_tab == true) {
      jQuery(".coupon_type").val("restau_coupon");
    }
    
  });

  var tmp_hotel = jQuery("#cpn_tab1").is(':checked');
  var tmp_car =  jQuery("#cpn_tab2").is(':checked');
  var tmp_restau =  jQuery("#cpn_tab3").is(':checked');

  if (tmp_hotel == true) {
    jQuery("#coupon_tab1").show();
  }
  if (tmp_car == true) {
    jQuery("#coupon_tab2").show();
  }
  if (tmp_restau == true) {
    jQuery("#coupon_tab3").show();
  }

  jQuery("#cpn_tab1").change( function () {

    var tmp_hotel = jQuery("#cpn_tab1").is(':checked');
    if (tmp_hotel == true ) {
      jQuery("#coupon_tab1").show();
      jQuery("#coupon_tab2").hide();
      jQuery("#coupon_tab3").hide();
    } 
    else {
      jQuery("#coupon_tab1").hide();
    }
  });
  
  jQuery("#cpn_tab2").change( function () {

    var tmp_car =  jQuery("#cpn_tab2").is(':checked');

    if (tmp_car == true ) {
      jQuery("#coupon_tab2").show();
      jQuery("#coupon_tab1").hide();
      jQuery("#coupon_tab3").hide();
    } 
    else {
      jQuery("#coupon_tab2").hide();
    }  
  });
  
  jQuery("#cpn_tab3").change( function () {

    var tmp_car =  jQuery("#cpn_tab3").is(':checked');

    if (tmp_car == true ) {
      jQuery("#coupon_tab3").show();
      jQuery("#coupon_tab1").hide();
      jQuery("#coupon_tab2").hide();
    } 
    else {
      jQuery("#coupon_tab3").hide();
    }  
  });
  
});

jQuery(".edit-btn.btn").click(function() {
  
  var coup_id = jQuery(this).val();
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "pass_value", id: coup_id },
    success: function(data){

      jQuery(".cpn_id").val(coup_id);
      jQuery(".coupon_quantity").val(data[0]["coupon_quantity"]);
      jQuery(".coupon_value").val(data[0]["coupon_value"]);
      jQuery(".sync_coupon_edit").modal('show');

    }
  });
});

jQuery(".edit-btn-car.btn").click(function() {
  
  var coup_id = jQuery(this).val();
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "pass_car_value", id: coup_id },
    success: function(data){

      jQuery(".cpn_id").val(coup_id);
      jQuery(".coupon_quantity").val(data[0]["coupon_quantity"]);
      jQuery(".coupon_value").val(data[0]["coupon_value"]);
      jQuery(".sync_coupon_car_edit").modal('show');

    }
  });
});

jQuery(".edit-btn-restau.btn").click(function() {
  
  var coup_id = jQuery(this).val();
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "pass_restau_value", id: coup_id },
    success: function(data){

      jQuery(".cpn_id").val(coup_id);
      jQuery(".coupon_quantity").val(data[0]["coupon_quantity"]);
      jQuery(".coupon_value").val(data[0]["coupon_value"]);
      jQuery(".sync_coupon_car_edit").modal('show');

    }
  });
});

jQuery(".btn-create-coupon").click(function () {
  jQuery(".hotel_coupon_form").show();
  jQuery(".btn-create-container").hide();
});

jQuery("#cancel_btn").click(function () {
  jQuery(".btn-create-container").show();
  jQuery(".hotel_coupon_form").hide();
});

jQuery(".btn-create-coupon_car").click(function () {
  jQuery(".car_coupon_form").show();
  jQuery(".btn-create-container-car").hide();
});

jQuery("#cancel_btn_car").click(function () {
  jQuery(".btn-create-container-car").show();
  jQuery(".car_coupon_form").hide();
});

jQuery(".btn-create-coupon_restau").click(function () {
  jQuery(".restau_coupon_form").show();
  jQuery(".btn-create-container-restau").hide();
});

jQuery("#cancel_btn_restau").click(function () {
  jQuery(".btn-create-container-restau").show();
  jQuery(".restau_coupon_form").hide();
});

</script>

<script>

jQuery(".btn.btn-default.sync-cancel-switch").click( function() {
  location.reload();
});

jQuery("#generate_code").click(function () {
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "append_coupon" },
    success: function(data){
      jQuery("#coupon_code").val(data);
    }
  });
});

jQuery("#generate_car_code").click(function () {
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "append_coupon_car" },
    success: function(data){
      jQuery("#coupon_code_car").val(data);
    }
  });
});

jQuery("#generate_restau_code").click(function () {
  jQuery.ajax({
    type: "POST",
    dataType: "json",
    url: easync_admin_ajax_directory.ajaxurl,
    data: { action: "append_coupon_restau" },
    success: function(data){
      jQuery("#coupon_code_restau").val(data);
    }
  });
});

</script>


