<?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;

/**
 * Elementor button widget.
 * Elementor widget that displays a button with the ability to control every
 * aspect of the button design.
 *
 * @since 1.0.0
 */
class helpdesk_about extends Widget_Base {

    /**
     * Get widget name.
     * Retrieve button widget name.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget name.
     */
    public function get_name() {
        return 'helpdesk_about';
    }

    /**
     * Get widget title.
     * Retrieve button widget title.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Helpdesk About', 'ximsa' );
    }

    /**
     * Get widget icon.
     * Retrieve button widget icon.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'eicon-library-open';
    }

    /**
     * Get widget categories.
     * Retrieve the list of categories the button widget belongs to.
     * Used to determine where to display the widget in the editor.
     *
     * @since  2.0.0
     * @access public
     * @return array Widget categories.
     */
    public function get_categories() {
        return [ 'ximsa' ];
    }

    /**
     * Register button 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(
            'helpdesk_newslater',
            [
                'label' => esc_html__( 'Helpdesk Newslater', 'ximsa' ),
            ]
        );
		$this->add_control(
			'banner_bg',
			[
				'label'       => __( 'Banner BG', 'ximsa' ),
				'label_block' => true,
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);


		$this->add_control(
			'subtitle', [
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);


		$this->add_control(
			'title', [
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);

		$this->add_control(
			'button_label', [
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);

		$this->add_control(
			'button_link', [
				'label' => esc_html__( 'Button Link', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::URL,
				'show_label' => true,
			]
		);
		$repeater = new Repeater();
		
        $repeater->add_control(
			'active',
			[
				'label' => esc_html__( 'Active', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'YES', 'ximsa' ),
				'label_off' => esc_html__( 'NO', 'ximsa' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);
        
		$repeater->add_control(
			'tab_title', [
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'content_title', [
				'label' => esc_html__( 'Content Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'content_description', [
				'label' => esc_html__( 'Content Description', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
        $repeater->add_control(
            'list_item1',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'List Item 1 Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
		$repeater->add_control(
			'list1_title', [
				'label' => esc_html__( 'List 1 Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'list1_text', [
				'label' => esc_html__( 'List 1 Text', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
        $repeater->add_control(
            'list_item2',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'List Item 2 Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
		$repeater->add_control(
			'list2_title', [
				'label' => esc_html__( 'List 2 Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'list2_text', [
				'label' => esc_html__( 'List 2 Text', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
        $repeater->add_control(
            'list_item3',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'List Item 3 Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
		$repeater->add_control(
			'list3_title', [
				'label' => esc_html__( 'List 3 Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'list3_text', [
				'label' => esc_html__( 'List 3 Text', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'conten_img', [
				'label' => esc_html__( 'Image', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'conten_img2', [
				'label' => esc_html__( 'Image Two', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
			]
		);
		
		$this->add_control(
			'tabsitems',
			[
				'label' => esc_html__( 'tab item Table', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ tab_title }}}',
			]
		);
		$this->end_controls_section();

        $this->start_controls_section(
            'section_heading_op',
            [
                'label' => __( 'Section Heading Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
			'width',
			[
				'label' => esc_html__( 'Container Width', 'plugin-name' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 2000,
						'step' => 1,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 1320,
				],
				'selectors' => [
					'{{WRAPPER}} .container' => 'max-width: {{SIZE}}{{UNIT}};',
				],
			]
		);
        
        
        $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-hd-banner-text .banner-tag, .xis-hd-section-title .sub-title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sub_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-banner-text .banner-tag, .xis-hd-section-title .sub-title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'title--style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'title_txt_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'title__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb-info-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'tab_item_color',
            [
                'label'     => esc_html__( 'Tab Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-btn .nav-tabs .nav-link' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tab_active_color',
            [
                'label'     => esc_html__( 'Tab Active Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-btn .nav-tabs .nav-link.active' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tab_active_br_color',
            [
                'label'     => esc_html__( 'Tab Active Border Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-btn .nav-link:after' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_item_btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-about-tab-btn .nav-tabs .nav-link',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb-content-s-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Content Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'tb_cont_title',
            [
                'label'     => esc_html__( 'Tab Content Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-text-wrap h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_content_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-about-tab-text-wrap h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb_cont_txt',
            [
                'label'     => esc_html__( 'Tab Content Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-text-wrap p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_content_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-about-tab-text-wrap p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb_list_txt',
            [
                'label'     => esc_html__( 'Tab List Item Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-text-wrap .xis-hd-about-tab-feature-item span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tb_list_bg_ck',
            [
                'label'     => esc_html__( 'Check Background Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-text-wrap .xis-hd-about-tab-feature-item span:before' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_content_lst_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-about-tab-text-wrap .xis-hd-about-tab-feature-item span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb_btn_link_ck',
            [
                'label'     => esc_html__( 'Button Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-about-tab-btn-wrap .xis-hd-about-btn a' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_btn_st_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-about-tab-btn-wrap .xis-hd-about-btn a',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
		$this->end_controls_section();
    }

    /**
     * Render button widget output on the frontend.
     * Written in PHP and used to generate the final HTML.
     *
     * @since  1.0.0
     * @access protected
     */
    protected function render() {
        $settings = $this->get_settings_for_display();
        $allowed_tags = wp_kses_allowed_html('post');
    ?>
		
    <!-- Start of About section
	============================================= -->
	<section id="xis-hd-about" class="xis-hd-about-section position-relative">
		<span class="xis-hd-bg-shape position-absolute"><img src="<?php echo esc_url($settings['banner_bg']['url']);?>" alt=""></span>
		<div class="container">
			<div class="xis-hd-section-title xis-hd-headline wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
				<div class="sub-title">
					<?php echo wp_kses( $settings['subtitle'], true );?>
				</div>
				<h2>
                    <?php echo wp_kses( $settings['title'], true );?>
				</h2>
			</div>
			<div class="xis-hd-about-content">
				<div class="xis-hd-about-tab-btn-wrap d-flex justify-content-between">
					<div class="xis-hd-about-tab-btn">
						<ul class="nav nav-tabs" id="myTab" role="tablist">
                            <?php foreach($settings['tabsitems'] as $item):?>
							<li class="nav-item" role="presentation">
								<button class="nav-link <?php if($item['active'] == 'yes'){echo esc_attr('active');}?>" id="home-tab-<?php echo esc_attr($item['_id']);?>" data-bs-toggle="tab" data-bs-target="#home<?php echo esc_attr($item['_id']);?>" type="button" role="tab" aria-controls="home<?php echo esc_attr($item['_id']);?>" aria-selected="true"><?php echo wp_kses( $item['tab_title'], true );?></button>
							</li>
							<?php endforeach;?>
						</ul>
					</div>
                    <?php if(!empty($settings['button_label'])):?>
					<div class="xis-hd-about-btn">
						<a href="<?php echo esc_url($settings['button_link']['url']);?>"><?php echo esc_html($settings['button_label']);?>  <i class="far fa-arrow-right"></i></a>
					</div>
                    <?php endif;?>
				</div>
				<div class="xis-hd-about-tab-content">
					<div class="tab-content" id="myTabContent">
                    <?php foreach($settings['tabsitems'] as $item):?>
						<div class="tab-pane fade <?php if($item['active'] == 'yes'){echo esc_attr('show active');}?>" id="home<?php echo esc_attr($item['_id']);?>" role="tabpanel" aria-labelledby="home-tab-<?php echo esc_attr($item['_id']);?>">
							<div class="xis-hd-about-tab-content-wrapper">
								<div class="row">
									<div class="col-lg-6">
										<div class="xis-hd-about-tab-text-wrap xis-hd-headline pera-content">
											<h3>
                                                <?php echo wp_kses( $item['content_title'], true );?>
											</h3>
											<p>
                                                <?php echo wp_kses( $item['content_description'], true );?>
											</p>
											<div class="xis-hd-about-tab-feature-wrap">
                                                <?php if(!empty($item['list1_title'])):?>
                                                    <div class="xis-hd-about-tab-feature-item">
                                                        <span><?php echo wp_kses( $item['list1_title'], true );?></span>
                                                        <p><?php echo wp_kses( $item['list1_text'], true );?></p>
                                                    </div>
                                                 <?php endif;?>    
                                                 
                                                 <?php if(!empty($item['list2_title'])):?>
                                                    <div class="xis-hd-about-tab-feature-item">
                                                        <span><?php echo wp_kses( $item['list2_title'], true );?></span>
                                                        <p><?php echo wp_kses( $item['list2_text'], true );?></p>
                                                    </div>
                                                <?php endif;?>   
                                                 
                                                 <?php if(!empty($item['list3_title'])):?>
                                                    <div class="xis-hd-about-tab-feature-item">
                                                        <span><?php echo wp_kses( $item['list3_title'], true );?></span>
                                                        <p><?php echo wp_kses( $item['list3_text'], true );?></p>
                                                    </div>
                                                <?php endif;?>   
                                                
											</div>
										</div>
									</div>
									<div class="col-lg-6">
										<div class="xis-hd-about-tab-img-wrap">
											<div class="row">
												<div class="col-md-6">
													<div class="xis-hd-about-tab-img">
														<img src="<?php echo esc_url($item['conten_img']['url']);?>" alt="">
													</div>
												</div>
												<div class="col-md-6">
													<div class="xis-hd-about-tab-img">
														<img src="<?php echo esc_url($item['conten_img2']['url']);?>" alt="">
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
                        <?php endforeach;?>
					</div>
				</div>
			</div>
		</div>
	</section>
<!-- End of About section
	============================================= -->
  
	<?php
    }
}
