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

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

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

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

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

	/**
	 * Register Card 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',
			[    
				'label' => __( 'Settings', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'show_card',
			[
				'label' => __( 'Show/Hide Card 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_card_pagination',
			[
				'label' => __( 'Show/Hide Product 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(
			'card_style_select',
			[
				'label' => __( 'Select Card 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(
			'card_section',
			[
				'label' => __( 'Card Section', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

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

		$this->add_control(
			'card_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-card-area',
			]
		);

        $this->end_controls_section();

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

		$this->add_control(
            'card_title_alignment',
            [
                'label' => esc_html__('Card Title Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ]
                ]
            ]
        );

        $this->add_control(
            'card_desc_alignment',
            [
                'label' => esc_html__('Card Description Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ]
                ],
                'condition' => [
                    'card_style_select' => array('style-01', 'style-02', 'style-03', 'style-04', 'style-05')
                ]
            ]
        );

        $this->add_control(
            'card_price_alignment',
            [
                'label' => esc_html__('Card Price Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ]
                ],
                'condition' => [
                    'card_style_select' => array('style-02', 'style-03')
                ]
            ]
        );

        $this->add_control(
            'card_btn_alignment',
            [
                'label' => esc_html__('Card Button Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ]
                ],
                'condition' => [
                    'card_style_select' => array('style-01', 'style-02', 'style-05')
                ]
            ]
        );

        $this->add_control(
            'card_img_alignment',
            [
                'label' => esc_html__('Card Image Alignment', 'endless-addons'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label_block' => true,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'endless-addons'),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'endless-addons'),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'endless-addons'),
                        'icon' => 'fa fa-align-right',
                    ]
                ]
            ]
        );

		$this->add_control(
			'card_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(
			'card_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' => [
                    'card_product_category_select' => 'yes'
                ]
			]
		);

		$this->add_control(
			'card_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' => [
                    'card_product_category_select' => 'no'
                ]
			]
		);

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

		$this->add_control(
			'card_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(
			'card_btn_text',
			[
				'label' => __( 'Card Button Text', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Text', 'endless-addons' ),
				'default' => __( 'Shop Now', 'endless-addons' )
			]
		);

		$this->add_control(
			'card_btn_link',
			[
				'label' => __( 'Card 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-card-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-card-area .section-title h2'
            ]
        );

        $this->add_control(
			'section_desc_color',
			[
				'label' => __( 'Section Description Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-card-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-card-area .section-title p'
            ]
        );

		$this->end_controls_section();

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

		$this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name'     => 'ea_card_border',
                'selector' => '{{WRAPPER}} .ea-single-card-box',
            ]
        );

        $this->add_control(
            'card_border_radius',
            [
                'label' => __( 'Border Radius', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'separator' => 'after',
                'selectors' => [
                    '{{WRAPPER}} .ea-single-card-box' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

		$this->add_control(
			'card_title_color',
			[
				'label' => __( 'Card Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-single-card-box h3, .ea-single-card-box h6, .ea-single-card-box.style-six .content h6, .ea-single-card-box.style-seven h3' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'card_title_typography',
                'label' => __( 'Card Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-single-card-box h3, .ea-single-card-box h6, .ea-single-card-box.style-six .content h6, .ea-single-card-box.style-seven h3'
            ]
        );

        $this->add_control(
			'card_desc_color',
			[
				'label' => __( 'Card Description Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-single-card-box p' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'card_desc_typography',
                'label' => __( 'Card Description Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-single-card-box p'
            ]
        );

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

		$this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name'     => 'ea_card_price_border',
                'selector' => '{{WRAPPER}} .ea-single-card-box.style-two .content .price, .ea-single-card-box.style-three .content .price, .ea-single-card-box.style-four .content .price',
                'condition' => [
                    'card_style_select' => array('style-02', 'style-03', 'style-04')
                ]
            ]
        );

        $this->add_control(
            'ea_card_price_border_radius',
            [
                'label' => __( 'Price Border Radius', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'separator' => 'after',
                'selectors' => [
                    '{{WRAPPER}} .ea-single-card-box.style-two .content .price, .ea-single-card-box.style-three .content .price, .ea-single-card-box.style-four .content .price' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'condition' => [
                    'card_style_select' => array('style-02', 'style-03', 'style-04', 'style-06', 'style-07')
                ]
            ]
        );

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

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

		$this->add_control(
			'card_img_width',
			[
				'label' => __( 'Card Image Width', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-card-area .ea-single-card-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-card-area .link-btn'
            ],
        );

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

		$this->add_control(
			'button_color',
			[
				'label' => __( 'Button Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-card-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-card-area .link-btn:hover' => 'background: {{VALUE}}'
                ],
                'condition' => [
                    'card_style_select' => array('style-03', 'style-04')
                ]
			]
		);

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

		$this->end_controls_section();

		$this->start_controls_section(
			'parallax_style',
			[
				'label' => __( 'Background Parallax', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
                    'card_style_select' => 'style-06'
               ]
			]
		);

		$this->add_control(
			'enable_parallax',
			[
				'label' => __( 'Enable Parallax', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => __( 'Yes', 'endless-addons' ),
				'label_off' => __( 'No', 'endless-addons' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$this->end_controls_section();

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

		$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-card-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-card-area:hover',
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();

	}

	/**
	 * Render Card 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(); 

		if( $settings['card_title_alignment'] == 'left' ) : 
		    $this->add_render_attribute('card_title_align', 'class', 'is-title-left');
		elseif( $settings['card_title_alignment'] == 'center' ) :
            $this->add_render_attribute('card_title_align', 'class', 'is-title-center');
		elseif( $settings['card_title_alignment'] == 'right' ) :
            $this->add_render_attribute('card_title_align', 'class', 'is-title-right');
        endif;

        if( $settings['card_desc_alignment'] == 'left' ) : 
		    $this->add_render_attribute('card_desc_align', 'class', 'is-desc-left');
		elseif( $settings['card_desc_alignment'] == 'center' ) :
            $this->add_render_attribute('card_desc_align', 'class', 'is-desc-center');
		elseif( $settings['card_desc_alignment'] == 'right' ) :
            $this->add_render_attribute('card_desc_align', 'class', 'is-desc-right');
        endif;

        if( $settings['card_price_alignment'] == 'left' ) : 
		    $this->add_render_attribute('card_price_align', 'class', 'is-price-left');
		elseif( $settings['card_price_alignment'] == 'center' ) :
            $this->add_render_attribute('card_price_align', 'class', 'is-price-center');
		elseif( $settings['card_price_alignment'] == 'right' ) :
            $this->add_render_attribute('card_price_align', 'class', 'is-price-right');
        endif; 

        if( $settings['card_btn_alignment'] == 'left' ) : 
		    $this->add_render_attribute('card_btn_align', 'class', 'is-btn-left');
		elseif( $settings['card_btn_alignment'] == 'center' ) :
            $this->add_render_attribute('card_btn_align', 'class', 'is-btn-center');
		elseif( $settings['card_btn_alignment'] == 'right' ) :
            $this->add_render_attribute('card_btn_align', 'class', 'is-btn-right');
        endif; 

        if( $settings['card_img_alignment'] == 'left' ) : 
		    $this->add_render_attribute('card_img_align', 'class', 'is-img-left');
		elseif( $settings['card_img_alignment'] == 'center' ) :
            $this->add_render_attribute('card_img_align', 'class', 'is-img-center');
		elseif( $settings['card_img_alignment'] == 'right' ) :
            $this->add_render_attribute('card_img_align', 'class', 'is-img-right');
        endif;  

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

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

        	if( $settings['card_product_category_select'] == 'no' ) :
        		$endless_addons_cat_type = $settings['card_product_category_single'];
            elseif( $settings['card_product_category_select'] == 'yes' ) :
                $endless_addons_cat_type = $settings['card_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['card_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.';
			} 
            
            // Card column style
		    if( $settings['card_product_column'] == 'columns-2' ) : 
		    	$card_column = 'col-lg-6 col-md-6 col-sm-6'; ?>
			<?php elseif( $settings['card_product_column'] == 'columns-3' ) : 
				$card_column = 'col-lg-4 col-md-6 col-sm-6'; ?>
			<?php elseif( $settings['card_product_column'] == 'columns-4' ) : 
				$card_column = 'col-lg-3 col-md-6 col-sm-6'; ?>
			<?php endif;

			if ( $endless_addons_loop->have_posts() ) {
		        if( $settings['card_style_select'] == 'style-01' ) : ?>
			        <div class="ea-card-area pb-70">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>                          
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
								    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
								    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
								    	<div <?php echo $this->get_render_attribute_string('card_desc_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_btn_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-one">
					                            <?php the_post_thumbnail(); ?>
					                            <div class="content">
					                                <a class="card-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['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
												    <?php endif; ?>
					                            </div>
					                        </div>
								        </div>
								        </div>
							            </div>
							            </div>
					                </div>
				                <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['card_style_select'] == 'style-02' ) : ?>
			    	<div class="ea-card-area pt-100 pb-70 bg-f9f9f9">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
								    	<div <?php echo $this->get_render_attribute_string('card_desc_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_price_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_btn_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-two">
					                            <?php the_post_thumbnail(); ?>
					                            <div class="content">
					                                <a class="card-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() ) : ?>
														<span class="price">
															<?php echo wp_kses_post( $price_html ); ?>
														</span>
													<?php endif; 
													if( ! $settings['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
												    <?php endif; ?>
					                            </div>
					                        </div>
				                        </div>
								        </div>
							            </div>
							            </div>
							            </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['card_style_select'] == 'style-03' ) : ?>
			    	<div class="ea-card-area pt-100 pb-70">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
								    	<div <?php echo $this->get_render_attribute_string('card_desc_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_price_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-three">
					                            <div class="row m-0">
					                                <div class="col-lg-8 col-md-8 col-sm-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="card-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['card_btn_text'] == '' ) : ?>
																<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
														    <?php endif; ?>
							                            </div>
					                                </div>
					                                <div class="col-lg-4 col-md-4 col-sm-4 p-0">
					                                    <div class="image bg1">
					                                        <?php the_post_thumbnail(); ?>
					                                    </div>
					                                </div>
					                            </div>
					                        </div>
				                        </div>
								        </div>
							            </div>
							            </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['card_style_select'] == 'style-04' ) : ?>
			    	<div class="ea-card-area pt-100 pb-70 bg-242424">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
								    	<div <?php echo $this->get_render_attribute_string('card_desc_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-four">
					                            <?php the_post_thumbnail(); ?>
					                            <div class="content">
					                                <a class="card-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['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
												    <?php endif; ?>
					                            </div>
					                        </div>
								        </div>
							            </div>
							            </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			    <?php elseif( $settings['card_style_select'] == 'style-05' ) : ?>
			    	<div class="ea-card-area pt-100 pb-70">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
								    	<div <?php echo $this->get_render_attribute_string('card_desc_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_btn_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-five">
					                            <?php the_post_thumbnail(); ?>
					                            <div class="content">
					                                <a class="card-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['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
												    <?php endif; ?>
					                            </div>
					                        </div>
					                    </div>
								        </div>
							            </div>
							            </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
		        <?php elseif( $settings['card_style_select'] == 'style-06' ) : ?>
		        	<div class="ea-card-area bg-image pt-100 pb-70">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?>">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-six">
					                        	<?php the_post_thumbnail(); ?>
					                            <div class="content">
					                                <a class="card-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>"><h6><?php the_title(); ?></h6></a>
					                                <?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['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_btn_text']); ?></a>
												    <?php endif; ?>
					                            </div>
					                        </div>
								        </div>
							            </div>
				                    </div>
			                    <?php endwhile; ?>
			                </div>
			            </div>
			        </div>
			        <?php if($settings['enable_parallax'] == 'yes' ){ ?>
				    	<style>
				    		.ea-card-area.bg-image {
				    			background-attachment: fixed;
				    		}
				    	</style>
				    <?php } ?>
			    <?php elseif( $settings['card_style_select'] == 'style-07' ) : ?>
			    	<div class="ea-card-area pt-100 bg-shape">
			            <div class="container">
			                <div class="section-title">
			                    <h2><?php echo esc_html__($settings['card_title']); ?></h2>
			                    <p><?php echo wp_kses_post($settings['card_desc']); ?></p>
			                </div>
			                <div class="card-row row justify-content-center m-0">
			                	<?php while ( $endless_addons_loop->have_posts() ) : $endless_addons_loop->the_post(); ?>
				                    <div class="card-col <?php echo esc_attr( $card_column ); ?> p-0">
				                    	<div <?php echo $this->get_render_attribute_string('card_title_align'); ?>>
			                			<div <?php echo $this->get_render_attribute_string('card_img_align'); ?>>
					                        <div class="ea-single-card-box style-seven">
					                            <?php the_post_thumbnail(); ?>
					                            <a class="card-product-title" href="<?php echo get_permalink( $endless_addons_loop->post->ID ) ?>">
					                            <h3><?php the_title(); ?></h3></a>
					                            <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; 
													if( ! $settings['card_btn_text'] == '' ) : ?>
														<a href="<?php echo esc_url($settings['card_btn_link']['url']); ?>" <?php echo wp_kses_post( $target ); ?> <?php echo wp_kses_post( $nofollow ); ?> class="link-btn"><?php echo esc_html__($settings['card_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_card_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 Card Area -->

    <?php

    }

}
