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

	/**
	 * 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 Product', '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(
            'product_control',
            [
                'label' => __( 'Product Control', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'shape',
			[
				'label' => esc_html__( 'Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'tm_subtitle',
			[
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
			]
		);
        $this->add_control(
			'tm_title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'video_label',
			[
				'label' => esc_html__( 'Video Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'video_link',
			[
				'label' => esc_html__( 'Video Link', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                '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,
			]
		);
        
        $this->end_controls_section();

		$this->start_controls_section(
            'service_options',
            [
                'label' => __( 'service Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
            'service_id', [
                'label'       => esc_html__( 'Select service', 'ximsa' ),
                'type'        => Controls_Manager::SELECT,
                'label_block' => true,
                'options'     => $this->select_param_posts(),
            ]
        );
        $repeater->add_control(
			'service_icon',
			[
				'label' => esc_html__( 'Service Icon Image Upload', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'service_excerpt',
			[
				'label' => esc_html__( 'Service Escerpt', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'btn_label',
			[
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
			]
		);
        $repeater->add_control(
			'custom_link',
			[
				'label' => esc_html__( 'Custom Link', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::URL,
			]
		);
        
        $repeater->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'item_bg_color',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'gradient' ],
				'selector' => '
                    {{WRAPPER}} {{CURRENT_ITEM}} .inner-box .more
                ',
			]
		);
        $this->add_control(
			'servicesitems',
			[
				'label' => esc_html__( 'Service List', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
        
		$this->end_controls_section();
        
        $this->start_controls_section(
            'section_title_style',
            [
                'label' => __( 'Section Title 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_control(
            'sub_h_bg_cl',
            [
                'label'     => esc_html__( 'Sub Heading BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .finance-products-section .title-column .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .finance-products-section .title-column .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(
            'main_title_color',
            [
                'label'     => esc_html__( 'Heading Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-four h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'main_colored_title_color',
            [
                'label'     => esc_html__( 'Colored Heading Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-four h2 span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'main_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-four h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'se_desc_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Desc Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'desc_title_color',
            [
                'label'     => esc_html__( 'Description Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-four .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'desc_clo_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-four .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'video_label',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Video Label Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'video_cl',
            [
                'label'     => esc_html__( 'Video Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .finance-products-section .title-column .play-box i' => 'color: {{VALUE}} ',
                    '{{WRAPPER}} .finance-products-section .title-column .play-box i' => 'border-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'video_clo_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .finance-products-section .title-column .play-box i',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
        $this->end_controls_section();
        $this->start_controls_section(
            'service_settings_style',
            [
                'label' => __( 'Service Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'service_title_stl',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Service Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'tm_ttl_color',
            [
                'label'     => esc_html__( 'service Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box h5' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tm_ttl_hv_color',
            [
                'label'     => esc_html__( 'Service Title Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box:hover h5' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tm_ttl_typography',
                'label'          => esc_html__( 'service Title Typography', 'ximsa' ),
                'selector'       => '
                {{WRAPPER}} .crypto-block .inner-box h5
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'serv_excerpt_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Service Excerpt Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'excerpt_color',
            [
                'label'     => esc_html__( 'Excerpt Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'excerpt_hov_color',
            [
                'label'     => esc_html__( 'Excerpt Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box:hover .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'excerpt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                {{WRAPPER}} .crypto-block .inner-box .title
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'btn_sv_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Button', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'srv_btn_txt',
            [
                'label'     => esc_html__( 'Button Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box .more' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'srv_btn__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                {{WRAPPER}} .crypto-block .inner-box .more
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'service_box_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Box Hover BG Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'box_hov_bg',
            [
                'label'     => esc_html__( 'Box Hover Background Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .crypto-block .inner-box:hover' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'play_btn_hover',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Play Button Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'play_btn_bg',
            [
                'label'     => esc_html__( 'Play Background Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .finance-products-section .title-column .play-box .fa' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'play_btn_hv_bg',
            [
                'label'     => esc_html__( 'Play Background Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .finance-products-section .title-column .play-box .fa:hover' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
              
        $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 .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', '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();?>
		<!-- Finance Products Section -->
        <section class="finance-products-section">
            <div class="bubble-dotted">
                <span class="dotted dotted-1"></span>
                <span class="dotted dotted-2"></span>
                <span class="dotted dotted-3"></span>
                <span class="dotted dotted-4"></span>
                <span class="dotted dotted-5"></span>
                <span class="dotted dotted-6"></span>
                <span class="dotted dotted-7"></span>
                <span class="dotted dotted-8"></span>
                <span class="dotted dotted-9"></span>
                <span class="dotted dotted-10"></span>
            </div>
            <div class="auto-container">
                <div class="row clearfix">
                
                    <!-- Title Column -->
                    <div class="title-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <div class="title">
                                <span class="icon"><img src="<?php echo esc_url($settings['shape']['url']);?>" alt="" /></span>
                                <?php echo wp_kses( $settings['tm_subtitle'], true );?>
                            </div>
                            <div class="sec-title-four">
                                <h2><?php echo wp_kses( $settings['tm_title'], true );?></h2>
                                <div class="text"><?php echo wp_kses( $settings['description'], true );?></div>
                            </div>
                            <div class="clearfix">
                                <div class="pull-left">
                                    <a href="<?php echo esc_url($settings['video_link']);?>" class="lightbox-image play-box"><span class="fa fa-play"><i class="ripple"></i></span><i><?php echo wp_kses( $settings['video_label'], true );?></i></a>
                                </div>
                                <div class="pull-left">
                                    <a href="<?php echo esc_url($settings['btn_link']['url']);?>" class="theme-btn btn-style-twentyone"><span class="txt"><?php echo wp_kses( $settings['btn_label'], true );?></span></a>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Products Column -->
                    <div class="products-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <?php $shape = 0; foreach($settings['servicesitems'] as $index => $box): $shape++;?>
                            <?php  if( $box['service_id'] ) : ?>
                            <!-- Crypto Block / Style Four -->
                            <div class="crypto-block style-four elementor-repeater-item-<?php echo esc_attr($box['_id']);?>">
                                <div class="inner-box">
                                    <div class="content">
                                        <span class="icon"><img src="<?php echo esc_url($box['service_icon']['url']);?>" alt="" /></span>
                                        <h5><?php echo get_the_title($box['service_id']);?></h5>
                                        <div class="title"><?php echo wp_kses( $box['service_excerpt'], true );?></div>
                                        <a href="<?php if($box['custom_link']['url']){ echo esc_url($box['custom_link']['url']);}else{echo get_the_permalink($box['service_id']);}?>" class="more"><?php echo esc_html($box['btn_label']);?> <span class="flaticon-right-arrow"></span></a>
                                    </div>
                                </div>
                            </div>
                            <?php endif; endforeach;?>
                        </div>
                    </div>
                    
                </div>
            </div>
        </section>
        <!-- End Finance Products Section -->

    <?php     
      }
	
      protected function select_param_posts() {
        $args = wp_parse_args( [
            'post_type'   => 'service',
            'numberposts' => -1,
            'orderby'     => 'title',
            'order'       => 'ASC',
        ] );
    
        $query_query = get_posts( $args );
    
        $posts = [];
        if ( $query_query ) {
            foreach ( $query_query as $query ) {
                $posts[$query->ID] = $query->post_title;
            }
        }
    
        return $posts;
    }

}

