<?php

if (!class_exists('AHACHAT_WP_SETUP_API')): /****/
    class AHACHAT_WP_SETUP_API {
        public function __construct() {
        ?>
<div class="wrap">

<h1 class="wp-heading-inline"> <?php _e("Reminder Options",AHACHAT_WP);?></h1>

</div>


<form action="options.php" method="post">

	<?php

		settings_fields(AHACHAT_WP);

        $ahachat_app_id = get_option('ahachat_app_id');
        $ahachat_broadcast_token = get_option('ahachat_broadcast_token');
        $ahachat_page_name = get_option('ahachat_page_name');
        $ahachat_page_id = get_option('ahachat_page_id');
        $ahachat_app_message=get_option('ahachat_customize_message');
        $ahachat_enable_cart = get_option('ahachat_app_enable_status');
        $ahachat_enable_non_login_user = get_option('ahachat_non_login_user');
        $ahachat_enable_skipit_on_time = get_option('ahachat_is_skip_ontime');
        $ahachat_enable_checkbox_checkout = get_option('ahachat_enable_checkbox_checkout');
        $ahachat_enable_skip_checkbox = get_option('ahachat_is_skip_checkbox');
        $ahachat_app_test_mode = get_option('ahachat_is_test_mode');
        $ahachat_message_checkout=get_option('ahachat_customize_checkout_message');
        $ahachat_custom_skipit=get_option('ahachat_skip_message');
        $ahachat_enable_alow_user_add_cart=get_option('ahachat_allow_user_add_cart');
        $ahachat_first_reminder=get_option('ahachat_first_reminder');
        $ahachat_second_reminder=get_option('ahachat_second_reminder');
        $ahachat_third_reminder=get_option('ahachat_third_reminder');
        $ahachat_text_send = get_option('ahachat_text_send');
        $ahachat_coupon = get_option('ahachat_coupons');
        $ahachat_customize_coupon = get_option('ahachat_coupon_customize');
        $cart_ahachat_hide_product = get_option('ahachat_hide_product');
        $cart_ahachat_show_product = get_option('ahachat_show_product');
	?>

    <input type="hidden" name="ahachat_app_id" value="<?php echo $ahachat_app_id; ?>">

    <input type="hidden" name="ahachat_broadcast_token" value="<?php echo $ahachat_broadcast_token; ?>">

    <input type="hidden" name="ahachat_page_id" value="<?php echo $ahachat_page_id; ?>">

    <input type="hidden" name="ahachat_page_name" value="<?php echo $ahachat_page_name; ?>">

	<input type="hidden" name="ahachat_app_enable_status" value="<?php echo $ahachat_enable_cart; ?>">

	<input type="hidden" name="ahachat_non_login_user" value="<?php echo $ahachat_enable_non_login_user; ?>">

	<input type="hidden" name="ahachat_is_skip_ontime" value="<?php echo $ahachat_enable_skipit_on_time; ?>">

	<input type="hidden" name="ahachat_enable_checkbox_checkout" value="<?php echo $ahachat_enable_checkbox_checkout; ?>">

	<input type="hidden" name="ahachat_is_skip_checkbox" value="<?php echo $ahachat_enable_skip_checkbox; ?>">

	<input type="hidden" name="ahachat_allow_user_add_cart" value="<?php echo $ahachat_enable_alow_user_add_cart; ?>">

    <input type="hidden" name="ahachat_is_test_mode" value="<?php echo $ahachat_app_test_mode; ?>">

	<input type="hidden" name="ahachat_customize_message" value="<?php echo $ahachat_app_message; ?>">

	<input type="hidden" name="ahachat_customize_checkout_message" value="<?php echo $ahachat_message_checkout; ?>">

	<input type="hidden" name="ahachat_skip_message" value="<?php echo $ahachat_custom_skipit; ?>">

	<?php if(!empty($ahachat_customize_coupon)): ?>

	<?php if(isset($ahachat_customize_coupon['box_width']) && !empty($ahachat_customize_coupon['box_width'])): ?>

	<input type="hidden" name="ahachat_coupon_customize[box_width]" value="<?php echo $ahachat_customize_coupon['box_width']; ?>">

	<?php endif; ?>

	<?php if(isset($ahachat_customize_coupon['title_color']) && !empty($ahachat_customize_coupon['title_color'])): ?>

		<input type="hidden" name="ahachat_coupon_customize[title_color]" value="<?php echo $ahachat_customize_coupon['title_color']; ?>">

	<?php endif; ?>

	<?php if(isset($ahachat_customize_coupon['subtitle_color']) && !empty($ahachat_customize_coupon['title_color'])): ?>

		<input type="hidden" name="ahachat_coupon_customize[subtitle_color]" value="<?php echo $ahachat_customize_coupon['subtitle_color']; ?>">

	<?php endif; ?>

	<?php if(isset($ahachat_customize_coupon['background_color'])) :?>

		<input type="hidden" name="ahachat_coupon_customize[background_color]" value="<?php echo $ahachat_customize_coupon['background_color']; ?>">

	<?php endif;?>



	<?php if(isset($ahachat_customize_coupon['border_size'])) :?>

		<input type="hidden" name="ahachat_coupon_customize[border_size]" value="<?php echo $ahachat_customize_coupon['border_size']; ?>">

	<?php endif;?>

	<?php if(isset($ahachat_customize_coupon['border_style'])) :?>

		<input type="hidden" name="ahachat_coupon_customize[border_style]" value="<?php echo $ahachat_customize_coupon['border_style']; ?>">

	<?php endif;?>

	<?php if(isset($ahachat_customize_coupon['border_color'])) :?>

		<input type="hidden" name="ahachat_coupon_customize[border_color]" value="<?php echo $ahachat_customize_coupon['border_color']; ?>">

	<?php endif;?>



<?php endif; ?>

	<!--UPDATE COUPON-->

	<?php if(!empty($ahachat_text_send)):?>

	<input type="hidden" name="ahachat_text_send" value="<?php echo (isset($ahachat_text_send)) ? $ahachat_text_send : ''; ?>">

<?php endif;?>

<?php if(!empty($ahachat_coupon)): ?>

	<?php if(isset($ahachat_coupon['enable'])) : ?>

		<input type="hidden" name="ahachat_coupons[enable]" value="<?php echo (isset($ahachat_coupon['enable'])) ? 'on' : ''; ?>">

	<?php endif;?>

	<input type="hidden" name="ahachat_coupons[title]" value="<?php echo (isset($ahachat_coupon['title'])) ? $ahachat_coupon['title'] : '15% Discount'; ?>">

	<input type="hidden" name="ahachat_coupons[sub_title]" value="<?php echo (isset($ahachat_coupon['sub_title'])) ? $ahachat_coupon['sub_title'] : 'Get your 15% discount now by subscribing to our newsletter in facebook messenger. Just click the blue button below.'; ?>">

	<input type="hidden" name="ahachat_coupons[display]" value="<?php echo (isset($ahachat_coupon['display'])) ? $ahachat_coupon['display'] : 'evething'; ?>">

<?php endif;?>

<?php if(!empty($cart_ahachat_hide_product)): ?>

		<input type="hidden" name="ahachat_hide_product" value="<?php echo (isset($cart_ahachat_hide_product)) ? $cart_ahachat_hide_product : ''; ?>">

<?php endif;?>

<?php if(!empty($cart_ahachat_show_product)): ?>

		<input type="hidden" name="ahachat_show_product" value="<?php echo (isset($cart_ahachat_show_product)) ? $cart_ahachat_show_product : ''; ?>">

<?php endif;?>

	<!--UPDATE COUPON-->
    <?php
    $args = array('posts_per_page' => 1, 'post_type' => 'product','orderby' => 'date' ,'order' => 'DESC', 'post_status'=>'publish');

    $product_lasted = new WP_Query($args);

    foreach ($product_lasted->posts as $key => $product) {

        $_product = wc_get_product( $product->ID );

        $product_img = get_the_post_thumbnail_url($product->ID,"medium");

        $product_title=get_the_title($product->ID);

        $product_link=get_the_permalink($product->ID);

        $product_price=$_product->get_price_html();
    }
    ?>
	<section class="full-width">
        <div class="ahachat-ac-container">
            <div class="ahachat-ac-setting">
                <div class="ahachat-reminder-box">
                    <div class="aha-remin-head">
                        <?php _e('After customers click Add to Cart, customers will receive this message',AHACHAT_WP)?>
                        <select style="width:50px;height: 28px;" id="ahachat_first_reminder_select" name="ahachat_first_reminder[hour]">
                            <?php for($i=1;$i<=24;$i++) : ?>
                                <option <?php if(isset($ahachat_first_reminder["hour"]) && $ahachat_first_reminder["hour"] ==$i) echo "selected='selected'"; ?> value="<?php echo $i; ?>"><?php echo $i;?><?php _e('h',AHACHAT_WP)?></option>
                            <?php endfor;?>
                        </select>
                        <?php _e('hours later.',AHACHAT_WP)?>
                        <label class="ahachat-switch-button top-right">
                            <input <?php if(isset($ahachat_first_reminder["on_of"]) && $ahachat_first_reminder["on_of"]=="on") echo "checked='checked'"; ?>  name="ahachat_first_reminder[on_of]" class="ahachat-switch-button-input ahachat_first_reminder_on_off" type="checkbox" />
                            <span class="ahachat-switch-button-label" data-on="Yes" data-off="No"></span>
                            <span class="ahachat-switch-button-handle"></span>
                        </label>
                    </div>
                    <div class="aha-remin-body">
                        <input class="messenger__msg full-width" type="text" required="" id="something_first_input" name="ahachat_first_reminder[something]" placeholder="Leave something behind?" value="<?php if(isset($ahachat_first_reminder['something'])) echo $ahachat_first_reminder['something']; else echo 'Leave something behind?';?>">
                    </div>
                    <div class="aha-remin-footer">
                        <p>Call-To-Action Button</p>
                        <div>
                            <input class="messenger__msg" type="text" required="" id="checkout_input_1" name="ahachat_first_reminder[checkout]" placeholder="Checkout Now" value="<?php if(isset($ahachat_first_reminder['checkout'])) echo $ahachat_first_reminder['checkout']; else echo 'Checkout Now';?>">
                        </div>
                    </div>
                </div>
                <div class="ahachat-reminder-box">
                    <div class="aha-remin-head">
                       <?php _e('Add-to-cart users will receive this message',AHACHAT_WP)?>
                        <select style="width:50px;height: 28px;" class="ahachat_second_reminder ahachat_second_reminder_select" id="ahachat_second_reminder_select" name="ahachat_second_reminder[hour]">
                            <?php for($i=1;$i<=24;$i++) : ?>
                                <option <?php if(isset($ahachat_second_reminder["hour"]) && $ahachat_second_reminder["hour"] ==$i) echo "selected='selected'"; ?> value="<?php echo $i; ?>"><?php echo $i;?><?php _e('h',AHACHAT_WP)?></option>
                            <?php endfor;?>
                        </select>
                       <?php _e('hours after the first reminder.',AHACHAT_WP)?>
                       <label class="ahachat-switch-button top-right">
                           <input <?php if(isset($ahachat_second_reminder["on_of"]) && $ahachat_second_reminder["on_of"]=="on") echo "checked='checked'"; ?>  name="ahachat_second_reminder[on_of]" class="ahachat-switch-button-input ahachat_first_reminder_on_off" type="checkbox" />
                           <span class="ahachat-switch-button-label" data-on="Yes" data-off="No"></span>
                           <span class="ahachat-switch-button-handle"></span>
                       </label>
                    </div>
                    <div class="aha-remin-body">
                        <input class="messenger__msg full-width" type="text" id="something_second_input" name="ahachat_second_reminder[something]" placeholder="Your cart is about to expire!" value="<?php if(isset($ahachat_second_reminder['something'])) echo $ahachat_second_reminder['something']; else echo 'Your cart is about to expire!';?>">
                    </div>
                    <div class="aha-remin-footer">
                        <p>Call-To-Action Button</p>
                        <div>
                            <input class="messenger__msg" type="text" id="checkout_input_2" name="ahachat_second_reminder[checkout]" placeholder="Checkout Now" value="<?php if(isset($ahachat_second_reminder['checkout'])) echo $ahachat_second_reminder['checkout']; else echo 'Checkout Now';?>">
                        </div>
                    </div>
                </div>
                <div class="ahachat-reminder-box">
                    <div class="aha-remin-head">
                        <?php _e('Add-to-cart users will receive this message',AHACHAT_WP)?>
                        <select style="width:50px;height: 28px;" class="ahachat_third_reminder ahachat_third_reminder_select" id="ahachat_third_reminder_select" name="ahachat_third_reminder[hour]">
                            <?php for($i=1;$i<=24;$i++) : ?>
                                <option <?php if(isset($ahachat_third_reminder["hour"]) && $ahachat_third_reminder["hour"] ==$i) echo "selected='selected'"; ?> value="<?php echo $i; ?>"><?php echo $i;?><?php _e('h',AHACHAT_WP)?></option>
                            <?php endfor;?>
                        </select>
                        <?php _e('hours after the first and second reminder.',AHACHAT_WP)?>
                        <label class="ahachat-switch-button top-right">
                            <input <?php if(isset($ahachat_first_reminder["on_of"]) && $ahachat_first_reminder["on_of"]=="on") echo "checked='checked'"; ?>  name="ahachat_first_reminder[on_of]" class="ahachat-switch-button-input ahachat_first_reminder_on_off" type="checkbox" />
                            <span class="ahachat-switch-button-label" data-on="Yes" data-off="No"></span>
                            <span class="ahachat-switch-button-handle"></span>
                        </label>
                    </div>
                    <div class="aha-remin-body">
                        <input class="messenger__msg full-width" type="text" id="something_third_input" name="ahachat_third_reminder[something]" placeholder="Your cart is about to expire!" value="<?php if(isset($ahachat_third_reminder['something'])) echo $ahachat_third_reminder['something']; else echo 'Your cart is about to expire!';?>">
                    </div>
                    <div class="aha-remin-footer">
                        <p>Call-To-Action Button</p>
                        <div>
                            <input class="messenger__msg" type="text" id="checkout_input_3" name="ahachat_third_reminder[checkout]" placeholder="Checkout Now" value="<?php if(isset($ahachat_third_reminder['checkout'])) echo $ahachat_third_reminder['checkout']; else echo 'Checkout Now';?>">
                        </div>
                    </div>
                </div>
            </div>
            <div class="ahachat-ac-preview">
                <div class="text-center ahachat_phone_container col-auto">
                    <div class="ahachat_phone_content_1 ahachat_phone_content_2 ahachat_phone_content_3">
                        <div class="ahachat_phone_content_div_1"></div>
                        <div class="ahachat_phone_content_div_2"></div>
                        <div class="ahachat_phone_content_div_3">
                            <div class="ahachat_phone_content_div_4_1 ahachat_phone_content_div_4_2">
                                <div class="ahachat_phone_content_div_5">
                                    <div><span class="ahachat_phone_content_span_1"><i class="ahachat_phone_content_i_1 ahachat_phone_content_i_2"></i><span class="ahachat_phone_content_span_2">Back</span></span>
                                    </div>
                                    <div class="ahachat_phone_content_div_6">
                                        <div class="ahachat_phone_content_div_7">
                                            <div class="ahachat_phone_content_div_8"><span class="ahachat_phone_content_div_9"><?php echo $ahachat_page_name; ?></span><i class="i-keyboard_arrow_right ahachat_phone_content_i_3"></i></div>
                                        </div>
                                        <div class="ahachat_phone_content_div_10_1 ahachat_phone_content_div_10_2"><span>Typically replies instantly</span>
                                        </div>
                                    </div>
                                    <div><span class="ahachat_phone_content_span_1"><span>Manage</span></span>
                                    </div>
                                </div>
                            </div>
                            <div class="ahachat_phone_content_div_11">
                                <div class="ahachat_phone_content_div_12">
                                    <div class="p-a-sm">
                                        <div class="ahachat_phone_content_div_13 ahachat_show_custom_text_not_list_product">
                                            <div class="clearfix">
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="_1hbKwGBfQZcGesLiE9VSN8 clearfix _2hCUWe1ICZtOnr4162RbNv qkGQ6r7HU9GM1IGycvLCk">
                                                        <span style="" id="tooltip_show_empty_1" tooltip="Please enter a text." flow="right"><div class="ahachat_phone_content_div_15_1 ahachat_phone_content_div_15_2 ahachat_text_preiew" style="border-bottom-left-radius: 0;border-color: rgb(241, 240, 240);"><div class="ahachat_phone_content_div_16"><div class="ahachat_phone_content_div_17" style="outline: none; white-space: pre-wrap; word-wrap: break-word;"><p><span><span><span>​<span id="txt_preview_1"></span></span></span></span></p></div></div></div>
                                                            <div class="messenger_abandoned_cart">
                                                                <div class="messenger__msg ahachat_frame in m-b-0">
                                                                    <img max-height="150" max-width="240" src="<?php echo $product_img; ?>">
                                                                    <div class="info">
                                                                        <span class="title"><?php echo $product_title; ?></span><br>
                                                                        <span class="body ahachat_ad_price" style="color: #bcbcbc;

                                  text-decoration: none;"><?php echo $product_price; ?> - <?php echo $product_title; ?></span><br>
                                                                        <span class="body subdued"><a class="ahachat_product_link" target="_blank" href="<?php echo $product_link; ?>"><?php echo home_url(); ?></a></span>
                                                                    </div>
                                                                    <div class="actions">
                                                                        <div class="messenger__unit in" style="margin-top:0px;">
                                                                            <span id="checkout_text_1">Checkout now</span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </span>
                                                    </div>
                                                </div>
                                                <div class="ahachat_phone_content_div_17_1 ahachat_phone_content_div_17_2 ahachat_phone_content_div_17_3" style="width: 32px; height: 32px;"><img src="https://i.imgur.com/1Dfpchn.png"></div>
                                            </div>
                                            <div>
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="ahachat_phone_content_div_18"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="p-a-sm">
                                        <div class="ahachat_phone_content_div_13 ahachat_show_custom_text_not_list_product">
                                            <div class="clearfix">
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="_1hbKwGBfQZcGesLiE9VSN8 clearfix _2hCUWe1ICZtOnr4162RbNv qkGQ6r7HU9GM1IGycvLCk">
                                                        <span style="" id="tooltip_show_empty_2" tooltip="Please enter a text." flow="right"><div class="ahachat_phone_content_div_15_1 ahachat_phone_content_div_15_2 ahachat_text_preiew" style="border-bottom-left-radius: 0;border-color: rgb(241, 240, 240);"><div class="ahachat_phone_content_div_16"><div class="ahachat_phone_content_div_17" style="outline: none; white-space: pre-wrap; word-wrap: break-word;"><p><span><span><span>​<span id="txt_preview_2"></span></span></span></span></p></div></div></div>
                                                            <div class="messenger_abandoned_cart">
                                                                <div class="messenger__msg ahachat_frame in m-b-0">
                                                                    <img max-height="150" max-width="240" src="<?php echo $product_img; ?>">
                                                                    <div class="info">
                                                                        <span class="title"><?php echo $product_title; ?></span><br>
                                                                        <span class="body ahachat_ad_price" style="color: #bcbcbc;

                                  text-decoration: none;"><?php echo $product_price; ?> - <?php echo $product_title; ?></span><br>
                                                                        <span class="body subdued"><a class="ahachat_product_link" target="_blank" href="<?php echo $product_link; ?>"><?php echo home_url(); ?></a></span>
                                                                    </div>
                                                                    <div class="actions">
                                                                        <div class="messenger__unit in" style="margin-top:0px;">
                                                                            <span id="checkout_text_2">Checkout now</span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </span>
                                                    </div>
                                                </div>
                                                <div class="ahachat_phone_content_div_17_1 ahachat_phone_content_div_17_2 ahachat_phone_content_div_17_3" style="width: 32px; height: 32px;"><img src="https://i.imgur.com/1Dfpchn.png"></div>
                                            </div>
                                            <div>
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="ahachat_phone_content_div_18"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="p-a-sm">
                                        <div class="ahachat_phone_content_div_13 ahachat_show_custom_text_not_list_product">
                                            <div class="clearfix">
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="_1hbKwGBfQZcGesLiE9VSN8 clearfix _2hCUWe1ICZtOnr4162RbNv qkGQ6r7HU9GM1IGycvLCk">
                                                        <span style="" id="tooltip_show_empty_3" tooltip="Please enter a text." flow="right"><div class="ahachat_phone_content_div_15_1 ahachat_phone_content_div_15_2 ahachat_text_preiew" style="border-bottom-left-radius: 0;border-color: rgb(241, 240, 240);"><div class="ahachat_phone_content_div_16"><div class="ahachat_phone_content_div_17" style="outline: none; white-space: pre-wrap; word-wrap: break-word;"><p><span><span><span>​<span id="txt_preview_3"></span></span></span></span></p></div></div></div>
                                                            <div class="messenger_abandoned_cart">
                                                                <div class="messenger__msg ahachat_frame in m-b-0">
                                                                    <img max-height="150" max-width="240" src="<?php echo $product_img; ?>">
                                                                    <div class="info">
                                                                        <span class="title"><?php echo $product_title; ?></span><br>
                                                                        <span class="body ahachat_ad_price" style="color: #bcbcbc;

                                  text-decoration: none;"><?php echo $product_price; ?> - <?php echo $product_title; ?></span><br>
                                                                        <span class="body subdued"><a class="ahachat_product_link" target="_blank" href="<?php echo $product_link; ?>"><?php echo home_url(); ?></a></span>
                                                                    </div>
                                                                    <div class="actions">
                                                                        <div class="messenger__unit in" style="margin-top:0px;">
                                                                            <span id="checkout_text_3">Checkout now</span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </span>
                                                    </div>
                                                </div>
                                                <div class="ahachat_phone_content_div_17_1 ahachat_phone_content_div_17_2 ahachat_phone_content_div_17_3" style="width: 32px; height: 32px;"><img src="https://i.imgur.com/1Dfpchn.png"></div>
                                            </div>
                                            <div>
                                                <div class="ahachat_phone_content_div_14_1 ahachat_phone_content_div_14_2">
                                                    <div class="ahachat_phone_content_div_18"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div style="clear: both;"></div>
            <div style="clear: both;"></div>
            <?php submit_button(); ?>
        </div>
	</section>
</form>
<script>
    jQuery(function($) {
        $('#txt_preview_1').html($('#something_first_input').val());
        $('#txt_preview_2').html($('#something_second_input').val());
        $('#txt_preview_3').html($('#something_third_input').val());
        $('#something_first_input').keyup(function() {
            $('#txt_preview_1').html($(this).val());
        });
        $('#something_second_input').keyup(function() {
            $('#txt_preview_2').html($(this).val());
        });
        $('#something_third_input').keyup(function() {
            $('#txt_preview_3').html($(this).val());
        });

        $('#checkout_text_1').html($('#checkout_input_1').val());
        $('#checkout_text_2').html($('#checkout_input_2').val());
        $('#checkout_text_3').html($('#checkout_input_3').val());
        $('#checkout_input_1').keyup(function() {
            $('#checkout_text_1').html($(this).val());
        });
        $('#checkout_input_2').keyup(function() {
            $('#checkout_text_2').html($(this).val());
        });
        $('#checkout_input_3').keyup(function() {
            $('#checkout_text_3').html($(this).val());
        });
    });
</script>
<?php
           }
       }
   endif;
   new AHACHAT_WP_SETUP_API();
?>
