<?php
namespace Elementor;

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

class Sd_Tab extends Widget_Base {

	public function get_name() {
		return 'feron-sd-tab-widget';
	}

	public function get_title() {
		return esc_html__( 'Service Details Tab', 'feron-core' );
	}

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

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

	protected function register_controls() {

        // ========== Slider Loop Section ==========
        $this->start_controls_section(
            'slider_loop_content',
            [
                'label' => __( 'Slider Items', 'feron-core' ),
                'tab'   => Controls_Manager::TAB_CONTENT,
            ]
        );

        $slider_content_repeater = new Repeater();

        $slider_content_repeater->add_control(
            'service_feature_number',
            [
				'label'   => esc_html__('Service Feature Number', 'feron-core'),
				'type'    => Controls_Manager::TEXT,
				'default' => '',
			]
        );

        $slider_content_repeater->add_control(
            'service_feature_number_title',
			[
				'label'   => esc_html__('Service Feature Number Title', 'feron-core'),
				'type'    => Controls_Manager::TEXT,
				'default' => '',
			]
        );

        $slider_content_repeater->add_control(
            'game_dev_title_image',
			[
				'label'   => __( 'Game Dev Title Image', 'feron-core' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src()],
			]
        );

		 $slider_content_repeater->add_control(
            'game_dev_title',
			[
				'label'   => esc_html__('Game Dev Title', 'feron-core'),
				'type'    => Controls_Manager::TEXT,
				'default' => '',
			]
        );

        $repeater = new Repeater();

        $repeater->add_control(
            'section_title',
            [
                'label'   => __( 'Title', 'feron-core' ),
                'type'    => Controls_Manager::TEXT,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );
		
        $repeater->add_control(
            'section_image',
          	[
				'name' => 'section_image',
				'label' => __( 'Image 1', 'feron-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			],
        );

		 $repeater->add_control(
            'sd_title',
            [
                'label'   => __( 'Inner Title', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		 $repeater->add_control(
            'sd_text',
            [
                'label'   => __( 'Inner Text', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		 $repeater->add_control(
            'sd_text2',
            [
                'label'   => __( 'Inner Text 2', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		$repeater->add_control(
            'sd_title2',
            [
                'label'   => __( 'Inner Title 2', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		 $repeater->add_control(
            'sd_text3',
            [
                'label'   => __( 'Inner Text 3', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		$repeater->add_control(
            'sd_title3',
            [
                'label'   => __( 'Inner Title 3', 'feron-core' ),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __( 'LALIGA EA SPORTS', 'feron-core' ),
            ]
        );

		$repeater->add_control(
            'sd_video_link',
           	[
				'name' => 'sd_video_link',
				'label' => __( 'Video Url', 'feron-core' ),
				'type' => Controls_Manager::URL,
				'placeholder' => __( 'https://your-link.com', 'feron-core' ),
				'show_external' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
					'nofollow' => true,
				],
			],
        );

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

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

        $repeater->add_control(
			'slider_content_loop',
			[
				'label'   => __( 'Slider Content Repeater', 'feron-core' ),
				'type'    => Controls_Manager::REPEATER,
				'fields'  => $slider_content_repeater->get_controls(),
				'default' => [],
			]
		);

        $this->add_control(
            'tab_nav_loop',
            [
                'type'        => Controls_Manager::REPEATER,
                'fields'      => $repeater->get_controls(),
                'title_field' => '{{{ section_title }}}',
                'default'     => [],
            ]
        );

        $this->end_controls_section();
    }

	protected function render() {
		$settings = $this->get_settings_for_display();
		$allowed_tags = wp_kses_allowed_html('post');

		$tab_nav_loop = ! empty( $settings['tab_nav_loop'] ) && is_array( $settings['tab_nav_loop'] ) ? $settings['tab_nav_loop'] : [];

		?>

		<section class="gt-service-details-section section-padding fix">
            <div class="container">
                <div class="gt-service-details-wrapper">
                    <div class="row justify-content-center">
                        <div class="col-xl-12">
                            <div class="gt-nav-items">
                                <ul class="nav" role="tablist">

									<?php foreach($tab_nav_loop as $key=>$item): ?>
                                    <li class="nav-item wow fadeInUp" data-wow-delay=".2s">
                                        <a href="#technical<?php echo esc_attr($key);?>" data-bs-toggle="tab" class="nav-link <?php if($key == 0) echo 'active';?>" aria-selected="<?php echo $key == 0 ? 'true' : 'false'; ?>" role="tab">
                                            <?php echo wp_kses($item['section_title'], $allowed_tags);?>
                                        </a>
                                    </li>
									<?php endforeach; ?>

                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="tab-content pt-0 mt-0">

						<?php foreach($tab_nav_loop as $key=>$item): ?>
                        <div id="technical<?php echo esc_attr($key);?>" class="tab-pane fade <?php if($key == 0) echo 'show active';?>">
                            <div class="row justify-content-center">
                                <div class="col-xl-10">
                                    <div class="gt-details-post-item">
                                        <div class="gt-details-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 class="gt-details-content">
                                            <h3>
                                                <?php echo wp_kses($item['sd_title'], $allowed_tags);?>
                                            </h3>
                                            <p>
                                               <?php echo wp_kses($item['sd_text'], $allowed_tags);?>
                                            </p>
                                            <p>
                                                <?php echo wp_kses($item['sd_text2'], $allowed_tags);?>
                                            </p>
                                            <h3 class="text">
                                                <?php echo wp_kses($item['sd_title2'], $allowed_tags);?>
                                            </h3>
                                            <div class="gt-service-feature-wrapper">

												<?php if (!empty($item['slider_content_loop'])) : 
												foreach ( $item['slider_content_loop'] as $platform ) : ?>
                                                <div class="gt-feature-item">
                                                    <h5 class="number"><?php echo esc_html($platform['service_feature_number']);?></h5>
                                                    <div class="gt-content">
                                                        <h5>
                                                            <?php echo esc_html($platform['service_feature_number_title']);?>
                                                        </h5>
                                                    </div>
                                                </div>
												<?php endforeach; 
												endif; ?>

                                            </div>
                                            <div class="row g-4">
                                                <div class="col-lg-6">
                                                    <div class="thumb">
                                                        <?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;?>
                                                    </div>
                                                </div>
                                                <div class="col-lg-6">
                                                    <div class="thumb">
                                                        <?php if(!empty(wp_get_attachment_url($item['section_image3']['id']))): ?>
															<img src="<?php echo wp_get_attachment_url($item['section_image3']['id']);?>" alt="">
														<?php endif;?>
                                                        <a href="<?php echo esc_url($item['sd_video_link']['url']);?>" class="video-btn ripple video-popup">
                                                            <i class="fa-solid fa-play"></i>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                            <p class="mt-4">
                                                <?php echo wp_kses($item['sd_text3'], $allowed_tags);?>
                                            </p>
                                            <h3 class="gt-text-2">
                                                <?php echo wp_kses($item['sd_title3'], $allowed_tags);?>
                                            </h3>
                                            <div class="gt-service-icon-wrapper mb-0">

												<?php if (!empty($item['slider_content_loop'])) : 
												foreach ( $item['slider_content_loop'] as $platform ) : ?>
                                                <div class="gt-icon-item">
                                                    <div class="icon">
													<?php if(!empty($platform['game_dev_title_image']['id'])): ?>
														<img src="<?php echo esc_url(wp_get_attachment_url($platform['game_dev_title_image']['id']));?>" alt="">
													<?php endif; ?>
                                                    </div>
                                                    <h5>
                                                        <?php echo esc_html($platform['game_dev_title']);?>
                                                    </h5>
                                                </div>
												<?php endforeach; 
												endif; ?>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
						<?php endforeach; ?>

                    </div>
                </div>
            </div>
         </section>


		<?php 
	}
}


Plugin::instance()->widgets_manager->register( new Sd_Tab() );
