<?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 insurance_fnf 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 'insurance-fanfact';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Insurance Fanfact', '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_fanfact_opt',
            [
                'label' => __( 'Insurance Fanfact', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new Repeater();
		$repeater->add_control(
			'icon', [
				'label' => esc_html__( 'Icon', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::ICONS,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'number', [
				'label' => esc_html__( 'Number', '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,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'subtitle', [
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
                'label_block' => true,
			]
		);

		$this->add_control(
			'fanfacts',
			[
				'label' => esc_html__( 'Add New Fanfact', '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(
            'icon-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'icon Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'icon',
            [
                'label'     => esc_html__( 'Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .fact-counter-three .counter-column .icon' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_control(
            'number_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Number Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'number_cl',
            [
                'label'     => esc_html__( 'Number Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .fact-counter-three .counter-column .inner .count-outer' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'no_cl__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .fact-counter-three .counter-column .inner .count-outer',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'feedback_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'title_txt_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .fact-counter-three .counter-column .inner .counter-text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'title_c__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .fact-counter-three .counter-column .inner .counter-text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
		$this->end_controls_section();
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
    <!-- Counter Section -->
	<section class="counter-section-ins">
		<div class="auto-container">
				
			<!-- Fact Counter Three -->
			<div class="fact-counter-three">
				<div class="row clearfix">
                    <?php foreach($settings['fanfacts'] as $item):?>
					<!-- Column -->
					<div class="counter-column col-lg-3 col-md-6 col-sm-12">
						<div class="inner wow fadeInLeft" data-wow-delay="450ms" data-wow-duration="1500ms">
							<div class="content">
								<div class="icon">
                                    <?php \Elementor\Icons_Manager::render_icon( $item['icon'], [ 'aria-hidden' => 'true' ] ); ?>
                                </div>
								<div class="count-outer count-box">
									<?php if(!empty($item['subtitle'])){echo esc_html($item['subtitle']);}?> <span class="count-text" data-speed="3000" data-stop="<?php echo esc_attr($item['number']);?>">0</span>
								</div>
								<div class="counter-text"><?php echo esc_html($item['title']);?></div>
							</div>
						</div>
					</div>
					<?php endforeach;?>
				</div>
			</div>

		</div>
	</section>
	<!-- End Counter Section -->
    <?php  
    }
	
}

