<?php
/**
 * Admin Menu Class
 *
 * @package Optikit
 */

namespace Optikit;

/**
 * Class Admin_Menu
 */
final class Admin_Menu extends \Optikit\DediData\Singleton {

	/**
	 * Constructor
	 */
	protected function __construct() {
		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
		// Adds a Settings link to the Plugins page
		add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
	}

	/**
	 * Admin Menu
	 *
	 * @return void
	 */
	public function admin_menu() {
		add_menu_page(
			esc_html__( 'Optikit', 'optikit' ),
			esc_html__( 'Optikit', 'optikit' ),
			'manage_options',
			'optikit',
			'',
			OPTIKIT()->get( 'plugin_url' ) . '/assets/public/images/logo.webp',
			56
		);

		/*
		add_submenu_page(
			'optikit',
			esc_html__( 'Bike Delivery', 'optikit' ),
			esc_html__( 'Bike Delivery', 'optikit' ),
			'manage_options',
			'admin.php?page=wc-settings&tab=shipping&section=shipping_bike',
			''
		);
		add_submenu_page(
			'optikit',
			esc_html__( 'Other DediData Services', 'optikit' ),
			esc_html__( 'Other DediData Services', 'optikit' ),
			'manage_options',
			esc_html__( 'https://dedidata.com', 'optikit' ),
			''
		);
		*/
	}

	/**
	 * Add Settings link to Plugins page
	 *
	 * @param array<string> $links       Links.
	 * @param string        $plugin_file Plugin File.
	 * @return array<string> array Links to add to plugin name
	 */
	public function plugin_action_links( $links, string $plugin_file ) {
		$this_plugin_file = OPTIKIT()->get( 'plugin_file' );
		if ( basename( plugin_dir_path( $this_plugin_file ) ) . '/Optikit.php' === $plugin_file ) {
			$links[] = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'admin.php?page=optikit' ) ), esc_html__( 'Settings', 'optikit' ) );
		}
		return $links;
	}
}
