<?php
    namespace Pixebuilder\Element;
    
    // prevent direct file access
	if( !defined( 'ABSPATH' ) ) exit;
    
    class Widget extends Item{

        static function get_name(){
            return 'widget';
        }

        static function get_default(){
            return array();
        }

        static function get_title(){
            return esc_html__('Widget', 'pixebuilder');
        }

        static function get_icon(){
            return 'widget';
        }
        
        static function render_content($settings){
            $ret = '';

            if( !empty($settings['widget']) && is_active_sidebar($settings['widget']) ){
                ob_start();
                dynamic_sidebar($settings['widget']);
                $ret .= ob_get_clean();
            }


            return $ret;
        }

    }

    \Pixe_Builder::register_element('Pixebuilder\Element\Widget');

    function register_widget_area() {
        register_sidebar(array(
            'name'          => esc_html__('Pixe Widget Area', 'pixebuilder'),
            'id'            => 'pixe_widget_area',
            'description'   => esc_html__('A custom widget area.', 'pixebuilder'),
            'before_widget' => '<div class="widget %2$s">',
            'after_widget'  => '</div>',
            'before_title'  => '<h3 class="widget-title">',
            'after_title'   => '</h3>',
        ));
    }
    add_action('widgets_init', 'Pixebuilder\Element\register_widget_area');