<?php
/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRESS is a RazorVue Trademark.
 *
 * @package     HappyFenceNG
 * @developer   Simonluca Scillitani
 * @copyright   2025 RazorVue di Scillitani Simonluca
 * @link        https://razorvue.it
 * @author      RazorVue di Scillitani Simonluca
 * @brand       HappyWPress
 * @uri         https://happywpress.com
 * @set all
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**PHPCS -> code compliance: we put useful comments where needed.. */
class HappyFenceNGMCore extends HappyFenceNGSystem {

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @var array $registry .
	 */
	private static array $registry = HappyFenceNGPlaceholder::EMPTY_ARRAY;

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $tier ..a tier.
	 * @param array  $menu_data ..see below.
	 */
	protected function push( $tier, $menu_data ) {
		if ( ! isset( self::$registry[ $tier ] ) ) {
			self::$registry[ $tier ] = $menu_data;
		} else {
			parent::raiseException( 'DUPLICATE MENU ENTRY ' . $tier );
		}
	}

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $method ..we don't use it.
	 * @param array  $args ..we don't use it.
	 */
	public function __call( $method, $args ) {
		$manager = HappyFenceNGCRcontrol::getRoute( 'MCORE' );
		add_menu_page(
			HappyFenceNGUtils::getPageTitle(),
			HappyFenceNGUtils::getMenuTitle(),
			HappyFenceNGStStored::OPTIONS,
			HappyFenceNGStStored::MAIN_SLUG,
			array( $manager, 'doRoute' ),
			'dashicons-shield',
			30
		);

		foreach ( self::$registry as $tier => $data ) {

				add_submenu_page(
					HappyFenceNGStStored::MAIN_SLUG,
					$data['title'],
					$data['menu_title'],
					HappyFenceNGStStored::OPTIONS,
					$data['slug'],
					$data['callback']
				);
		}
	}
}
