<?php
/**
 * @author      Elicus <hello@elicus.com>
 * @link        https://www.elicus.com/
 * @copyright   2026 Elicus Technologies Private Limited
 * @version     1.0.2
 */

// if this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WPMOZO_Addons_Lite_For_Elementor' ) ) {
	class WPMOZO_Addons_Lite_For_Elementor {

		/**
		 * The loader that's responsible for maintaining and registering all hooks that power
		 * the plugin.
		 *
		 * @since    1.0.0
		 * @access   private
		 * @var      Object    $loader    Maintains and registers all hooks for the plugin.
		 */
		private $loader;

		/**
		 * The unique identifier of this plugin.
		 *
		 * @since    1.0.0
		 * @access   protected
		 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
		 */
		protected $plugin_name = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_SLUG;

		/**
		 * The current version of the plugin.
		 *
		 * @since    1.0.0
		 * @access   protected
		 * @var      string    $version    The current version of the plugin.
		 */
		protected $plugin_version = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_VERSION;

		/**
		 * Plugin option name.
		 *
		 * @since    1.0.0
		 * @access   protected
		 * @var      string    $plugin_option    The plugin option name where all the settings are stored.
		 */
		protected $plugin_option = WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_OPTION;

		public static $public_instance;
		
		protected static $_instance;

		/**
		 * The instance of this class.
		 *
		 * Ensures only one instance of Mozo_Bna_Blocks_And_Addons is loaded or can be loaded.
		 *
		 * @since 1.0.0
		 * @return Mozo_Bna_Blocks_And_Addons - Main instance.
		 */
		public static function instance() {
			if ( is_null( self::$_instance ) ) {
				self::$_instance = new self();
			}
			return self::$_instance;
		}

		/**
		 * Define the core functionality of the plugin.
		 *
		 * Set the plugin name and the plugin version that can be used throughout the plugin.
		 * Load the dependencies, define the locale, and set the hooks for the admin area and
		 * the public-facing side of the site.
		 *
		 * @since    1.0.0
		 */
		public function __construct() {

			$this->load_dependencies();
			$this->set_locale();
			$this->define_admin_hooks();
			$this->define_public_hooks();
			add_filter( 'upload_mimes', array( $this, 'wpmozo_mime_types' ) );
		}

		/**
		 * Load the required dependencies for this plugin.
		 *
		 * Include the following files that make up the plugin:
		 *
		 * - WPMOZO_Addons_Lite_For_Elementor_Loader. Orchestrates the hooks of the plugin.
		 * - WPMOZO_Addons_Lite_For_Elementor_i18n. Defines internationalization functionality.
		 * - WPMOZO_Addons_Lite_For_Elementor_Admin. Defines all hooks for the admin area.
		 * - WPMOZO_Addons_Lite_For_Elementor_Public. Defines all hooks for the public side of the site.
		 *
		 * Create an instance of the loader which will be used to register the hooks
		 * with WordPress.
		 *
		 * @since    1.0.0
		 * @access   private
		 */
		private function load_dependencies() {

			/**
			 * The class responsible for orchestrating the actions and filters of the
			 * core plugin.
			 */
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpmozo-addons-lite-for-elementor-loader.php';

			/**
			 * The class responsible for defining internationalization functionality
			 * of the plugin.
			 */
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpmozo-addons-lite-for-elementor-i18n.php';
			/**
			 * The class responsible for defining all actions that occur in the admin area.
			 */
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpmozo-addons-lite-for-elementor-admin.php';

			/**
			 * The class responsible for defining all settings that occur on the settings page in the admin area.
			 */
			require_once plugin_dir_path( __DIR__ ) . 'admin/partials/settings/class-wpmozo-addons-lite-for-elementor-settings.php';

			/**
			 * The trait containing helper functions.
			 */
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/trait-helper-functions.php';
			
			/**
			 * The class responsible for defining all actions that occur in the public-facing side of the site.
			 */
			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpmozo-addons-lite-for-elementor-public.php';

			/**
			 * The class responsible for defining all actions that occur in the public-facing side of the site.
			 */

			$this->loader = new WPMOZO_Addons_Lite_For_Elementor_Loader();
		}

		/**
		 * add JSON to allowed file uploads.
		 *
		 * @since 1.5.2
		 */
		public function wpmozo_mime_types( $mimes ) {
			if ( is_user_logged_in() ) {
				$mimes['svg'] = 'image/svg+xml';
			}
			return $mimes;
		}

		/**
		 * Define the locale for this plugin for internationalization.
		 *
		 * Uses the WPMOZO_Addons_Lite_For_Elementor_i18n class in order to set the domain and to register the hook
		 * with WordPress.
		 *
		 * @since    1.0.0
		 * @access   private
		 */
		private function set_locale() {

			$plugin_i18n = new WPMOZO_Addons_Lite_For_Elementor_I18n();

			$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
		}

		/**
		 * Register all of the hooks related to the admin area functionality
		 * of the plugin.
		 *
		 * @since    1.0.0
		 * @access   private
		 */
		private function define_admin_hooks() {
			global $wp_version;

			$settings     = new WPMOZO_Addons_Lite_For_Elementor_Settings( $this->get_plugin_option() );
			$plugin_admin = new WPMOZO_Addons_Lite_For_Elementor_Admin( $settings );
			$this->loader->add_action( 'wp_loaded', $plugin_admin, 'wp_loaded' );
			$plugin_admin->wpmozo_register_post_types();
			$plugin_admin->wpmozo_register_taxonomies();
			$this->loader->add_action( 'admin_menu', $plugin_admin, 'admin_menu' );
			$this->loader->add_action( 'save_post', $plugin_admin, 'wpmozo_save_team_member_meta_fields' );
			$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
			$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
			$this->loader->add_action( 'wp_ajax_wpmozo_ae_lite_panel_save_settings', $plugin_admin, 'save_options' );
			$this->loader->add_filter( 'plugin_action_links_' . WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_BASENAME,  $plugin_admin, 'plugin_action_links' );
			if(defined('WPMOZO_ADDONS_FOR_ELEMENTOR_BASENAME')){
				$this->loader->add_filter( 'plugin_action_links_' . WPMOZO_ADDONS_LITE_FOR_ELEMENTOR_BASENAME, $plugin_admin, 'wpmozo_remove_upgrade_action_links', 50 );
			}
			if ( ! $plugin_admin->wpmozo_is_widget_disabled('team-slider,team-grid') ) {
				// Hook to add meta box.
				$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'wpmozo_add_team_member_metabox' );
				// Hook to save meta box data.
				$this->loader->add_action( 'save_post', $plugin_admin, 'wpmozo_save_team_member_meta_fields' );
			}
			if ( ! $plugin_admin->wpmozo_is_widget_disabled('blog-categories') ) {
				// Hook to add meta box.
				if(! $plugin_admin->diviplus_active){
					$this->loader->add_action( 'category_add_form_fields', $plugin_admin, 'wpmozo_add_post_category_image_field', 10 );
					// Hook to save meta box data.
				
					$this->loader->add_action( 'category_edit_form_fields', $plugin_admin, 'wpmozo_edit_post_category_image_field', 10, 2 );
				
				$this->loader->add_action( 'created_category', $plugin_admin, 'wpmozo_save_post_category_image', 10, 2 );
				
				$this->loader->add_action( 'edited_category', $plugin_admin, 'wpmozo_save_post_category_image', 10, 2 );
				
				$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'wpmozo_blog_category_enqueue_scripts' );
				
				$this->loader->add_filter( 'manage_edit-category_columns', $plugin_admin, 'wpmozo_category_image_columns' );
				
				$this->loader->add_filter( 'manage_category_custom_column', $plugin_admin, 'wpmozo_category_image_column', 10, 3 );
				}
			}
			if ( ! $plugin_admin->wpmozo_is_widget_disabled('testimonial-slider,testimonial-grid') ) {
				// Hook to add meta box.
				$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'wpmozo_add_testimonial_metabox' );
				// Hook to save meta box data.
				$this->loader->add_action( 'save_post', $plugin_admin, 'wpmozo_save_testimonial_meta_fields' );
			}
			$this->loader->add_action( 'admin_footer_text', $plugin_admin, 'admin_footer_text' );
		}

		/**
		 * Register all of the hooks related to the public-facing functionality
		 * of the plugin.
		 *
		 * @since    1.0.0
		 * @access   private
		 */
		private function define_public_hooks() {

			$plugin_public = new WPMOZO_Addons_Lite_For_Elementor_Public();
			self::$public_instance = $plugin_public;
			$this->loader->add_action( 'elementor/init', $plugin_public, 'init' );
			$this->loader->add_action( 'elementor/elements/categories_registered', $plugin_public, 'add_elementor_widget_categories', 99 );
			$this->loader->add_action( 'elementor/widgets/register', $plugin_public, 'register_oembed_widget', 99 );
			$this->loader->add_action( 'elementor/frontend/after_register_styles', $plugin_public, 'register_frontend_styles' );
			$this->loader->add_action( 'elementor/frontend/after_register_scripts', $plugin_public, 'register_frontend_scripts' );
			$this->loader->add_action( 'elementor/editor/before_enqueue_scripts', $plugin_public, 'wpmozo_ale_editor_enqueue_scripts' );
			$this->loader->add_action( 'elementor/controls/controls_registered', $plugin_public, 'register_custom_controls' );
			$this->loader->add_action( 'wp_ajax_wpmozo_get_testimonials', $plugin_public, 'wpmozo_get_testimonials' );
			$this->loader->add_action( 'wp_ajax_nopriv_wpmozo_get_testimonials', $plugin_public, 'wpmozo_get_testimonials' );
			$this->loader->add_action( 'wp_ajax_wpmozo_ae_select2_ajax_posts', $plugin_public, 'wpmozo_ae_select2_ajax_posts' );
			$this->loader->add_action( 'wp_ajax_nopriv_wpmozo_ae_select2_ajax_posts', $plugin_public, 'wpmozo_ae_select2_ajax_posts' );
			$this->loader->add_action( 'wp_ajax_wpmozo_ae_select2_get_title', $plugin_public, 'wpmozo_ae_select2_get_title' );
			$this->loader->add_action( 'wp_ajax_nopriv_wpmozo_ae_select2_get_title', $plugin_public, 'wpmozo_ae_select2_get_title' );
			/*$plugin_public->help_me();*/
		}

		/**
		 * Run the loader to execute all of the hooks with WordPress.
		 *
		 * @since    1.0.0
		 */
		public function run() {
			$this->loader->run();
		}

		/**
		 * The name of the plugin used to uniquely identify it within the context of
		 * WordPress and to define internationalization functionality.
		 *
		 * @since     1.0.0
		 * @return    string    The name of the plugin.
		 */
		public function get_plugin_name() {
			return $this->plugin_name;
		}

		/**
		 * The reference to the class that orchestrates the hooks with the plugin.
		 *
		 * @since     1.0.0
		 * @return    WPMOZO_PRODUCT_GRID_For_Elementor_Loader    Orchestrates the hooks of the plugin.
		 */
		public function get_loader() {
			return $this->loader;
		}

		/**
		 * Retrieve the version number of the plugin.
		 *
		 * @since     1.0.0
		 * @return    string    The version number of the plugin.
		 */
		public function get_plugin_version() {
			return $this->plugin_version;
		}

		/**
		 * Retrieve the option name of the plugin.
		 *
		 * @since     1.0.0
		 * @return    string    The option name of the plugin.
		 */
		public function get_plugin_option() {
			return $this->plugin_option;
		}
	}
}
