<?php

namespace TRANZIXPLUGIN\Element;

use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Plugin;

/**
 * Elementor button widget.
 * Elementor widget that displays a button with the ability to control every
 * aspect of the button design.
 *
 * @since 1.0.0
 */
class Slider extends Widget_Base {

	/**
	 * Get widget name.
	 * Retrieve button widget name.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'tranzix_slider';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Slider', 'tranzix' );
	}

	/**
	 * Get widget icon.
	 * Retrieve button widget icon.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-briefcase';
	}

	/**
	 * Get widget categories.
	 * Retrieve the list of categories the button widget belongs to.
	 * Used to determine where to display the widget in the editor.
	 *
	 * @since  2.0.0
	 * @access public
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'tranzix' ];
	}
	
	/**
	 * Register button 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->start_controls_section(
			'slider',
			[
				'label' => esc_html__( 'Slider', 'tranzix' ),
			]
		);
		$this->add_control(
            'style', 
				[
					'label'   => esc_html__( 'Choose Different Style', 'tranzix' ),
					'label_block' => true,
					'type'    => Controls_Manager::SELECT,
					'return_value' => 'style1',
                    'default'      => 'style1',
					'options' => array(
						'style8' => esc_html__( 'Choose Style 8', 'tranzix' ),
						'style9' => esc_html__( 'Choose Style 9', 'tranzix' ),
					),
				]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your title', 'rashid' ),
			]
		);
		$this->add_control(
			'text',
			[
				'label'       => __( 'Description Text', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Description', 'rashid' ),
			]
		);
		$this->add_control(
			'bttn',
			[
				'label'       => __( 'Button', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Button Title', 'rashid' ),
			]
		);	
		$this->add_control(
			'btnlink',
			[
			  'label' => __( 'Button Url', 'rashid' ),
			  'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
			  'type' => Controls_Manager::URL,
			  'placeholder' => __( 'https://your-link.com', 'rashid' ),
			  'show_external' => true,
			  'default' => [
				'url' => '',
				'is_external' => true,
				'nofollow' => true,
			  ],
			
		   ]
		);
		$this->add_control(
			'bttn1',
			[
				'label'       => __( 'Button', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Button Title', 'rashid' ),
			]
		);	
		$this->add_control(
			'btnlink1',
			[
			  'label' => __( 'Button Url', 'rashid' ),
			  'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
			  'type' => Controls_Manager::URL,
			  'placeholder' => __( 'https://your-link.com', 'rashid' ),
			  'show_external' => true,
			  'default' => [
				'url' => '',
				'is_external' => true,
				'nofollow' => true,
			  ],
			
		   ]
		);
		$this->add_control(
			'title2',
			[
				'label'       => __( 'Title Two', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your title', 'rashid' ),
			]
		);
		$this->add_control(
			'contact_us_form',
			[
				'label'       => __( 'Contact Form 7 Url', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Contact Form 7 Url', 'rashid' ),
				'default'     => __( '', 'rashid' ),
			]
		);
		$this->add_control(
			'sec_class',
			[
				'label'       => __( 'Section Class', 'rashid' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Section Class', 'rashid' ),
			]
		);
		
		
		$this->end_controls_section();
		
		
		// New Tab#2

		$this->start_controls_section(
					'content_section2',
					[
						'label' => __( 'Image Block', 'rashid' ),
						'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
					]
				);
				$this->add_control(
					'bgimg',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style2',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style3',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style5',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style6',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style7',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg1',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style2',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style6',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style7',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg2',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style2',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style6',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style7',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg3',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style7',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg4',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'image',
						[
						  'label' => __( 'Image', 'rashid' ),
							  'conditions' => array(
								'relation' => 'or',
								'terms'    => array(
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style4',
									),
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style13',
									),
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style14',
									),
								),
							),
						  'type' => Controls_Manager::MEDIA,
						  'default' => ['url' => Utils::get_placeholder_image_src(),],
						]
				);
				$this->add_control(
					'alt_text',
					[
						'label'       => __( 'Alt text', 'rashid' ),
						  'conditions' => array(
								'relation' => 'or',
								'terms'    => array(
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style4',
									),
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style13',
									),
									array(
										'name'     => 'style',
										'operator' => '==',
										'value'    => 'style14',
									),
								),
							),
						'type'        => Controls_Manager::TEXTAREA,
						'dynamic'     => [
							'active' => true,
						],
						'placeholder' => __( 'Enter your Description', 'rashid' ),
					]
				);
				$this->add_control(
					'bgimg5',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style1',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style6',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style15',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg6',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style1',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style6',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg7',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style1',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg8',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style1',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				
				
		$this->end_controls_section();
		
		// New Tab#1

		$this->start_controls_section(
					'content_section',
					[
						'label' => __( 'Slider Block', 'rashid' ),
						'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
					]
				);
				$this->add_control(
				  'repeat', 
					[
						'type' => Controls_Manager::REPEATER,
						'seperator' => 'before',
						'default' => 
							[
								['block_title' => esc_html__('Projects Completed', 'rashid')],
							],
						'fields' => 
							[
								'block_bgimg' =>
								[
									'name' => 'block_bgimg',
									'label' => esc_html__('Background image', 'rashid'),
									'type' => Controls_Manager::MEDIA,
									'default' => ['url' => Utils::get_placeholder_image_src(),],
								],
								'block_image' =>
								[
									'name' => 'block_image',
									'label' => __( 'Image', 'rashid' ),
									'type' => Controls_Manager::MEDIA,
									'default' => ['url' => Utils::get_placeholder_image_src(),],
								],
								'block_alt_text' =>
								[
									'name' => 'block_alt_text',
									'label' => esc_html__('Alt Text', 'rashid'),
									'type' => Controls_Manager::TEXTAREA,
									'default' => esc_html__('', 'rashid')
								],
								'block_title' =>
								[
									'name' => 'block_title',
									'label' => esc_html__('Title', 'rashid'),
									'type' => Controls_Manager::TEXTAREA,
									'default' => esc_html__('', 'rashid')
								],
								'block_text' =>
								[
									'name' => 'block_text',
									'label' => esc_html__('Text', 'rashid'),
									'type' => Controls_Manager::TEXTAREA,
									'default' => esc_html__('', 'rashid')
								],
								'block_button' =>
								[
									'name' => 'block_button',
									'label'       => __( 'Button', 'rashid' ),
									'type'        => Controls_Manager::TEXT,
									'dynamic'     => [
										'active' => true,
									],
									'placeholder' => __( 'Enter your Button Title', 'rashid' ),
								],
								'block_btnlink' =>
								[
									'name' => 'block_btnlink',
									'label' => __( 'Button Url', 'rashid' ),
									'type' => Controls_Manager::URL,
									'placeholder' => __( 'https://your-link.com', 'rashid' ),
									'show_external' => true,
									'default' => [
									'url' => '',
									'is_external' => true,
									'nof
									ollow' => true,
									],
								],
								'block_button1' =>
								[
									'name' => 'block_button1',
									'label'       => __( 'Button', 'rashid' ),
									'type'        => Controls_Manager::TEXT,
									'dynamic'     => [
										'active' => true,
									],
									'placeholder' => __( 'Enter your Button Title', 'rashid' ),
								],
								'block_btnlink1' =>
								[
									'name' => 'block_btnlink1',
									'label' => __( 'Button Url', 'rashid' ),
									'type' => Controls_Manager::URL,
									'placeholder' => __( 'https://your-link.com', 'rashid' ),
									'show_external' => true,
									'default' => [
									'url' => '',
									'is_external' => true,
									'nof
									ollow' => true,
									],
								],
							],
						'title_field' => '{{block_title}}',
					 ]
			);
				
				
		$this->end_controls_section();	
		
			
		
	
		}

	/**
	 * Render button 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();
		$allowed_tags = wp_kses_allowed_html('post');
		?>
        
<?php
	  echo '
	 <script>
 jQuery(document).ready(function($) {

//put the js code under this line 

	if ($(".banner-carousel").length) {
		$(".banner-carousel").owlCarousel({
			loop:true,
			margin:0,
			nav:true,
			active: true,
			smartSpeed: 1000,
			autoplay: 6000,
			responsive:{
				0:{
					items:1
				},
				600:{
					items:1
				},
				800:{
					items:1
				},
				1024:{
					items:1
				}
			}
		});
	}

//put the code above the line 

  });
</script>';


?>
		
		<?php  if ( 'style8' === $settings['style'] ) : ?>
		
		<section class="slider-six p_relative <?php echo esc_attr($settings['sec_class']);?>">
            <div class="banner-carousel owl-theme owl-carousel owl-dots-none">
			
				<?php foreach($settings['repeat'] as $item):?>
			
                <div class="slide-item p_relative pt_160">
					<?php if(wp_get_attachment_url($item['block_bgimg']['id'])): ?>
                    <div class="image-layer p_absolute" style="background-image:url(<?php echo esc_url($item['block_bgimg']['url']);?>)">
					<?php else :?>	
					<div class="noimage">
					<?php endif;?>
					
					</div>
					
                    <div>
                        <svg class="waves" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
                            <defs>
                                <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
                            </defs>
                            <g class="parallax">
                            <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
                            <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
                            <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
                            <use xlink:href="#gentle-wave" x="48" y="7" fill="#ffffff" />
                            </g>
                        </svg>
                    </div>
                    <div class="auto-container">
                        <div class="content-inner p_relative d_block pt_70 pr_70 pb_80 pl_80 z_5">
                            <h2 class="p_relative d_block font_family_pt fs_80 lh_80 fw_bold mb_25"><?php echo wp_kses($item['block_title'], $allowed_tags);?></h2>
                            <p class="d_block fs_20 lh_28 mb_40 font_family_oxygen fw_sbold"><?php echo wp_kses($item['block_text'], $allowed_tags);?></p>
							<?php if(wp_kses($item['block_button'], $allowed_tags)): ?>
                            <div class="btn-box clearfix">
                                <a href="<?php echo esc_url($item['block_btnlink']['url']);?>" class="theme-btn"><?php echo wp_kses($item['block_button'], $allowed_tags);?></a>
                            </div>
							<?php endif; ?>
                            <div class="bubbleContainer">
                                <div class="bubble-1"></div>
                                <div class="bubble-2"></div>
                                <div class="bubble-3"></div>
                            </div>
                        </div> 
                    </div>
                </div>
				
				<?php endforeach; ?>
				
            </div>
        </section>
		
		<?php endif;?>
		
		<?php  if ( 'style9' === $settings['style'] ) : ?>
		
		<section class="slider-seven p_relative <?php echo esc_attr($settings['sec_class']);?>">
            <div class="banner-carousel owl-theme owl-carousel owl-dots-none">
			
				<?php foreach($settings['repeat'] as $item):?>
			
                <div class="slide-item p_relative pb_180">
					<?php if(wp_get_attachment_url($item['block_bgimg']['id'])): ?>
                    <div class="image-layer p_absolute" style="background-image:url(<?php echo esc_url($item['block_bgimg']['url']);?>)">
					<?php else :?>	
					<div class="noimage">
					<?php endif;?>
					</div>
                    <div class="auto-container">
                        <div class="content-box p_relative d_block z_5">
                            <h2 class="p_relative d_block fw_exbold fs_70 lh_60 mb_20 font_family_spartan"><?php echo wp_kses($item['block_title'], $allowed_tags);?></h2>
							<?php if(wp_kses($item['block_button'], $allowed_tags)): ?>
                            <div class="btn-box clearfix">
                                <a href="<?php echo esc_url($item['block_btnlink']['url']);?>" class="theme-btn theme-btn-eight"><?php echo wp_kses($item['block_button'], $allowed_tags);?></a>
                            </div>
							<?php endif; ?>
                        </div> 
                    </div>
                </div>
				
				<?php endforeach; ?>
				
            </div>
        </section>
		
		<?php endif;?>


		<?php 
	}

}