<?php
/**
 * The file that defines the core plugin class
 *
 * @since      1.0.0
 *
 * @package    captain-widgets-kit
 * @subpackage captain-widgets-kit/includes
 */

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

/**
 * Define Captwiki_Extensions_Main class for the free version.
 *
 * @since 1.0.0
 */
if ( ! class_exists( 'Captwiki_Extensions_Main' ) ) {

	/**
	 * Define Captwiki_Extensions_Main class for the free version
	 *
	 * @since 1.0.0
	 */
	class Captwiki_Extensions_Main {

		/**
		 * Call __construct.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {
			add_action( 'elementor/init', array( $this, 'captwiki_elementor_extensions' ) );
			add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'captwiki_custom_css_scrpt' ) );
		}

		/**
		 * Load elementor extensions.
		 *
		 * @since 1.0.0
		 */
		public function captwiki_elementor_extensions() {

			$captwiki_settings   = get_option( 'captwiki_settings', array() );
			$captwiki_extensions = ! empty( $captwiki_settings['extensions'] ) && is_array( $captwiki_settings['extensions'] ) ? $captwiki_settings['extensions'] : array();

			$extension_files = array(
				'Captwiki_Custom_Css'            => 'custom/class-captwiki-custom-css.php',
				'Captwiki_Custom_JS'             => 'custom/class-captwiki-custom-js.php',
				'Captwiki_Browser_Compatibility' => 'display-condition/class-captwiki-browser-compatibility.php',
				'Captwiki_Location'              => 'display-condition/class-captwiki-location.php',
				'Captwiki_Weekdays_Visibility'   => 'display-condition/class-captwiki-weekdays-visibility.php',
				'Captwiki_Date_Time_Visibility'  => 'display-condition/class-captwiki-datetime-visibility.php',
				'Captwiki_Page_Conditions'       => 'display-condition/class-captwiki-page-conditions.php',
				'Captwiki_URL_Conditions'        => 'display-condition/class-captwiki-url-conditions.php',
				'Captwiki_Device_Type'           => 'display-condition/class-captwiki-device-type.php',
				'Captwiki_Operating_System'      => 'display-condition/class-captwiki-operating-system.php',
				'Captwiki_Wrapper_Link'          => 'wrapper-link/class-captwiki-wrapper-link.php',
			);

			// Dynamic Tags — loaded separately (group-based toggle).
			if ( in_array( 'Captwiki_Dynamic_Tags', $captwiki_extensions, true ) ) {
				require_once CAPTWIKI_PATH . 'includes/elementor/dynamic-tags/class-captwiki-dynamic-tags.php';
				Captwiki_Dynamic_Tags::get_instance();
			}

			foreach ( $extension_files as $extension => $file ) {
				if ( in_array( $extension, $captwiki_extensions, true ) ) {
					require_once CAPTWIKI_PATH . 'includes/elementor/extensions/' . $file;
				}
			}
		}

		/**
		 * Load custom css for editor.
		 *
		 * @since 1.0.0
		 */
		public function captwiki_custom_css_scrpt() {
			wp_enqueue_style( 'captwiki-ad-editor-css', CAPTWIKI_URL . 'assets/fonts/style.css', array(), CAPTWIKI_VERSION );
		}
	}
}

new Captwiki_Extensions_Main();
