<?php
namespace EcafeAddons\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Css_Filter;
use Elementor\Group_Control_Text_Shadow;

use EcafeAddons\EcafeElementLoad;

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

class Ecafe_Coupon_Code extends Widget_Base {

	public function get_name() {
		return 'ecafe-coupon-code';
	}

	public function get_title() {
		return esc_html__( 'Coupon Code', 'essential-classy-addons-for-elementor' );
	}

	public function get_icon() {
		return 'ecafe-ele-back-icon ecafe-coupon-code-icon';
	}

	public function get_categories() {
		return array( 'essential' );
	}
	public function get_script_depends() {
		return array( 'ecafe-coupon-code' );
	}
	public function get_keywords() {
		return array( 'coupon', 'code', 'coupon code', 'promo code', 'discount code', 'voucher code', 'offer code', 'deal code' );
	}
	public function get_custom_help_url() {
		return 'https://store.kapasias.com/helpdesk/';
	}
	public function has_widget_inner_wrapper(): bool {
		return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
	}
	protected function register_controls() {

		$this->start_controls_section(
			'contentSection',
			array(
				'label' => esc_html__( 'Coupon Code', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'couponCode',
			array(
				'label'       => esc_html__( 'Coupon Code', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'default'     => esc_html__( 'ECADDONS', 'essential-classy-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Enter Code', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'buttonText',
			array(
				'label'       => esc_html__( 'Button Text', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'default'     => esc_html__( 'Copy', 'essential-classy-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Enter Text', 'essential-classy-addons-for-elementor' ),
				'separator'   => 'before',
			)
		);
		$this->add_control(
			'buttonCopiedText',
			array(
				'label'       => esc_html__( 'Button Copied Text', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'default'     => esc_html__( 'Copied', 'essential-classy-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Enter Text', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'couponImage',
			array(
				'label'      => esc_html__( 'Image', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::MEDIA,
				'media_type' => 'image',
				'dynamic'    => array(
					'active' => true,
				),
				'separator'  => 'before',
			)
		);
		$this->add_control(
			'couponTitle',
			array(
				'label'       => esc_html__( 'Title', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => array( 'active' => true ),
				'placeholder' => esc_html__( 'Enter Title', 'essential-classy-addons-for-elementor' ),
				'separator'   => 'before',
			)
		);
		$this->add_control(
			'couponTitleTag',
			array(
				'label'   => esc_html__( 'Title Tag', 'essential-classy-addons-for-elementor' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'h1',
				'options' => \EcafeHelper::getHtmlTag(),
			)
		);
		$this->add_control(
			'couponExtraText',
			array(
				'label'       => esc_html__( 'Extra Text', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => array( 'active' => true ),
				'placeholder' => esc_html__( 'Enter Text', 'essential-classy-addons-for-elementor' ),
				'separator'   => 'before',
			)
		);
		$this->add_control(
			'couponRedirectUrl',
			array(
				'label'       => esc_html__( 'Redirect URL', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::URL,
				'dynamic'     => array( 'active' => true ),
				'placeholder' => esc_html__( 'Enter URl', 'essential-classy-addons-for-elementor' ),
				'separator'   => 'before',
			)
		);
		$this->add_control(
			'couponRedirectUrlType',
			array(
				'label'     => esc_html__( 'Redirect Type', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::SELECT,
				'options'   => array(
					''         => esc_html__( 'New Tab', 'essential-classy-addons-for-elementor' ),
					'redirect' => esc_html__( 'Same Tab', 'essential-classy-addons-for-elementor' ),
				),
				'default'   => '',
				'separator' => 'before',
			)
		);
		$this->add_control(
			'couponDesign',
			array(
				'label'     => esc_html__( 'Design Overlay', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::SELECT,
				'options'   => array(
					''         => esc_html__( 'None', 'essential-classy-addons-for-elementor' ),
					'pattern1' => esc_html__( 'Pattern 1', 'essential-classy-addons-for-elementor' ),
				),
				'default'   => '',
				'separator' => 'before',
			)
		);
		$this->end_controls_section();

		/*Tilt Effect Options*/
		include ECAFE_PATH . 'element/widgets/ecafe-tilt-options.php';

		/*Tippy Tooltip Options*/
		include ECAFE_PATH . 'element/widgets/ecafe-tippy-options.php';

		/*Notice panel*/
		$ecwidgetdemolink = esc_url( 'https://ecaddons.com/elements/coupon-code/' );
		$ecwidgetdoclink  = esc_url( 'https://ecaddons.com/docs/coupon-code-widget-tutorial/' );
		include ECAFE_PATH . 'element/widgets/ecafe-widgetpanel-help.php';

		/*style start*/
		$this->start_controls_section(
			'couponCodeStyling',
			array(
				'label' => esc_html__( 'Coupon Code', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'couponCodeBorder',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-coupon',
			)
		);
		$this->add_responsive_control(
			'couponCodePadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-coupon' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
				'separator'  => 'before',
			)
		);
		$this->add_responsive_control(
			'couponCodeTopBottomGap',
			array(
				'label'      => esc_html__( 'Gap', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => 1,
						'max' => 100,
					),
				),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap' => 'margin:{{SIZE}}{{UNIT}} auto;',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'couponCodeTypo',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-coupon',
			)
		);
		$this->add_control(
			'couponCodeColor',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-coupon' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Text_Shadow::get_type(),
			array(
				'name'     => 'couponCodeTextShadow',
				'label'    => esc_html__( 'Text Shadow', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-coupon',
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'couponCodeButtonStyling',
			array(
				'label' => esc_html__( 'Coupon Code Button', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'ccbPadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccbMargin',
			array(
				'label'      => esc_html__( 'Margin', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccbWidth',
			array(
				'label'      => esc_html__( 'Min. Width', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 1,
						'max' => 300,
					),
					'%'  => array(
						'min'  => 1,
						'max'  => 100,
						'step' => 1,
					),
				),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'min-width:{{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'ccbTypography',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button',
			)
		);
		$this->start_controls_tabs( 'tabsCcbStyle' );
		$this->start_controls_tab(
			'tabCcbN',
			array(
				'label' => esc_html__( 'Normal', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'ccbColorN',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccbBgN',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccbBorderN',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button',
			)
		);
		$this->add_responsive_control(
			'ccbBrN',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccbShadowN',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button',
			)
		);
		$this->add_control(
			'ccbTransitionN',
			array(
				'label'       => esc_html__( 'Transition css', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'all .3s linear', 'essential-classy-addons-for-elementor' ),
				'selectors'   => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'transition:{{VALUE}};',
				),
			)
		);
		$this->add_control(
			'ccbTransformN',
			array(
				'label'       => esc_html__( 'Transform css', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'skew(-20deg)', 'essential-classy-addons-for-elementor' ),
				'selectors'   => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button' => 'transform: {{VALUE}};-ms-transform: {{VALUE}};-moz-transform: {{VALUE}};-webkit-transform: {{VALUE}};',
				),
			)
		);
		$this->end_controls_tab();
		$this->start_controls_tab(
			'tabCcbH',
			array(
				'label' => esc_html__( 'Hover', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'ccbColorH',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccbBgH',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccbBorderH',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover',
			)
		);
		$this->add_responsive_control(
			'ccbBrH',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccbShadowH',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover',
			)
		);
		$this->add_control(
			'ccbTransitionH',
			array(
				'label'       => esc_html__( 'Transition css', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'all .3s linear', 'essential-classy-addons-for-elementor' ),
				'selectors'   => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover' => 'transition:{{VALUE}};',
				),
			)
		);
		$this->add_control(
			'ccbTransformH',
			array(
				'label'       => esc_html__( 'Transform css', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXT,
				'placeholder' => esc_html__( 'skew(-20deg)', 'essential-classy-addons-for-elementor' ),
				'selectors'   => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-wrap .ec-cc-button:hover' => 'transform: {{VALUE}};-ms-transform: {{VALUE}};-moz-transform: {{VALUE}};-webkit-transform: {{VALUE}};',
				),
			)
		);
		$this->end_controls_tab();
		$this->end_controls_tabs();
		$this->end_controls_section();

		$this->start_controls_section(
			'ccImageStyling',
			array(
				'label' => esc_html__( 'Image', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'ccImagePadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccImageMargin',
			array(
				'label'      => esc_html__( 'Margin', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccImageSize',
			array(
				'label'      => esc_html__( 'Image Size', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => 1,
						'max' => 300,
					),
				),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image' => 'width: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccImageBackground',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccImageBorder',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image',
			)
		);
		$this->add_responsive_control(
			'ccImageBr',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccImageShadow',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image',
			)
		);
		$this->add_group_control(
			Group_Control_Css_Filter::get_type(),
			array(
				'name'     => 'ccImageCssFilter',
				'label'    => esc_html__( 'Filter', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image',
			)
		);
		$this->add_control(
			'mask_shape_image',
			array(
				'label'     => esc_html__( 'Mask Image', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::MEDIA,
				'separator' => 'before',
				'dynamic'    => array(
					'active' => true,
				),
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-image' => 'mask-image: url({{URL}});-webkit-mask-image: url({{URL}});-webkit-mask-size: 100% 100%;-webkit-mask-repeat: no-repeat;',
				),
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'ccTitleStyling',
			array(
				'label' => esc_html__( 'Title', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'ccTitlePadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccTitleMargin',
			array(
				'label'      => esc_html__( 'Margin', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'ccTitleTypography',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title',
			)
		);
		$this->add_control(
			'ccTitleColor',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccTitleBackground',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccTitleBorder',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title',
			)
		);
		$this->add_responsive_control(
			'ccTitleBr',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccTitleShadow',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-title',
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'ccETStyling',
			array(
				'label' => esc_html__( 'Extra Text', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'ccETPadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_responsive_control(
			'ccETMargin',
			array(
				'label'      => esc_html__( 'Margin', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'ccETTypography',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text',
			)
		);
		$this->add_control(
			'ccETColor',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccETBackground',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccETBorder',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text',
			)
		);
		$this->add_responsive_control(
			'ccETBr',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccETShadow',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-extra-text',
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'ccODStyling',
			array(
				'label'     => esc_html__( 'Design Overlay', 'essential-classy-addons-for-elementor' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array(
					'couponDesign' => 'pattern1',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccODP1Background',
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-dc-left,{{WRAPPER}} .ec-coupon-code-wrapper .ec-cc-dc-right',
			)
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'ccBoxStyling',
			array(
				'label' => esc_html__( 'Box', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_responsive_control(
			'ccBoxPadding',
			array(
				'label'      => esc_html__( 'Padding', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Background::get_type(),
			array(
				'name'     => 'ccBoxBackground',
				'types'    => array( 'gradient' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper',
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'ccBoxBorder',
				'label'    => esc_html__( 'Border', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper',
			)
		);
		$this->add_responsive_control(
			'ccBoxBr',
			array(
				'label'      => esc_html__( 'Border Radius', 'essential-classy-addons-for-elementor' ),
				'type'       => Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .ec-coupon-code-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			array(
				'name'     => 'ccBoxShadow',
				'selector' => '{{WRAPPER}} .ec-coupon-code-wrapper',
			)
		);
		$this->end_controls_section();
		/*style end*/
	}

	protected function render() {

		$settings          = $this->get_settings_for_display();
		$buttonText        = ! empty( $settings['buttonText'] ) ? $settings['buttonText'] : '';
		$buttonCopiedText  = ! empty( $settings['buttonCopiedText'] ) ? $settings['buttonCopiedText'] : '';
		$couponRedirectUrl = ! empty( $settings['couponRedirectUrl']['url'] ) ? esc_url( $settings['couponRedirectUrl']['url'] ) : '';

		$cc['buttonText']            = esc_html( $buttonText );
		$cc['buttonCopiedText']      = esc_html( $buttonCopiedText );
		$cc['couponRedirectUrl']     = esc_url( $couponRedirectUrl );
		$cc['couponRedirectUrlType'] = ! empty( $settings['couponRedirectUrlType'] ) ? esc_attr( $settings['couponRedirectUrlType'] ) : '';

		$tiltclass  = '';
		$tiltrender = '';
		if ( isset( $settings['tiltEffect'] ) && $settings['tiltEffect'] === 'yes' ) {
			/*Tilt Effect Render*/
			include ECAFE_PATH . 'element/widgets/ecafe-tilt-render.php';
		}
		$tippyclass  = '';
		$tippyrender = '';
		if ( isset( $settings['tippyTooltip'] ) && $settings['tippyTooltip'] === 'yes' ) {
			/*Tippy Tooltip Render*/
			include ECAFE_PATH . 'element/widgets/ecafe-tippy-render.php';
		}
		$output = '<div class="ec-coupon-code-wrapper ' . esc_attr( $tiltclass ) . ' ' . esc_attr( $tippyclass ) . '" data-ccoptions=\'' . json_encode( $cc ) . '\' ' . $tiltrender . ' ' . $tippyrender . '>';

		if ( ! empty( $settings['couponImage']['url'] ) ) {
			$couponImage = $settings['couponImage']['id'];
			$img         = wp_get_attachment_image_src( $couponImage, 'full' );
			$imgSrc      = $img[0];
			$imageId     = $settings['couponImage']['id'];
			$imageAlt    = get_post_meta( $imageId, '_wp_attachment_image_alt', true );
			if ( empty( $imageAlt ) ) {
						$imageAlt = get_the_title( $imageId );
			}
					$output .= '<img class="ec-cc-image" src=' . esc_url( $imgSrc ) . ' alt="' . esc_attr( $imageAlt ) . '" />';
		}

				$couponTitle    = ! empty( $settings['couponTitle'] ) ? $settings['couponTitle'] : '';
				$couponTitleTag = ! empty( $settings['couponTitleTag'] ) ? $settings['couponTitleTag'] : 'h1';
		if ( ! empty( $couponTitle ) ) {
			$output .= '<' . \EcafeHelper::check_and_validate_html_tag( $couponTitleTag ) . ' class="ec-cc-title">' . esc_html( $couponTitle ) . '</' . \EcafeHelper::check_and_validate_html_tag( $couponTitleTag ) . '>';
		}

				$couponCode  = ! empty( $settings['couponCode'] ) ? $settings['couponCode'] : '';
				$output     .= '<div class="ec-cc-wrap">';
					$output .= '<span class="ec-cc-coupon">' . esc_html( $couponCode ) . '</span>';
					$output .= '<span class="ec-cc-button">' . esc_html( $buttonText ) . '</span>';
				$output     .= '</div>';

				$couponExtraText = ! empty( $settings['couponExtraText'] ) ? $settings['couponExtraText'] : '';
				$output         .= '<div class="ec-cc-extra-text">' . esc_html( $couponExtraText ) . '</div>';

				$couponDesign = ! empty( $settings['couponDesign'] ) ? $settings['couponDesign'] : '';
		if ( ! empty( $couponDesign ) ) {
			if ( $couponDesign == 'pattern1' ) {
						$output .= '<div class="ec-cc-dc-left"></div>';
						$output .= '<div class="ec-cc-dc-right"></div>';
			}
		}

			$output .= '</div>';

			echo wp_kses_normalize_entities( $output );
	}
}
