<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php 

class Beruco_Widget_Register {
	
	private static $_instance = null;

    public static $widget_args = null;
	
	public function __construct() {

		// Arguments used in all register_sidebar() calls.
        self::$widget_args = array(
            'before_title'  => '<h3 class="widget-title subheading heading-size-3">',
            'after_title'   => '</h3>',
            'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
            'after_widget'  => '</div></div>',
        );

        $this->beruco_register_sidebars();
		
        $this->beruco_custom_sidebar_register();

        add_action( 'beruco_footer_top', array( $this, 'beruco_insta_footer' ), 10 );

	}

    public function beruco_register_sidebars(){
        // Footer Top
        register_sidebar(
            array_merge(
                self::$widget_args,
                array(
                    'name'        => esc_html__( 'Footer Top', 'beruco-addon' ),
                    'id'          => 'insta-footer',
                    'description' => esc_html__( 'Widgets in this area will be displayed in the top of footer.', 'beruco-addon' ),
                )
            )
        );
    }

    public function beruco_custom_sidebar_register(){
        // Custom Sidebars / Core Functions
        $sidebars = get_option( 'beruco_custom_sidebars' );
        if( !empty( $sidebars ) && is_array( $sidebars ) ){
            foreach( $sidebars as $sidebar_slug => $sidebar_name ){
                register_sidebar(
                    array_merge(
                        self::$widget_args,
                        array(
                            'name'        => esc_html( $sidebar_name ),
                            'id'          => esc_attr( $sidebar_slug )
                        )
                    )
                );
            }
        }
    }

    public function beruco_insta_footer(){
        if( is_active_sidebar( 'insta-footer' ) ):
            $keys = array(
                'chk' => 'insta-footer-chk',
                'fields' => array(
                    'insta_footer_layout' => 'insta-footer-layout'
                )			
            );
            $footer_top_values = Beruco_Wp_Elements::beruco_get_meta_and_option_values( $keys );
            $footer_top_class = isset( $footer_top_values['insta_footer_layout'] ) && $footer_top_values['insta_footer_layout'] == 'boxed' ? 'container' : 'container-fluid p-0';
    ?>
        <div class="insta-footer-wrap">
	        <div class="<?php echo esc_attr( $footer_top_class ); ?>">
                <div class="row">
                    <aside class="footer-insta-widget col-12">
                        <?php dynamic_sidebar( 'insta-footer' ); ?>
                    </aside>
                </div>
            </div>
        </div>
    <?php
        endif;
    }
	
	/**
	 * Creates and returns an instance of the class
	 * @since 1.0.0
	 * @access public
	 * return object
	 */
	public static function get_instance() {
		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}

} Beruco_Widget_Register::get_instance();


