<?php
/**
 * Small helpers extracted from Admin to keep class-admin.php maintainable.
 *
 * @package LLMagnet_AI_SEO_Optimizer
 */

namespace LLMagnet_AI_SEO_Optimizer;

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

/**
 * WordPress admin hook / page slug mapping for the React shell.
 */
class Admin_WP_Helper {

	/**
	 * Map WP admin screen hook to ?page= slug for the React admin shell.
	 *
	 * @param string $hook Current admin hook.
	 * @return string|null
	 */
	public static function wp_page_from_hook( string $hook ): ?string {
		$map = [
			'toplevel_page_llmagnet-ai-seo-optimizer'          => 'llmagnet-ai-seo-optimizer',
			'llmagnet_page_llmagnet-ai-seo-overview'           => 'llmagnet-ai-seo-overview',
			'llmagnet_page_llmagnet-ai-seo-pages'              => 'llmagnet-ai-seo-pages',
			'llmagnet_page_llmagnet-ai-seo-products'           => 'llmagnet-ai-seo-products',
			'llmagnet_page_llmagnet-ai-seo-bot-analytics'      => 'llmagnet-ai-seo-bot-analytics',
			'llmagnet_page_llmagnet-ai-seo-reports'            => 'llmagnet-ai-seo-reports',
			'llmagnet_page_llmagnet-ai-seo-content-settings'   => 'llmagnet-ai-seo-content-settings',
			'llmagnet_page_llmagnet-ai-seo-schema-jsonld'      => 'llmagnet-ai-seo-schema-jsonld',
			'llmagnet_page_llmagnet-ai-seo-system-information' => 'llmagnet-ai-seo-system-information',
		];
		return $map[ $hook ] ?? null;
	}

	/**
	 * Whether the ?page= slug belongs to this plugin admin UI.
	 *
	 * @param string $wp_page Page slug.
	 * @return bool
	 */
	public static function is_plugin_wp_page( string $wp_page ): bool {
		$valid = [
			'llmagnet-ai-seo-optimizer',
			'llmagnet-ai-seo-overview',
			'llmagnet-ai-seo-pages',
			'llmagnet-ai-seo-products',
			'llmagnet-ai-seo-bot-analytics',
			'llmagnet-ai-seo-reports',
			'llmagnet-ai-seo-content-settings',
			'llmagnet-ai-seo-schema-jsonld',
			'llmagnet-ai-seo-system-information',
		];
		return in_array( $wp_page, $valid, true );
	}
}
