<?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\Plugin;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.

class banking_feature 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 'banking-feature-item';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Banking Feature Box', '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(
            'feature_options',
            [
                'label' => __( 'Feature Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
			'icon_type',
			[
				'label' => esc_html__( 'Icon Type', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'icon' => [
						'title' => esc_html__( 'Choose Icon', 'ximsa' ),
						'icon' => 'eicon-nerd',
					],
					'image' => [
						'title' => esc_html__( 'Upload Icon Image', 'ximsa' ),
						'icon' => 'eicon-image-bold',
					],
				],
				'default' => 'icon',
				'toggle' => true,
			]
		);
        $repeater->add_control(
			'icons',
			[
				'label' => esc_html__( 'Icon', 'ximsa' ),
				'type' => Controls_Manager::ICONS,
                'label_block' => true,
                'condition' => [ 'icon_type' => 'icon' ]
			]
		);
        $repeater->add_control(
			'icons_img',
			[
				'label' => esc_html__( 'Icon Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
                'condition' => [ 'icon_type' => 'image' ]
			]
		);
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Apply For Innsurance', 'ximsa' ),
				'placeholder' => esc_html__( 'Box Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Box Short Description Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'link_label',
			[
				'label' => esc_html__( 'Link Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Explore More ', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'link_url',
			[
				'label' => esc_html__( 'Link URL', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'featuresitem',
			[
				'label' => esc_html__( 'Add Feature Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        
		$this->end_controls_section();
        
        $this->start_controls_section(
            'feature_style',
            [
                'label' => __( 'Feature Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'feature_shadowbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'classic' ],
				'exlcude' => [ 'color' ],
				'selector' => '{{WRAPPER}} .xis-feature-item:after',
			]
		);
        $this->add_control(
            'featre_box_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Box Style Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'hv-bgbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-feature-item .xis-inner-item:before',
			]
		);
        $this->add_responsive_control(
            'top_spacing',
            [
                'label'      => esc_html__( 'Feature Section Top Space', 'ximsa' ),
                'type'       => Controls_Manager::SLIDER,
                'size_units' => ['px'],
                'range'      => [
                    'px' => [
                        'min' => 1,
                        'max' => 1000,
                    ],
                ],
                'selectors'  => [
                    '{{WRAPPER}} .xis-feature-content' => 'top: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'ft_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feature Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'ft_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-inner-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ft_t_typography',
                'label'          => esc_html__( 'Number Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-inner-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'ft_desc_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Description Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'ft_desc_cl',
            [
                'label'     => esc_html__( 'Feature Desc Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pera-content p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'ft_ds_typography',
                'label'          => esc_html__( 'Description Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .pera-content p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'link_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Link Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'link__color',
            [
                'label'     => esc_html__( 'Link Label Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-ft-btn a' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'link_hv_color',
            [
                'label'     => esc_html__( 'Link Label Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-ft-btn a:hover' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'link_bg_color',
            [
                'label'     => esc_html__( 'Link BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-ft-btn a' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'link_bg_hv_color',
            [
                'label'     => esc_html__( 'Link BG Hover Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-ft-btn a:hover' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'li_tx_typography',
                'label'          => esc_html__( 'Link Text Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-feature-item .xis-inner-item .xis-ft-btn a',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        
		$this->end_controls_section();
	}
		


	protected function render() {
		
		
	$settings = $this->get_settings_for_display(); ?>
		<!-- Start of Feature section
        ============================================= -->
        <section id="xis-feature" class="xis-feature-section">
            <div class="container">
                <div class="xis-feature-content">
                    <div class="row justify-content-center">
                        <?php 
                        if(!empty($settings['featuresitem'])):
                        foreach($settings['featuresitem'] as $item): ?>
                        <div class="col-lg-4 col-md-6 wow fadeInUp" data-wow-delay="400ms" data-wow-duration="1500ms">
                            <div class="xis-feature-item">
                                <div class="xis-inner-item position-relative">
                                    <?php if($item['icon_type'] == 'icon'):?>
                                    <div class="xis-inner-icon">
                                        <?php \Elementor\Icons_Manager::render_icon( $item['icons'], [ 'aria-hidden' => 'true' ] ); ?>
                                    </div>
                                    <?php endif;?>

                                    <?php if($item['icon_type'] == 'image'):?>
                                        <div class="xis-inner-icon">
                                            <img src="<?php echo esc_url($item['icons_img']['url']);?>" alt="">
                                        </div>
                                    <?php endif;?>

                                    <div class="xis-inner-text headline pera-content">
                                        <h3><?php echo __($item['title']);?></h3>
                                        <p><?php echo __($item['description']);?></p>
                                    </div>
                                    <div class="xis-ft-btn">
                                        <a class="d-flex justify-content-center align-items-center" href="<?php echo esc_url($item['link_url']['url']);?>"><?php echo __($item['link_label']);?> <i class="far fa-arrow-down"></i></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php endforeach; endif;?>
                    </div>
                </div>
            </div>
        </section>		
    <!-- End of Feature section
        ============================================= -->
    <?php  
    }
	
	

}

