<?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_pricing_table 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_pricingtable';
    }

    /**
     * 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 Pricing Table', '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_pricing_table',
            [
                'label' => esc_html__( 'Helpdesk Pricing Table', '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(
			'description', [
				'label' => esc_html__( 'Description', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
		$this->add_control(
			'tab_1', [
				'label' => esc_html__( 'Tab 1 Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$this->add_control(
			'tab_2', [
				'label' => esc_html__( 'Tab 1 Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
        $this->add_control(
			'pricng_shape', [
				'label' => esc_html__( 'Pricing Box Shape Upload', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'label_block' => 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(
			'title', [
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'price', [
				'label' => esc_html__( 'Price', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'preiod', [
				'label' => esc_html__( 'Preiod', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		
		$repeater->add_control(
			'short_desc', [
				'label' => esc_html__( 'Short Description', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'price_list',
			[
				'label' => esc_html__( 'Priceing List', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
			]
		);
		
		$repeater->add_control(
			'btn_label', [
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => false,
			]
		);
		$repeater->add_control(
			'btn_link', [
				'label' => esc_html__( 'Button Link', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::URL,
				'show_label' => false,
			]
		);

		$this->add_control(
			'monthlypricing',
			[
				'label' => esc_html__( 'Add Monthly Pricing Table', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
        $repeater = new Repeater();
		
		$repeater->add_control(
			'title', [
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
        $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(
			'price', [
				'label' => esc_html__( 'Price', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'preiod', [
				'label' => esc_html__( 'Preiod', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
			]
		);
		
		$repeater->add_control(
			'short_desc', [
				'label' => esc_html__( 'Short Description', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
			]
		);
		$repeater->add_control(
			'price_list',
			[
				'label' => esc_html__( 'Priceing List', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
			]
		);
		
		$repeater->add_control(
			'btn_label', [
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => false,
			]
		);
		$repeater->add_control(
			'btn_link', [
				'label' => esc_html__( 'Button Link', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::URL,
				'show_label' => false,
			]
		);

		$this->add_control(
			'yearlypricing',
			[
				'label' => esc_html__( 'Add Yearly Pricing Table', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ 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', 'ximsa' ),
				'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(
            'title-txt-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            '__txt_cl',
            [
                'label'     => esc_html__( 'Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-section-title.text-center p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'title_text_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-section-title.text-center p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tabs-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'tab_btn_cl',
            [
                'label'     => esc_html__( 'Tab Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-btn .nav-pills .nav-link' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_control(
            'tab_btn_btn_cl',
            [
                'label'     => esc_html__( 'Tab Button Active Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-btn .year-btn:after' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tba_btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-btn .nav-pills .nav-link',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing-heading-style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Pricing Info Style Settings', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'pricing_title_style',
            [
                'label'     => esc_html__( 'Pricing Title Settings', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .inner-title .price-category' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'pricing_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-item .inner-title .price-category',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing_style_s',
            [
                'label'     => esc_html__( 'Pricing Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .inner-title h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'pricing__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-item .inner-title h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing_txte_s',
            [
                'label'     => esc_html__( 'Pricing Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .inner-title p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'pricing_txt_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-item .inner-title p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing_list_s',
            [
                'label'     => esc_html__( 'Pricing List Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .inner-list li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'pricing_dots_s',
            [
                'label'     => esc_html__( 'Pricing Dot Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .inner-list li:before' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'pricing_list_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-item .inner-list li',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing_btn_cl',
            [
                'label'     => esc_html__( 'Pricing Button Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .price-btn a span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'pricing_btn_bg_cl',
            [
                'label'     => esc_html__( 'Pricing Button BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item .price-btn a' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'pricing_btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-hd-pricing-item .price-btn a span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'pricing_bg_bg_cl',
            [
                'label'     => esc_html__( 'Pricing Hover Background Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-hd-pricing-item:hover' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
		$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 Pricing section
	============================================= -->
	<section id="xis-hd-pricing" class="xis-hd-pricing-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 text-center pera-content 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>
				<p><?php echo wp_kses( $settings['description'], true );?></p>
			</div>
			<div class="xis-hd-pricing-content">
				<div class="xis-hd-pricing-btn ul-li">
					<ul class="nav nav-pills  text-center text-capitalize" id="pills-tab" role="tablist">
						<li class="nav-item"  role="presentation">
							<a class="nav-link  active"  data-bs-toggle="pill" href="#tb1" role="tab"  aria-selected="true"><?php echo wp_kses( $settings['tab_1'], true );?></a>
						</li>
						<li class="nav-item"  role="presentation">
							<a class="nav-link year-btn"  data-bs-toggle="pill" href="#tb2" role="tab"  aria-selected="true"><?php echo wp_kses( $settings['tab_2'], true );?></a>
						</li>
					</ul>
				</div>
				<div class="xis-hd-price-tab-content">
					<div class="tab-content" id="pills-tabContent">
						<div class="tab-pane fade active show" id="tb1" role="tabpanel" aria-labelledby="pills-home-tab">
							<div class="xis-hd-pricing-plan-content">
								<div class="row">
									<?php foreach($settings['monthlypricing'] as $month):?>
									<div class="col-lg-4">
										<div class="xis-hd-pricing-item xis-hd-headline pera-content ul-li-block position-relative <?php if('yes' == $month['active']){echo esc_attr('active');}?>">
											<span class="xis-hd-price-bg position-absolute"><img src="<?php echo esc_url($settings['pricng_shape']['url']);?>" alt=""></span>
											<div class="inner-title">
												<span class="price-category text-uppercase"><?php echo wp_kses( $month['title'], true );?></span>
												<h3><?php echo wp_kses( $month['price'], true );?> <span><?php echo wp_kses( $month['preiod'], true );?></span></h3>
												<p><?php echo wp_kses( $month['short_desc'], true );?></p>
											</div>
											<div class="inner-list">
                                                <?php echo wp_kses( $month['price_list'], true );?>
											</div>
											<div class="price-btn">
												<a class="d-flex justify-content-center align-items-center" href="<?php echo esc_url($month['btn_link']['url']);?>"><i class="fal fa-arrow-right"></i> <span><?php echo wp_kses( $month['btn_label'], true );?></span></a>
											</div>
										</div>
									</div>
                                    <?php endforeach;?>
								</div>
							</div>
						</div>
						<div class="tab-pane fade" id="tb2" role="tabpanel" aria-labelledby="pills-home-tab">
							<div class="xis-hd-pricing-plan-content">
								<div class="row">
									
                                    <?php foreach($settings['yearlypricing'] as $year):?>
									<div class="col-lg-4">
										<div class="xis-hd-pricing-item xis-hd-headline pera-content ul-li-block position-relative <?php if('yes' == $year['active']){echo esc_attr('active');}?>">
											<span class="xis-hd-price-bg position-absolute"><img src="<?php echo esc_url($settings['pricng_shape']['url']);?>" alt=""></span>
											<div class="inner-title">
												<span class="price-category text-uppercase"><?php echo wp_kses( $year['title'], true );?></span>
												<h3><?php echo wp_kses( $year['price'], true );?> <span><?php echo wp_kses( $year['preiod'], true );?></span></h3>
												<p><?php echo wp_kses( $year['short_desc'], true );?></p>
											</div>
											<div class="inner-list">
                                                <?php echo wp_kses( $year['price_list'], true );?>
											</div>
											<div class="price-btn">
												<a class="d-flex justify-content-center align-items-center" href="<?php echo esc_url($year['btn_link']['url']);?>"><i class="fal fa-arrow-right"></i> <span><?php echo wp_kses( $year['btn_label'], true );?></span></a>
											</div>
										</div>
									</div>
                                    <?php endforeach;?>
                                    
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
<!-- End of Pricing section
	============================================= -->
  
	<?php
    }
}
