<?php //phpcs:ignore
/**
 * Main Plugin File
 *
 * The primary entry point for the Meeting Hub plugin.
 *
 * @package SOVLIX\WEMEET
 */

namespace SOVLIX\WEMEET;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Check if the main class already exists.
 *
 * @since 1.0.0
 */
if ( ! class_exists( 'Wemeet' ) ) {
	/**
	 * Meeting Hub Plugin Main Class
	 *
	 * Sets up and initializes the Meeting Hub plugin.
	 *
	 * @since 1.0.0
	 */
	class Wemeet {
		/**
		 * Class constructor.
		 *
		 * Hooks into the 'plugins_loaded' action to initiate the plugin.
		 */
		private function __construct() {
			add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
		}

		/**
		 * Initialize a singleton instance of the plugin.
		 *
		 * @return Wemeet An instance of the Wemeet class.
		 * @since  1.0.0
		 */
		public static function init() {
			static $instance = false;

			if ( ! $instance ) {
				$instance = new self();
			}

			return $instance;
		}

		/**
		 * Initialize the Meeting Hub plugin.
		 *
		 * Initiates the necessary components for the plugin, such as Assets,
		 * and either the Admin or Frontend components based on the current context.
		 *
		 * @return void
		 * @since  1.0.0
		 */
		public function init_plugin() {

			// Initialize Ajax component for asynchronous actions.
			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
				new Wemeet_Ajax();
			}

			new Wemeet_Assets();

			if ( is_admin() ) {
				new Wemeet_Admin();
			} else {
				new Wemeet_Frontend();
			}

			new Wemeet_Post_Types();
			new Wemeet_API();
			new Wemeet_Shortcodes();
			new Wemeet_Gutenberg();

			// Get the list of active plugins.
			$active_plugins = get_option( 'active_plugins' );

			// Check if the Elementor plugin is active.
			if ( in_array( 'elementor/elementor.php', $active_plugins, true ) ) {
				new Elementor\Wemeet_Elementor_Integrator();
			}
		}
	}

	// Kick-off the Meeting Hub plugin.
	Wemeet::init();
}
