<?php
/**
 * Register Widgets
 *
 * @package HvnlyNab\Database\Custom_Widgets
 */

namespace HvnlyNab\Database\Custom_Widgets;

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

/**
 * Class Register_Widgets
 */
class Register_Widgets {

	/**
	 * Constructor.
	 */
	public function __construct() {
		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
	}

	/**
	 * Get sidebar definitions.
	 *
	 * @return array
	 */
	public static function register_sidebar() {
		return array(
			array(
				'name'          => esc_html__( 'Havenlytics - Single Property Sidebar', 'havenlytics' ),
				'id'            => 'hvnly_single_property_sidebar_widgets_area',
				'description'   => esc_html__( 'Add widgets for the sidebar on single property page.', 'havenlytics' ),
				'before_widget' => '<div id="%1$s" class="widget hvnly-widget %2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="hvnly-property-single__widget-title">',
				'after_title'   => '</h4>',
			)
			
		);
	}

	/**
	 * Get widget classes.
	 *
	 * @return array
	 */
	public static function get_widgets() {
		return array(
			All_Widgets\Hvnly_Featured_Properties_Widget::class,
			All_Widgets\Hvnly_Property_Agent_Widget::class,
			All_Widgets\Hvnly_Mortgage_Calculator_Widget::class,
			All_Widgets\Hvnly_Related_Properties_Widget::class,
			
		);
	}

	/**
	 * Register widgets and sidebars.
	 */
	public function register_widgets() {
		foreach ( self::get_widgets() as $class ) {
			if ( class_exists( $class ) ) {
				register_widget( $class );
			}
		}

		foreach ( self::register_sidebar() as $sidebar ) {
			register_sidebar( $sidebar );
		}
	}
}