<?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 helpdesk_footer 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 'helpdesk-footer';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Helpdesk Footer', '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(
            'footer_content',
            [
                'label' => __('Helpdesk Footer Content', 'ximsa'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'logo',
            [
                'label' => __('Choose Custom Logo', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        
        $this->add_control(
            'about_short',
            [
                'label' => __('Short About', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
            ]
        );
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'icons',
			[
				'label' => esc_html__( 'Icon', 'ximsa' ),
				'type' => Controls_Manager::ICONS,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'link_url',
			[
				'label' => esc_html__( 'Link URL', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'socialicons',
			[
				'label' => esc_html__( 'Social Icon', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
        $this->add_control(
            'links_title',
            [
                'label' => __('Links Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $this->add_control(
            'links_nav',
            [
                'label' => __('Links Menu', 'ximsa'),
                'type' => Controls_Manager::SELECT2,
                'options' =>  ximsa_menu_selector(),
                'multiple' => false,
                'label_block' => true,
            ]
        );
        

        $this->add_control(
            'contact_title',
            [
                'label' => __('Contact Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $this->add_control(
            'contact_infos',
            [
                'label' => __('Contact Infos', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
            ]
        );
        
        $this->add_control(
            'newslater_title',
            [
                'label' => __('Newslater Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $this->add_control(
            'newslater_infos',
            [
                'label' => __('Newslater Infos', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
            ]
        );
        $this->add_control(
            'newslater_form',
            [
                'label' => __('Newslater Form', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
            ]
        );
        
        $this->add_control(
            'footer_copyright',
            [
                'label' => __('Footer Copyright', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
            ]
        );

        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'footer_link_txt',
			[
				'label' => esc_html__( 'Link Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'footer_link',
			[
				'label' => esc_html__( 'Link URL', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'footerlinks',
			[
				'label' => esc_html__( 'Add Footer Link Icon', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
        
        
        $this->end_controls_section();


        $this->start_controls_section(
            'Header_container_style',
            [
                'label' => __('Header Container Style', 'ximsa'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'footer_bg_color',
            [
                'label' => esc_html__( 'Footer Background Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-section' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'footer_text_color',
            [
                'label' => esc_html__( 'Footer Text Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} footer#xis-hd-footer p' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_responsive_control(
            'logo_max_width',
            [
                'label' => esc_html__( 'Logo Width', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%' ],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 1920,
                        'step' => 1,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .footer-logo a img' => 'max-width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        
        $this->add_control(
            'main_nav_color',
            [
                'label' => esc_html__( 'Nav link Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .menu-widget li a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'main_nav_hover_color',
            [
                'label' => esc_html__( 'Main Nav Hover Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .menu-widget li a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'Main Nav Typo', 'ximsa' ),
                'name' => 'main_nav_typography',
                'selector' => '{{WRAPPER}} .xis-hd-footer-widget .menu-widget li a',
            ]
        );
        
        
        $this->add_control(
            'copyright_txt',
            [
                'label' => esc_html__( 'Copyright Text Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-copyright-content .copyright-text' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'Copyright Title', 'ximsa' ),
                'name' => 'cpr_title_typography',
                'selector' => '{{WRAPPER}} .xis-hd-footer-copyright-content .copyright-text',
            ]
        );
        $this->add_control(
            'social_icon_clr',
            [
                'label' => esc_html__( 'Social Icon Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'social_icon_hover_clr',
            [
                'label' => esc_html__( 'Social Icon Hover Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'social_icon_hover_bg_',
            [
                'label' => esc_html__( 'Social Icon BG Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a' => 'background-color: {{VALUE}}',
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a' => 'border-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'social_icon_hover_bg_clr',
            [
                'label' => esc_html__( 'Social Icon Hover BG Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a:hover' => 'background-color: {{VALUE}}',
                    '{{WRAPPER}} .xis-hd-footer-widget .logo-widget .footer-social a:hover' => 'border-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'btn_bg_cl',
            [
                'label' => esc_html__( 'Newslater Button Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .newslatter-widget button' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'btn_bg_hover_cl',
            [
                'label' => esc_html__( 'Newslater Button Hover Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-footer-widget .newslatter-widget button:hover' => 'background-color: {{VALUE}}',
                ],
            ]
        );

        
        $this->end_controls_section();
	}
		


	protected function render() {
		
		
	$settings = $this->get_settings_for_display(); ?>
        <!-- Start of Footer section
        ============================================= -->
        <footer id="xis-hd-footer" class="xis-hd-footer-section">
            <div class="container">
                <div class="xis-hd-footer-widget-wrapper">
                    <div class="row">
                        <div class="col-lg-3 col-md-6">
                            <div class="xis-hd-footer-widget xis-hd-headline pera-content">
                                <div class="logo-widget">
                                    <div class="footer-logo">
                                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url($settings['logo']['url']);?>" alt="<?php echo esc_url($settings['logo']['alt']);?>"></a>
                                    </div>
                                    <p><?php echo wp_kses( $settings['about_short'], true );?></p>
                                    <div class="footer-social d-flex">	
                                        <?php foreach($settings['socialicons'] as $icon):?>
                                            <a href="<?php echo esc_url($icon['link_url']['url']);?>"><?php \Elementor\Icons_Manager::render_icon( $icon['icons'], [ 'aria-hidden' => 'true' ] ); ?></a>
                                        <?php endforeach;?>	
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <div class="xis-hd-footer-widget xis-hd-headline ul-li-block pera-content">
                                <div class="menu-widget">
                                    <h3 class="widget-title"><?php echo wp_kses( $settings['links_title'], true )?></h3>
                                    <?php
                                        wp_nav_menu( array(
                                            'menu' => $settings['links_nav'],
                                        ) );
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <div class="xis-hd-footer-widget xis-hd-headline ul-li-block pera-content">
                                <div class="contact-widget">
                                    <h3 class="widget-title"><?php echo wp_kses( $settings['contact_title'], true )?></h3>
                                    <p>
                                        <?php echo wp_kses( $settings['contact_infos'], true )?>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <div class="xis-hd-footer-widget xis-hd-headline ul-li-block pera-content">
                                <div class="newslatter-widget">
                                    <h3 class="widget-title"><?php echo wp_kses( $settings['newslater_title'], true )?></h3>
                                    <p>
                                        <?php echo wp_kses( $settings['newslater_infos'], true )?>
                                    </p>
                                    <?php echo do_shortcode( $settings['newslater_form'] );?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="xis-hd-footer-copyright">
                <div class="container">
                    <div class="xis-hd-footer-copyright-content d-flex justify-content-between align-items-center">
                        <div class="copyright-text">
                            <?php echo wp_kses( $settings['footer_copyright'], true )?>
                        </div>
                        <div class="copyright-menu ul-li">
                            <ul>
                                <?php foreach($settings['footerlinks'] as $link):?>
                                <li><a href="<?php echo esc_url($link['footer_link']['url']);?>"> <?php echo esc_html($link['footer_link_txt']);?></a></li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </footer>		
    <!-- End of Footer section
        ============================================= -->
    <?php  
    }
	
	

}

