<?php

namespace XIMSAPLUGIN\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\Group_Control_Background;
use Elementor\Plugin;

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

class nft_top_seller extends Widget_Base {

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

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Nft Top Seller', 'ximsa' );
	}

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

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Elementor widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'ximsa' ];
	}

	/**
	 * Register Elementor 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(
            'nft_top_options',
            [
                'label' => __( 'NFT Top Seller Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );        
        $this->add_control(
			'shape',
			[
				'label' => esc_html__( 'Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'subtitle_shape',
			[
				'label' => esc_html__( 'Sub Title Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);        
        $this->add_control(
			'title_main',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'title_shape',
			[
				'label' => esc_html__( 'Title Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'authore_img',
			[
				'label' => esc_html__( 'Authore Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'auth_name',
			[
				'label' => esc_html__( 'Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'earning',
			[
				'label' => esc_html__( 'Earning', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'link',
			[
				'label' => esc_html__( 'Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'topseller',
			[
				'label' => esc_html__( 'Add Top Seller Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ earning }}} {{{ auth_name }}}',
			]
		);
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'authore_img',
			[
				'label' => esc_html__( 'Authore Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'auth_name',
			[
				'label' => esc_html__( 'Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'earning',
			[
				'label' => esc_html__( 'Earning', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'link',
			[
				'label' => esc_html__( 'Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'topseller2',
			[
				'label' => esc_html__( 'Add Top Seller Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ earning }}} {{{ auth_name }}}',
			]
		);
        $this->add_control(
			'community_title',
			[
				'label' => esc_html__( 'Community Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape_2',
			[
				'label' => esc_html__( 'Shape 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape_3',
			[
				'label' => esc_html__( 'Shape 3', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape_4',
			[
				'label' => esc_html__( 'Shape 4', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'currency_symbole',
			[
				'label' => esc_html__( 'Currency Symbole', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'community_earning',
			[
				'label' => esc_html__( 'Community Earning', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'community_comment',
			[
				'label' => esc_html__( 'Community Comment', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
		$this->end_controls_section();

        $this->start_controls_section(
            'slider_settings_style',
            [
                'label' => __( 'Banner Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        
        $this->add_control(
            'slider_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sl_title_color',
            [
                'label'     => esc_html__( 'Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'authore_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Name Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'authore_name_color',
            [
                'label'     => esc_html__( 'Authore Name Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-top-seller-item .xis-nft-top-seller-text h3 a' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'auth_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-item .xis-nft-top-seller-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'earning_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Earning Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'earning_color',
            [
                'label'     => esc_html__( 'Earning Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-top-seller-item .xis-nft-top-seller-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'auth_ern_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-item .xis-nft-top-seller-text p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'community_pric_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Community Price Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'com_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-community-income .income-amount p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'community_desc_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Community Desc Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'elmbackground',
				'label' => esc_html__( 'Elem Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-top-seller-community-income .income-amount h3',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'com_pri_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-community-income .income-amount h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'community_comment',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Community Comment Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'community_title_color',
            [
                'label'     => esc_html__( 'Community Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-top-seller-community-income .income-text' => 'color: {{VALUE}} ',
                ],
            ]
        );
       
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'com_cmt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-community-income .income-text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'number_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Number Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'number_cl_brbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-top-seller-item .serial',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'no_cmt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-nft-top-seller-item .serial',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'top_box_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Box Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'box_bg_cl',
            [
                'label'     => esc_html__( 'Box BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-top-seller-list-wrapper:after, .xis-nft-top-seller-items:after' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'box_brbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-top-seller-list-wrapper:before, .xis-nft-top-seller-items:before',
			]
		);
        
		$this->end_controls_section();
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
        <!-- Start of Top sellers section
        ============================================= -->
        <section id="xis-nft-top-seller" class="xis-nft-top-seller-section position-relative">
            <span class="xis-nft-side-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape']['url']);?>" alt=""></span>
            <div class="container">
                <div class="xis-nft-section-title xis-nft-headline d-flex align-items-center wow fadeInUp"  data-wow-delay="0ms" data-wow-duration="1000ms">
                    <h2><img src="<?php echo esc_url($settings['subtitle_shape']['url']);?>" alt=""><?php echo esc_html($settings['title_main']);?> <span><img src="<?php echo esc_url($settings['title_shape']['url']);?>" alt=""></span></h2>
                </div>
                <div class="xis-nft-top-seller-content">
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="xis-nft-top-seller-list-wrapper">
                                <?php $i = 0; foreach($settings['topseller'] as $item): $i++;
                                ?>
                                <div class="xis-nft-top-seller-item xis-nft-headline d-flex align-items-center pera-content position-relative wow fadeInUp"  data-wow-delay="500ms" data-wow-duration="1000ms">
                                    <span class="serial position-absolute"><?php echo esc_attr($i);?></span>
                                    <div class="xis-nft-top-seller-img position-relative">
                                        <img src="<?php echo esc_url($item['authore_img']['url']);?>" alt="<?php echo esc_attr($item['authore_img']['alt']);?>">
                                    </div>
                                    <div class="xis-nft-top-seller-text">
                                        <h3><a href="<?php echo esc_url($item['link']['url']);?>"><?php echo esc_html($item['auth_name']);?></a></h3>
                                        <p><?php echo esc_html($item['earning']);?></p>
                                    </div>
                                </div>
                                <?php endforeach;?>
                            </div>
                        </div>
                        <div class="col-lg-8">
                            <div class="xis-nft-top-seller-community-wrapper position-relative">

                                <span class="xis-nft-ts-shape1 position-absolute" data-parallax='{"y" : 50, "rotateY":200}'><img src="<?php echo esc_url($settings['shape_2']['url']);?>" alt=""></span>

                                <span class="xis-nft-ts-shape2 position-absolute"><img src="<?php echo esc_url($settings['shape_3']['url']);?>" alt=""></span>

                                <span class="xis-nft-ts-shape3 position-absolute" data-parallax='{"x" : -50, "rotateX":200}'><img src="<?php echo esc_url($settings['shape_4']['url']);?>" alt=""></span>
                                
                                <div class="xis-nft-top-seller-community-income xis-nft-headline pera-content">
                                    <div class="income-amount">
                                        <p><?php echo wp_kses( $settings['community_title'], true )?></p>
                                        <h3><?php echo esc_html($settings['currency_symbole']);?><span class="counter"><?php echo wp_kses( $settings['community_earning'], true )?></span></h3>
                                    </div>
                                    <div class="income-text">
                                        <?php echo wp_kses( $settings['community_comment'], true )?>
                                    </div>
                                </div>
                                <div class="xis-nft-top-seller-items">
                                    <div class="row">
                                        <?php $i = 0; foreach($settings['topseller2'] as $item): $i++; ?>
                                        <div class="col-md-6 wow fadeInUp"  data-wow-delay="600ms" data-wow-duration="1000ms">
                                            <div class="xis-nft-top-seller-item xis-nft-headline d-flex align-items-center pera-content position-relative">
                                                <span class="serial position-absolute"><?php echo esc_attr($i);?></span>
                                                <div class="xis-nft-top-seller-img position-relative">
                                                    <img src="<?php echo esc_url($item['authore_img']['url']);?>" alt="<?php echo esc_attr($item['authore_img']['alt']);?>">
                                                </div>
                                                <div class="xis-nft-top-seller-text">
                                                    <h3><a href="<?php echo esc_url($item['link']['url']);?>"><?php echo esc_html($item['auth_name']);?></a></h3>
                                                    <p><?php echo esc_html($item['earning']);?></p>
                                                </div>
                                            </div>                                     
                                        </div>                                     
                                        <?php endforeach;?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <!-- End of Top sellers section
        ============================================= -->
    <?php  
    }
	
}

