<?php

/**
 * Init section.
 *
 * @package    Extra_Product_Options_For_WooCommerce
 * @subpackage Extra_Product_Options_For_WooCommerce/includes
 */
// If this file is called directly, abort.
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( !class_exists( 'EPOFW_Init' ) ) {
    /**
     * EPOFW_Init class.
     */
    class EPOFW_Init {
        /**
         * Instance of this class.
         *
         * @since 1.0.0
         * @var EPOFW_Init
         */
        private static $instance = null;

        /**
         * Constructor.
         *
         * @since 1.0.0
         */
        public function __construct() {
            add_action( 'init', array($this, 'init') );
            // Note: load_plugin_textdomain removed - WordPress.org auto-loads translations since WP 4.6.
            add_filter(
                'woocommerce_locate_template',
                array($this, 'epofw_locate_wc_template'),
                20,
                2
            );
        }

        /**
         * Define the plugins name and versions and also call admin section.
         *
         * @since 1.0.0
         */
        public static function instance() {
            if ( is_null( self::$instance ) ) {
                self::$instance = new self();
            }
            return self::$instance;
        }

        /**
         * Required files.
         *
         * @since    1.0.0
         */
        public function init() {
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-style-collector.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'settings/epofw-style-helper.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'settings/epofw-common-function.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'settings/epofw-tutorial-links.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'settings/epofw-actions.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'settings/epofw-deactivation-feedback.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-custom-tables.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-migration.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-post-parser.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-admin.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-front.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-import.php';
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-discount-popup.php';
            // Initialize and enable custom tables.
            EPOFW_Custom_Tables::init();
            // Enable custom tables by default for new installs.
            if ( false === get_option( 'epofw_use_custom_tables' ) ) {
                EPOFW_Custom_Tables::enable();
            }
            // Load third-party theme/plugin compatibility BEFORE front class.
            // This ensures compatibility filters are registered before hooks.
            require_once EPOFW_PLUGIN_DIR_PATH . 'includes/compatibility/class-epofw-compatibility.php';
            EPOFW_Front::instance();
            if ( class_exists( 'WOOCS' ) ) {
                require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-woocs-compatiblity.php';
                EPOFW_Woocs_Compatiblity::instance();
            }
            if ( class_exists( 'WooCommerceWholeSalePrices' ) ) {
                require_once EPOFW_PLUGIN_DIR_PATH . 'includes/class-epofw-wc-wholesale-prices-rymera.php';
                EPOFW_WC_Wholesale_Prices_Rymera::instance();
            }
        }

        /**
         * Function to locates the WooCommerce template files from this plugin.
         *
         * @since 3.0.4
         *
         * @param string $template      Already found template.
         * @param string $template_name Searchable template name.
         *
         * @return string search result for the template
         * @internal
         */
        public function epofw_locate_wc_template( $template, $template_name ) {
            // Set the path to our templates directory.
            $plugin_path = EPOFW_PLUGIN_DIR_PATH . '/woocommerce/';
            // If a template is found, make it so.
            if ( is_readable( $plugin_path . $template_name ) ) {
                $template = $plugin_path . $template_name;
            }
            return $template;
        }

    }

}
$epofw_init = new EPOFW_Init();