<?php

namespace ONLINE_ADAv4;

use ONLINE_ADAv4\Plugin;
use ONLINE_ADAv4\Helper;

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

class Menus{
	public function __construct(){
		add_action( 'admin_menu', [$this, 'menu']);
		add_action( 'admin_notices', [$this, 'display_current_scan_on_results_page'] );
	}
	/**
	 * Registers custom submenu pages for the accessibility menu. The parent page is created within post-type.php.
	 */
	public function menu() {
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Getting Started',
			'Getting Started',
			'manage_options',
			'getting-started',
			[$this, "display_menu_getting_started"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'WCAG 2.0 Accessibility Guidelines',
			'Guidelines',
			'manage_options',
			'wcag-guidelines',
			[$this, "display_menu_guidelines"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Get Certified',
			'Get Certified',
			'manage_options',
			'get_certified',
			__NAMESPACE__ . "\\external_redirects"
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Unlock Full Audit',
			'Unlock Full Audit',
			'manage_options',
			'unlock_full_scan',
			__NAMESPACE__ . "\\external_redirects"
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Scheduled Audits',
			'Scheduled Audits',
			'manage_options',
			'scheduled_scans',
			[$this, "display_scheduled_scans"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Community',
			'Community',
			'manage_options',
			'community',
			[$this, "display_menu_community"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Alt Tag Manager',
			'Alt Tag Manager',
			'manage_options',
			'fix_images',
			[$this, "display_menu_fix_images"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'Manage Sitemap',
			'Sitemap',
			'manage_options',
			'sitemap',
			[$this, "display_menu_sitemap"]
		);
		add_submenu_page(
			'edit.php?post_type=wcag_scan',
			'License',
			'License',
			'manage_options',
			'license',
			[$this, "license_page"]
		);
	}


	public function display_menu_getting_started(){
		include_once Plugin::$instance->info["path"] . 'templates/getting-started.php';
	}

	public function display_menu_fix_images(){
		if(Helper::is_pro()){
			include_once Plugin::$instance->info["path"] . 'templates/pro/fix-images.php';
		}else{
			include_once Plugin::$instance->info["path"] . 'templates/free/fix-images.php';
		}
	}

	public function license_page(){
		include_once Plugin::$instance->info["path"] . "templates/license.php";
	}

	public function display_menu_sitemap(){
		if(Helper::is_pro()){
			include_once Plugin::$instance->info["path"] . "templates/pro/sitemap.php";
		}else{
			include_once Plugin::$instance->info["path"] . "templates/free/sitemap.php";
		}
	}

	public function display_menu_community(){
		include_once Plugin::$instance->info["path"] . 'templates/community.php';
	}

	/**
	 * Renders the guidelines page.
	 */
	public function display_menu_guidelines() {
		include_once Plugin::$instance->info["path"] . 'templates/guidelines.php' ;
	}

	public function display_scheduled_scans()
	{
		include_once Plugin::$instance->info["path"] . 'templates/scheduled.php';
	}

	/**
	 * Displays the progress of the current scan when viewing the "Scan Results" screen. DISABLED FOR NOW, DESIGN THE REST FIRST.
	 */
	public function display_current_scan_on_results_page() {
		$free_banner_dismissed = get_transient("_oadaas_upgrade_banner_dismissed");

		if ( !Helper::is_pro() && !$free_banner_dismissed ) {
			include_once Plugin::$instance->info["path"] . "templates/partials/banner.php";
		}
		$screen = get_current_screen();

		if ( $screen->id == 'wcag_scan' ) return;

		$scan = get_active_scan();
		if ( !$scan ) return;

		if($scan->status == "complete") return;

		// If the scan progress popup has been dismissed, do not show it.
		echo '<div class="updated wcag-notice ada-plugin-notice-progress';
		if ($scan->is_dismissed() && !$is_scan_screen) {
			echo " dismissed";
		}
		echo '">';

		include( Plugin::$instance->info["path"] . 'templates/partials/progress.php' );
		echo '</div>';
	}

}