<?php

namespace BexioConnectorByHelvy;

/**
 * Setup Menu Pages
 *
 * @since 0.1.0
 */

defined('ABSPATH') || exit;

class AdminMenu
{

	public function __construct()
	{
		// Add submenu items
		add_action('admin_menu', array($this, 'register_menu'));
		// Add links under plugin page.
		add_filter('plugin_action_links_wp-react-admin-panel/wp-react-admin-panel.php', array($this, 'add_settings_link'));
		add_filter('plugin_action_links_wp-react-admin-panel/wp-react-admin-panel.php', array($this, 'docs_link'));
	}


	/**
	 * Define Menu
	 *
	 * @since 0.1.0
	 */
	public function register_menu()
	{
		add_submenu_page(
			'woocommerce', // Parent slug: 'woocommerce' for WooCommerce menu
			__('Bexio Connector', 'bexio-connector-by-helvy'), // Page title
			__('Bexio Connector', 'bexio-connector-by-helvy'), // Menu title
			'manage_woocommerce', // Capability
			'bexio-connector-by-helvy', // Menu slug
			array($this, 'display_react_admin_page') // Function to display the page content
		);
	}

	/**
	 * Init the view part.
	 *
	 * @since 0.1.0
	 */
	public function display_react_admin_page()
	{
		echo "<div id='bexio-connector-root'></div>";
	}

	/**
	 * Plugin Settings Link on plugin page
	 *
	 * @since 0.1.0
	 */
	function add_settings_link($links)
	{
		$settings = array(
			'<a href="' . admin_url('admin.php?page=bexio-connector-by-helvy') . '">Settings</a>',
		);
		return array_merge($links, $settings);
	}


	/**
	 * Plugin Documentation Link on plugin page
	 *
	 * @since 0.1.0
	 */
	function docs_link($links)
	{
		$docs = array(
			'<a target="_blank" href="https://helvy.ch">Documentation</a>',
		);
		return array_merge($links, $docs);
	}
}
