<?php
/**
 * Theme Config Initializer.
 *
 * Loads and initializes all theme-related configuration values
 * such as theme name, version, logo, slug, and related URLs.
 *
 * @package    Wira
 * @since      1.0.0
 */

namespace ThemeConfig;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Main_Theme_Config' ) ) {

	/**
	 * Main theme configuration class.
	 *
	 * Provides global theme configuration values via Singleton pattern.
	 *
	 * @since 1.0.0
	 */
	class Main_Theme_Config {

		/**
		 * Singleton instance.
		 *
		 * @since 1.0.0
		 * @var Main_Theme_Config|null
		 */
		private static $instance = null;

		/**
		 * Theme configuration array.
		 *
		 * @since 1.0.0
		 * @var array
		 */
		private $config = array();

		/**
		 * Private constructor to enforce Singleton.
		 *
		 * Loads theme configuration on instantiation.
		 *
		 * @since 1.0.0
		 */
		private function __construct() {
			$this->theme_config();
		}

		/**
		 * Get Singleton instance.
		 *
		 * @since 1.0.0
		 * @return Main_Theme_Config
		 */
		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}
			return self::$instance;
		}

		/**
		 * Prevent cloning of the instance.
		 *
		 * @since 1.0.0
		 * @return void
		 */
		private function __clone() {}

		/**
		 * Prevent unserialization of the instance.
		 *
		 * @since 1.0.0
		 * @throws \Exception If unserialization is attempted.
		 * @return void
		 */
		public function __wakeup() {
			throw new \Exception( 'Cannot unserialize singleton' );
		}

		/**
		 * Define theme configuration values.
		 *
		 * @since 1.0.0
		 * @return void
		 */
		private function theme_config() {
			$this->config = array(
				'home_url'    => home_url(),
				'activeTheme' => get_option( 'stylesheet' ),
				'version'     => WIRA_VERSION,
				'name'        => 'Wira',
				'demo'        => '',
				'banner'      => trailingslashit( get_template_directory_uri() ) . 'screenshot.jpg',
				'logo'        => trailingslashit( get_template_directory_uri() ) . 'assets/img/wira-logo.png',
				'logoWidth'   => '120',
				'slug'        => 'wira',
			);
		}

		/**
		 * Get a config value or the entire config array.
		 *
		 * @since 1.0.0
		 * @param string|null $key Config key to retrieve. Null returns full array.
		 * @return mixed Config value or full array.
		 */
		public function get_config( $key = null ) {
			if ( null !== $key && isset( $this->config[ $key ] ) ) {
				return $this->config[ $key ];
			}
			return $this->config;
		}
	}
}
