<?php
/**
 * Product Image Grid — TAB_CONTENT Controls
 * Included via require inside register_controls().
 * $this is the widget instance.
 *
 * @package GGM_Commerce
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// -------------------------------------------------------------------------
// Content section
// -------------------------------------------------------------------------
$this->start_controls_section(
	'content_section',
	[
		'label' => __( 'Content', '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' => __( 'Enter the product ID', 'ggm-commerce' ),
	]
);

$this->add_control(
	'image_size',
	[
		'label'   => __( 'Image Size', '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 (Original)', 'ggm-commerce' ),
		],
	]
);

$this->end_controls_section();

// -------------------------------------------------------------------------
// Layout section
// -------------------------------------------------------------------------
$this->start_controls_section(
	'layout_section',
	[
		'label' => __( 'Layout', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'layout_preset',
	[
		'label'   => __( 'Layout', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'standard-grid',
		'options' => [
			'standard-grid' => __( 'Standard Grid', 'ggm-commerce' ),
			'featured-grid' => __( 'Featured + Grid', 'ggm-commerce' ),
			'masonry'       => __( 'Masonry', 'ggm-commerce' ),
			'alternating'   => __( 'Alternating Rows', 'ggm-commerce' ),
		],
	]
);

$this->add_responsive_control(
	'grid_columns',
	[
		'label'          => __( 'Columns', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SELECT,
		'default'        => '3',
		'tablet_default' => '2',
		'mobile_default' => '2',
		'options'        => [
			'2' => '2',
			'3' => '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
		],
		'condition'      => [
			'layout_preset!' => 'masonry',
		],
		'selectors'      => [
			'{{WRAPPER}} .ggmc-image-grid--standard .ggmc-image-grid__grid'   => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
			'{{WRAPPER}} .ggmc-image-grid--featured .ggmc-image-grid__grid'   => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
			'{{WRAPPER}} .ggmc-image-grid--alternating .ggmc-image-grid__row' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
		],
	]
);

$this->add_responsive_control(
	'masonry_columns',
	[
		'label'          => __( 'Columns', 'ggm-commerce' ),
		'type'           => \Elementor\Controls_Manager::SELECT,
		'default'        => '3',
		'tablet_default' => '2',
		'mobile_default' => '2',
		'options'        => [
			'2' => '2',
			'3' => '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
		],
		'condition'      => [
			'layout_preset' => 'masonry',
		],
		'selectors'      => [
			'{{WRAPPER}} .ggmc-image-grid--masonry .ggmc-image-grid__grid' => 'column-count: {{VALUE}};',
		],
	]
);

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

$this->add_control(
	'alternating_primary',
	[
		'label'       => __( 'Primary Row Count', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::NUMBER,
		'default'     => 3,
		'min'         => 1,
		'max'         => 6,
		'condition'   => [
			'layout_preset' => 'alternating',
		],
		'description' => __( 'Number of images in odd rows', 'ggm-commerce' ),
	]
);

$this->add_control(
	'alternating_secondary',
	[
		'label'       => __( 'Secondary Row Count', 'ggm-commerce' ),
		'type'        => \Elementor\Controls_Manager::NUMBER,
		'default'     => 2,
		'min'         => 1,
		'max'         => 6,
		'condition'   => [
			'layout_preset' => 'alternating',
		],
		'description' => __( 'Number of images in even rows', 'ggm-commerce' ),
	]
);

$this->add_responsive_control(
	'grid_gap',
	[
		'label'      => __( 'Gap', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => [ 'px', 'em' ],
		'range'      => [
			'px' => [
				'min' => 0,
				'max' => 50,
			],
			'em' => [
				'min'  => 0,
				'max'  => 3,
				'step' => 0.1,
			],
		],
		'selectors'  => [
			'{{WRAPPER}} .ggmc-image-grid--standard .ggmc-image-grid__grid'    => 'gap: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-image-grid--featured .ggmc-image-grid__grid'    => 'gap: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-image-grid--alternating .ggmc-image-grid__grid' => 'gap: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-image-grid--alternating .ggmc-image-grid__row'  => 'gap: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-image-grid--masonry .ggmc-image-grid__grid'     => 'column-gap: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-image-grid--masonry .ggmc-image-grid__item'     => 'margin-bottom: {{SIZE}}{{UNIT}};',
		],
	]
);

$this->add_control(
	'image_aspect_ratio',
	[
		'label'     => __( 'Image Aspect Ratio', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => 'original',
		'options'   => [
			'original' => __( 'Original', 'ggm-commerce' ),
			'1-1'      => __( '1:1 Square', 'ggm-commerce' ),
			'4-3'      => __( '4:3', 'ggm-commerce' ),
			'3-2'      => __( '3:2', 'ggm-commerce' ),
			'16-9'     => __( '16:9', 'ggm-commerce' ),
		],
		'condition' => [
			'layout_preset!' => 'masonry',
		],
	]
);

$this->end_controls_section();

// -------------------------------------------------------------------------
// Load More section
// -------------------------------------------------------------------------
$this->start_controls_section(
	'load_more_section',
	[
		'label' => __( 'Load More', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	]
);

$this->add_control(
	'enable_load_more',
	[
		'label'        => __( 'Limit Visible Rows', 'ggm-commerce' ),
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'label_on'     => __( 'Yes', 'ggm-commerce' ),
		'label_off'    => __( 'No', 'ggm-commerce' ),
		'return_value' => 'yes',
		'default'      => '',
		'description'  => __( 'Show a limited number of rows initially with a link to reveal the rest.', 'ggm-commerce' ),
	]
);

$this->add_control(
	'initial_rows',
	[
		'label'     => __( 'Initial Rows', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::NUMBER,
		'min'       => 1,
		'max'       => 10,
		'default'   => 2,
		'condition' => [ 'enable_load_more' => 'yes' ],
	]
);

$this->end_controls_section();

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

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

$this->end_controls_section();

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

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

$this->end_controls_section();
