<?php

namespace Unlockafe_addons\Widgets;

use Unlockafe_addons\Traits\Utils as UnlockafeUtils;
use Unlockafe_addons\Traits\Widget_helper;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use \Elementor\Utils;
use \Elementor\Control_Media;
use \Elementor\Group_Control_Image_Size;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Group_Control_Text_Shadow;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Background;
use \Elementor\Repeater;

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

/**
 * Text Slider Widget
 *
 * @since 1.0.0
 */
class Text_Slider extends Widget_Base
{

	use Widget_helper, UnlockafeUtils;

	/**
	 * Retrieve the widget name.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name()
	{
		return 'unlockafe-text-slider';
	}

	/**
	 * Retrieve the widget title.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return __('WPRealizer - Text Slider', 'unlock-addons-for-elementor');
	}

	/**
	 * Retrieve the widget icon.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'eicon-slider-push ulicon';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	 *
	 * Used to determine where to display the widget in the editor.
	 *
	 * Note that currently Elementor supports only one category.
	 * When multiple categories passed, Elementor uses the first one.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories()
	{
		return ['unlockafe-addons'];
	}

	/**
	 * Retrieve the list of scripts the widget depended on.
	 *
	 * Used to set scripts dependencies required to run the widget.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget scripts dependencies.
	 */
	public function get_script_depends()
	{
		return [];
	}

	public function get_style_depends()
	{
		return ['unlockafe-global'];
	}

	/**
	 * Register the widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */

	protected function register_controls()
	{
		$this->register_controls_section();
		$this->style_tab_content();
	}

	protected function register_controls_section()
	{

		// layout Panel
		$this->start_controls_section(
			'wpr_layout',
			[
				'label' => esc_html__('Design Layout', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'wpr_design_style',
			[
				'label' => esc_html__('Select Layout', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'layout-1' => esc_html__('Layout 1', 'unlock-addons-for-elementor'),
					'layout-2' => esc_html__('Layout 2', 'unlock-addons-for-elementor'),
					'layout-3' => esc_html__('Layout 3', 'unlock-addons-for-elementor'),
					// 'layout-4' => esc_html__('Layout 4', 'unlock-addons-for-elementor'),
					// 'layout-5' => esc_html__('Layout 5', 'unlock-addons-for-elementor'),
				],
				'default' => 'layout-1',
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'tp_list_sec',
			[
				'label' => esc_html__('Repeater List', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$repeater = new Repeater();

		$repeater->add_control(
			'repeater_condition',
			[
				'label' => __('Field condition', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'style_1' => __('Style 1', 'unlock-addons-for-elementor'),
					'style_2' => __('Style 2', 'unlock-addons-for-elementor'),
					'style_3' => __('Style 3', 'unlock-addons-for-elementor'),
				],
				'default' => 'style_1',
				'frontend_available' => true,
				'style_transfer' => true,
			]
		);

		$repeater->add_control(
			'wpr_text_title',
			[
				'label' => esc_html__('Title', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Brand Identity', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'tp_text_list',
			[
				'label' => esc_html__('Text List', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'wpr_text_title' => esc_html__('Art Direction', 'unlock-addons-for-elementor'),
					],
					[
						'wpr_text_title' => esc_html__('Branding', 'unlock-addons-for-elementor'),
					],
					[
						'wpr_text_title' => esc_html__('Content Production', 'unlock-addons-for-elementor'),
					],
					[
						'wpr_text_title' => esc_html__('Animation', 'unlock-addons-for-elementor'),
					],
				],
				'title_field' => '{{{ wpr_text_title }}}',
			]
		);

		$this->end_controls_section();
	}

	// style_tab_content
	protected function style_tab_content()
	{
		$this->tp_section_style_controls('section', 'Section - Style', '.wpr-el-section');
		$this->tp_basic_style_controls('title_style', 'Repeater Title - Style', '.wpr-el-title');

		$this->start_controls_section(
			'tp_text_slider_parcentage',
			[
				'label' => esc_html__('Parcentage', 'unlock-addons-for-elementor'),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => [
					'wpr_design_style' => ['layout-10']
				]

			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name' => 'tp_text_slider_parcentage_typo',
				'label'   => esc_html__('Typography', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} .wpr-el-title span',
			]
		);

		$this->add_control(
			'tp_text_slider_parcentage_color',
			[
				'label'       => esc_html__('Number Color', 'unlock-addons-for-elementor'),
				'type'     => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .wpr-el-title span' => 'color: {{VALUE}}; -webkit-text-fill-color: {{VALUE}}',
				],
			]
		);

		$this->add_control(
			'tp_text_slider_parcentage_shape_color',
			[
				'label'       => esc_html__('Shape Color', 'unlock-addons-for-elementor'),
				'type'     => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .wpr-el-title span path' => 'fill: {{VALUE}};',
				],
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Render the widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function render()
	{
		$settings = $this->get_settings_for_display();

?>

		<?php if ($settings['wpr_design_style'] == 'layout-2'): ?>

            <div class="swiper text__slider fade-anim" data-offset="200" data-delay="0.25">
              	<div class="swiper-wrapper linear">
              		<?php foreach ($settings['tp_text_list'] as $item): ?>
	                <div class="swiper-slide">
	                  	<h3 class="text wpr-el-title">
		                    <svg
		                      xmlns="http://www.w3.org/2000/svg"
		                      width="28"
		                      height="27"
		                      viewBox="0 0 28 27"
		                      fill="none">
		                      <path
		                        d="M17.0221 0L17.0275 9.70428L26.1324 6.71117L28 12.5393L18.8988 15.5433L24.5202 23.3978L19.6305 27L14 19.152L8.36952 27L3.47981 23.3978L9.1009 15.5433L0 12.5393L1.86761 6.71117L1.87083 6.71226L1.91537 6.72695L10.9723 9.70428L10.9779 0H17.0221Z"
		                        fill="currentColor"
		                      />
		                    </svg>
		                    <?php echo $this->tp_kses($item['wpr_text_title']); ?>
	                  	</h3>
	                </div>
	                <?php endforeach; ?>
              	</div>
            </div>


		<?php elseif ($settings['wpr_design_style'] == 'layout-3'): ?>

         <!--================= text-slider section start =================-->
         <section class="swiper text__slider v4">
            <div class="swiper-wrapper linear">
            	<?php foreach ($settings['tp_text_list'] as $item): ?>
              	<div class="swiper-slide">
	                <h3 class="text wpr-el-title">
		                <svg xmlns="http://www.w3.org/2000/svg" width="68" height="68" viewBox="0 0 68 68" fill="none">
		                    <path d="M34 0L34.0081 33.967L49.8006 3.8945L34.0225 33.9746L61.9815 14.6858L34.0318 33.9879L67.7521 29.9018L34.0338 34.0041L65.7906 46.0566L34.028 34.0193L56.5462 59.4494L34.0158 34.0301L42.1367 67.012L34 34.034L25.8633 67.012L33.9842 34.0301L11.4538 59.4494L33.972 34.0193L2.20945 46.0566L33.9662 34.0041L0.247898 29.9018L33.9682 33.9879L6.01855 14.6858L33.9775 33.9746L18.1994 3.8945L33.9919 33.967L34 0Z" stroke="currentColor" stroke-width="3" />
		                </svg>
	                 	<?php echo $this->tp_kses($item['wpr_text_title']); ?>
	                </h3>
              	</div>
              	<?php endforeach; ?>
            </div>
        </section>
         <!--================= text-slider section end =================-->


		<?php elseif ($settings['wpr_design_style'] == 'layout-4'): ?>

		<?php else: ?>

			<div class="footer-two__center wpr-el-section">
				<div class="swiper footer-two__marquee">
					<div class="swiper-wrapper linear">
						<?php foreach ($settings['tp_text_list'] as $item): ?>
							<div class="swiper-slide">
								<h2 class="marquee wpr-el-title"><?php echo $this->tp_kses($item['wpr_text_title']); ?></h2>
							</div>
						<?php endforeach; ?>
					</div>
				</div>
			</div>

<?php endif;
	}
}


