<?php
/**
 * RadiusBooking API Route Registrar
 *
 * This class is responsible for registering API routes dynamically with the WordPress REST API.
 * It supports CRUD operations and allows for middleware to be applied globally or per route.
 *
 * @package RadiusTheme\RadiusBooking\Core\Api\Routes
 */

namespace RadiusTheme\RadiusBooking\Admin;

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

/**
 * Class Menu
 *
 * Admin menu class for Radius Booking plugin.
 *
 * @package RadiusTheme\RadiusBooking\Admin
 */
class Menu {

	/**
	 * Admin constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		add_action( 'admin_menu', array( $this, 'init_menu' ) );
	}


	/**
	 * Init menu
	 *
	 * @since 1.0.0
	 */
	public function init_menu() {
		global $submenu;

		$slug          = RADIUS_BOOKING_SLUG;
		$menu_position = 50;
		$capability    = 'manage_options';

		add_menu_page( esc_attr__( 'Radius Booking', 'radius-booking' ), esc_attr__( 'Radius Booking', 'radius-booking' ), $capability, $slug, array( $this, 'plugin_page' ), RADIUS_BOOKING_ASSETS . '/icon/calendar.svg', $menu_position );

		if ( current_user_can( $capability ) ) { // phpcs:ignore
			$submenu[ $slug ][] = array( esc_attr__( 'Dashboard', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/' );
			$submenu[ $slug ][] = array( esc_attr__( 'Calender', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/calendar' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			$submenu[ $slug ][] = array( esc_attr__( 'Appointments', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/appointment' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			$submenu[ $slug ][] = array( esc_attr__( 'Staff', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/employees' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			$submenu[ $slug ][] = array( esc_attr__( 'Services', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/services' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			if ( rtrb_is_module_active( 'meeting' ) ) {
				$submenu[ $slug ][] = array( esc_attr__( 'Meeting Bookings', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/meeting-bookings' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			}
			if ( rtrb_is_module_active( 'event' ) ) {
				$submenu[ $slug ][] = array( esc_attr__( 'Event Registrations', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/event-registrations' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
			}
		    $submenu[ $slug ][] = array( esc_attr__( 'Locations', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/locations' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		    $submenu[ $slug ][] = array( esc_attr__( 'Customers', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/customers' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		    $submenu[ $slug ][] = array( esc_attr__( 'Payments', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/payments' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		    $submenu[ $slug ][] = array( esc_attr__( 'Coupons', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/coupons' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		    $submenu[ $slug ][] = array( esc_attr__( 'Emails', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/notifications' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		    $submenu[ $slug ][] = array( esc_attr__( 'Settings', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/settings?tab=general' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
//		    $submenu[ $slug ][] = array( esc_attr__( 'Form Customize', 'radius-booking' ), $capability, 'admin.php?page=' . $slug . '#/form-customization' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

			do_action( 'radius_booking_after_settings_menu_item' );
		}
	}


	/**
	 * Render the plugin page.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function plugin_page() {
		require_once RADIUS_BOOKING_TEMPLATE_PATH . '/app.php';
	}
}
