<?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 nft_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 'nft-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__( 'NFT 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' => __('NFT Footer Content', 'ximsa'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'footert_bg_img',
            [
                'label' => __('Footer BG Image', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
        $this->add_control(
            'shape1',
            [
                'label' => __('Shape Image', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
        $this->add_control(
            'shape2',
            [
                'label' => __('Shape 2 Image', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
        $this->add_control(
            'logo',
            [
                'label' => __('Choose Custom Logo', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
        $this->add_control(
            'about_title',
            [
                'label' => __('About Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $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(
			'con_info',
			[
				'label' => esc_html__( 'Infos', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'link_url',
			[
				'label' => esc_html__( 'Link URL', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'contactinfo',
			[
				'label' => esc_html__( 'Contact Info', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
        $this->add_control(
            'market_title',
            [
                'label' => __('Market 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(
            'accunt_title',
            [
                'label' => __('Developer Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $this->add_control(
            'devs_nav',
            [
                'label' => __('Links', 'ximsa'),
                'type' => Controls_Manager::SELECT2,
                'options' =>  ximsa_menu_selector(),
                'multiple' => false,
                'label_block' => true,
            ]
        );
        $this->add_control(
            'recent_post',
            [
                'label' => __('Recent Post Title', 'ximsa'),
                'type' => Controls_Manager::TEXT,
            ]
        );
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
            'post_id', [
                'label'       => esc_html__( 'Select post', 'ximsa' ),
                'type'        => Controls_Manager::SELECT,
                'label_block' => true,
                'options'     => $this->select_param_posts(),
            ]
        );
        
        $this->add_control(
			'postitems',
			[
				'label' => esc_html__( 'Post Item Store', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
        
        $this->add_control(
            'footer_copyright',
            [
                'label' => __('Footer Copyright', 'ximsa'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
            ]
        );
        $this->add_control(
            'footer_copyright_bg',
            [
                'label' => __('Footer Copyright BG', 'ximsa'),
                'type' => Controls_Manager::MEDIA,
                'label_block' => true,
            ]
        );
        $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->end_controls_section();


        $this->start_controls_section(
            'Header_container_style',
            [
                'label' => __('Header Container Style', 'ximsa'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $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}} .xis-nft-footer-logo img' => 'max-width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        
        $this->add_control(
            'contact_info_cl',
            [
                'label' => esc_html__( 'Contact Info Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-footer-widget .about-widget .nft-icon-text .text a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'con_info_icon_color',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '
                    {{WRAPPER}} .xis-nft-footer-widget .about-widget .nft-icon-text .icon
                ',
			]
		);
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'Contact Info Icon', 'ximsa' ),
                'name' => 'cpr_title_typography',
                'selector' => '{{WRAPPER}} .xis-nft-copywright-text',
            ]
        );
        $this->add_control(
            'copyright_brand_txt',
            [
                'label' => esc_html__( 'Copyright Text Brand Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-copywright-text span' => 'color: {{VALUE}}',
                ],
            ]
        );
        
        $this->add_control(
            'copyright_txt',
            [
                'label' => esc_html__( 'Copyright Text Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-copywright-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-nft-copywright-text',
            ]
        );
        $this->add_control(
            'social_icon_clr',
            [
                'label' => esc_html__( 'Social Icon Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-copywright-social li a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'social_icon_hv_clr',
            [
                'label' => esc_html__( 'Social Icon Hover Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-copywright-social li a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'social_icon_hover_clr',
            [
                'label' => esc_html__( 'Social Icon Hover BG Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-copywright-social li a:before' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        
        $this->add_control(
            'heading_title_st',
            [
                'label' => esc_html__( 'Title Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-footer-widget .menu-widget li a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'Title', 'ximsa' ),
                'name' => 'hd_title_typography',
                'selector' => '{{WRAPPER}} .xis-nft-footer-widget .widget-title',
            ]
        );
        $this->add_control(
            'footer_nav_cl',
            [
                'label' => esc_html__( 'Footer Link Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-footer-widget .menu-widget li a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'footer_nav_hv_cl',
            [
                'label' => esc_html__( 'Footer Nav Hover Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-footer-widget .menu-widget li a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'Footer Link Typograsphy', 'ximsa' ),
                'name' => 'ft_title_typography',
                'selector' => '{{WRAPPER}} .xis-nft-footer-widget .menu-widget li a',
            ]
        );
        $this->add_control(
            'about_txt_cl',
            [
                'label' => esc_html__( 'About Text Color', 'ximsa' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-nft-footer-widget .about-widget p' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'label' => esc_html__( 'About Text Typography', 'ximsa' ),
                'name' => 'about_txt_typography',
                'selector' => '{{WRAPPER}} .xis-nft-footer-widget .about-widget p',
            ]
        );
       
        $this->end_controls_section();
	}
		


	protected function render() {
		
		
	$settings = $this->get_settings_for_display(); ?>

        <!-- Start of Footer section
        ============================================= -->
        <section id="xis-nft-footer" class="xis-nft-footer-section" data-background="<?php echo esc_url($settings['footert_bg_img']['url']);?>">
            <div class="xis-nft-footer-area position-relative">
                <span class="xis-nft-footer-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape1']['url']);?>" alt=""></span>
                <span class="xis-nft-footer-shape2 position-absolute"><img src="<?php echo esc_url($settings['shape2']['url']);?>" alt=""></span>
                <div class="container">
                    <div class="xis-nft-footer-content">
                        <div class="xis-nft-footer-widget-wrapper">
                            <div class="row">
                                <div class="col-lg-3 col-md-6">
                                    <div class="xis-nft-footer-widget xis-nft-headline pera-content ul-li-block">
                                        <div class="about-widget">
                                            <h2 class="widget-title text-capitalize"><?php echo wp_kses( $settings['about_title'], true )?></h2>
                                            <p><?php echo wp_kses( $settings['about_short'], true )?></p>
                                            <div class="about-info">
                                                <?php foreach($settings['contactinfo'] as $item):?>
                                                <div class="nft-icon-text d-flex align-items-center">
                                                    <div class="icon d-flex align-items-center justify-content-center">
                                                     <?php \Elementor\Icons_Manager::render_icon( $item['icons'], [ 'aria-hidden' => 'true' ] ); ?>
                                                    </div>
                                                    <div class="text">
                                                        <a href="<?php echo esc_url($item['link_url']['url']);?>"><?php echo wp_kses( $item['con_info'], true )?></a>
                                                    </div>
                                                </div>
                                                <?php endforeach;?>    
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-3 col-md-6">
                                    <div class="xis-nft-footer-widget xis-nft-headline pera-content ul-li-block">
                                        <div class="menu-widget">
                                            <h2 class="widget-title text-capitalize"><?php echo wp_kses( $settings['market_title'], true )?></h2>
                                            <?php
                                                wp_nav_menu( array(
                                                    'menu' => $settings['links_nav'],
                                                ) );
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-3 col-md-6">
                                    <div class="xis-nft-footer-widget xis-nft-headline pera-content ul-li-block">
                                        <div class="menu-widget">
                                            <h2 class="widget-title text-capitalize"><?php echo wp_kses( $settings['accunt_title'], true )?></h2>
                                            <?php
                                                wp_nav_menu( array(
                                                    'menu' => $settings['devs_nav'],
                                                ) );
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-3 col-md-6">
                                    <div class="xis-nft-footer-widget xis-nft-headline pera-content ul-li-block">
                                        <div class="recent-blog-widget">
                                            <h2 class="widget-title text-capitalize"><?php echo wp_kses( $settings['recent_post'], true )?></h2>
                                            <div class="recent-blog-feed">
                                                <?php $shape = 0; foreach($settings['postitems'] as $index => $box): $shape++;?>
                                                <?php  if( $box['post_id'] ) : 
                                                    $categories = get_the_category($box['post_id']); 
                                                ?>
                                                <div class="blog-feed-img-text d-flex  align-items-center">
                                                    <div class="blog-img">
                                                        <img src="<?php echo esc_url(get_the_post_thumbnail_url($box['post_id'], 'thumbnail'));?>" alt="">
                                                    </div>
                                                    <div class="blog-text">
                                                        <span class="meta"><a href="<?php echo get_the_permalink($box['post_id']);?>"><?php echo get_the_date()?></a></span>
                                                        <h3><a href="<?php echo get_the_permalink($box['post_id']);?>"><?php echo get_the_title($box['post_id']);?></a></h3>
                                                    </div>
                                                </div>
                                                <?php endif; endforeach;?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="xis-nft-copywright-wrapper" data-background="<?php echo esc_url($settings['footer_copyright_bg']['url']);?>">
                <div class="container">
                    <div class="xis-nft-copywright-content d-flex justify-content-between align-items-center">
                        <div class="xis-nft-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>
                        <div class="xis-nft-copywright-text text-center">
                            <?php echo wp_kses( $settings['footer_copyright'], true )?>
                        </div>
                        <div class="xis-nft-copywright-social ul-li">
                            <ul>
                                <?php foreach($settings['socialicons'] as $icon):?>
                                    <li><a href="<?php echo esc_url($icon['link_url']['url']);?>"><?php \Elementor\Icons_Manager::render_icon( $icon['icons'], [ 'aria-hidden' => 'true' ] ); ?></a></li>
                                <?php endforeach;?>	
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <!-- End of Footer section
        ============================================= -->
    <?php  
    }
	
    protected function select_param_posts() {
        $args = wp_parse_args( [
            'post_type'   => 'post',
            'numberposts' => -1,
            'orderby'     => 'title',
            'order'       => 'ASC',
        ] );
    
        $query_query = get_posts( $args );
    
        $posts = [];
        if ( $query_query ) {
            foreach ( $query_query as $query ) {
                $posts[$query->ID] = $query->post_title;
            }
        }
    
        return $posts;
    }

}

