<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class IDSC_Core {

    private static $instance = null;

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

    private function __construct() {
        require_once IDSC_PLUGIN_DIR . 'includes/class-idsc-shortcodes.php';
        require_once IDSC_PLUGIN_DIR . 'includes/class-idsc-assets.php';

        new IDSC_Shortcodes();
        new IDSC_Assets();

        add_action( 'plugins_loaded', array( $this, 'maybe_load_idve_integration' ) );
        add_action( 'plugins_loaded', array( $this, 'maybe_load_wpbakery_integration' ) );
        add_action( 'plugins_loaded', array( $this, 'maybe_load_elementor_integration' ) );
    }

    public function maybe_load_idve_integration() {
        if ( ! defined( 'IDVE_VERSION' ) ) {
            return;
        }
        require_once IDSC_PLUGIN_DIR . 'includes/class-idsc-idve-blocks.php';
        new IDSC_IDVE_Blocks();
    }

    public function maybe_load_wpbakery_integration() {
        if ( ! function_exists( 'vc_map' ) ) {
            return;
        }
        require_once IDSC_PLUGIN_DIR . 'includes/class-idsc-wpbakery.php';
        new IDSC_WPBakery();
    }

    public function maybe_load_elementor_integration() {
        if ( ! did_action( 'elementor/loaded' ) ) {
            return;
        }
        require_once IDSC_PLUGIN_DIR . 'includes/class-idsc-elementor.php';
        new IDSC_Elementor();
    }

    public static function is_idve_active() {
        return defined( 'IDVE_VERSION' );
    }
}
