<?php
namespace Pay4All\Pro\Integrations\Age;

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

/**
 * Injects a « Vérification de l'âge » submenu under WooCommerce that
 * links straight to pay4all-age's settings page
 * (`admin.php?page=p4all-age-settings`).
 *
 * Only booted when pay4all-pro + pay4all-age + WooCommerce are all
 * active — see Plugin::boot_form_mode() and the WC-only branch of
 * Plugin::boot(). The submenu is a pure redirect entry : WordPress
 * accepts an `admin.php?page=…` URL as the fifth `add_submenu_page()`
 * argument and treats the item as a link with no render callback.
 */
final class WooMenu {

	public static function register() : void {
		add_action( 'admin_menu', [ self::class, 'add_submenu' ], 12 );
	}

	public static function add_submenu() : void {
		// WooCommerce registers its own top-level menu on `admin_menu`
		// at the default priority ; running at 12 keeps us safely
		// after it. Guard on capability so the entry doesn't appear
		// to admins who can't reach the target settings page.
		if ( ! current_user_can( 'manage_options' ) ) { return; }

		$label = __( 'Vérification de l\'âge', 'pay4all-pro' );
		add_submenu_page(
			'woocommerce',
			$label,
			$label,
			'manage_options',
			'admin.php?page=p4all-age-settings',
			''
		);
	}
}
