<?php
/**
 * Coupons admin page (list + designer mount point).
 *
 * @package SuiteMkt3k
 */

namespace SuiteMkt3k\Admin\Pages;

use SuiteMkt3k\Modules\Coupons\Coupon_Manager;
use SuiteMkt3k\Security\Capabilities;
use SuiteMkt3k\Security\Nonces;

defined( 'ABSPATH' ) || exit;

final class Coupons_Page extends Base_Page {

	protected static string $slug         = 'suitemkt3k-coupons';
	protected static string $cap          = Capabilities::EDIT_CAMPAIGN;
	protected static bool   $requires_wc  = true;

	public static function render(): void {
		static::$page_title    = __( 'Coupon Campaigns', 'suitemkt3k' );
		static::$page_subtitle = __( 'Design, schedule and track your discount 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 ) {
			$coupon = $id ? Coupon_Manager::get( $id ) : null;
			include SUITEMKT3K_PATH . 'includes/admin/views/coupon-designer.php';
			return;
		}
		if ( 'calendar' === $view ) {
			include SUITEMKT3K_PATH . 'includes/admin/views/coupon-calendar.php';
			return;
		}
		if ( 'email_template' === $view ) {
			include SUITEMKT3K_PATH . 'includes/admin/views/coupon-email-template-editor.php';
			return;
		}
		$coupons = Coupon_Manager::list();
		include SUITEMKT3K_PATH . 'includes/admin/views/coupon-list.php';
	}
}
