<?php
namespace Elementor;

class Banner_Slider_2 extends Widget_Base {

	public function get_name() {
		return 'feron-banner-slider-2-widget';
	}

	public function get_title() {
		return esc_html__( 'Banner Slider 2', 'feron-core' );
	}

	public function get_icon() {
		return 'eicon-flash';
	}

	public function get_categories() {
		return ['feron_widgets'];
	}

	protected function register_controls() {

		// === HERO CONTENT SECTION ===
		$this->start_controls_section(
			'slider_content_section',
			[
				'label' => __( 'Slider Content', 'feron-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

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

		$this->add_control(
			'hero_subtitle',
			[
				'label'   => __( 'Subtitle', 'feron-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'Gaming Expertise', 'feron-core' ),
			]
		);

		$this->add_control(
			'hero_title',
			[
				'label'   => __( 'Title', 'feron-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => __( 'How to Choose The Right Equipment When You Are The Best Gaming Player', 'feron-core' ),
			]
		);

		$this->add_control(
			'hero_desc',
			[
				'label'   => __( 'Description', 'feron-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => __( 'Emerging trends in the esports industry include the growth of mobile esports, the integration of virtual reality in gaming experiences, and the increasing involvement of traditional sports.', 'feron-core' ),
			]
		);

		$this->end_controls_section();

		// === SLIDES REPEATER ===
		$this->start_controls_section(
			'slides_section',
			[
				'label' => __( 'Slides', 'feron-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

		$repeater = new Repeater();

		$repeater->add_control(
			'slide_image',
			[
				'label'   => __( 'Slide Image', 'feron-core' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src()],
			]
		);

		$repeater->add_control(
			'slide_video_link',
			[
				'label'       => __( 'Video URL', 'feron-core' ),
				'type'        => Controls_Manager::URL,
				'placeholder' => __( 'https://www.youtube.com/watch?v=...', 'feron-core' ),
				'default'     => [
					'url'        => 'https://www.youtube.com/watch?v=SjJhuZQlkbA',
					'is_external'=> true,
					'nofollow'   => true,
				],
			]
		);

		$repeater->add_control(
			'slide_size',
			[
				'label'   => __( 'Slide Size', 'feron-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'small',
				'options' => [
					'small'  => __( 'Small', 'feron-core' ),
					'active' => __( 'Active (Large)', 'feron-core' ),
				],
			]
		);

		$this->add_control(
			'slides',
			[
				'label'       => __( 'Slides', 'feron-core' ),
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => [
					['slide_size' => 'small'],
					['slide_size' => 'active'],
					['slide_size' => 'small'],
				],
				'title_field' => __( 'Slide - {{slide_size}}', 'feron-core' ),
			]
		);

		$this->end_controls_section();
	}

	protected function render() {
		$settings = $this->get_settings_for_display();
		?>
		<div class="hero-section hero-5 fix bg-cover" 
			style="background-image: url('<?php echo esc_url($settings['hero_bg']['url']); ?>');">
			
			<div class="array-buttons">
				<button class="array-prev"><i class="fa-solid fa-arrow-up"></i></button>
				<button class="array-next"><i class="fa-solid fa-arrow-down"></i></button>
			</div>

			<div class="container">
				<div class="row g-4 align-items-center">
					<div class="col-lg-7">
						<div class="hero-content">
							<?php if (!empty($settings['hero_subtitle'])) : ?>
								<span class="wow fadeInUp" data-wow-delay=".3s">
									<?php echo esc_html($settings['hero_subtitle']); ?>
								</span>
							<?php endif; ?>

							<?php if (!empty($settings['hero_title'])) : ?>
								<h1 class="wow fadeInUp" data-wow-delay=".5s">
									<?php echo wp_kses_post($settings['hero_title']); ?>
								</h1>
							<?php endif; ?>

							<?php if (!empty($settings['hero_desc'])) : ?>
								<p class="wow fadeInUp" data-wow-delay=".7s">
									<?php echo esc_html($settings['hero_desc']); ?>
								</p>
							<?php endif; ?>

							 <ul class="social wow fadeInUp" data-wow-delay=".5s">
                                <li>
                                    <i class="fa-solid fa-calendar-days"></i>
                                    11 March 2025
                                </li>
                                <li>
                                    <i class="fa-solid fa-comment"></i>
                                    25 comments
                                </li>
                            </ul>
						</div>
					</div>

					<div class="col-lg-5">
						<div class="slider-container">
							<?php if (!empty($settings['slides'])) : ?>
								<?php foreach ($settings['slides'] as $slide) : 
									$slide_class = !empty($slide['slide_size']) ? $slide['slide_size'] : 'small';
									?>
									<div class="slide <?php echo esc_attr($slide_class); ?>">
										<?php if (!empty($slide['slide_image']['url'])) : ?>
											<img src="<?php echo esc_url($slide['slide_image']['url']); ?>" alt="slide">
										<?php endif; ?>

										<?php if (!empty($slide['slide_video_link']['url'])) : ?>
											<a href="<?php echo esc_url($slide['slide_video_link']['url']); ?>" 
											   class="video-btn ripple video-popup">
												<i class="fa-solid fa-play"></i>
											</a>
										<?php endif; ?>
									</div>
								<?php endforeach; ?>
							<?php endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php
	}
}

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