<?php
/**
 * PostGate Admin Class
 *
 * This file contains the WordPress admin interface controller for the PostGate
 * plugin. Handles admin menu structure and page rendering for the plugin's
 * admin interface. All admin pages use React-based dynamic interfaces.
 *
 * @package PostGate
 * @subpackage Admin
 * @since 1.0.0
 * @author QodeSphere
 * @license GPL-2.0+
 */

defined( 'ABSPATH' ) || exit;

/**
 * PostGate Admin Controller Class
 *
 * Provides the WordPress admin interface for PostGate plugin.
 * Manages the admin menu structure and renders container pages for
 * React-based dynamic admin interfaces.
 *
 * This class creates a top-level menu with three subpages:
 * - Dashboard: Overview and key metrics
 * - Orders: Customer orders and payment management
 * - Settings: Plugin configuration and Stripe integration
 *
 * All page content is dynamically rendered via React applications that
 * mount to container divs provided by this class. The actual functionality
 * for settings, Stripe connection, and data management is handled by
 * separate specialized classes and JavaScript modules.
 *
 * @since 1.0.0
 */
class PostGate_Admin {

	/**
	 * Initialize the admin class.
	 *
	 * Sets up WordPress hooks for admin menu registration.
	 * Registers the admin_menu action to create the PostGate admin interface.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public static function init() {
		add_action( 'admin_menu', [ __CLASS__, 'add_admin_menu' ] );
	}

	/**
	 * Add the admin menu and submenus to WordPress admin.
	 *
	 * Creates a top-level PostGate menu with lock icon at position 30,
	 * followed by three submenus:
	 * - Dashboard: Main overview page (also serves as the parent page)
	 * - Orders: Order management and payment history
	 * - Settings: Plugin configuration and Stripe integration
	 *
	 * All menu items require 'manage_options' capability (administrator access).
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public static function add_admin_menu() {
		// Add top-level menu with dashboard page
		add_menu_page(
			'PostGate',           // Page title
			'PostGate',                     // Menu title
			'manage_options',               // Capability
			'postgate-dashboard',           // Menu slug
			[ __CLASS__, 'render_dashboard_page' ], // Callback
			PostGate_Icons::get_admin_menu_icon(),  // Icon (custom SVG)
			30                              // Position
		);

		// Add submenu for Dashboard
		add_submenu_page(
			'postgate-dashboard',           // Parent slug
			'PostGate Dashboard',           // Page title
			'Dashboard',                    // Menu title
			'manage_options',               // Capability
			'postgate-dashboard',           // Menu slug
			[ __CLASS__, 'render_dashboard_page' ] // Callback
		);

		// Add submenu for Orders
		add_submenu_page(
			'postgate-dashboard',           // Parent slug
			'PostGate Orders',              // Page title
			'Orders',                       // Menu title
			'manage_options',               // Capability
			'postgate-orders',              // Menu slug
			[ __CLASS__, 'render_orders_page' ] // Callback
		);

		// Add submenu for Settings New
		add_submenu_page(
			'postgate-dashboard',           // Parent slug
			'PostGate Settings',            // Page title
			'Settings',                     // Menu title
			'manage_options',               // Capability
			'postgate-settings',            // Menu slug
			[ __CLASS__, 'render_settings_page' ] // Callback
		);
	}

	/**
	 * Render the PostGate dashboard page.
	 *
	 * Outputs the container div for the React-based dashboard interface.
	 * The actual dashboard content (overview, metrics, recent orders, etc.)
	 * is dynamically rendered by the JavaScript application that mounts to
	 * the #postgate-dashboard-root element.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public static function render_dashboard_page() {
		?>
		<!-- Dashboard content will be implemented here -->
		<div id="postgate-dashboard-root" class="postgate-container">
			<!-- Dynamic content will be loaded here -->
		</div>

		<?php
	}

	/**
	 * Render the PostGate orders page.
	 *
	 * Outputs the container div for the React-based orders interface.
	 * The actual orders list (filtering, pagination, order details, refunds)
	 * is dynamically rendered by the JavaScript application that mounts to
	 * the #postgate-orders-root element.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public static function render_orders_page() {
		?>
		<div id="postgate-orders-root" class="postgate-container">
			<!-- Dynamic content will be loaded here -->
		</div>
		<?php
	}

	/**
	 * Render the PostGate settings page.
	 *
	 * Outputs the container div for the React-based settings interface.
	 * The actual settings forms (Stripe connection, webhook configuration,
	 * preview mode, bypass roles, post types, etc.) are dynamically rendered
	 * by the JavaScript application that mounts to the #postgate-settings-root element.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public static function render_settings_page() {
		?>
		<div id="postgate-settings-root" class="postgate-container">
			<!-- Dynamic content will be loaded here -->
		</div>
		<?php
	}
}

