<?php
/**
 * Class SettingsSubmenu
 *
 * @package DhlPolska\Admin\Menu
 */

namespace DhlPolska\Admin\Menu;

use DhlPolska\Admin\DhlPolskaMenu;
use DhlPolska\WooCommerceSettings\WooCommerceDHLPolskaSettingsPage;
use DhlPolskaVendor\WPDesk\PluginBuilder\Plugin\Hookable;

/**
 * Register DHL Polska settings submenu.
 */
class SettingsSubmenu implements Hookable {
	public const MENU_SLUG = 'dhl-polska-settings';

	/**
	 * Hooks.
	 */
	public function hooks() {
		add_action( 'admin_menu', [ $this, 'register_submenu' ] );
	}

	/**
	 * @return void
	 */
	public function register_submenu() {
		add_submenu_page(
			DhlPolskaMenu::MENU_SLUG,
			__( 'Ustawienia', 'dhl-polska' ),
			__( 'Ustawienia', 'dhl-polska' ),
			'manage_woocommerce',
			self::MENU_SLUG,
			[ $this, 'redirect_to_settings' ],
			30
		);
	}

	/**
	 * @return void
	 */
	public function redirect_to_settings() {
		wp_safe_redirect(
			admin_url(
				'admin.php?page=wc-settings&tab=shipping&section=' . WooCommerceDHLPolskaSettingsPage::SECTION_ID
			)
		);
		exit;
	}
}
