<?php 

    namespace Pixebuilder\Element;

    // prevent direct file access
	if( !defined( 'ABSPATH' ) ) exit;
    
    class Wrapper{
        static function render($settings){
            
            $atts = array(
                'id' => empty($settings['_id'])? '': $settings['_id'],
                'anim-location' => pixe_animation_atts($settings),
                'scroll-motion' => pixe_scroll_motion_atts($settings),
            );
            $extra_class  = empty($settings['class'])? '': ' ' . trim($settings['class']);
            $extra_class .= empty($settings['header-sticky']['visibility'])? '': ' pixe-sticky-' . $settings['header-sticky']['visibility'];
            $extra_class .= pixe_get_responsive_class($settings);
            $extra_class .= pixe_animation_class($settings);

            // additional class for collection
            if( !empty($settings['is-overlay']) ){
                $extra_class .= ' pixe-is-overlay';
            }
            if( !empty($settings['_subtype']) && $settings['_subtype'] == 'mega-menu' ){
                $extra_class .= ' pixe-mega-menu';
                $extra_class .=  (empty($settings['mega-menu']['align'])? '': ' pixe-pos-' . $settings['mega-menu']['align']);
            }
            if( !empty($settings['slide']['slide-duration']) ){
                $atts['slide-duration'] = $settings['slide']['slide-duration'];
            }
            if( empty($settings['mega-menu']['size']) && !empty($settings['mega-menu']['align']) ){
                $atts['mmenu-align'] = $settings['mega-menu']['align'];
            }

            // content atts
            $content_atts = array();
            if( !empty($settings['child-margin']) || !empty($settings['tablet-child-margin']) || !empty($settings['mobile-child-margin']) ){
                $content_atts['content-id'] = $settings['_id'];
            }
            
            // background filter
            if( !empty($settings['bg-style']) ){
                pixe_set_background_color_filter($settings['bg-style']);
            }
            
            $ret = '<div class="pixe-wrapper' . esc_attr($extra_class) . '" ';
            $ret .= empty($settings['id'])? '': 'id="' . esc_attr($settings['id']) . '" ';
            $ret .= pixe_get_data_atts($atts);
            $ret .= ' >';
            $ret .= pixe_get_background_media($settings, !empty($settings['bg-style-display']));
            $ret .= '<div class="pixe-wrapper-content" ';
            $ret .= pixe_get_data_atts($content_atts);
            $ret .= ' >';
            $ret .= pixe_get_shape_divider($settings);
            $ret .= empty($settings['_elements'])? '': pixe_get_builder_content($settings['_elements']);
            $ret .= '</div>'; // pixe-wrapper-content

            if( !empty($settings['wrapper-link']) ){
                $link_tag = pixe_get_link_tag($settings['wrapper-link'], array(
                    'class' => 'pixe-wrapper-link',
                    'default-link-to' => 'custom'
                ));

                $ret .= empty($link_tag)? '': $link_tag . '</a>';
            }
            $ret .= '</div>'; // pixe-wrapper

            return $ret;
        }
    }