<?php
/**
 * Statistics admin page.
 *
 * @package SuiteMkt3k
 */

namespace SuiteMkt3k\Admin\Pages;

use SuiteMkt3k\Modules\Statistics\Stats_Aggregator;
use SuiteMkt3k\Security\Capabilities;
use SuiteMkt3k\Security\Nonces;

defined( 'ABSPATH' ) || exit;

final class Statistics_Page extends Base_Page {

	protected static string $slug = 'suitemkt3k-statistics';
	protected static string $cap  = Capabilities::VIEW_STATS;

	public static function render(): void {
		static::$page_title    = __( 'Statistics', 'suitemkt3k' );
		static::$page_subtitle = __( 'Track impressions, opens, clicks, conversions and revenue', 'suitemkt3k' );
		parent::render();
	}

	protected static function content(): void {
		$range     = \SuiteMkt3k\Utils\Sanitizer::get( 'range', 'key' );
		$category  = \SuiteMkt3k\Utils\Sanitizer::get( 'category', 'key' );
		$entity_id = max( 0, (int) \SuiteMkt3k\Utils\Sanitizer::get( 'entity_id', 'int' ) );
		if ( '' === $range ) {
			$range = '30d';
		}
		if ( '' === $category ) {
			$category = 'all';
		}
		$nonce     = Nonces::create( Nonces::ADMIN_ACTION );
		$data      = Stats_Aggregator::overview( $range, $category, $entity_id );
		include SUITEMKT3K_PATH . 'includes/admin/views/statistics.php';
	}
}
