<?php

namespace EDPW\Core;
defined( 'ABSPATH' ) or die();

use EDPW\Core\Controllers\Admin\AddOn;
use EDPW\Core\Controllers\Admin\Common;
use EDPW\Core\Controllers\Admin\EmailTemplates;
use EDPW\Core\Controllers\Admin\Labels;
use EDPW\Core\Controllers\Admin\Settings;
use EDPW\Core\Controllers\EmailManager;
use EDPW\Core\Controllers\WordPress;
use EDPW\Core\Helpers\Input;

class Router {
	/**
	 * Init action and filter.
	 *
	 * @return void
	 */
	public static function init() {
		if ( is_admin() ) {
			add_action( 'admin_menu', [ Common::class, 'addMenu' ] );
			add_action( 'admin_footer', [ Common::class, 'setMenuIconStyle' ] );
			if ( Input::get( 'page' ) == EDPW_PLUGIN_SLUG ) {
				remove_all_actions( 'admin_enqueue_scripts' );
			}
			add_action( 'admin_enqueue_scripts', [ Common::class, 'adminScripts' ], 100 );
			add_filter( 'plugin_action_links_' . plugin_basename( EDPW_PLUGIN_FILE ), [
				Common::class,
				'pluginActionLinks'
			] );
			// Common ajax call
			if ( wp_doing_ajax() ) {
				add_action( 'wp_ajax_edpw_local_data', [ Labels::class, 'getLocalData' ] );
				add_action( 'wp_ajax_edpw_get_labels', [ Labels::class, 'getLabels' ] );
				// Template
				add_action( 'wp_ajax_edpw_get_templates', [ EmailTemplates::class, 'getEmailTemplates' ] );
				add_action( 'wp_ajax_edpw_get_template', [ EmailTemplates::class, 'getEmailTemplate' ] );
				add_action( 'wp_ajax_edpw_new_templates', [ EmailTemplates::class, 'getNewTemplateList' ] );
				add_action( 'wp_ajax_edpw_save_chosen_template', [ EmailTemplates::class, 'saveChosenTemplate' ] );
				add_action( 'wp_ajax_edpw_save_template', [ EmailTemplates::class, 'saveEmailTemplate' ] );
				add_action( 'wp_ajax_edpw_copy_template', [ EmailTemplates::class, 'copyEmailTemplate' ] );
				add_action( 'wp_ajax_edpw_toggle_template', [ EmailTemplates::class, 'toggleEmailTemplate' ] );
				add_action( 'wp_ajax_edpw_delete_template', [ EmailTemplates::class, 'deleteEmailTemplate' ] );
				add_action( 'wp_ajax_edpw_export_template', [ EmailTemplates::class, 'getExportTemplate' ] );
				add_action( 'wp_ajax_edpw_get_template_options', [ EmailTemplates::class, 'getTemplateOptions' ] );
				add_action( 'wp_ajax_edpw_get_image_list', [ EmailTemplates::class, 'getImageList' ] );
				
				//add_action('wp_ajax_edpw_export_template', [EmailTemplates::class, 'exportEmailTemplate']);
				//add_action('wp_ajax_edpw_export_templates', [EmailTemplates::class, 'exportEmailTemplates']);

				add_action( 'wp_ajax_edpw_get_preview_data', [ EmailTemplates::class, 'getPreviewData' ] );
				add_action( 'wp_ajax_edpw_get_template_preview', [ EmailTemplates::class, 'previewEmailTemplates' ] );
				add_action( 'wp_ajax_edpw_send_test_email', [ EmailTemplates::class, 'sendTestMail' ] );
				add_action( 'wp_ajax_edpw_get_shortcode_data', [ EmailTemplates::class, 'getShortCodes' ] );
				// Settings
				add_action( 'wp_ajax_edpw_get_settings', [ Settings::class, 'getSettings' ] );
				add_action( 'wp_ajax_edpw_save_settings', [ Settings::class, 'saveSettings' ] );

				//add-ons
				add_action( 'wp_ajax_edpw_get_active_addon_list', [ AddOn::class, 'getActiveAddonList' ] );
				add_action( 'wp_ajax_edpw_get_available_addon_list', [ AddOn::class, 'getAvailableAddonList' ] );
				add_action( 'wp_ajax_edpw_perform_addon_action', [ AddOn::class, 'toggleAddonActivate' ] );
				//recommendation
				add_action( 'wp_ajax_edpw_recommendation_list', [ Common::class, 'getRecommendationList' ] );
			}
		}
		add_action( 'plugins_loaded', [ Common::class, 'loadTextDomain' ] );
		//Need to check a license key before change email template content
		add_filter( 'wc_get_template', [ EmailManager::class, 'overrideEmailTemplates' ], 10, 5 );
		add_filter( 'woocommerce_mail_content', [ EmailManager::class, 'reproduceHtmlContent' ] );

		//New User Registration
		add_filter( 'wp_new_user_notification_email', [ WordPress::class, 'notifyOnUserRegistration' ], 10, 2 );
		add_filter( 'retrieve_password_notification_email', [
			WordPress::class,
			'forgotPasswordNotificationEmail'
		], 10, 4 );

		add_filter( 'password_change_email', [ WordPress::class, 'notifyOnPasswordChange' ], 10, 2 );
		add_filter( 'email_change_email', [ WordPress::class, 'notifyOnEmailChange' ], 10, 2 );
	}
}