<?php

/**
 * The main Bootstrap file, used to load all the PHP files used by this plugin.
 *
 * @package Flexible_FAQs
 */
namespace WPGO_Plugins\Flexible_Faqs;

/**
 * Main bootstrap class.
 */
class BootStrap
{
    /**
     * Common root paths/directories.
     *
     * @var $module_roots
     */
    protected  $module_roots ;
    /**
     * Main class constructor.
     */
    public function __construct()
    {
        $this->module_roots = Main::$module_roots;
        $this->load_supported_features();
    }
    
    /**
     * Load plugin features.
     */
    public function load_supported_features()
    {
        // Plugin dir path.
        $root = $this->module_roots['dir'];
        // Use custom plugin icon.
        flexible_faqs_fs()->add_filter( 'plugin_icon', function () {
            // return WP_PLUGIN_DIR . '/' . basename( $this->module_roots['file'], '.php' ) . '/assets/images/flexible-faqs-thumb.jpg';
            return WP_PLUGIN_DIR . '/' . dirname( plugin_basename( $this->module_roots['file'] ) ) . '/assets/images/flexible-faqs-thumb.jpg';
        } );
        // Disable the Freemius feedback popup that appears when deactivating plugin.
        flexible_faqs_fs()->add_filter( 'show_deactivation_feedback_form', function () {
            return false;
        } );
        // FAQ SVG Icons (expand/collapse icons).
        // Load icons class early so we can dynamically determine the list of icons available.
        require_once $root . '/classes/class-svg-icons.php';
        // Load plugin constants/data.
        require_once $root . 'classes/class-constants.php';
        $custom_plugin_data = new Constants( $this->module_roots );
        // Import plugin framework classes (fw = framework).
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Utilities_FW' ) ) {
            require_once $root . 'api/classes/utilities.php';
        }
        $utilities_fw = new \WPGO_Plugins\Plugin_Framework\Utilities_FW( $this->module_roots );
        // Links on the main plugin index page.
        require_once $root . 'classes/class-utility.php';
        $utility = new Utility( $this->module_roots, $custom_plugin_data );
        $plugin_data = get_plugin_data( $this->module_roots['file'], false, false );
        // Load the compatibility class.
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Compatibility_FW' ) ) {
            require_once $root . 'api/classes/compatibility.php';
        }
        new \WPGO_Plugins\Plugin_Framework\Compatibility_FW(
            $this->module_roots,
            $plugin_data,
            $custom_plugin_data,
            $utility
        );
        // Import plugin framework classes (fw = framework).
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Settings_Templates_FW' ) ) {
            require_once $root . 'api/templates/settings/settings.php';
        }
        $settings_fw = new \WPGO_Plugins\Plugin_Framework\Settings_Templates_FW( $this->module_roots );
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\New_Features_Templates_FW' ) ) {
            require_once $root . 'api/templates/settings/new-features.php';
        }
        $new_features_fw = new \WPGO_Plugins\Plugin_Framework\New_Features_Templates_FW( $this->module_roots );
        // Data to pass to certain classes.
        $new_features_json = '';
        if ( file_exists( $root . 'assets/misc/new-features.json' ) ) {
            $new_features_json = file_get_contents( $root . 'assets/misc/new-features.json' );
        }
        $new_features_arr = Utility::filter_and_decode_json( $new_features_json );
        // Custom post type.
        require_once $root . 'classes/class-custom-post-type.php';
        new Custom_Post_Type(
            $this->module_roots,
            $custom_plugin_data,
            $utilities_fw,
            $new_features_arr,
            $plugin_data
        );
        // Plugin framework hooks.
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Hooks_FW' ) ) {
            require_once $root . 'api/classes/hooks.php';
        }
        new \WPGO_Plugins\Plugin_Framework\Hooks_FW( $this->module_roots, $custom_plugin_data, flexible_faqs_fs() );
        // Enqueue framework scripts.
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Enqueue_Framework_Scripts' ) ) {
            require_once $root . 'api/classes/enqueue-scripts.php';
        }
        new \WPGO_Plugins\Plugin_Framework\Enqueue_Framework_Scripts(
            $this->module_roots,
            $new_features_arr,
            $plugin_data,
            $custom_plugin_data
        );
        // Enqueue plugin scripts.
        require_once $root . 'classes/class-enqueue-scripts.php';
        new Enqueue_Scripts(
            $this->module_roots,
            $new_features_arr,
            $plugin_data,
            $custom_plugin_data,
            $utilities_fw
        );
        // Plugin settings pages.
        require_once $root . 'classes/plugin-admin-pages/class-settings.php';
        new Settings(
            $this->module_roots,
            $plugin_data,
            $custom_plugin_data,
            $utility,
            $settings_fw,
            $new_features_arr
        );
        require_once $root . 'classes/plugin-admin-pages/class-settings-new-features.php';
        new Settings_New_Features(
            $this->module_roots,
            $new_features_arr,
            $plugin_data,
            $custom_plugin_data,
            $utility,
            $new_features_fw
        );
        require_once $root . 'classes/plugin-admin-pages/class-settings-welcome.php';
        new Settings_Welcome(
            $this->module_roots,
            $plugin_data,
            $custom_plugin_data,
            $utility
        );
        // Register blocks.
        require_once $root . 'classes/class-register-blocks.php';
        new Register_Blocks( $this->module_roots, $custom_plugin_data );
        // Shortcodes bootstrap.
        require_once $root . 'classes/shortcodes/class-shortcodes.php';
        new Shortcodes( $this->module_roots, $custom_plugin_data, $utilities_fw );
        // Links on the main plugin index page.
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Plugin_Links_FW' ) ) {
            require_once $root . 'api/classes/links.php';
        }
        new \WPGO_Plugins\Plugin_Framework\Plugin_Links_FW(
            $this->module_roots,
            $plugin_data,
            $custom_plugin_data,
            $utility
        );
        // Run upgrade routine when plugin updated to new version.
        if ( !class_exists( '\\WPGO_Plugins\\Plugin_Framework\\Upgrade_FW' ) ) {
            require_once $root . 'api/classes/upgrade.php';
        }
        new \WPGO_Plugins\Plugin_Framework\Upgrade_FW( $this->module_roots, $custom_plugin_data );
        // Localize plugin.
        require_once $root . 'classes/class-localize.php';
        new Localize( $this->module_roots );
        // Register REST API endpoints.
        require_once $root . 'classes/class-custom-rest-api-endpoints.php';
        new Custom_Rest_Api_Endpoints( $this->module_roots );
        // FAQ post templates.
        require_once $root . '/classes/templates/class-faq-post-templates.php';
        // FAQ templates.
        require_once $root . '/classes/templates/class-faq-templates.php';
        require_once $root . '/classes/templates/template-markup/class-faq-templates-markup.php';
        // Add FAQ schema.
        require_once $root . 'classes/class-faq-schema.php';
        new Faq_Schema( $this->module_roots );
    }

}
/* End class definition */