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

namespace SuiteMkt3k\Admin\Pages;

use SuiteMkt3k\Modules\Subscribers\Subscriber_Manager;
use SuiteMkt3k\Security\Capabilities;
use SuiteMkt3k\Security\Nonces;

defined( 'ABSPATH' ) || exit;

final class Subscribers_Page extends Base_Page {

	protected static string $slug = 'suitemkt3k-subscribers';
	protected static string $cap  = Capabilities::EDIT_CAMPAIGN;

	public static function render(): void {
		static::$page_title    = __( 'Subscribers', 'suitemkt3k' );
		static::$page_subtitle = __( 'Manage marketing contacts captured through coupons and newsletter forms', 'suitemkt3k' );
		parent::render();
	}

	protected static function content(): void {
		$nonce       = Nonces::create( Nonces::ADMIN_ACTION );
		$paged_raw   = filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT );
		$search = \SuiteMkt3k\Utils\Sanitizer::get( 's', 'text' );
		$source = \SuiteMkt3k\Utils\Sanitizer::get( 'source', 'key' );
		$status = \SuiteMkt3k\Utils\Sanitizer::get( 'status', 'key' );
		$paged = max( 1, (int) $paged_raw );
		$subscribers = Subscriber_Manager::query( array(
			'paged'  => $paged,
			'search' => $search,
			'source' => $source,
			'status' => $status,
		) );
		include SUITEMKT3K_PATH . 'includes/admin/views/subscribers-list.php';
	}
}
