<?php
/**
 * BuddyPress support for FansPaysite theme.
 *
 * Loaded only when BuddyPress is active. Declares theme compatibility so
 * BuddyPress uses WordPress templates, and enqueues the bundled stylesheet
 * that applies the theme's light/dark mode variables to core BP elements.
 *
 * @package FansPaysite
 * @since   2.3
 */

// Bail if BuddyPress is not active.
if ( ! function_exists( 'buddypress' ) ) {
	return;
}

/**
 * Add a body class on BuddyPress pages for targeted CSS overrides.
 *
 * @since 2.3
 * @param  array $classes Existing body classes.
 * @return array
 */
function fanspaysite_buddypress_body_class( $classes ) {
	if ( function_exists( 'is_buddypress' ) && is_buddypress() ) {
		$classes[] = 'has-buddypress';
	}
	return $classes;
}
add_filter( 'body_class', 'fanspaysite_buddypress_body_class' );

/**
 * Enqueue the BuddyPress stylesheet on BuddyPress screens only.
 *
 * Depends on the main theme stylesheet so CSS variable declarations are
 * already available when BuddyPress rules are parsed.
 *
 * @since 2.3
 */
function fanspaysite_buddypress_styles() {
	if ( ! function_exists( 'is_buddypress' ) || ! is_buddypress() ) {
		return;
	}

	$path    = get_template_directory() . '/css/buddypress.css';
	$version = file_exists( $path ) ? filemtime( $path ) : '2.3';
	wp_enqueue_style(
		'fanspaysite-buddypress',
		get_template_directory_uri() . '/css/buddypress.css',
		array( 'fanspaysite-style' ),
		$version
	);
}
add_action( 'wp_enqueue_scripts', 'fanspaysite_buddypress_styles' );
