<?php
/**
 * Product Gallery Widget - TAB_CONTENT controls
 *
 * Included via require inside register_controls(). $this refers to the widget instance.
 */

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

// ── Gallery Configuration ─────────────────────────────────────────────────────

$this->start_controls_section(
	'gallery_content_section',
	[
		'label' => __( 'Gallery Configuration', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'product_source',
	[
		'label'   => __( 'Product Source', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'current',
		'options' => [
			'current' => __( 'Current Product (Auto-detect)', 'ggm-commerce' ),
			'custom'  => __( 'Select Product', 'ggm-commerce' ),
		],
	]
);

$this->add_control(
	'product_id',
	[
		'label'       => __( 'Product', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::NUMBER,
		'default'     => '',
		'condition'   => [
			'product_source' => 'custom',
		],
		'description' => __( 'Start typing product name to search', 'ggm-commerce' ),
	]
);

$this->add_control(
	'gallery_layout',
	[
		'label'   => __( 'Gallery Layout', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'standard',
		'options' => [
			'standard' => __( 'Standard (Main + Thumbnails)', 'ggm-commerce' ),
			'slider'   => __( 'Image Slider', 'ggm-commerce' ),
			'grid'     => __( 'Grid Layout', 'ggm-commerce' ),
		],
	]
);

$this->end_controls_section();

// ── Thumbnail Settings ────────────────────────────────────────────────────────

$this->start_controls_section(
	'thumbnail_section',
	[
		'label'     => __( 'Thumbnail Settings', 'ggm-commerce' ),
		'tab'       => \Elementor\Controls_Manager::TAB_CONTENT,
		'condition' => [
			'gallery_layout' => 'standard',
		],
	]
);

$this->add_control(
	'thumbnail_position',
	[
		'label'   => __( 'Thumbnail Position', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'bottom',
		'options' => [
			'bottom' => __( 'Bottom', 'ggm-commerce' ),
			'top'    => __( 'Top', 'ggm-commerce' ),
			'left'   => __( 'Left', 'ggm-commerce' ),
			'right'  => __( 'Right', 'ggm-commerce' ),
		],
	]
);

$this->add_control(
	'max_visible_thumbnails',
	[
		'label'       => __( 'Max Visible Thumbnails', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::NUMBER,
		'default'     => 4,
		'min'         => 1,
		'max'         => 10,
		'step'        => 1,
		'description' => __( 'Maximum number of thumbnails to show at once. Navigation arrows will appear if there are more.', 'ggm-commerce' ),
	]
);

$this->add_responsive_control(
	'thumbnail_size',
	[
		'label'      => __( 'Thumbnail Size', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => [ 'px' ],
		'range'      => [
			'px' => [
				'min' => 50,
				'max' => 200,
			],
		],
		'default'   => [
			'size' => 80,
			'unit' => 'px',
		],
		'selectors' => [
			'{{WRAPPER}} .ggm-gallery-thumbnail' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
		],
	]
);

$this->add_responsive_control(
	'thumbnail_spacing',
	[
		'label'      => __( 'Thumbnail Spacing', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => [ 'px' ],
		'range'      => [
			'px' => [
				'min' => 0,
				'max' => 50,
			],
		],
		'default'   => [
			'size' => 10,
			'unit' => 'px',
		],
		'selectors' => [
			'{{WRAPPER}} .ggm-gallery-thumbnails' => 'gap: {{SIZE}}{{UNIT}};',
		],
	]
);

$this->end_controls_section();

// ── Slider Settings ───────────────────────────────────────────────────────────

$this->start_controls_section(
	'slider_section',
	[
		'label'     => __( 'Slider Settings', 'ggm-commerce' ),
		'tab'       => \Elementor\Controls_Manager::TAB_CONTENT,
		'condition' => [
			'gallery_layout' => 'slider',
		],
	]
);

$this->add_control(
	'slider_autoplay',
	[
		'label'     => __( 'Autoplay', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'no',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
	]
);

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

$this->add_control(
	'slider_pause_on_hover',
	[
		'label'     => __( 'Pause on Hover', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'slider_autoplay' => 'yes',
		],
	]
);

$this->add_control(
	'slider_loop',
	[
		'label'     => __( 'Infinite Loop', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
	]
);

$this->add_control(
	'slider_show_arrows',
	[
		'label'     => __( 'Show Navigation Arrows', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
	]
);

$this->add_control(
	'slider_show_dots',
	[
		'label'     => __( 'Show Dots Navigation', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
	]
);

$this->add_control(
	'slider_transition',
	[
		'label'   => __( 'Transition Effect', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'slide',
		'options' => [
			'slide' => __( 'Slide', 'ggm-commerce' ),
			'fade'  => __( 'Fade', 'ggm-commerce' ),
		],
	]
);

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

$this->end_controls_section();

// ── Grid Settings ─────────────────────────────────────────────────────────────

$this->start_controls_section(
	'grid_section',
	[
		'label'     => __( 'Grid Settings', 'ggm-commerce' ),
		'tab'       => \Elementor\Controls_Manager::TAB_CONTENT,
		'condition' => [
			'gallery_layout' => 'grid',
		],
	]
);

$this->add_responsive_control(
	'grid_columns',
	[
		'label'          => __( 'Columns', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SELECT,
		'default'        => '3',
		'tablet_default' => '2',
		'mobile_default' => '2',
		'options'        => [
			'1' => '1',
			'2' => '2',
			'3' => '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
		],
		'selectors' => [
			'{{WRAPPER}} .ggm-gallery-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
		],
	]
);

$this->add_responsive_control(
	'grid_gap',
	[
		'label'      => __( 'Gap', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => [ 'px' ],
		'range'      => [
			'px' => [
				'min' => 0,
				'max' => 50,
			],
		],
		'default'   => [
			'size' => 10,
			'unit' => 'px',
		],
		'selectors' => [
			'{{WRAPPER}} .ggm-gallery-grid' => 'gap: {{SIZE}}{{UNIT}};',
		],
	]
);

$this->add_control(
	'grid_image_ratio',
	[
		'label'   => __( 'Image Aspect Ratio', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'square',
		'options' => [
			'square'    => __( 'Square (1:1)', 'ggm-commerce' ),
			'landscape' => __( 'Landscape (4:3)', 'ggm-commerce' ),
			'portrait'  => __( 'Portrait (3:4)', 'ggm-commerce' ),
			'original'  => __( 'Original', 'ggm-commerce' ),
		],
	]
);

$this->add_control(
	'grid_first_image_featured',
	[
		'label'       => __( 'Feature First Image', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SWITCHER,
		'default'     => 'no',
		'label_on'    => __( 'Yes', 'ggm-commerce' ),
		'label_off'   => __( 'No', 'ggm-commerce' ),
		'description' => __( 'Make the first image span multiple columns/rows.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'grid_featured_span',
	[
		'label'     => __( 'Featured Image Size', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => '2x2',
		'options'   => [
			'2x1' => __( '2 Columns x 1 Row', 'ggm-commerce' ),
			'2x2' => __( '2 Columns x 2 Rows', 'ggm-commerce' ),
			'1x2' => __( '1 Column x 2 Rows', 'ggm-commerce' ),
		],
		'condition' => [
			'grid_first_image_featured' => 'yes',
		],
	]
);

$this->end_controls_section();

// ── Lightbox Settings ─────────────────────────────────────────────────────────

$this->start_controls_section(
	'lightbox_section',
	[
		'label' => __( 'Lightbox Settings', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'enable_lightbox',
	[
		'label'       => __( 'Enable Lightbox', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SWITCHER,
		'default'     => 'yes',
		'label_on'    => __( 'Yes', 'ggm-commerce' ),
		'label_off'   => __( 'No', 'ggm-commerce' ),
		'description' => __( 'Click on main image to open fullscreen lightbox gallery.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'lightbox_animation',
	[
		'label'     => __( 'Lightbox Animation', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'fade',
		'options'   => [
			'fade'  => __( 'Fade', 'ggm-commerce' ),
			'slide' => __( 'Slide', 'ggm-commerce' ),
			'zoom'  => __( 'Zoom', 'ggm-commerce' ),
		],
		'condition' => [
			'enable_lightbox' => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_product_info',
	[
		'label'     => __( 'Show Product Info in Lightbox', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'no',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'enable_lightbox' => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_info_position',
	[
		'label'     => __( 'Info Position', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'bottom',
		'options'   => [
			'top'    => __( 'Top', 'ggm-commerce' ),
			'bottom' => __( 'Bottom', 'ggm-commerce' ),
			'left'   => __( 'Left', 'ggm-commerce' ),
			'right'  => __( 'Right', 'ggm-commerce' ),
		],
		'condition' => [
			'enable_lightbox'        => 'yes',
			'lightbox_product_info'  => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_show_title',
	[
		'label'     => __( 'Show Title', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'enable_lightbox'       => 'yes',
			'lightbox_product_info' => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_show_price',
	[
		'label'     => __( 'Show Price', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'yes',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'enable_lightbox'       => 'yes',
			'lightbox_product_info' => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_show_description',
	[
		'label'     => __( 'Show Description', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'no',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'enable_lightbox'       => 'yes',
			'lightbox_product_info' => 'yes',
		],
	]
);

$this->add_control(
	'lightbox_show_stock',
	[
		'label'     => __( 'Show Stock Status', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SWITCHER,
		'default'   => 'no',
		'label_on'  => __( 'Yes', 'ggm-commerce' ),
		'label_off' => __( 'No', 'ggm-commerce' ),
		'condition' => [
			'enable_lightbox'       => 'yes',
			'lightbox_product_info' => 'yes',
		],
	]
);

$this->end_controls_section();

// ── Zoom Settings ─────────────────────────────────────────────────────────────

$this->start_controls_section(
	'zoom_section',
	[
		'label' => __( 'Zoom Settings', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'enable_zoom',
	[
		'label'       => __( 'Enable Zoom', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SWITCHER,
		'default'     => 'yes',
		'label_on'    => __( 'Yes', 'ggm-commerce' ),
		'label_off'   => __( 'No', 'ggm-commerce' ),
		'description' => __( 'Hover over main image to zoom in. Works in both gallery and lightbox.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'zoom_level',
	[
		'label'   => __( 'Zoom Level', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SLIDER,
		'default' => [
			'size' => 2,
		],
		'range'     => [
			'px' => [
				'min'  => 1.5,
				'max'  => 4,
				'step' => 0.1,
			],
		],
		'condition' => [
			'enable_zoom' => 'yes',
		],
	]
);

$this->add_control(
	'zoom_type',
	[
		'label'     => __( 'Zoom Type', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'inner',
		'options'   => [
			'inner'  => __( 'Inner Zoom', 'ggm-commerce' ),
			'lens'   => __( 'Lens Zoom', 'ggm-commerce' ),
			'window' => __( 'Window Zoom', 'ggm-commerce' ),
		],
		'condition' => [
			'enable_zoom' => 'yes',
		],
	]
);

$this->end_controls_section();

// ── Performance Settings ──────────────────────────────────────────────────────

$this->start_controls_section(
	'performance_section',
	[
		'label' => __( 'Performance Settings', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'enable_lazy_loading',
	[
		'label'       => __( 'Enable Lazy Loading', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SWITCHER,
		'default'     => 'yes',
		'label_on'    => __( 'Yes', 'ggm-commerce' ),
		'label_off'   => __( 'No', 'ggm-commerce' ),
		'description' => __( 'Load images only when they become visible to improve page load speed.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'enable_preloading',
	[
		'label'       => __( 'Enable Image Preloading', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SWITCHER,
		'default'     => 'no',
		'label_on'    => __( 'Yes', 'ggm-commerce' ),
		'label_off'   => __( 'No', 'ggm-commerce' ),
		'description' => __( 'Preload next/previous images in background for smoother navigation.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'image_quality',
	[
		'label'       => __( 'Image Quality', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::SELECT,
		'default'     => 'medium',
		'options'     => [
			'thumbnail' => __( 'Thumbnail (150px)', 'ggm-commerce' ),
			'medium'    => __( 'Medium (300px)', 'ggm-commerce' ),
			'large'     => __( 'Large (600px)', 'ggm-commerce' ),
			'full'      => __( 'Full Size', 'ggm-commerce' ),
		],
		'description' => __( 'Default image size for main gallery image.', 'ggm-commerce' ),
	]
);

$this->end_controls_section();
