<?php
if( ! defined( 'ABSPATH' ) ) exit;
if(!is_admin()) {
	session_start();
	global $wpdb, $post, $errors_config_restau;

	if(!empty($errors_config_restau) && is_user_logged_in()==true) {
		?><h3>Please configure the following on eaSYNC Booking settings:</h3><span>Go to your backend and find "eaSYNC Booking" on the sidebar and click "Settings" then click the "General" and click "Restaurant Reservation"</span><ul><?php
		foreach ($errors_config_restau as $error) {
			?>
			<li><?php echo esc_html($error); ?></li>
			<?php
		}
		exit;
		?></ul><?php
	}elseif(!empty($errors_config_restau) && is_user_logged_in()==false){
		?><h3>This module is currently under maintenance, check back soon!</h3><?php
		exit;
	}	
?>

<div class="sync_form_wrapper_set sync_check_reservation" style="display:none;">
    <div class="go_back">
        <span class="back_text"><i class="fa fa-arrow-left"></i> Back</span>
    </div>
    <div class="ref_head">
        <h2>Search Reservation</h2>
    </div>
    <div class="get_reference">
        <input type="text" class="ref_number" name="ref_number" placeholder="Enter Reference Number" >
        <span class="search_ref_restau"> Search </span>
    </div>
</div>

<div class="reserve_table_wrapper">
    <?php
        include ('select-date.php');
        include ('restau-table.php');
    ?>
</div>

<div class="modall sync-transform fade sync-modal-reserve-notFound" id="reserve_notFound" tabindex="-1" role="dialog" aria-labelledby="customer-infoLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false" >
    <div class="modal-dialog modal-md" role="document" data-keyboard="false">
        <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close" >
            <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-bodyy">
                <div class="rental-details">
                    <h3>No Record Found.</h3>
                </div>
                <br>
                <div class="button_close">
                    <input class="close_modal" type="button" value="Close" data-dismiss="modal">
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modall sync-transform fade sync-modal-reservation-info" id="show_cancel" tabindex="-1" role="dialog" aria-labelledby="customer-infoLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false" >
    <div class="modal-dialog" role="document" data-keyboard="false">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" data-toggle="modal" data-targett="#customer_info">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-bodyy">
                <div class="cancel_content">
                    <div class="cancel_body">
                        <div class="cancel_details">
                            <div class="breakdown_label">
                                <h2>Cancellation Cost Breakdown</h2>
                            </div>
                            <br>
                            <div class="breakdown_details">
                                <div class="breakdown_labels">

                                </div>
                                <div class="space">

                                </div>
                                <div class="breakdown_calculation">

                                </div>
                            </div>
                            <hr style="border: 1px solid;">
                            <div class="return_details">
                                <div class="return_label">

                                </div>
                                <div class="space">

                                </div>
                                <div class="return_amount">

                                </div>
                            </div>
                            <br>
                        </div>
                        <div class="cancel_action">
                            <input class="confirm_cancel_restau" type="button" value="Confirm" id="">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modall sync-transform fade sync-modal-reservation-info" id="reservation_info_restau" tabindex="-1" role="dialog" aria-labelledby="customer-infoLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false" >
    <div class="modal-dialog" role="document" data-keyboard="false">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" >
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-bodyy">
                <div class="cancel_content">
                    <div class="reservation-details">
                        <div class="cust_name">
                        </div>
                        <br>
                        <div class="reservation_details">
                            <div class="person_email">
                            </div>
                            <div class="person_phone">
                            </div>
                        </div>
                        <div class="reservation_details">
                            <div class="menu_name">
                            </div>
                        </div>
                        <br>
                        <div class="reservation_details">
                            <div class="reservation_date">
                            </div>
                            <div class="reservation_time">
                            </div>
                            <div class="reservation_branch">
                            </div>
                            <div class="reservation_table">
                            </div>
                            <div class="reservation_guests">
                            </div>
                            <div class="reservation_paid">
                            </div>
                        </div>
                        <br>
                        <div class="cancel_section">	
                            <?php
                                $table_name = $wpdb->prefix . 'sync_options';
                                $get_val = $wpdb->get_results($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", 'sync_car_grace_period')); ?>
                            <span class="note" style="text-align: left;"><strong>Note:</strong> Cancellations are only allowed <?php echo $get_val[0]->option_value; ?> days prior to booked date.</span>
					
                            <?php 
                                $val_array = array('sync_restau_grace_period', 'sync_restau_refund_rate');
                                $placeholders = implode(',', array_fill(0, count($val_array), '%s'));
                                $check = $wpdb->get_results($wpdb->prepare("SELECT * from $table_name  where option_name IN ($placeholders)", $val_array));
                                if( (!empty($check[0]->option_value)) && (!empty($check[1]->option_value))) { ?>
                                    <input class="cancel_reservation" type="button" value="Cancel Reservation" id="">
                                <?php } 
                            ?>
                        </div>
                        <br>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modall sync-transform fade sync-modal-reservation-info" id="cancel_success" tabindex="-1" role="dialog" aria-labelledby="customer-infoLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false" >
    <div class="modal-dialog" role="document" data-keyboard="false">
        <div class="modal-content">
            <div class="modal-bodyy">
                <div class="cancel_content">
                    <div class="cancel_body">
                        <h2>Cancellation Request Sent.</h2>
                        <div class="sub_content">
                            <span class="content">Please allow 1-2 business days to review and assist you with your request.</span>
                        </div>
                        <br>
                        <div class="button_close" style="text-align:center;">
                            <input class="close_modal restau" type="button" value="Close">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php } ?>