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

namespace SuiteMkt3k\Admin\Pages;

use SuiteMkt3k\Modules\Newsletter\Newsletter_Manager;
use SuiteMkt3k\Security\Capabilities;
use SuiteMkt3k\Security\Nonces;

defined( 'ABSPATH' ) || exit;

final class Newsletter_Page extends Base_Page {

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

	public static function render(): void {
		static::$page_title    = __( 'Newsletter', 'suitemkt3k' );
		static::$page_subtitle = __( 'Design, schedule and send email campaigns', 'suitemkt3k' );
		parent::render();
	}

	protected static function content(): void {
		$view = \SuiteMkt3k\Utils\Sanitizer::get( 'view', 'key' );
		if ( '' === $view ) {
			$view = 'list';
		}
		$id = max( 0, (int) \SuiteMkt3k\Utils\Sanitizer::get( 'id', 'int' ) );
		$nonce = Nonces::create( Nonces::ADMIN_ACTION );

		if ( 'edit' === $view ) {
			$campaign = $id ? Newsletter_Manager::get( $id ) : null;
			include SUITEMKT3K_PATH . 'includes/admin/views/newsletter-designer.php';
			return;
		}
		if ( 'forms' === $view ) {
			include SUITEMKT3K_PATH . 'includes/admin/views/newsletter-forms.php';
			return;
		}
		$campaigns = Newsletter_Manager::list();
		include SUITEMKT3K_PATH . 'includes/admin/views/newsletter-list.php';
	}
}
