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

// === STYLE TAB ===
$this->start_controls_section(
	'price_style_section',
	[
		'label' => 'Price',
		'tab' => \Elementor\Controls_Manager::TAB_STYLE,
	]
);

// Alignment Control
$this->add_control(
	'alignment',
	[
		'label' => 'Alignment',
		'type' => \Elementor\Controls_Manager::CHOOSE,
		'options' => [
			'left' => ['title' => 'Left', 'icon' => 'eicon-text-align-left'],
			'center' => ['title' => 'Center', 'icon' => 'eicon-text-align-center'],
			'right' => ['title' => 'Right', 'icon' => 'eicon-text-align-right'],
		],
		'default' => 'left',
		'selectors' => [
			'{{WRAPPER}}' => 'text-align: {{VALUE}};',
		],
	]
);

// Typography Group Control
$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	[
		'name' => 'price_typography',
		'selector' => '{{WRAPPER}} .product-price',
		'fields_options' => [
			'typography' => [
				'default' => 'custom',
			],
			'font_family' => [
				'default' => "'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
			],
			'font_size' => [
				'default' => [
					'size' => 24,
					'unit' => 'px',
				],
			],
			'font_weight' => [
				'default' => '700',
			],
			'letter_spacing' => [
				'default' => [
					'size' => -0.025,
					'unit' => 'em',
				],
			],
		],
	]
);

// Regular Price Color
$this->add_control(
	'price_color',
	[
		'label' => 'Regular Price Color',
		'type' => \Elementor\Controls_Manager::COLOR,
		'selectors' => [
			'{{WRAPPER}} .product-price .current-price' => 'color: {{VALUE}};',
		],
	]
);

// Sale Price Color (plugin-specific)
$this->add_control(
	'sale_price_color',
	[
		'label' => 'Sale Price Color',
		'type' => \Elementor\Controls_Manager::COLOR,
		'selectors' => [
			'{{WRAPPER}} .product-price .sale-price' => 'color: {{VALUE}};',
		],
	]
);

// Original Price Color (crossed out)
$this->add_control(
	'original_price_color',
	[
		'label' => 'Original Price Color',
		'type' => \Elementor\Controls_Manager::COLOR,
		'selectors' => [
			'{{WRAPPER}} .product-price .original-price' => 'color: {{VALUE}};',
		],
	]
);

// ===== VARIABLE PRICE SECTION =====
$this->add_control(
	'variable_price_heading',
	[
		'label' => __('Variable Price', 'ggm-commerce'),
		'type' => \Elementor\Controls_Manager::HEADING,
		'separator' => 'before',
	]
);

// From Label Color
$this->add_control(
	'from_label_color',
	[
		'label' => 'From Label Color',
		'type' => \Elementor\Controls_Manager::COLOR,
		'selectors' => [
			'{{WRAPPER}} .product-price .price-from-label' => 'color: {{VALUE}};',
		],
	]
);

// From Label Typography
$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	[
		'name' => 'from_label_typography',
		'selector' => '{{WRAPPER}} .product-price .price-from-label',
		'fields_options' => [
			'font_size' => [
				'default' => [
					'size' => 14,
					'unit' => 'px',
				],
			],
			'font_weight' => [
				'default' => '400',
			],
		],
	]
);

// Range Separator Color
$this->add_control(
	'range_separator_color',
	[
		'label' => 'Range Separator Color',
		'type' => \Elementor\Controls_Manager::COLOR,
		'selectors' => [
			'{{WRAPPER}} .product-price .price-range-separator' => 'color: {{VALUE}};',
		],
	]
);

// ===== SPACING SECTION =====
$this->add_control(
	'spacing_heading',
	[
		'label' => __('Spacing', 'ggm-commerce'),
		'type' => \Elementor\Controls_Manager::HEADING,
		'separator' => 'before',
	]
);

$this->add_responsive_control(
	'margin',
	[
		'label' => __('Margin', 'ggm-commerce'),
		'type' => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => ['px', '%', 'em'],
		'default' => [
			'top' => '0',
			'right' => '0',
			'bottom' => '16',
			'left' => '0',
			'unit' => 'px',
			'isLinked' => false,
		],
		'selectors' => [
			'{{WRAPPER}} .product-price' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		],
	]
);

$this->add_responsive_control(
	'padding',
	[
		'label' => __('Padding', 'ggm-commerce'),
		'type' => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => ['px', '%', 'em'],
		'default' => [
			'top' => '0',
			'right' => '0',
			'bottom' => '0',
			'left' => '0',
			'unit' => 'px',
			'isLinked' => false,
		],
		'selectors' => [
			'{{WRAPPER}} .product-price' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		],
	]
);

$this->end_controls_section();
