<?php
/** 
 * Elementor Banner slider one
 * @since 1.0.0
*/
class Banner_slider__o extends \Elementor\Widget_Base {
    public function get_name() {
        return 'banner_slider__o';
    }
    public function get_title(){
        return esc_html__( 'Banner Slider one', 'plugin-name' );
    }
    public function get_icon(){
        return 'fa fa-object-ungroup';
    }
    public function get_categories(){
        return [ 'dexencore' ];
    }
    protected function _register_controls() {
        $this->start_controls_section(
            'banner_slider_content',
            [
                'label' => esc_html__( 'Banner Slider Content', 'plugin-name' ),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'banner_slider_style',
			[
				'label' => esc_html__( 'Banner Slider Designs', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'style-one',
				'options' => [
					'style-one'  => esc_html__( 'One', 'plugin-domain' ),
					'style-two'  => esc_html__( 'Two', 'plugin-domain' ),
				],
			]
		);
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
            'slider_background_images', [
                'label' => __( 'Background image', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );
        $repeater->add_control(
            'content_images', [
                'label' => __( 'Content image', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );
        $repeater->add_control(
			'text_align',
			[
				'label' => __( 'Alignment', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'left' => [
						'title' => __( 'Left', 'plugin-domain' ),
						'icon' => 'fa fa-align-left',
					],
					'center' => [
						'title' => __( 'Center', 'plugin-domain' ),
						'icon' => 'fa fa-align-center',
					],
					'justify' => [
						'title' => __( 'Justify', 'plugin-domain' ),
						'icon' => 'fa fa-align-justify',
					],
				],
				'default' => 'center',
				'toggle' => true,
			]
		);

        $repeater->add_control(
            'banner_tagline',
            [
				'label' => esc_html__( 'Banner Tag Line', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Welcome to Dexen Company' ),
				'placeholder' => esc_html__( 'Type your content here', 'plugin-domain' ),
			]
        );
        $repeater->add_control(
            'banner_title',
            [
				'label' => esc_html__( 'Banner Title', 'plugin-domain' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Trusted Printing <br> & Copy Center' ),
				'placeholder' => esc_html__( 'Type your content here', 'plugin-domain' ),
			]
        );
        $repeater->add_control(
            'banner_content',
            [
                'label' => esc_html__( 'Banner content', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::WYSIWYG,
                'default' => __( 'Design helps us to stand out, It tells a story <br> about us and what we stand for. ', 'plugin-domain' ),
                'placeholder' => esc_html__( 'Type your content here', 'plugin-domain' ),
            ]
        );
        $repeater->add_control(
            'button_text',
            [
                'label' => esc_html__( 'Button Title', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => __( 'Order Online Now', 'plugin-domain' ),
                'placeholder' => esc_html__( 'Type your content here', 'plugin-domain' ),
            ]
        );
        $repeater->add_control(
            'button_text_link', [
                'label' => esc_html__( 'Button link', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::URL,
                'show_external' => true,
                'default' => [
                    'url' => '',
                    'is_external' => true,
                    'nofollow' => true,
                ],
            ]
        );
        $this->add_control(
            'slider_list', [
                'label' => esc_html__( 'Slider list', 'plugin-domain' ),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
            ]
        );
        $this->end_controls_section();
    }
    protected function render() {
        $settings = $this->get_settings_for_display();
        $banner_slider_style = $settings['banner_slider_style'];
        $slider_list = $settings['slider_list'];

        $slider_btn_class = 'banner-btn';
        $slider_row_class ='';
        $slider_text_class = 'left';
        $slider_column_class = '12';


        $slide_class = 'one';


        ?>

    <div class="main-banner-wrapper">
            <section class="banner-<?php echo esc_attr($banner_slider_style); ?> owl-theme owl-carousel">
            <?php if( $slider_list ) : ?>
                <?php foreach ( $slider_list as $item ) { 
                    
                    if( ($banner_slider_style == 'style-two') && ($item['text_align']=='justify')) {
                        $slider_text_class = '';
                        $slider_row_class = 'justify-content-end';
                        $slide_column_class = '7';
                        $slide_class = 'two';

                    }else{
                        $slider_text_class = '';
                        $slider_row_class = '';
                        $slide_column_class = '12';
                        $slide_class = 'one';
                    }
            
                  
                    ?>
                <div class="slide slide-<?php echo wp_kses_post($slide_class); ?>" style="background-image: url(<?php echo esc_url($item['slider_background_images']['url']); ?>);">


                        <!-- style -1-->
                        <?php if($banner_slider_style == 'style-one') :?>
                        <div class="container">
                        <div class="row <?php echo wp_kses_post($slider_row_class); ?>">
                            <div class="col-lg-12 text-<?php echo wp_kses_post($slider_text_class); ?>">
                                <span class="tag-line"><?php echo wp_kses_post($item['banner_tagline']); ?></span>
                                <h3 class="banner-title"><?php echo wp_kses_post($item['banner_title']); ?></h3>
                                <p><?php echo wp_kses_post($item['banner_content']); ?></p>
                                <?php if(!empty($item['button_text_link']['url'])) :?>
                                <div class="btn-block">
                                    <a 
                                                    class="theme-btn <?php echo esc_attr($slider_btn_class); ?>"
                                                    href="<?php echo esc_url($item['button_text_link']['url']); ?>"
                                                    <?php
                                                        $target = $item['button_text_link']['is_external'] ? ' target=_blank' : '';
                                                        $nofollow = $item['button_text_link']['nofollow'] ? ' rel=nofollow' : '';
                                                        echo esc_attr($target . $nofollow);
                                                    ?>><?php echo wp_kses_post($item['button_text']); ?>
                                    </a>   
                                </div> <!-- /.btn-block -->
                                <?php endif;?>
                            </div><!-- /.col-lg-12 -->
                            </div><!-- /.row -->
                        </div><!-- /.container -->
                            <!-- style -1-->
                            <?php else :?>
                        <img src="<?php echo esc_url($item['content_images']['url']); ?>"  class="slider-moc" />
                        <div class="container">
                        <div class="row <?php echo wp_kses_post($slider_row_class); ?>">
                               <div class="col-lg-<?php echo wp_kses_post($slide_column_class); ?> text-<?php echo wp_kses_post($slider_text_class); ?>">
                                <span class="tag-line"><?php echo wp_kses_post($item['banner_tagline']); ?></span>
                                <h3 class="banner-title"><?php echo wp_kses_post($item['banner_title']); ?></h3>
                                <p><?php echo wp_kses_post($item['banner_content']); ?></p>
                                <?php if(!empty($item['button_text_link']['url'])) :?>
                                <div class="btn-block">
                                    <a 
                                                    class="theme-btn <?php echo esc_attr($slider_btn_class); ?>"
                                                    href="<?php echo esc_url($item['button_text_link']['url']); ?>"
                                                    <?php
                                                        $target = $item['button_text_link']['is_external'] ? ' target=_blank' : '';
                                                        $nofollow = $item['button_text_link']['nofollow'] ? ' rel=nofollow' : '';
                                                        echo esc_attr($target . $nofollow);
                                                    ?>><?php echo wp_kses_post($item['button_text']); ?>
                                    </a>   
                                </div> <!-- /.btn-block -->
                                <?php endif;?>
                            </div><!-- /.col-lg-12 -->
                            </div><!-- /.row -->
                        </div><!-- /.container -->
                        <?php endif;?>
          
                </div><!-- /.slide -->
                <?php } ?>
            <?php endif; ?>
            </section><!-- /.banner-style-one -->
            <div class="carousel-btn-block banner-carousel-btn">
                <span class="carousel-btn left-btn"><i class="dexen-icon-music-player-play"></i></span>
                <span class="carousel-btn right-btn"><i class="dexen-icon-music-player-play"></i></span>
            </div><!-- /.carousel-btn-block banner-carousel-btn -->
        </div><!-- /.main-banner-wrapper -->
        <?php
    }
}

\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Banner_slider__o() );