<commit_before><?php namespace Experiensa\Component;

use Experiensa\Modules\QueryBuilder;

class SectionLayout
{
    private $background_settings;
    private $background = array();
    private $content_settings;
    private $slider = array();
    private $slider_obj;
    private $layout;
    private $textimage;
    private $showcase_data;
    private $page_data;
    private $source = 'page';

    function __construct($content_settings,$background_settings){
        $this->source = $content_settings['source_type'];
        $this->background_settings = $background_settings;
        $this->content_settings = $content_settings;
        $this->setSectionBackground($background_settings,$this->source);
        $this->setSectionLayout();
        $this->setTextImage();
        $this->setShowcaseData();
    }
    public function displaySectionLayout(){
        //Showcase
        if($this->source == 'showcase'){
            if($this->content_settings['component'] == 'slider'){
                $this->setSectionShowcaseSlider();
                $this->slider_obj = new Slider($this->slider['component'],
                    $this->slider['post_type'],
                    $this->slider['taxonomy'],
                    $this->slider['terms'],
                    $this->slider['message']);
                $show_layout = ($this->content_settings['show_layout']=='TRUE'?true:false);
                $background = $this->background;
                $layout = $this->layout;
                include(locate_template('templates/partials/section/component_slider.php'));
            }else{
                $component = $this->content_settings['component'];
                $background = $this->background;
                $showcase_data = $this->showcase_data;
//                print_r($showcase_data);
                $textimage_obj = new Textimage($this->textimage);
                $layout = $this->layout;
                include(locate_template('templates/partials/section/component.php'));
            }
        }else{//Page
            $this->setSectionPageSlider($this->background_settings,$this->source);
            $this->setPageData();
            //Show Page with Slider
            if(!empty($this->slider)){
                $message = '<h1>'.$this->page_data['title'].'</h1>'.$this->page_data['content'];
                $this->slider_obj = new Slider($this->slider['component'],
                    $this->slider['post_type'],
                    $this->slider['taxonomy'],
                    $this->slider['terms'],
                    $message);
                $this->slider_obj->showSlider();
            }else{
                $background = $this->background;
                $layout = $this->layout;
                $page = $this->page_data;
                include(locate_template('templates/partials/section/single_page.php'));
            }
        }
    }
    public function setSectionBackground($background_settings, $source = 'page'){
        $background['style'] = '';
        $background['class'] = '';
        $background['type'] = 'none';
        if($background_settings['show_background'] == 'TRUE' && ( $source == 'showcase' || ($source == 'page' && $background_settings['background_type_page'] != 'slider')) ){
            $type = $this->getBackgroundType($background_settings,$source);
            if($type == 'color'){
                $background['style'] = '';
                $background['class'] = $this->getBgColor($background_settings,$source);
                $background['type'] = 'color';
            }else{
                if($type == 'texture'){
                    $background['style'] = $this->getBgTexture($background_settings,$source);
                    $background['class'] = '';
                    $background['type'] = 'texture';
                }else{
                    $background['style'] = $this->getBgImage($background_settings,$source);
                    $background['class'] = '';
                    $background['type'] = 'image';
                }
            }
        }
        $this->background = $background;
    }
    public function getBackgroundType($background_settings, $source = 'page'){
        if($source == 'page'){
            return $background_settings['background_type_page'];
        }
        return $background_settings['background_type_showcase'];
    }
    public function getBgColor($background_settings,$source){
        if($source == 'page'){
            return get_the_color($background_settings['background_color_page'], $background_settings['color_inverted_page']);
        }
        return get_the_color($background_settings['background_color_showcase'], $background_settings['color_inverted_showcase']);
    }
    public function getBgTexture($background_settings,$source){
        if($source == 'page'){
            $texture_image = $this->getBackgroundImage($background_settings['bg_texture_page']);
        }else{
            $texture_image = $this->getBackgroundImage($background_settings['bg_texture_showcase']);
        }
        return ($texture_image ? "background-image: url(" . $texture_image . "); background-repeat:repeat;" : "");
    }
    public function getBgImage($background_settings,$source){
        if($source == 'page'){
            $image = $this->getBackgroundImage($background_settings['bg_image_page']);
        }else{
            $image = $this->getBackgroundImage($background_settings['bg_image_showcase']);
        }
        return ($image ? "background:url('" . $image . "') no-repeat center center fixed; background-size: cover; height:100vh;" : "");
    }
    private function getBackgroundImage($images){
        $bg_img = false;
        foreach($images as $img){
            if(isset($img)){
                $bg_img = wp_get_attachment_url($img);
                break;
            }
        }
        return $bg_img;
    }
    private function checkShowPageBgSlider($background_settings,$source){
        if($source == 'page' && $background_settings['show_background'] == 'TRUE' && $background_settings['background_type_page'] == 'slider')
            return true;
        return false;
    }
    private function setSectionPageSlider($background_settings, $source){
        if($this->checkShowPageBgSlider($background_settings,$source)){
            $slider['component'] = 'vegas';
            $slider['post_type'] = ['attachment'];
            $slider['taxonomy'] = 'media_category';
            $slider_terms = explode(',',$background_settings['media_category']);
            $slider['terms'] = (!empty($slider_terms)?$slider_terms:['landing']);
            $this->slider = $slider;
        }
    }
    private function setSectionShowcaseSlider(){
        $type = $this->content_settings['slider_type'];
        if($type == 'posts'){
            $slider['component'] = 'superslides';
            $slider['post_type'] = [$this->content_settings['posttype']];
            $slider['taxonomy'] = $this->content_settings['category'];
            $slider['terms'] = explode(',',$this->content_settings['terms']);
            $slider['message'] = '';
            $this->slider = $slider;
        }else{
            $slider['component'] = 'vegas';
            $slider['post_type'] = ['attachment'];
            $slider['taxonomy'] = $this->content_settings['category'];
            $slider['terms'] = explode(',',$this->content_settings['terms']);
            $slider['message'] = (!empty($this->content_settings['message'])?$this->content_settings['message']:ucwords(str_replace('_',' ',$slider['taxonomy'])));
            $this->slider = $slider;
        }
    }
    private function setSectionLayout(){
        $layout['container_class'] = '';
        $layout['container_style'] = 'padding: 0px 15px 0 15px;';
        
        if($this->background['type'] == 'color' || $this->background['type'] == 'none'){
          $layout['content_color'] = 'color:#000000;';
          $layout['title_color'] = 'color:#000000;';
        }
        else{
          $layout['content_color'] = 'color:#FFFFFF;';
          $layout['title_color'] = 'color:#FFFFFF;';
        }
        $layout['title_alignment'] = 'left aligned';
        $layout['title'] = ucwords(str_replace('_',' ',$this->content_settings['category']));
        $layout['subtitle'] = '';
        if($this->source == 'showcase' && $this->content_settings['show_layout'] == 'TRUE'){
            if ($this->content_settings['container'] == 'container') {
                $layout['container_class'] = 'container';
                $layout['container_style'] = '';
            }
            if(!empty($this->content_settings['content_color'] ))
                $layout['content_color'] = 'color:'.$this->content_settings['content_color'].';';<commit_msg>title centered align by default on section layout<commit_after><?php namespace Experiensa\Component;

use Experiensa\Modules\QueryBuilder;

class SectionLayout
{
    private $background_settings;
    private $background = array();
    private $content_settings;
    private $slider = array();
    private $slider_obj;
    private $layout;
    private $textimage;
    private $showcase_data;
    private $page_data;
    private $source = 'page';

    function __construct($content_settings,$background_settings){
        $this->source = $content_settings['source_type'];
        $this->background_settings = $background_settings;
        $this->content_settings = $content_settings;
        $this->setSectionBackground($background_settings,$this->source);
        $this->setSectionLayout();
        $this->setTextImage();
        $this->setShowcaseData();
    }
    public function displaySectionLayout(){
        //Showcase
        if($this->source == 'showcase'){
            if($this->content_settings['component'] == 'slider'){
                $this->setSectionShowcaseSlider();
                $this->slider_obj = new Slider($this->slider['component'],
                    $this->slider['post_type'],
                    $this->slider['taxonomy'],
                    $this->slider['terms'],
                    $this->slider['message']);
                $show_layout = ($this->content_settings['show_layout']=='TRUE'?true:false);
                $background = $this->background;
                $layout = $this->layout;
                include(locate_template('templates/partials/section/component_slider.php'));
            }else{
                $component = $this->content_settings['component'];
                $background = $this->background;
                $showcase_data = $this->showcase_data;
//                print_r($showcase_data);
                $textimage_obj = new Textimage($this->textimage);
                $layout = $this->layout;
                include(locate_template('templates/partials/section/component.php'));
            }
        }else{//Page
            $this->setSectionPageSlider($this->background_settings,$this->source);
            $this->setPageData();
            //Show Page with Slider
            if(!empty($this->slider)){
                $message = '<h1>'.$this->page_data['title'].'</h1>'.$this->page_data['content'];
                $this->slider_obj = new Slider($this->slider['component'],
                    $this->slider['post_type'],
                    $this->slider['taxonomy'],
                    $this->slider['terms'],
                    $message);
                $this->slider_obj->showSlider();
            }else{
                $background = $this->background;
                $layout = $this->layout;
                $page = $this->page_data;
                include(locate_template('templates/partials/section/single_page.php'));
            }
        }
    }
    public function setSectionBackground($background_settings, $source = 'page'){
        $background['style'] = '';
        $background['class'] = '';
        $background['type'] = 'none';
        if($background_settings['show_background'] == 'TRUE' && ( $source == 'showcase' || ($source == 'page' && $background_settings['background_type_page'] != 'slider')) ){
            $type = $this->getBackgroundType($background_settings,$source);
            if($type == 'color'){
                $background['style'] = '';
                $background['class'] = $this->getBgColor($background_settings,$source);
                $background['type'] = 'color';
            }else{
                if($type == 'texture'){
                    $background['style'] = $this->getBgTexture($background_settings,$source);
                    $background['class'] = '';
                    $background['type'] = 'texture';
                }else{
                    $background['style'] = $this->getBgImage($background_settings,$source);
                    $background['class'] = '';
                    $background['type'] = 'image';
                }
            }
        }
        $this->background = $background;
    }
    public function getBackgroundType($background_settings, $source = 'page'){
        if($source == 'page'){
            return $background_settings['background_type_page'];
        }
        return $background_settings['background_type_showcase'];
    }
    public function getBgColor($background_settings,$source){
        if($source == 'page'){
            return get_the_color($background_settings['background_color_page'], $background_settings['color_inverted_page']);
        }
        return get_the_color($background_settings['background_color_showcase'], $background_settings['color_inverted_showcase']);
    }
    public function getBgTexture($background_settings,$source){
        if($source == 'page'){
            $texture_image = $this->getBackgroundImage($background_settings['bg_texture_page']);
        }else{
            $texture_image = $this->getBackgroundImage($background_settings['bg_texture_showcase']);
        }
        return ($texture_image ? "background-image: url(" . $texture_image . "); background-repeat:repeat;" : "");
    }
    public function getBgImage($background_settings,$source){
        if($source == 'page'){
            $image = $this->getBackgroundImage($background_settings['bg_image_page']);
        }else{
            $image = $this->getBackgroundImage($background_settings['bg_image_showcase']);
        }
        return ($image ? "background:url('" . $image . "') no-repeat center center fixed; background-size: cover; height:100vh;" : "");
    }
    private function getBackgroundImage($images){
        $bg_img = false;
        foreach($images as $img){
            if(isset($img)){
                $bg_img = wp_get_attachment_url($img);
                break;
            }
        }
        return $bg_img;
    }
    private function checkShowPageBgSlider($background_settings,$source){
        if($source == 'page' && $background_settings['show_background'] == 'TRUE' && $background_settings['background_type_page'] == 'slider')
            return true;
        return false;
    }
    private function setSectionPageSlider($background_settings, $source){
        if($this->checkShowPageBgSlider($background_settings,$source)){
            $slider['component'] = 'vegas';
            $slider['post_type'] = ['attachment'];
            $slider['taxonomy'] = 'media_category';
            $slider_terms = explode(',',$background_settings['media_category']);
            $slider['terms'] = (!empty($slider_terms)?$slider_terms:['landing']);
            $this->slider = $slider;
        }
    }
    private function setSectionShowcaseSlider(){
        $type = $this->content_settings['slider_type'];
        if($type == 'posts'){
            $slider['component'] = 'superslides';
            $slider['post_type'] = [$this->content_settings['posttype']];
            $slider['taxonomy'] = $this->content_settings['category'];
            $slider['terms'] = explode(',',$this->content_settings['terms']);
            $slider['message'] = '';
            $this->slider = $slider;
        }else{
            $slider['component'] = 'vegas';
            $slider['post_type'] = ['attachment'];
            $slider['taxonomy'] = $this->content_settings['category'];
            $slider['terms'] = explode(',',$this->content_settings['terms']);
            $slider['message'] = (!empty($this->content_settings['message'])?$this->content_settings['message']:ucwords(str_replace('_',' ',$slider['taxonomy'])));
            $this->slider = $slider;
        }
    }
    private function setSectionLayout(){
        $layout['container_class'] = '';
        $layout['container_style'] = 'padding: 0px 15px 0 15px;';
        
        if($this->background['type'] == 'color' || $this->background['type'] == 'none'){
          $layout['content_color'] = 'color:#000000;';
          $layout['title_color'] = 'color:#000000;';
        }
        else{
          $layout['content_color'] = 'color:#FFFFFF;';
          $layout['title_color'] = 'color:#FFFFFF;';
        }
        $layout['title_alignment'] = 'center aligned';
        $layout['title'] = ucwords(str_replace('_',' ',$this->content_settings['category']));
        $layout['subtitle'] = '';
        if($this->source == 'showcase' && $this->content_settings['show_layout'] == 'TRUE'){
            if ($this->content_settings['container'] == 'container') {
                $layout['container_class'] = 'container';
                $layout['container_style'] = '';
            }
            if(!empty($this->content_settings['content_color'] ))
                $layout['content_color'] = 'color:'.$this->content_settings['content_color'].';';
{'fraction_non_alphanumeric': 0.16476234003656307, 'fraction_numerical': 0.0026279707495429614, 'mean_word_length': 2.513649136892814, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7292189', 'n_tokens_mistral': 4702, 'n_tokens_neox': 4545, 'n_words': 656}