<?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_service_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-service-';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Digital Service', '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(
            'section_title_control',
            [
                'label' => __( 'Section Title Control', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'gs_subtitle',
			[
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'gs_title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'dot_shape',
			[
				'label' => esc_html__( 'Dot Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'dot_shape2',
			[
				'label' => esc_html__( 'Dot Shape 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->end_controls_section();

		$this->start_controls_section(
            'service_options',
            [
                'label' => __( 'Service Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'shadow_shape', [
                'label'       => esc_html__( 'Shadow Shape', 'ximsa' ),
                'type'        => Controls_Manager::MEDIA,
                'label_block' => true,
            ]
        );

        // choose column
        $this->add_control(
            'choose_column',
            [
                'label'              => __( 'Choose Column', 'maxiz-core' ),
                'type'               => Controls_Manager::SELECT,
                'options'            => [
                    'col_1' => __( '1 Column', 'maxiz-core' ),
                    'col_2' => __( '2 Column', 'maxiz-core' ),
                    'col_3' => __( '3 Column', 'maxiz-core' ),
                    'col_4' => __( '4 Column', 'maxiz-core' ),
                    'col_5' => __( '5 Column', 'maxiz-core' ),
                    'col_6' => __( '6 Column', 'maxiz-core' ),
                ],
                'default'            => 'col_4',
                'frontend_available' => true,
                'style_transfer'     => true,
            ]
        );


        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
			'service_icon_img',
			[
				'label' => esc_html__( 'Service Icon Img', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'service_title',
			[
				'label' => esc_html__( 'Service Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'description',
			[
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => Controls_Manager::WYSIWYG,
				'default' => esc_html__( 'Contrary to popular belief is not simply random text velit.', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Slider Color Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'button_label',
			[
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Get Start ', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Slider Button Label Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'button_link',
			[
				'label' => esc_html__( 'Button Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);

        $this->add_control(
			'serviceitem',
			[
				'label' => esc_html__( 'Service List', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			]
		);
		$this->end_controls_section();

        $this->start_controls_section(
            'service_btm_option',
            [
                'label' => __( 'Service More Option', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
			'sl_title',
			[
				'label' => esc_html__( 'Solution Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'sl2_title',
			[
				'label' => esc_html__( 'Solution 2 Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $this->add_control(
			'sl_link_text',
			[
				'label' => esc_html__( 'Link Text', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
			]
		);

        $this->add_control(
			'sl_link',
			[
				'label' => esc_html__( 'Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
		$this->end_controls_section();
        $this->start_controls_section(
            'section_title_style',
            [
                'label' => __( 'Section Title Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'se__sub_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'sub_bgbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-dia-section-title span',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dia-section-title span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'se_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'se_ht_color',
            [
                'label'     => esc_html__( 'Heading Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dia-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'serv_settings_style',
            [
                'label' => __( 'Service Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'service_title_stl',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Service Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'srv_ttl_color',
            [
                'label'     => esc_html__( 'Service Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-service-inner-item .xis-dia-service-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'srv_ttl_typography',
                'label'          => esc_html__( 'Service Title Typography', 'ximsa' ),
                'selector'       => '
                {{WRAPPER}} .xis-dia-service-inner-item .xis-dia-service-text h3
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'service_excerpt_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Description Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'srv_desc_color',
            [
                'label'     => esc_html__( 'Desc Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pera-content p' => 'color: {{VALUE}} ',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                {{WRAPPER}} .pera-content p
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'srv_btn_stl',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Link Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'btn_bgbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-dia-service-inner-item .xis-dia-service-more:before',
			]
		);
        $this->add_control(
            'srv_link_cl',
            [
                'label'     => esc_html__( 'Link Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-service-inner-item .xis-dia-service-more a' => 'color: {{VALUE}} ',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'srv_link_cl_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-service-inner-item .xis-dia-service-more a
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->end_controls_section();
	}



	protected function render() {


		$settings = $this->get_settings_for_display();
            if($settings['choose_column'] == 'col_1'){
                $col = 'col-lg-12';
            }elseif($settings['choose_column'] == 'col_2'){
                $col = 'col-lg-6';
            }elseif($settings['choose_column'] == 'col_3'){
                $col = 'col-lg-4';
            }elseif($settings['choose_column'] == 'col_4'){
                $col = 'col-lg-3';
            }elseif($settings['choose_column'] == 'col_5'){
                $col = 'col-lg-2';
            }elseif($settings['choose_column'] == 'col_6'){
                $col = 'col-lg-2';
            } else {
                $col = 'col-lg-3';
            }

        ?>

		<!-- Start of Service section
        ============================================= -->
        <section id="xis-dia-service" class="xis-dia-service-section position-relative">
            <span class="xis-dia-side-shape1 position-absolute"><img src="<?php echo esc_url($settings['dot_shape']['url']);?>" alt=""></span>
            <span class="xis-dia-service-shape2 position-absolute"><img src="<?php echo esc_url($settings['dot_shape2']['url']);?>" alt=""></span>
            <div class="container">
                <div class="xis-dia-section-title xis-dia-headline text-center wow fadeInUp" data-wow-delay="0ms" data-wow-duration="1500ms">
                    <span><?php echo esc_html($settings['gs_subtitle']);?></span>
                    <h2><?php echo __($settings['gs_title']);?></h2>
                </div>
                <div class="xis-dia-service-content">
                    <div class="xis-dia-service-content-area">
                        <div class="row">
                            <?php foreach($settings['serviceitem'] as $index => $box):

                            ?>
                            <div class="<?php echo esc_attr($col); ?> col-md-6 wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
                                <div class="xis-dia-service-inner-item text-center position-relative">
                                    <span class="xis-dia-service-shape position-absolute"><img src="<?php echo esc_url($settings['shadow_shape']['url']);?>" alt=""></span>
                                    <div class="xis-dia-service-icon position-relative">
                                        <img src="<?php echo esc_url($box['service_icon_img']['url']);?>" alt="">
                                    </div>
                                    <div class="xis-dia-service-text xis-dia-headline pera-content">
                                        <h3><a href="<?php echo esc_url($box['button_link']['url']);?>"><?php echo esc_html($box['service_title']);?></a></h3>
                                        <?php echo __($box['description']);?>
                                    </div>
                                    <div class="xis-dia-service-more">
                                        <a class="text-uppercase" href="<?php echo esc_url($box['button_link']['url']);?>"><?php echo esc_html($box['button_label']);?> <i class="far fa-arrow-right"></i></a>
                                    </div>
                                </div>
                            </div>
                            <?php endforeach;?>
                        </div>
                    </div>
                    <div class="xis-dia-service-meta pera-content text-center wow fadeInUp" data-wow-delay="500ms" data-wow-duration="1500ms">
                        <p><?php echo esc_html($settings['sl_title']);?> <a href="<?php echo esc_url($settings['sl_link']['url']);?>"><?php echo esc_html($settings['sl_link_text']);?></a> <?php echo esc_html($settings['sl2_title']);?></p>
                    </div>
                </div>
            </div>
        </section>
    <!-- End of Service section
        ============================================= -->
    <?php
      }


}
