<?php
namespace Prodigy\Includes\Support\Addons\Elementor\Widgets\Product;

use Elementor\Controls_Manager;
use Prodigy\includes\helpers\Prodigy_Elementor;

if ( ! defined( 'ABSPATH' ) ) {
	die( '-1' );
}

/**
 * @version 2.0.7
 */
class Prodigy_Price_Range extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve oEmbed widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'pae-price-range';
	}


	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the oEmbed widget belongs to.
	 *
	 * @return array Widget categories.
	 * @since 1.0.0
	 * @access public
	 */
	public function get_categories() {
		return array( 'prodigy-elements-single' );
	}

	/**
	 * Get widget price-range.
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Price Range', 'prodigy-commerce' );
	}

	/**
	 * Get widget icon.
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'prgicon prgicon-price-range';
	}

	/**
	 * Register oEmbed widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 */
	protected function register_controls() {
		/*
		 * General
		 */
		$this->start_controls_section(
			'prg_style_price_range',
			array(
				'label' => __( 'General', 'prodigy-commerce' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_control(
			'prg_price_range_show_sale',
			array(
				'label'       => __( 'Show original price for on sale item', 'prodigy-commerce' ),
				'description' => 'setting to show/hide original price for on sale item',
				'type'        => Controls_Manager::SWITCHER,
				'label_on'    => __( 'Show', 'prodigy-commerce' ),
				'label_off'   => __( 'Hide', 'prodigy-commerce' ),
				'default'     => 'yes',
			)
		);

		$this->add_responsive_control(
			'prg_style_alignment_price_range',
			array(
				'label'           => __( 'Alignment', 'prodigy-commerce' ),
				'type'            => \Elementor\Controls_Manager::SELECT,
				'desktop_default' => 'left',
				'tablet_default'  => 'left',
				'mobile_default'  => 'left',
				'options'         => array(
					'left'   => 'Left',
					'center' => 'Center',
					'right'  => 'Right',
				),
				'selectors'       => array(
					'{{WRAPPER}} .prodigy-product__main-price' => 'text-align: {{VALUE}}',
				),
			)
		);

		$this->add_responsive_control(
			'prg_style_margin_price_range',
			array(
				'label'          => __( 'Margin Bottom', 'prodigy-commerce' ),
				'type'           => \Elementor\Controls_Manager::SLIDER,
				'size_units'     => array( 'px' ),
				'default'        => array(
					'size' => 16,
					'unit' => 'px',
				),
				'tablet_default' => array(
					'size' => 16,
					'unit' => 'px',
				),
				'mobile_default' => array(
					'size' => 16,
					'unit' => 'px',
				),
				'selectors'      => array(
					'{{WRAPPER}} .prodigy-product__main-price' => 'margin-bottom: {{SIZE}}{{UNIT}}',
				),
			)
		);

		$this->end_controls_section();

		/*
		 * Text
		 */
		$this->start_controls_section(
			'prg_style_price_range_text',
			array(
				'label' => __( 'Text', 'prodigy-commerce' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'           => 'prg_price_range_typography',
				'label'          => __( 'Typography', 'prodigy-commerce' ),
				'selector'       => '{{WRAPPER}} .prodigy-product__main-price, .prodigy-product__main-price > *',
				'fields_options' => array(
					'typography'     => array( 'default' => 'yes' ),
					'font_size'      => array(
						'default'        => array(
							'unit' => 'px',
							'size' => 28,
						),
						'tablet_default' => array(
							'unit' => 'px',
							'size' => 28,
						),
						'mobile_default' => array(
							'unit' => 'px',
							'size' => 28,
						),
					),
					'font_weight'    => array(
						'default' => 600,
					),
					'line_height'    => array(
						'default'        => array(
							'unit' => 'em',
							'size' => 1.8,
						),
						'tablet_default' => array(
							'unit' => 'em',
							'size' => 1.8,
						),
						'mobile_default' => array(
							'unit' => 'em',
							'size' => 1.8,
						),
					),
					'letter_spacing' => array(
						'default'        => array(
							'unit' => 'px',
							'size' => 0,
						),
						'tablet_default' => array(
							'unit' => 'px',
							'size' => 0,
						),
						'mobile_default' => array(
							'unit' => 'px',
							'size' => 0,
						),
					),
					'word_spacing'   => array(
						'default'        => array(
							'unit' => 'em',
							'size' => 0,
						),
						'tablet_default' => array(
							'unit' => 'em',
							'size' => 0,
						),
						'mobile_default' => array(
							'unit' => 'em',
							'size' => 0,
						),
					),
				),
			)
		);

		$this->add_control(
			'prg_price_range_color',
			array(
				'label'      => __( 'Color', 'prodigy-commerce' ),
				'type'       => \Elementor\Controls_Manager::COLOR,
				'input_type' => 'color',
				'default'    => '#3a3a3a',
				'selectors'  => array(
					'{{WRAPPER}} .prodigy-product__main-price > *' => 'color: {{VALUE}} !important',
					'{{WRAPPER}} .prodigy-product__main-price' => 'color: {{VALUE}} !important',
				),
			)
		);

		$this->end_controls_section();
	}

	/**
	 * Render oEmbed widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 */
	protected function render() {
		$settings             = $this->get_settings_for_display();
		$sett_prg             = Prodigy_Elementor::clear_widget_params( $settings );
		$sett_prg['idWidget'] = $this->get_id();

		do_action( 'prodigy_single_product_price_range', $sett_prg );
	}
}
