<?php

namespace Tech360;

defined( 'ABSPATH' ) or die;

class Widget {

	private $sidebars = [];

	/**
	 * Add a sidebar
	 * @param array		$sidebar		Sidebar args
	 */
	function add( $sidebar ) {

		if( ! is_array( $sidebar ) ) {
			return;
		}

		if( ! array_key_exists( 'name', $sidebar ) || ! array_key_exists( 'id', $sidebar ) ) {
			return;
		}

		if( ! array_key_exists( 'before_widget', $sidebar ) ) {
			$sidebar[ 'before_widget' ] = '<div id="%1$s" class="footer-widget %2$s">';
		}

		if( ! array_key_exists( 'after_widget', $sidebar ) ) {
			$sidebar[ 'after_widget' ] = '</div>';
		}

		if( ! array_key_exists( 'before_title', $sidebar ) ) {
			$sidebar[ 'before_title' ] = '<h4 class="footer-widget-title">';
		}

		if( ! array_key_exists( 'after_title', $sidebar ) ) {
			$sidebar[ 'after_title' ] = '</h4>';
		}

		$this->sidebars[] = $sidebar;

	}

	/**
	 * Register the sidebars
	 */
	function _register() {

		if( empty( $this->sidebars ) ) {
			return;
		}

		foreach( $this->sidebars as $sidebar ) {
			register_sidebar( $sidebar );
		}

	}

	/**
	 * Add action function
	 */
	function render() {

		add_action( 'widgets_init', [ $this, '_register' ] );

	}

}
