<?php
/**
 * Recently Viewed Widget - Style Controls
 *
 * @package GGM_Commerce
 */

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

// $this is the GGM_Commerce_Widget_Recently_Viewed instance.

// ── Title ─────────────────────────────────────────────────────────────────────

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

$this->add_control(
	'title_color',
	array(
		'label'     => __( 'Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-title' => 'color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'title_typography',
		'label'    => __( 'Typography', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-title',
	)
);

$this->add_responsive_control(
	'title_margin',
	array(
		'label'      => __( 'Margin', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', 'em', '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Grid ──────────────────────────────────────────────────────────────────────

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

$this->add_responsive_control(
	'gap',
	array(
		'label'      => __( 'Gap Between Items', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::SLIDER,
		'size_units' => array( 'px', 'em' ),
		'range'      => array(
			'px' => array(
				'min' => 0,
				'max' => 60,
			),
			'em' => array(
				'min' => 0,
				'max' => 4,
			),
		),
		'default'    => array(
			'size' => 20,
			'unit' => 'px',
		),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-grid' => 'gap: {{SIZE}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Product Card ──────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_card_style',
	array(
		'label' => __( 'Product Card', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_control(
	'card_background',
	array(
		'label'     => __( 'Background Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item' => 'background-color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Border::get_type(),
	array(
		'name'     => 'card_border',
		'label'    => __( 'Border', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-item',
	)
);

$this->add_responsive_control(
	'card_border_radius',
	array(
		'label'      => __( 'Border Radius', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Box_Shadow::get_type(),
	array(
		'name'     => 'card_box_shadow',
		'label'    => __( 'Box Shadow', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-item',
	)
);

$this->add_responsive_control(
	'card_padding',
	array(
		'label'      => __( 'Content Padding', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', 'em', '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Product Name ──────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_name_style',
	array(
		'label' => __( 'Product Name', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

$this->add_control(
	'name_color',
	array(
		'label'     => __( 'Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-name a' => 'color: {{VALUE}};',
		),
	)
);

$this->add_control(
	'name_hover_color',
	array(
		'label'     => __( 'Hover Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-name a:hover' => 'color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'name_typography',
		'label'    => __( 'Typography', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-item-name',
	)
);

$this->add_responsive_control(
	'name_margin',
	array(
		'label'      => __( 'Margin', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', 'em', '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-name' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->end_controls_section();

// ── Price ─────────────────────────────────────────────────────────────────────

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

$this->add_control(
	'price_color',
	array(
		'label'     => __( 'Color', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::COLOR,
		'default'   => '',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-price' => 'color: {{VALUE}};',
		),
	)
);

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'price_typography',
		'label'    => __( 'Typography', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-item-price',
	)
);

$this->end_controls_section();

// ── Image ─────────────────────────────────────────────────────────────────────

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

$this->add_responsive_control(
	'image_border_radius',
	array(
		'label'      => __( 'Border Radius', 'ggm-commerce' ),
		'type'       => \Elementor\Controls_Manager::DIMENSIONS,
		'size_units' => array( 'px', '%' ),
		'selectors'  => array(
			'{{WRAPPER}} .ggmc-recently-viewed-item-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		),
	)
);

$this->add_control(
	'image_hover_effect',
	array(
		'label'   => __( 'Hover Effect', 'ggm-commerce' ),
		'type'    => \Elementor\Controls_Manager::SELECT,
		'default' => 'zoom',
		'options' => array(
			'none'   => __( 'None', 'ggm-commerce' ),
			'zoom'   => __( 'Zoom', 'ggm-commerce' ),
			'fade'   => __( 'Fade', 'ggm-commerce' ),
		),
	)
);

$this->end_controls_section();

// ── Empty State ───────────────────────────────────────────────────────────────

$this->start_controls_section(
	'section_empty_style',
	array(
		'label' => __( 'Empty State', 'ggm-commerce' ),
		'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
	)
);

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

$this->add_group_control(
	\Elementor\Group_Control_Typography::get_type(),
	array(
		'name'     => 'empty_typography',
		'label'    => __( 'Typography', 'ggm-commerce' ),
		'selector' => '{{WRAPPER}} .ggmc-recently-viewed-empty',
	)
);

$this->add_responsive_control(
	'empty_text_align',
	array(
		'label'     => __( 'Text Align', 'ggm-commerce' ),
		'type'      => \Elementor\Controls_Manager::CHOOSE,
		'options'   => array(
			'left'   => array(
				'title' => __( 'Left', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-left',
			),
			'center' => array(
				'title' => __( 'Center', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-center',
			),
			'right'  => array(
				'title' => __( 'Right', 'ggm-commerce' ),
				'icon'  => 'eicon-text-align-right',
			),
		),
		'default'   => 'center',
		'selectors' => array(
			'{{WRAPPER}} .ggmc-recently-viewed-empty' => 'text-align: {{VALUE}};',
		),
	)
);

$this->end_controls_section();

// ── Add to Cart Button ────────────────────────────────────────────────────────

GGM_Add_To_Cart_Controls::register(
	$this,
	array(
		'selector'      => '.ggmc-recently-viewed-add-to-cart',
		'prefix'        => 'button',
		'section_id'    => 'section_button_style',
		'section_label' => __( 'Add to Cart Button', 'ggm-commerce' ),
		'include_icon'  => false,
		'condition'     => array( 'show_add_to_cart' => 'yes' ),
	)
);
