<?php
/**
 * Frontend Hooks
 *
 * @package Kutby
 * @since   1.0.0
 */

declare(strict_types=1);

namespace Kutby\Hooks;

use Kutby\Contracts\ModuleInterface;
use Kutby\ThemeOptions\Manager;

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

/**
 * Class FrontendHooks
 */
final class FrontendHooks implements ModuleInterface {

	/**
	 * Register hooks.
	 *
	 * @return void
	 */
	public function register(): void {
		add_filter( 'body_class', array( $this, 'body_classes' ) );
	}

	/**
	 * {@inheritdoc}
	 */
	public function boot(): void {}

	/**
	 * Add contextual body classes.
	 *
	 * @param array<int, string> $classes Classes.
	 * @return array<int, string>
	 */
	public function body_classes( array $classes ): array {
		$classes[] = 'kutby';
		$classes[] = 'kutby-rtl';

		if ( Manager::get( 'general.enable_dark_mode' ) ) {
			$classes[] = 'kutby-dark-ready';
		}

		// header.sticky → kutby-header-sticky is owned by HeaderModule.

		$sidebar = Manager::get_group( 'sidebar' );
		if ( ! empty( $sidebar['enabled'] ) ) {
			$classes[] = 'kutby-has-sidebar';
			$classes[] = 'kutby-sidebar-' . sanitize_html_class( (string) ( $sidebar['position'] ?? 'left' ) );
		}

		return $classes;
	}

	/**
	 * @deprecated 2.5.1 Sidebars moved to WidgetsModule. Kept as no-op BC shim.
	 * @return void
	 */
	public function register_sidebars(): void {
		// Intentionally empty — registration lives in Kutby\Modules\WidgetsModule.
	}
}
