<?php
/**
 * Theme functions and definitions.
 *
 * @package     Business Interface
 * @author  WPInterface Team
 * @since   1.0.0
 */

/**
 * Main Business Interface class.
 *
 * @since 1.0.0
 */
final class Business_Interface
{

	/**
	 * Singleton instance of the class.
	 *
	 * @since 1.0.0
	 * @var object
	 */
	private static $instance;

	/**
	 * Theme version.
	 *
	 * @since 1.0.0
	 * @var string
	 */
	public $version = '1.0.6';

    /**
     * Theme option handler.
     *
     * @var Business_Interface_Options
     */
    public $options;

    /**
     * Font handler.
     *
     * @var Business_Interface_Fonts
     */
    public $fonts;

    /**
     * Icon handler.
     *
     * @var Business_Interface_Icons
     */
    public $icons;

    /**
     * Customizer handler.
     *
     * @var Business_Interface_Customizer
     */
    public $customizer;

    /**
     * Admin handler.
     *
     * @var Business_Interface_Admin
     */
    public $admin;
	/**
	 * Main Business Interface Instance.
	 *
	 * Insures that only one instance of Business Interface exists in memory at any one
	 * time. Also prevents needing to define globals all over the place.
	 *
	 * @since 1.0.0
	 * @return Business Interface
	 */
	public static function instance()
	{

		if (!isset(self::$instance) && !(self::$instance instanceof Business_Interface)) {
			self::$instance = new Business_Interface();

			self::$instance->constants();
			self::$instance->includes();
			self::$instance->objects();

			// Hook now that all of the Business Interface stuff is loaded.
			do_action('business_interface_loaded');
		}
		return self::$instance;
	}

	/**
	 * Primary class constructor.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function __construct()
	{
	}

	/**
	 * Setup constants.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	private function constants()
	{

		if (!defined('BUSINESS_INTERFACE_VERSION')) {
			define('BUSINESS_INTERFACE_VERSION', $this->version);
		}

		if (!defined('BUSINESS_INTERFACE_URI')) {
			define('BUSINESS_INTERFACE_URI', get_parent_theme_file_uri());
		}

		if (!defined('BUSINESS_INTERFACE_PATH')) {
			define('BUSINESS_INTERFACE_PATH', get_parent_theme_file_path());
		}
	}

	/**
	 * Include files.
	 *
	 * @since  1.0.0
	 * @return void
	 */
	public function includes()
	{

		require_once BUSINESS_INTERFACE_PATH . '/inc/common.php';

		require_once BUSINESS_INTERFACE_PATH . '/inc/helpers.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/widgets.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/template-tags.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/template-parts.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/icon-functions.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/breadcrumbs.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/class-interface-dynamic-styles.php';

		// Core.
		require_once BUSINESS_INTERFACE_PATH . '/inc/core/class-interface-options.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/core/class-interface-enqueue-scripts.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/core/class-interface-fonts.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/core/class-interface-theme-setup.php';

		// Compatibility.
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/woocommerce/class-interface-woocommerce.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/socialsnap/class-interface-socialsnap.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-wpforms.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-jetpack.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-beaver-themer.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-elementor.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-elementor-pro.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-hfe.php';
		require_once BUSINESS_INTERFACE_PATH . '/inc/compatibility/class-interface-smartocs.php';

		if (is_admin()) {
			require_once BUSINESS_INTERFACE_PATH . '/inc/utilities/class-interface-plugin-utilities.php';
			require_once BUSINESS_INTERFACE_PATH . '/inc/admin/class-interface-admin.php';
		}

		// Customizer.
		require_once BUSINESS_INTERFACE_PATH . '/inc/customizer/class-interface-customizer.php';
	}

	/**
	 * Setup objects to be used throughout the theme.
	 *
	 * @since  1.0.0
	 * @return void
	 */
	public function objects()
	{

		business_interface()->options = new Business_Interface_Options();
		business_interface()->fonts = new Business_Interface_Fonts();
		business_interface()->icons = new Business_Interface_Icons();
		business_interface()->customizer = new Business_Interface_Customizer();

		if (is_admin()) {
			business_interface()->admin = new Business_Interface_Admin();
		}
	}
}

/**
 * The function which returns the one Business Interface instance.
 *
 * Use this function like you would a global variable, except without needing
 * to declare the global.
 *
 * Example: <?php $business-interface = business_interface(); ?>
 *
 * @since 1.0.0
 * @return object
 */
function business_interface()
{
	return Business_Interface::instance();
}

business_interface();

/**
 * Declare theme category for WPInterface Add-ons demo import.
 * 
 * @since 1.0.0
 * @return string
 */
add_filter('wpinterface_theme_category', function () {
	return 'business';
});