<?php

namespace WPKIN_SHOP_MANAGER\Admin;

if ( ! defined( 'ABSPATH' ) ) {
	wp_die( esc_html__( 'You can\'t access this page', 'shop-manager' ) );
}

/**
 * Admin Menu Class
 *
 * @since 1.0.0
 */
class Menu {

	/**
	 * Menu class constructor
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		add_action( 'admin_menu', [ $this, 'wpkin_regiter_admin_menu' ] );
		add_action( 'admin_head', [ $this, 'wpkin_menu_icon_style' ] );
	}

	/**
	 * Register Admin Menue
	 *
	 * @return void
	 */
	public function wpkin_regiter_admin_menu() {
		$user    = 'manage_options';
		$svg_url = plugins_url( '../../images/dashboard-icon.svg', __FILE__ );
		add_menu_page( __( 'Shop Manager', 'shop-manager' ), __( 'Shop Manager', 'shop-manager' ), $user, 'shop-manager-settings', [ $this, 'wpkin_plugin_page' ], $svg_url, 58 );
	}

	/**
	 * Fix SVG icon colors for dark admin sidebar
	 *
	 * @return void
	 */
	public function wpkin_menu_icon_style() {
		?>
		<style>
		#adminmenu #toplevel_page_shop-manager-settings .wp-menu-image img {
			padding: 4px 0 0;
		}
		</style>
		<?php
	}

	/**
	 * Plugin Admin Menu
	 *
	 * @return void
	 */
	public function wpkin_plugin_page() {
		echo '<div id="shop-manager-admin"></div>';
	}
}
