<?php
/**
 * Functions and definitions for the Wira theme.
 *
 * @package Wira
 * @since   1.0.1
 */

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

// Define theme constants globally so they are accessible from anywhere (including template parts).
if ( ! defined( 'WIRA_VERSION' ) ) {
	$theme = wp_get_theme();
	define( 'WIRA_VERSION', $theme->get( 'Version' ) );
}
defined( 'WIRA_DIR' ) || define( 'WIRA_DIR', trailingslashit( get_template_directory() ) );
defined( 'WIRA_URI' ) || define( 'WIRA_URI', trailingslashit( get_template_directory_uri() ) );

// Check if the main class exists.
if ( ! class_exists( 'Wira_Theme' ) ) {

	/**
	 * Main theme class to initialize core functionality.
	 */
	class Wira_Theme {


		/**
		 * Holds the single instance of the class.
		 *
		 * @var Wira_Theme|null
		 */
		private static $instance = null;

		/**
		 * Returns the singleton instance.
		 *
		 * @return Wira_Theme
		 */
		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}
			return self::$instance;
		}

		/**
		 * Constructor is private to enforce singleton usage.
		 */
		private function __construct() {
			$this->include_files();
			$this->loader_init();
		}

		/**
		 * Dynamically load all required class files.
		 */
		private function include_files() {

			include_once WIRA_DIR . 'inc/class-main-theme-config.php';
			include_once WIRA_DIR . 'inc/class-loader.php';
			include_once WIRA_DIR . 'inc/class/compatibility/class-block-patterns.php';
		}

		/**
		 * Class Init
		 */
		private function loader_init() {
			\Wira\Class_Loader::get_instance();
			\Wira\Block_Patterns::get_instance();
		}
	}

	// Initialize the theme.
	Wira_Theme::get_instance();
}
