<?php

namespace ONLINE_ADAv4;

use ONLINE_ADAv4\Plugin;
use ONLINE_ADAv4\Helper;

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

/**
 * Registers custom submenu pages for the accessibility menu. The parent page is created within post-type.php.
 */
function register_menu() {
	add_submenu_page(
		'edit.php?post_type=wcag_scan',
		'WCAG 2.0 Accessibility Guidelines',
		'Guidelines',
		'manage_options',
		'wcag-guidelines',
		__NAMESPACE__ .'\\display_menu_guidelines'
	);
	add_submenu_page(
		'edit.php?post_type=wcag_scan',
		'Getting Started',
		'Getting Started',
		'manage_options',
		'getting-started',
		__NAMESPACE__ . '\\display_menu_getting_started'
	);
	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',
		__NAMESPACE__ . '\\display_scheduled_scans'
	);
	add_submenu_page(
		'edit.php?post_type=wcag_scan',
		'Community',
		'Community',
		'manage_options',
		'community',
		__NAMESPACE__ . '\\display_menu_community'
	);
	add_submenu_page(
		'edit.php?post_type=wcag_scan',
		'Alt Tag Manager',
		'Alt Tag Manager',
		'manage_options',
		'fix_images',
		__NAMESPACE__ . '\\display_menu_fix_images'
	);
}
add_action( 'admin_menu', __NAMESPACE__ . '\\register_menu');

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

function display_menu_fix_images(){
	if(is_plugin_active("accessibility-suite-pro/index.php") && Helper::check_access()){
		include(Plugin_Pro::$instance->info["path"] . 'templates/fix-images.php');
	}else{
		include( Plugin::$instance->info["path"] . 'templates/fix-images.php');
	}
}


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

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

function display_menu_sitemap(){
    include( Plugin::$instance->info["path"] . 'templates/sitemap.php' );
}

function display_scheduled_scans()
{
	include( 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.
 */
function display_current_scan_on_results_page() {
	$free_banner_dismissed = get_transient("_oadaas_upgrade_banner_dismissed");
	if ( !Helper::is_pro() && !$free_banner_dismissed ) {
		include( 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>';
}
add_action( 'admin_notices', __NAMESPACE__ . '\\display_current_scan_on_results_page' );

