<?php
namespace EACCustomWidgets\Includes\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Border;

trait Badges_Trait {

	/** Badge Stock */
	protected function register_stock_content_controls() {

		$this->add_control(
			'stock_text',
			array(
				'label'       => esc_html__( 'Text', 'eac-components' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'ai'          => array( 'active' => false ),
				'label_block' => false,
				'default'     => esc_html__( 'Out of stock', 'eac-components' ),
			)
		);

		$start = is_rtl() ? 'end' : 'start';
		$end   = is_rtl() ? 'start' : 'end';
		$this->add_control(
			'stock_position',
			array(
				'label'        => esc_html__( 'Position', 'eac-components' ),
				'type'         => Controls_Manager::CHOOSE,
				'options'      => array(
					'left'  => array(
						'title' => is_rtl() ? esc_html__( 'Right', 'eac-components' ) : esc_html__( 'Left', 'eac-components' ),
						'icon'  => "eicon-order-{$start}",
					),
					'right' => array(
						'title' => is_rtl() ? esc_html__( 'Left', 'eac-components' ) : esc_html__( 'Right', 'eac-components' ),
						'icon'  => "eicon-order-{$end}",
					),
				),
				'default'      => 'left',
				'prefix_class' => 'badge-stock-pos-',
			)
		);
	}

	protected function register_stock_style_controls() {

		$this->add_control(
			'stock_color',
			array(
				'label'     => esc_html__( 'Color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
				'selectors' => array( '{{WRAPPER}} .badge-stock' => 'color: {{VALUE}};' ),
			)
		);

		$this->add_control(
			'stock_bg',
			array(
				'label'     => esc_html__( 'Background color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_SECONDARY ),
				'selectors' => array( '{{WRAPPER}} .badge-stock' => 'background-color: {{VALUE}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'stock_typo',
				'label'    => esc_html__( 'Typography', 'eac-components' ),
				'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ),
				'selector' => '{{WRAPPER}} .badge-stock',
			)
		);

		$this->add_control(
			'stock_width',
			array(
				'label'     => esc_html__( 'Width', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 250,
				'step'      => 5,
				'default'   => 90,
				'selectors' => array( '{{WRAPPER}} .badge-stock' => 'inline-size: {{VALUE}}px;' ),
				'separator' => 'before',
			)
		);

		$this->add_control(
			'stock_height',
			array(
				'label'     => esc_html__( 'Height', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 100,
				'step'      => 5,
				'default'   => 25,
				'selectors' => array( '{{WRAPPER}} .badge-stock' => 'block-size: {{VALUE}}px;' ),
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'stock_border',
				'selector' => '{{WRAPPER}} .badge-stock',
			)
		);

		$this->add_control(
			'stock_radius',
			array(
				'label'              => esc_html__( 'Border radius', 'eac-components' ),
				'type'               => Controls_Manager::DIMENSIONS,
				'size_units'         => array( 'px', '%' ),
				'allowed_dimensions' => array( 'top', 'right', 'bottom', 'left' ),
				'default'            => array(
					'top'      => 0,
					'right'    => 0,
					'bottom'   => 0,
					'left'     => 0,
					'unit'     => 'px',
					'isLinked' => true,
				),
				'selectors'          => array(
					'{{WRAPPER}} .badge-stock' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
	}

	/** Badge Sale */
	protected function register_sale_content_controls() {

		$this->add_control(
			'sale_format',
			array(
				'label'   => esc_html__( 'Percentage', 'eac-components' ),
				'type'    => Controls_Manager::CHOOSE,
				'options' => array(
					'yes' => array(
						'title' => esc_html__( 'Yes', 'eac-components' ),
						'icon'  => 'eicon-check',
					),
					'no'  => array(
						'title' => esc_html__( 'No', 'eac-components' ),
						'icon'  => 'eicon-ban',
					),
				),
				'default' => 'no',
				'toggle'  => false,
			)
		);

		$this->add_control(
			'sale_text',
			array(
				'label'       => esc_html__( 'Text', 'eac-components' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'ai'          => array( 'active' => false ),
				'label_block' => false,
				'default'     => esc_html__( 'Sale!', 'eac-components' ),
				'condition'   => array( 'sale_format' => 'no' ),
			)
		);

		$start = is_rtl() ? 'end' : 'start';
		$end   = is_rtl() ? 'start' : 'end';
		$this->add_control(
			'sale_position',
			array(
				'label'        => esc_html__( 'Position', 'eac-components' ),
				'type'         => Controls_Manager::CHOOSE,
				'options'      => array(
					'left'  => array(
						'title' => is_rtl() ? esc_html__( 'Right', 'eac-components' ) : esc_html__( 'Left', 'eac-components' ),
						'icon'  => "eicon-order-{$start}",
					),
					'right' => array(
						'title' => is_rtl() ? esc_html__( 'Left', 'eac-components' ) : esc_html__( 'Right', 'eac-components' ),
						'icon'  => "eicon-order-{$end}",
					),
				),
				'default'      => 'left',
				'prefix_class' => 'badge-sale-pos-',
			)
		);
	}

	protected function register_sale_style_controls() {

		$this->add_control(
			'sale_color',
			array(
				'label'     => esc_html__( 'Color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
				'selectors' => array( '{{WRAPPER}} .badge-sale' => 'color: {{VALUE}};' ),
			)
		);

		$this->add_control(
			'sale_bg',
			array(
				'label'     => esc_html__( 'Background color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_SECONDARY ),
				'selectors' => array( '{{WRAPPER}} .badge-sale' => 'background-color: {{VALUE}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'sale_typo',
				'label'    => esc_html__( 'Typography', 'eac-components' ),
				'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ),
				'selector' => '{{WRAPPER}} .badge-sale',
			)
		);

		$this->add_control(
			'sale_width',
			array(
				'label'     => esc_html__( 'Width', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 250,
				'step'      => 5,
				'default'   => 90,
				'selectors' => array( '{{WRAPPER}} .badge-sale' => 'inline-size: {{VALUE}}px;' ),
				'separator' => 'before',
			)
		);

		$this->add_control(
			'sale_height',
			array(
				'label'     => esc_html__( 'Height', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 100,
				'step'      => 5,
				'default'   => 25,
				'selectors' => array( '{{WRAPPER}} .badge-sale' => 'block-size: {{VALUE}}px;' ),
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'sale_border',
				'selector' => '{{WRAPPER}} .badge-sale',
			)
		);

		$this->add_control(
			'sale_radius',
			array(
				'label'              => esc_html__( 'Border radius', 'eac-components' ),
				'type'               => Controls_Manager::DIMENSIONS,
				'size_units'         => array( 'px', '%' ),
				'allowed_dimensions' => array( 'top', 'right', 'bottom', 'left' ),
				'default'            => array(
					'top'      => 0,
					'right'    => 0,
					'bottom'   => 0,
					'left'     => 0,
					'unit'     => 'px',
					'isLinked' => true,
				),
				'selectors'          => array(
					'{{WRAPPER}} .badge-sale' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
	}

	/** Badge New */
	protected function register_new_content_controls() {

		$this->add_control(
			'new_text',
			array(
				'label'       => esc_html__( 'Text', 'eac-components' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'ai'          => array( 'active' => false ),
				'default'     => esc_html__( 'New', 'eac-components' ),
				'label_block' => false,
			)
		);

		$this->add_control(
			'new_date',
			array(
				'label'       => esc_html__( 'Number of days', 'eac-components' ),
				'type'        => Controls_Manager::TEXT,
				'ai'          => array( 'active' => false ),
				'description' => esc_html__( "The badge will be displayed for 'Number of days' after the product sheet has been created", 'eac-components' ),
				'label_block' => false,
			)
		);

		$start = is_rtl() ? 'end' : 'start';
		$end   = is_rtl() ? 'start' : 'end';
		$this->add_control(
			'new_position',
			array(
				'label'        => esc_html__( 'Position', 'eac-components' ),
				'type'         => Controls_Manager::CHOOSE,
				'options'      => array(
					'left'  => array(
						'title' => is_rtl() ? esc_html__( 'Right', 'eac-components' ) : esc_html__( 'Left', 'eac-components' ),
						'icon'  => "eicon-order-{$start}",
					),
					'right' => array(
						'title' => is_rtl() ? esc_html__( 'Left', 'eac-components' ) : esc_html__( 'Right', 'eac-components' ),
						'icon'  => "eicon-order-{$end}",
					),
				),
				'default'      => 'left',
				'prefix_class' => 'badge-new-pos-',
			)
		);
	}

	protected function register_new_style_controls() {

		$this->add_control(
			'new_color',
			array(
				'label'     => esc_html__( 'Color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_PRIMARY ),
				'selectors' => array( '{{WRAPPER}} .badge-new' => 'color: {{VALUE}};' ),
			)
		);

		$this->add_control(
			'new_bg',
			array(
				'label'     => esc_html__( 'Background color', 'eac-components' ),
				'type'      => Controls_Manager::COLOR,
				'global'    => array( 'default' => Global_Colors::COLOR_SECONDARY ),
				'selectors' => array( '{{WRAPPER}} .badge-new' => 'background-color: {{VALUE}};' ),
			)
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'new_typo',
				'label'    => esc_html__( 'Typography', 'eac-components' ),
				'global'   => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ),
				'selector' => '{{WRAPPER}} .badge-new',
			)
		);

		$this->add_control(
			'new_width',
			array(
				'label'     => esc_html__( 'Width', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 250,
				'step'      => 5,
				'default'   => 90,
				'selectors' => array( '{{WRAPPER}} .badge-new' => 'inline-size: {{VALUE}}px;' ),
				'separator' => 'before',
			)
		);

		$this->add_control(
			'new_height',
			array(
				'label'     => esc_html__( 'Height', 'eac-components' ),
				'type'      => Controls_Manager::NUMBER,
				'min'       => 10,
				'max'       => 100,
				'step'      => 5,
				'default'   => 25,
				'selectors' => array( '{{WRAPPER}} .badge-new' => 'block-size: {{VALUE}}px;' ),
			)
		);

		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'new_border',
				'selector' => '{{WRAPPER}} .badge-new',
			)
		);

		$this->add_control(
			'new_radius',
			array(
				'label'              => esc_html__( 'Border radius', 'eac-components' ),
				'type'               => Controls_Manager::DIMENSIONS,
				'size_units'         => array( 'px', '%' ),
				'allowed_dimensions' => array( 'top', 'right', 'bottom', 'left' ),
				'default'            => array(
					'top'      => 0,
					'right'    => 0,
					'bottom'   => 0,
					'left'     => 0,
					'unit'     => 'px',
					'isLinked' => true,
				),
				'selectors'          => array(
					'{{WRAPPER}} .badge-new' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
	}
}
