<?php
/**
 * Theme functions
 * Handle theme functionality
 *
 * @package Brandy/Functions
 */

namespace Brandy;

if ( ! defined( 'BRANDY_TEMPLATE_DIR' ) ) {
	define( 'BRANDY_TEMPLATE_DIR', get_template_directory() );
}
if ( ! defined( 'BRANDY_TEMPLATE_URL' ) ) {
	define( 'BRANDY_TEMPLATE_URL', get_template_directory_uri() );
}
if ( ! defined( 'BRANDY_PATTERN_BASE_SLUG' ) ) {
	define( 'BRANDY_PATTERN_BASE_SLUG', 'brandy' );
}
if ( ! defined( 'BRANDY_IS_DEVELOPMENT' ) ) {
	define( 'BRANDY_IS_DEVELOPMENT', false );
}
if ( ! defined( 'BRANDY_VERSION' ) ) {
	define( 'BRANDY_VERSION', wp_get_theme()->get( 'Version' ) );
}

if ( ! defined( 'BRANDY_SCRIPT_VERSION' ) ) {
	define( 'BRANDY_SCRIPT_VERSION', BRANDY_IS_DEVELOPMENT ? time() : BRANDY_VERSION );
}

require_once get_template_directory() . '/vendor/autoload.php';

// WordPress skips widget customizer for block themes (decided at plugins_loaded).
// Manually load WP_Customize_Widgets before customize_register fires (at wp_loaded).
add_action(
	'after_setup_theme',
	function () {
		// Temp open for Bookster and Brandy Blocks
		if ( ! defined( 'BOOKSTER_VERSION' ) && ! defined( 'BRANDY_BLOCKS_VERSION' ) ) {
			return;
		}
		if ( ! defined( 'ABSPATH' ) ) {
			return;
		}
		if ( ! defined( 'WPINC' ) ) {
			return;
		}
		global $wp_customize;
		if ( $wp_customize && empty( $wp_customize->widgets ) ) {
			$path_to_widgets_definition = ABSPATH . WPINC . '/class-wp-customize-widgets.php';
			if ( ! file_exists( $path_to_widgets_definition ) ) {
				return;
			}
			require_once $path_to_widgets_definition;
			$wp_customize->widgets = new \WP_Customize_Widgets( $wp_customize );
		}
	}
);

ThemeInitialize::get_instance();
