<?php
class TFLoadPagePiling_Widget_Free extends \Elementor\Widget_Base {

	public function get_name() {
        return 'tf-load-pagepiling';
    }
    
    public function get_title() {
        return esc_html__( 'TF Page Piling', 'themesflat-elementor' );
    }

    public function get_icon() {
        return 'eicon-document-file';
    }    
    
    public function get_categories() {
        return [ 'themesflat_addons' ];
    }
	
	public function get_style_depends(){
	    return ['jquery-pagepiling-min', 'tf-style'];
	}

    public function get_script_depends() {
    	return ['jquery-pagepiling-min', 'tf-main'];
  	}

	protected function register_controls() {
        // Start Template        
		$this->start_controls_section( 
			'section_load_template',
            [
                'label' => esc_html__('Load Template', 'themesflat-elementor'),
            ]
        );			

		$repeater = new \Elementor\Repeater();
		$repeater->add_control( 
			'list_content_template',
			[
				'label' => esc_html__( 'Template', 'themesflat-elementor' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'options' => ThemesFlat_Addon_For_Elementor::tf_get_template_elementor(),				
			]
		);

		$repeater->add_control(
			'section_id',
			[
				'label' => esc_html__( 'Section id', 'themesflat-elementor' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__( '', 'themesflat-elementor' ),
				'placeholder' => esc_html__( 'home', 'themesflat-elementor' ),
			]
		);

		$repeater->add_control(
			'section_bg_white',
			[
				'label' => esc_html__( 'Section Background White', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Yes', 'your-plugin' ),
				'label_off' => esc_html__( 'No', 'your-plugin' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$this->add_control( 
			'template_list',
			[					
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),					
			]
		);
		
		$this->end_controls_section();
        // /.End Template
	}

	protected function render($instance = []) {
		$settings = $this->get_settings_for_display();	
		?>	
		<div id="pagepiling">
			<?php foreach ($settings['template_list'] as $key => $templates): 
				?>	
				<section <?php echo ($templates['section_id'] != '') ? 'id="'.esc_attr($templates['section_id']).'"' : '' ?> class="section pagepiling-section pp-scrollable <?php echo esc_attr($templates['section_id']); ?> <?php echo ($templates['section_bg_white'] == 'yes') ? 'section-bg-white' : '' ?> " data-pagehash="<?php echo ($templates['section_id'] != '') ? esc_attr($templates['section_id']) : '_'.esc_attr($key) ?>">
					<div class="inner-pagepiling-section">
					<?php 
						if ( !empty($templates['list_content_template']) ) {
				            $post_id = flat_get_post_page_content($templates['list_content_template']);
				            $frontend = new \Elementor\Frontend;
				            echo $frontend->get_builder_content_for_display($post_id, true);	
				        }	
					?>
					</div>
				</section>	
			<?php endforeach;?>	
		</div>		
		<?php	
	}

		

}