<?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 it_v2_about 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 'itsl-v2-about';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'It Solution V2 About', '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(
            'ins_about_opt',
            [
                'label' => __( 'Insurance About', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
             
        $this->add_control(
			'about_bg',
			[
				'label' => esc_html__( 'About Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);  
        $this->add_control(
			'about_title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'ab_link_to_page',
			[
				'label' => esc_html__( 'About Page Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $repeater = new Repeater();
		$repeater->add_control(
			'icon1', [
				'label' => esc_html__( 'Icon 1 Image', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'label_block' => true,
			]
		);
		$repeater->add_control(
			'icon2', [
				'label' => esc_html__( 'Icon 2 Image', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'label_block' => true,
			]
		);

		$repeater->add_control(
			'number', [
				'label' => esc_html__( 'Number', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'symbole', [
				'label' => esc_html__( 'Symbole', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'title', [
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		
		$this->add_control(
			'itfnafacts',
			[
				'label' => esc_html__( 'Add Item', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
		
		$this->end_controls_section();

        $this->start_controls_section(
            'top_info_style',
            [
                'label' => __( 'About Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        
        $this->add_control(
            'about_box_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'About Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'about_box_verlay',
            [
                'label'     => esc_html__( 'Box Overlay Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .ximsa-about-title:before' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'about_box_title',
            [
                'label'     => esc_html__( 'Box Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .ximsa-about-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'about_title__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .ximsa-about-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'faanfact_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Fanfact Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'fanfact_number_cl',
            [
                'label'     => esc_html__( 'Fanfact Number Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .ximsa-it-counter-it-counter .inner-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fnf_number__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .ximsa-it-counter-it-counter .inner-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fanfact_title_cl',
            [
                'label'     => esc_html__( 'Fanfact Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .ximsa-it-counter-it-counter .inner-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fnf_title__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .ximsa-it-counter-it-counter .inner-text p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
		$this->end_controls_section();
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
	    <div class="ximsa-it-about-content">
            <div class="row">
                <div class="col-lg-6 wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
                    <div class="ximsa-about-title text-uppercase xis-it-main-headline d-flex justify-content-center align-items-center position-relative" data-background="<?php echo esc_url($settings['about_bg']['url']);?>">
                        <h2><a href="<?php echo esc_url($settings['ab_link_to_page']['url']);?>"><?php echo esc_html($settings['about_title']);?> <i class="fal fa-angle-right"></i></a></h2>
                    </div>
                </div>
                <?php foreach($settings['itfnafacts'] as $item):?>
                <div class="col-lg-3 col-md-6 wow fadeInUp" data-wow-delay="400ms" data-wow-duration="1500ms">
                    <div class="ximsa-it-counter-it-counter position-relative">
                        <span class="icon-shade position-absolute"><img src="<?php echo esc_url($item['icon1']['url']);?>" alt=""></span>
                        <div class="inner-icon">
                            <img src="<?php echo esc_url($item['icon2']['url']);?>" alt="">
                        </div>
                        <div class="inner-text xis-it-main-headline pera-content">
                            <h3><span class="odometer" data-count="<?php echo esc_attr($item['number']);?>"></span><strong><?php echo esc_html($item['symbole']);?></strong></h3>
                            <p><?php echo esc_html($item['title']);?></p>
                        </div>
                    </div>
                </div>
                <?php endforeach;?>
                
            </div>
        </div>
        <!-- End of About section
        ============================================= -->
    <?php  
    }
	
}

