<?php
/**
 * Custom page class.
 *
 * @package northmill-online-shared
 */

namespace Northmill_Online_Shared\Modules\Admin\Pages\Page;

use Closure;
use Northmill_Online_Shared\Modules\Admin\Pages\Abstract_Admin_Page;

defined( 'ABSPATH' ) || exit;

/**
 * Class Custom_Page
 */
class Custom_Page extends Abstract_Admin_Page {

	/**
	 * Callback for rendering the custom page.
	 *
	 * @var $custom_callback
	 *
	 * @noinspection PhpMissingFieldTypeInspection
	 */
	public $custom_callback;

	/**
	 * Custom_Page constructor.
	 *
	 * @param mixed              $custom_callback              Callable for rendering the custom page.
	 * @param string             $page_collection_key          Collection key for the page.
	 * @param string             $page_id                      Page ID.
	 * @param array|Closure      $page_title                   Function to get page title.
	 * @param array|Closure|null $page_menu_title              Function to get page menu title.
	 * @param bool               $is_main_page                 Whether the page is the main page.
	 * @param array|Closure|null $script_localization_callback Optional callback to get script localization data.
	 * @param array|Closure|null $script_dependencies_callback Optional callback to get script dependency data.
	 */
	public function __construct(
		mixed $custom_callback,
		string $page_collection_key,
		string $page_id,
		array|Closure $page_title,
		null|array|Closure $page_menu_title = null,
		bool $is_main_page = false,
		array|Closure|null $script_localization_callback = null,
		array|Closure|null $script_dependencies_callback = null
	) {
		parent::__construct(
			$page_collection_key,
			$page_id,
			$page_title,
			$page_menu_title,
			$is_main_page,
			$script_localization_callback,
			$script_dependencies_callback
		);
		$this->custom_callback = $custom_callback;
	}

	/**
	 * Render the settings page.
	 */
	public function render_settings_page(): void {
		if ( ! empty( $this->custom_callback ) && is_callable( $this->custom_callback ) ) {
			call_user_func( $this->custom_callback );
		}
	}
}
