<?php
/**
 * Filedoc for Pixelio Cart Abandonment Recovery Email Admin
 *
 * This file handles the display and management of email templates in the Pixelio Cart Abandonment Recovery plugin.
 * It includes the following functionalities:
 *
 * - Display of available email templates with edit/delete actions.
 * - Creation and configuration of new email templates.
 * - Inline email content editing with placeholders.
 * - Sending test emails.
 * - Enable/disable sending emails and coupons per template.
 * - Integration with WooCommerce products for placeholder insertion.
 *
 * Dependencies:
 * - Pixelio_Cart_Abandon_Recovery_More_Admin_Dialog_Popup
 * - Pixelio_Cart_Abandon_Recovery_More_Header
 * - Pixelio_Cart_Abandon_Recovery_More_Multi_Tab_Switcher
 * - Pixelio_Cart_Abandon_Recovery_More_Util
 * - Pixelio_Cart_Abandon_Recovery_More_Email_Logs
 *
 * Notes:
 * - Uses WordPress AJAX for sending and saving email templates.
 * - Sanitizes output using esc_html, esc_attr, and wp_kses.
 * - Provides a responsive UI with placeholder management for dynamic content.
 *
 * @package PixelioCartAbandonRecoveryMore
 * @version 1.0
 * @since 1.0
 */

use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Admin_Dialog_Popup;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Admin_Loader_Spinner;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Header;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Multi_Tab_Switcher;
use PixelioCartAbandonRecoveryMore\Admin\Wrapper\Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper;
use PixelioCartAbandonRecoveryMore\Frontend\Repositories\Pixelio_Cart_Abandon_Recovery_More_Email_Logs_Repository;
use PixelioCartAbandonRecoveryMore\Frontend\Repositories\Pixelio_Cart_Abandon_Recovery_More_Email_Templates_Repository;
use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

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

?>

<?php
$pixelio_wordpress_wrapper = new Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper();
$pixelio_util = new Pixelio_Cart_Abandon_Recovery_More_Util($pixelio_wordpress_wrapper);
$pixelio_cart_abandon_recovery_more_header = new Pixelio_Cart_Abandon_Recovery_More_Header($pixelio_util);
$pixelio_cart_abandon_recovery_more_header->pixelio_cart_abandon_recovery_more_get_views();
$pixelio_cart_abandon_recovery_more_templates = array();
$pixelio_cart_abandon_recovery_more_my_tabs = array(
	'Email' => 'show_email_tab',
	'Email logs' => 'show_email_logs_tab',
);
$pixelio_cart_abandon_recovery_more_tabs = new Pixelio_Cart_Abandon_Recovery_More_Multi_Tab_Switcher($pixelio_cart_abandon_recovery_more_my_tabs);
$pixelio_cart_abandon_recovery_more_tabs->pixelio_cart_abandon_recovery_more_get_views();

$pixelio_cart_abandon_recovery_more_data = [];
if ($pixelio_util->pixelio_cart_abandon_recovery_more_decrypt_api_key('pixelio_api_key')) {
	$pixelio_cart_abandon_recovery_more_data = $pixelio_util->pixelio_cart_abandon_recovery_more_call_api(
		$pixelio_util->pixelio_cart_abandon_recovery_more_get_url() . 'email-templates');
} else {
	$pixelio_Cart_Abandon_Recovery_More_Email_Templates_Model = new Pixelio_Cart_Abandon_Recovery_More_Email_Templates_Repository($pixelio_wordpress_wrapper);
	$pixelio_cart_abandon_recovery_more_all_email = array_merge(
		$pixelio_Cart_Abandon_Recovery_More_Email_Templates_Model->pixelio_get_all_non_deleted_emails_templates(1),
		$pixelio_Cart_Abandon_Recovery_More_Email_Templates_Model->pixelio_get_all_non_deleted_emails_templates(2)
	);
	if (count($pixelio_cart_abandon_recovery_more_all_email) > 0) {
		$pixelio_cart_abandon_recovery_more_data["data"] = $pixelio_cart_abandon_recovery_more_all_email;
	}
}


$pixelio_cart_abandon_recovery_more_load_spinner = new Pixelio_Cart_Abandon_Recovery_More_Admin_Loader_Spinner(__("Please wait until the operation is completed", "rivio-ai-cart-recovery-marketing-email-automation"));
$pixelio_cart_abandon_recovery_more_load_spinner->pixelio_cart_abandon_recovery_more_get_views();
?>

<div class="pixelio-cart-abandon-recovery-more-card pixelio-cart-abandon-recovery-more-card-template">
	<div class="pixelio-cart-abandon-recovery-more-card-header">
		<h2 class="pixelio-cart-abandon-recovery-more-card-title"><?php esc_attr_e('Templates', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h2>

		<button class="pixelio-cart-abandon-recovery-more-create-email">
			<img width="100%"
				 src="<?php echo esc_attr(plugins_url('../../assets/icons/new-email-icon.svg', __FILE__)); ?>"
				 alt="Icone remove Pixelio"
				 class="pixelio-remove-icon"
			/>
		</button>
	</div>
	<div id="pixelio-cart-abandon-recovery-more-auto-mode-banner"
		 style="display:none; background:#fffae6; color:#333; padding:10px; text-align:center; margin-bottom:50px; border-radius:5px;">
		<?php esc_attr_e('You are in auto mode — The generated emails will be used automatically once validated.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
		<span id="pixelio-cart-abandon-recovery-more-auto-mode-banner-validation-required">
			<?php esc_attr_e('Please review all of them to ensure they match your brand, modify & then click on validate.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
		</span>
	</div>

	<hr class="pixelio-cart-abandon-recovery-more-card-separator"/>
	<div class="pixelio-cart-abandon-recovery-more-card-content">
		<a class="pixelio-cart-abandon-recovery-more-validate-email">
			<?php esc_attr_e('Validate all templates', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
		</a>
		<table id="pixelio-cart-abandon-recovery-more-table" class="display" style="width:100%">
			<thead>
			<tr>
				<th><?php esc_attr_e('Name', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Language', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Type', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Send After', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Subject', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Performance', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Status', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Action', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
			</tr>
			</thead>
			<tbody>

			<?php

			if (null !== $pixelio_cart_abandon_recovery_more_data && !is_wp_error($pixelio_cart_abandon_recovery_more_data) && $pixelio_cart_abandon_recovery_more_data && isset($pixelio_cart_abandon_recovery_more_data['data'])) {
				$pixelio_cart_abandon_recovery_more_templates = $pixelio_cart_abandon_recovery_more_data['data'];

				foreach ($pixelio_cart_abandon_recovery_more_templates as $pixelio_cart_abandon_recovery_more_template) {
					$document_status = $pixelio_cart_abandon_recovery_more_template['document_status'] ?? 'pending';
					echo wp_kses(
						'<tr
        data-template-id="' . esc_html($pixelio_cart_abandon_recovery_more_template['id']) . '"
        document_status="' . (
						$pixelio_cart_abandon_recovery_more_template['generated_by_ia'] != null
							? esc_html($document_status)
							: 'validated'
						) . '"
        is_ia="' . esc_html($pixelio_cart_abandon_recovery_more_template['generated_by_ia']) . '"
    >',
						Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html
					);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['template_name']) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['language']) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html((string)($pixelio_cart_abandon_recovery_more_template['type_of_email'] ?? null) === '2' ? __('Review type email', 'rivio-ai-cart-recovery-marketing-email-automation') : ((string)($pixelio_cart_abandon_recovery_more_template['type_of_email'] ?? null) === '1' ? __('Abandon type email', 'rivio-ai-cart-recovery-marketing-email-automation') : __('No data', 'rivio-ai-cart-recovery-marketing-email-automation'))) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['send_after'] . esc_attr(' min') ?? __('No data', 'rivio-ai-cart-recovery-marketing-email-automation')) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['subject']) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['performanceCategory'] ?? __('No data', 'rivio-ai-cart-recovery-marketing-email-automation')) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					echo wp_kses('<td>' . esc_html($pixelio_cart_abandon_recovery_more_template['is_active'] == 1 ? __('Active', 'rivio-ai-cart-recovery-marketing-email-automation') : __('Disabled', 'rivio-ai-cart-recovery-marketing-email-automation')) . '</td>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
					?>
					<td>
					<button class="pixelio-cart-abandon-recovery-more-edit-button"
							data-template-id="<?php echo esc_attr($pixelio_cart_abandon_recovery_more_template['id']) ?>">
						<img width="100%"
							 src="<?php echo esc_attr(plugins_url('../../assets/icons/edit-icon.svg', __FILE__)); ?>"
							 alt="Icone remove Pixelio"
							 class="pixelio-remove-icon"
						/>
					</button>
					<?php if (empty($pixelio_cart_abandon_recovery_more_template['generated_by_ia'])) : ?>
						<button class="pixelio-cart-abandon-recovery-more-remove-button"
								data-template-id="<?php echo esc_attr($pixelio_cart_abandon_recovery_more_template['id']) ?>">
							<img width="100%"
								 src="<?php echo esc_attr(plugins_url('../../assets/icons/remove-icon.svg', __FILE__)); ?>"
								 alt="Icone remove Pixelio"
								 class="pixelio-remove-icon"
							/>
						</button>
					<?php endif; ?>
					</td><?php
					echo wp_kses('</tr>', Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);

				}
			}
			?>
			</tbody>
		</table>

	</div>
</div>
<?php
$pixelio_cart_abandon_recovery_more_products = wc_get_products(
	array(
		'status' => 'publish',
		'limit' => -1,
		'orderby' => 'title',
		'order' => 'ASC',
	)
);


$pixelio_cart_abandon_recovery_more_remove_popup = new Pixelio_Cart_Abandon_Recovery_More_Admin_Dialog_Popup('Delete Confirmation', "Are you sure you want to delete this item? This action cannot be undone.'", 'Cancel', 'Delete', '', 'pixelio_remove_email_template');
$pixelio_cart_abandon_recovery_more_remove_popup->pixelio_cart_abandon_recovery_more_get_views();
?>


<div class="pixelio-cart-abandon-recovery-more-card pixelio-cart-abandon-recovery-more-card-create-email">
	<button class="pixelio-cart-abandon-recovery-more-card-create-email-close">
		<img width="100%"
			 src="<?php echo esc_attr(plugins_url('../../assets/icons/close-icon.svg', __FILE__)); ?>"
			 alt="Icone remove Pixelio"
			 class="pixelio-remove-icon"
		/>
	</button>
	<h2 style="margin-bottom:15px;"><?php esc_attr_e('Configuration of the email', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h2>

	<!-- Nom du template -->
	<div style="margin-bottom:15px;">
		<label
			for="template_name"><strong><?php esc_attr_e('Name of template', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label><br>
		<input type="text" id="pixelio-cart-abandon-recovery-more-template-name" name="template_name"
			   class="pixelio-cart-abandon-recovery-more-input-text"/>
	</div>

	<!-- Langue -->
	<div style="margin-bottom:15px;"
		 class="pixelio-cart-abandon-recovery-more-language pixelio-cart-abandon-recovery-more-select-wrapper">
		<p for="template_lang"><strong>Langue</strong></p><br>
		<select id="pixelio-cart-abandon-recovery-more-template-lang" name="template_lang">
			<option
				value="fr"><?php esc_attr_e('French', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
			<option
				value="en"><?php esc_attr_e('English', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
		</select>
	</div>

	<!-- Sujet -->
	<div style="margin-bottom:15px;">
		<label
			for="template_subject"><strong><?php esc_attr_e('Subject of the email', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label><br>
		<input type="text" id="pixelio-cart-abandon-recovery-more-template-subject" name="template_subject"
			   class="pixelio-cart-abandon-recovery-more-input-text"/>
	</div>

	<!-- Type de mail -->
	<div style="margin-bottom:15px;"
		 class="pixelio-cart-abandon-recovery-more-type-of-email pixelio-cart-abandon-recovery-more-select-wrapper">
		<p>
			<strong><?php esc_attr_e('Type of the email', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong>
		</p>
		<select id="pixelio-cart-abandon-recovery-more-email-type" name="type_of_email">
			<option
				value="abandoned_cart"><?php esc_attr_e('Abandoned Cart', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
			<option
				value="review_cart"><?php esc_attr_e('Ask review', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
		</select>
	</div>

	<?php
	$pixelio_cart_abandon_recovery_more_products = wc_get_products(
		array(
			'status' => 'publish',
			'limit' => -1,
			'orderby' => 'title',
			'order' => 'ASC',
		)
	);

	$pixelio_cart_abandon_recovery_more_placeholders = array(
		'firstname' => __('Customer first name', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'lastname' => __('Customer last name', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'cart_content' => __('Cart content', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'recover_link' => __('Recover cart link', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'unsubscribe' => __('Unsubscribe link', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'discount_code' => __('Coupon', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'discount_expiration_time' => __('Discount expiration time', 'rivio-ai-cart-recovery-marketing-email-automation'),
		'store_name' => __('Store Name', 'rivio-ai-cart-recovery-marketing-email-automation'),
	);
	?>


	<strong><?php esc_attr_e('Edit your email :', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong>

	<div id='pixelio-cart-abandon-recovery-more-email-creator-parent'>
		<div id="pixelio-cart-abandon-recovery-more-email-creator-parent-container">

			<div class="pixelio-cart-abandon-recovery-more-email-preview-column">
				<?php
				ob_start();
				require plugin_dir_path(__FILE__) . '../../../includes/templates/email-templates/pixelio-cart-abandon-recovery-more-email-reminder-header.php';
				$pixelio_cart_abandon_recovery_more_header = ob_get_clean();
				echo wp_kses($pixelio_cart_abandon_recovery_more_header, Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
				?>

				<div id="pixelio-cart-abandon-recovery-more-email-preview-content">
					<?php esc_html_e('Click here to start to write', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
				</div>

				<?php
				ob_start();
				$pixelio_cart_abandon_recovery_unsubscribed_link = '';
				require plugin_dir_path(__FILE__) . '../../../includes/templates/email-templates/pixelio-cart-abandon-recovery-more-email-reminder-footer.php';
				$pixelio_cart_abandon_recovery_more_footer = ob_get_clean();
				echo wp_kses($pixelio_cart_abandon_recovery_more_footer, Pixelio_Cart_Abandon_Recovery_More_Util::$pixelio_cart_abandon_recovery_more_allowed_html);
				?>
			</table>
			</div>
			</div>

			<div id="pixelio-cart-abandon-recovery-more-email-creator-parent-placeholder-container">
				<strong><?php esc_html_e('Placeholders', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong>

				<?php foreach ($pixelio_cart_abandon_recovery_more_placeholders as $key => $label) : ?>
					<button
						type="button"
						class="pixelio-cart-abandon-recovery-more-button pixelio-cart-abandon-recovery-more-button-placeholder pixelio-cart-abandon-recovery-more-insert-placeholder"
						data-key="<?php echo esc_attr($key); ?>"
					>
						<?php echo esc_html($label); ?>
					</button>
				<?php endforeach; ?>
			</div>

		</div>
		<!-- Activation envoi -->
		<div style="margin-bottom:15px; margin-top: 15px;">
			<label><input type="checkbox" id="pixelio-cart-abandon-recovery-more-enable-send"
						  name="enable_send"/> <?php esc_attr_e('Enable sending email', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
			</label>
		</div>

		<!-- Délai -->
		<div id="pixelio-cart-abandon-recovery-more-send-delay"
			 style="display:none; margin-bottom:15px; margin-top: 15px; margin-left: 15px;">
			<label><strong><?php esc_attr_e('Delivery time', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label><br>

			<div class="" style="display: flex; margin-top: 15px;">
				<input
					type="number"
					name="delay_value"
					min="0"
					value="0"
					style="margin-top: 15px;"
				>
				<p name="delay_unit"
				   style="margin-top: 15px; margin-left: 15px;    margin-bottom: 0;  line-height: 30px;">
					<?php esc_attr_e('Minutes', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
				</p>
			</div>
		</div>

		<!-- Activation coupon -->
		<div style="margin-bottom:15px;">
			<label><input type="checkbox" id="pixelio-cart-abandon-recovery-more-enable-coupon" name="enable_coupon"/>
				<?php esc_attr_e('Activate coupon', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
			</label>
		</div>

		<!-- Paramètres coupon -->
		<div id="pixelio-cart-abandon-recovery-more-coupon-settings"
			 style="display:none; margin-bottom:15px; margin-left: 15px;">
			<label><strong><?php esc_attr_e('Value of the coupon', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label><br>
			<input type="number" name="coupon_value" min="0" style="width:80px;margin-top: 15px;"/>

			<select name="coupon_type" class="">
				<option
					value="0"><?php esc_attr_e('€ (Fixed value)', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
				<option
					value="1"><?php esc_attr_e('% (Percentage value)', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
			</select><br><br>

			<label><strong><?php esc_attr_e('Coupon expiration', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label><br>
			<div class="" style="display: flex; margin-top: 15px;">
				<input type="number" name="coupon_expire_value" min="1" style="width:80px;margin-top: 15px;"/>
				<p name="delay_unit"
				   style="margin-top: 15px; margin-left: 15px;    margin-bottom: 0;  line-height: 30px;">
					<?php esc_attr_e('Minutes', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
			</div>
		</div>
		<div class="pixelio-cart-abandon-recovery-more-send-test-section">

			<!-- Test email -->
			<div class="pixelio-cart-abandon-recovery-more-send-test-email-wrapper">
				<label><strong><?php esc_attr_e('Send a test email', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></strong></label>
				<p class="pixelio-cart-abandon-recovery-more-send-test-hint"><?php esc_attr_e('Optional, but recommended to check your email content.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
				<div class="pixelio-cart-abandon-recovery-more-send-test-email-fields">
					<input type="email" name="test_email" id="pixelio-cart-abandon-recovery-more-email-recipient"
						   class="pixelio-cart-abandon-recovery-more-input-text" placeholder="exemple@site.com"/>
					<button type="button"
							class="pixelio-cart-abandon-recovery-more-button pixelio-cart-abandon-recovery-more-send-email">
						<?php esc_attr_e('Send', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
					</button>
				</div>
			</div>

			<!-- Save button -->
			<div class="pixelio-cart-abandon-recovery-more-save-email-wrapper">
				<button id="pixelio-cart-abandon-recovery-more-save-email-content"
						class="pixelio-cart-abandon-recovery-more-button pixelio-cart-abandon-recovery-more-save-main">
			<span
				class="pixelio-cart-abandon-recovery-more-save-text"><?php esc_attr_e('Save the template', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
				</button>
			</div>

		</div>

	</div>


	<div class="pixelio-cart-abandon-recovery-more-card pixelio-cart-abandon-recovery-more-card-logs-email"
		 style=" margin-top:20px;">

		<h2><?php esc_attr_e('Sent Emails Logs', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h2>
		<p style="color:#666;"><?php esc_attr_e('Record of emails sent, linked to the corresponding abandoned cart ID.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
		<table id="email-logs-table" class="display"
			   style="width:100%; border-collapse:separate; border-spacing:0 10px;">
			<thead>
			<tr>
				<th><?php esc_attr_e('Recipient', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Subject', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Type', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Sent Date', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
				<th><?php esc_attr_e('Abandoned Cart ID', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
			</tr>
			</thead>
			<tbody>
			<?php
			$pixelio_cart_abandon_and_more_logs_model = new Pixelio_Cart_Abandon_Recovery_More_Email_Logs_Repository($pixelio_wordpress_wrapper);
			$pixelio_cart_abandon_and_more_logs = $pixelio_cart_abandon_and_more_logs_model->pixelio_get_all_emails();

			if (!empty($pixelio_cart_abandon_and_more_logs) && is_array($pixelio_cart_abandon_and_more_logs)) {
				foreach ($pixelio_cart_abandon_and_more_logs as $pixelio_cart_abandon_and_more_log) {
					$pixelio_cart_abandon_and_more_cart_id = $pixelio_cart_abandon_and_more_log->cart_id ?? '-';
					$pixelio_cart_abandon_and_more_type = (1 === intval($pixelio_cart_abandon_and_more_log->type))
						? __('Recover', 'rivio-ai-cart-recovery-marketing-email-automation')
						: __('Review', 'rivio-ai-cart-recovery-marketing-email-automation');
					?>
					<tr>
						<td><?php echo esc_html($pixelio_cart_abandon_and_more_log->recipient ?? '-'); ?></td>
						<td><?php echo esc_html($pixelio_cart_abandon_and_more_log->subject ?? '-'); ?></td>
						<td><?php echo esc_html($pixelio_cart_abandon_and_more_type); ?></td>
						<td><?php echo esc_html($pixelio_cart_abandon_and_more_log->sent_at ?? '-'); ?></td>
						<td><?php echo esc_html($pixelio_cart_abandon_and_more_cart_id); ?></td>
					</tr>
					<?php
				}
			} else {
				// Aucun log trouvé
				?>
				<tr>
					<td colspan="5" style="text-align:center;">
						<?php echo esc_html__('No email logs found for now.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>
					</td>
				</tr>
				<?php
			}
			?>
			</tbody>
		</table>
	</div>

