<?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 it_service 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-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__( 'IT 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(
            'service_contetn',
            [
                'label' => __( 'Service Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'service_bg',
			[
				'label' => esc_html__( 'Service Bg', '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' ),
			]
		);

		$this->add_control(
			'description',
			[
				'label'       => __( 'Description', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $this->add_control(
			'btn_label',
			[
				'label'       => __( 'Button Label', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Title', 'ximsa' ),
			]
		);

        $this->add_control(
			'btn_link',
			[
				'label'       => __( 'Button Link', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::URL,
				'dynamic'     => [
					'active' => true,
				],
			]
		);

        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
			'shape',
			[
				'label' => esc_html__( 'Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'shape2',
			[
				'label' => esc_html__( 'Shape 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'icon',
			[
				'label' => esc_html__( 'Icon Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'linke',
			[
				'label' => esc_html__( 'Link', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);

        $this->add_control(
			'services',
			[
				'label' => esc_html__( 'Services Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);

        $this->add_control(
            'call_to_action',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Call To Action', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'cta-bgbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'classic' ],
				'exclude' => [ 'color' ],
				'selector' => '{{WRAPPER}} .xis-it-sservice-cta-content:after',
			]
		);
        $this->add_control(
			'cta_img',
			[
				'label'       => __( 'CTA Image', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $this->add_control(
			'ctasubtitle',
			[
				'label'       => __( 'CTA Sub Title', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Sub Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'ctatitle',
			[
				'label'       => __( 'CTA Title', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'call_title',
			[
				'label'       => __( 'Call Title', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'phone_no',
			[
				'label'       => __( 'Phone No', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Form Title', 'ximsa' ),
			]
		);

        $this->end_controls_section();

        $this->start_controls_section(
            'service_settings_style',
            [
                'label' => __( 'Service 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(
            'main_txt_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'text_cl',
            [
                'label'     => esc_html__( 'Heading Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-section-title p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'hd_text_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-section-title p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'feature_btn',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feature Button Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'feature_desc_color',
            [
                'label'     => esc_html__( 'Feature Button Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-btn a' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'btn-bg-info-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-btn a',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'btn__title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-btn a',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'feature_box_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feature Box Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'box-bg-info-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-service-item .xis-it-service-shape:before, .xis-it-service-item .xis-it-service-shape:after, .xis-it-service-item .inner-icon:before',
			]
		);
        $this->add_control(
            'feature_box_title_color',
            [
                'label'     => esc_html__( 'Feature Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-service-item .inner-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'service___title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-service-item .inner-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'cta-info_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'CTA info Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'cta-sub_title_cl',
            [
                'label'     => esc_html__( 'CTA Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-section-title span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'cta-sub_title_bg',
            [
                'label'     => esc_html__( 'CTA Sub Title BG', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-section-title span' => 'background: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'cta___title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-section-title span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'cta-_title_bg',
            [
                'label'     => esc_html__( 'CTA Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'cta_main__title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'contact-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-service-cta-btn .cia-btn-text span',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'cta_con__title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-service-cta-btn .cia-btn-text span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'cta-_phn_bg',
            [
                'label'     => esc_html__( 'CTA Phone Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-service-cta-btn .cia-btn-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'cta_phn__title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-it-sservice-cta-content .xis-it-service-text-wrap .xis-it-service-cta-btn .cia-btn-text h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'cta-box-background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-it-sservice-cta-content:before',
			]
		);
		$this->end_controls_section();
	}



	protected function render() {


		$settings = $this->get_settings_for_display(); ?>

        <!-- Start of service section
        ============================================= -->
        <section id="xis-it-service" class="xis-it-service-section" data-background="<?php echo esc_url($settings['service_bg']['url']);?>">
            <div class="container">
                <div class="xis-it-service-content">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="xis-it-service-inner-items d-flex flex-wrap wow fadeInLeft" data-wow-delay="200ms" data-wow-duration="1500ms">
                                <?php foreach($settings['services'] as $item):?>
                                <div class="xis-it-service-item position-relative text-center">
                                    <span class="xis-it-service-shape position-absolute"></span>
                                    <span class="xis-it-bottom-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape']['url']);?>" alt=""></span>
                                    <span class="xis-it-bottom-shape2 position-absolute"><img src="<?php echo esc_url($settings['shape2']['url']);?>" alt=""></span>
                                    <div class="inner-icon position-relative d-flex justify-content-center align-items-center">
                                        <img src="<?php echo esc_url($item['icon']['url']);?>" alt="">
                                    </div>
                                    <div class="inner-text position-relative xis-it-headline">
                                        <h3><a href="<?php echo esc_url($item['linke']['url']);?>"><?php echo esc_html($item['title']);?></a></h3>
                                    </div>
                                </div>
                                 <?php endforeach;?>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="xis-it-service-text-wrapper">
                                <div class="xis-it-section-title 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 wp_kses( $settings['title'], true );?></h2>
                                    <p><?php echo wp_kses( $settings['description'], true );?>
                                    </p>
                                </div>
                                <div class="xis-it-btn wow fadeInUp" data-wow-delay="300ms" data-wow-duration="1500ms">
                                    <a class="d-flex justify-content-center align-items-center" href="<?php echo esc_html($settings['btn_link']['url']);?>"><?php echo esc_html($settings['btn_label']);?></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="xis-it-sservice-cta-content position-relative">
                    <div class="cta-img-area position-absolute wow fadeInRight" data-wow-delay="200ms" data-wow-duration="1500ms">
                        <img src="<?php echo esc_url($settings['cta_img']['url']);?>" alt="">
                    </div>
                    <div class="xis-it-service-text-wrap position-relative">
                        <div class="xis-it-section-title xis-it-headline pera-content wow fadeInLeft" data-wow-delay="200ms" data-wow-duration="1500ms">
                            <span><?php echo esc_html($settings['ctasubtitle']);?></span>
                            <h2><?php echo esc_html($settings['ctatitle']);?></h2>
                        </div>
                        <div class="xis-it-service-cta-btn d-flex align-items-center  wow fadeInUp" data-wow-delay="300ms" data-wow-duration="1500ms">
                            <div class="cia-btn-icon d-flex align-items-center justify-content-center">
                                <i class="fas fa-phone-alt"></i>
                            </div>
                            <div class="cia-btn-text xis-it-headline wow fadeInLeft" data-wow-delay="400ms" data-wow-duration="1500ms">
                                <span><?php echo esc_html($settings['call_title']);?></span>
                                <h3><a href="tel:<?php echo esc_attr($settings['phone_no']);?>"><?php echo esc_html($settings['phone_no']);?></a></h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <!-- End of service  section
        ============================================= -->
		<?php
      }



}
