<?php
/**
 * This this is main class of this plugin
 *
 * @package Vite_Reward_Lite\Core
 */

namespace Elite_Notification_Lite\Core;

use Appsbd_Lite\V4\Core\Kernel_Lite;
use Elite_Notification_Lite\Libs\Elite_Notification_Client_Language;
use Elite_Notification_Lite\Modules\Elite_Dummy_Notification;
use Elite_Notification_Lite\Modules\Elite_Notification_Dashboard;
use Elite_Notification_Lite\Modules\Elite_Notification_Settings;
use Elite_Notification_Lite\Modules\Elite_Notification_Source;

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

/**
 * Class Elite_Notification_Lite
 *
 * @package Elite_Notification_Lite\Core
 */
class Elite_Notification_Lite extends Kernel_Lite {
	/**
	 * The initialize is generated by appsbd
	 *
	 * @return mixed|void
	 */
	public function initialize() {
		$this->plugin_base = 'elite-notification';

		$this->menu_icon  = 'dashicons-en-logo';
		$this->menu_label = 'Elite Notification';
	}

	/**
	 * The on init is generated by appsbd
	 */
	public function on_init() {
		parent::on_init();
	}

	/**
	 * The app init is generated by appsbd
	 */
	public function app_init() {
		parent::app_init();
	}

	/**
	 * The get action prefix is generated by appsbd
	 *
	 * @return string
	 */
	public function get_action_prefix() {
		return 'apbd-eln';
	}

	/**
	 * The register_modules is generated by appsbd
	 *
	 * @return mixed
	 */
	public function register_modules() {
		$this->add_module( Elite_Notification_Dashboard::class );
		$this->add_module( Elite_Dummy_Notification::class );
		$this->add_module( Elite_Notification_Settings::class );
		$this->add_module( Elite_Notification_Source::class );
	}

	/**
	 * The on admin global scripts is generated by appsbd
	 *
	 * @return mixed
	 */
	public function on_admin_global_scripts_lite() {
		parent::on_admin_global_scripts_lite();
		if ( $this->check_admin_page() ) {
			return;
		}
	}

	/**
	 * The on admin global styles is generated by appsbd
	 */
	public function on_admin_global_styles_lite() {
		 $this->add_style( 'apbd-eln-fonts', 'admin-assets/font.css', true );
	}

	/**
	 * The on admin scripts is generated by appsbd
	 */
	public function on_admin_scripts_lite() {
		$script_version = self::is_develop_mode() ? time() : $this->plugin_version;
		wp_enqueue_media();
		$handler_name = 'apbd-eln-admin';
		wp_register_script(
			$handler_name,
			plugins_url( 'admin-assets/js/script.js', $this->plugin_file ),
			array(),
			$script_version,
			true
		);

		$this->add_script( $handler_name );
		$jv_object                                      = new \stdClass();
		$jv_object->ajax_url                            = wp_nonce_url( admin_url( 'admin-ajax.php' ), 'appsbd' );
		$jv_object->base_slug                           = $this->get_action_prefix();
		$jv_object->assets_path                         = Elite_Notification_Settings::get_module_instance()->get_plugin_url( 'admin-assets/' );
		$jv_object->ajax_nonce                          = wp_create_nonce( 'elite-notification' );
		$jv_object->app_version                         = $this->plugin_version;
		$jv_object->translation_obj                     = new \stdClass();
		$jv_object->translation_obj->availableLanguages = new \stdClass();
		$jv_object->translation_obj->availableLanguages->en_US = 'American English';
		$jv_object->translation_obj->defaultLanguage           = 'en_US';
		$jv_object->translation_obj->translations              = new \stdClass();
		$jv_object->translation_obj->translations->en_US       = Elite_Notification_Client_Language::get_admin_languages( $this );

		/**
		 * Its for check is there any change before process
		 *
		 * @since 1.0
		 */
		$jv_object = apply_filters( 'appsbd/elite-notification/settings', $jv_object );
		wp_localize_script( $handler_name, 'apbd_admin', (array) $jv_object );
	}

	/**
	 * The on admin styles is generated by appsbd
	 */
	public function on_admin_styles_lite() {
		 $this->add_style( 'apbd-elite-notification-admin', 'admin-assets/css/style.css', true );
	}
	/**
	 * The _myautoload_method is generated by appsbd
	 *
	 * @param any $class_name_space Its class_name_space param.
	 */
	public function _myautoload_method( $class_name_space ) {

		$class_name_space = str_replace( '\\', '/', $class_name_space );
		$path             = plugin_dir_path( $this->plugin_file );
		$class            = basename( $class_name_space );
		$dir              = strtolower( dirname( $class_name_space ) );
		$filename         = realpath( $path . $dir . '/' . $class . '.php' );
		$filename_class   = $path . ( strtolower( $dir . '/class-' . str_replace( '_', '-', $class ) . '.php' ) ) . '';

		if ( ! empty( $filename_class ) && file_exists( $filename_class ) ) {
			require_once $filename_class;
			return;
		}
		if ( ! empty( $filename ) && file_exists( $filename ) ) {
			require_once $filename;
			return;
		}
	}
	/**
	 * The LiteAdminMenu is generated by appsbd
	 */
	public function wc_warning() {

			add_menu_page(
				$this->menu_label,
				$this->menu_label,
				'activate_plugins',
				$this->plugin_base,
				function () {
					?>
						<div id="appsbd-woo-required">
							<div class="apbd-card">
								<div class="apbd-card-header">
									<i class="rwd rwd-reward-logo"></i> <?php echo esc_html( $this->__( 'Vite Rewards' ) ); ?>
								</div>
								<div class="apbd-card-body apbd-text-center">
									<div class="apbd-app-logo-container">
										  <span class="vtp-circle-logo me-3">
											<i class="rwd rwd-reward-logo"></i>
										  </span>
									</div>
								   <strong><?php echo esc_html( $this->__( 'Missing dependency' ) ); ?></strong><br>
								<?php echo esc_html( $this->__( 'It requires woocommerce, please install woocommerce first' ) ); ?>

								</div>
							</div>
						</div>
						<?php
				},
				$this->menu_icon
			);
	}

	/**
	 * The on client scripts lite is generated by appsbd
	 */
	public function on_client_scripts_lite() {
	}
}
