<?php
/**
 * Elementor FlipBox Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.5
 */
class Elementor_FlipBox_Widget extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve FlipBox widget name.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'flipbox';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve FlipBox widget title.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'FlipBox', 'endless-addons' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve FlipBox widget icon.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-box';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the FlipBox widget belongs to.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'endless-elements' ];
	}

	/**
	 * Register FlipBox widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function register_controls() {

		$this->start_controls_section(
			'default_section_flipbox',
			[    
				'label' => __( 'Settings', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'show_flipbox',
			[
				'label' => __( 'Show/Hide FlipBox Section', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true
			]
		);

		$this->add_control(
			'show_flipbox_pagination',
			[
				'label' => __( 'Show/Hide Pagination', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'hide',
				'toggle' => true
			]
		);

		$this->add_control(
			'flipbox_style_select',
			[
				'label' => __( 'Select FlipBox Style', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'style-01' => __( 'Style 01', 'endless-addons' ),
					'style-02' => __( 'Style 02', 'endless-addons' ),
					'style-03' => __( 'Style 03', 'endless-addons' ),
					'style-04' => __( 'Style 04', 'endless-addons' ),
					'style-05' => __( 'Style 05', 'endless-addons' ),
					'style-06' => __( 'Style 06', 'endless-addons' ),
					'style-07' => __( 'Style 07', 'endless-addons' )
				],
				'default' => 'style-01'
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'flipbox_top_section',
			[
				'label' => __( 'Flipbox Section', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'flipbox_title',
			[
				'label' => __( 'Section Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Featured Products', 'endless-addons' )
			]
		);

		$this->add_control(
			'flipbox_desc',
			[
				'label' => __( 'Section Description', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
				'input_type' => 'WYSIWYG',
				'placeholder' => __( 'Description', 'endless-addons' ),
				'default' => __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse ultrices gravida.', 'endless-addons')
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'section_background',
				'label' => __( 'Background', 'plugin-domain' ),
				'types' => [ 'classic', 'gradient', 'video' ],
				'selector' => '{{WRAPPER}} .ea-flip-box-area',
			]
		);

        $this->end_controls_section();

		$this->start_controls_section(
			'flipbox_section',
			[
				'label' => __( 'FlipBox Content', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'flipbox_product_category_select',
			[
				'label' => __( 'Sort By Multiple Category', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'yes' => [
						'title' => __( 'Yes', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'no' => [
						'title' => __( 'No', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'no',
				'toggle' => true
			]
		);

		$this->add_control(
			'flipbox_product_category_multiple',
			[
				'label' => __( 'Write Category Name', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Cat-1, Cat-2', 'endless-addons' ),
				'condition' => [
                    'flipbox_product_category_select' => 'yes'
                ]
			]
		);

		$this->add_control(
			'flipbox_product_category_single',
			[
				'label' => __( 'Sort By Category', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'select',
				'options' => endless_addons_get_products_cat_list(),
				'condition' => [
                    'flipbox_product_category_select' => 'no'
                ]
			]
		);

		$this->add_control(
			'flipbox_product_count',
			[
				'label' => __( 'Number of Products', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::NUMBER,
				'input_type' => 'number',
				'default' => __( 12, 'endless-addons' )
			]
		);

		$this->add_control(
			'flipbox_product_column',
			[
				'label' => __( 'Number of columns', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'columns-2' => __( '2', 'endless-addons' ),
					'columns-3' => __( '3', 'endless-addons' ),
					'columns-4' => __( '4', 'endless-addons' )
				],
				'default' => 'columns-3'
			]
		);

		$this->add_control(
			'flipbox_price_style',
			[
				'label' => __( 'Flipbox Price Style', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'default' => __( 'Default', 'endless-addons' ),
					'circle' => __( 'Circle', 'endless-addons' ),
					'box' => __( 'Box', 'endless-addons' )
				],
				'default' => 'default'
			]
		);

		$this->add_control(
			'flipbox_btn_text',
			[
				'label' => __( 'FlipBox Button Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Shop Now', 'endless-addons' )
			]
		);

		$this->add_control(
			'flipbox_btn_link',
			[
				'label' => __( 'FlipBox Button Link', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::URL,
				'input_type' => 'url',
				'default' => [
					'url' => '#',
					'is_external' => true,
					'nofollow' => true
				]
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'section_style',
			[
				'label' => __( 'Section Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'section_title_color',
			[
				'label' => __( 'Section Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .section-title h2' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_title_typography',
                'label' => __( 'Section Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-flip-box-area .section-title h2'
            ]
        );

        $this->add_control(
			'section_desc_color',
			[
				'label' => __( 'Section Description Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .section-title p' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'section_desc_typography',
                'label' => __( 'Section Description Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-flip-box-area .section-title p'
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'flipbox_style',
			[
				'label' => __( 'Flipbox Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'flipbox_title_color',
			[
				'label' => __( 'Flipbox Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-single-flip-box h3, .ea-single-flip-box.style-three .ea-flip-box-back-part .content h3' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'flipbox_title_typography',
                'label' => __( 'Flipbox Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-single-flip-box h3, .ea-single-flip-box.style-three .ea-flip-box-back-part .content h3'
            ]
        );

        $this->add_control(
			'flipbox_price_color',
			[
				'label' => __( 'Flipbox Price Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-single-flip-box span, .ea-single-flip-box .price, .ea-single-flip-box span .price' => 'color: {{VALUE}}'
                ],
                'condition' => [
                    'flipbox_style_select' => array('style-02', 'style-03', 'style-05', 'style-06', 'style-07')
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'flipbox_price_typography',
                'label' => __( 'Flipbox Price Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-single-flip-box span, .ea-single-flip-box .price, .ea-single-flip-box span .price',
                'condition' => [
                    'flipbox_style_select' => array('style-02', 'style-03', 'style-05', 'style-06', 'style-07')
                ]
            ]
        );

        $this->add_control(
			'flipbox_img_height',
			[
				'label' => __( 'Flipbox Image Height', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-flip-box-area .ea-single-flip-box img' => 'height: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->add_control(
			'flipbox_img_width',
			[
				'label' => __( 'Flipbox Image Width', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-flip-box-area .ea-single-flip-box img' => 'width: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'card_button_style',
			[
				'label' => __( 'Button Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'card_button_typography',
                'label' => __( 'Card Button/Link Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-flip-box-area .link-btn'
            ],
        );

        $this->add_control(
			'button_bg_color',
			[
				'label' => __( 'Button Background Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .link-btn' => 'background: {{VALUE}}'
                ],
                'condition' => [
                    'flipbox_style_select' => array('style-01', 'style-03', 'style-05', 'style-06')
                ]
			]
		);

		$this->add_control(
			'button_color',
			[
				'label' => __( 'Button Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .link-btn' => 'color: {{VALUE}}'
                ],
			]
		);

		$this->add_control(
			'button_bg_hover_color',
			[
				'label' => __( 'Button Background Hover Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .link-btn:hover' => 'background: {{VALUE}}'
                ],
                'condition' => [
                    'flipbox_style_select' => array('style-01', 'style-03', 'style-05', 'style-06')
                ]
			]
		);

		$this->add_control(
			'button_hover_color',
			[
				'label' => __( 'Button Hover Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-flip-box-area .link-btn:hover' => 'color: {{VALUE}}'
                ],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'_section_overlay_style',
			[
				'label' => __('Background Overlay', 'endless-addons'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
                    'flipbox_style_select' => array('style-01', 'style-03', 'style-05', 'style-06')
                ]
			]
		);

		$this->start_controls_tabs('_tabs_overlay_style');

		$this->start_controls_tab(
			'_tab_overlay_normal',
			[
				'label' => __('Normal', 'endless-addons'),
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_normal',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-flip-box-area',
			]
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'_tab_overlay_hover',
			[
				'label' => __('Hover', 'endless-addons'),
			]
		);


		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_hover',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-flip-box-area:hover',
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();

	}

	/**
	 * Render FlipBox widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function render() {

		$settings = $this->get_settings_for_display();

		$target = $settings['flipbox_btn_link']['is_external'] ? ' target="_blank"' : '';
	    $nofollow = $settings['flipbox_btn_link']['nofollow'] ? ' rel="nofollow"' : ''; ?>

        <!-- Start FlipBox Area -->
        <?php if( $settings['show_flipbox'] == 'show' ) :

        	if( $settings['flipbox_product_category_select'] == 'no' ) :
        		$endless_addons_cat_type = $settings['flipbox_product_category_single'];
            elseif( $settings['flipbox_product_category_select'] == 'yes' ) :
                $endless_addons_cat_type = $settings['flipbox_product_category_multiple'];
            endif;

        	global $paged;
        	$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
			$endless_addons_args = array(
				'post_type' => 'product',
				'posts_per_page' => $settings['flipbox_product_count'],
				'order' => 'DESC',
				'product_cat' => $endless_addons_cat_type,
				'paged' => $paged
			);
			$endless_addons_loop = new WP_Query( $endless_addons_args );

			include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
			if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
				return 'Please Install and Activate WooCommerce.';
			} 

			// Flipbox column style
		    if( $settings['flipbox_product_column'] == 'columns-2' ) : 
		    	$flipbox_column = 'col-lg-6 col-md-6 col-sm-6'; ?>
			<?php elseif( $settings['flipbox_product_column'] == 'columns-3' ) : 
				$flipbox_column = 'col-lg-4 col-md-6 col-sm-6'; ?>
			<?php elseif( $settings['flipbox_product_column'] == 'columns-4' ) : 
				$flipbox_column = 'col-lg-3 col-md-6 col-sm-6'; ?>
			<?php endif;

			if ( $endless_addons_loop->have_posts() ) {
		        if( $settings['flipbox_style_select'] == 'style-01' ) : ?>
			        <div class="ea-flip-box-area pb-70">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>                          
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-one">
				                            <div class="ea-flip-box-front-part">
				                            	<?php the_post_thumbnail(); ?>
				                                <a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
				                            </div>
				                            <div class="ea-flip-box-back-part">
				                                <div class="d-table">
				                                    <div class="d-table-cell">
				                                    	<a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
						                                <?php global $product;
						                                global $post;
														$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
						                                echo wp_kses_post($short_description);
														if( ! $settings['flipbox_btn_text'] == '' ) : ?>
							                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
							                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
							                                </a>
						                                <?php endif; ?>
						                            </div>
						                        </div>
						                    </div>
				                        </div>
				                    </div>
				                <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['flipbox_style_select'] == 'style-02' ) : ?>
			    	<div class="ea-flip-box-area pb-70 pt-100 bg-f9f9f9">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-two">
				                        	<div class="ea-flip-box-front-part">
				                                <?php the_post_thumbnail(); ?>
				                                <a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
				                            </div>
				                            <div class="ea-flip-box-back-part">
				                                <div class="d-table">
				                                    <div class="d-table-cell">
						                                <?php global $product;
						                                global $post;
														$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
						                                 echo wp_kses_post($short_description);
						                                if ( $price_html = $product->get_price_html() ) : ?>
															<p class="price">
																<?php echo wp_kses_post( $price_html ); ?>
															</p>
														<?php endif;
														if( ! $settings['flipbox_btn_text'] == '' ) : ?>
							                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
							                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
							                                </a>
						                                <?php endif; ?>
				                                    </div>
				                                </div>
				                            </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['flipbox_style_select'] == 'style-03' ) : ?>
			    	<div class="ea-flip-box-area pb-70 pt-100">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-three">
				                        	<div class="ea-flip-box-front-part">
					                            <div class="row m-0">
					                                <div class="col-lg-8 col-md-8 p-0">
							                            <div class="content">
                                                        	<a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>">
								                            	<h3>
								                                	<?php the_title(); ?>
								                                </h3>
							                                </a>
							                                <?php global $post;
															$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
							                                 echo wp_kses_post($short_description); ?>
					                                    </div>
													</div>
													<div class="col-lg-4 col-md-4 p-0">
                                                        <div class="image bg1" style="background-image: url(<?php the_post_thumbnail_url(); ?>);">
                                                        	<?php the_post_thumbnail(); ?>
                                                        </div>
                                                    </div>
	                                            </div>
	                                        </div>
                                            <div class="ea-flip-box-back-part">
				                                <div class="row m-0">
				                                    <div class="col-lg-4 col-md-4 p-0">
				                                        <div class="image bg1" style="background-image: url(<?php the_post_thumbnail_url(); ?>);">
					                                        <?php the_post_thumbnail(); ?>  
					                                    </div>
					                                </div>      
					                                <div class="col-lg-8 col-md-8 p-0">
                                                        <div class="content">
                                                        	<?php global $product;
							                                if ( $price_html = $product->get_price_html() ) : ?>
																<span class="price">
																	<?php echo wp_kses_post( $price_html ); ?>
																</span>
															<?php endif; ?>
                                                        	<a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>">
								                            	<h3>
								                                	<?php the_title(); ?>
								                                </h3>
							                                </a>
							                                <?php global $post;
															$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
							                                 echo wp_kses_post($short_description);
							                                if( ! $settings['flipbox_btn_text'] == '' ) : ?>
								                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
								                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
								                                </a>
							                                <?php endif; ?>
					                                    </div>
			                                        </div>
			                                    </div>
			                                </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['flipbox_style_select'] == 'style-04' ) : ?>
			    	<div class="ea-flip-box-area pb-70 pt-100 bg-gradient-color">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?>
			                    </p>
			                </div>
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-four">
				                            <?php the_post_thumbnail(); ?>
				                            <div class="content">
				                                <a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
				                                <?php global $product;
				                                global $post;
												$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
				                                 echo wp_kses_post($short_description);
				                                if ( $price_html = $product->get_price_html() ) : ?>
													<p class="price">
														<?php echo wp_kses_post( $price_html ); ?>
													</p>
												<?php endif; 
												if( ! $settings['flipbox_btn_text'] == '' ) : ?>
					                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
					                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
					                                </a>
				                                <?php endif; ?>
				                            </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['flipbox_style_select'] == 'style-05' ) : ?>
			    	<div class="ea-flip-box-area pb-70 pt-100">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-five">
				                        	<div class="ea-flip-box-front-part">
				                                <?php the_post_thumbnail(); ?>
				                            </div>
				                            <div class="ea-flip-box-back-part">
				                                <div class="d-table">
				                                    <div class="d-table-cell">
						                                <a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
						                                <?php global $post;
														$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); 
						                                 echo wp_kses_post($short_description);
						                                global $product;
						                                if ( $price_html = $product->get_price_html() ) : ?>
															<p class="price">
																<?php echo wp_kses_post( $price_html ); ?>
															</p>
														<?php endif; 
														if( ! $settings['flipbox_btn_text'] == '' ) : ?>
							                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
							                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
							                                </a>
						                                <?php endif; ?>
						                            </div>
						                        </div>
						                    </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
		        <?php elseif( $settings['flipbox_style_select'] == 'style-06' ) : ?>
		        	<div class="ea-flip-box-area pb-70 pt-100 bg-image">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>
			                <div class="flipbox-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?>">
				                        <div class="ea-single-flip-box style-six">
				                        	<div class="ea-flip-box-front-part">
				                        	    <?php the_post_thumbnail(); ?>
				                            </div>
				                            <div class="ea-flip-box-back-part">
				                                <div class="d-table">
				                                    <div class="d-table-cell">
						                                <?php global $product;
						                                if ( $price_html = $product->get_price_html() ) : ?>
															<span class="price">
																<?php echo wp_kses_post( $price_html ); ?>
															</span>
														<?php endif; ?>
														<a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h3><?php the_title(); ?></h3></a>
						                                <?php if( ! $settings['flipbox_btn_text'] == '' ) : ?>
							                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
							                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
							                                </a>
						                                <?php endif; ?>
						                            </div>
						                        </div>
				                            </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['flipbox_style_select'] == 'style-07' ) : ?>
			    	<div class="ea-flip-box-area pt-100 bg-shape">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['flipbox_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['flipbox_desc']); ?></p>
			                </div>
			                <div class="flipbox-row row justify-content-center m-0">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="flipbox-col <?php echo esc_attr( $flipbox_column ); ?> p-0">
				                        <div class="ea-single-flip-box style-seven">
				                        	<div class="ea-flip-box-front-part">
				                                <?php the_post_thumbnail(); ?>
				                            </div>
				                            <div class="ea-flip-box-back-part">
				                                <div class="d-table">
				                                    <div class="d-table-cell">
							                            <a class="flipbox-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>">
							                            <h3><?php the_title(); ?></h3></a><br/>
							                            <?php global $product;
						                                if ( $price_html = $product->get_price_html() ) : ?>
															<span class="price">
																<?php echo wp_kses_post( $price_html ); ?>
															</span>
														<?php endif; 
														if( ! $settings['flipbox_btn_text'] == '' ) : ?>
							                                <a href="<?php echo esc_url($settings['flipbox_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn">
							                                	<?php echo esc_html__($settings['flipbox_btn_text']); ?>
							                                </a>
						                                <?php endif; ?>
							                        </div>
							                    </div>
							                </div>
				                        </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php endif;
			    $total_pages = $endless_addons_loop->max_num_pages;
                $total   = isset( $total ) ? $total : wc_get_loop_prop( 'total_pages' );
		        $current = isset( $current ) ? $current : wc_get_loop_prop( 'current_page' );
		    	$base    = isset( $base ) ? $base : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
		        $format  = isset( $format ) ? $format : '';
		        if( $settings['show_flipbox_pagination'] == 'show' ) : ?>
	                <nav class="card-nav d-flex justify-content-center">
		                <?php 								        
					        $current_page = max(1, get_query_var('paged'));
	                        previous_posts_link( '&laquo; PREV', $endless_addons_loop->max_num_pages);
					        echo paginate_links(array(
					            'base'      => $base,
								'format'    => $format,
								'add_args'  => false,
					            'current'   => max( 1, $current ),
					            'total'     => $total_pages,
					            'prev_text' => false,
								'next_text' => false,
								'end_size'  => 3,
		                        'mid_size'  => 3
					        ));
					        next_posts_link( 'NEXT &raquo;', $endless_addons_loop->max_num_pages); 
					    ?>
				    </nav>
			    <?php endif;
			} 
			else {
				echo wp_kses_post( '<h2 class="product-empty-message">'.'No products found'.'</h2>', 'endless-addons' );
			}

			wp_reset_postdata();

	    endif; ?>
	    <!-- End FlipBox Area -->
        
    <?php
        
	}
	
}
