<?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_live_auction 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_live_auction';
	}

	/**
	 * 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 Live Auction', '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(
            'live_auction',
            [
                'label' => __( 'NFT Live Auction', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );        
        
        $this->add_control(
			'subtitle_shape',
			[
				'label' => esc_html__( 'Sub Title Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'subtitle',
			[
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'subtitle_line',
			[
				'label' => esc_html__( 'Sub Title Line', '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,
			]
		);
        
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
			'product_img',
			[
				'label' => esc_html__( 'Product Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'countdown',
			[
				'label' => esc_html__( 'Count Down', 'plugin-name' ),
				'type' => \Elementor\Controls_Manager::DATE_TIME,
			]
		);
        $repeater->add_control(
			'authore_img',
			[
				'label' => esc_html__( 'Authore Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'authore_title',
			[
				'label' => esc_html__( 'Authore Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'release_date',
			[
				'label' => esc_html__( 'Release Date', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'highest_bid',
			[
				'label' => esc_html__( 'Highest Bid', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'price_label',
			[
				'label' => esc_html__( 'Price Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'price',
			[
				'label' => esc_html__( 'Price', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'fav_like',
			[
				'label' => esc_html__( 'Favorite', '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(
			'products',
			[
				'label' => esc_html__( 'Add Products Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
		$this->end_controls_section();
        $this->start_controls_section(
            'feature_settings_style',
            [
                'label' => __( 'Content Style 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__( 'Description Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-section-title-2 .subtitle' => '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-2 .subtitle',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'main_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-section-title-2 h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'ttl_bg_bg_color',
                'label'    => __( 'Background', 'ximsa' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .xis-nft-section-title-2 h2 span
                ',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-market-text-wrapper .xis-nft-section-title-2 h2
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
        $this->add_control(
            'auth_title_desc',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'auth_title_color',
            [
                'label'     => esc_html__( 'Authore Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .author-text 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-product-item .xis-nft-product-text .author-text a
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'product_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Product Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'product_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'product_title_hv_cl',
            [
                'label'     => esc_html__( 'Title Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text h3 a:hover' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'title_cl_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-product-item .xis-nft-product-text h3
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'meta_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Meta Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'meta_cl',
            [
                'label'     => esc_html__( 'Meta Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'meta_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-product-item .xis-nft-product-text p
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'price_info_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Price Info Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'price_label_cl',
            [
                'label'     => esc_html__( 'Price Label Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-price p span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'price__cl',
            [
                'label'     => esc_html__( 'Price Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-price p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'price_info_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-price p span,
                    .xis-nft-product-item .xis-nft-product-text .product-price p
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'like_info_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Like Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'like_no_cl',
            [
                'label'     => esc_html__( 'Like NUmber Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-like' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'like_icon_sl',
            [
                'label'     => esc_html__( 'Like Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-like i' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'like_info_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-product-item .xis-nft-product-text .product-like
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'box_date_desc',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'CountDown Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'count-time-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'classic', 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-live-bid-item .coming-countdown li strong',
			]
		);
        $this->add_control(
            'day_color',
            [
                'label'     => esc_html__( 'Days Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-live-bid-item .coming-countdown li span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'timeo_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-nft-live-bid-item .coming-countdown li span
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'count-box-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'classic', 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-live-bid-item .coming-countdown',
			]
		);
        $this->add_control(
            'box_count_desc',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Box Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'box-bg-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'classic', 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-nft-product-item',
			]
		);
       
        
		$this->end_controls_section();
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
        <!-- Start of Live Bid section
        ============================================= -->
        <section id="xis-nft-live-bid" class="xis-nft-live-bid-section">
            <div class="container">
                <div class="xis-nft-live-bid-top-content d-flex align-items-center justify-content-between">
                    <div class="xis-nft-section-title-2 text-left xis-nft-headline">
                        <div class="subtitle position-relative">
                            <img src="<?php echo esc_url($settings['subtitle_shape']['url']);?>" alt=""><?php echo wp_kses( $settings['subtitle'], true );?> <span><img src="<?php echo esc_url($settings['subtitle_line']['url']);?>" alt=""></span>
                        </div>
                        <h2><?php echo wp_kses( $settings['title_main'], true );?></span></h2>
                    </div>
                    <div class="carousel_nav text-right ">
                        <button type="button" class="liv-bid_left_arrow"><i class="far fa-long-arrow-left"></i></button>
                        <button type="button" class="liv-bid_right_arrow"><i class="far fa-long-arrow-right"></i></button>
                    </div>
                </div>
                <div class="xis-nft-live-bid-slider-wrapper">
                    <div class="xis-nft-live-bid-slider">
                        <?php foreach($settings['products'] as $product):  ?>
                        <div class="xis-nft-live-bid-item">
                            <div class="xis-nft-product-item">
                                <div class="xis-nft-product-img position-relative">
                                    <img src="<?php echo esc_url($product['product_img']['url']);?>" alt="<?php echo esc_url($product['product_img']['alt']);?>">
                                    <div class="coming-countdown ul-li">
                                        <ul class="countdown_timer text-center clearfix" data-countdown="<?php echo esc_attr($product['countdown']);?>"></ul>
                                    </div> 
                                </div>
                                <div class="xis-nft-product-text xis-nft-headline pera-content">
                                    <div class="product-author d-flex  align-items-center position-relative">
                                        <span class="dot-link position-absolute"><a href="#">...</a></span>
                                        <div class="author-img position-relative">
                                            <img src="<?php echo esc_url($product['authore_img']['url']);?>" alt="<?php echo esc_url($product['authore_img']['alt']);?>">
                                        </div>
                                        <div class="author-text d-flex justify-content-between">
                                            <a href="<?php echo esc_url($product['link']['url']);?>"><?php echo wp_kses( $product['authore_title'], true );?></a>
                                        </div>
                                    </div>
                                    <h3><a href="<?php echo esc_url($product['link']['url']);?>"><?php echo wp_kses( $product['title'], true );?></a></h3>
                                    <p><?php echo wp_kses( $product['release_date'], true );?></p>
                                    <p class="hi-bid"><?php echo wp_kses( $product['highest_bid'], true );?></p>
                                    <div class="product-price-like d-flex justify-content-between align-items-center">
                                        <div class="product-price">
                                            <p><span><?php echo esc_html($product['price_label']);?></span> <i class="fab fa-ethereum"></i> <?php echo esc_html($product['price']);?></p>
                                        </div>
                                        <div class="product-like">
                                            <i class="far fa-heart"></i><?php echo esc_html($product['fav_like']);?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php endforeach;?>
                    </div>
                </div>
            </div>
        </section>		
    <!-- End  of Live Bid section
        ============================================= -->
    <?php  
    }
	
}

