<?php

// Add theme support for essential features
function fanspaysite_setup() {
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ) );
	add_theme_support( 'customize-selective-refresh-widgets' );


	add_theme_support('custom-logo', array(
		'height'      => 128, // Set the desired height for the logo
		'width'       => 128, // Set the desired width for the logo
		'flex-height' => true, // Allow flexible logo height
		'flex-width'  => true, // Allow flexible logo width
	//	'header-text' => array('site-title', 'site-description'), // Select which elements the logo can replace
	));

	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'responsive-embeds');
	add_theme_support( 'align-wide' );

	add_theme_support( 'custom-header', array(
		'width'         => 1920,
		'height'        => 128,
		'flex-width'    => true,
		'flex-height'   => true,
		'default-image' => '', // Path to default header image
		'header-text'   => false, // Set to true if you want text over the header image
	));

	add_theme_support( 'custom-background', array(
		'default-color' => 'fff', // Default background color
		'default-image' => '', // Path to default background image, if any
		'wp-head-callback' => '_custom_background_cb',
	));

	add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'video', 'quote', 'link', 'audio' ) );

	load_theme_textdomain('fanspaysite', get_template_directory() . '/languages');
}
add_action( 'after_setup_theme', 'fanspaysite_setup' );

function fanspaysite_register_sidebars() {
	register_sidebar(array(
		'id'            => 'fanspaysite_left_sidebar',
		'name'          => __('FansPaysite Left Sidebar', 'fanspaysite'),
		'description'   => __('Widgets added here will appear in the left column of the site, under menu.', 'fanspaysite'),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	));
	register_sidebar(array(
		'id'            => 'fanspaysite_right_sidebar',
		'name'          => __('FansPaysite Right Sidebar', 'fanspaysite'),
		'description'   => __('Widgets added here will appear in the right column of the site, when visible.', 'fanspaysite'),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	));

	// Footer widget areas (up to 3 columns)
	for ( $i = 1; $i <= 3; $i++ ) {
		register_sidebar( array(
			'id'            => 'fanspaysite_footer_' . $i,
			'name'          => sprintf( __( 'Footer Column %d', 'fanspaysite' ), $i ),
			'description'   => sprintf( __( 'Widgets for footer column %d.', 'fanspaysite' ), $i ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		) );
	}
}
add_action('widgets_init', 'fanspaysite_register_sidebars');

// Add body classes for menu display mode, submenu display, hover mode, and layout
function fanspaysite_body_classes($classes) {
	$menu_mode = get_theme_mod('fanspaysite_menu_display_mode', 'auto');
	$classes[] = 'menu-display-' . sanitize_html_class($menu_mode);

	$submenu_mode = get_theme_mod('fanspaysite_submenu_display_mode', 'auto');
	$classes[] = 'submenu-display-' . sanitize_html_class($submenu_mode);

	$hover_mode = get_theme_mod('fanspaysite_submenu_hover', 'auto');
	$classes[] = 'submenu-hover-' . sanitize_html_class($hover_mode);

	$layout = get_theme_mod('fanspaysite_layout', 'left-sidebar');
	$classes[] = 'layout-' . sanitize_html_class($layout);

	$burger_menu = get_theme_mod('fanspaysite_burger_menu', 'auto');
	$classes[] = 'burger-menu-' . sanitize_html_class($burger_menu);

	// Archive display mode (only on archive-like pages)
	if ( is_home() || is_archive() || is_search() ) {
		$archive_display = get_theme_mod( 'fanspaysite_archive_display', 'classic' );
		$classes[] = 'archive-display-' . sanitize_html_class( $archive_display );
	}

	return $classes;
}
add_filter('body_class', 'fanspaysite_body_classes');

/**
 * Get the current archive display mode.
 *
 * @since 2.3
 * @return string 'classic', 'fullpage', or 'boxes'
 */
function fanspaysite_get_archive_display() {
	return get_theme_mod( 'fanspaysite_archive_display', 'classic' );
}

require_once get_template_directory() . '/inc/enqueue.php';
require_once get_template_directory() . '/inc/menu.php';
require_once get_template_directory() . '/inc/mode.php';
require_once get_template_directory() . '/inc/customizer.php';
require_once get_template_directory() . '/inc/comments.php';
require_once get_template_directory() . '/inc/blocks.php';
require_once get_template_directory() . '/inc/skins.php';
require_once get_template_directory() . '/inc/onboarding.php';

// WooCommerce support — loaded only when WooCommerce is active.
if ( class_exists( 'WooCommerce' ) ) {
	require_once get_template_directory() . '/inc/woocommerce.php';
}

// BuddyPress support — loaded only when BuddyPress is active.
if ( function_exists( 'buddypress' ) ) {
	require_once get_template_directory() . '/inc/buddypress.php';
}
