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

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

// $this is the GGM_Commerce_Widget_Product_Rating instance.

// ── Stars Style ───────────────────────────────────────────────────────────────

$this->start_controls_section(
	'stars_style_section',
	array(
		'label' => __( 'Stars Style', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_control(
	'star_size',
	array(
		'label'      => __( 'Star Size', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px', 'em' ),
		'range'      => array(
			'px' => array(
				'min' => 10,
				'max' => 50,
			),
			'em' => array(
				'min'  => 0.5,
				'max'  => 3,
				'step' => 0.1,
			),
		),
		'default'   => array(
			'unit' => 'px',
			'size' => 18,
		),
		'selectors' => array(
			'{{WRAPPER}} .ggmc-star' => 'font-size: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->add_control(
	'star_spacing',
	array(
		'label'      => __( 'Star Spacing', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 20,
			),
		),
		'default'   => array(
			'unit' => 'px',
			'size' => 2,
		),
		'selectors' => array(
			'{{WRAPPER}} .ggmc-star'            => 'margin-right: {{SIZE}}{{UNIT}};',
			'{{WRAPPER}} .ggmc-star:last-child' => 'margin-right: 0;',
		),
	)
);

$this->add_control(
	'filled_star_color',
	array(
		'label'     => __( 'Filled Star Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-star-full' => 'color: {{VALUE}};',
			'{{WRAPPER}} .ggmc-star-half' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'empty_star_color',
	array(
		'label'     => __( 'Empty Star Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-star-empty' => 'color: {{VALUE}};',
		),
	)
);

$this->end_controls_section();

// ── Text Style ────────────────────────────────────────────────────────────────

$this->start_controls_section(
	'text_style_section',
	array(
		'label' => __( 'Text Style', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'text_typography',
		'selector' => '{{WRAPPER}} .ggmc-rating-text',
	)
);

$this->add_control(
	'text_color',
	array(
		'label'     => __( 'Text Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-rating-text' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'average_color',
	array(
		'label'     => __( 'Average Rating Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-rating-average' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'text_spacing',
	array(
		'label'      => __( 'Spacing from Stars', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 30,
			),
		),
		'default'   => array(
			'unit' => 'px',
			'size' => 8,
		),
		'selectors' => array(
			'{{WRAPPER}} .ggmc-rating-text' => 'margin-left: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Hover Style ───────────────────────────────────────────────────────────────

$this->start_controls_section(
	'hover_style_section',
	array(
		'label'     => __( 'Hover Style', 'ggm-commerce' ),
		'tab'       => \Elementor\Controls_Manager::TAB_STYLE,
		'condition' => array(
			'link_to_reviews' => 'yes',
		),
	)
);

$this->add_control(
	'hover_star_color',
	array(
		'label'     => __( 'Stars Hover Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-product-rating-link:hover .ggmc-star-full' => 'color: {{VALUE}};',
			'{{WRAPPER}} .ggmc-product-rating-link:hover .ggmc-star-half' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'hover_text_color',
	array(
		'label'     => __( 'Text Hover Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'selectors' => array(
			'{{WRAPPER}} .ggmc-product-rating-link:hover .ggmc-rating-text' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'hover_transition',
	array(
		'label'   => __( 'Transition Duration', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SLIDER,
		'default' => array(
			'size' => 0.3,
			'unit' => 's',
		),
		'range'     => array(
			's' => array(
				'min'  => 0,
				'max'  => 1,
				'step' => 0.1,
			),
		),
		'selectors' => array(
			'{{WRAPPER}} .ggmc-star, {{WRAPPER}} .ggmc-rating-text' => 'transition: color {{SIZE}}s ease;',
		),
	)
);

$this->end_controls_section();
