<?php
/**
 * Post Single.
 *
 * @package MadeByAura\Prime\Pages
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Pages;

use MadeByAura\Prime\Base;
use MadeByAura\Prime\Helpers\SingletonTrait;

defined( 'ABSPATH' ) || die();

/**
 * Post Single.
 */
class PostSingle {
	use SingletonTrait;

	/**
	 * Constructor.
	 */
	protected function __construct() {
		// Add hooks after WordPress environment has been set up.
		add_action( 'wp', [ __CLASS__, 'add_hooks' ] );
	}

	/**
	 * Add hooks after WordPress environment has been set up.
	 */
	public static function add_hooks() {
		// Do not proceed if the current page is not post.
		if ( ! is_singular( 'post' ) ) {
			return;
		}

		// Change sidebar position.
		add_filter( 'aura_theme_sidebar_position', [ __CLASS__, 'change_position_sidebar' ] );
	}

	/**
	 * Change sidebar position.
	 *
	 * @param bool|string $position  Sidebar position.
	 * @return string
	 */
	public static function change_position_sidebar( $position ) {
		// Get meta.
		$post_meta = Base::get_acf( 'post', 'position_sidebar', null, 'default' );

		return 'default' === $post_meta ? $position : $post_meta;
	}
}
