<?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 it_instagram 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 'it-instagram';
	}

	/**
	 * 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 Instagram', '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(
            'instagram_content',
            [
                'label' => __( 'Instagram Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        
        $this->add_control(
			'shape2',
			[
				'label' => esc_html__( 'Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'subtitle',
			[
				'label'       => __( 'Sub Title', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Sub Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Title', 'ximsa' ),
			]
		);
        $this->add_control(
			'description',
			[
				'label' => esc_html__( 'Feature Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);

        $repeater = new \Elementor\Repeater();
               
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);        
        $this->add_control(
			'listitems',
			[
				'label' => esc_html__( 'feature List Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        
        $this->add_control(
			'gallery1',
			[
				'label' => esc_html__( 'Add One Gallery', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'default' => [],
			]
		);
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'insta-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'classic' ],
				'exclude' => [ 'color' ],
				'selector' => '{{WRAPPER}} .xis-it-instagram-img-wrap .xis-it-instagram-img a:before',
			]
		);
        
        $this->add_control(
			'gallery1',
			[
				'label' => esc_html__( 'Add One Gallery', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'default' => [],
			]
		);
        $this->add_control(
			'gallery2',
			[
				'label' => esc_html__( 'Add Two Gallery', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'default' => [],
			]
		);
        $this->end_controls_section();

        $this->start_controls_section(
            'feature_settings_style',
            [
                'label' => __( 'feature Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'sub_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'sub_title_cl',
            [
                'label'     => esc_html__( 'Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-section-title span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'sub_title_bg',
            [
                'label'     => esc_html__( 'Sub Title BG', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-section-title span' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sub_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-section-title span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'main_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'main_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'list_item_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'List Item Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'list_item_cl',
            [
                'label'     => esc_html__( 'List Item Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-instagram-feature-list li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'main_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-instagram-feature-list li',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'list-item-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-instagram-feature-list li:before, .xis-it-instagram-img-wrap .xis-it-instagram-img a:after',
			]
		);
		$this->end_controls_section();
	}
		


	protected function render() {
		
		
		$settings = $this->get_settings_for_display(); ?>		
        <!-- Start of Instagram section
        ============================================= -->
        <section id="xi-it-instagram" class="xis-it-instagram-section position-relative">
            <span class="xis-it-side-shape position-absolute" data-parallax='{"y" : 50}'><img src="<?php echo esc_url($settings['shape2']['url']);?>" alt=""></span>
            <div class="xis-it-instagram-content position-relative">
                <div class="container">
                    <div class="xis-it-instagram-text-area">
                        <div class="xis-it-section-title xis-it-headline pera-content  wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
                            <span><?php echo wp_kses( $settings['subtitle'], true )?></span>
                            <h2><?php echo wp_kses( $settings['title'], true )?></h2>
                            <p><?php echo wp_kses( $settings['description'], true )?></p>
                        </div>
                        <div class="xis-it-instagram-feature-list ul-li-block  wow fadeInUp" data-wow-delay="600ms" data-wow-duration="1500ms">
                            <ul>
                                <?php foreach($settings['listitems'] as $item):?>
                                    <li><?php echo esc_html($item['title']);?></li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="xis-it-instagram-img-wrap">
                    <div class="xis-it-instagram-img-item-wrap-1 d-flex">
                        <?php foreach($settings['gallery1'] as $gall1):?>
                        <div class="xis-it-instagram-img position-relative  wow fadeInLeft" data-wow-delay="200ms" data-wow-duration="1500ms">
                            <a href="<?php echo esc_url($gall1['url']);?>"><img src="<?php echo esc_url($gall1['url']);?>" alt=""></a>
                        </div>
                        <?php endforeach;?>
                    </div>
                    <div class="xis-it-instagram-img-item-wrap-2 d-flex">
                        <?php foreach($settings['gallery2'] as $gall2):?>
                        <div class="xis-it-instagram-img position-relative  wow fadeInLeft" data-wow-delay="100ms" data-wow-duration="1500ms">
                            <a href="<?php echo esc_url($gall2['url']);?>"><img src="<?php echo esc_url($gall1['url']);?>" alt=""></a>
                        </div>
                        <?php endforeach;?>
                    </div>
                </div>
            </div>
        </section>
        <!-- End of Instagram section
        ============================================= -->
		<?php 
      }
	
	

}

