<?php
/**
 * Pixelio Cart Abandon Recovery More - Dashboard Page
 *
 * This file handles the dashboard page in the WordPress admin for the
 * Pixelio Cart Abandon Recovery More plugin. It provides:
 * - Global KPI statistics
 * - Email campaign KPIs
 * - Product abandonment statistics
 * - Cart logs
 * - Date range selection
 *
 * Features:
 * - Retrieves data via AJAX from the plugin API
 * - Displays charts and tables for statistics
 * - Allows custom date range selection
 *
 * @package PixelioCartAbandonRecoveryMore
 * @subpackage Admin
 * @since 0.1
 */
if (!defined('ABSPATH')) exit;

use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Header;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Overlay;
use PixelioCartAbandonRecoveryMore\Admin\Views\Reusable\Pixelio_Cart_Abandon_Recovery_More_Section_Title;
use PixelioCartAbandonRecoveryMore\Admin\Wrapper\Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper;
use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

$pixelio_cart_abandon_recovery_more_value_of_select = 0;

$pixelio_cart_abandon_recovery_more_no_data = esc_html(__('No data available yet', 'rivio-ai-cart-recovery-marketing-email-automation'));

$pixelio_util = new Pixelio_Cart_Abandon_Recovery_More_Util(new Pixelio_Cart_Abandon_Recovery_More_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();
?>
<div id="pixelio-cart-abandon-recovery-more-page-body">


	<div
		class="pixelio-cart-abandon-recovery-more-page-section pixelio-cart-abandon-recovery-more-page-section-container pixelio-cart-abandon-recovery-more-card">
		<?php $pixelio_cart_abandon_recovery_more_overlay = new Pixelio_Cart_Abandon_Recovery_More_Overlay();
		$pixelio_cart_abandon_recovery_more_overlay->pixelio_cart_abandon_recovery_more_get_views(); ?>
		<div class="pixelio-cart-abandon-recovery-more-page-section-container-header">
			<?php
			$pixelio_cart_abandon_recovery_more_product_title_section = new Pixelio_Cart_Abandon_Recovery_More_Section_Title(esc_html(__('Dashboard', 'rivio-ai-cart-recovery-marketing-email-automation')));
			$pixelio_cart_abandon_recovery_more_product_title_section->pixelio_cart_abandon_recovery_more_get_views();
			?>
			<div class="pixelio-cart-abandon-recovery-more-page-section-container">

				<form action="" method="post"
					  class="pixelio-cart-abandon-recovery-more-dashboard-form- pixelio-cart-abandon-recovery-more-hide-it">
					<label
						for="pixelio-cart-abandon-recovery-more-dashboard-range"><?php esc_html_e('Select date range', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></label>

					<select name="pixelio-cart-abandon-recovery-more-dashboard-range"
							class="pixelio-cart-abandon-recovery-more-select"
							id="pixelio-cart-abandon-recovery-more-select-date-dashboard" required>
						<option
							value="0" <?php echo '0' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>><?php esc_html_e('Today', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
						<option
							value="-1" <?php echo '-1' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>> <?php esc_html_e('Yesterday', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
						<option
							value="-30" <?php echo '-30' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>><?php esc_html_e('30 days', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
						<option
							value="-90" <?php echo '-90' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>><?php esc_attr_e('90 days', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
						<option
							value="-365" <?php echo '-365' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>><?php esc_attr_e('365 days', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
						<option
							value="custom" <?php echo 'custom' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('selected') : esc_html(''); ?>><?php esc_attr_e('Custom', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></option>
					</select>
					<input type="text" id="pixelio-cart-abandon-recovery-more-date-range"
						   name="pixelio-cart-abandon-recovery-more-date-range"
						   class="<?php echo 'custom' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('') : esc_html('pixelio-cart-abandon-recovery-more-hide-it'); ?>"
						   placeholder="<?php esc_attr_e('Select Date Range', 'rivio-ai-cart-recovery-marketing-email-automation'); ?>" <?php echo 'custom' === $pixelio_cart_abandon_recovery_more_value_of_select ? esc_html('required') : esc_html(''), esc_html('pixelio-cart-abandon-recovery-more'); ?>/>
					<button
						class="pixelio-cart-abandon-recovery-more-gradient pixelio-cart-abandon-recovery-more-style-2 pixelio-cart-abandon-recovery-more-pixelio-style-button"
						type="submit"><?php esc_attr_e('Submit', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></button>
				</form>
			</div>
		</div>

		<div class="pixelio-cart-abandon-recovery-more-stats-container">
			<div class="pixelio-cart-abandon-recovery-more-stat-card">
				<div class="pixelio-cart-abandon-recovery-more-stat-card-header">
					<h3><?php esc_attr_e('Global statistics', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h3>
					<div class="pixelio-cart-abandon-recovery-more-canvas-container">

					</div>
				</div>

				<div class="pixelio-cart-abandon-recovery-more-kpi-container">
					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="abandonment">
						<div class="pixelio-kpi-icon">↘</div>
						<div>
							<p><?php esc_attr_e('Abandonment Rate', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>
					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="sent">
						<div class="pixelio-kpi-icon">✉</div>
						<div>
							<p><?php esc_attr_e('Emails Sent', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>

					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="open">
						<div class="pixelio-kpi-icon">€</div>
						<div>
							<p><?php esc_attr_e('Open Rate', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>

					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="recovery">
						<div class="pixelio-kpi-icon">👁</div>
						<div>
							<p><?php esc_attr_e('Recovery Rate', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>

					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="avg-recovery">
						<div class="pixelio-kpi-icon">€</div>
						<div>
							<p><?php esc_attr_e('Average Recovery Cart', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>

					<div class="pixelio-cart-abandon-recovery-more-kpi" data-kpi="generetaed">
						<div class="pixelio-kpi-icon">⚡</div>
						<div>
							<p><?php esc_attr_e('Revenue Generated Cart', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
							<strong class="pixelio-kpi-value is-loading">—</strong>
							<span class="pixelio-kpi-helper"><?php esc_attr_e('Collecting cart activity', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></span>
						</div>
					</div>
				</div>
				<p class="pixelio-cart-abandon-recovery-more-analyze-explanation pixelio-cart-abandon-recovery-more-hide-it"> <?php esc_attr_e('*We\'re still collecting data. Insights will be available in a few days.', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></p>
			</div>

			<div class="pixelio-cart-abandon-recovery-more-stat-card">
				<div class="pixelio-cart-abandon-recovery-more-stat-card-header">
					<h3><?php esc_attr_e('Email statistics', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h3>
					<div class="pixelio-cart-abandon-recovery-more-canvas-container">
						<canvas id="bar-campaigns" height="50"></canvas>
					</div>
				</div>
				<table id="emails-table" class="display"
					   style="width:100%; color:#000; background:#fff; border-radius:12px;">
					<thead>
					<tr>
						<th><?php esc_attr_e('#', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Email Name', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Sent', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Opens', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Clicks', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Conversions', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Revenue (€)', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
					</tr>
					</thead>
					<tbody>
					<tr>
						<th></th>
						<th></th>
						<th></th>
						<th>        <?php esc_attr_e('Currently no data', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th></th>
						<th></th>
						<th></th>
					</tr>

					</tbody>
				</table>
			</div>

			<!-- Statistiques par Produit -->
			<div class="pixelio-cart-abandon-recovery-more-stat-card">
				<div class="pixelio-cart-abandon-recovery-more-stat-card-header">
					<h3><?php esc_attr_e('Most Abandoned Products', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h3>
					<div class="pixelio-cart-abandon-recovery-more-canvas-container">

					</div>
				</div>
				<table id="products-table" class="display"
					   style="width:100%; color:#000; background:#fff; border-radius:12px;">
					<thead>
					<tr>
						<th><?php esc_attr_e('Product', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Number of Abandoned Carts', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Total Value (€)', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Last Abandoned', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
					</tr>
					</thead>
					<tbody>
					<tr>
						<th></th>
						<th></th>
						<th>        <?php esc_attr_e('Currently no data', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th></th>
					</tr>
					</tbody>
				</table>
			</div>

			<div class="pixelio-cart-abandon-recovery-more-stat-card">
				<div class="pixelio-cart-abandon-recovery-more-stat-card-header">
					<h3><?php esc_attr_e('Cart logs', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></h3>
					<div class="pixelio-cart-abandon-recovery-more-canvas-container">
						<canvas id="bar-cart" height="50"></canvas>
					</div>
				</div>
				<table id="logs-table" class="display"
					   style="width:100%; color:#000; background:#fff; border-radius:12px;">
					<thead>
					<tr>
						<th><?php esc_attr_e('Cart ID', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Price', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Date', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th><?php esc_attr_e('Status', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
					</tr>
					</thead>
					<tbody>
					<tr>
						<th></th>
						<th></th>
						<th>        <?php esc_attr_e('Currently no data', 'rivio-ai-cart-recovery-marketing-email-automation'); ?></th>
						<th></th>
					</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>

</div>

