<?php
namespace EcafeAddons\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Group_Control_Text_Stroke;

use EcafeAddons\EcafeElementLoad;

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

class Ecafe_Marquee_Text extends Widget_Base {

	public function get_name() {
		return 'ecafe-marquee-text';
	}

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

	public function get_icon() {
		return 'ecafe-ele-back-icon ecafe-marquee-text-icon';
	}

	public function get_categories() {
		return array( 'essential' );
	}

	public function get_keywords() {
		return array( 'maqquee text', 'text animation', 'marquee left', 'marquee right' );
	}
	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__( 'Maqquee Text', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'marqueeDirection',
			array(
				'label'   => esc_html__( 'Direction', 'essential-classy-addons-for-elementor' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'ltr',
				'options' => array(
					'ltr' => esc_html__( 'LTR', 'essential-classy-addons-for-elementor' ),
					'rtl' => esc_html__( 'RTL', 'essential-classy-addons-for-elementor' ),
				),
			)
		);
		$this->add_control(
			'marqueeText',
			array(
				'label'       => esc_html__( 'Text', 'essential-classy-addons-for-elementor' ),
				'type'        => Controls_Manager::TEXTAREA,
				'default'     => esc_html__( 'giving information on its origins, as well as a random Lipsum generator.', 'essential-classy-addons-for-elementor' ),
				'dynamic'     => array( 'active' => true ),
				'label_block' => true,
			)
		);
		$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/marquee-text-animation-elementor/' );
		$ecwidgetdoclink  = esc_url( 'https://ecaddons.com/docs/marquee-text-animation-tutorial/' );
		include ECAFE_PATH . 'element/widgets/ecafe-widgetpanel-help.php';

		$this->start_controls_section(
			'maqrueeStyling',
			array(
				'label' => esc_html__( 'Marquee Text', 'essential-classy-addons-for-elementor' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'maqrueeTypo',
				'selector' => '{{WRAPPER}} .ec-marquee-text-wrapper .ec-marquee-text-content',
			)
		);
		$this->start_controls_tabs( 'tabsMaqrueeStyle' );
		$this->start_controls_tab(
			'tabMaqrueeN',
			array(
				'label' => esc_html__( 'Normal', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'maqrueeColor',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-marquee-text-wrapper .ec-marquee-text-content' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Text_Shadow::get_type(),
			array(
				'name'     => 'maqrueeTextShadow',
				'label'    => esc_html__( 'Text Shadow', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-marquee-text-wrapper .ec-marquee-text-content',
			)
		);
		$this->add_group_control(
			Group_Control_Text_Stroke::get_type(),
			array(
				'name'     => 'maqrueeTextStroke',
				'selector' => '{{WRAPPER}} .ec-marquee-text-wrapper .ec-marquee-text-content',
			)
		);
		$this->end_controls_tab();
		$this->start_controls_tab(
			'tabMaqrueeHover',
			array(
				'label' => esc_html__( 'Hover', 'essential-classy-addons-for-elementor' ),
			)
		);
		$this->add_control(
			'maqrueeColorH',
			array(
				'label'     => esc_html__( 'Color', 'essential-classy-addons-for-elementor' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .ec-marquee-text-wrapper:hover .ec-marquee-text-content' => 'color: {{VALUE}};',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Text_Shadow::get_type(),
			array(
				'name'     => 'maqrueeTextShadowH',
				'label'    => esc_html__( 'Text Shadow', 'essential-classy-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .ec-marquee-text-wrapper:hover .ec-marquee-text-content',
			)
		);
		$this->add_group_control(
			Group_Control_Text_Stroke::get_type(),
			array(
				'name'     => 'maqrueeTextStrokeH',
				'selector' => '{{WRAPPER}} .ec-marquee-text-wrapper:hover .ec-marquee-text-content',
			)
		);
		$this->end_controls_tab();
		$this->end_controls_tabs();
		$this->end_controls_section();
	}

	protected function render() {
		$settings         = $this->get_settings_for_display();
		$marqueeDirection = ! empty( $settings['marqueeDirection'] ) ? $settings['marqueeDirection'] : 'ltr';
		$marqueeText      = ! empty( $settings['marqueeText'] ) ? esc_attr( $settings['marqueeText'] ) : '';

		$output = '';
		if ( ! empty( $marqueeText ) ) {
			$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-marquee-text-wrapper ec-mt-' . esc_attr( $marqueeDirection ) . ' ' . esc_attr( $tiltclass ) . ' ' . esc_attr( $tippyclass ) . '" ' . $tiltrender . ' ' . $tippyrender . '>';
				$output .= '<span class="ec-marquee-text-content">' . $marqueeText . '</span>';
				$output .= '<span class="ec-marquee-text-content">' . $marqueeText . '</span>';
				$output .= '<span class="ec-marquee-text-content">' . $marqueeText . '</span>';
				$output .= '<span class="ec-marquee-text-content">' . $marqueeText . '</span>';
				$output .= '<span class="ec-marquee-text-content">' . $marqueeText . '</span>';
			$output     .= '</div>';
		}
		echo wp_kses_normalize_entities( $output );
	}
}
