<?php
/**
 * Site-wide SPA navigation for public theme pages.
 *
 * Keeps the persistent header/footer in place and swaps only the page-content
 * shell. Full navigation remains the automatic fallback whenever a target
 * cannot be hydrated safely.
 *
 * @package Shabnam_MuchWOW
 */

defined( 'ABSPATH' ) || exit;

/**
 * Enqueue the global SPA navigation layer.
 */
function shabnam_site_spa_assets() {
	if ( is_admin() || ( function_exists( 'shabnam_get_setting' ) && ! shabnam_get_setting( 'site_spa_enabled', true ) ) ) {
		return;
	}
	$uri = get_template_directory_uri();
	wp_enqueue_script( 'shabnam-site-spa', $uri . '/assets/js/site-spa.js', array(), shabnam_asset_version( 'assets/js/site-spa.js' ), true );
	wp_localize_script(
		'shabnam-site-spa',
		'SHCDSiteSPA',
		array(
			'enabled' => true,
			'home'    => esc_url_raw( home_url( '/' ) ),
			'admin'   => esc_url_raw( admin_url() ),
			'login'   => esc_url_raw( wp_login_url() ),
		)
	);
}
add_action( 'wp_enqueue_scripts', 'shabnam_site_spa_assets', 50 );

/**
 * Add a body class for CSS transitions.
 *
 * @param array<int,string> $classes Body classes.
 * @return array<int,string>
 */
function shabnam_site_spa_body_class( $classes ) {
	if ( ! function_exists( 'shabnam_get_setting' ) || shabnam_get_setting( 'site_spa_enabled', true ) ) {
		$classes[] = 'shabnam-site-spa-enabled';
	}
	return $classes;
}
add_filter( 'body_class', 'shabnam_site_spa_body_class' );
