<?php
/**
 * Product Barcode Widget - Style Controls
 *
 * @package GGM_Commerce
 */

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

// $this is the GGM_Commerce_Widget_Product_Barcode instance.

// ── Label ─────────────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_label_style',
	array(
		'label' => 'Label',
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_control(
	'label_color',
	array(
		'label'     => 'Color',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#666666',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-barcode-label' => 'color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'label_typography',
		'label'    => 'Typography',
		'selector' => '{{WRAPPER}} .ggmc-barcode-label',
	)
);

$this->add_responsive_control(
	'label_spacing',
	array(
		'label'      => 'Spacing',
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 50,
			),
		),
		'default'    => array(
			'unit' => 'px',
			'size' => 5,
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-barcode-label' => 'margin-right: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}}.layout-stacked .ggmc-barcode-label' => 'margin-right: 0; margin-bottom: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Barcode Value ─────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_value_style',
	array(
		'label' => 'Barcode Value',
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_control(
	'value_color',
	array(
		'label'     => 'Color',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#333333',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-barcode-value' => 'color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'value_typography',
		'label'    => 'Typography',
		'selector' => '{{WRAPPER}} .ggmc-barcode-value',
	)
);

$this->add_control(
	'value_background',
	array(
		'label'     => 'Background',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#f5f5f5',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-barcode-value' => 'background-color: {{VALUE}};',
		),
	)
);

$this->add_responsive_control(
	'value_padding',
	array(
		'label'      => 'Padding',
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', 'em' ),
		'default'    => array(
			'top'    => 4,
			'right'  => 8,
			'bottom' => 4,
			'left'   => 8,
			'unit'   => 'px',
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-barcode-value' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->add_control(
	'value_border_radius',
	array(
		'label'      => 'Border Radius',
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 20,
			),
		),
		'default'    => array(
			'unit' => 'px',
			'size' => 3,
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-barcode-value' => 'border-radius: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Type Badge ────────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_type_style',
	array(
		'label'     => 'Type Badge',
		'tab'       => \Elementor\Controls_Manager::TAB_STYLE,
		'condition' => array(
			'show_barcode_type' => 'yes',
		),
	)
);

$this->add_control(
	'type_color',
	array(
		'label'     => 'Color',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#ffffff',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-barcode-type' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'type_background',
	array(
		'label'     => 'Background',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '#667eea',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-barcode-type' => 'background-color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'type_typography',
		'label'    => 'Typography',
		'selector' => '{{WRAPPER}} .ggmc-barcode-type',
	)
);

$this->end_controls_section();

// ── Container ─────────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_container_style',
	array(
		'label' => 'Container',
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_responsive_control(
	'container_padding',
	array(
		'label'      => 'Padding',
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', 'em' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-product-barcode' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->add_control(
	'container_background',
	array(
		'label'     => 'Background',
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-product-barcode' => 'background-color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Border::get_type(),
	array(
		'name'     => 'container_border',
		'label'    => 'Border',
		'selector' => '{{WRAPPER}} .ggmc-product-barcode',
	)
);

$this->add_control(
	'container_border_radius',
	array(
		'label'      => 'Border Radius',
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 20,
			),
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-product-barcode' => 'border-radius: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->add_responsive_control(
	'item_spacing',
	array(
		'label'      => 'Item Spacing',
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 30,
			),
		),
		'default'    => array(
			'unit' => 'px',
			'size' => 10,
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-barcode-item:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}};',
		),
		'condition'  => array(
			'barcode_display' => 'all',
		),
	)
);

$this->end_controls_section();
