<?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_app_section_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-app-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 App 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_app_options',
            [
                'label' => __( 'Crypto Options', '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(
			'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,
			]
		);

        $repeater = new \Elementor\Repeater();
        
        $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,
			]
		);
        
        $this->add_control(
			'listitems',
			[
				'label' => esc_html__( 'feature List Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        $this->add_control(
            'app_store_control',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'App Store Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
			'app_store_btn',
			[
				'label' => esc_html__( 'App Store Button', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);

        $this->add_control(
			'app_link',
			[
				'label' => esc_html__( 'App Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        $this->add_control(
            'play_store_control',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Play Store Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
			'play_store_btn',
			[
				'label' => esc_html__( 'Play Store Button', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);

        $this->add_control(
			'play_link',
			[
				'label' => esc_html__( 'Play Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        $this->add_control(
            'qr_code_control',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Qr Code Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
			'qrcode_btn',
			[
				'label' => esc_html__( 'QR Code Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);

        $this->add_control(
			'qr_link',
			[
				'label' => esc_html__( 'QR 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(
			'symbole',
			[
				'label' => esc_html__( 'Symbole', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'fanfacts',
			[
				'label' => esc_html__( 'Fanfact Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        $this->add_control(
			'app_image',
			[
				'label' => esc_html__( 'App Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
		$this->end_controls_section();

		$this->start_controls_section(
            'feature_options',
            [
                'label' => __( 'Feature Image Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'circle_shape',
			[
				'label' => esc_html__( 'Circle Shape Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'mobile_mockup',
			[
				'label' => esc_html__( 'Mobile Screen', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'payment_img',
			[
				'label' => esc_html__( 'Payment Screen', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'msg_img',
			[
				'label' => esc_html__( 'Message Screen', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        
        $this->end_controls_section();

        $this->start_controls_section(
            'feature_settings_style',
            [
                'label' => __( 'feature Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $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_list_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'feature List Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'fs_list_cl',
            [
                'label'     => esc_html__( 'List Txt Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-app-section .content-column .options li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'ab_list_bg',
            [
                'label'     => esc_html__( 'List Dot BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-app-section .content-column .options li::before' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ab_list_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-app-section .content-column .options li',
                '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(
            'ct_no_cl',
            [
                'label'     => esc_html__( 'Counter Number Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-fact-counter .counter-column .inner .count-outer' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ct_number_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-fact-counter .counter-column .inner .count-outer',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_symbole_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Counter Symbole Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'ct_bg_symbole_bgbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .crypto-fact-counter .counter-column .inner .count-outer i',
			]
		);
        $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-fact-counter .counter-column .inner .counter-title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ct_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-fact-counter .counter-column .inner .counter-title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
		$this->end_controls_section();
	}
		


	protected function render() {
		
		
		$settings = $this->get_settings_for_display(); ?>
		<!-- Crypto App Section -->
        <section class="crypto-app-section">
            <!-- Shape Layer One -->
            <div class="deco_image shape_1" data-parallax='{"y" : 90}'>
                <div class="shape-layer-one updown-animate" style="background-image: url(<?php echo esc_url($settings['shape1']['url']);?>)"></div>
            </div>
            <div class="shape-layer-two" style="background-image: url(<?php echo esc_url($settings['shape2']['url']);?>)"></div>
            <div class="auto-container">
                <div class="row clearfix">
                
                    <!-- 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>
                            <ul class="options">
                                <?php foreach($settings['listitems'] as $item):?>
                                <li><?php echo __($item['title']);?></li>
                                <?php endforeach;?>
                            </ul>
                            <div class="buttons-box">
                                
                                <?php if(!empty($settings['app_store_btn']['url'])):?>
                                    <a href="<?php echo esc_url($settings['app_link']['url']);?>"><img src="<?php echo esc_url($settings['app_store_btn']['url']);?>" alt="" /></a>
                                <?php endif;?>

                                <?php if(!empty($settings['play_store_btn']['url'])):?>
                                    <a href="<?php echo esc_url($settings['play_link']['url']);?>"><img src="<?php echo esc_url($settings['play_store_btn']['url']);?>" alt="" /></a>
                                <?php endif;?>

                                <?php if(!empty($settings['qrcode_btn']['url'])):?>
                                    <a href="<?php echo esc_url($settings['qr_link']['url']);?>"><img src="<?php echo esc_url($settings['qrcode_btn']['url']);?>" alt="" /></a>
                                <?php endif;?>

                            </div>
                            
                            <!-- Counter Box -->
                            <div class="counter-box">
                                <!-- Fact Counter -->
                                <div class="crypto-fact-counter">
                                    <div class="row clearfix">
                                        <?php if($settings['fanfacts']):?>
                                            <?php foreach($settings['fanfacts'] as $fnf):?>
                                            <!-- Column -->
                                            <div class="counter-column col-lg-4 col-md-4 col-sm-12">
                                                <div class="inner wow fadeInLeft" data-wow-delay="0ms" data-wow-duration="1500ms">
                                                    <div class="content">
                                                        <div class="count-outer count-box">
                                                            <span class="count-text odometer" data-count="<?php echo esc_attr($fnf['number']);?>"></span><i><?php echo esc_html($fnf['symbole']);?></i>
                                                        </div>
                                                        <div class="counter-title"><?php echo esc_html($fnf['title']);?></div>
                                                    </div>
                                                </div>
                                            </div>
                                            <?php endforeach;?>
                                        <?php endif;?>
                                    </div>
                                </div>
                                
                            </div>
                            <!-- End Counter Box -->
                            
                        </div>
                    </div>
                    <?php if($settings['app_image']['url']):?>
                        <!-- Image Column -->
                        <div class="image-column col-lg-6 col-md-12 col-sm-12">
                            <div class="inner-column">
                                <div class="image wow fadeInRight" data-wow-delay=".3s" data-wow-duration="1500ms">
                                    <img src="<?php echo esc_url($settings['app_image']['url']);?>" alt="" />
                                </div>
                            </div>
                        </div>
                    <?php endif;?>
                </div>
            </div>
        </section>
        <!-- End Crypto App Section -->
		<?php 
      }
	
	

}

