<?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 fintech_rewards 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 'fintech-rewards';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Fintech Rewards', '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(
            'fintech_rewards_options',
            [
                'label' => __( 'Fintech Rewards Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'icon_type',
			[
				'label' => esc_html__( 'Icon Type', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'icon' => [
						'title' => esc_html__( 'Icon', 'ximsa' ),
						'icon' => 'eicon-nerd',
					],
					'text' => [
						'title' => esc_html__( 'Text', 'ximsa' ),
						'icon' => 'eicon-text-field',
					],
				],
				'default' => 'icon',
				'toggle' => true,
			]
		);
        $this->add_control(
			'top_icon',
			[
				'label' => esc_html__( 'Icon', 'ximsa' ),
				'type' => Controls_Manager::ICONS,
                'label_block' => true,
                'condition' => ['icon_type' => 'icon'],
			]
		);
        $this->add_control(
			'top_icon_xtx',
			[
				'label' => esc_html__( 'Icon Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
                'condition' => ['icon_type' => 'text'],
			]
		);

        $this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
				'placeholder' => esc_html__( 'The World’s Most Rewarding Buying Experience.', 'ximsa' ),
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'subtext',
			[
				'label' => esc_html__( 'Sub Text', '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__( 'Button link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $repeater = new \Elementor\Repeater();        
        $repeater->add_control(
			'style',
			[
				'label' => esc_html__( 'Style', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => '1',
				'options' => [
					'1'  => esc_html__( 'Style One', 'ximsa' ),
					'2' => esc_html__( 'Style One', 'ximsa' ),
				],
			]
		);
        $repeater->add_control(
			'icon_type',
			[
				'label' => esc_html__( 'Icon Type', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'icon' => [
						'title' => esc_html__( 'Icon', 'ximsa' ),
						'icon' => 'eicon-nerd',
					],
					'text' => [
						'title' => esc_html__( 'Text', 'ximsa' ),
						'icon' => 'eicon-text-field',
					],
				],
				'default' => 'icon',
				'toggle' => true,
			]
		);
        $repeater->add_control(
			'icon',
			[
				'label' => esc_html__( 'Block Icon', 'ximsa' ),
				'type' => Controls_Manager::ICONS,
                'label_block' => true,
                'condition' => ['icon_type' => 'icon'],
			]
		);
        $repeater->add_control(
			'icon_txt',
			[
				'label' => esc_html__( 'Block Icon Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
                'condition' => ['icon_type' => 'text'],
			]
		);
        $repeater->add_control(
			'block_pattern',
			[
				'label' => esc_html__( 'Block Patterns', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'blockitem',
			[
				'label' => esc_html__( 'Add Block Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);

		$this->end_controls_section();
        $this->start_controls_section(
            'slider_settings_style',
            [
                'label' => __( 'Banner Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        
        $this->add_control(
            'section_bg_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Section BG Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'section_bg_cl',
            [
                'label'     => esc_html__( 'Section Bg Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rewards-section' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'icon_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Icon Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'icon_color',
            [
                'label'     => esc_html__( 'Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rewards-section .title-column .icon' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_control(
            'slider_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sl_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rewards-section .title-column h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .rewards-section .title-column h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'sub_text_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sb_txt_cl',
            [
                'label'     => esc_html__( 'Sub Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rewards-section .blocks-column .lower-text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sb_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .rewards-section .blocks-column .lower-text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'slider_txt_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sl_txt_cl',
            [
                'label'     => esc_html__( 'Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .rewards-section .text-column .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .rewards-section .text-column .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'reward_block_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Reward Block Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'reward_blog_bg',
            [
                'label'     => esc_html__( 'Block Bg Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block-two .inner-box' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rew_icon_color',
            [
                'label'     => esc_html__( 'Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block-two .inner-box .icon' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rew_txt_color',
            [
                'label'     => esc_html__( 'Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .reward-block-two .inner-box .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'rw_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .reward-block-two .inner-box .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        
		$this->end_controls_section();
        
        $this->start_controls_section(
            'button__content',
            [
                'label' => __( '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-twentyone
                ',
                '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', 'ximsa' ),
            ]
        );
        $this->add_control(
            'btn__color',
            [
                'label'     => esc_html__( 'Color', 'ximsa' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .btn-style-twentyone' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_bg_color',
                'label'    => __( 'Background', 'ximsa' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .btn-style-twentyone
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'ximsa' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .btn-style-twentyone' => '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', 'ximsa' ),
            ]
        );
        $this->add_control(
            'btn__hover_color',
            [
                'label'     => esc_html__( 'Color', 'ximsa' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .btn-style-twentyone:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_hover_bg_color',
                'label'    => __( 'Background', 'ximsa' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .btn-style-twentyone:before
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_hover_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'ximsa' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .btn-style-twentyone: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();?>        
		<!-- Rewards Section -->
        <section class="rewards-section">
		<div class="auto-container">
			<div class="row clearfix">
			
				<!-- Title Column -->
				<div class="title-column col-lg-4 col-md-6 col-sm-12">
					<div class="inner-column">
						<div class="icon">
                            <?php if($settings['icon_type'] == 'icon'):?>
                                <?php \Elementor\Icons_Manager::render_icon( $settings['top_icon'], [ 'aria-hidden' => 'true' ] ); ?>
                            <?php else:?>
                                <i class="<?php echo esc_attr($settings['top_icon_xtx']);?>"></i>
                            <?php endif;?>
                        </div>
						<h2><?php echo wp_kses( $settings['title'], true );?></h2>
					</div>
				</div>
				
				<!-- Blocks Column -->
				<div class="blocks-column col-lg-4 col-md-12 col-sm-12">
					<div class="inner-column">
						<div class="row clearfix">
                            <?php foreach($settings['blockitem'] as $item):?>
							<!-- Reward Block Two -->
                            <?php if($item['style'] == '1'):?>
							<div class="reward-block-two col-lg-6 col-md-6 col-sm-12">
								<div class="inner-box" style="background-image: url(<?php echo esc_url($item['block_pattern']['url']);?>)">
									<div class="icon">
                                        <?php if($item['icon_type'] == 'icon'):?>
                                        <?php \Elementor\Icons_Manager::render_icon( $item['icon'], [ 'aria-hidden' => 'true' ] ); ?>
                                        <?php else:?>
                                            <i class="<?php echo esc_attr($item['icon_txt']);?>"></i>
                                        <?php endif;?>
                                    </div>
									<div class="text"> <?php echo wp_kses( $item['title'], true );?></div>
								</div>
							</div>
                            <?php else:?>
                                <div class="reward-block-two col-lg-6 col-md-6 col-sm-12">
                                    <div class="inner-box" style="background-image: url(<?php echo esc_url($item['block_pattern']['url']);?>)">                                    
                                        <div class="text"> <?php echo wp_kses( $item['title'], true );?></div>
                                        <div class="icon">
                                            <?php if($item['icon_type'] == 'icon'):?>
                                            <?php \Elementor\Icons_Manager::render_icon( $item['icon'], [ 'aria-hidden' => 'true' ] ); ?>
                                            <?php else:?>
                                                <i class="<?php echo esc_attr($item['icon_txt']);?>"></i>
                                            <?php endif;?>
                                        </div>
                                    </div>
                                </div>
                            <?php endif;?>
							<?php endforeach;?>
							
						</div>
						
						<div class="lower-text"><?php echo wp_kses( $settings['subtext'], true );?></div>
						<div class="text-center">
							<a class="btn-style-twenty theme-btn" href="<?php echo esc_url($settings['btn_link']['url']);?>"><span class="txt"><?php echo wp_kses( $settings['btn_label'], true );?></span></a>
						</div>
					</div>
				</div>
				
				<!-- Text Column -->
				<div class="text-column col-lg-4 col-md-6 col-sm-12">
					<div class="inner-column">
						<div class="text"><?php echo wp_kses( $settings['description'], true );?></div>
					</div>
				</div>
				
			</div>
		</div>
	</section>
	<!-- End Rewards Section -->
    <?php  
    }
	
}

