<?php
/**
 * Product Carousel Widget - Content Tab Controls
 *
 * @package GGM_Commerce
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// ──────────────────────────────────────────────
// SECTION: Product Query
// ──────────────────────────────────────────────
$this->start_controls_section(
	'query_section',
	array(
		'label' => __( 'Product Query', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'products_per_page',
	array(
		'label'   => __( 'Number of Products', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::NUMBER,
		'default' => 8,
		'min'     => 1,
		'max'     => 20,
	)
);

$this->add_control(
	'orderby',
	array(
		'label'   => __( 'Order By', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'created_at',
		'options' => array(
			'created_at' => __( 'Date Created', 'ggm-commerce' ),
			'updated_at' => __( 'Date Modified', 'ggm-commerce' ),
			'name'       => __( 'Name', 'ggm-commerce' ),
			'price'      => __( 'Price', 'ggm-commerce' ),
			'stock'      => __( 'Stock', 'ggm-commerce' ),
			'featured'   => __( 'Featured First', 'ggm-commerce' ),
		),
	)
);

$this->add_control(
	'order',
	array(
		'label'   => __( 'Order', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'DESC',
		'options' => array(
			'ASC'  => __( 'Ascending', 'ggm-commerce' ),
			'DESC' => __( 'Descending', 'ggm-commerce' ),
		),
	)
);

$this->add_control(
	'show_featured_only',
	array(
		'label'        => __( 'Featured Products Only', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
	)
);

// Category filter
$category_options = class_exists( 'GGM_Commerce_Product_Data_Handler' )
	? GGM_Commerce_Product_Data_Handler::get_categories_options()
	: array();

$this->add_control(
	'filter_by_category',
	array(
		'label'       => __( 'Filter by Category', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SELECT2,
		'multiple'    => true,
		'options'     => $category_options,
		'default'     => array(),
		'label_block' => true,
	)
);

// Tag filter
$tag_options = class_exists( 'GGM_Commerce_Product_Data_Handler' )
	? GGM_Commerce_Product_Data_Handler::get_tags_options()
	: array();

$this->add_control(
	'filter_by_tag',
	array(
		'label'       => __( 'Filter by Tag', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SELECT2,
		'multiple'    => true,
		'options'     => $tag_options,
		'default'     => array(),
		'label_block' => true,
	)
);

$this->add_control(
	'stock_filter',
	array(
		'label'   => __( 'Stock Status', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'all',
		'options' => array(
			'all'        => __( 'All', 'ggm-commerce' ),
			'instock'    => __( 'In Stock', 'ggm-commerce' ),
			'outofstock' => __( 'Out of Stock', 'ggm-commerce' ),
			'lowstock'   => __( 'Low Stock', 'ggm-commerce' ),
		),
	)
);

// Attribute filter (conditional on custom-attributes premium feature)
$attr_filter_active = function_exists('ggm_commerce_license') && ggm_commerce_license()->is_widget_activated('custom-attributes');
if ($attr_filter_active) {
	$attr_filter_options = array( '' => __( '-- No Filter --', 'ggm-commerce' ) );
	if ( class_exists( 'GGM_Commerce_Attributes' ) ) {
		$all_attrs = GGM_Commerce_Attributes::get_instance()->get_all_attributes();
		foreach ( $all_attrs as $attr ) {
			$label = $attr->name;
			if ( ! empty( $attr->group_name ) ) {
				$label .= ' (' . $attr->group_name . ')';
			}
			$attr_filter_options[ $attr->id ] = $label;
		}
	}

	$this->add_control(
		'filter_by_attribute',
		array(
			'label'       => __( 'Filter by Attribute', 'ggm-commerce' ),
			'type'        => \Elementor\Controls_Manager::SELECT,
			'default'     => '',
			'options'     => $attr_filter_options,
			'description' => __( 'Show only products with a specific attribute value.', 'ggm-commerce' ),
		)
	);

	$this->add_control(
		'filter_by_attribute_value',
		array(
			'label'       => __( 'Attribute Value', 'ggm-commerce' ),
			'type'        => \Elementor\Controls_Manager::TEXT,
			'default'     => '',
			'description' => __( 'Enter the exact attribute value to filter by.', 'ggm-commerce' ),
			'condition'   => array( 'filter_by_attribute!' => '' ),
		)
	);
}

$this->end_controls_section();

// ──────────────────────────────────────────────
// SECTION: Card Layout
// ──────────────────────────────────────────────
$this->start_controls_section(
	'card_layout_section',
	array(
		'label' => __( 'Card Layout', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'card_layout',
	array(
		'label'   => __( 'Layout', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'vertical',
		'options' => array(
			'vertical'   => __( 'Vertical (Image Above Content)', 'ggm-commerce' ),
			'horizontal' => __( 'Horizontal (Image Beside Content)', 'ggm-commerce' ),
			'overlay'    => __( 'Overlay (Content Over Image)', 'ggm-commerce' ),
		),
	)
);

$this->add_control(
	'image_position',
	array(
		'label'     => __( 'Image Position', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::CHOOSE,
		'options'   => array(
			'left'  => array(
				'title' => __( 'Left', 'ggm-commerce' ),
				'icon'  => 'eicon-h-align-left',
			),
			'right' => array(
				'title' => __( 'Right', 'ggm-commerce' ),
				'icon'  => 'eicon-h-align-right',
			),
		),
		'default'   => 'left',
		'condition' => array(
			'card_layout' => 'horizontal',
		),
	)
);

$this->add_responsive_control(
	'image_width',
	array(
		'label'      => __( 'Image Width', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( '%' ),
		'range'      => array(
			'%' => array( 'min' => 30, 'max' => 70 ),
		),
		'default'    => array( 'size' => 40, 'unit' => '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-carousel-card.layout-horizontal .carousel-card-image' => 'width: {{SIZE}}{{UNIT}}; flex: 0 0 {{SIZE}}{{UNIT}};',
		),
		'condition'  => array(
			'card_layout' => 'horizontal',
		),
	)
);

$this->add_control(
	'overlay_position',
	array(
		'label'     => __( 'Content Position', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'bottom',
		'options'   => array(
			'bottom' => __( 'Bottom', 'ggm-commerce' ),
			'center' => __( 'Center', 'ggm-commerce' ),
			'full'   => __( 'Full', 'ggm-commerce' ),
		),
		'condition' => array(
			'card_layout' => 'overlay',
		),
	)
);

$this->add_control(
	'overlay_gradient',
	array(
		'label'     => __( 'Overlay Gradient', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => 'rgba(0,0,0,0.6)',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-carousel-card.layout-overlay .carousel-card-content' => 'background: linear-gradient(transparent, {{VALUE}});',
		),
		'condition' => array(
			'card_layout'      => 'overlay',
			'overlay_position' => 'bottom',
		),
	)
);

$this->add_control(
	'overlay_gradient_center',
	array(
		'label'     => __( 'Overlay Background', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => 'rgba(0,0,0,0.5)',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-carousel-card.layout-overlay.overlay-center .carousel-card-content' => 'background: {{VALUE}};',
			'{{WRAPPER}} .ggmc-carousel-card.layout-overlay.overlay-full .carousel-card-content'   => 'background: {{VALUE}};',
		),
		'condition' => array(
			'card_layout'       => 'overlay',
			'overlay_position!' => 'bottom',
		),
	)
);

$this->add_control(
	'overlay_text_color',
	array(
		'label'     => __( 'Overlay Text Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#ffffff',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-carousel-card.layout-overlay .carousel-card-content' => 'color: {{VALUE}};',
			'{{WRAPPER}} .ggmc-carousel-card.layout-overlay .carousel-card-content a' => 'color: {{VALUE}};',
		),
		'condition' => array(
			'card_layout' => 'overlay',
		),
	)
);

$this->add_control(
	'content_alignment',
	array(
		'label'     => __( 'Content Alignment', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::CHOOSE,
		'options'   => array(
			'left'   => array(
				'title' => __( 'Left', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-left',
			),
			'center' => array(
				'title' => __( 'Center', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-center',
			),
			'right'  => array(
				'title' => __( 'Right', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-right',
			),
		),
		'default'   => 'left',
		'selectors' => array(
			'{{WRAPPER}} .carousel-card-content' => 'text-align: {{VALUE}};',
		),
	)
);

$this->add_control(
	'content_vertical_align',
	array(
		'label'     => __( 'Vertical Alignment', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::CHOOSE,
		'options'   => array(
			'flex-start' => array(
				'title' => __( 'Top', 'ggm-commerce' ),
				'icon'  => 'eicon-v-align-top',
			),
			'center'     => array(
				'title' => __( 'Center', 'ggm-commerce' ),
				'icon'  => 'eicon-v-align-middle',
			),
			'flex-end'   => array(
				'title' => __( 'Bottom', 'ggm-commerce' ),
				'icon'  => 'eicon-v-align-bottom',
			),
		),
		'default'   => 'center',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-carousel-card.layout-horizontal' => 'align-items: {{VALUE}};',
		),
		'condition' => array(
			'card_layout' => 'horizontal',
		),
	)
);

$this->end_controls_section();

// ──────────────────────────────────────────────
// SECTION: Carousel Settings
// ──────────────────────────────────────────────
$this->start_controls_section(
	'carousel_section',
	array(
		'label' => __( 'Carousel Settings', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_responsive_control(
	'slides_per_view',
	array(
		'label'          => __( 'Slides Per View', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SELECT,
		'default'        => '3',
		'tablet_default' => '2',
		'mobile_default' => '1',
		'options'        => array(
			'1' => '1',
			'2' => '2',
			'3' => '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
		),
	)
);

$this->add_control(
	'slides_to_scroll',
	array(
		'label'   => __( 'Slides to Scroll', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::NUMBER,
		'default' => 1,
		'min'     => 1,
		'max'     => 6,
	)
);

$this->add_responsive_control(
	'slide_gap',
	array(
		'label'          => __( 'Gap Between Slides', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SLIDER,
		'size_units'     => array( 'px' ),
		'range'          => array(
			'px' => array( 'min' => 0, 'max' => 60 ),
		),
		'default'        => array( 'size' => 20, 'unit' => 'px' ),
		'tablet_default' => array( 'size' => 15, 'unit' => 'px' ),
		'mobile_default' => array( 'size' => 10, 'unit' => 'px' ),
	)
);

$this->add_responsive_control(
	'peek_width',
	array(
		'label'          => __( 'Peek Width (Adjacent Slide Visibility)', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SLIDER,
		'size_units'     => array( 'px' ),
		'range'          => array(
			'px' => array( 'min' => 0, 'max' => 200 ),
		),
		'default'        => array( 'size' => 40, 'unit' => 'px' ),
		'tablet_default' => array( 'size' => 30, 'unit' => 'px' ),
		'mobile_default' => array( 'size' => 20, 'unit' => 'px' ),
		'description'    => __( 'How much of the previous/next slides to show on each side.', 'ggm-commerce' ),
	)
);

$this->add_control(
	'center_mode',
	array(
		'label'        => __( 'Center Mode', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
		'description'  => __( 'Center the active slides with equal peek on both sides.', 'ggm-commerce' ),
	)
);

$this->add_control(
	'overflow_visible',
	array(
		'label'        => __( 'Overflow Visible', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
		'description'  => __( 'Show adjacent slides beyond the container edges instead of clipping them.', 'ggm-commerce' ),
	)
);

$this->add_control(
	'autoplay',
	array(
		'label'        => __( 'Autoplay', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'autoplay_speed',
	array(
		'label'     => __( 'Autoplay Speed (ms)', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::NUMBER,
		'default'   => 3000,
		'min'       => 1000,
		'max'       => 10000,
		'step'      => 500,
		'condition' => array(
			'autoplay' => 'yes',
		),
	)
);

$this->add_control(
	'pause_on_hover',
	array(
		'label'        => __( 'Pause on Hover', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
		'condition'    => array(
			'autoplay' => 'yes',
		),
	)
);

$this->add_control(
	'infinite_loop',
	array(
		'label'        => __( 'Infinite Loop', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'transition_speed',
	array(
		'label'   => __( 'Transition Speed (ms)', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::NUMBER,
		'default' => 400,
		'min'     => 100,
		'max'     => 2000,
		'step'    => 100,
	)
);

$this->add_control(
	'transition_easing',
	array(
		'label'   => __( 'Transition Easing', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'ease',
		'options' => array(
			'ease'           => __( 'Ease', 'ggm-commerce' ),
			'ease-in'        => __( 'Ease In', 'ggm-commerce' ),
			'ease-out'       => __( 'Ease Out', 'ggm-commerce' ),
			'ease-in-out'    => __( 'Ease In Out', 'ggm-commerce' ),
			'linear'         => __( 'Linear', 'ggm-commerce' ),
		),
	)
);

$this->end_controls_section();

// ──────────────────────────────────────────────
// SECTION: Show/Hide Components
// ──────────────────────────────────────────────
$this->start_controls_section(
	'elements_section',
	array(
		'label' => __( 'Show/Hide Components', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'show_image',
	array(
		'label'        => __( 'Image', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_badge',
	array(
		'label'        => __( 'Badges (Featured, Sale, New)', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_categories',
	array(
		'label'        => __( 'Categories', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'link_categories',
	array(
		'label'        => __( 'Link Categories', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
		'condition'    => array(
			'show_categories' => 'yes',
		),
	)
);

$this->add_control(
	'show_title',
	array(
		'label'        => __( 'Title', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

// Rating (conditional on premium feature)
$show_rating_condition = array();
if ( function_exists( 'ggm_commerce_license' ) ) {
	$license = ggm_commerce_license();
	if ( ! $license->is_widget_activated( 'product-reviews' ) ) {
		$show_rating_condition = array( 'show_rating_never_match' => 'yes' );
	}
}

$this->add_control(
	'show_rating',
	array(
		'label'        => __( 'Rating', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
		'condition'    => $show_rating_condition,
	)
);

$this->add_control(
	'show_price',
	array(
		'label'        => __( 'Price', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_description',
	array(
		'label'        => __( 'Description', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'description_length',
	array(
		'label'     => __( 'Description Length (words)', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::NUMBER,
		'default'   => 15,
		'min'       => 5,
		'max'       => 100,
		'condition' => array(
			'show_description' => 'yes',
		),
	)
);

$this->add_control(
	'show_stock',
	array(
		'label'        => __( 'Stock Status', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_restock_date',
	array(
		'label'        => __( 'Show Restock Date', 'goose-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
		'description'  => __( 'Replaces "Out of Stock" with the expected restock message if a date is set.', 'goose-commerce' ),
		'condition'    => array(
			'show_stock' => 'yes',
		),
	)
);

$this->add_control(
	'restock_display_format',
	array(
		'label'     => __( 'Restock Display Format', 'goose-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'descriptive',
		'options'   => array(
			'exact_date'  => __( 'Exact Date (Expected 04/Aug)', 'goose-commerce' ),
			'weeks'       => __( 'Weeks (Expected in 2 to 3 weeks)', 'goose-commerce' ),
			'descriptive' => __( 'Descriptive (Expected Soon / Imminent)', 'goose-commerce' ),
		),
		'condition' => array(
			'show_stock'        => 'yes',
			'show_restock_date' => 'yes',
		),
	)
);

$attributes_active = function_exists( 'ggm_commerce_license' ) && ggm_commerce_license()->is_widget_activated( 'custom-attributes' );
if ( $attributes_active ) {

	// Build attribute options for the selector
	$carousel_attr_options = array();
	if ( class_exists( 'GGM_Commerce_Attributes' ) ) {
		$all_attrs = GGM_Commerce_Attributes::get_instance()->get_all_attributes();
		foreach ( $all_attrs as $attr ) {
			$label = $attr->name;
			if ( ! empty( $attr->group_name ) ) {
				$label .= ' (' . $attr->group_name . ')';
			}
			$carousel_attr_options[ $attr->id ] = $label;
		}
	}

	$this->add_control(
		'show_attributes',
		array(
			'label'        => __( 'Attributes', 'ggm-commerce' ),
			'type'         => \Elementor\Controls_Manager::SWITCHER,
			'default'      => '',
			'return_value' => 'yes',
		)
	);

	$this->add_control(
		'carousel_selected_attributes',
		array(
			'label'       => __( 'Attributes to Display', 'ggm-commerce' ),
			'type'        => \Elementor\Controls_Manager::SELECT2,
			'multiple'    => true,
			'options'     => $carousel_attr_options,
			'default'     => array(),
			'description' => __( 'Select which attributes to show. Leave empty to show all.', 'ggm-commerce' ),
			'label_block' => true,
			'condition'   => array( 'show_attributes' => 'yes' ),
		)
	);

	$this->add_control(
		'carousel_attributes_layout',
		array(
			'label'     => __( 'Attributes Layout', 'ggm-commerce' ),
			'type'      => \Elementor\Controls_Manager::SELECT,
			'default'   => 'inline',
			'options'   => array(
				'inline' => __( 'Inline', 'ggm-commerce' ),
				'list'   => __( 'List', 'ggm-commerce' ),
				'table'  => __( 'Table', 'ggm-commerce' ),
			),
			'condition' => array( 'show_attributes' => 'yes' ),
		)
	);

	$this->add_control(
		'carousel_attributes_show_units',
		array(
			'label'        => __( 'Show Units', 'ggm-commerce' ),
			'type'         => \Elementor\Controls_Manager::SWITCHER,
			'default'      => 'yes',
			'return_value' => 'yes',
			'condition'    => array( 'show_attributes' => 'yes' ),
		)
	);
}

$this->add_control(
	'show_details_link',
	array(
		'label'        => __( 'Details Link', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_add_to_cart',
	array(
		'label'        => __( 'Add to Cart Button', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'add_to_cart_text',
	array(
		'label'     => __( 'Button Text', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::TEXT,
		'default'   => __( 'Add to Cart', 'ggm-commerce' ),
		'condition' => array(
			'show_add_to_cart' => 'yes',
		),
	)
);

// Wishlist (conditional on premium feature)
$wishlist_active = function_exists( 'ggm_commerce_license' ) && ggm_commerce_license()->is_widget_activated( 'wishlist' );
if ( $wishlist_active ) {
	$this->add_control(
		'show_wishlist',
		array(
			'label'        => __( 'Wishlist Icon', 'ggm-commerce' ),
			'type'         => \Elementor\Controls_Manager::SWITCHER,
			'default'      => '',
			'return_value' => 'yes',
		)
	);
}

// Compare (conditional on premium feature)
$compare_active = function_exists( 'ggm_commerce_license' ) && ggm_commerce_license()->is_widget_activated( 'product-comparison' );
if ( $compare_active ) {
	$this->add_control(
		'show_compare',
		array(
			'label'        => __( 'Compare Icon', 'ggm-commerce' ),
			'type'         => \Elementor\Controls_Manager::SWITCHER,
			'default'      => '',
			'return_value' => 'yes',
		)
	);
}

$this->end_controls_section();

// ──────────────────────────────────────────────
// SECTION: Component Order
// ──────────────────────────────────────────────
$this->start_controls_section(
	'component_order_section',
	array(
		'label' => __( 'Component Order', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$_component_order_styles = '
<style>
/* Component Order Repeater Styling */
.elementor-control-component_order .elementor-repeater-row-controls {
    display: none !important;
}
.elementor-control-component_order .elementor-repeater-fields:hover {
    background: #f5f5f5;
}
.elementor-control-component_order .elementor-repeater-fields .elementor-repeater-row-item-title {
    padding: 10px 12px 10px 36px !important;
    cursor: move;
    position: relative;
}
/* Drag handle icon */
.elementor-control-component_order .elementor-repeater-fields .elementor-repeater-row-item-title::before {
    content: "\e816";
    font-family: "eicons";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #a4afb7;
    font-size: 12px;
}
</style>';

$this->add_control(
	'component_order_heading',
	array(
		'type' => \Elementor\Controls_Manager::RAW_HTML,
		'raw'  => '<p style="font-size: 12px; color: #6d7882; margin: 0;">' .
		           __( 'Drag to reorder how components appear on each product card.', 'ggm-commerce' ) .
		           '</p>' . $_component_order_styles,
	)
);

$repeater = new \Elementor\Repeater();

$repeater->add_control(
	'component_id',
	array(
		'type' => \Elementor\Controls_Manager::HIDDEN,
	)
);

$repeater->add_control(
	'component_label',
	array(
		'type' => \Elementor\Controls_Manager::HIDDEN,
	)
);

$this->add_control(
	'component_order',
	array(
		'type'          => \Elementor\Controls_Manager::REPEATER,
		'fields'        => $repeater->get_controls(),
		'default'       => ggmc_product_carousel_get_available_components(),
		'title_field'   => '{{{ component_label }}}',
		'prevent_empty' => true,
		'item_actions'  => array(
			'add'       => false,
			'duplicate' => false,
			'remove'    => false,
			'sort'      => true,
		),
	)
);

$this->end_controls_section();
