<?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 dgi_banner_widget 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 'xim-digital-banner';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Bank Digital Agency Banner', '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(
            'slider_options',
            [
                'label' => __( 'Banner Image Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
			'shape',
			[
				'label' => esc_html__( 'Shape Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape_2',
			[
				'label' => esc_html__( 'Shape 2 Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'banner_img',
			[
				'label' => esc_html__( 'Banner Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);

        $this->end_controls_section();
        $this->start_controls_section(
            'banner_content_options',
            [
                'label' => __( 'Banner Content Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'We are Digital Marketing', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Banner Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
			'skilltitle',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);

        $this->add_control(
			'skils',
			[
				'label' => esc_html__( 'Skill Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ skilltitle }}}',
			]
		);
        $this->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Take payments online with a scalable platform that grows with your perfect business.', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Banner Short Info Here', 'ximsa' ),
                'label_block' => true,
			]
		);

        $this->add_control(
			'button_label',
			[
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Get In Touch', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Slider Button Label Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $this->add_control(
			'button_link',
			[
				'label' => esc_html__( 'Button Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        $this->add_control(
			'clients',
			[
				'label' => esc_html__( 'Add Client Images', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'default' => [],
			]
		);
		$this->end_controls_section();
        $this->start_controls_section(
            'slider_settings_style',
            [
                'label' => __( 'Banner Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'slider_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'title-bgbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'gradient' ],
				'selector' => '
                    {{WRAPPER}} .xis-dia-banner-text h1,
                    {{WRAPPER}} .xis-dia-banner-text .cd-words-wrapper b,
                    {{WRAPPER}} .xis-dia-banner-text .cd-words-wrapper span
                ',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-banner-text h1,
                    {{WRAPPER}} .xis-dia-banner-text .cd-words-wrapper b,
                    {{WRAPPER}} .xis-dia-banner-text .cd-words-wrapper span
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'slider_desc',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Description Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'sl_desc_color',
            [
                'label'     => esc_html__( 'Description Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-banner-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_desc_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-banner-text p
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

		$this->end_controls_section();

        $this->start_controls_section(
            'button__content',
            [
                'label' => __( 'Slider Button Style', 'ximsa' ),
                'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name'           => 'btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
			'btnwidth',
			[
				'label' => esc_html__( 'Width', 'ximsa' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->add_control(
			'btnheight',
			[
				'label' => esc_html__( 'Height', 'ximsa' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->start_controls_tabs( '_banner_button_1' );
        $this->start_controls_tab(
            '_glow-extension_btn__banner_normal',
            [
                'label' => esc_html__( 'Normal', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_tab();
        $this->start_controls_tab(
            '_glow-extension_btn_hover',
            [
                'label' => esc_html__( 'Hover', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__hover_color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_hover_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a:hover
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_hover_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .xis-dia-btn a, .xis-dia-btn-2 a:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();
        $this->end_controls_section();
	}



	protected function render() {
	$settings = $this->get_settings_for_display();?>
	<!-- Start of Banner section
	============================================= -->
	<section id="xis-dia-banner" class="xis-dia-banner-section position-relative" data-background="<?php echo $settings['shape']['url'] ? esc_url($settings['shape']['url']) : '';?>">

        <?php if(!empty( $settings['shape_2']['url'] )) : ?>
		<div class="xis-dia-banner-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape_2']['url']);?>" alt=""></div>
        <?php endif; ?>
		<div class="container">
			<div class="xis-dia-banner-content position-relative">
				<div class="xis-dia-banner-text xis-dia-headline pera-content">
					<h1 class="cd-headline clip is-full-width"><?php echo esc_html($settings['title']);?>
						<span class="cd-words-wrapper">
                            <?php $i = 0; foreach($settings['skils'] as $skill): $i++?>
                            <?php if($i == 1):?>
							    <b class="is-visible"><?php echo esc_html($skill['skilltitle']);?></b>
                            <?php else:?>
                                <b><?php echo esc_html($skill['skilltitle']);?></b>
                            <?php endif;?>
                            <?php endforeach;?>
						</span>
					</h1>
                    <?php if(!empty( $settings['description'] )) : ?>
					<p>
                        <?php echo esc_html($settings['description']); ?>
                    </p>
                    <?php endif; ?>

                    <?php if(!empty( $settings['button_label'] )) : ?>
					<div class="xis-dia-btn">
						<a
                        class="d-flex justify-content-center align-items-center text-uppercase"
                        href="<?php echo esc_url($settings['button_link']['url']); ?>"
                        target="<?php echo esc_attr($settings['button_link']['is_external'] ? '_blank' : '_self'); ?>"
                        rel="<?php echo esc_attr($settings['button_link']['nofollow'] ? 'nofollow' : ''); ?>"
                        >
                        <?php echo esc_html($settings['button_label']); ?>
                        <i class="far fa-arrow-right"></i>
                    </a>
					</div>
                    <?php endif; ?>
				</div>

                <?php if(!empty( $settings['banner_img']['url'] )) : ?>
				<div class="xis-dia-banner-img position-absolute wow zoomIn scene" data-wow-delay="400ms" data-wow-duration="1500ms">
					<img class="layer" data-depth="0.2" src="<?php echo esc_url($settings['banner_img']['url']);?>" alt="">
				</div>
                <?php endif; ?>
				<div class="xis-dia-banner-sponsor">
                    <?php foreach($settings['clients'] as $client):?>
                        <div class="xis-dia-sponsor-item">
                            <img src="<?php echo esc_url($client['url']);?>" alt="">
                        </div>
					<?php endforeach;?>
				</div>
			</div>
		</div>
	</section>
    <!-- End of Banner section
	============================================= -->
    <?php
    }

}
