<?php
if ( ! class_exists( 'Draly_Dropshipping_Starter_Elementor_Products' ) ) {
	class Draly_Dropshipping_Starter_Elementor_Products extends Draly_Dropshipping_Starter_Elementor {
		public $name = 'products';
		public $title = 'Products';
		public $icon = 'eicon-products';

		/**
		 * Register the widget controls.
		 *
		 * Adds different input fields to allow the user to change and customize the widget settings.
		 *
		 * @since 1.0.0
		 *
		 * @access protected
		 */
		protected function register_controls() {
			//General Section
			$this->start_controls_section(
				'general_section',
				[
					'label' => esc_html__( 'General', 'draly-dropshipping-starter' ),
				]
			);
			$layoutDir = get_template_directory() . '/woocommerce/product-styles/';
			$options   = array();
			if ( is_dir( $layoutDir ) ) {
				$files = scandir( $layoutDir );
				if ( $files && is_array( $files ) ) {
					foreach ( $files as $file ) {
						if ( $file != '.' && $file != '..' ) {
							$fileInfo = pathinfo( $file );
							if ( $fileInfo['extension'] == 'php' && $fileInfo['basename'] != 'index.php') {
								$file_data             = get_file_data( $layoutDir . $file, array( 'Name' => 'Name' ) );
								$file_name             = str_replace( 'content-product-', '', $fileInfo['filename'] );
								$options[ $file_name ] = $file_data['Name'];
							}
						}
					}
				}
			}
			$this->add_control(
				'style',
				[
					'label'       => esc_html__( 'Style', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => $options,
					'default'     => 'style-01',
					'label_block' => true
				]
			);
			$this->add_control(
				'product_image_size',
				[
					'label'       => esc_html__( 'Image size', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => Draly_Dropshipping_Starter_Elementor::draly_dropshipping_starter_elementor_size(),
					'description' => esc_html__( 'Select a size for product', 'draly-dropshipping-starter' ),
					'label_block' => true

				]
			);
			$this->add_control(
				'product_custom_thumb_width',
				[
					'label'       => esc_html__( 'Width', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'default'     => 300,
					'description' => esc_html__( 'Unit px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'product_image_size' => 'custom'
					),
				]
			);
			$this->add_control(
				'product_custom_thumb_height',
				[
					'label'       => esc_html__( 'Height', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'default'     => 300,
					'description' => esc_html__( 'Unit px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'product_image_size' => 'custom'
					),
				]
			);
			$this->add_control(
				'target',
				[
					'label'       => esc_html__( 'Target', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'recent-product'    => esc_html__( 'Recent Products', 'draly-dropshipping-starter' ),
						'best-selling'      => esc_html__( 'Best Selling Products', 'draly-dropshipping-starter' ),
						'top-rated'         => esc_html__( 'Top Rated Products', 'draly-dropshipping-starter' ),
						'product-category'  => esc_html__( 'Product Category', 'draly-dropshipping-starter' ),
						'featured_products' => esc_html__( 'Featured Products', 'draly-dropshipping-starter' ),
						'on_sale'           => esc_html__( 'On Sale', 'draly-dropshipping-starter' ),
						'on_new'            => esc_html__( 'On New', 'draly-dropshipping-starter' ),
						'products'          => esc_html__( 'Products', 'draly-dropshipping-starter' ),
					],
					'default'     => 'recent-product',
					'description' => esc_html__( 'Choose the target to filter products', 'draly-dropshipping-starter' ),
					'label_block' => true

				]
			);
			$this->add_control(
				'taxonomy', [
					'label'       => esc_html__( 'Product Category', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT2,
					'multiple'    => true,
					'options'     => Draly_Dropshipping_Starter_Elementor::draly_dropshipping_starter_elementor_taxonomy(),
					'description' => esc_html__( 'Note: If you want to narrow output, select category(s) above. Only selected categories will be displayed.', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'target' => array(
							'recent-product',
							'top-rated',
							'product-category',
							'featured_products',
							'on_sale',
							'on_new',
							'product_attribute'
						)
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'orderby',
				[
					'label'       => esc_html__( 'Order by', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'date'          => esc_html__( 'Date', 'draly-dropshipping-starter' ),
						'ID'            => esc_html__( 'ID', 'draly-dropshipping-starter' ),
						'author'        => esc_html__( 'Author', 'draly-dropshipping-starter' ),
						'title'         => esc_html__( 'Title', 'draly-dropshipping-starter' ),
						'modified'      => esc_html__( 'Modified', 'draly-dropshipping-starter' ),
						'rand'          => esc_html__( 'Random', 'draly-dropshipping-starter' ),
						'comment_count' => esc_html__( 'Comment count', 'draly-dropshipping-starter' ),
						'menu_order'    => esc_html__( 'Menu order', 'draly-dropshipping-starter' ),
						'_sale_price'   => esc_html__( 'Sale price', 'draly-dropshipping-starter' ),
					],
					'default'     => 'date',
					'description' => esc_html__( 'Select how to sort', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'target' => array(
							'recent-product',
							'top-rated',
							'product-category',
							'featured_products',
							'on_sale',
							'on_new',
							'product_attribute'
						)
					),
					'label_block' => true

				]
			);
			$this->add_control(
				'order',
				[
					'label'       => esc_html__( 'Order', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'ASC'  => esc_html__( 'Ascending', 'draly-dropshipping-starter' ),
						'DESC' => esc_html__( 'Descending', 'draly-dropshipping-starter' ),
					],
					'default'     => 'DESC',
					'condition'   => array(
						'target' => array(
							'recent-product',
							'top-rated',
							'product-category',
							'featured_products',
							'on_sale',
							'on_new',
							'product_attribute'
						)
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'per_page',
				[
					'label'       => esc_html__( 'Product per page', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 6,
					'condition'   => array(
						'target' => array(
							'recent-product',
							'best-selling',
							'top-rated',
							'product-category',
							'featured_products',
							'on_sale',
							'on_new',
							'product_attribute'
						)
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'ids',
				[
					'label'       => esc_html__( 'Product IDs', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::TEXT,
					'placeholder' => esc_html__( 'Enter IDs', 'draly-dropshipping-starter' ),
					'description' => esc_html__( 'Ex: 1,2,3,...', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'target' => 'products'
					),
					'label_block' => true
				]
			);
			$this->end_controls_section();
			//Layout Section
			$this->start_controls_section(
				'layout_section',
				[
					'label' => esc_html__( 'Layout', 'draly-dropshipping-starter' ),
				]
			);
			$this->add_control(
				'layout',
				[
					'label'       => esc_html__( 'Layout', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'carousel' => esc_html__( 'Carousel', 'draly-dropshipping-starter' ),
						'grid'     => esc_html__( 'Grid', 'draly-dropshipping-starter' ),
						'scroll'   => esc_html__( 'Scroll', 'draly-dropshipping-starter' ),
					],
					'default'     => 'carousel',
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_number_row',
				[
					'label'       => esc_html__( 'The Number Of Rows', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'1' => esc_html__( '1 Row', 'draly-dropshipping-starter' ),
						'2' => esc_html__( '2 Rows', 'draly-dropshipping-starter' ),
						'3' => esc_html__( '3 Rows', 'draly-dropshipping-starter' ),
						'4' => esc_html__( '4 Rows', 'draly-dropshipping-starter' ),
						'5' => esc_html__( '5 Rows', 'draly-dropshipping-starter' ),
						'6' => esc_html__( '6 Rows', 'draly-dropshipping-starter' ),
					],
					'default'     => '1',
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_rows_space',
				[
					'label'       => esc_html__( 'Rows Space', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'rows-space-0'   => esc_html__( 'Default', 'draly-dropshipping-starter' ),
						'rows-space-10'  => esc_html__( '10px', 'draly-dropshipping-starter' ),
						'rows-space-20'  => esc_html__( '20px', 'draly-dropshipping-starter' ),
						'rows-space-30'  => esc_html__( '30px', 'draly-dropshipping-starter' ),
						'rows-space-40'  => esc_html__( '40px', 'draly-dropshipping-starter' ),
						'rows-space-50'  => esc_html__( '50px', 'draly-dropshipping-starter' ),
						'rows-space-60'  => esc_html__( '60px', 'draly-dropshipping-starter' ),
						'rows-space-70'  => esc_html__( '70px', 'draly-dropshipping-starter' ),
						'rows-space-80'  => esc_html__( '80px', 'draly-dropshipping-starter' ),
						'rows-space-90'  => esc_html__( '90px', 'draly-dropshipping-starter' ),
						'rows-space-100' => esc_html__( '100px', 'draly-dropshipping-starter' ),
					],
					'default'     => 'rows-space-0',
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_vertical',
				[
					'label'       => esc_html__( 'Vertical Slide Mode', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'false',
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_verticalswiping',
				[
					'label'       => esc_html__( 'Vertical Swipe Mode', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'false',
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'true'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_autoplay',
				[
					'label'       => esc_html__( 'AutoPlay', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'false',
					'description' => esc_html__( 'Enables Autoplay', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_autoplayspeed',
				[
					'label'       => esc_html__( 'Autoplay Speed', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1000,
					'default'     => 3000,
					'description' => esc_html__( 'Autoplay Speed in milliseconds', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_autoplay' => 'true'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_navigation',
				[
					'label'       => esc_html__( 'Navigation', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'true',
					'description' => esc_html__( 'Prev/Next Arrows', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_dots',
				[
					'label'       => esc_html__( 'Dots', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'false',
					'description' => esc_html__( 'Show dot indicators', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_loop',
				[
					'label'       => esc_html__( 'Loop', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'true'  => esc_html__( 'Yes', 'draly-dropshipping-starter' ),
						'false' => esc_html__( 'No', 'draly-dropshipping-starter' ),
					],
					'default'     => 'false',
					'description' => esc_html__( 'Infinite loop sliding', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_slidespeed',
				[
					'label'       => esc_html__( 'Slide Speed', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 300,
					'default'     => 300,
					'description' => esc_html__( 'Slide Speed in milliseconds', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_ls_items',
				[
					'label'       => esc_html__( 'Items per row on Wide Screens', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 4,
					'description' => esc_html__( 'Items per row on screen resolution of device >= 1400px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Wide Screens', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 30,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device >= 1400px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_lg_items',
				[
					'label'       => esc_html__( 'Items per row on Desktop', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 4,
					'description' => esc_html__( 'Items per row on screen resolution of device >= 1200px and < 1400px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_lg_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Desktop', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 30,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device >= 1200px and < 1400px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_md_items',
				[
					'label'       => esc_html__( 'Items per row on Landscape Tablet', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 3,
					'description' => esc_html__( 'Items per row on screen resolution of device >=992px and < 1200px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_md_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Landscape Tablet', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 20,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device >=992px and < 1200px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_sm_items',
				[
					'label'       => esc_html__( 'Items per row on Tablet', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 2,
					'description' => esc_html__( 'Items per row on screen resolution of device >=768px and < 992px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_sm_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Tablet', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 20,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device >=768px and < 992px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_xs_items',
				[
					'label'       => esc_html__( 'Items per row on Mobile Landscape', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 2,
					'description' => esc_html__( 'Items per row on screen resolution of device >=576px and < 768px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_xs_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Mobile Landscape', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 20,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device >=576px and < 768px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_ts_items',
				[
					'label'       => esc_html__( 'Items per row on Mobile', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 1,
					'step'        => 1,
					'default'     => 1,
					'description' => esc_html__( 'Items per row on screen resolution of device < 576px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'carousel'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'owl_ts_slide_margin',
				[
					'label'       => esc_html__( 'Margin on Mobile', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::NUMBER,
					'min'         => 0,
					'default'     => 10,
					'description' => esc_html__( 'Distance( or space) between 2 items on screen resolution of device < 576px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout'       => 'carousel',
						'owl_vertical' => 'false'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_rows_space',
				[
					'label'       => esc_html__( 'Rows space', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'rows-space-0'   => esc_html__( 'Default', 'draly-dropshipping-starter' ),
						'rows-space-10'  => esc_html__( '10px', 'draly-dropshipping-starter' ),
						'rows-space-20'  => esc_html__( '20px', 'draly-dropshipping-starter' ),
						'rows-space-30'  => esc_html__( '30px', 'draly-dropshipping-starter' ),
						'rows-space-40'  => esc_html__( '40px', 'draly-dropshipping-starter' ),
						'rows-space-50'  => esc_html__( '50px', 'draly-dropshipping-starter' ),
						'rows-space-60'  => esc_html__( '60px', 'draly-dropshipping-starter' ),
						'rows-space-70'  => esc_html__( '70px', 'draly-dropshipping-starter' ),
						'rows-space-80'  => esc_html__( '80px', 'draly-dropshipping-starter' ),
						'rows-space-90'  => esc_html__( '90px', 'draly-dropshipping-starter' ),
						'rows-space-100' => esc_html__( '100px', 'draly-dropshipping-starter' ),
					],
					'default'     => 'rows-space-0',
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_items',
				[
					'label'       => esc_html__( 'Items per row on Extra small devices (e.g., phones) - default for anything smaller', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '12',
					'description' => esc_html__( 'Screen resolution of device >= 0px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_sm_items',
				[
					'label'       => esc_html__( 'Items per row on Small devices (e.g., phones in landscape mode)', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '6',
					'description' => esc_html__( 'Screen resolution of device >= 576px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_md_items',
				[
					'label'       => esc_html__( 'Items per row on Medium devices (e.g., tablets)', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '6',
					'description' => esc_html__( 'Screen resolution of device >= 768px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_lg_items',
				[
					'label'       => esc_html__( 'Items per row on Large devices (e.g., small laptops)', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '4',
					'description' => esc_html__( 'Screen resolution of device >= 992px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_xl_items',
				[
					'label'       => esc_html__( 'Items per row on Extra large devices (e.g., desktops)', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '4',
					'description' => esc_html__( 'Screen resolution of device >= 1200px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'boostrap_xxl_items',
				[
					'label'       => esc_html__( 'Items per row on Extra extra large devices (e.g., large desktops or high-res displays)', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::SELECT,
					'options'     => [
						'12' => esc_html__( '1 item', 'draly-dropshipping-starter' ),
						'6'  => esc_html__( '2 items', 'draly-dropshipping-starter' ),
						'4'  => esc_html__( '3 items', 'draly-dropshipping-starter' ),
						'3'  => esc_html__( '4 items', 'draly-dropshipping-starter' ),
						'15' => esc_html__( '5 items', 'draly-dropshipping-starter' ),
						'2'  => esc_html__( '6 items', 'draly-dropshipping-starter' ),
					],
					'default'     => '4',
					'description' => esc_html__( 'Screen resolution of device >= 1400px', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_group_control(
				\Elementor\Group_Control_Background::get_type(),
				[
					'name'      => 'background',
					'types'     => [ 'classic' ],
					'selector'  => '{{WRAPPER}} .product-banner-inner::before',
					'condition' => array(
						'layout' => 'grid'
					),
				]
			);
			$this->add_control(
				'subtitle', [
					'label'       => esc_html__( 'Subtitle', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::TEXT,
					'placeholder' => esc_html__( 'Enter your subtitle', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'title', [
					'label'       => esc_html__( 'Title', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::TEXT,
					'placeholder' => esc_html__( 'Enter your title', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'desc', [
					'label'       => esc_html__( 'Description', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::TEXT,
					'placeholder' => esc_html__( 'Enter your description', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'text', [
					'label'       => esc_html__( 'Button Text', 'draly-dropshipping-starter' ),
					'type'        => \Elementor\Controls_Manager::TEXT,
					'placeholder' => esc_html__( 'Enter your button text', 'draly-dropshipping-starter' ),
					'condition'   => array(
						'layout' => 'grid'
					),
					'label_block' => true
				]
			);
			$this->add_control(
				'link', [
					'label'         => esc_html__( 'Button Link', 'draly-dropshipping-starter' ),
					'type'          => \Elementor\Controls_Manager::URL,
					'placeholder'   => esc_html__( 'https://your-link.com', 'draly-dropshipping-starter' ),
					'show_external' => true,
					'default'       => [
						'url'         => '',
						'is_external' => true,
						'nofollow'    => false,
					],
					'condition'     => array(
						'layout' => 'grid'
					),
					'label_block'   => true
				]
			);
			$this->end_controls_section();

		}

		/**
		 * Render the widget output on the frontend.
		 *
		 * Written in PHP and used to generate the final HTML.
		 *
		 * @since 1.0.0
		 *
		 * @access protected
		 */
		protected function render() {
			$atts        = $this->get_settings_for_display();
			$css_class   = array( 'draly-products' );
			$css_class[] = $atts['style'];
			if ( $atts['product_image_size'] ) {
				if ( $atts['product_image_size'] == 'custom' ) {
					$thumb_width  = $atts['product_custom_thumb_width'];
					$thumb_height = $atts['product_custom_thumb_height'];
				} else {
					$product_image_size = explode( "x", $atts['product_image_size'] );
					$thumb_width        = $product_image_size[0];
					$thumb_height       = $product_image_size[1];
				}
				if ( $thumb_width > 0 ) {
					add_filter( 'draly_shop_product_thumb_width', function () use ( $thumb_width ) {
						return $thumb_width;
					} );
				}
				if ( $thumb_height > 0 ) {
					add_filter( 'draly_shop_product_thumb_height', function () use ( $thumb_height ) {
						return $thumb_height;
					} );
				}
			}
			$products      = Draly_Dropshipping_Starter_Pluggable_WooCommerce::draly_dropshipping_starter_get_products($atts);
			$total_product = $products->post_count;
			$list_class    = array( 'response-product' );
			$item_class    = array( 'product-item' );
			$item_class[]  = $atts['target'];
			$item_class[]  = $atts['style'];
			$owl_settings  = '';
			if ( $atts['layout'] == 'grid' ) {
				$list_class[] = 'product-list-grid row';
				$item_class[] = $atts['boostrap_rows_space'];
				$item_class[] = 'col-' . $atts['boostrap_items'];
				$item_class[] = 'col-sm-' . $atts['boostrap_sm_items'];
				$item_class[] = 'col-md-' . $atts['boostrap_md_items'];
				$item_class[] = 'col-lg-' . $atts['boostrap_lg_items'];
				$item_class[] = 'col-xl-' . $atts['boostrap_xl_items'];
				$item_class[] = 'col-xxl-' . $atts['boostrap_xxl_items'];
			}
			if ( $atts['layout'] == 'carousel' ) {
				if ( $total_product < $atts['owl_lg_items'] ) {
					$atts['owl_loop'] = 'false';
				}
				$list_class[] = 'product-list-owl owl-slick';
				$item_class[] = $atts['owl_rows_space'];
				$owl_settings = Draly_Dropshipping_Starter_Helper::carousel_data_attributes( 'owl_', $atts );
			}
			if ( $atts['layout'] == 'scroll' ) {
				$list_class[] = 'product-list-scroll';
			}
			$id_loop = array();
			?>
            <div class="<?php echo esc_attr( implode( ' ', $css_class ) ); ?>">
				<?php if ( $products->have_posts() ): ?>
                    <div class="<?php echo esc_attr( implode( ' ', $list_class ) ); ?>" <?php echo esc_attr( $owl_settings ); ?>>
						<?php if ( ( $atts['subtitle'] || $atts['title'] || $atts['desc'] ) && $atts['layout'] == 'grid' ): ?>
                            <div class="product-banner col-12 col-sm-12 col-md-12 col-lg-8 col-xl-9 <?php echo esc_attr( $atts['boostrap_rows_space'] ) ?>">
                                <div class="product-banner-inner banner-zoom">
									<?php if ( $atts['subtitle'] ): ?>
                                        <div class="subtitle"><?php echo esc_html( $atts['subtitle'] ); ?></div>
									<?php endif; ?>
									<?php if ( $atts['title'] ): ?>
                                        <h3 class="title"><?php echo wp_kses_post( $atts['title'] ); ?></h3>
									<?php endif; ?>
									<?php if ( $atts['desc'] ): ?>
                                        <div class="desc"><?php echo esc_html( $atts['desc'] ); ?></div>
									<?php endif; ?>
									<?php if ( $atts['text'] && $atts['link']['url'] ):
										$target = $atts['link']['is_external'] ? '_blank' : '_self'; ?>
                                        <a class="button" href="<?php echo esc_url( $atts['link']['url'] ); ?>"
                                           target="<?php echo esc_attr( $target ); ?>">
                                            <span><?php echo esc_html( $atts['text'] ); ?></span>
                                            <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"
                                                 viewBox="0 0 10 10" fill="none">
                                                <g>
                                                    <path d="M9.94245 6.62514C9.94661 6.10164 9.95165 5.57874 9.95759 5.05644L9.9923 1.52912C9.9923 1.43917 9.9923 1.34608 9.99541 1.25433C9.99808 1.08433 10.0008 0.908927 9.99942 0.734428V0.719586C9.99934 0.54834 9.93293 0.383927 9.81441 0.261542C9.69588 0.139157 9.53465 0.0685238 9.36524 0.0647628L3.67187 0.00854509L3.42354 0.00494716C3.24597 0 3.06217 0 2.8797 0H2.87125C2.78314 5.61749e-05 2.69594 0.0179997 2.61483 0.0527654C2.53372 0.0875312 2.46034 0.138411 2.39906 0.202384C2.3406 0.261951 2.29469 0.332871 2.26409 0.410864C2.23349 0.488856 2.21885 0.572304 2.22105 0.656173C2.22327 0.825654 2.29022 0.98771 2.40791 1.10848C2.52559 1.22925 2.6849 1.29939 2.85256 1.30425L7.78803 1.35282L0.192119 8.88374C0.129727 8.94669 0.080543 9.02172 0.0475088 9.10433C0.0144745 9.18694 -0.0017306 9.27543 -0.000137048 9.36452C-0.000168624 9.44861 0.0166976 9.53183 0.0494393 9.60914C0.082181 9.68644 0.130116 9.75623 0.190339 9.81426C0.310516 9.9333 0.471804 10.0004 0.640081 10.0014C0.808358 10.0024 0.970423 9.93725 1.09199 9.81965L8.69234 2.28469L8.66787 4.82393L8.65451 6.45649C8.65451 6.54419 8.65229 6.63234 8.65095 6.72049C8.64828 6.89408 8.64517 7.07353 8.6465 7.25208V7.26557C8.64665 7.35457 8.66449 7.44263 8.69897 7.52452C8.73345 7.60642 8.78386 7.68047 8.84722 7.7423C8.90599 7.80135 8.97602 7.84774 9.05305 7.87866C9.13008 7.90959 9.21251 7.92439 9.29537 7.92219C9.4636 7.92026 9.62452 7.85242 9.74423 7.73295C9.86394 7.61349 9.93309 7.45173 9.93711 7.28176L9.94245 6.62514Z"
                                                          fill="currentColor"></path>
                                                </g>
                                                <defs>
                                                    <clipPath>
                                                        <rect width="10" height="10" fill="currentColor"></rect>
                                                    </clipPath>
                                                </defs>
                                            </svg>
                                        </a>
									<?php endif; ?>
                                </div>
                            </div>
						<?php endif; ?>
						<?php while ( $products->have_posts() ) : $products->the_post(); ?>
                            <div <?php post_class( $item_class ); ?>>
								<?php wc_get_template_part( 'product-styles/content-product', $atts['style'] ); ?>
                            </div>
						<?php endwhile; ?>
                    </div>
				<?php else: ?>
                    <p>
                        <strong><?php esc_html_e( 'No Product', 'draly-dropshipping-starter' ); ?></strong>
                    </p>
				<?php endif; ?>
            </div>
			<?php wp_reset_postdata();
		}
	}
}