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

namespace SOVLIX\GOODMEET;

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

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

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

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

			return $instance;
		}

		/**
		 * Initialize the goodmeet 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 Goodmeet_Ajax();
			}

			new Goodmeet_Assets();

			if ( is_admin() ) {
				new Goodmeet_Admin();
			} else {
				new Goodmeet_Frontend();
			}

			new Goodmeet_Post_Types();
			new Goodmeet_API();
			new Goodmeet_Shortcodes();
			new Goodmeet_Gutenberg();
			$goodmeet_meet = Googlemeet\Goodmeet_Meet::get_instance();

			// 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\Goodmeet_Elementor_Integrator();
			}
		}

		/**
		 * Initialize Promo SDK
		 *
		 * @return void
		 * @since  1.23.10
		 */
		private function init_promo_sdk() {
			// Load SDK main class.
			$sdk_path = GOODMEET_INCLUDES . '/lib/promo-sdk/class-promo-sdk.php';

			if ( ! file_exists( $sdk_path ) ) {
				return;
			}

			require_once $sdk_path;

			// Initialize SDK with configuration.
			\Promo_SDK::init_sdk(
				array(
					'product_slug'         => 'goodmeet',
					'plugin_page_slug'     => 'goodmeet',
					'hide_modal_demo_link' => true,
					'api_endpoint'         => 'https://sovlix.com/wp-json/leetcampaign/v1/campaigns/active/meetinghub',
					'cache_duration'       => 3600,
					'text_domain'          => 'goodmeet',
					'prefix'               => 'goodmeet',
					'is_pro'               => goodmeet_fs()->is_premium(),
				)
			);
		}
	}

	// Kick-off the goodmeet plugin.
	Goodmeet_Boot::init();
}
