<?php
/**
 * Admin menu registration.
 *
 * @package Vanquish\MultipleAddresses\Admin
 */

namespace Vanquish\MultipleAddresses\Admin;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Registers the plugin admin menu. The top-level slug (vanmuad-addresses)
 * matches the Freemius menu slug, so Freemius attaches its own sub-pages
 * (Account, Upgrade, …) under it.
 */
class AdminMenu {

	/**
	 * Top-level menu slug (must match the Freemius 'menu' => 'slug').
	 */
	const MENU_SLUG = 'vanmuad-addresses';

	/**
	 * Settings page.
	 *
	 * @var SettingsPage
	 */
	private $settings_page;

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->settings_page = new SettingsPage();

		add_action( 'admin_menu', array( $this, 'register' ) );
	}

	/**
	 * Register the menu and sub-pages.
	 *
	 * @return void
	 */
	public function register() {
		add_menu_page(
			__( 'Multiple Addresses', 'vanquish-multiple-addresses-for-woocommerce' ),
			__( 'Multiple Addresses', 'vanquish-multiple-addresses-for-woocommerce' ),
			'manage_woocommerce',
			self::MENU_SLUG,
			array( $this->settings_page, 'render' ),
			'dashicons-book-alt',
			56
		);

		add_submenu_page(
			self::MENU_SLUG,
			__( 'Settings', 'vanquish-multiple-addresses-for-woocommerce' ),
			__( 'Settings', 'vanquish-multiple-addresses-for-woocommerce' ),
			'manage_woocommerce',
			self::MENU_SLUG,
			array( $this->settings_page, 'render' )
		);

		/**
		 * Extension point for premium admin pages (Import, per-product shipping, …).
		 *
		 * @param string $parent_slug The plugin's top-level menu slug.
		 */
		do_action( 'vanmuad_admin_menu', self::MENU_SLUG );
	}
}
