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

final class Sifency_Addons {

	private static $instance = null;

	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * It runs once when the plugin is activated.
	 */
	public static function activate() {
		update_option( 'sifency_addons_version', SIFENCY_ADDONS_VERSION );
	}

	private function __construct() {
		add_action( 'plugins_loaded', [ $this, 'init' ] );
		add_action( 'admin_init', [ $this, 'check_requirements_and_notices' ] );
		add_action( 'init', [ $this, 'sifency_addons_load_post_duplicator' ] );
	}

	public function init() {
		if ( did_action( 'elementor/loaded' ) ) {
			require_once SIFENCY_ADDONS_DIR . 'base/load/assets-manager.php';
			\Sifency\Includes\Sifency_Addons_Elementor_Widgets_Asset_Manager::init();
		}
		$this->load_components();
		do_action( 'sifency_addons/loaded' );
		
	}

	private function load_components() {
		require_once SIFENCY_ADDONS_DIR . 'base/load/assets-register.php';
		require_once SIFENCY_ADDONS_DIR . 'includes/elementor/elementor-init.php';
		require_once SIFENCY_ADDONS_DIR . 'helpers/functions.php';
		require_once SIFENCY_ADDONS_DIR . 'includes/custom-icon/custom-icons.php';
		require_once SIFENCY_ADDONS_DIR . 'theme-builder/theme-builder-loader.php';
		require_once SIFENCY_ADDONS_DIR . 'classes/class-admin-menu.php';
		require_once SIFENCY_ADDONS_DIR . 'classes/admin-module/init.php';
		require_once SIFENCY_ADDONS_DIR . 'classes/admin-module/data-management/init.php';
		require_once SIFENCY_ADDONS_DIR . 'classes/template-shortcode/init.php';
		
		new \Sifency_Addons\Includes\Sifency_Addons_Elementor_Widgets_Asset_Manager();
		new \Sifency_Addons\Includes\Admin\Sifency_Addons_Admin_Widgets();
		new \Sifency_Addons\Includes\Elementor\Sifency_Elementor_Integration();
	}

	/**
	 * Check requirements and show notices in admin.
	 */
	public function check_requirements_and_notices() {
		$notice = \Sifency_Addons_Notice::instance();
		$notice->check_requirements();
	}

	public function sifency_addons_load_post_duplicator() {
		$file = SIFENCY_ADDONS_DIR . 'classes/admin-module/post-duplicator/post-duplicate.php';
		if ( file_exists( $file ) ) {
			include_once $file;
		}
		
	}
	
}