<?php
/**
 * Sidebar.
 *
 * @package MadeByAura\Prime\Hooks
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Hooks;

use MadeByAura\Prime\Helpers\SingletonTrait;

defined( 'ABSPATH' ) || die();
use MadeByAura\Prime\Modules\Sidebar as ModulesSidebar;

/**
 * Sidebar.
 */
class Sidebar {
	use SingletonTrait;

	/**
	 * Constructor.
	 */
	protected function __construct() {
		// Add classes to body tag.
		add_filter( 'body_class', [ __CLASS__, 'add_classes' ] );

		// Disable sidebar conditionally.
		add_filter( 'aura_theme|view|disable|views/sidebar/index', [ __CLASS__, 'disable_sidebar_conditionally' ] );
	}

	/**
	 * Add classes to body tag.
	 *
	 * @param array $classes  Classes for body tag.
	 * @return array $classes
	 */
	public static function add_classes( $classes ) {
		$position = ModulesSidebar::get_position();

		if ( $position ) {
			$classes[] = 'aura-g-sidebar-enabled';
			$classes[] = 'aura-g-' . $position . '-sidebar';
		} else {
			$classes[] = 'aura-g-sidebar-disabled';
		}

		return $classes;
	}

	/**
	 * Disable sidebar conditionally.
	 */
	public static function disable_sidebar_conditionally() {
		return ModulesSidebar::get_position() ? false : true;
	}
}
