<?php
/**
 * Variation Selector Widget - Content Controls
 *
 * @package GGM_Commerce
 */

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

// $this is the GGM_Commerce_Widget_Variation_Selector instance.

// Content Section.
$this->start_controls_section(
	'section_content',
	array(
		'label' => 'Content',
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'product_id',
	array(
		'label'       => 'Product ID',
		'type'        => \Elementor\Controls_Manager::NUMBER,
		'default'     => '',
		'description' => 'Leave empty to use current product from URL.',
	)
);

$this->add_control(
	'show_attribute_label',
	array(
		'label'        => 'Show Attribute Labels',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
	)
);

$this->add_control(
	'show_selected_value',
	array(
		'label'        => 'Show Selected Value',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
		'description'  => 'Display the selected value next to attribute label.',
	)
);

$this->add_control(
	'hide_out_of_stock',
	array(
		'label'        => 'Hide Out of Stock',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => '',
		'label_on'     => 'Hide',
		'label_off'    => 'Show',
		'return_value' => 'yes',
		'description'  => 'Hide variations that are out of stock.',
	)
);

$this->add_control(
	'show_price_change',
	array(
		'label'        => 'Show Price Change',
		'type'         => \Elementor\Controls_Manager::SWITCHER,
		'default'      => 'yes',
		'label_on'     => 'Show',
		'label_off'    => 'Hide',
		'return_value' => 'yes',
		'description'  => 'Show price difference when selecting variations.',
	)
);

$this->add_control(
	'clear_selection_text',
	array(
		'label'   => 'Clear Selection Text',
		'type'    => \Elementor\Controls_Manager::TEXT,
		'default' => 'Clear',
	)
);

$this->end_controls_section();

// Display Settings Section.
$this->start_controls_section(
	'section_display',
	array(
		'label' => 'Display Settings',
		'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
	)
);

$this->add_control(
	'default_display_type',
	array(
		'label'       => 'Default Display Type',
		'type'        => \Elementor\Controls_Manager::SELECT,
		'default'     => 'auto',
		'options'     => array(
			'auto'     => 'Auto (from attribute type)',
			'select'   => 'Dropdown',
			'buttons'  => 'Buttons',
			'swatches' => 'Swatches (color/image)',
		),
		'description' => 'Override how attributes are displayed.',
	)
);

$this->add_control(
	'swatch_size',
	array(
		'label'      => 'Swatch Size',
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min'  => 20,
				'max'  => 80,
				'step' => 2,
			),
		),
		'default'    => array(
			'unit' => 'px',
			'size' => 36,
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-variation-swatch' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->add_control(
	'button_layout',
	array(
		'label'   => 'Button Layout',
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'inline',
		'options' => array(
			'inline' => 'Inline',
			'grid'   => 'Grid',
		),
	)
);

$this->add_responsive_control(
	'buttons_per_row',
	array(
		'label'     => 'Buttons Per Row',
		'type'      => \Elementor\Controls_Manager::SELECT,
		'default'   => '4',
		'options'   => array(
			'2' => '2',
			'3' => '3',
			'4' => '4',
			'5' => '5',
			'6' => '6',
		),
		'condition' => array(
			'button_layout' => 'grid',
		),
		'selectors' => array(
			'{{WRAPPER}} .ggmc-variation-options.layout-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);',
		),
	)
);

$this->end_controls_section();
