<?php 

    namespace Pixebuilder\Element;

    // prevent direct file access
	if( !defined( 'ABSPATH' ) ) exit;

    class Collection{
        static function render($settings){

            $atts = array(
                'id' => empty($settings['_id'])? '': $settings['_id']
            );
            $controls = empty($settings['controls'])? '': $settings['controls'];

            // slider settings
            if( $settings['_subtype'] == 'slider' ){
                $slider_settings = array();
                if( empty($settings['slider']['anim-in']) || $settings['slider']['anim-in'] != 'none' ){
                    if( !empty($settings['slider']['anim-in-duration']) ){
                        $slider_settings['in-duration'] = $settings['slider']['anim-in-duration'];
                    }
                }
                if( empty($settings['slider']['autoplay']) ){
                    $slider_settings['autoplay'] = 1; // default enable
                }
                if( !empty($settings['slider']['pause-on-hover']) ){
                    $slider_settings['pause-on-hover'] = 1; // default disable
                }
                if( !empty($settings['slider']['slide-duration']) ){
                    $slider_settings['slide-duration'] = $settings['slider']['slide-duration'];
                }

                $atts['slider'] = $slider_settings;
            }else if( $settings['_subtype'] == 'carousel' ){
                
                if( !empty($settings['slider']['autoplay']) && $settings['slider']['autoplay'] == 'cont' ){
                    $atts['autoplay'] = $settings['slider']['autoplay'];
                    $atts['speed'] = empty($settings['slider']['cont-speed'])? '': $settings['slider']['cont-speed'];
                    $atts['direction'] = empty($settings['slider']['cont-direction'])? '': $settings['slider']['cont-direction'];
                }else{
                    $atts['loop'] = empty($settings['slider']['loop'])? 'no': ''; // default no 
                    $atts['speed'] = empty($settings['slider']['slide-speed'])? '': $settings['slider']['slide-speed'];
                    $atts['autoplay'] = empty($settings['slider']['autoplay'])? '': $settings['slider']['autoplay']; 
                    $atts['delay'] = empty($settings['slider']['slide-duration'])? '': $settings['slider']['slide-duration'];
                    $atts['start'] = empty($settings['slider']['start-item'])? '': $settings['slider']['start-item'];
                    $atts['move'] = empty($settings['slider']['slide-amount'])? '': $settings['slider']['slide-amount'];
                    $atts['active-class'] = empty($settings['slider']['fade-overflow'])? '': 'yes'; // fade overflow
                    $atts['poh'] = empty($settings['slider']['pause-on-hover'])? '': 'yes'; // pause on hover
                }
            }   

            $extra_class  = empty($settings['class'])? '': $settings['class'];
            $extra_class .= empty($settings['_subtype'])? '': 'pixe-collection-' . $settings['_subtype'];

            $ret = '<div class="pixe-collection pixe-wrapper ' . esc_attr($extra_class) . '" ';
            $ret .= empty($settings['id'])? '': 'id="' . esc_attr($settings['id']) . '" ';
            $ret .= pixe_get_data_atts($atts);
            $ret .= ' >';
            $ret .= empty($settings['bg-style-display'])? '': '<div class="pixe-bg-style" ></div>';
            $ret .= pixe_get_background_media($settings);
            $ret .= '<div class="pixe-collection-content" >';
            $ret .= empty($settings['_elements'])? '': pixe_get_builder_content($settings['_elements']);
            $ret .= '</div>'; // pixe-collection-content

            // slider controls
            $ret .= pixe_get_slider_bullet($controls);
            $ret .= pixe_get_slider_navigation($controls);
            $ret .= pixe_get_slider_touch_navigation($controls);
            
            $ret .= '</div>'; // pixe-wrapper

            return $ret;
        }
    }