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

	/**
	 * 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 Portfolio', '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(
            'portfolio',
            [
                'label' => __( 'Portfolio Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        
        $this->add_control(
			'portfolio_shape',
			[
				'label' => esc_html__( 'Portfolio 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' ),
			]
		);
        
        
        $repeater = new \Elementor\Repeater();      
        $repeater->add_control(
			'category_title',
			[
				'label' => esc_html__( 'Category Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'category_id',
			[
				'label' => esc_html__( 'Category ID', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        
        
        $this->add_control(
			'portfolios_cate',
			[
				'label' => esc_html__( 'Add List Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ category_id }}} {{{ category_title }}}',
			]
		);

        $repeater = new \Elementor\Repeater(); 
        $repeater->add_control(
			'fl_category_id',
			[
				'label' => esc_html__( 'Filter Category ID', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);     
        $repeater->add_control(
			'portfolio_shape',
			[
				'label' => esc_html__( 'Portfolio Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'portfolio_img',
			[
				'label' => esc_html__( 'Portfolio Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'category_title',
			[
				'label' => esc_html__( 'Category Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'category',
			[
				'label' => esc_html__( 'Category', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'video_link',
			[
				'label' => esc_html__( 'Video Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'portfolio_link',
			[
				'label' => esc_html__( 'Portfolio Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        
        $this->add_control(
			'portfolios_items',
			[
				'label' => esc_html__( 'Add List Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ category_title }}}',
			]
		);
		
		$this->end_controls_section();
        
        $this->start_controls_section(
            'section_heading_op',
            [
                'label' => __( 'Section Heading 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(
            'filter_style_info',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Filter Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'fl-item-clbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-portfolio-filter-btn button.is-checked, .xis-it-portfolio-filter-btn button:before',
			]
		);
        $this->add_control(
            'filter_color',
            [
                'label'     => esc_html__( 'Filter Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-portfolio-filter-btn button' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'filter__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-portfolio-filter-btn button',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            '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-portfolio-item .inner-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-portfolio-item .inner-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'cate-st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Category Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'cat_nst',
            [
                'label'     => esc_html__( 'Category Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-portfolio-item .inner-text .port-category' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'cate_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-portfolio-item .inner-text .port-category',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
		$this->end_controls_section();
        
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
	<!-- Start of Portfolio section
	============================================= -->
	<section id="xis-it-portfolio" class="xis-it-portfolio-section position-relative">
		<span class="xis-it-side-shape position-absolute" data-parallax='{"x" : -50}'><img src="<?php echo esc_url($settings['portfolio_shape']['url']);?>" alt=""></span>
		<div class="container">
			<div class="xis-it-section-title text-center xis-it-headline pera-content wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
				<span><?php echo esc_html($settings['subtitle']);?></span>
				<h2><?php echo esc_html($settings['title']);?></h2>
			</div>
			<div class="xis-it-portfolio-content">
				<div class="xis-it-portfolio-filter-btn">
					<div class="button-group yl-course-filter-btn text-center clearfix">
						<button class="filter-button is-checked" data-filter="*">All Items </button>
                        <?php foreach($settings['portfolios_cate'] as $filter):?>
						    <button class="filter-button" data-filter=".<?php echo esc_attr($filter['category_id']);?>"><?php echo esc_html($filter['category_title']);?></button>
                        <?php endforeach;?>
					</div>
				</div>
				<div class="filtr-container-area grid clearfix" data-isotope="{ &quot;masonry&quot;: { &quot;columnWidth&quot;: 0 } }">
					<div class="grid-sizer"></div>
					<?php foreach($settings['portfolios_items'] as $item):?>
					<div class="grid-item grid-size-33 <?php echo esc_attr($item['fl_category_id']);?>" data-category="<?php echo esc_attr($item['fl_category_id']);?>">
						<div class="xis-it-portfolio-item position-relative">
							<span class="xis-it-portfolio-shape position-absolute"><img src="<?php echo esc_url($item['portfolio_shape']['url']);?>" alt=""></span>
							<div class="inner-img">
								<img src="<?php echo esc_url($item['portfolio_img']['url']);?>" alt="">
							</div>
							<div class="inner-text xis-it-headline">
								<span class="port-category"><?php echo esc_html($item['category_title']);?></span>
								<h3><a href="<?php echo esc_url($item['portfolio_link']['url']);?>"><?php echo esc_html($item['category']);?></a></h3>
								<div class="inner-btn d-flex ">
									<a class="d-flex video_box justify-content-center align-items-center" href="<?php echo esc_url($item['video_link']['url']);?>"><i class="fas fa-play"></i></a>
									<a class="d-flex justify-content-center align-items-center" href="<?php echo esc_url($item['portfolio_link']['url']);?>"><i class="far fa-link"></i></a>
								</div>
							</div>
						</div>
					</div>
                    <?php endforeach;?>
				</div>
			</div>
		</div>
	</section>		
<!-- End of Portfolio section
	============================================= -->
    <?php  
    }
	
}

