<?php

/**
 * Cart Widget.
 *
 * @since 1.10.0
 */

use \Elementor\Widget_Base;
use \Elementor\Controls_Manager;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Repeater;

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

class Sina_Ext_Pro_Cart_Widget extends Widget_Base{

	/**
	 * Get widget name.
	 *
	 * @since 1.10.0
	 */
	public function get_name() {
		return 'sina_ext_pro_cart';
	}

	/**
	 * Get widget title.
	 *
	 * @since 1.10.0
	 */
	public function get_title() {
		return esc_html__( 'Sina Cart', 'sina-ext-pro' );
	}

	/**
	 * Get widget icon.
	 *
	 * @since 1.10.0
	 */
	public function get_icon() {
		return 'eicon-cart-light';
	}

	/**
	 * Get widget categories.
	 *
	 * @since 1.10.0
	 */
	public function get_categories() {
		return [ 'sina-ext-pro-woocommerce' ];
	}

	/**
	 * Get widget keywords.
	 *
	 * Retrieve the list of keywords the widget belongs to.
	 *
	 * @since 1.10.0
	 */
	public function get_keywords() {
		return [ 'sina shop', 'sina product', 'sina cart', 'woocommerce shop', 'woocommerce cart', 'woocommerce product' ];
	}

	/**
	 * Get widget styles.
	 *
	 * Retrieve the list of styles the widget belongs to.
	 *
	 * @since 1.10.0
	 */
	public function get_style_depends() {
		return [
			'sina-ext-pro-widgets',
		];
	}

	/**
	 * Register widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.10.0
	 */
	protected function register_controls() {
		// Start Cart Content
		// ===================
			$this->start_controls_section(
				'wc_cart_content',
				[
					'label' => esc_html__( 'Content', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_CONTENT,
				]
			);

			$this->add_control(
				'wc_cart_apply',
				[
					'type' => Controls_Manager::RAW_HTML,
					'raw' => '<div class="elementor-update-preview" style="background: rgba(0,0,0,0);margin: 0;"><div class="elementor-update-preview-title">Refresh?</div><div class="elementor-update-preview-button-wrapper"><button class="elementor-update-preview-button elementor-button elementor-button-success">Yes</button></div></div>',
				]
			);

			$this->end_controls_section();
		// End Cart Content
		// =================


		// Start Title Styles
		// ===================
			Sina_Pro_Woo_Common_Data::checkout_title_styles($this, '.sina-pro-wc-cart h2');
		// End Title Styles
		// =================


		// Start Fields Styles
		// ======================
			$this->start_controls_section(
				'wc_fields_style',
				[
					'label' => esc_html__( 'Fields', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			$this->add_control(
				'wc_fields_color',
				[
					'label' => esc_html__( 'Color', 'sina-ext-pro' ),
					'type' => Controls_Manager::COLOR,
					'default' => '#aaa',
					'selectors' => [
						'{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart td.actions .input-text, {{WRAPPER}} .sina-pro-wc-cart .quantity input' => 'color: {{VALUE}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Background::get_type(),
				[
					'name' => 'wc_fields_bg',
					'types' => [ 'classic', 'gradient' ],
					'fields_options' => [
						'background' => [ 
							'default' =>'classic', 
						],
						'color' => [
							'default' => '#fff',
						],
					],
					'selector' => '{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart td.actions .input-text, {{WRAPPER}} .sina-pro-wc-cart .quantity input',
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'wc_fields_border',
					'fields_options' => [
						'border' => [
							'default' => 'solid',
						],
						'color' => [
							'default' => '#ccc',
						],
						'width' => [
							'default' => [
								'top' => '1',
								'right' => '1',
								'bottom' => '1',
								'left' => '1',
								'isLinked' => true,
							]
						],
					],
					'selector' => '{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart td.actions .input-text, {{WRAPPER}} .sina-pro-wc-cart .quantity input',
				]
			);
			$this->add_responsive_control(
				'wc_fields_radius',
				[
					'label' => esc_html__( 'Radius', 'sina-ext-pro' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', 'em', '%' ],
					'default' => [
						'top' => '4',
						'right' => '4',
						'bottom' => '4',
						'left' => '4',
						'isLinked' => true,
					],
					'selectors' => [
						'{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart td.actions .input-text, {{WRAPPER}} .sina-pro-wc-cart .quantity input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);
			$this->add_responsive_control(
				'wc_fields_padding',
				[
					'label' => esc_html__( 'Padding', 'sina-ext-pro' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', 'em', '%' ],
					'default' => [
						'top' => '8',
						'right' => '8',
						'bottom' => '8',
						'left' => '8',
						'isLinked' => true,
					],
					'selectors' => [
						'{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart td.actions .input-text, {{WRAPPER}} .sina-pro-wc-cart .quantity input' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);

			$this->end_controls_section();
		// End Fields Styles
		// =====================


		// Start Thumbnail Styles
		// ========================
			$this->start_controls_section(
				'wc_thumbnail_style',
				[
					'label' => esc_html__( 'Thumbnail', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			$this->add_control(
				'thumbnail_size',
				[
					'label' => esc_html__( 'Size', 'sina-ext-pro' ),
					'type' => Controls_Manager::SLIDER,
					'size_units' => [ 'px'],
					'default' => [
						'size' => '60',
					],
					'selectors' => [
						'{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart img' => 'width: {{SIZE}}{{UNIT}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				[
					'name' => 'thumbanil_bshadow',
					'selector' => '{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart img',
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'thumbanil__border',
					'selector' => '{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart img',
				]
			);
			$this->add_responsive_control(
				'thumbanil__radius',
				[
					'label' => esc_html__( 'Radius', 'sina-ext-pro' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', 'em', '%' ],
					'default' => [
						'top' => '4',
						'right' => '4',
						'bottom' => '4',
						'left' => '4',
						'isLinked' => true,
					],
					'selectors' => [
						'{{WRAPPER}} .sina-pro-wc-cart .woocommerce table.cart img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
			);

			$this->end_controls_section();
		// End Thumbnail Styles
		// =====================


		// Start Coupon Button Styles
		// ===========================
			$this->start_controls_section(
				'wc_coupon_button_style',
				[
					'label' => esc_html__( 'Coupon Button', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			Sina_Pro_Woo_Common_Data::buttons_styles($this, '.sina-pro-wc-cart button[name="apply_coupon"]', 'wc_coupon_button_');

			$this->end_controls_section();
		// End Coupon Button Styles
		// =========================


		// Start Cart Button Styles
		// ===========================
			$this->start_controls_section(
				'wc_cart_button_style',
				[
					'label' => esc_html__( 'Cart Button', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			Sina_Pro_Woo_Common_Data::buttons_styles($this, '.sina-pro-wc-cart button[name="update_cart"]', 'wc_cart_button_');

			$this->end_controls_section();
		// End Cart Button Styles
		// =========================


		// Start Checkout Button Styles
		// =============================
			$this->start_controls_section(
				'wc_checkout_button_style',
				[
					'label' => esc_html__( 'Checkout Button', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			Sina_Pro_Woo_Common_Data::buttons_styles($this, '.sina-pro-wc-cart a.checkout-button', 'wc_checkout_button_');

			$this->end_controls_section();
		// End Checkout Button Styles
		// ===========================


		// Start Return Button Styles
		// ===========================
			$this->start_controls_section(
				'wc_return_button_style',
				[
					'label' => esc_html__( 'Return Button', 'sina-ext-pro' ),
					'tab' => Controls_Manager::TAB_STYLE,
				]
			);

			Sina_Pro_Woo_Common_Data::buttons_styles($this, '.sina-pro-wc-cart a.wc-backward', 'wc_return_button_');

			$this->end_controls_section();
		// End Return Button Styles
		// =========================
	}


	protected function render() {
		$data = $this->get_settings_for_display();

		if ( class_exists( 'WooCommerce' ) ):
			?>
			<div class="sina-pro-wc-cart">
				<?php echo do_shortcode("[woocommerce_cart]"); ?>
			</div>
			<?php
		else:
			printf('<h3>%s</h3>', esc_html__('Please install and activate the WooCommerce plugin to use this feature!', 'sina-ext-pro') );
		endif;
	}


	protected function content_template() {

	}
}
