<?php
/**
 * Dashboard screen for cart recovery.
 *
 * @package EDD\Pro\CartRecovery\Admin\Screens
 * @copyright Copyright (c) 2026, Sandhills Development, LLC
 * @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since 3.6.5
 */

namespace EDD\Pro\CartRecovery\Admin\Screens;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use EDD\Pro\CartRecovery\Admin\Tables\Carts;

/**
 * Dashboard screen for cart recovery.
 */
class Dashboard {

	/**
	 * Renders the dashboard screen.
	 *
	 * @since 3.6.5
	 */
	public static function render() {
		$table = new Carts();
		$table->prepare_items();

		// Get summary statistics for current view.
		$summary = $table->get_summary_stats();
		if ( $summary['count'] > 0 ) :
			?>
		<div class="edd-acr-summary-bar">
			<div class="edd-acr-summary-item">
				<span class="dashicons dashicons-cart"></span>
				<span class="edd-acr-summary-label"><?php esc_html_e( 'Showing', 'easy-digital-downloads' ); ?>:</span>
				<span class="edd-acr-summary-value"><?php echo esc_html( number_format_i18n( $summary['count'] ) ); ?></span>
				<span class="edd-acr-summary-unit"><?php echo esc_html( _n( 'cart', 'carts', $summary['count'], 'easy-digital-downloads' ) ); ?></span>
			</div>

			<div class="edd-acr-summary-divider"></div>

			<div class="edd-acr-summary-item">
				<span class="dashicons dashicons-money-alt"></span>
				<span class="edd-acr-summary-label"><?php esc_html_e( 'Total Value', 'easy-digital-downloads' ); ?>:</span>
				<span class="edd-acr-summary-value"><?php echo esc_html( edd_currency_filter( edd_format_amount( $summary['total_value'] ) ) ); ?></span>
			</div>

			<div class="edd-acr-summary-divider"></div>

			<div class="edd-acr-summary-item">
				<span class="dashicons dashicons-chart-bar"></span>
				<span class="edd-acr-summary-label"><?php esc_html_e( 'Average', 'easy-digital-downloads' ); ?>:</span>
				<span class="edd-acr-summary-value"><?php echo esc_html( edd_currency_filter( edd_format_amount( $summary['avg_value'] ) ) ); ?></span>
			</div>
		</div>
		<?php endif; ?>

		<?php
		$table->display();
	}
}
