<?php
/**
 * Created by PhpStorm.
 * User: Villatheme-Thanh
 * Date: 08-06-19
 * Time: 12:01 PM
 */

namespace WACVP\Inc\Settings;

use WACVP\Inc\Functions;
use WP_Roles;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class General_Settings extends Admin_Settings {

	protected static $instance = null;

	public function __construct() {
	}

	public static function get_instance() {

		if ( null == self::$instance ) {
			self::$instance = new self;
		}

		return self::$instance;
	}

	public function setting_page() {
		?>
        <div class="vi-ui bottom attached active tab segment tab-admin" data-tab="general">
            <h4><?php esc_html_e( 'Cart', 'woo-abandoned-cart-recovery' ) ?></h4>
            <table class="wacv-table">
				<?php
				$this->checkbox_option( 'tracking_member', esc_html__( "Tracking Member's Cart", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enable, the plugin will track abandoned cart of logged users', 'woo-abandoned-cart-recovery' ) );
				$this->number_option( 'member_cut_off_time', esc_html__( 'Abandoned Cart time for Members', 'woo-abandoned-cart-recovery' ), esc_html__( 'Select the time to mark a cart as abandoned with logged in users', 'woo-abandoned-cart-recovery' ), 'minutes' );
				$this->checkbox_option( 'tracking_guest', esc_html__( "Tracking Guest's Cart", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enable, the plugin will track abandoned cart of guests', 'woo-abandoned-cart-recovery' ) );
				$this->number_option( 'guest_cut_off_time', esc_html__( 'Abandoned Cart time for Guest', 'woo-abandoned-cart-recovery' ), esc_html__( 'Select the time to mark a cart as abandoned with guests', 'woo-abandoned-cart-recovery' ), 'minutes' );
				$this->checkbox_option( 'tracking_require_email', esc_html__( "Tracking if email available", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enabled, the plugin will only track abandoned carts of guests if the input email is available', 'woo-abandoned-cart-recovery' ) );
				$this->number_option( 'block_record_ip', esc_html__( 'Block IP record', 'woo-abandoned-cart-recovery' ), esc_html__( 'If an IP address already has an abandoned record, this option will prevent new abandoned carts from being recorded during this period. Leave blank to disable.', 'woo-abandoned-cart-recovery' ), 'days', false, 0, 9999, false );
				$this->number_option( 'delete_record_time', esc_html__( 'Delete abandoned records', 'woo-abandoned-cart-recovery' ), esc_html__( 'Abandoned cart records will be automatically deleted after this time', 'woo-abandoned-cart-recovery' ), 'days' );

				$tracking_user_exclude_opts = array();
				if ( is_array( self::get_field( 'tracking_user_exclude' ) ) && count( self::get_field( 'tracking_user_exclude' ) ) > 0 ) {
					foreach ( get_users( array( 'include' => self::get_field( 'tracking_user_exclude' ) ) ) as $user ) {
						$tracking_user_exclude_opts[ $user->ID ] = $user->user_nicename;
					}
				}
				$this->select_option( 'tracking_user_exclude', $tracking_user_exclude_opts, esc_html__( "Exclude people", 'woo-abandoned-cart-recovery' ), '', '', true );

				global $wp_roles;
				if ( ! isset( $wp_roles ) ) {
					$wp_roles = new WP_Roles();
				}
				$roles = $wp_roles->roles;
				$roles_names = wp_list_pluck( $roles, 'name' );
				$this->select_option('tracking_role_exclude', $roles_names,
					esc_html__( "Exclude user role", 'woo-abandoned-cart-recovery' ), '', '', true );
				$this->text_option( 'exclude_email_provider', esc_html__( 'Send email exclude provider', 'woo-abandoned-cart-recovery' ), '', '', false, esc_html__( 'Split email provider by "," eg: @dev.com,@track.net', 'woo-abandoned-cart-recovery' ) );
				$this->number_option( 'exclude_min_cart_total', esc_html__( 'Send email minimum cart total', 'woo-abandoned-cart-recovery' ), esc_html__( 'Only send email for abandoned cart with cart total value higher this value. Leave blank to disable.', 'woo-abandoned-cart-recovery' ), '', false, 0, 'unset', false );

				$this->select_option(
					'direct_recover_link',
					[ esc_html__( 'Cart page', 'woo-abandoned-cart-recovery' ), esc_html__( 'Checkout page', 'woo-abandoned-cart-recovery' ) ],
					esc_html__( "Recover link to", 'woo-abandoned-cart-recovery' ) );

				$this->checkbox_option( 'enable_immediate_detail', esc_html__( "Immediate show Cart detail in Abandoned list", 'woo-abandoned-cart-recovery' ), esc_html__( 'Enable to display the Cart detail, no need click to view cart details', 'woo-abandoned-cart-recovery' ) );
				$this->checkbox_option( 'enable_order_page', esc_html__( "Show Abandoned order options in Admin Order", 'woo-abandoned-cart-recovery' ), esc_html__( 'Enable to display the Send abandoned email buttons and the column of Abandoned email sending status in the Admin Order List Page; Display the Send abandoned email buttons on the order editing page.', 'woo-abandoned-cart-recovery' ) );
				$this->checkbox_option( 'enable_cart_log', esc_html__( "Cart logs", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enable, add to cart or remove cart action will be record.', 'woo-abandoned-cart-recovery' ) );
				$this->time_button_option( 'clear_cart_logs', esc_html__( "Clear cart logs", 'woo-abandoned-cart-recovery' ), esc_html__( 'Clear cart log table from input date.', 'woo-abandoned-cart-recovery' ), '', false, false, esc_html__( 'Clear logs', 'woo-abandoned-cart-recovery' ) );
				$this->checkbox_option( 'enable_checkout_initial', esc_html__( "Load guest information", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enable, load guest information checkout page if the guest already saved.', 'woo-abandoned-cart-recovery' ) );
				$this->checkbox_option( 'enable_fill_full_phone', esc_html__( "Load full phone number", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enabled, load guest phone number with the country code on the checkout page if the guest has already saved.', 'woo-abandoned-cart-recovery' ) );
				$this->checkbox_option( 'enable_checkout_gdpr', esc_html__( "Checkout GDPR", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enabled, a GDPR notice will display after the email input field on the checkout page.', 'woo-abandoned-cart-recovery' ) );
				$this->text_option( 'checkout_gdpr_message', esc_html__( 'GDPR message', 'woo-abandoned-cart-recovery' ), '', '', true );
				$this->text_option( 'checkout_gdpr_cancel', esc_html__( 'Ignore Email Button Text', 'woo-abandoned-cart-recovery' ), '', '', true );
				?>
            </table>
            <hr>

            <table class="wacv-table">
                <tr class="vlt-row vlt-margin-top">
                    <td class="vlt-third vlt-margin-bottom-8 col-1">
                        <label style="font-weight: bold" class=""><?php esc_html_e( 'Cron job' ) ?></label>
                    </td>
                    <td class="vlt-twothird vlt-row col-2">
				        <?php
				        $cron_command = site_url() . '/wp-cron.php';
				        if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
					        ?>
                            <p>
						        <?php esc_html_e( "Your WP Cron is disabled. If you want to use WP Cron, open file wp-config.php and delete row define( \"DISABLE_WP_CRON\", true );.", 'woo-abandoned-cart-recovery' ); ?>
                            </p>
                            <p>
						        <?php esc_html_e( " If you want to use CronJob server, access your server and config with command:", 'woo-abandoned-cart-recovery' ); ?>
                            </p>
                            <p>
                                <input type="text" value="<?php echo( " * * * * * curl " . esc_attr( $cron_command ) ) ?>" readonly>
                            </p>
							<?php
						} else {
							?>
                            <p>
								<?php esc_html_e( "Your WP Cron is enabled. If you want to use Cronjob server, open file wp-config.php and add row define( \"DISABLE_WP_CRON\", true );. Access your server and config with command:", 'woo-abandoned-cart-recovery' ); ?>
                            </p>
                            <div class="wacv-input-readonly-block">
                                <input type="text" class="wacv-readonly"
                                       value="<?php echo( " * * * * * curl " . esc_attr( $cron_command ) ) ?>" readonly>
                                <span class="wacv-copy-icon">
                                  <i class="copy outline icon"></i>
                                </span>
                            </div>
				        <?php }
				        ?>
                    </td>
                    <td class="col-3"></td>
                </tr>
                <!--				--><?php //$this->checkbox_option( 'enable_cron_server', esc_html__( "Enable cron server", 'woo-abandoned-cart-recovery' ), esc_html__( 'If enable, command from Cron server will be accepted', 'woo-abandoned-cart-recovery' ) ); ?>
            </table>
        </div>
		<?php
	}

	//Email Rules

}
