<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Banner_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 'pubzi-banner-slider-widget';
	}

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

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

	/**
	 * 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 ['pubzi_widgets'];
    }
	
	/**
	 * 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_content_section',
			[
				'label' => __( 'Slider Content', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
		'image',
			[
				'label' => __( 'Image', 'pubzi-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			]
		);

		$this->add_control(
		'image2',
			[
				'label' => __( 'Image 2', 'pubzi-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			]
		);

		$this->add_control(
		'image3',
			[
				'label' => __( 'Image 3', 'pubzi-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			]
		);

		$this->add_control(
			'video_link',
			[
			  'label' => __( 'Video Url', 'pubzi-core' ),
			  'type' => Controls_Manager::URL,
			  'placeholder' => __( 'https://your-link.com', 'pubzi-core' ),
			  'show_external' => true,
			  'default' => [
				'url' => 'https://www.youtube.com/watch?v=SjJhuZQlkbA',
				'is_external' => true,
				'nofollow' => true,
			  ],
			
		   ]
		);	

		$this->add_control(
			'text',
			[
				'label'       => __( 'Description Text', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Get specialist cargo services worldwide', 'pubzi-core'),
				'dynamic'     => [
					'active' => true,
				],
			]
		);


		$this->end_controls_section();	


		$this->start_controls_section(
			'content_section',
			[
				'label' => __( 'Slider Block', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);
		$this->add_control(
		  'repeat', 
			[
				'type' => Controls_Manager::REPEATER,
				'separator' => 'before',
				'default' => 
					[
						['section_title' => esc_html__('Projects Completed', 'pubzi-core')],
					],
				'fields' => 
					[		
						
						[
							'name' => 'section_image',
							'label' => __( 'Image', 'pubzi-core' ),
							'type' => Controls_Manager::MEDIA,
							'default' => [
								'url' => Utils::get_placeholder_image_src(),
							],
						],

						[
							'name' => 'section_subtitle',
							'label' => esc_html__('Subtitle', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],	

						[
							'name' => 'section_title',
							'label' => esc_html__('Title', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],
						
						[
							'name' => 'section_title2',
							'label' => esc_html__('Title 2', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],	

							[
							'name' => 'section_image2',
							'label' => __( 'Image', 'pubzi-core' ),
							'type' => Controls_Manager::MEDIA,
							'default' => [
								'url' => Utils::get_placeholder_image_src(),
							],
						],


						
					],
				'title_field' => '{{section_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');
		?>

	  <section class="hero-section hero-3 fix">
		<div class="top-shape">
			<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
				<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
			<?php endif;?>
		</div>
			<div class="right-shape">
			<?php  if ( !empty(esc_url($settings['image2']['id']) )) : ?>   
				<img src="<?php echo wp_get_attachment_url($settings['image2']['id']);?>" alt=""/>
			<?php endif;?>
		</div>
		<div class="radius-shape">
			<?php  if ( !empty(esc_url($settings['image3']['id']) )) : ?>   
				<img src="<?php echo wp_get_attachment_url($settings['image3']['id']);?>" alt=""/>
			<?php endif;?>
		</div>
		<div class="container-fluid">
			<div class="row g-4">
				<div class="col-xl-8">
					<div class="swiper hero-image-slider">
						<div class="swiper-wrapper">

							<?php foreach($settings['repeat'] as $item):?>	
							<div class="swiper-slide">
								<div class="hero-image">
								<?php if(!empty(wp_get_attachment_url($item['section_image']['id']))): ?>
									<img src="<?php echo wp_get_attachment_url($item['section_image']['id']);?>" alt="">
								<?php endif;?>
								</div>
							</div>
							<?php endforeach; ?>

						</div>
					</div>
				</div>
				<div class="col-xl-4">
					<div class="swiper hero-slider">
						<div class="swiper-wrapper">

							<?php foreach($settings['repeat'] as $item):?>	
							<div class="swiper-slide">
								<div class="hero-content">
									<h6><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></h6>
									<h1 class="wave-text">
									<?php echo wp_kses($item['section_title'], $allowed_tags);?>
									<?php if(!empty(wp_get_attachment_url($item['section_image2']['id']))): ?>
										<img src="<?php echo wp_get_attachment_url($item['section_image2']['id']);?>" alt="">
									<?php endif;?>
									<?php echo wp_kses($item['section_title2'], $allowed_tags);?>
									</h1>
								</div>
							</div>
							<?php endforeach; ?>

						</div>
					</div>
					<div class="video-content">
						<a href="<?php echo esc_url($settings['video_link']['url']);?>" class="video-btn video-popup">
							<i class="fa-solid fa-play"></i></a>
							<p>
							<?php echo $settings['text'];?>
							</p>
					</div>
				</div>
			</div>
		</div>
		<div class="right-item">
			<div class="dot-number">
				<span class="dot-num">
					<span>01</span>
				</span>
				<span class="dot-num">
					<span>02</span>
				</span>
				
			</div>
			<div class="array-btn">
			<button class="array-prev">
				<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
				<g clip-path="url(#clip0_200_860)">
					<path d="M-7.36055e-07 1.1603L-1.41494e-07 14.7623C-1.13526e-07 15.4021 0.520312 15.9224 1.16016 15.9224C1.8 15.9224 2.32031 15.4021 2.32031 14.7623L2.32031 3.96577L16.0172 17.6591C16.4707 18.1126 17.2055 18.1126 17.659 17.6591C18.1125 17.2056 18.1125 16.4708 17.659 16.0173L3.96211 2.32397L14.7586 2.32397C15.3984 2.32397 15.9187 1.80366 15.9187 1.16382C15.9187 0.523975 15.3984 0.00366144 14.7586 0.00366146L1.16016 0.00366206C0.520312 0.000146843 -7.64023e-07 0.520458 -7.36055e-07 1.1603Z" fill="#0B0E13"/>
				</g>
				<defs>
					<clipPath id="clip05_200_860">
					<rect width="18" height="18" fill="white" transform="translate(0 18.0002) rotate(-90)"/>
					</clipPath>
				</defs>
				</svg>
			</button>
			<button class="array-next">
				<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
				<g clip-path="url(#clip0_161_5474)">
					<path d="M17.9941 16.8401L17.9941 3.23811C17.9941 2.59827 17.4738 2.07795 16.834 2.07795C16.1941 2.07795 15.6738 2.59827 15.6738 3.23811L15.6738 14.0346L1.97695 0.341235C1.52344 -0.112281 0.788671 -0.112281 0.335157 0.341235C-0.118359 0.79475 -0.118359 1.52952 0.335157 1.98303L14.032 15.6764L3.23555 15.6764C2.5957 15.6764 2.07539 16.1967 2.07539 16.8365C2.07539 17.4764 2.5957 17.9967 3.23555 17.9967L16.834 17.9967C17.4738 18.0002 17.9941 17.4799 17.9941 16.8401Z" fill="#CBFE1C"/>
				</g>
				<defs>
					<clipPath id="clip06_161_5474">
					<rect width="18" height="18" fill="white" transform="translate(17.9941 0.000244141) rotate(90)"/>
					</clipPath>
				</defs>
				</svg>
			</button>
		</div>
		</div>
	</section>

             
		<?php 
	}


}

Plugin::instance()->widgets_manager->register_widget_type(new Banner_Slider());