<?php

if (! defined('ABSPATH')) {
	exit; // Exit if accessed directly.
}

add_action('admin_menu', 'prwfr_setting_api_tabs');

/**
 * Add options page first.
 */
function prwfr_setting_api_tabs()
{
	add_menu_page('', __('Product Recommendations', 'sft-product-recommendations-for-woocommerce'), 'manage_options', 'prwfr_menu', 'prwfr__rvp_setting_tabs');
	add_submenu_page('prwfr_menu', '', __('Post-Purchase', 'sft-product-recommendations-for-woocommerce'), 'manage_options', 'prwfr_post_purcahse_submenu', 'prwfr_post_purcahse_set_tabs');
	add_submenu_page('prwfr_menu', '', __('Product Discovery', 'sft-product-recommendations-for-woocommerce'), 'manage_options', 'prwfr_product_discovery_submenu', 'prwfr_product_discovery_set_tabs');
	add_submenu_page('prwfr_menu', '', __('General Settings', 'sft-product-recommendations-for-woocommerce'), 'manage_options', 'prwfr_general_submenu', 'prwfr_general_set_tabs');
	add_submenu_page('prwfr_menu', '', __('Email Notifications', 'sft-product-recommendations-for-woocommerce'), 'manage_options', 'prwfr_email_submenu', 'prwfr_email_set_tabs');
	add_submenu_page(
		'prwfr_menu',
		'Chat GPT (API) Key Settings',
		__('Chat GPT (API) Key Settings', 'sft-product-recommendations-for-woocommerce'),
		'manage_options',
		'prwfr_api_setting_page',
		'prwfr_api_integration_settings_section'
	);
	add_submenu_page(
		'prwfr_menu',
		'Request Log',
		__('Request Log', 'sft-product-recommendations-for-woocommerce'),
		'manage_options',
		'prwfr_api_log_page',
		'prwfr_api_log_page_section'
	);
}

/**
 * Add API LOG Section.
 *
 * @return void
 */
function prwfr_api_log_page_section()
{
	global $wpdb;
	// Option name.
	$option_name  = 'prwfr_ai_request_logs';
	$all_products = prwfr_get_all_products();
	$iterator     = 1;

	// Get the existing data from the option.
	$data = get_option($option_name);
	// Get API Request Status.
	$api_key_status     = (get_option('prwfr_api_request_created_status')) ? get_option('prwfr_api_request_created_status') : '';
	$request_processing = 0;

	// Fetch the data from the table.
	$results = $wpdb->get_results(
		"SELECT id, request_time, prompt, recommendations_recurrence, associated_product_category_ids, product_details, about_store, response, status, tokens_used, est_token 
		FROM {$wpdb->prefix}prprow_api_request_log 
		ORDER BY request_time DESC"
	);

	// Get the number of rows.
	$num_rows = count($results) + 1;

?>
	<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
	<div class="prwfr-log-main-container">
		<?php
		if (empty($results) && ! ('created' == $api_key_status || 'pending' == $api_key_status || 'fulfilled' == $api_key_status)) {
			echo '<p>' . esc_html__('No data available.', 'sft-product-recommendations-for-woocommerce') . '</p>';
			return;
		} else {
			if ('fulfilled' !== $api_key_status) {
				$current_request_date_time = get_option('prwfr_current_ai_request');
				$currrent_datetime_string  = $current_request_date_time;
				// list($current_date, $current_time) = explode( ' ', $currrent_datetime_string );
				if (! empty($current_request_date_time)) {
					$dt           = new DateTime($current_request_date_time);
					$current_date = $dt->format('Y-m-d');
					$current_time = $dt->format('H:i:s');
				} else {
					$current_date = '';
					$current_time = '';
				}

				$request_processing = 1;
		?>
				<div class="prwfr-single-log-container prwfr-log-current-status">
					<?php
					if ('created' == $api_key_status || 'pending' == $api_key_status) {
					?>
						<div class="prwfr-log-inner prwfr-log-header">
							<div class="prwfr-log-header-details">
								<div class="prwfr-log-ref-id"><?php echo '#' . esc_html($num_rows); ?></div>
								<div><b><?php echo esc_html__('Date: ', 'sft-product-recommendations-for-woocommerce'); ?></b> <?php echo esc_attr($current_date); ?></div>
								<div><b><?php echo esc_html__('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></b> <?php echo esc_attr($current_time); ?></div>
								<div><span class="prwfr-log-progress-msg">&#x2941; <?php echo esc_html__('Processing', 'sft-product-recommendations-for-woocommerce'); ?><span></div>
							</div>
						</div>
						<div class="prwfr-log-extra-details">
							<div class="prwfr-log-additional-details-container">
								<div class="prwfr-log-inner">
									<?php
									// $recurrence = json_decode( $row->recommendations_recurrence, true );
									?>
									<h2><?php echo esc_html__('Recommendations Frequency', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<?php
									if (get_option('prwfr_recurrence_period_ai') == 'one_time') {
									?>
										<div>
											<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('One Time', 'sft-product-recommendations-for-woocommerce'); ?>
										</div>
									<?php
									} elseif (get_option('prwfr_recurrence_period_ai') == 'weekly') {
									?>
										<div>
											<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Weekly', 'sft-product-recommendations-for-woocommerce'); ?>
										</div>
										<?php
										if (get_option('prwfr_weekly_save_recommendations') == 'automatic') {
										?>
											<div>
												<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Automatic', 'sft-product-recommendations-for-woocommerce'); ?>
											</div>
										<?php
										} elseif (get_option('prwfr_weekly_save_recommendations') == 'manual') {
										?>
											<div>
												<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Manual', 'sft-product-recommendations-for-woocommerce'); ?>
											</div>
											<div>
												<div>
													<?php echo esc_html__('Scheduled Day and Time:', 'sft-product-recommendations-for-woocommerce'); ?>
												</div>
												<span> <?php echo esc_html__('Every', 'sft-product-recommendations-for-woocommerce'); ?> <?php echo esc_attr(get_option('prwfr_ai_recommendations_everyweek')); ?></span>
											</div>
											<div>
												<div>
													<?php echo esc_html__('Mail sent to:', 'sft-product-recommendations-for-woocommerce'); ?>
												</div>
												<span> <?php echo esc_attr(get_option('prwfr_ai_admin_email')); ?></span>
											</div>
									<?php
										}
									}
									?>

								</div>
								<div class="prwfr-log-inner">
									<?php
									// $category_product_selection = json_decode( $row->associated_product_category_ids, true );
									if (get_option('prwfr_multiple_products_check') == 'on') {
										$selected_products = get_option('prwfr_product_selection');
										if (! empty($selected_products)) {
									?>
											<h2><?php echo esc_html__('Products Selection', 'sft-product-recommendations-for-woocommerce'); ?></h2>
											<div><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Selected Products', 'sft-product-recommendations-for-woocommerce'); ?> (<?php echo count($selected_products); ?>)</div>
											<table class="prwfr-log-product-table">
												<thead>
													<tr>
														<th><?php echo esc_html__('Product Id', 'sft-product-recommendations-for-woocommerce'); ?></th>
														<th><?php echo esc_html__('Product Name', 'sft-product-recommendations-for-woocommerce'); ?></th>
													</tr>
												</thead>
												<tbody>
													<?php
													foreach ($selected_products as $product_id) {
														$product_name = get_the_title($product_id);
													?>
														<tr>
															<td><?php echo esc_attr(intval($product_id)); ?></td>
															<td><?php echo esc_attr($product_name); ?></td>
														</tr>
													<?php
													}
													?>
												</tbody>
											</table>
										<?php
										}
									}
									if (get_option('prwfr_multiple_categories_check') == 'on') {
										$category_ids = get_option('prwfr_category_selection');
										if (! empty($category_ids)) {
										?>
											<h2><?php echo esc_html__('Categories Selection', 'sft-product-recommendations-for-woocommerce'); ?></h2>
											<div><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Selected Categories', 'sft-product-recommendations-for-woocommerce'); ?> (<?php echo esc_attr(count($category_ids)); ?>)</div>
											<table class="prwfr-log-product-table">
												<thead>
													<tr>
														<th><?php echo esc_html__('Category Id', 'sft-product-recommendations-for-woocommerce'); ?></th>
														<th><?php echo esc_html__('Category Name', 'sft-product-recommendations-for-woocommerce'); ?></th>
													</tr>
												</thead>
												<tbody>
													<?php
													foreach ($category_ids as $category_id) {
														$category = get_term($category_id, 'product_cat');

													?>
														<tr>
															<td><?php echo esc_attr(intval($category_id)); ?></td>
															<td><?php echo esc_attr($category->name); ?></td>
														</tr>
													<?php
													}
													?>
												</tbody>
											</table>
									<?php
										}
									}
									?>

								</div>
								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Product Details Included', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div class="prwfr-log-pr-details-container">
										<?php
										$selected_product_detail_check = array('products_url', 'products_name', 'products_price', 'products_desc', 'products_desc_long', 'products_categories');

										$selected_product_detail = array();

										foreach ($selected_product_detail_check as $selected_option) {
											$selected_product_detail[] = get_option('prwfr_' . $selected_option) == 'on' ? $selected_option : '';
										}
										$product_details = $selected_product_detail;

										if (! empty($product_details)) {
											if (in_array('products_name', $product_details)) {
										?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Name', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('product_url', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product URL', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('products_desc', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Description', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('products_price', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Price', 'sft-product-recommendations-for-woocommerce'); ?></span>
										<?php
											}
										}
										?>
									</div>
								</div>
								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Store Description', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div>
										<?php echo esc_html(get_option('prwfr_about_store')); ?>
									</div>
								</div>
								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Prompt Used', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div>
										<?php
										$display_prompt = get_option('prwfr_ai_prompt_similar_display');
										echo esc_html($display_prompt); // get_option( 'prprow_ai_request_prompt' );
										?>
									</div>
								</div>
								<div class="prwfr-log-inner-last">
									<div><b><?php echo esc_html__('Total Tokens Used: ', 'sft-product-recommendations-for-woocommerce'); ?></b><?php echo esc_html(get_option('prwfr_tokens_used')); ?></div>
								</div>
							</div>
						</div>
					<?php
					} elseif ('insufficient_quota' === $api_key_status) {
					?>
						<div><?php echo esc_html__('We\'re sorry, but your current request could not be processed due to insufficient quota remaining on your API key.', 'sft-product-recommendations-for-woocommerce'); ?></div>
						<div><?php echo esc_html__('It appears that you have used up most of your allocated quota. Please check your API usage or consider upgrading your plan.', 'sft-product-recommendations-for-woocommerce'); ?></div>
					<?php
					} elseif ('system_overloaded' === $api_key_status) {
					?>
						<div><?php echo esc_html__('Unfortunately, we were unable to fulfill your request at this time because the API system is currently experiencing heavy load.', 'sft-product-recommendations-for-woocommerce'); ?></div>
						<div><?php echo esc_html__('Our servers are working at full capacity. Please try again in a few moments when the system has stabilized.', 'sft-product-recommendations-for-woocommerce'); ?></div>
					<?php
					}
					?>
				</div>
				<?php
			}

			if ((! empty($results))) {
				// Display the data.
				foreach ($results as $row) {
					$datetime_string   = $row->request_time;
					list($date, $time) = explode(' ', $datetime_string);
					$status            = intval($row->status) ? 'success' : 'failed';
				?>
					<div class="prwfr-single-log-container">
						<div class="prwfr-log-inner prwfr-log-header">
							<div class="prwfr-log-header-details">
								<div class="prwfr-log-ref-id"><?php echo '#' . esc_html($row->id); ?></div>
								<div><b><?php echo esc_html__('Date: ', 'sft-product-recommendations-for-woocommerce'); ?></b> <?php echo esc_attr($date); ?></div>
								<div><b><?php echo esc_html__('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></b> <?php echo esc_attr($time); ?></div>
								<div><span class="prwfr-log-<?php echo esc_attr($status); ?>-msg"><?php echo esc_attr($status) == 'success' ? '&check; ' . esc_html__('Success', 'sft-product-recommendations-for-woocommerce') : '&#x2715; ' . esc_html__('Failed', 'sft-product-recommendations-for-woocommerce'); ?></span></div>
							</div>
							<button class="prwfr-log-toggle-details-btn"><?php echo esc_html__('Show Details', 'sft-product-recommendations-for-woocommerce'); ?></button>
						</div>
						<div class="prwfr-log-extra-details" style="display: none;">
							<div class="prwfr-log-additional-details-container">
								<div class="prwfr-log-inner">
									<?php
									$recurrence = json_decode($row->recommendations_recurrence, true);
									?>
									<h2><?php echo esc_html__('Recommendations Frequency', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<?php
									if (isset($recurrence['ai_recurrence'])) {
										if ('one_time' == $recurrence['ai_recurrence']) {
									?>
											<div>
												<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('One Time', 'sft-product-recommendations-for-woocommerce'); ?>
											</div>
										<?php
										} elseif ('weekly' == $recurrence['ai_recurrence']) {
										?>
											<div>
												<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Weekly', 'sft-product-recommendations-for-woocommerce'); ?>
											</div>
											<?php
											if ('automatic' == $recurrence['ai_weekly_type']) {
											?>
												<div>
													<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Automatic', 'sft-product-recommendations-for-woocommerce'); ?>
												</div>
											<?php
											} elseif ('manual' == $recurrence['ai_weekly_type']) {

											?>
												<div>
													<span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Manual', 'sft-product-recommendations-for-woocommerce'); ?>
												</div>
												<div>
													<div>
														<?php echo esc_html__('Scheduled Day and Time:', 'sft-product-recommendations-for-woocommerce'); ?>
													</div>
													<span> <?php echo esc_html__('Every', 'sft-product-recommendations-for-woocommerce'); ?> <?php echo esc_attr($recurrence['ai_weekly_date_time']); ?></span>
												</div>
												<div>
													<div>
														<?php echo esc_html__('Mail sent to:', 'sft-product-recommendations-for-woocommerce'); ?>
													</div>
													<span> <?php echo esc_attr($recurrence['ai_weekly_email']); ?></span>
												</div>
									<?php
											}
										}
									} else {
										echo '';
									}

									?>
								</div>
								<div class="prwfr-log-inner">
									<?php
									$category_product_selection = json_decode($row->associated_product_category_ids, true);
									if ($category_product_selection['products'] == 'on') {
										$selected_products = $category_product_selection['selected_products'];
										if (! empty($selected_products)) {
									?>
											<h2><?php echo esc_html__('Products Selection', 'sft-product-recommendations-for-woocommerce'); ?></h2>
											<div><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Selected Products', 'sft-product-recommendations-for-woocommerce'); ?> (<?php echo count($selected_products); ?>)</div>
											<table class="prwfr-log-product-table">
												<thead>
													<tr>
														<th><?php echo esc_html__('Product Id', 'sft-product-recommendations-for-woocommerce'); ?></th>
														<th><?php echo esc_html__('Product Name', 'sft-product-recommendations-for-woocommerce'); ?></th>
													</tr>
												</thead>
												<tbody>
													<?php
													foreach ($selected_products as $product_id) {
														$product_name = get_the_title($product_id);
													?>
														<tr>
															<td><?php echo esc_attr(intval($product_id)); ?></td>
															<td><?php echo esc_attr($product_name); ?></td>
														</tr>
													<?php
													}
													?>
												</tbody>
											</table>
										<?php
										}
									}
									if ($category_product_selection['categories'] == 'on') {
										$category_ids = $category_product_selection['selected_categories'];
										if (! empty($category_ids)) {
										?>
											<h2><?php echo esc_html__('Categories Selection', 'sft-product-recommendations-for-woocommerce'); ?></h2>
											<div><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Selected Categories', 'sft-product-recommendations-for-woocommerce'); ?> (<?php echo esc_attr(count($category_ids)); ?>)</div>
											<table class="prwfr-log-product-table">
												<thead>
													<tr>
														<th><?php echo esc_html__('Category Id', 'sft-product-recommendations-for-woocommerce'); ?></th>
														<th><?php echo esc_html__('Category Name', 'sft-product-recommendations-for-woocommerce'); ?></th>
													</tr>
												</thead>
												<tbody>
													<?php
													foreach ($category_ids as $category_id) {
														$category = get_term($category_id, 'product_cat');

													?>
														<tr>
															<td><?php echo esc_attr(intval($category_id)); ?></td>
															<td><?php echo esc_attr($category->name); ?></td>
														</tr>
													<?php
													}
													?>
												</tbody>
											</table>
									<?php
										}
									}
									?>

								</div>
								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Product Details Included', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div class="prwfr-log-pr-details-container">
										<?php
										$product_details = explode(',', $row->product_details);

										if (! empty($product_details)) {
											if (in_array('products_name', $product_details)) {
										?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Name', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('product_url', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product URL', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('products_desc', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Description', 'sft-product-recommendations-for-woocommerce'); ?></span>
											<?php
											}

											if (in_array('products_price', $product_details)) {
											?>
												<span><span class="prwfr-log-green-tick">&check;</span> <?php echo esc_html__('Product Price', 'sft-product-recommendations-for-woocommerce'); ?></span>
										<?php
											}
										}

										?>
									</div>
								</div>
								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Store Description', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div>
										<?php echo wp_kses_post($row->about_store); ?>
									</div>
								</div>

								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Prompt Used', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div>
										<?php echo wp_kses_post($row->prompt); ?>
									</div>
								</div>

								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Received Response', 'sft-product-recommendations-for-woocommerce'); ?></h2>
									<div>
										<?php
										echo esc_html(
											'success' === $status
												? __('Recommendations are set successfully for the selected products.', 'sft-product-recommendations-for-woocommerce')
												: __('Request Failed', 'sft-product-recommendations-for-woocommerce')
										);
										?>
									</div>

								</div>

								<!-- AI response to decode and get the prompt tokens and error message -->
								<?php $ai_response = json_decode($row->response); ?>
								<!-- <div class="prwfr-log-inner-last">
									<div><b><?php //echo esc_html__('Total Tokens Used: ', 'sft-product-recommendations-for-woocommerce'); 
											?></b><?php // echo esc_html($row->tokens_used); 
													?></div>
								</div> -->

								<div class="prwfr-log-inner">
									<h2><?php echo esc_html__('Token Usage', 'sft-product-recommendations-for-woocommerce'); ?>
									</h2>

									<div class="prwfr-tokens-used-info">
										<table class="prwfr-log-product-table">
											<tbody>

												<tr>
													<td><b><?php echo esc_html__('Total AI Tokens Used: ', 'sft-product-recommendations-for-woocommerce'); ?></b><?php echo esc_html($row->tokens_used); ?></td>
													<td>( <?php echo esc_html__('Prompt Tokens: ', 'sft-product-recommendations-for-woocommerce'); ?><?php echo esc_html($ai_response->usage->prompt_tokens ?? 0); ?> + <?php echo esc_html__('Completion Tokens: ', 'sft-product-recommendations-for-woocommerce'); ?><?php echo esc_html($ai_response->usage->completion_tokens ?? 0); ?> )</td>
												</tr>

											</tbody>
										</table>
										<span class="prwfr-learn-more"><a href="https://platform.openai.com/usage"><?php echo esc_html__('Learn More', 'sft-product-recommendations-for-woocommerce'); ?></a></span>
									</div>
								</div>

								<div class="prwfr-log-inner-last">
									<div><em><?php echo esc_html__('Estimated Token Count: ', 'sft-product-recommendations-for-woocommerce'); ?><?php echo $status == 'success' ? esc_html($row->est_token != 0 ? $row->est_token : $row->tokens_used) : 0; ?> Displayed token counts are estimates and may differ from OpenAI's actual usage. </em></div>
								</div>

							</div>
						</div>
					</div>
		<?php
				}
			}
		}

		?>
	</div>
	<?php
	if ($num_rows > 10) {
	?>
		<div class="prwfr-log-load-more-btn-container">
			<button id="prwfr-log-load-more-button"><?php echo esc_html__('Load More', 'sft-product-recommendations-for-woocommerce'); ?></button>
		</div>
	<?php
	}
	?>
<?php
}
/**
 * Displaying page HTML and print settings.
 */
function prwfr__rvp_setting_tabs()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}
	// Write below pro banner.
?>

	<div class="wrap">
		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
		<?php
		$tabs = array(
			'rvp'         => __('Recently Viewed Products', 'sft-product-recommendations-for-woocommerce'),
			'rvp_related' => __('Products related to Recently Viewed Products', 'sft-product-recommendations-for-woocommerce'),
			'rvp_onsale'  => __('Sale Items Related to Recently Viewed Products', 'sft-product-recommendations-for-woocommerce'),
		);

		$current_tab = isset($_GET['tab']) && isset($tabs[$_GET['tab']]) ? sanitize_key($_GET['tab']) : array_key_first($tabs);
		?>

		<form method="post" action="options.php" class="prwfr-setting-tabs">
			<nav class="nav-tab-wrapper">
				
				<?php
				foreach ($tabs as $tab => $name) {
					$current = $tab === $current_tab ? ' nav-tab-active' : '';
					$url     = admin_url('admin.php');
					echo wp_kses_post("<a class=\"nav-tab{$current}\" href=\"{$url}?page=prwfr_menu&tab={$tab}\">{$name}</a>");
				}
				?>

				<div style="display: inline-block; float: right;">
					<button id="prwfr-popup-button" class="button button-secondary prwfr-ai-recommendations">
						<svg fill="#FFFFFF" height="24px" width="24px" version="1.1" id="Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve">
							<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
							<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
							<g id="SVGRepo_iconCarrier">
								<g>
									<path d="M12,17c0.8-4.2,1.9-5.3,6.1-6.1c0.5-0.1,0.8-0.5,0.8-1s-0.3-0.9-0.8-1C13.9,8.1,12.8,7,12,2.8C11.9,2.3,11.5,2,11,2 c-0.5,0-0.9,0.3-1,0.8C9.2,7,8.1,8.1,3.9,8.9C3.5,9,3.1,9.4,3.1,9.9s0.3,0.9,0.8,1c4.2,0.8,5.3,1.9,6.1,6.1c0.1,0.5,0.5,0.8,1,0.8 S11.9,17.4,12,17z"></path>
									<path d="M22,24c-2.8-0.6-3.4-1.2-4-4c-0.1-0.5-0.5-0.8-1-0.8s-0.9,0.3-1,0.8c-0.6,2.8-1.2,3.4-4,4c-0.5,0.1-0.8,0.5-0.8,1 s0.3,0.9,0.8,1c2.8,0.6,3.4,1.2,4,4c0.1,0.5,0.5,0.8,1,0.8s0.9-0.3,1-0.8c0.6-2.8,1.2-3.4,4-4c0.5-0.1,0.8-0.5,0.8-1 S22.4,24.1,22,24z"></path>
									<path d="M29.2,14c-2.2-0.4-2.7-0.9-3.1-3.1c-0.1-0.5-0.5-0.8-1-0.8c-0.5,0-0.9,0.3-1,0.8c-0.4,2.2-0.9,2.7-3.1,3.1 c-0.5,0.1-0.8,0.5-0.8,1s0.3,0.9,0.8,1c2.2,0.4,2.7,0.9,3.1,3.1c0.1,0.5,0.5,0.8,1,0.8c0.5,0,0.9-0.3,1-0.8 c0.4-2.2,0.9-2.7,3.1-3.1c0.5-0.1,0.8-0.5,0.8-1S29.7,14.1,29.2,14z"></path>
									<path d="M5.7,22.3C5.4,22,5,21.9,4.6,22.1c-0.1,0-0.2,0.1-0.3,0.2c-0.1,0.1-0.2,0.2-0.2,0.3C4,22.7,4,22.9,4,23s0,0.3,0.1,0.4 c0.1,0.1,0.1,0.2,0.2,0.3c0.1,0.1,0.2,0.2,0.3,0.2C4.7,24,4.9,24,5,24c0.1,0,0.3,0,0.4-0.1s0.2-0.1,0.3-0.2 c0.1-0.1,0.2-0.2,0.2-0.3C6,23.3,6,23.1,6,23s0-0.3-0.1-0.4C5.9,22.5,5.8,22.4,5.7,22.3z"></path>
									<path d="M28,7c0.3,0,0.5-0.1,0.7-0.3C28.9,6.5,29,6.3,29,6s-0.1-0.5-0.3-0.7c-0.1-0.1-0.2-0.2-0.3-0.2c-0.2-0.1-0.5-0.1-0.8,0 c-0.1,0-0.2,0.1-0.3,0.2C27.1,5.5,27,5.7,27,6c0,0.3,0.1,0.5,0.3,0.7C27.5,6.9,27.7,7,28,7z"></path>
								</g>
							</g>
						</svg>
						<div><?php echo esc_html__('AI Recommendations !', 'sft-product-recommendations-for-woocommerce'); ?></div>
						<div class="prwfr-popup-btn-tooltip-container" data-tooltip="Configuring Related, Upsell, and Cross-Sell Products with AI.">
							<svg width="18px" height="18px" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg">
								<g id="SVGRepo_bgCarrier" stroke-width="0" transform="translate(5.88,5.88), scale(0.51)">
									<rect x="0" y="0" width="24.00" height="24.00" rx="12" fill="#000000" strokewidth="0"></rect>
								</g>
								<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"></g>
								<g id="SVGRepo_iconCarrier">
									<path fill-rule="evenodd" clip-rule="evenodd" d="M22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12ZM12 17.75C12.4142 17.75 12.75 17.4142 12.75 17V11C12.75 10.5858 12.4142 10.25 12 10.25C11.5858 10.25 11.25 10.5858 11.25 11V17C11.25 17.4142 11.5858 17.75 12 17.75ZM12 7C12.5523 7 13 7.44772 13 8C13 8.55228 12.5523 9 12 9C11.4477 9 11 8.55228 11 8C11 7.44772 11.4477 7 12 7Z" fill="#ffffff"></path>
								</g>
							</svg>
							<div class="prwfr-ai-popup-btn-tooltip"><?php echo esc_html__('Added configuration for Product Recommendations in the shortcode using ChatGPT', 'sft-product-recommendations-for-woocommerce'); ?></div>
						</div>
					</button>
				</div>

			</nav>

			<div class="prwfr-setting-section">
				<?php
				settings_fields("prwfr__page_{$current_tab}_settings");
				do_settings_sections("prwfr__page_{$current_tab}");
				?>
				<div class="prwfr-submt-btn"><?php submit_button(); ?></div>
			</div>
		</form>
	</div>

	<!-- Upgrade footer -->
	<div class="sft-prwfr-upgrade-to-pro-banner">
		<div class="sft-uppro-inner-container">
			<div class="sft-uppro-main-logo">
				<a href="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
					<img src="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
				</a>
			</div>
		</div>

		<div class="sft-uppro-hidden-desktop">
			<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
		</div>

		<div class="sft-uppro-details-container">
			<div class="sft-uppro-money-back-guarantee">
				<div>
					<a href="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
						<img src="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
					</a>
				</div>
				<div>
					<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
					<h3><?php esc_html_e('100% Risk-Free Money Back Guarantee!', 'sft-product-recommendations-for-woocommerce'); ?></h3>
					<p><?php esc_html_e('We guarantee you a complete refund for new purchases or renewals if a request is made within 15 Days of purchase.', 'sft-product-recommendations-for-woocommerce'); ?></p>
					<div class="prwfr-upgrade-pro-btn">
						<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
							<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
								<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
							</button>
						</a>
					</div>
				</div>
			</div>

			<div class="sft-uppro-features-container">
				<h3> <?php echo esc_html__('Pro Features', 'sft-product-recommendations-for-woocommerce'); ?></h3>
				<ul>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('AI powered Product Recommendations:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Leverage the power of ChatGPT to create personalized product recommendations for your customers.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Recommended Products" Emails  based on Browsing History:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Customers get "Recommended Products" email notifications based on their browsing history.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Price Drop" Email Alerts for your Featured Sale Items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Sends "Price Drop" email to customers on products marked as "Featured Sale Item" at specified intervals of your choice.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Buy It Again" Widget & Purchase History Related items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Display previously bought items and similar items to your customers to boost repeat orders or similar orders.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('Customization options for All Widgets:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Get a plethora of options to customize widget like Title, Sale Price etc.', 'sft-product-recommendations-for-woocommerce'); ?></li>
				</ul>
			</div>

		</div>

	</div>

<?php
	prwfr_ai_script();
}

// ----------------------------------------------- Dismmiss plugin popup notice ---------------------------------------.


add_action('wp_ajax_prwfr_update_new_sale_notice_read', 'prwfr_update_new_sale_notice_read');


/**
 * AJAX handler to hide the sale popup.
 */
function prwfr_update_new_sale_notice_read()
{
	update_option('prwfr_latest_popup_sale_notice', 1);
	wp_die();
}
// ======
/**
 * Get all product in required format ( simple + variation ).
 *
 * @return array
 */
function prwfr_get_all_products()
{
	$all_products = array();

	$products_id = wc_get_products(
		array(
			'limit'  => -1,  // All products.
			'status' => 'publish', // Only published products.
			'return' => 'ids',
		)
	);

	foreach ($products_id as $product_id) {
		$product = wc_get_product($product_id);

		// All simple products.
		$all_products[] = array(
			'product_id' => intval($product_id),
			'label'      => 'ID:' . esc_attr($product_id) . ' ' . esc_html(wp_strip_all_tags($product->get_formatted_name())),
		);
	}

	return $all_products;
}

add_action('admin_init', 'prwfr_register_settings');

/**
 * Registering fields .
 */
function prwfr_register_settings()
{

	// ========================api settings======================
	add_settings_section('prwfr-account-settings-group', '', null, 'prwfr-ai-key-settings-options');

	// Setting api key enter.
	register_setting(
		'prwfr-api-field-setting',
		'prwfr_openai_api_key',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	add_settings_field(
		'prwfr_openai_api_key',
		esc_attr__('Enter Open AI API Key', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_get_ai_api_key_field',
		'prwfr-ai-key-settings-options',
		'prwfr-account-settings-group'
	);

	// Setting api model select.
	register_setting(
		'prwfr-api-field-setting',
		'prwfr_openai_api_model',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	add_settings_field(
		'prwfr_openai_api_model',
		esc_attr__('Select OpenAi Model', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_get_ai_api_model_field',
		'prwfr-ai-key-settings-options',
		'prwfr-account-settings-group'
	);

	// -------------------- General ---------------------------------------

	// For the first tab.
	$page_slug    = 'prwfr__general';
	$option_group = 'prwfr__general_settings';

	// add section.
	add_settings_section('prwfr_general_section', '', '', $page_slug);

	// Color pickers (HEX colors).
	register_setting(
		$option_group,
		'prwfr_color_picker_btn',
		array(
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	register_setting(
		$option_group,
		'prwfr_color_picker_card_bg_front',
		array(
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	register_setting(
		$option_group,
		'prwfr_color_picker_background_front',
		array(
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	register_setting(
		$option_group,
		'prwfr_button_arrow_color',
		array(
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);

	// Product image size (text / slug).
	register_setting(
		$option_group,
		'prwfr_product_image_size',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Display ratings (checkbox / boolean).
	register_setting(
		$option_group,
		'prwfr_display_ratings',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Field to pick cololr for back and next button.
	add_settings_field(
		'prwfr_color_picker_btn',
		__('Slider Background Color', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_bgcolor_picker_field',
		$page_slug,
		'prwfr_general_section'
	);
	// Field to pick cololr for card background.
	add_settings_field(
		'prwfr_color_picker_card_bg_front',
		__('Select Card Background Color', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_card_color_picker_field',
		$page_slug,
		'prwfr_general_section'
	);

	// Field to pick cololr for back and next button.
	add_settings_field(
		'prwfr_color_picker_background_front',
		__('Slider Button Color', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_color_picker_field',
		$page_slug,
		'prwfr_general_section'
	);

	add_settings_field(
		'prwfr_arrow_color_row',
		__('Select Button Arrow Icon Color', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_color_picker_field_for_arrow_icon',
		$page_slug,
		'prwfr_general_section',
	);

	add_settings_field(
		'prwfr_products_rating_field',
		__('Display rating in Products Slider', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_products_rating_field',
		$page_slug,
		'prwfr_general_section'
	);

	// Field to remove out of stock products.
	add_settings_field(
		'prwfr_rvps_out_of_stock',
		__('Remove Out-of-Stock Products', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_outofstock_field',
		$page_slug,
		'prwfr_general_section'
	);

	add_settings_field(
		'prwfr_cart_tabs_display_field',
		__('Show After Cart Tabs', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_cart_tabs_display_field',
		$page_slug,
		'prwfr_general_section'
	);

	// Radio button for categories and tags slatest.
	add_settings_field(
		'prwfr_tabs_to_display',
		__('Tabs to Display', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_tabs_to_display',
		$page_slug,
		'prwfr_general_section'
	);


	// add_settings_field(
	// 	'prwfr_recommendation_mode',
	// 	__( 'Recommendation Mode', 'sft-product-recommendations-for-woocommerce' ),
	// 	'prwfr_recommendation_mode',
	// 	$page_slug,
	// 	'prwfr_general_section'
	// );

	// ==========================email notification========================

	// for the second tab.
	$page_slug    = 'prwfr__email_general';
	$option_group = 'prwfr__email_general_settings';

	// add section.
	add_settings_section('prwfr_email_section', '', '', $page_slug);

	register_setting(
		$option_group,
		'prwfr_email_logo',
		array(
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	add_settings_field(
		'prwfr_price_drop_email_template_logo',
		__('Upload Logo for Email Header ', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_email_template_logo',
		$page_slug,
		'prwfr_email_section'
	);

	add_settings_field(
		'prwfr_learn_more_btn_color',
		__('Select "Learn more" CTA Color for Email', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_learn_more_btn_color',
		$page_slug,
		'prwfr_email_section'
	);

	add_settings_field(
		'prwfr_email_gdpr_permission',
		__('Enable GDPR Integration', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_email_gdpr_permission',
		$page_slug,
		'prwfr_email_section'
	);

	add_settings_field(
		'prwfr_email_template_header_bg_color',
		__('Choose Background for Email Template Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_email_template_header_bg_color',
		$page_slug,
		'prwfr_email_section'
	);

	add_settings_field(
		'prwfr_display_similar_products_link',
		__('Hide/Show "Similar Products" Link in Email Footer', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_display_similar_products_link',
		$page_slug,
		'prwfr_email_section'
	);

	// ---------------------------------------reorder------------------------------------------------------------

	// add section.
	add_settings_section('prwfr_reorder_section', '', '', 'prwfr__post_purchase_reorder');
	register_setting(
		'prwfr__post_purchase_reorder_settings',
		'prwfr_display_reorder',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0; // store as 1 or 0
			},
		)
	);

	add_settings_field(
		'prwfr_display_reorder_value',
		__('Display Re-Order button', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_reorder_field',
		'prwfr__post_purchase_reorder',
		'prwfr_reorder_section'
	);

	// ------------------- Recently Viewed Products ------------------------------------------

	// for the second tab.
	$page_slug    = 'prwfr__page_rvp';
	$option_group = 'prwfr__page_rvp_settings';

	// add section.
	add_settings_section('prwfr_rvp_section', '', 'prwfr_rvp_section', $page_slug);

	// Text input for title.
	register_setting(
		$option_group,
		'prwfr_rvps_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Radio selection (string).
	register_setting(
		$option_group,
		'prwfr_rvps_page_redirect_radio',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_manage_history_access',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_rvps_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_rvps_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_rvps_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_rvps_hide_cookie',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Manage history field.
	add_settings_field(
		'prwfr_manage_history_access',
		__('Allow Users to Turn Off Browsing History', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_manage_history_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// Field to select redirect page for rvps.
	add_settings_field(
		'prwfr_rvps_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_page_redirect_radio_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// select page from dropdown for rvps.
	add_settings_field(
		'prwfr_rvps_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_url_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// Takes the no of products to display in single row.
	add_settings_field(
		'prwfr_rvp_ajax_slider',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_shortcode_container_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// Rvps label field.
	add_settings_field(
		'prwfr_rvps_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_label_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// add_settings_field(
	// 	'prwfr_rvps_out_of_stock',
	// 	__( 'Remove Out-of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_rvps_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_rvp_section'
	// );

	// Cookie disable for rvp.
	add_settings_field(
		'prwfr_rvps_hide_cookie',
		__('Hide Recently Viewed Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_cookie_field_rvps',
		$page_slug,
		'prwfr_rvp_section'
	);

	// For Categories and tags.
	add_settings_field(
		'prwfr_rvps_filter_switch',
		__('Filter by Categories and Tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_toggle_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// Radio button for categories and tags.
	add_settings_field(
		'prwfr_rvps_cat_tag_selection_radio',
		__('Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_cat_tag_selection_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// For category include/exclude.
	add_settings_field(
		'prwfr_rvps_cat_inc_exc_radio',
		__('Category Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_category_radio_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	add_settings_field(
		'prwfr_rvps_cat_exc_selection',
		__('Categories to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_category_exclude_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	add_settings_field(
		'prwfr_rvps_cat_inc_selection',
		__('Categories to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_category_include_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// For tag include/exclude.

	add_settings_field(
		'prwfr_rvps_tag_inc_exc_radio',
		__('Tag Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_tag_radio_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	add_settings_field(
		'prwfr_rvps_tag_exc_selection',
		__('Tags to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_tag_exclude_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	add_settings_field(
		'prwfr_rvps_tag_inc_selection',
		__('Tags to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_tag_include_field',
		$page_slug,
		'prwfr_rvp_section'
	);

	// -----------------------------------------------------------------------------------------------------.

	// --------------------- Recently Viewed Related -------------------------------------------------------.

	$page_slug    = 'prwfr__page_rvp_related';
	$option_group = 'prwfr__page_rvp_related_settings';

	// add section.
	add_settings_section('prwfr_rvp_related_section', '', 'prwfr_rvp_related_section', $page_slug);

	// Radio selection (string).
	register_setting(
		$option_group,
		'prwfr_viewed_related_page_redirect_radio',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Radio / select option (string).
	register_setting(
		$option_group,
		'prwfr_viewed_related_see_more_option',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_viewed_related_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_viewed_related_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_viewed_related_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_viewed_related_hide_cookie',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Text input.
	register_setting(
		$option_group,
		'prwfr_viewed_related_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);


	register_setting(
		$option_group,
		'prwfr_rvp_related_recommendation_mode',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	add_settings_field(
		'prwfr_rvp_related_recommendation_mode',
		__('Recommendation Mode', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvp_related_recommendation_mode',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	add_settings_field(
		'prwfr_viewed_related_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_views_related_page_redirect_radio_field',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	// select page from dropdown for rvps related.
	add_settings_field(
		'prwfr_viewed_related_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_views_related_url_field',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	// Takes the no of products to display in single row.
	add_settings_field(
		'prwfr_viewed_related_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_views_related_shortcode_container_field',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	// Rvps related label field.
	add_settings_field(
		'prwfr_viewed_related_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_view_related_label_field',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	// add_settings_field(
	// 	'prwfr_enable_ai_recommendations',
	// 	__( 'Display AI Product Recommendations in Widget', 'sft-product-recommendations-for-woocommerce' ),
	// 	'prwfr_enable_ai_recommendations',
	// 	$page_slug,
	// 	'prwfr_rvp_related_section'
	// );

	// add_settings_field(
	// 	'prwfr_viewed_related_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_views_related_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_rvp_related_section'
	// );

	// Cookie disable for rvp related.
	add_settings_field(
		'prwfr_viewed_related_hide_cookie',
		__('Hide Products related to Recently Viewed Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_cookie_field_rvps_related',
		$page_slug,
		'prwfr_rvp_related_section'
	);

	add_settings_section('prwfr_rvp_related_filter_section', '', 'prwfr_rvp_related_filter_section', $page_slug);

	// ------------------------------------------------------------------------------------------------------.

	// --------------------- RVP-onsale ---------------------------
	$page_slug    = 'prwfr__page_rvp_onsale';
	$option_group = 'prwfr__page_rvp_onsale_settings';

	// add section.
	add_settings_section('prwfr_rvp_onsale_section', '', 'prwfr_rvp_onsale_section', $page_slug);

	// Text input for title.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Radio / select option.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_page_redirect_radio',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Radio / select option.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_see_more_option',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_rvps_onsale_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_rvps_onsale_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_hide_cookie',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_rvps_onsale_out_of_stock',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Field to select redirect page for rvps onsale.
	add_settings_field(
		'prwfr_rvps_onsale_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_onsale_page_redirect_radio_field',
		$page_slug,
		'prwfr_rvp_onsale_section'
	);

	// select page from dropdown for rvps onsale.
	add_settings_field(
		'prwfr_rvps_onsale_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_rvps_onsale_url_field',
		$page_slug,
		'prwfr_rvp_onsale_section'
	);

	// Takes the no of products to display in single row.
	add_settings_field(
		'prwfr_rvps_onsale_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_onsale_shortcode_container_field',
		$page_slug,
		'prwfr_rvp_onsale_section'
	);

	// Rvps and related on sale label field.
	add_settings_field(
		'prwfr_rvps_onsale_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvps_onsale_label_field',
		$page_slug,
		'prwfr_rvp_onsale_section'
	);

	// add_settings_field(
	// 	'prwfr_rvps_onsale_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_rvps_onsale_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_rvp_onsale_section'
	// );

	// Cookie disable for rvp_onsale.
	add_settings_field(
		'prwfr_rvps_onsale_hide_cookie',
		__('Hide Sale Items Related to Recently Viewed Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_cookie_field_rvps_onsale',
		$page_slug,
		'prwfr_rvp_onsale_section'
	);

	add_settings_section('prwfr_rvp_onsale_filter_section', '', 'prwfr_rvp_onsale_filter_section', $page_slug);

	// -------------------------------------------------------------

	// -------------------Purchase History Related-----------------------------------------

	$page_slug    = 'prwfr__post_purchase_phrp';
	$option_group = 'prwfr__post_purchase_phrp_settings';

	// add section.
	add_settings_section('prwfr_phrp_section', '', '', $page_slug);

	register_setting(
		$option_group,
		'prwfr_phrp_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);


	add_settings_field(
		'prwfr_phrp_recommendation_mode',
		__('Recommendation Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_recommendation_mode',
		$page_slug,
		'prwfr_phrp_section'
	);


	add_settings_field(
		'prwfr_phrp_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_page_redirect_radio_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_url_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_shortcode_container_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_label_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	// add_settings_field(
	// 	'prwfr_phrp_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_phrp_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_phrp_section',
	// );

	add_settings_field(
		'prwfr_phrp_no_of_days',
		__('Purchase History Period', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_no_of_days_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_toggle_value',
		__('Filter by Categories and Tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_toggle_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_cat_tag_selection_value',
		__('Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_cat_tag_selection_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_category_radio_value',
		__('Category Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_category_radio_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_category_exclude_value',
		__('Categories to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_category_exclude_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_category_include_value',
		__('Categories to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_category_include_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_tag_radio_value',
		__('Tag Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_tag_radio_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_tag_exclude_value',
		__('Tags to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_tag_exclude_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	add_settings_field(
		'prwfr_phrp_tag_include_value',
		__('Tags to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_phrp_tag_include_field',
		$page_slug,
		'prwfr_phrp_section',
	);

	// --------------------------------------------------------------

	// ------------------------Buy-it again--------------------------

	$page_slug    = 'prwfr__post_purchase_buy_again';
	$option_group = 'prwfr__post_purchase_buy_again_settings';

	// add section.
	add_settings_section('prwfr_buy_again_section', '', 'prwfr_buy_again_url_section', $page_slug);

	register_setting(
		$option_group,
		'prwfr_buy_again_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// add section.
	add_settings_field(
		'prwfr_buy_again_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_page_redirect_radio_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_url_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_label_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_no_of_days',
		__('Number of Days after Purchase', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_no_of_days_field',
		$page_slug,
		'prwfr_buy_again_section',
	);


	add_settings_field(
		'prwfr_buy_again_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_shortcode_container_field',
		$page_slug,
		'prwfr_buy_again_section',
	);


	add_settings_field(
		'prwfr_buy_again_bulk_add_to_cart',
		__('Add to cart products in bulk', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_buy_again_bulk_add_to_cart_field',
		$page_slug,
		'prwfr_buy_again_section'
	);


	add_settings_field(
		'prwfr_buy_again_toggle_value',
		__('Filter by Categories and Tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_toggle_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_cat_tag_selection_value',
		__('Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_cat_tag_selection_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_category_radio_value',
		__('Category Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_category_radio_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_category_exclude_value',
		__('Categories to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_category_exclude_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_category_include_value',
		__('Categories to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_category_include_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_tag_radio_value',
		__('Tag Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_tag_radio_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_tag_exclude_value',
		__('Tags to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_tag_exclude_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	add_settings_field(
		'prwfr_buy_again_tag_include_value',
		__('Tags to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-required">*</span><span class="prwfr-pro">Pro</span>',
		'prwfr_buy_again_tag_include_field',
		$page_slug,
		'prwfr_buy_again_section',
	);

	// -------------------- All On-Sale ----------------------
	$page_slug    = 'prwfr__highlighting_all_onsale';
	$option_group = 'prwfr__highlighting_all_onsale_settings';

	// add section.
	add_settings_section('prwfr_all_onsale_section', '', 'prwfr_all_onsale_section', $page_slug);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_all_onsale_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_all_onsale_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_all_onsale_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Text input for title.
	register_setting(
		$option_group,
		'prwfr_all_onsale_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	add_settings_field(
		'prwfr_all_onsale_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_all_onsale_page_redirect_radio_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// Select default and custom page.
	add_settings_field(
		'prwfr_all_onsale_see_more_option',
		__('Choose page ', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_url_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// Get no of products to display in single row.
	add_settings_field(
		'prwfr_all_onsale_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_all_onsale_shortcode_container_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// All on sale label field.
	add_settings_field(
		'prwfr_all_onsale_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_all_onsale_label_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// add_settings_field(
	// 	'prwfr_all_onsale_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_all_onsale_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_all_onsale_section'
	// );

	// Cookie disable for all onsale.
	add_settings_field(
		'prwfr_all_onsale_cookie_display',
		__('Hide All On-Sale Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_cookie_field_all_onsale',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// Category and tag field.
	add_settings_field(
		'prwfr_all_onasle_toggle_value',
		__('Filter by Categories and Tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_toggle_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	add_settings_field(
		'prwfr_all_onsale_cat_tag_selection_value',
		__('Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_cat_tag_selection_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// Category radio field.
	add_settings_field(
		'prwfr_all_onsale_category_radio_value',
		__('Category Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_category_radio_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	add_settings_field(
		'prwfr_all_onsale_category_exclude_value',
		__('Categories to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_category_exclude_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	add_settings_field(
		'prwfr_all_onsale_category_include_value',
		__('Categories to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_category_include_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	// Tag radio field.
	add_settings_field(
		'prwfr_all_onsale_tag_radio_value',
		__('Tag Filter Mode', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_tag_radio_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	add_settings_field(
		'prwfr_all_onsale_tag_exclude_value',
		__('Tags to Exclude', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_tag_exclude_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);

	add_settings_field(
		'prwfr_all_onsale_tag_include_value',
		__('Tags to Include', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_all_onsale_tag_include_field',
		$page_slug,
		'prwfr_all_onsale_section'
	);
	// -----------------------------------------------------------

	// -------------------------- Best Selling ---------------------------------------

	$page_slug    = 'prwfr__highlighting_best_selling';
	$option_group = 'prwfr__highlighting_best_selling_settings';

	// add section.
	add_settings_section(
		'prwfr_best_selling_section',
		'',
		'prwfr_best_selling_section',
		$page_slug
	);

	// Text input for title.
	register_setting(
		$option_group,
		'prwfr_best_selling_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_best_selling_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_best_selling_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_best_selling_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	// Numeric limit (already registered above, but ensure absint).
	register_setting(
		$option_group,
		'prwfr_all_onsale_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	add_settings_field(
		'prwfr_best_selling_redirect_page_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_best_seller_page_redirect_radio_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_see_more_option',
		__('Choose page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_url_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_seller_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_best_seller_shortcode_container_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_best_seller_label_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	// add_settings_field(
	// 	'prwfr_best_selling_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_best_seller_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_best_selling_section'
	// );

	add_settings_field(
		'prwfr_best_selling_cookie_display',
		__('Hide Best Selling Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_cookie_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_display_mode',
		__('Product Display Filter', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_product_display_option_selection',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_category_selection',
		__('Choose Categories', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_product_display_category_selection_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_tag_selection',
		__('Choose tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_product_display_tags_selection_field',
		$page_slug,
		'prwfr_best_selling_section'
	);

	add_settings_field(
		'prwfr_best_selling_individual_selection',
		__('Choose individual products', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_best_seller_product_display_individual_selection_field',
		$page_slug,
		'prwfr_best_selling_section'
	);
	// ----------------------------------------------------------------------------

	// -------------------------------- Featured Products ------------------------------
	$page_slug    = 'prwfr__highlighting_featured';
	$option_group = 'prwfr__highlighting_featured_settings';

	// add section.
	add_settings_section('prwfr_featured_section', '', 'prwfr_featured_section', $page_slug);

	// Text input.
	register_setting(
		$option_group,
		'prwfr_featured_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	// Numeric limits.
	register_setting(
		$option_group,
		'prwfr_featured_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_featured_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_featured_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	add_settings_field(
		'prwfr_featured_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_featured_page_redirect_radio_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_url_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_featured_shortcode_container_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_featured_label_field',
		$page_slug,
		'prwfr_featured_section'
	);

	// add_settings_field(
	// 	'prwfr_featured_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_featured_product_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_featured_section'
	// );

	add_settings_field(
		'prwfr_featured_cookie_display',
		__('Hide Featured Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_cookie_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_display_radio',
		__('Product Display Filter', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_product_display_option_selection',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_category_selection',
		__('Choose Categories', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_product_display_category_selection_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_tag_name',
		__('Choose tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_product_display_tags_selection_field',
		$page_slug,
		'prwfr_featured_section'
	);

	add_settings_field(
		'prwfr_featured_individual_selection',
		__('Choose individual products', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_featured_product_display_individual_selection_field',
		$page_slug,
		'prwfr_featured_section'
	);
	// ----------------------------------------------------------------------

	// --------------------------------New Arrivals----------------------------------
	$page_slug    = 'prwfr__highlighting_new_arrivals';
	$option_group = 'prwfr__highlighting_new_arrivals_settings';

	// add section.
	add_settings_section('prwfr_new_arrivals_section', '', 'prwfr_new_arrivals_section', $page_slug);

	register_setting(
		$option_group,
		'prwfr_new_arrivals_title',
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	register_setting(
		$option_group,
		'prwfr_new_arrivals_desktop_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_new_arrivals_tab_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_new_arrivals_mobile_limit',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	register_setting(
		$option_group,
		'prwfr_new_arrivals_days_filter',
		array(
			'sanitize_callback' => 'absint',
		)
	);

	add_settings_field(
		'prwfr_new_arrivals_page_redirect_radio',
		__('"See More" Page', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_new_arrivals_page_redirect_radio_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrival_see_more_option',
		__('Choose Page', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrivals_url_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_shortcode_container',
		__('Products Per Row', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_new_arrivals_shortcode_container_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_title',
		__('Title for Widget', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_new_arrivals_label_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_days_filter',
		__('Show New Products from the Past n Days.', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_new_arrivals_days_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	// add_settings_field(
	// 	'prwfr_new_arrivals_out_of_stock',
	// 	__( 'Remove Out-Of-Stock Products', 'sft-product-recommendations-for-woocommerce' ) . '<span class="prwfr-pro">Pro</span>',
	// 	'prwfr_new_arrivals_outofstock_field',
	// 	$page_slug,
	// 	'prwfr_new_arrivals_section'
	// );

	add_settings_field(
		'prwfr_new_arrivals_cookie_display',
		__('Hide Newly Arrived Products for Non-Logged Users', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrivals_cookie_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_display_radio',
		__('Product Display Filter', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrival_product_display_option_selection',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_category_selection',
		__('Choose Categories', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrival_product_display_category_selection_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_tag_selection',
		__('Choose tags', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrival_product_display_tags_selection_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	add_settings_field(
		'prwfr_new_arrivals_individual_selection',
		__('Choose individual products', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_new_arrival_product_display_individual_selection_field',
		$page_slug,
		'prwfr_new_arrivals_section'
	);

	// -------------------------------------------------------------------------------
	// email notification.
	$page_slug    = 'prwfr__email_price_drop';
	$option_group = 'prwfr__email_price_drop_settings';

	// add section.
	add_settings_section('prwfr_price_drop_email_section', '', '', $page_slug);

	register_setting(
		$option_group,
		'prwfr_price_drop_email_send_check',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	add_settings_field(
		'prwfr_price_drop_email_send_check_status',
		__('Enable Price Drop Emails', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_email_send_check',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_email_trigger',
		__('Select Email Recipients', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_email_trigger',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_price_drop_trigger_type_all',
		__('Email Frequency', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_price_drop_trigger_type_all',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_onetime',
		__('Schedule One-time Event', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_date_time_onetime',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_daily',
		__('Schedule Event Daily', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_date_time_select',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_everyweek',
		__('Schedule Event Every Week', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_date_time_all_everyweek',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_monthly',
		__('Schedule Event Every Month', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_all_monthly',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	// recently viewed.

	add_settings_field(
		'prwfr_price_drop_rvp_duration',
		__('Schedule Emails to be Sent', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span>',
		'prwfr_price_drop_rvp_schedule_event',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_rvp_everyweek',
		__('Schedule Event Every Week', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_date_time_rvp_everyweek',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_rvp_monthly',
		__('Schedule Event Every Month', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_rvp_monthly',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_rvp_fortnightly',
		__('Schedule Event Fortnightly', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_rvp_fortnightly',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_price_drop_email_template_subject',
		__('Email Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_price_drop_email_template_subject',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	add_settings_field(
		'prwfr_price_drop_email_template_content',
		__('Email Content', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span><span class="prwfr-content-placeholder"><div class="placeholder-disabled-color" style="margin: 10px 0;">' . esc_html__('Use placeholder {First_name} to display First name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-firstname-placeholder clipboard">&#128203;</button>
		</div> 
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {Last_name} to display Last name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-lastname-placeholder clipboard">&#128203;</button>
		</div>
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {User_name} to display User name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-username-placeholder clipboard">&#128203;</button>
		</div> </span>',
		'prwfr_price_drop_email_template_content',
		$page_slug,
		'prwfr_price_drop_email_section'
	);

	// ==============================new recommendations===================================
	$page_slug    = 'prwfr__email_related_rvp';
	$option_group = 'prwfr__email_related_rvp_settings';
	// add section.
	add_settings_section('prwfr_rvp_related_email_section', '', '', $page_slug);

	register_setting(
		$option_group,
		'prwfr_related_rvp_email_send',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// email notification.
	add_settings_field(
		'prwfr_related_rvp_email_send_status',
		__('Enable Recommendation Emails', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_related_rvp_email_send',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_rvp_related_duration',
		__('Email Frequency', 'sft-product-recommendations-for-woocommerce') . '<span class="trigger-rvp"></span>',
		'prwfr_rvp_related_schedule_event',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_date_time_rvp_related_everyweek',
		__('Schedule Event Every Week', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_date_time_rvp_related_everyweek',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_rvp_related_fortnightly',
		__('Schedule Event Fortnightly', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_rvp_related_fortnightly',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_date_time_picker_rvp_related_monthly',
		__('Schedule Event Every Month', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_rvp_related_monthly',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_related_rvp_email_template_subject',
		__('Email Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_related_rvp_email_template_subject',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	add_settings_field(
		'prwfr_related_rvp_email_template_content',
		__('Email Content', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro">Pro</span><span class="prwfr-content-placeholder"><div class="placeholder-disabled-color" style="margin: 10px 0;">' . esc_html__('Use placeholder {First_name} to display First name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-firstname-placeholder clipboard">&#128203;</button>
		</div> 
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {Last_name} to display Last name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-lastname-placeholder clipboard">&#128203;</button>
		</div>
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {User_name} to display User name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-username-placeholder clipboard">&#128203;</button>
		</div> </span>',
		'prwfr_related_rvp_email_template_content',
		$page_slug,
		'prwfr_rvp_related_email_section'
	);

	// --------------------------------------------------------------
	// --------------------------RVP EMAIL NOTIFICATION--------------------
	$page_slug    = 'prwfr__rvp_email';
	$option_group = 'prwfr__rvp_email_settings';
	// add section.
	add_settings_section('prwfr_rvp_email_section', '', '', $page_slug);

	// Checkbox / boolean.
	register_setting(
		$option_group,
		'prwfr_rvp_email_send',
		array(
			'sanitize_callback' => function ($value) {
				return $value ? 1 : 0;
			},
		)
	);

	// Text / HTML content (sanitize text, or allow some HTML if needed).
	register_setting(
		$option_group,
		'prwfr_rvp_email_content',
		array(
			'type'              => 'array',
			'sanitize_callback' => function ($value) {

				if (! is_array($value)) {
					return array();
				}

				return array_map('wp_kses_post', $value);
			},
			'default'           => array(),
		)
	);

	// Numeric / recurrence interval (e.g., days).
	register_setting(
		$option_group,
		'prwfr_rvp_email_recurrence_interval',
		array(
			'sanitize_callback' => function ($value) {
				$allowed = array('hours'); // allowed options.
				return in_array($value, $allowed, true) ? $value : 'hours';
			},
		)
	);

	// email notification.
	add_settings_field(
		'prwfr_rvp_email_send_status',
		__('Enable Recently Viewed Emails', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvp_email_send',
		$page_slug,
		'prwfr_rvp_email_section'
	);

	add_settings_field(
		'prwfr_rvp_schedule_type',
		__('Email Recurrence Interval', 'sft-product-recommendations-for-woocommerce'),
		'prwfr_rvp_email_recurrence',
		$page_slug,
		'prwfr_rvp_email_section'
	);

	add_settings_field(
		'prwfr_rvp_hours_duration',
		__('Schedule Emails to be Sent', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_rvp_related_hours_duration',
		$page_slug,
		'prwfr_rvp_email_section'
	);

	add_settings_field(
		'prwfr_rvp_days_duration',
		__('Schedule Emails to be Sent', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_rvp_related_days_duration',
		$page_slug,
		'prwfr_rvp_email_section'
	);

	add_settings_field(
		'prwfr_rvp_email_template_subject',
		__('Email Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_rvp_email_template_subject',
		$page_slug,
		'prwfr_rvp_email_section'
	);

	add_settings_field(
		'prwfr_rvp_email_template_content',
		__('Email Content', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro" style="cursor: pointer;">Pro</span><span class="prwfr-content-placeholder"><div class="placeholder-disabled-color" style="margin: 10px 0;">' . esc_html__('Use placeholder {First_name} to display First name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-firstname-placeholder clipboard">&#128203;</button>
		</div> 
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {Last_name} to display Last name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-lastname-placeholder clipboard">&#128203;</button>
		</div>
		<div class="placeholder-disabled-color" style="margin: 10px 0;">' .
			esc_html__('Use placeholder {User_name} to display User name', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-username-placeholder clipboard">&#128203;</button>
		</div> </span>',
		'prwfr_rvp_email_template_content',
		$page_slug,
		'prwfr_rvp_email_section'
	);


	// ==============================Purchase Products Recommendation Email Notification==============================

	$page_slug    = 'prwfr__ppr_email';
	$option_group = 'prwfr__ppr_email_settings';

	add_settings_section('prwfr_ppr_email_section', '', '', $page_slug);


	// email notification Status.
	add_settings_field(
		'prwfr_ppr_email_send_status',
		__('Enable Purchase History based Recommendation Emails', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_related_ppr_email_send',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	add_settings_field(
		'prwfr_ppr_email_duration',
		__('Email Frequency', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_related_schedule_event',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// Scheduling Week .
	add_settings_field(
		'prwfr_ppr_email_date_time_picker_everyweek',
		__('Send Day & Time', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_date_time_all_everyweek',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// Scheduling Fortnight.
	add_settings_field(
		'prwfr_ppr_email_date_time_picker_fortnightly',
		__('Schedule Event Fortnightly', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_fortnightly',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// Scheduling Month Time.
	add_settings_field(
		'prwfr_date_ppr_email_time_picker_monthly',
		__('Schedule Event Every Month', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_all_monthly',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// email order days.
	add_settings_field(
		'prwfr_ppr_email_order_interval',
		__('Consider Purchases From', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_order_day_interval',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// Emial Header / Subject.
	add_settings_field( // header.
		'prwfr_ppr_email_template_subject',
		__('Email Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_ppr_email_template_subject',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	// Email placeholder note and Content.
	add_settings_field( // temp contant.
		'prwfr_ppr_email_template_content',
		__('Email Content', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro" style="cursor: pointer;">Pro</span><span class="prwfr-content-placeholder"><div style="margin: 10px 0;font-weight: 400;">' . esc_html__('Use placeholder {First_name} to display First name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-firstname-placeholder clipboard">&#128203;</button>
		</div>
		<div style="margin: 10px 0;font-weight: 400;">' .
			esc_html__('Use placeholder {Last_name} to display Last name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-lastname-placeholder clipboard">&#128203;</button>
		</div>
		<div style="margin: 10px 0;font-weight: 400;">' .
			esc_html__('Use placeholder {User_name} to display User name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-username-placeholder clipboard">&#128203;</button>
		</div> </span>',
		'prwfr_ppr_email_template_content',
		$page_slug,
		'prwfr_ppr_email_section'
	);

	$page_slug    = 'prwfr__new_arrival_email';
	$option_group = 'prwfr__new_arrival_email_settings';

	add_settings_section('prwfr__new_arrival_email_settings', '', '', $page_slug);

	// ======================================= New arrivals email notification Status. =======================================
	add_settings_field(
		'prwfr_new_arrival_email_send_status',
		__('Enable New Arrivals Emails', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_send',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	add_settings_field(
		'prwfr_new_arrival_email_duration',
		__('Email Frequency', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_related_schedule_event',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// Scheduling Week .
	add_settings_field(
		'prwfr_new_arrival_email_date_time_picker_everyweek',
		__('Send Day & Time', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_date_time_all_everyweek',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// Scheduling Fortnight.
	add_settings_field(
		'prwfr_new_arrival_email_date_time_picker_fortnightly',
		__('Schedule Event Fortnightly', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_fortnightly',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// Scheduling Month Time.
	add_settings_field(
		'prwfr_new_arrivale_ppr_email_time_picker_monthly',
		__('Schedule Event Every Month', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_all_monthly',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// email order days.
	add_settings_field(
		'prwfr_new_arrival_email_order_day_interval',
		__('Consider Products From', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_order_day_interval',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// Emial Header / Subject.
	add_settings_field(
		'prwfr_new_arrival_email_template_subject',
		__('Email Header', 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>",
		'prwfr_new_arrival_email_header_content',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);

	// Email placeholder note and Content.
	add_settings_field(
		'prwfr_new_arrival_email_template_content',
		__('Email Content', 'sft-product-recommendations-for-woocommerce') . '<span class="prwfr-pro" style="cursor: pointer;">Pro</span><span class="prwfr-content-placeholder"><div style="margin: 10px 0;font-weight: 400;">' . esc_html__('Use placeholder {First_name} to display First name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-firstname-placeholder clipboard">&#128203;</button>
		</div>
		<div style="margin: 10px 0;font-weight: 400;">' .
			esc_html__('Use placeholder {Last_name} to display Last name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-lastname-placeholder clipboard">&#128203;</button>
		</div>
		<div style="margin: 10px 0;font-weight: 400;">' .
			esc_html__('Use placeholder {User_name} to display User name ', 'sft-product-recommendations-for-woocommerce') . '<button class="prwfr-email-username-placeholder clipboard">&#128203;</button>
		</div> </span>',
		'prwfr_new_arrival_email_content',
		$page_slug,
		'prwfr__new_arrival_email_settings'
	);
}


/**
 * Function to display Filter text.
 */
function prwfr_rvp_related_filter_section()
{
?>
	<div style="margin-top: 10px; padding: 21px 11px 20px 20px;">
		<?php
		echo esc_html__("The product filter applied for 'Recently Viewed Products' will be effective on 'Products related to Recently Viewed Products", 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>";
		?>
	</div>
<?php
}


/**
 * Function to display Filter text.
 */
function prwfr_rvp_onsale_filter_section()
{
?>
	<div style="margin-top: 10px; padding: 21px 11px 20px 20px;">
		<?php
		echo esc_html__("The product filter applied for 'Recently Viewed Products' will be effective on 'Sale Items Related to Recently Viewed Products", 'sft-product-recommendations-for-woocommerce') . "<span class='prwfr-pro'>Pro</span>";
		?>
	</div>
<?php
}

/**
 * Highliting tabs settings tabs.
 */
function prwfr_product_discovery_set_tabs()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}

?>

	<div class="wrap">
		<h1><?php echo esc_url(get_admin_page_title()); ?></h1>

		<?php
		$tabs = array(
			'all_onsale'   => __('All Products On-Sale', 'sft-product-recommendations-for-woocommerce'),
			'best_selling' => __('Best Selling Products', 'sft-product-recommendations-for-woocommerce'),
			'featured'     => __('Featured Products', 'sft-product-recommendations-for-woocommerce'),
			'new_arrivals' => __('Newly Arrived Products', 'sft-product-recommendations-for-woocommerce'),
		);

		$current_tab = isset($_GET['tab']) && isset($tabs[$_GET['tab']]) ? sanitize_key($_GET['tab']) : array_key_first($tabs);
		?>

		<form method="post" action="options.php" class="prwfr-setting-tabs">
			<nav class="nav-tab-wrapper">
				<?php
				foreach ($tabs as $tab => $name) {
					$current = $tab === $current_tab ? ' nav-tab-active' : '';
					$url     = admin_url('admin.php');
					echo wp_kses_post("<a class=\"nav-tab{$current}\" href=\"{$url}?page=prwfr_product_discovery_submenu&tab={$tab}\">{$name}</a>");
				}
				?>

				<div class="prwfr-upgrade-pro-btn">
					<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
						<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
							<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
						</button>
					</a>
				</div>
			</nav>

			<div class="prwfr-setting-section">
				<?php
				settings_fields("prwfr__highlighting_{$current_tab}_settings");
				do_settings_sections("prwfr__highlighting_{$current_tab}");
				?>
				<div class="prwfr-submt-btn"><?php submit_button(); ?></div>
			</div>
		</form>
	</div>

	<!-- Upgrade footer -->

	<div class="sft-prwfr-upgrade-to-pro-banner">
		<div class="sft-uppro-inner-container">
			<div class="sft-uppro-main-logo">
				<a href="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
					<img src="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
				</a>
			</div>
		</div>

		<div class="sft-uppro-hidden-desktop">
			<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
		</div>

		<div class="sft-uppro-details-container">
			<div class="sft-uppro-money-back-guarantee">
				<div>
					<a href="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
						<img src="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
					</a>
				</div>
				<div>
					<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
					<h3><?php esc_html_e('100% Risk-Free Money Back Guarantee!', 'sft-product-recommendations-for-woocommerce'); ?></h3>
					<p><?php esc_html_e('We guarantee you a complete refund for new purchases or renewals if a request is made within 15 Days of purchase.', 'sft-product-recommendations-for-woocommerce'); ?></p>
					<div class="prwfr-upgrade-pro-btn">
						<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
							<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
								<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
							</button>
						</a>
					</div>
				</div>
			</div>

			<div class="sft-uppro-features-container">
				<h3> <?php echo esc_html__('Pro Features', 'sft-product-recommendations-for-woocommerce'); ?></h3>
				<ul>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('AI powered Product Recommendations:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Leverage the power of ChatGPT to create personalized product recommendations for your customers.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Recommended Products" Emails  based on Browsing History:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Customers get "Recommended Products" email notifications based on their browsing history.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Price Drop" Email Alerts for your Featured Sale Items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Sends "Price Drop" email to customers on products marked as "Featured Sale Item" at specified intervals of your choice.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Buy It Again" Widget & Purchase History Related items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Display previously bought items and similar items to your customers to boost repeat orders or similar orders.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('Customization options for All Widgets:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Get a plethora of options to customize widget like Title, Sale Price etc.', 'sft-product-recommendations-for-woocommerce'); ?></li>
				</ul>
			</div>

		</div>

	</div>

<?php
}

/**
 * Displaying page HTML and print settings.
 */
function prwfr_post_purcahse_set_tabs()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}

?>
	<div class="wrap">
		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

		<?php
		$tabs = array(
			'reorder'   => __('Re-order', 'sft-product-recommendations-for-woocommerce'),
			'phrp'      => __('Purchase History Related Products  ', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
			'buy_again' => __('Buy-it Again Products  ', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
		);

		$current_tab = isset($_GET['tab']) && isset($tabs[$_GET['tab']]) ? sanitize_key($_GET['tab']) : array_key_first($tabs);
		?>

		<form method="post" action="options.php" class="prwfr-setting-tabs">
				<nav class="nav-tab-wrapper">
					<?php
					foreach ($tabs as $tab => $name) {
						$current = $tab === $current_tab ? ' nav-tab-active' : '';
						$url     = admin_url('admin.php');
						echo wp_kses_post("<a class=\"nav-tab{$current}\" href=\"{$url}?page=prwfr_post_purcahse_submenu&tab={$tab}\">{$name}</a>");
					}
					?>
				<div class="prwfr-upgrade-pro-btn">
					<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
						<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
							<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
						</button>
					</a>
				</div>
			</nav>

			<div class="prwfr-setting-section">
				<?php
				settings_fields("prwfr__post_purchase_{$current_tab}_settings");
				do_settings_sections("prwfr__post_purchase_{$current_tab}");
				?>
				<div class="prwfr-submt-btn"><?php submit_button(); ?></div>
			</div>
		</form>
	</div>

	<!-- Upgrade footer -->

	<div class="sft-prwfr-upgrade-to-pro-banner">
		<div class="sft-uppro-inner-container">
			<div class="sft-uppro-main-logo">
				<a href="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
					<img src="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
				</a>
			</div>
		</div>

		<div class="sft-uppro-hidden-desktop">
			<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
		</div>

		<div class="sft-uppro-details-container">
			<div class="sft-uppro-money-back-guarantee">
				<div>
					<a href="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
						<img src="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
					</a>
				</div>
				<div>
					<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
					<h3><?php esc_html_e('100% Risk-Free Money Back Guarantee!', 'sft-product-recommendations-for-woocommerce'); ?></h3>
					<p><?php esc_html_e('We guarantee you a complete refund for new purchases or renewals if a request is made within 15 Days of purchase.', 'sft-product-recommendations-for-woocommerce'); ?></p>
					<div class="prwfr-upgrade-pro-btn">
						<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
							<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
								<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
							</button>
						</a>
					</div>
				</div>
			</div>

			<div class="sft-uppro-features-container">
				<h3> <?php echo esc_html__('Pro Features', 'sft-product-recommendations-for-woocommerce'); ?></h3>
				<ul>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('AI powered Product Recommendations:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Leverage the power of ChatGPT to create personalized product recommendations for your customers.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Recommended Products" Emails  based on Browsing History:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Customers get "Recommended Products" email notifications based on their browsing history.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Price Drop" Email Alerts for your Featured Sale Items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Sends "Price Drop" email to customers on products marked as "Featured Sale Item" at specified intervals of your choice.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Buy It Again" Widget & Purchase History Related items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Display previously bought items and similar items to your customers to boost repeat orders or similar orders.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('Customization options for All Widgets:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Get a plethora of options to customize widget like Title, Sale Price etc.', 'sft-product-recommendations-for-woocommerce'); ?></li>
				</ul>
			</div>

		</div>

	</div>
<?php
}

/**
 * General setting tabs.
 */
function prwfr_general_set_tabs()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}

?>
	<div class="wrap">
		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

		<?php
		$tabs = array(
			'general'           => __('General', 'sft-product-recommendations-for-woocommerce'),
		);

		$current_tab = isset($_GET['tab']) && isset($tabs[$_GET['tab']]) ? sanitize_key($_GET['tab']) : array_key_first($tabs);
		?>

		<form method="post" action="options.php" class="prwfr-setting-tabs">
			<nav class="nav-tab-wrapper">
				<?php
				foreach ($tabs as $tab => $name) {
					$current = $tab === $current_tab ? ' nav-tab-active' : '';
					$url     = admin_url('admin.php');
					echo wp_kses_post("<a class=\"nav-tab{$current}\" href=\"{$url}?page=prwfr_general_submenu&tab={$tab}\">{$name}</a>");
				}
				?>

				<div class="prwfr-upgrade-pro-btn">
					<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
						<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
							<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
						</button>
					</a>
				</div>
			</nav>

			<div class="prwfr-setting-section">
				<?php
				settings_fields("prwfr__{$current_tab}_settings");
				do_settings_sections("prwfr__{$current_tab}");
				?>
				<div class="prwfr-submt-btn"><?php submit_button(); ?></div>
			</div>
		</form>
	</div>

	<!-- Upgrade footer -->

	<div class="sft-prwfr-upgrade-to-pro-banner">
		<div class="sft-uppro-inner-container">
			<div class="sft-uppro-main-logo">
				<a href="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
					<img src="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
				</a>
			</div>
		</div>

		<div class="sft-uppro-hidden-desktop">
			<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
		</div>

		<div class="sft-uppro-details-container">
			<div class="sft-uppro-money-back-guarantee">
				<div>
					<a href="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
						<img src="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
					</a>
				</div>
				<div>
					<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
					<h3><?php esc_html_e('100% Risk-Free Money Back Guarantee!', 'sft-product-recommendations-for-woocommerce'); ?></h3>
					<p><?php esc_html_e('We guarantee you a complete refund for new purchases or renewals if a request is made within 15 Days of purchase.', 'sft-product-recommendations-for-woocommerce'); ?></p>
					<div class="prwfr-upgrade-pro-btn">
						<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
							<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
								<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
							</button>
						</a>
					</div>
				</div>
			</div>

			<div class="sft-uppro-features-container">
				<h3> <?php echo esc_html__('Pro Features', 'sft-product-recommendations-for-woocommerce'); ?></h3>
				<ul>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('AI powered Product Recommendations:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Leverage the power of ChatGPT to create personalized product recommendations for your customers.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Recommended Products" Emails  based on Browsing History:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Customers get "Recommended Products" email notifications based on their browsing history.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Price Drop" Email Alerts for your Featured Sale Items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Sends "Price Drop" email to customers on products marked as "Featured Sale Item" at specified intervals of your choice.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Buy It Again" Widget & Purchase History Related items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Display previously bought items and similar items to your customers to boost repeat orders or similar orders.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('Customization options for All Widgets:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Get a plethora of options to customize widget like Title, Sale Price etc.', 'sft-product-recommendations-for-woocommerce'); ?></li>
				</ul>
			</div>

		</div>

	</div>
<?php
}

/**
 * Email setting tabs.
 */
function prwfr_email_set_tabs()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}

?>
	<div class="wrap">
		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>

		<?php
		$tabs = array(
			'email_general'     => __('Custom Email Template Settings', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
			'rvp_email'         => __('Recently Viewed Products Email Notification', 'sft-product-recommendations-for-woocommerce'),
			'email_price_drop'  => __('Price Drop Email Notification', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
			'email_related_rvp' => __('New Recommendations Email Notification', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
			'ppr_email'             => __('Purchase Products Recommendation Email Notification', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
			'new_arrival_email'     => __('New Arrivals Email Notification', 'sft-product-recommendations-for-woocommerce') . '<img class="prwfr-pro-feature-tab-icon" src="' . esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)) . '" />',
		);

		$current_tab = isset($_GET['tab']) && isset($tabs[$_GET['tab']]) ? sanitize_key($_GET['tab']) : array_key_first($tabs);
		?>

		<form method="post" action="options.php" class="prwfr-setting-tabs">
			<nav class="nav-tab-wrapper">
				<div class="nav-links-wrap">
				<?php
				foreach ($tabs as $tab => $name) {
					$current = $tab === $current_tab ? ' nav-tab-active' : '';
					$url     = admin_url('admin.php');
					echo wp_kses_post("<a class=\"nav-tab{$current}\" href=\"{$url}?page=prwfr_email_submenu&tab={$tab}\">{$name}</a>");
				}
				?>
			</div>
				<div class="prwfr-upgrade-pro-btn">
					<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
						<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
							<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
						</button>
					</a>
				</div>
			</nav>

			<div class="prwfr-setting-section">
				<?php
				settings_fields("prwfr__{$current_tab}_settings");
				do_settings_sections("prwfr__{$current_tab}");
				?>
				<div class="prwfr-submt-btn"><?php submit_button(); ?></div>
			</div>
		</form>
	</div>

	<!-- Upgrade footer -->

	<div class="sft-prwfr-upgrade-to-pro-banner">
		<div class="sft-uppro-inner-container">
			<div class="sft-uppro-main-logo">
				<a href="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
					<img src="<?php echo esc_url(plugins_url('../../assets/images/saffiretech_logo.png', __FILE__)); ?>">
				</a>
			</div>
		</div>

		<div class="sft-uppro-hidden-desktop">
			<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
		</div>

		<div class="sft-uppro-details-container">
			<div class="sft-uppro-money-back-guarantee">
				<div>
					<a href="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
						<img src="<?php echo esc_url(plugins_url('../../assets/images/moneyback-badge.png', __FILE__)); ?>">
					</a>
				</div>
				<div>
					<h2><?php esc_html_e('Unlock Advanced Features For Product Recommendations', 'sft-product-recommendations-for-woocommerce'); ?></h2>
					<h3><?php esc_html_e('100% Risk-Free Money Back Guarantee!', 'sft-product-recommendations-for-woocommerce'); ?></h3>
					<p><?php esc_html_e('We guarantee you a complete refund for new purchases or renewals if a request is made within 15 Days of purchase.', 'sft-product-recommendations-for-woocommerce'); ?></p>
					<div class="prwfr-upgrade-pro-btn">
						<a href="https://www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=profield&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr" target="_blank">
							<button class="prwfr-upgrade-to-pro-btn" onclick="window.open('https:\/\/www.saffiretech.com/woocommerce-product-recommendations-pro/?utm_source=wp_plugin&utm_medium=footer&utm_campaign=free2pro&utm_id=c1&utm_term=upgrade_now&utm_content=prwfr', '_blank');">
								<?php esc_html_e('Upgrade To Pro!', 'sft-product-recommendations-for-woocommerce'); ?>
							</button>
						</a>
					</div>
				</div>
			</div>

			<div class="sft-uppro-features-container">
				<h3> <?php echo esc_html__('Pro Features', 'sft-product-recommendations-for-woocommerce'); ?></h3>
				<ul>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('AI powered Product Recommendations:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Leverage the power of ChatGPT to create personalized product recommendations for your customers.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Recommended Products" Emails  based on Browsing History:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Customers get "Recommended Products" email notifications based on their browsing history.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Price Drop" Email Alerts for your Featured Sale Items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Sends "Price Drop" email to customers on products marked as "Featured Sale Item" at specified intervals of your choice.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('"Buy It Again" Widget & Purchase History Related items:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Display previously bought items and similar items to your customers to boost repeat orders or similar orders.', 'sft-product-recommendations-for-woocommerce'); ?></li>
					<li><img width="15px" height="13px" src="<?php echo esc_url(plugins_url('../../assets/images/footer-green-tick.svg', __FILE__)); ?>"> <strong><?php echo esc_html__('Customization options for All Widgets:', 'sft-product-recommendations-for-woocommerce'); ?></strong> <?php echo esc_html__('Get a plethora of options to customize widget like Title, Sale Price etc.', 'sft-product-recommendations-for-woocommerce'); ?></li>
				</ul>
			</div>

		</div>

	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_email_template_header_bg_color()
{
	$value = get_option('prwfr_email_template_header_bg_color') ? get_option('prwfr_email_template_header_bg_color') : '#7f54b3';

?>

	<div style="display: flex; align-items: center;">
		<?php
		if ($value) {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" id="prwfr_email_template_header_bg_color" class="prwfr-btn-color" name="prwfr_email_template_header_bg_color" value="<?php echo esc_attr($value); ?>" placeholder="<?php esc_html('Add label', 'sft-product-recommendations-for-woocommerce'); ?>">
			</div>
		<?php
		} else {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" id="prwfr_email_template_header_bg_color" class="prwfr-btn-color" name="prwfr_email_template_header_bg_color" value="#7f54b3" placeholder="<?php esc_html_e('Add label', 'sft-product-recommendations-for-woocommerce'); ?>">
			</div>
		<?php
		}
		?>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to pick the background color to change background color of custom email template', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

function prwfr_display_similar_products_link()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_display_similar_products_link" value="1" <?php echo checked('1', get_option('prwfr_display_similar_products_link'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose whether to hide or show "Similar products" Link in Email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_learn_more_btn_color()
{
	$value = get_option('prwfr_learn_more_btn_color');
?>

	<div style="display: flex; align-items: center;">
		<?php
		if ($value) {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" id="prwfr_learn_more_btn_color" class="prwfr-btn-color" name="prwfr_learn_more_btn_color" value="<?php echo esc_attr(get_option('prwfr_learn_more_btn_color')); ?>" placeholder="<?php esc_html_e('Add label', 'sft-product-recommendations-for-woocommerce'); ?>">
			</div>
		<?php
		} else {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" id="prwfr_learn_more_btn_color" class="prwfr-btn-color" name="prwfr_learn_more_btn_color" value="#0473aa" placeholder="<?php esc_html_e('Add label', 'sft-product-recommendations-for-woocommerce'); ?>">
			</div>
		<?php
		}
		?>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to pick the color to change color of learn more CTA in email', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}
/**
 * Add Files.
 *
 * @return void
 */

function prwfr_color_picker_field_for_arrow_icon()
{
	$value = get_option('prwfr_button_arrow_color');
?>

	<div style="display: flex; align-items: center;">
		<?php
		if ($value) {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" class="prwfr-btn-color" name="prwfr_button_arrow_color" value="<?php echo esc_attr(get_option('prwfr_button_arrow_color')); ?>" placeholder="Add label">
			</div>
		<?php
		} else {
		?>
			<div style="display: flex; align-items: center;" class="prwfr-color-picker-container">
				<input type="text" class="prwfr-btn-color" name="prwfr_button_arrow_color" value="#FFF" placeholder="Add label">
			</div>
		<?php
		}
		?>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to pick the color to change color of previous and next button within shortcode', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php

}

// slatest
function prwfr_cart_tabs_display_field()
{

?>

	<div style="display: flex; align-items: center;">

		<label class="switch ">
			<input type="checkbox" class="prwfr-cart-tabs-switch" name="prwfr_cart_tabs_switch" value="1" <?php echo checked('1', get_option('prwfr_cart_tabs_switch', '0'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting enables or disables the recommendation tabs section displayed after the cart page.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>
<?php
}

// slatest
function prwfr_tabs_to_display()
{
	$value = get_option('prwfr_rvps_cat_tag_selection_radio');
?>

	<div class="prwfr-tabs-to-display-container" style="display: flex; align-items: center;">

		<div class="prwfr-tabs-to-display">

			<div>
				<input type="checkbox" class="prwfr-but-it-again-tab " name="prwfr_buy_it_again_tab" value="1" <?php echo checked('1', get_option('prwfr_buy_it_again_tab', ''), false); ?> disabled>
				<label><?php esc_html_e('Buy it Again', 'sft-product-recommendations-for-woocommerce'); ?></label><br>
			</div>
			<div>
				<input type="checkbox" class="prwfr-phrp-tab " name="prwfr_phrp_tab" value="1" <?php echo checked('1', get_option('prwfr_phrp_tab', ''), false); ?> disabled>
				<label><?php esc_html_e('Suggested Products from Past Purchases', 'sft-product-recommendations-for-woocommerce'); ?></label><br>
			</div>
			<div>
				<input type="checkbox" class="prwfr-rrvp-tab " name="prwfr_rrvp_tab" value="1" <?php echo checked('1', get_option('prwfr_rrvp_tab', ''), false); ?> disabled>
				<label><?php esc_html_e('Related to Recently Viewed Products', 'sft-product-recommendations-for-woocommerce'); ?></label><br>
			</div>

		</div>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting shows or hides the recommendation tabs section displayed after the cart page.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>
<?php
}


/**
 * Add Files.
 *
 * @return void
 */
function prwfr_email_gdpr_permission()
{
?>
	<div>
		<label class="switch">
			<input type="checkbox" class="prwfr-email-gdpr-permission" name="prwfr_email_gdpr_permission" value="1" <?php echo checked('1', get_option('prwfr_email_gdpr_permission'), false); ?> style="padding-right: 12px;" checked="checked">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('By checking this, it will show up confirmation text below the email id on checkout page.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_rvp_schedule_event()
{

?>
	<div class="prwfr-rvp-price-drop" style="display:flex; flex-wrap: wrap; align-items: center; gap: 10px;">

		<div>
			<input type="radio" id="weekly" class="prwfr-price-drop-email-days-interval" name="prwfr_price_drop_rvp_email_days_interval" value="7" <?php echo checked('7', get_option('prwfr_price_drop_rvp_email_days_interval'), false); ?> checked="checked">
			<label for="weekly"><?php esc_html_e('Weekly ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="fortnightly" class="prwfr-price-drop-email-days-interval" name="prwfr_price_drop_rvp_email_days_interval" value="15" <?php echo checked('15', get_option('prwfr_price_drop_rvp_email_days_interval'), false); ?>>
			<label for="fortnightly"><?php esc_html_e('Fortnightly ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<input type="radio" id="monthly" class="prwfr-price-drop-email-days-interval" name="prwfr_price_drop_rvp_email_days_interval" value="30" <?php echo checked('30', get_option('prwfr_price_drop_rvp_email_days_interval'), false); ?>>
		<label for="monthly"><?php esc_html_e('Monthly ', 'sft-product-recommendations-for-woocommerce'); ?></label>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule an email notification to be sent to the user according to the trigger set.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_email_template_logo()
{

	// nonce verification.
	$secure_nonce      = wp_create_nonce('sft-product-recommendations-for-woocommerce');
	$id_nonce_verified = wp_verify_nonce($secure_nonce, 'sft-product-recommendations-for-woocommerce');

	if (! $id_nonce_verified) {
		wp_die(esc_html__('Nonce Not verified', 'sft-product-recommendations-for-woocommerce'));
	}

?>
	<form enctype="multipart/form-data">
		<?php
		if (get_option('prwfr_email_logo') != '') {
		} else {
		?>
			<div class="prwfr-email-logo">
				<i class="fa-solid fa-circle-xmark fa-lg prwfr-cross-icon" style="color: #ff3d3d; cursor: pointer;"></i>
				<img src="" class="prwfr-img-logo" style="height: 100px;" />
			</div>
			<style>
				.prwfr-email-logo-loader,
				.prwfr-email-logo {
					visibility: hidden;
				}
			</style>
		<?php
		}
		?>

		<div class="prwfr-email-img-logo">
			<input type="file" name="prwfr_email_logo" id="prwfr_image_upload_form" accept="image/*" style="
		margin: 10px !important;">
			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('This setting allows you to set your company\'s logo, which will be displayed in the header of the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>

	</form>
<?php

}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_email_template_content()
{

?>
	<div class="prwfr-textarea-field-container" style="position: relative;width: 70%;">
		<?php
		wp_editor(
			'',
			'prwfr_price_drop_email_content_text',
			array(
				'textarea_name' => 'prwfr_price_drop_email_content[prwfr_price_drop_email_content_text]',
				'textarea_rows' => 10,
				'teeny'         => true,
			)
		);

		?>
		<div class="setting-help-tip" style="position: absolute !important; z-index: 10; right: -28px; top: 10px;">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</div>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_email_template_subject()
{
?>
	<div style="display: flex; align-items: center;">
		<input type="text" class="prwfr-email-subject" name="prwfr_price_drop_email_header_content" value="<?php echo esc_attr(get_option('prwfr_price_drop_email_header_content')); ?>" <?php echo esc_html(get_option('prwfr_price_drop_email_header_content')); ?>>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to set the subject for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_related_rvp_email_send()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_related_rvp_email_send" value="1" <?php echo checked('1', get_option('prwfr_related_rvp_email_send'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Enable this option to send recommendation emails based on products the customer recently viewed. Disable to stop these emails.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_related_rvp_schedule_event()
{

?>
	<div>

		<input type="radio" id="7days" checked="checked" class="prwfr-price-drop-email-days-interval" name="prwfr_related_rvp_email_days_interval" value="7" <?php echo checked('7', get_option('prwfr_related_rvp_email_days_interval'), false); ?>>
		<label for="7days"><?php esc_html_e('7 Days ', 'sft-product-recommendations-for-woocommerce'); ?></label>

		<input type="radio" id="15days" class="prwfr-price-drop-email-days-interval" name="prwfr_related_rvp_email_days_interval" value="15" <?php echo checked('15', get_option('prwfr_related_rvp_email_days_interval'), false); ?>>
		<label for="15days"><?php esc_html_e('15 Days ', 'sft-product-recommendations-for-woocommerce'); ?></label>

		<input type="radio" id="30day" class="prwfr-price-drop-email-days-interval" name="prwfr_related_rvp_email_days_interval" value="30" <?php echo checked('30', get_option('prwfr_related_rvp_email_days_interval'), false); ?>>
		<label for="30day"><?php esc_html_e('30 Days ', 'sft-product-recommendations-for-woocommerce'); ?></label>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the recurrence interval after which the next email will be sent to the user.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_related_rvp_schedule_event_time()
{

	$time_interval = get_option('prwfr_related_rvp_email_time_interval');

?>
	<div>
		<input type="time" class="prwfr-price-drop-email-time-interval" name="prwfr_related_rvp_email_time_interval" value="<?php echo esc_attr(sanitize_text_field($time_interval)); ?>">
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to specify the time at which you want to send emails to users.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_related_rvp_email_template_subject()
{
?>
	<div>
		<input type="text" class="prwfr-email-subject" name="prwfr_personalized_recommendations_email_header_content" value="<?php echo ''; ?>" <?php echo ''; ?>>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_related_rvp_email_template_content()
{

?>
	<div class="prwfr-textarea-field-container" style="position: relative;width: 70%;">
		<?php
		wp_editor(
			'',
			'prwfr_personalized_recommendations_email_content_text',
			array(
				'textarea_name' => 'prwfr_personalized_recommendations_email_content[prwfr_personalized_recommendations_email_content_text]',
				'textarea_rows' => 10,
				'teeny'         => true,
			)
		);

		?>
		<span class="setting-help-tip" style="position: absolute !important; z-index: 10; right: -28px; top: 10px;">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_email_template_subject()
{
?>
	<div style="display:flex; align-items:center;">
		<input type="text" class="prwfr-email-subject" name="prwfr_rvp_email_header_content" value="Still Thinking About Them? It's Time to Make Those Recently Viewed Items Yours!" <?php echo esc_attr(get_option('prwfr_rvp_email_header_content')); ?>>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_email_template_content()
{

?>
	<div class="prwfr-textarea-field-container" style="position: relative;width: 70%;">
		<?php
		wp_editor(
			'We noticed you\'ve been checking out some great items on our site and wanted to give you a quick recap to help you make your decision. Here\'s a reminder of what caught your eye:',
			'prwfr_rvp_email_content_text',
			array(
				'textarea_name' => 'prwfr_rvp_email_content[prwfr_rvp_email_content_text]',
				'textarea_rows' => 10,
				'teeny'         => true,
			)
		);
		?>
		<span class="setting-help-tip" style="position: absolute !important; z-index: 10; right: -28px; top: 10px;">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_date_time_onetime()
{

?>
	<div>
		<input type="datetime-local" class="prwfr-price-drop-date-time" name="prwfr_price_drop_date_time_onetime" value="<?php echo ''; ?>" <?php echo ''; ?>>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule a one-time event that will trigger an email notification only once according to the provided date and time.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_email_trigger()
{

?>
	<div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px;">
		<div>
			<input type="radio" id="all_customer"
				name="prwfr_price_drop_email_trigger" value="all" <?php echo checked('all', get_option('prwfr_price_drop_email_trigger'), false); ?> checked="checked">
			<label for="all_customer"><?php esc_html_e('All Customers', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="rvp_sale"
				name="prwfr_price_drop_email_trigger" value="rvp_sale" <?php echo checked('rvp_sale', get_option('prwfr_price_drop_email_trigger'), false); ?>>
			<label for="rvp_sale"><?php esc_html_e('Users with Recently Viewed Products', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Choose which customers should be included, and select who will receive the notification.', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_date_time_select()
{

	$time_interval = get_option('prwfr_price_drop_daily_time');
?>
	<div>
		<input type="time" class="prwfr-price-drop-email-daily" name="prwfr_price_drop_daily_time" value="<?php echo esc_html($time_interval); ?>">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose whether to send emails to all users or only to those who have recently viewed products on your site.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php

}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_date_time_all_everyweek()
{

	$time_interval = get_option('prwfr_price_drop_weekly_time');
	$days_of_week  = array(__('Monday', 'sft-product-recommendations-for-woocommerce'), __('Tuesday', 'sft-product-recommendations-for-woocommerce'), __('Wednesday', 'sft-product-recommendations-for-woocommerce'), __('Thursday', 'sft-product-recommendations-for-woocommerce'), __('Friday', 'sft-product-recommendations-for-woocommerce'), __('Saturday', 'sft-product-recommendations-for-woocommerce'), __('Sunday', 'sft-product-recommendations-for-woocommerce'));
	$value         = get_option('prwfr_price_drop_everyweek');
?>
	<div class="prwfr-price-drop-all-email-weekly">
		<label for="day-of-week"><?php echo esc_html__('Day of the Week:', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<select id="day-of-week" name="prwfr_price_drop_everyweek">
			<?php
			foreach ($days_of_week as $day) {
				if ($value === $day) {
			?>
					<option selected="selected" value='<?php echo esc_html($value); ?>'><?php echo esc_html($day); ?></option>
				<?php
				} else {
				?>
					<option value='<?php echo esc_html($day); ?>'><?php echo esc_html($day); ?></option>
			<?php
				}
			}
			?>
		</select>

		<label for="time-of-day"><?php echo esc_html__('Time:', 'sft-product-recommendations-for-woocommerce'); ?> </label>
		<input type="time" name="prwfr_price_drop_weekly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose a day of the week when you want to schedule email notifications.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_date_time_rvp_everyweek()
{
	$time_interval = get_option('prwfr_price_drop_weekly_time_rvp');
	$days_of_week  = array(__('Monday', 'sft-product-recommendations-for-woocommerce'), __('Tuesday', 'sft-product-recommendations-for-woocommerce'), __('Wednesday', 'sft-product-recommendations-for-woocommerce'), __('Thursday', 'sft-product-recommendations-for-woocommerce'), __('Friday', 'sft-product-recommendations-for-woocommerce'), __('Saturday', 'sft-product-recommendations-for-woocommerce'), __('Sunday', 'sft-product-recommendations-for-woocommerce'));
	$value         = get_option('prwfr_price_drop_everyweek_rvp');

?>
	<div class="prwfr-price-drop-rvp-email-weekly">
		<label for="day-of-week"><?php esc_html_e('Day of the Week: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<select id="day-of-week" name="prwfr_price_drop_everyweek_rvp">
			<?php
			foreach ($days_of_week as $day) {
				if (ucfirst($value) === $day) {
			?>
					<option selected="selected" value='<?php echo esc_html(ucfirst($value)); ?>'><?php echo esc_html($day); ?></option>
				<?php
				} else {
				?>
					<option value='<?php echo esc_html($day); ?>'><?php echo esc_html($day); ?></option>
			<?php
				}
			}
			?>
		</select>

		<label for="time-of-day"><?php esc_html_e('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_price_drop_weekly_time_rvp" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose a day of the week when you want to schedule email notifications.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_all_monthly()
{

	$value         = get_option('prwfr_price_drop_monthly');
	$time_interval = get_option('prwfr_price_drop_monthly_time');
?>
	<div class="prwfr-price-drop-all-email-monthly">
		<label for="day-of-month"><?php esc_html_e('Select the nth day of the month: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="number" id="day-of-month" name="prwfr_price_drop_monthly" value="<?php echo esc_html($value); ?>" min="1" max="31">

		<label for="time-of-day"><?php esc_html_e('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_price_drop_monthly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_rvp_monthly()
{

	$value         = intval(get_option('prwfr_price_drop_monthly_rvp')) ? get_option('prwfr_price_drop_monthly_rvp') : 1;
	$time_interval = get_option('prwfr_price_drop_monthly_time_rvp');
?>
	<div class="prwfr-price-drop-rvp-email-monthly">

		<label for="day-of-month"><?php esc_html_e('Select the nth day of the month: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="number" id="day-of-month" name="prwfr_price_drop_monthly_rvp" value="<?php echo esc_html($value); ?>" min="1" max="31">

		<label for="time-of-day">Time: </label>
		<input type="time" name="prwfr_price_drop_monthly_time_rvp" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_rvp_fortnightly()
{
?>
	<div>
		<input type="datetime-local" class="prwfr-price-drop-date-time-fortnightly" name="prwfr_price_drop_date_time_rvp_fortnightly" value="<?php echo ''; ?>" <?php echo ''; ?>>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule an email to be sent after every 15 days.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_trigger_type_all()
{

?>
	<div style="display:flex; flex-wrap:wrap; align-items:center; gap: 10px;">
		<div>
			<input type="radio" id="onetime"
				name="prwfr_price_drop_trigger_type_all" value="onetime" <?php echo checked('onetime', get_option('prwfr_price_drop_trigger_type_all'), false); ?> checked="checked">
			<label for="onetime"><?php esc_html_e('One-Time', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="daily"
				name="prwfr_price_drop_trigger_type_all" value="1" <?php echo checked('1', get_option('prwfr_price_drop_trigger_type_all'), false); ?>>
			<label for="daily"><?php esc_html_e('Daily', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="weekly"
				name="prwfr_price_drop_trigger_type_all" value="7" <?php echo checked('7', get_option('prwfr_price_drop_trigger_type_all'), false); ?>>
			<label for="weekly"><?php esc_html_e('Weekly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="monthly"
				name="prwfr_price_drop_trigger_type_all" value="30" <?php echo checked('30', get_option('prwfr_price_drop_trigger_type_all'), false); ?>>
			<label for="monthly"><?php esc_html_e('Monthly', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('This setting allows you to schedule an email to be sent One-time, Daily, Weekly and Monthly.', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_related_schedule_event()
{

?>
	<div class="prwfr-rvp-related-duration" style="display:flex; flex-wrap:wrap; align-items: center; gap: 10px;">

		<div>
			<input type="radio" id="weekly"
				name="prwfr_rvp_related_duration" value="7" <?php echo checked('7', get_option('prwfr_rvp_related_duration'), false); ?>>
			<label for="weekly"><?php esc_html_e('Weekly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>

		<div>
			<input type="radio" id="fortnightly"
				name="prwfr_rvp_related_duration" value="15" <?php echo checked('15', get_option('prwfr_rvp_related_duration'), false); ?>>
			<label for="fortnightly"><?php esc_html_e('Fortnightly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>

		<div>
			<input type="radio" id="monthly"
				name="prwfr_rvp_related_duration" value="30" <?php echo checked('30', get_option('prwfr_rvp_related_duration'), false); ?>>
			<label for="monthly"><?php esc_html_e('Monthly', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Choose how often recommendation emails should be sent (Weekly, Fortnightly, or Monthly).', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>
	</div>
<?php

}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_date_time_rvp_related_everyweek()
{

	$time_interval = get_option('prwfr_rvp_related_weekly_time');
	$days_of_week  = array(__('Monday', 'sft-product-recommendations-for-woocommerce'), __('Tuesday', 'sft-product-recommendations-for-woocommerce'), __('Wednesday', 'sft-product-recommendations-for-woocommerce'), __('Thursday', 'sft-product-recommendations-for-woocommerce'), __('Friday', 'sft-product-recommendations-for-woocommerce'), __('Saturday', 'sft-product-recommendations-for-woocommerce'), __('Sunday', 'sft-product-recommendations-for-woocommerce'));
	$value         = get_option('prwfr_rvp_related_everyweek');

?>
	<div class="prwfr-rvp-related-weekly">
		<label for="day-of-week"><?php esc_html_e('Day of the Week:', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<select id="day-of-week" name="prwfr_rvp_related_everyweek">
			<?php
			foreach ($days_of_week as $day) {
				if (ucfirst($value) == $day) {
			?>
					<option selected="selected" value='<?php echo esc_html(ucfirst($value)); ?>'><?php echo esc_html($day); ?></option>
				<?php
				} else {
				?>
					<option value='<?php echo esc_html($day); ?>'><?php echo esc_html($day); ?></option>
			<?php
				}
			}
			?>
		</select>

		<label for="time-of-day"><?php esc_html_e('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_rvp_related_weekly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule an email to be sent Weekly, After 15days and Monthly.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>

<?php

}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_related_monthly()
{
	$value         = get_option('prwfr_rvp_related_monthly_day') ? intval(get_option('prwfr_rvp_related_monthly_day')) : 1;
	$time_interval = get_option('prwfr_rvp_related_monthly_time') == ':' ? '' : get_option('prwfr_rvp_related_monthly_time');

?>
	<div class="prwfr-rvp-related-monthly">

		<label for="day-of-month"><?php esc_html_e('Select the nth day of the month:', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="number" id="day-of-month" name="prwfr_rvp_related_monthly_day" value="<?php echo esc_html($value); ?>" min="1" max="31">

		<label for="time-of-day">Time: </label>
		<input type="time" name="prwfr_rvp_related_monthly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_related_fortnightly()
{

?>
	<div>
		<input type="datetime-local" class="prwfr-rvp-related-fortnightly" name="prwfr_rvp_related_fortnightly" value="<?php echo ''; ?>">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_related_hours_duration()
{
	$value = get_option('prwfr_rvp_email_hours_interval') ? get_option('prwfr_rvp_email_hours_interval') : 8;
?>
	<div class="prwfr-rvp-email-hours-interval" style="margin: 0px 0 15px;">
		<?php esc_html_e('After ', 'sft-product-recommendations-for-woocommerce'); ?>
		<input type="number" style="width: 50px;" name="prwfr_rvp_email_hours_interval" value="<?php echo esc_attr($value); ?>" <?php echo esc_attr($value); ?>>
		<?php esc_html_e(' Hours ', 'sft-product-recommendations-for-woocommerce'); ?>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the hours of the day to schedule an email to be sent every \'n\' hours if a user has viewed a new batch of products.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_related_days_duration()
{

?>
	<div class="prwfr-rvp-email-days-interval">
		<?php esc_html_e('After Every ', 'sft-product-recommendations-for-woocommerce'); ?>
		<input type="number" id="ndays" style="width: 50px;" name="prwfr_rvp_email_days_interval" value="<?php echo ''; ?>" min="1">
		<?php esc_html_e('  Days at ', 'sft-product-recommendations-for-woocommerce'); ?>
		<input type="time" name="prwfr_rvp_email_time" value="<?php echo ''; ?>" <?php echo ''; ?>>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the hours of the day to schedule an email to be sent every \'n\' hours if a user has viewed a new batch of products.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_email_send()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_rvp_email_send" value="1" <?php echo checked('1', get_option('prwfr_rvp_email_send'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Enable this option to send emails featuring products the customer recently viewed.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

/**
 * Add Files.
 *
 * @return void
 */
function prwfr_price_drop_email_send_check()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_price_drop_email_send_check" value="1" <?php echo checked('1', get_option('prwfr_price_drop_email_send_check'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Enable this option to send price drop email notifications to eligible customers. Disable it to stop all automatic emails.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}


/**
 * Add Files.
 *
 * @return void
 */
function prwfr_rvp_email_recurrence()
{
?>
	<div style="display: flex; align-items: center; gap: 5px;">

		<div>
			<input type="radio" class="prwfr-email-recurrence-radio" id="hours" name="prwfr_rvp_email_recurrence_interval" value="hours" <?php echo checked('hours', get_option('prwfr_rvp_email_recurrence_interval'), false); ?> checked="checked">
			<label for="hours"><?php esc_html_e('After X Hours ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" class="prwfr-email-recurrence-radio" id="days" name="prwfr_rvp_email_recurrence_interval" value="days" <?php echo checked('days', get_option('prwfr_rvp_email_recurrence_interval'), false); ?>>
			<label for="days"><?php esc_html_e('After X Days', 'sft-product-recommendations-for-woocommerce'); ?><img class="prwfr-pro-feature-tab-icon" src="<?php echo esc_url(plugins_url('../../assets/images/pro-feature-icon.png', __FILE__)); ?>" /></label><br>
		</div>

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Select whether the email should recur after hours or days.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>


	</div>
<?php
}


// ====================================================== PPR NEW EMAIL  ==============================================

function prwfr_related_ppr_email_send()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_related_ppr_email_send" value="1" <?php echo checked('1', get_option('prwfr_related_ppr_email_send'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Enable this option to send recommendation emails based on customers’ past purchases.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

// Limit previous order (DATE ) ? Will  date be vaalid ? since there can be or cannot be oredr in date ? so limit by number of orders?
function prwfr_related_ppr_email_date()
{
?>
	<div style="display: flex; align-items: center;">
		<label>
			<input type="date" name="prwfr_ppr_email_order_limit_date" value="<?php echo esc_attr(get_option('prwfr_ppr_email_order_limit_date', '')); ?>" style="margin-right: 12px;">
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Select the date for sending related product recommendation emails to users.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

// Email header / suvject
function prwfr_ppr_email_template_subject()
{
?>
	<?php
	$prwfr_email_header_content = (get_option('prwfr_ppr_recommendation_email_header_content') !== false && get_option('prwfr_ppr_recommendation_email_header_content') !== '') ? get_option('prwfr_ppr_recommendation_email_header_content') : 'More to Love Based on Your Last Pick';
	?>

	<div class="prwfr-textbox-tooltip-container">
		<input type="text" class="prwfr-email-subject" name="prwfr_ppr_recommendation_email_header_content" value="<?php echo esc_attr($prwfr_email_header_content); ?>">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting lets you add a header to the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

function prwfr_ppr_email_template_content()
{
	$options = get_option('prwfr_ppr_recommendation_email_content');

	$default_content = 'Hello {First_name}, <br><br>Thank you for your recent purchase! We’ve picked out a few more things we think you’ll love based on your order. Check them out below:';

	$content = ! empty($options['prwfr_ppr_recommendation_email_content_text']) ? $options['prwfr_ppr_recommendation_email_content_text'] : $default_content;

?>
	<div class="prwfr-textarea-container">
		<?php
		wp_editor(
			wp_kses_post($content),
			'prwfr_ppr_recommendation_email_content_text',
			array(
				'textarea_name' => 'prwfr_ppr_recommendation_email_content[prwfr_ppr_recommendation_email_content_text]',
				'textarea_rows' => 10,
				'teeny'         => true,
			)
		);
		?>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}


function prwfr_ppr_email_related_schedule_event()
{

?>
	<div class="prwfr-ppr-email-duration prwfr-radio-buttons-alt-container">

		<div>
			<input type="radio" id="ppr-email-weekly"
				name="prwfr_ppr_email_duration" value="7" <?php echo checked('7', get_option('prwfr_ppr_email_duration'), false); ?>>
			<label for="ppr-email-weekly"><?php esc_html_e('Weekly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="ppr-email-fortnightly"
				name="prwfr_ppr_email_duration" value="15" <?php echo checked('15', get_option('prwfr_ppr_email_duration'), false); ?>>
			<label for="ppr-email-fortnightly"><?php esc_html_e('Fortnightly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="ppr-email-monthly"
				name="prwfr_ppr_email_duration" value="30" <?php echo checked('30', get_option('prwfr_ppr_email_duration'), false); ?>>
			<label for="ppr-email-monthly"><?php esc_html_e('Monthly', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Choose how often purchase-based recommendation emails should be sent (Weekly, Fortnightly, or Monthly).', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>

	</div>
<?php

}

function prwfr_ppr_email_all_monthly()
{

	$value         = get_option('prwfr_ppr_email_monthly');
	$time_interval = get_option('prwfr_ppr_email_monthly_time');
?>
	<div class="prwfr-ppr-email-all-email-monthly prwfr-textbox-time-tooltip-container">

		<label for="day-of-month"><?php esc_html_e('Select the nth day of the month: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="number" id="day-of-month" name="prwfr_ppr_email_monthly" value="<?php echo esc_html($value); ?>" min="1" max="31">

		<label for="time-of-day"><?php esc_html_e('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_ppr_email_monthly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}

function prwfr_ppr_email_date_time_all_everyweek()
{

	$time_interval = get_option('prwfr_ppr_email_weekly_time');
	$days_of_week  = array(__('Monday', 'sft-product-recommendations-for-woocommerce'), __('Tuesday', 'sft-product-recommendations-for-woocommerce'), __('Wednesday', 'sft-product-recommendations-for-woocommerce'), __('Thursday', 'sft-product-recommendations-for-woocommerce'), __('Friday', 'sft-product-recommendations-for-woocommerce'), __('Saturday', 'sft-product-recommendations-for-woocommerce'), __('Sunday', 'sft-product-recommendations-for-woocommerce'));
	$value         = get_option('prwfr_ppr_email_everyweek_day');
?>
	<div class="prwfr-ppr-email-all-email-weekly prwfr-textbox-time-tooltip-container">

		<label for="day-of-week"><?php echo esc_html__('Day of the Week: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<select id="day-of-week" name="prwfr_ppr_email_everyweek_day">
			<?php
			foreach ($days_of_week as $day) {
				if ($value === $day) {
			?>
					<option selected="selected" value='<?php echo esc_html($value); ?>'><?php echo esc_html($day); ?></option>
				<?php
				} else {
				?>
					<option value='<?php echo esc_html($day); ?>'><?php echo esc_html($day); ?></option>
			<?php
				}
			}
			?>
		</select>
		<label for="time-of-day"><?php echo esc_html__('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_ppr_email_weekly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose a day of the week when you want to schedule email notifications.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>
<?php
}

function prwfr_ppr_email_fortnightly()
{
	$storedValue   = get_option('prwfr_ppr_email_fortnightly');
	$correctFormat = substr($storedValue, 0, 10) . 'T' . substr($storedValue, 11, 2) . substr($storedValue, 13);
?>
	<div class="prwfr-textbox-tooltip-container">
		<input type="datetime-local" class="prwfr-ppr-email-date-time-fortnightly" name="prwfr_ppr_email_fortnightly" value="<?php echo esc_attr($correctFormat); ?>">
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule an email to be sent after every 15 days.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

function prwfr_ppr_email_order_day_interval()
{

?>
	<div class="prwfr-ppr-email-duration prwfr-radio-buttons-alt-container">

		<div>
			<input type="radio" id="weekly"
				name="prwfr_ppr_email_order_day_interval" value="30" <?php echo checked('30', get_option('prwfr_ppr_email_order_day_interval'), false); ?>>
			<label for="weekly"><?php esc_html_e('Last 30 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="fortnightly"
				name="prwfr_ppr_email_order_day_interval" value="60" <?php echo checked('60', get_option('prwfr_ppr_email_order_day_interval'), false); ?>>
			<label for="fortnightly"><?php esc_html_e('Last 60 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="monthly"
				name="prwfr_ppr_email_order_day_interval" value="90" <?php echo checked('90', get_option('prwfr_ppr_email_order_day_interval'), false); ?>>
			<label for="monthly"><?php esc_html_e('Last 90 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Allows you to select the time range within which customer purchases are considered when sending related product recommendations.', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>

	</div>
<?php

}

	// ====================================================== New Arival Email Setting Fields. ====================================

/**
 * Create toggle  option field to on of the email notification in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_send()
{
?>
	<div style="display: flex; align-items: center;">
		<label class="switch">
			<input type="checkbox" name="prwfr_new_arrivals_email_send" value="1" <?php echo checked('1', get_option('prwfr_new_arrivals_email_send'), false); ?> style="padding-right: 12px;">
			<span class="slider round"></span>
		</label>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('Enable this option to send emails featuring newly arrived products.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}


/**
 * Create email header field in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_header_content()
{
?>
	<?php
	$default_header = 'Brand New, Just for You';
	$email_header   = get_option('prwfr_new_arrival_email_header_content') ? get_option('prwfr_new_arrival_email_header_content') : $default_header;
	?>
	<div class="prwfr-textbox-tooltip-container">
		<input type="text" class="prwfr-email-subject" name="prwfr_new_arrival_email_header_content" value="<?php echo esc_attr($email_header); ?>">
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting lets you add a header to the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}


/**
 * Create emial xontent option field in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_content()
{

	$options = get_option('prwfr_new_arrival_email_content');
	$content = isset($options['prwfr_new_arrival_email_content_text']) && ! empty($options['prwfr_new_arrival_email_content_text'])
		? $options['prwfr_new_arrival_email_content_text']
		: 'Hello {First_name}, <br><br>We\'ve just added some exciting new items to our collection, and we thought you\'d love to check them out! Here\'s a sneak peek at the latest arrivals that we think you\'ll adore.';

?>
	<div class="prwfr-textarea-container">
		<?php
		wp_editor(
			$content,
			'prwfr_new_arrival_email_content_text',
			array(
				'textarea_name' => 'prwfr_new_arrival_email_content[prwfr_new_arrival_email_content_text]',
				'textarea_rows' => 10,
				'teeny'         => true,
				'wpautop'       => false, // Ensures <p> tags are preserved
			)
		);
		?>
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to add content body for the custom email template.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>
<?php
}


/**
 * Create scheduling option field in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_related_schedule_event()
{
?>
	<div class="prwfr-ppr-email-duration prwfr-radio-buttons-alt-container">

		<div>
			<input type="radio" id="weekly"
				name="prwfr_new_arrival_email_duration" value="7" <?php echo checked('7', get_option('prwfr_new_arrival_email_duration'), false); ?>>
			<label for="weekly"><?php esc_html_e('Weekly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="fortnightly"
				name="prwfr_new_arrival_email_duration" value="15" <?php echo checked('15', get_option('prwfr_new_arrival_email_duration'), false); ?>>
			<label for="fortnightly"><?php esc_html_e('Fortnightly', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="monthly"
				name="prwfr_new_arrival_email_duration" value="30" <?php echo checked('30', get_option('prwfr_new_arrival_email_duration'), false); ?>>
			<label for="monthly"><?php esc_html_e('Monthly', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Choose how often new arrivals emails should be sent (Weekly, Fortnightly, or Monthly).', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>

	</div>
<?php

}


/**
 * Create a Month field for weekly scheduling email in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_all_monthly()
{

	$value         = get_option('prwfr_new_arrival_email_monthly');
	$time_interval = get_option('prwfr_new_arrival_email_monthly_time');
?>
	<div class="prwfr-ppr-email-all-email-monthly prwfr-textbox-time-tooltip-container">

		<label for="day-of-month"><?php esc_html_e('Select the nth day of the month: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="number" id="day-of-month" name="prwfr_new_arrival_email_monthly" value="<?php echo esc_html($value); ?>" min="1" max="31">

		<label for="time-of-day"><?php esc_html_e('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_new_arrival_email_monthly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose the day of the month on which to schedule an email to be sent once a month.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>

	</div>
<?php
}


/**
 * Create a weekday and time field for weekly scheduling email in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_date_time_all_everyweek()
{

	$time_interval = get_option('prwfr_new_arrival_email_weekly_time');
	$days_of_week  = array(__('Monday', 'sft-product-recommendations-for-woocommerce'), __('Tuesday', 'sft-product-recommendations-for-woocommerce'), __('Wednesday', 'sft-product-recommendations-for-woocommerce'), __('Thursday', 'sft-product-recommendations-for-woocommerce'), __('Friday', 'sft-product-recommendations-for-woocommerce'), __('Saturday', 'sft-product-recommendations-for-woocommerce'), __('Sunday', 'sft-product-recommendations-for-woocommerce'));
	$value         = get_option('prwfr_new_arrival_email_everyweek_day');
?>
	<div class="prwfr-ppr-email-all-email-weekly prwfr-textbox-time-tooltip-container">


		<label for="day-of-week"><?php echo esc_html__('Day of the Week: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<select id="day-of-week" name="prwfr_new_arrival_email_everyweek_day">
			<?php
			foreach ($days_of_week as $day) {
				if ($value === $day) {
			?>
					<option selected="selected" value='<?php echo esc_html($value); ?>'><?php echo esc_html($day); ?></option>
				<?php
				} else {
				?>
					<option value='<?php echo esc_html($day); ?>'><?php echo esc_html($day); ?></option>
			<?php
				}
			}
			?>
		</select>

		<label for="time-of-day"><?php echo esc_html__('Time: ', 'sft-product-recommendations-for-woocommerce'); ?></label>
		<input type="time" name="prwfr_new_arrival_email_weekly_time" value="<?php echo esc_html($time_interval); ?>" id="time-of-day">

		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to choose a day of the week when you want to schedule email notifications.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>


	</div>
<?php
}

/**
 * Create a date field for fourtnightlu scheduling email in the new arrival email notification settings tab.
 *
 * @return void
 */
function prwfr_new_arrival_email_fortnightly()
{
	$storedValue   = get_option('prwfr_new_arrival_email_fortnightly');
	$correctFormat = substr($storedValue, 0, 10) . 'T' . substr($storedValue, 11, 2) . substr($storedValue, 13);
?>
	<div class="prwfr-textbox-tooltip-container">
		<input type="datetime-local" class="prwfr-ppr-email-date-time-fortnightly" name="prwfr_new_arrival_email_fortnightly" value="<?php echo esc_attr($correctFormat); ?>">
		<span class="setting-help-tip">
			<div class="tooltipdata">
				<?php esc_html_e('This setting allows you to schedule an email to be sent after every 15 days.', 'sft-product-recommendations-for-woocommerce'); ?>
			</div>
		</span>
	</div>

<?php
}

/**
 * Create Field Interval days for the new arrival email notification.
 *
 * @return void
 */
function prwfr_new_arrival_email_order_day_interval()
{

?>
	<div class="prwfr-ppr-email-duration prwfr-radio-buttons-alt-container">

		<div>
			<input type="radio" id="new-arrival-email-weekly"
				name="prwfr_new_arrival_email_order_day_interval" value="30" <?php echo checked('30', get_option('prwfr_new_arrival_email_order_day_interval'), false); ?>>
			<label for="new-arrival-email-weekly"><?php esc_html_e('Last 30 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="new-arrival-email-fortnightly"
				name="prwfr_new_arrival_email_order_day_interval" value="60" <?php echo checked('60', get_option('prwfr_new_arrival_email_order_day_interval'), false); ?>>
			<label for="new-arrival-email-fortnightly"><?php esc_html_e('Last 60 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>
		</div>
		<div>
			<input type="radio" id="new-arrival-email-monthly"
				name="prwfr_new_arrival_email_order_day_interval" value="90" <?php echo checked('90', get_option('prwfr_new_arrival_email_order_day_interval'), false); ?>>
			<label for="new-arrival-email-monthly"><?php esc_html_e('Last 90 Days', 'sft-product-recommendations-for-woocommerce'); ?></label>

			<span class="setting-help-tip">
				<div class="tooltipdata">
					<?php esc_html_e('Select the time range within which products are considered new arrivals.', 'sft-product-recommendations-for-woocommerce'); ?>
				</div>
			</span>
		</div>

	</div>
<?php

}



// --------------------------------------AI Section Settings ---------------------------------------------.

/**
 * Api key section.
 */
function prwfr_api_integration_settings_section()
{
?>
	<div class="pluginHeadingwrap">

		<section class="pluginHeader">
			<div class="headerRight">
			</div>
		</section>

		<main>
			<div class="notificationGrup"></div>

			<!-- Form saving api key -->
			<form method="post" action="options.php">
				<?php
				settings_fields('prwfr-api-field-setting');
				do_settings_sections('prwfr-ai-key-settings-options');
				?>
				<input type="submit" name="prwfr_save_key" class="button button-primary" value="<?php echo esc_html__('Save API Key', 'sft-product-recommendations-for-woocommerce'); ?>">
			</form><br><br />
		</main>
	</div>
<?php
}


/**
 * To display To get API Key.
 */
function prwfr_get_ai_api_key_field()
{
	$display_key_status = '';
?>

	<div class="prwfr-add-api-key-container">
		<input type="text" class="prwfr-token-invalid" name="prwfr_openai_api_key" id="prwfr_api_key" value="<?php echo esc_attr(get_option('prwfr_openai_api_key')); ?>" />
		<input type="button" name="prwfr_ajax_button" class="prwfr_ajax_button" id="prwfr_ajax_button" value="<?php echo esc_html_e('Validate API Key', 'sft-product-recommendations-for-woocommerce'); ?>" />
		<span style="margin-top: 12px;"><a href="https://www.saffiretech.com/docs/sft-woocommerce-product-recommendations/" target='_blank'><?php echo esc_html__('learn more', 'sft-product-recommendations-for-woocommerce'); ?></a></span>
	</div>

	<div class="prwfr-add-api-key-message-container">
		<?php
		if (get_option('prwfr_api_valid_key_status') == 1) {
			$display_key_status = '<i class="fas fa-check-circle" style="color: green;"></i> ' . __('Your API key is valid!', 'sft-product-recommendations-for-woocommerce');
		} else {
			$display_key_status = '<i class="fas fa-times-circle" style="color: red;"></i> ' . __('Please Enter Valid API key!', 'sft-product-recommendations-for-woocommerce');
		}
		?>
		<span id="prwfr-key-valid-message"><?php echo wp_kses_post($display_key_status); ?></span>
	</div>
	<?php
}

/**
 * To display all chat model name available with this api key.
 */
function prwfr_get_ai_api_model_field()
{

	// Call the request and save data.
	$api_key_data = get_option('prwfr_openai_api_key');

	if ('' == $api_key_data) {
		echo esc_html__('API Key is required to fetch models', 'sft-product-recommendations-for-woocommerce');
	} else {

		// Check existing models if not found refresh the models again.
		if ((false === get_transient('prwfr_set_model_names')) || (empty(get_transient('prwfr_set_model_names')))) {

			// Get the api response data for model names.
			$response_data = prwfr_api_server_callback_validation($api_key_data);
			$model_names   = $response_data['data']['data'];

			// Get the valid model names.
			$model_data = prwfr_get_valid_model_names($model_names, $api_key_data);

			// If valid models found.
			if ($model_data) {

				// Initally update the first model names for dropdown to option.
				update_option('prwfr_openai_api_model', $model_data[0]);

				// Refresh models after one month.
				set_transient('prwfr_set_model_names', $model_data, 2628000);

				// Get the selected model name.
				$selected_model = get_option('prwfr_openai_api_model');

				// Update insufficient quota to empty.
				update_option('prwfr_api_request_created_status', '');
	?>

				<!-- Load all the valid model names -->
				<select name="prwfr_openai_api_model" class="prwfr_openai_api_model">
					<?php
					foreach ($model_data as $model) {
						if ($selected_model == $model) {
					?>
							<option value="<?php echo esc_html($model); ?>" selected><?php echo esc_html($model); ?></option>
						<?php
						} else {
						?>
							<option value="<?php echo esc_html($model); ?>"><?php echo esc_html($model); ?></option>
					<?php
						}
					}
					?>
				</select>

				<!-- Loader div -->
				<p class="prwfr-ai-message-data">
				<?php
			} else {

				// Update insufficient quota.
				update_option('prwfr_api_request_created_status', 'insufficient_quota');
				?>

					<!-- Loader div -->
				<p class="prwfr-ai-message-data"><?php echo esc_html__('It looks like you don\'t have access to the ChatGPT model with your current API key.', 'sft-product-recommendations-for-woocommerce'); ?><br />
					<?php echo esc_html__('To resolve this please check your subscription by visiting the', 'sft-product-recommendations-for-woocommerce'); ?> <a href="https://platform.openai.com/settings/organization/billing/"><?php echo esc_html__('billing', 'sft-product-recommendations-for-woocommerce'); ?></a> <?php echo esc_html__('page.', 'sft-product-recommendations-for-woocommerce'); ?></p>
			<?php
			}
		} else {

			// All the stored model data.
			$model_data = get_transient('prwfr_set_model_names');

			// Get the selected model name.
			$selected_model = get_option('prwfr_openai_api_model');
			?>

			<!-- Load all the valid model names -->
			<select name="prwfr_openai_api_model" class="prwfr_openai_api_model">
				<?php
				// If model data exist.
				if (! empty($model_data)) {
					foreach ($model_data as $model) {

						if ($model == $selected_model) {
				?>
							<option value="<?php echo esc_html($model); ?>" selected><?php echo esc_html($model); ?></option>
						<?php
						} else {
						?>
							<option value="<?php echo esc_html($model); ?>"><?php echo esc_html($model); ?></option>
					<?php
						}
					}
				} else {
					?>
					<option value="0"><?php echo esc_html('No Models Found !', 'sft-product-recommendations-for-woocommerce'); ?></option>
				<?php
				}
				?>
			</select>

			<!-- Loader div -->
			<p class="prwfr-ai-message-data">
	<?php
		}
	}
}
