<?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_market_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-market-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 Market', '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_mrkt_options',
            [
                'label' => __( 'Crypto Market 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(
			'market_heading',
			[
				'label' => esc_html__( 'Market Heading', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'price_heading',
			[
				'label' => esc_html__( 'Price Heading', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'change_heading',
			[
				'label' => esc_html__( 'Change Heading', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'dynamic_heading',
			[
				'label' => esc_html__( 'Dynamic Heading', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'upgrade-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'classic' ],
				'exlcude' => [ 'color' ],
				'selector' => '{{WRAPPER}} .pricing-rates li:before',
			]
		);
        
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
            'market_info',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Marketing Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $repeater->add_control(
			'coin_logo',
			[
				'label' => esc_html__( 'Coin Logo', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'coin_shprt_name',
			[
				'label' => esc_html__( 'Coin Short Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'coin_full_name',
			[
				'label' => esc_html__( 'Coin Full Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
            'price_info',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Price Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $repeater->add_control(
			'price',
			[
				'label' => esc_html__( 'Price', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
            'change_info',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Change Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $repeater->add_control(
			'down',
			[
				'label' => esc_html__( 'Down', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'YES', 'ximsa' ),
				'label_off' => esc_html__( 'NO', 'ximsa' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);
        $repeater->add_control(
			'change_percentage',
			[
				'label' => esc_html__( 'Change Percentage', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
            'dynamic_info',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Dynamic Info', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $repeater->add_control(
			'dynamic_bar',
			[
				'label' => esc_html__( 'Dynamic Img', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'marketsections',
			[
				'label' => esc_html__( 'Add Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ coin_shprt_name }}}',
			]
		);
       
		$this->end_controls_section();

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

        $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}} .crypto-market-section .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-market-section .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'short_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Short Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'short_title_color',
            [
                'label'     => esc_html__( 'Short Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-market-section .coins-list li span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'short_desc_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-market-section .coins-list li span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'full_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Full Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'full_title_cl',
            [
                'label'     => esc_html__( 'Full Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-market-section .coins-list li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fl_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-market-section .coins-list li',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'price_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Price Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'price_cl',
            [
                'label'     => esc_html__( 'Price Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-market-section .price-list li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'price_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .crypto-market-section .price-list li',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
        $this->add_control(
            'rate_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Rate Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'rate__clr',
            [
                'label'     => esc_html__( 'Rate BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-rates li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rate_bg_clr',
            [
                'label'     => esc_html__( 'Rate BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-rates li' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rate_down_bg_clr',
            [
                'label'     => esc_html__( 'Rate Down BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-rates li.down' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'rt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .pricing-rates li',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
		$this->end_controls_section();
	}
		


	protected function render() {
		
		
		$settings = $this->get_settings_for_display(); ?>
		<!-- Crypto Market Section -->
        <section class="crypto-market-section" style="background-image: url(<?php echo esc_url($settings['shape1']['url']);?>)">
            <div class="auto-container">
                <div class="inner-container">
                    <div class="content">
                    
                        <!-- Market Names -->
                        <div class="market-name">
                            <div class="title"><?php echo esc_html($settings['market_heading']);?></div>
                            <ul class="coins-list">
                                <?php foreach($settings['marketsections'] as $item):?>
                                <li>
                                    <span class="icon"><img src="<?php echo esc_html($item['coin_logo']['url']);?>" alt="" /></span>
                                    <span><?php echo esc_html($item['coin_shprt_name']);?></span> <?php echo esc_html($item['coin_full_name']);?>
                                </li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                        <!-- End Market Names -->
                        
                        <!-- Price Box -->
                        <div class="price-box">
                            <div class="title"><?php echo esc_html($settings['price_heading']);?></div>
                            <ul class="price-list">
                                <?php foreach($settings['marketsections'] as $item):?>
                                    <li><?php echo esc_html($item['price']);?></li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                        <!-- Price Box -->
                        
                        <!-- Price Box -->
                        <div class="price-change-box">
                            <div class="title"><?php echo esc_html($settings['change_heading']);?></div>
                            <ul class="pricing-rates">
                                <?php foreach($settings['marketsections'] as $item):?>
                                <li class="<?php if($item['down'] == 'yes'){echo esc_attr('down');}?>"><?php echo esc_html($item['change_percentage']);?></li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                        <!-- Price Box -->
                        
                        <!-- Dynamic Box -->
                        <div class="dynamic-box">
                            <div class="title"><?php echo esc_html($settings['dynamic_heading']);?></div>
                            <ul class="dynamic-graph">
                                <?php foreach($settings['marketsections'] as $item):?>
                                <li><img src="<?php echo esc_url($item['dynamic_bar']['url']);?>" alt="" /></li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                        <!-- End Dynamic Box -->
                        
                    </div>
                </div>
            </div>
        </section>
        <!-- End Crypto Market Section -->
		<?php 
      }
	
	

}
