<?php
/**
 * Created by PhpStorm.
 * User: Villatheme-Thanh
 * Date: 26-06-19
 * Time: 2:27 PM
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div id="wacv-modal" class="wacv-modal-get-email template-1" tabindex="-1" <?php echo $param['enable_captcha'] && is_cart() ? '' : 'style="display: none;"' ?>>
    <div class="wacv-modal-wrapper">
        <div class="wacv-modal-content">
			<?php if ( ! $param['info_require'] && ! $param['phone_require'] ) : ?>
                <span class="wacv-close-popup">&times;</span>
			<?php endif; ?>
            <div class="wacv-container">
                <div class="wacv-get-email-title">
					<?php  if ( $lang ) { echo esc_html( stripslashes( $param['title_popup_' . $lang] ) ); }
					    else { echo esc_html( stripslashes( $param['title_popup'] ) ); } ?>
                </div>
                <div class="wacv-get-email-sub-title">
					<?php if ( $lang ) { echo esc_html( stripslashes( $param['sub_title_popup_' . $lang] ) ); }
					    else { echo esc_html( stripslashes( $param['sub_title_popup'] ) ); } ?>
                </div>

				<?php if ( $param['email_field'] ) { ?>
                    <div class="wacv-email-invalid-notice" style="color:red;">
						<?php if ( $lang ) { echo esc_html( stripslashes( $param['invalid_email_' . $lang] ) ); }
						    else { echo esc_html( stripslashes( $param['invalid_email'] ) ); } ?>
                    </div>
                    <div>
                        <input type="text" class="wacv-popup-input-email" placeholder="<?php esc_attr_e( 'Email', 'woo-abandoned-cart-recovery' ); ?>">
                    </div>
				<?php } ?>

				<?php if ( $param['phone_field'] ) { ?>
                    <div class="wacv-phone-number-invalid-notice" style="color:red;">
						<?php if ( $lang ) { echo esc_html( stripslashes( $param['invalid_phone_' . $lang] ) ); }
						    else { echo esc_html( stripslashes( $param['invalid_phone'] ) ); } ?>
                    </div>
                    <div class="wacv-get-customer-phone-number">
						<?php
						$codes = include WC()->plugin_path() . '/i18n/phone.php';
						ksort( $codes );
                        $get_def_country = $param['def_phone_country'];
                        if ( empty( $get_def_country ) ) {
	                        $locate         = WC_Geolocation::geolocate_ip();
	                        $detect_country = $locate['country'] ?? '';
                        } else {
	                        $detect_country = '';
                            foreach ( $codes as $c_country => $c_code ) {
                                if ( is_array( $c_code ) ) {
                                    if ( in_array( $get_def_country, $c_code ) ) $detect_country = $c_country;
                                } else {
                                    if ( $get_def_country == $c_code ) $detect_country = $c_country;
                                }
                            }
                        }
						?>
                        <select class="wacv-country-calling-code">
							<?php

							foreach ( $codes as $country => $code ) {
								if ( ! $code ) {
									continue;
								}

								$selected = $detect_country == $country ? 'selected' : '';

								if ( is_array( $code ) ) {
									foreach ( $code as $c ) {
										$selected = $c == current( $code ) ? $selected : '';
										printf( '<option value="%s" %s>%s (%s)</option>', esc_attr( $c ), esc_attr( $selected ), esc_html( $country ), esc_html( $c ) );
									}
								} else {
									printf( '<option value="%s" %s>%s (%s)</option>', esc_attr( $code ), esc_attr( $selected ), esc_html( $country ), esc_html( $code ) );
								}
							}
							?>
                        </select>
                        <input type="text" class="wacv-popup-input-phone-number" placeholder="<?php esc_attr_e( 'Phone number', 'woo-abandoned-cart-recovery' ); ?>">
                    </div>
				<?php }


				if ( $param['enable_captcha'] ) {
					?>
                    <div class="wacv-recaptcha-field">
                        <div  class="wacv-recaptcha"></div>
                        <input type="hidden" value="" class="wacv-g-validate-response">
                    </div>
					<?php
				}

				if ( $param['enable_gdpr'] && $param['gdpr_content'] ) {
					?>
                    <div class="wacv-gdpr-group">
                        <input type="checkbox" class="wacv-gdpr-checkbox">
                        <span class="wacv-gdpr-content">
                            <?php if ( $lang ) { echo wp_kses_post( html_entity_decode( $param['gdpr_content_' . $lang] ) ); }
                            else { echo wp_kses_post( html_entity_decode( $param['gdpr_content'] ) ); } ?>
                        </span>
                    </div>
				<?php } ?>

                <div class="wacv-get-email-btn-group">
                    <button type="button" class="wacv-get-email-btn wacv-add-to-cart-btn wacv-btn-first">
						<?php if ( $lang ) { echo esc_html( stripslashes( $param['add_to_cart_btn_' . $lang] ) ); }
						    else { echo esc_html( stripslashes( $param['add_to_cart_btn'] ) ); } ?>
                    </button>
                    <?php if ( ! $param['info_require'] && ! $param['phone_require'] ) :
                        if ( $lang ) {
                            if ( ! empty( $param['popup_close_text_' . $lang] ) ) { ?>
                                <div class="wacv-close-popup wacv-close-text"><?php echo esc_html( $param['popup_close_text_' . $lang] )?></div>
                        <?php }
                        } else {
                            if ( ! empty( $param['popup_close_text'] ) )?>
                                <div class="wacv-close-popup wacv-close-text"><?php echo esc_html( $param['popup_close_text'] )?></div>
                        <?php }
                    endif; ?>
                </div>
				<?php do_action( 'wacv_popup_footer' ); ?>
            </div>
        </div>
    </div>
</div>
