<?php
/**
 * TutorHelper admin menu controller.
 *
 * @package TutorHelper_Bookings
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Registers the shared TutorHelper admin menu.
 */
final class TutorHelper_Admin {

	/**
	 * Main TutorHelper menu slug.
	 *
	 * @var string
	 */
	const MENU_SLUG = 'tutorhelper';

	/**
	 * Capability required to manage TutorHelper Bookings.
	 *
	 * This can later be filtered or replaced with a dedicated capability.
	 *
	 * @var string
	 */
	const CAPABILITY = 'manage_options';

	/**
	 * Register WordPress hooks.
	 *
	 * @return void
	 */
	public static function init() {
		add_action(
			'admin_menu',
			array( __CLASS__, 'register_menu' )
		);
	}

	/**
     * Register the top-level TutorHelper menu.
     *
     * @return void
     */
    public static function register_menu() {
        add_menu_page(
            __(
                'TutorHelper Booking Hub',
                'tutorhelper-bookings'
            ),
            __(
                'TutorHelper',
                'tutorhelper-bookings'
            ),
            self::CAPABILITY,
            self::MENU_SLUG,
            array(
                'TutorHelper_Booking_Hub',
                'render_page',
            ),
            'dashicons-calendar-alt',
            30
        );
    }

	/**
	 * Render the temporary TutorHelper dashboard.
	 *
	 * @return void
	 */
	public static function render_dashboard() {
		if ( ! current_user_can( self::CAPABILITY ) ) {
			return;
		}

		?>
		<div class="wrap">
			<h1>
				<?php
				echo esc_html__(
					'TutorHelper',
					'tutorhelper-bookings'
				);
				?>
			</h1>

			<p>
				<?php
				echo esc_html__(
					'Manage lesson booking types, tutor availability and student bookings.',
					'tutorhelper-bookings'
				);
				?>
			</p>

			<p>
				<a
					class="button button-primary"
					href="<?php echo esc_url( self::get_booking_types_url() ); ?>"
				>
					<?php
					echo esc_html__(
						'Manage Booking Types',
						'tutorhelper-bookings'
					);
					?>
				</a>
			</p>
		</div>
		<?php
	}

	/**
	 * Return the Booking Types admin URL.
	 *
	 * @return string
	 */
	public static function get_booking_types_url() {
		return add_query_arg(
			array(
				'page' => TutorHelper_Booking_Types_Admin::PAGE_SLUG,
			),
			admin_url( 'admin.php' )
		);
	}
}
