<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Feron
 * @since 1.0.0
 */ 
 
class Club_Players 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 'feron-club-players-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__( 'Club Players', 'feron-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 ['feron_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() {

		// Tab Start - 1

		$this->start_controls_section(
			'club_players_content',
			[
				'label' => esc_html__( 'Club players', 'feron-core' ),
			]
		);		
		

		$this->add_control(
			'title',
			[
				'label'       => esc_html__( 'Title', 'feron-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => esc_html__( 'Our Clients Feedback', 'feron-core' ),
				'label_block' => true,
			]
		);

		$this->add_control(
			'text',
			[
				'label'       => esc_html__( 'Text', 'feron-core' ),
				'type'        => Controls_Manager::TEXTAREA,
				'default'     => esc_html__( 'What They Say', 'feron-core' ),
				'label_block' => true,
			]
		);

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

		// Tab Start - 2

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

						[
							'name' => 'section_button_link',
							'label' => __( 'Player Url', 'feron-core' ),
							'type' => Controls_Manager::URL,
							'placeholder' => __( 'https://your-link.com', 'feron-core' ),
							'show_external' => true,
							'default' => [
								'url' => '',
								'is_external' => true,
								'nofollow' => true,
							],
						],
						[
							'name'  => 'section_title',
							'label' => esc_html__( 'Player Name', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('John Doe', 'feron-core'),
						],

						[
							'name'  => 'section_player_position',
							'label' => esc_html__( 'Player Position', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('Forward', 'feron-core'),
						],

						[
							'name'  => 'total_matches_number',
							'label' => esc_html__( 'total matches number', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('100', 'feron-core'),
						],

						[
							'name'  => 'current_season',
							'label' => esc_html__( 'current season', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('2025/2026', 'feron-core'),
						],

						[
							'name'  => 'current_season_appearances',
							'label' => esc_html__( 'current season appearances', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('0', 'feron-core'),
						],

						[
							'name'  => 'total_goals',
							'label' => esc_html__( 'total goals', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('60', 'feron-core'),
						],

						[
							'name'  => 'current_season_goals',
							'label' => esc_html__( 'current season goals', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('0', 'feron-core'),
						],

						[
							'name'  => 'total_assists',
							'label' => esc_html__( 'total assists', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('60', 'feron-core'),
						],

						[
							'name'  => 'current_season_assists',
							'label' => esc_html__( 'current season assists', 'feron-core' ),
							'type'  => Controls_Manager::TEXT,
							'default' => esc_html__('0', 'feron-core'),
						],

						
					],
				'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="our-club-player-section fix">
            <div class="container">
                <div class="section-title-area">
                    <div class="section-title style-3 mb-0">
                        <?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
							<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
						<?php endif;?>
                        <h2 class="t-uppercase wow fadeInUp" data-wow-delay=".3s">
                             <?php echo $settings['title'];?>
                        </h2>
                    </div>
                    <div class="right-content">
                        <p>
                            <?php echo $settings['text'];?>
                        </p>
                        <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="clip03_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_200_853)">
                                <path d="M17.9941 16.8402L17.9941 3.23823C17.9941 2.59839 17.4738 2.07808 16.834 2.07808C16.1941 2.07808 15.6738 2.59839 15.6738 3.23823L15.6738 14.0347L1.97695 0.341357C1.52344 -0.112159 0.788671 -0.112159 0.335157 0.341357C-0.118359 0.794872 -0.118359 1.52964 0.335157 1.98315L14.032 15.6765L3.23555 15.6765C2.5957 15.6765 2.07539 16.1968 2.07539 16.8367C2.07539 17.4765 2.5957 17.9968 3.23555 17.9968L16.834 17.9968C17.4738 18.0003 17.9941 17.48 17.9941 16.8402Z" fill="#0B0E13"/>
                            </g>
                            <defs>
                                <clipPath id="clip04_200_853">
                                <rect width="18" height="18" fill="white" transform="translate(17.9941 0.000244141) rotate(90)"/>
                                </clipPath>
                            </defs>
                            </svg>
                        </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="swiper player-slider">
                <div class="swiper-wrapper">

					<?php foreach($settings['repeat'] as $item):?>	
                    <div class="swiper-slide">
                        <div class="our-club-payer-item">
                            <div class="player-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;?>
                                <h2 class="number"><?php echo wp_kses($item['section_player_number'], $allowed_tags);?></h2>
                                <div class="player-content">
                                    <h4>
                                        <a href="<?php echo esc_url($item['section_button_link']['url']);?>"><?php echo wp_kses($item['section_title'], $allowed_tags);?></a>
                                    </h4>
                                    <p>
                                      <?php echo wp_kses($item['section_player_position'], $allowed_tags);?>
                                    </p>
                                </div>
                                <div class="content-item">

                                    <div class="content">
                                        <h6>Appearances</h6>
                                        <h5><?php echo wp_kses($item['total_matches_number'], $allowed_tags);?></h5>
                                        <span><?php echo wp_kses($item['current_season'], $allowed_tags);?></span>
                                        <h6 class="title"><?php echo wp_kses($item['current_season_appearances'], $allowed_tags);?></h6>
                                    </div>

                                    <div class="content">
                                        <h6>NITRO gola</h6>
                                        <h5><?php echo wp_kses($item['total_goals'], $allowed_tags);?></h5>
                                        <span><?php echo wp_kses($item['current_season'], $allowed_tags);?></span>
                                        <h6 class="title"><?php echo wp_kses($item['current_season_goals'], $allowed_tags);?></h6>
                                    </div>

                                    <div class="content">
                                        <h6>NITRO Assists</h6>
                                        <h5><?php echo wp_kses($item['total_assists'], $allowed_tags);?></h5>
                                        <span><?php echo wp_kses($item['current_season'], $allowed_tags);?></span>
                                        <h6 class="title"><?php echo wp_kses($item['current_season_assists'], $allowed_tags);?></h6>
                                    </div>
									
                                </div>
                            </div>
                        </div>
                    </div>
					<?php endforeach; ?>

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

             
		<?php 
	}


}

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