<?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 crypto_reward_widget 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 'crypto-reward-section';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Crypto Reward Section', '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(
            'crypto_reward_options',
            [
                'label' => __( 'Crypto Reward', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'shape1',
			[
				'label' => esc_html__( 'Shape 1', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape2',
			[
				'label' => esc_html__( 'Shape 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape3',
			[
				'label' => esc_html__( 'Shape 3', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'box_icon',
			[
				'label' => esc_html__( 'Box Icon', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Business is the Best Plan', 'ximsa' ),
				'placeholder' => esc_html__( 'Type List Item Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'feature_info',
			[
				'label' => esc_html__( 'Feature Info', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'featuresitem',
			[
				'label' => esc_html__( 'Add Feature Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        $this->add_control(
			'cr_sub_title',
			[
				'label' => esc_html__( 'Feature Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
                'default' => esc_html__( 'Who We Are?', 'ximsa' ),
				'placeholder' => esc_html__( 'Type feature Sub Title Here', 'ximsa' ),
			]
		);
        $this->add_control(
			'cr_title',
			[
				'label' => esc_html__( 'Feature Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
                'default' => esc_html__( 'Create your crypto portfolio today', 'ximsa' ),
				'placeholder' => esc_html__( 'Type feature Title Here', 'ximsa' ),
			]
		);
        $this->add_control(
			'cr_txt',
			[
				'label' => esc_html__( 'Feature Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);

        $this->add_control(
			'btn_label',
			[
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);

        $this->add_control(
			'btn_link',
			[
				'label' => esc_html__( 'Btn Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'number',
			[
				'label' => esc_html__( 'Number', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'text',
			[
				'label' => esc_html__( 'Text', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'calculations',
			[
				'label' => esc_html__( 'Add Calculations Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ text }}}',
			]
		);
        $this->end_controls_section();
        $this->start_controls_section(
            'feature_settings_style',
            [
                'label' => __( 'section Title Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'feature_box_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Box Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );     
        $this->add_control(
            'box_bg_color',
            [
                'label'     => esc_html__( 'Feature Box Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block .inner-box' => 'background: {{VALUE}} ',
                ],
            ]
        );   
        $this->add_control(
            'box_bg_icon_color',
            [
                'label'     => esc_html__( 'Feature Box Icon BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block .inner-box .icon' => 'background: {{VALUE}} ',
                ],
            ]
        );   
        $this->add_control(
            'se__sub_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );        
        $this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'sub_bgbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .sec-title-two .title',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-two .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'se_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'se_ht_color',
            [
                'label'     => esc_html__( 'Heading Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-two h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-two h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'feature_desc',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Description Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'sl_desc_color',
            [
                'label'     => esc_html__( 'Description Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-two .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ab_desc_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-two .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'fs_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'feature Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'fs_title_cl',
            [
                'label'     => esc_html__( 'Feature Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block .inner-box h4' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fs_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .reward-block .inner-box h4',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_ct_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Counter Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'fs_text_cl',
            [
                'label'     => esc_html__( 'Feature Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block .inner-box .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fs_text_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .reward-block .inner-box .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

       
        $this->add_control(
            'ct_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Counter Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'ct_title_cl',
            [
                'label'     => esc_html__( 'Counter Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-reward-section .calculation-box .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ct_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-reward-section .calculation-box .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'ct_number_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Counter Number Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'ct_num_cl',
            [
                'label'     => esc_html__( 'Counter Number Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-reward-section .calculation-box h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ct_number_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-reward-section .calculation-box h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'ct_txt_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Counter Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'ct_txt_cl',
            [
                'label'     => esc_html__( 'Counter Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-reward-section .calculation-box .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ct_text_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-reward-section .calculation-box .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
		$this->end_controls_section();
        $this->start_controls_section(
            'button__content',
            [
                'label' => __( 'Crypto Button Style', 'ximsa' ),
                'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name'           => 'btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .btn-style-fifteen .txt
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
        $this->start_controls_tabs( '_banner_button_1' );
        $this->start_controls_tab(
            '_glow-extension_btn__banner_normal',
            [
                'label' => esc_html__( 'Normal', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .btn-style-fifteen' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .btn-style-fifteen
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .btn-style-fifteen' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        
        $this->end_controls_tab();
        $this->start_controls_tab(
            '_glow-extension_btn_hover',
            [
                'label' => esc_html__( 'Hover', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__hover_color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .btn-style-fifteen:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_hover_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .btn-style-fifteen:before
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_hover_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .btn-style-fifteen:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',                    
                ],
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();
        $this->end_controls_section();
	}
		


	protected function render() {
		
		
		$settings = $this->get_settings_for_display(); ?>
		<!-- Crypto Reward Section -->
        <section class="crypto-reward-section">
            <!-- Shape Layer One -->
            <div class="shape-layer-one" style="background-image: url(<?php echo esc_url($settings['shape1']['url']);?>)"></div>

            <div class="shape_1" data-parallax='{"y" : 90}'>
                <div class="shape-layer-two updown-animate" style="background-image: url(<?php echo esc_url($settings['shape2']['url']);?>)"></div>
            </div>
            
            <div class="shape-layer-three" style="background-image: url(<?php echo esc_url($settings['shape3']['url']);?>)"></div>
            <div class="auto-container">
                <div class="row clearfix">
                
                    <!-- Blocks Column -->
                    <div class="blocks-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <div class="row clearfix">
                                <?php foreach($settings['featuresitem'] as $item):?>
                                <!-- Reward Block -->
                                <div class="reward-block wow fadeInUp col-lg-6 col-md-6 col-sm-12" data-wow-delay="0s" data-wow-duration="1500ms">
                                    <div class="inner-box">
                                        <div class="color-one"></div>
                                        <div class="color-two"></div>
                                        <div class="icon"><img src="<?php echo esc_url($item['box_icon']['url']);?>" alt="" /></div>
                                        <div class="content">
                                            <h4><?php echo esc_html($item['title']);?></h4>
                                            <div class="text"><?php echo __($item['feature_info']);?></div>
                                        </div>
                                    </div>
                                </div>
                                <?php endforeach;?>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Content Column -->
                    <div class="content-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <div class="sec-title-two">
                                <div class="title"><?php echo esc_html($settings['cr_sub_title']);?></div>
                                <h2><?php echo esc_html($settings['cr_title']);?></h2>
                                <div class="text"><?php echo __($settings['cr_txt']);?></div>
                            </div>
                            <div class="btn-box">
                                <a href="<?php echo esc_url($settings['btn_link']['url']);?>" class="theme-btn btn-style-fifteen"><span class="txt"><?php echo esc_html($settings['btn_label']);?> <i class="fa fa-chevron-circle-right"></i></span></a>
                            </div>
                            <div class="reward-calculation">
                                <div class="row clearfix">
                                    <?php foreach($settings['calculations'] as $item):?>
                                    <!-- Calculation Box -->
                                    <div class="calculation-box col-xl-4 col-lg-6 col-md-6 col-sm-12">
                                        <div class="title"><?php echo esc_html($item['title']);?></div>
                                        <h3><?php echo esc_html($item['number']);?></h3>
                                        <div class="text"><?php echo esc_html($item['text']);?></div>
                                    </div>
                                    <?php endforeach;?>
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
        </section>
        <!-- End Crypto Reward Section -->
		<?php 
      }
	
	

}
