<?php
/**
 * Sidebar Hooks Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Hook;

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\Errigal_Sidebar_Hook as Sidebar_Hook;
use Errigal\Content\Errigal_Content as Content;
use Errigal\Shared\Errigal_Validator as Validator;

/**
 * This class is in charge of adding sidebar hooks.
 *
 * @since 1.1.0
 */
class Errigal_Sidebar_Hooks extends Errigal_Hooks_Base {
	/**
	 * Determines whether sidebar can be displayed.
	 *
	 * @since 1.1.0
	 *
	 * @see Errigal\Sidebar\Errigal_Sidebar::can_show()
	 *
	 * @param bool $can_show Whether sidebar can be displayed.
	 * @return bool
	 */
	public function can_show_sidebar( $can_show ) {
		return Validator::is_true( $can_show ) &&
			! is_404() &&
			! Content::is_no_sidebar_post();
	}

	/**
	 * Adds hooks.
	 *
	 * @since 1.1.0
	 *
	 * @return void
	 */
	public function add_hooks() {
		add_filter( Sidebar_Hook::CAN_SHOW_SIDEBAR, array( $this, 'can_show_sidebar' ) );
	}
}
