<?php
/**
 * Sidebar and Default Widgets Manager
 *
 * Handles registration of theme sidebars and automatic
 * insertion of default widgets when the theme is activated.
 *
 * @package    Wira
 * @subpackage Widgets
 * @since      1.0.0
 */

namespace Wira;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

if ( ! class_exists( 'Sidebar_Manager' ) ) {

	/**
	 * Sidebar Manager Class.
	 *
	 * Registers custom sidebars for the theme and populates
	 * them with default widgets when the theme is first activated.
	 *
	 * @since 1.0.0
	 */
	class Sidebar_Manager {

		/**
		 * Constructor.
		 *
		 * Initializes hooks for sidebar and widget management.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {
			$this->load_hooks();
		}

		/**
		 * Register all necessary hooks.
		 *
		 * @since 1.0.0
		 * @return void
		 */
		private function load_hooks() {
			add_action( 'widgets_init', array( $this, 'register_sidebar' ) );
		}

		/**
		 * Register sidebar for the theme.
		 *
		 * Defines widget wrapper markup and title structure
		 * for the "Right Sidebar".
		 *
		 * @since 1.0.0
		 * @return void
		 */
		public function register_sidebar() {
			register_sidebar(
				array(
					/* translators: Sidebar name. */
					'name'          => __( 'Right Sidebar', 'wira' ),
					'id'            => 'right-sidebar',
					/* translators: Sidebar description. */
					'description'   => __( 'Sidebar for widgets', 'wira' ),
					'before_widget' => '<div id="%1$s" class="widget theme-blog-sidebar %2$s">',
					'after_widget'  => '</div>',
					'before_title'  => '<h4 class="widget-title">',
					'after_title'   => '</h4>',
				)
			);
		}
	}
}
