<?php

/**
 * Elementor Widget
 * @package Meditest
 * @since 1.0.0
 */

namespace Elementor;

if (!defined('ABSPATH')) exit; // Exit if accessed directly.

class meditest_pricing_table 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 'meditest-pricing-table';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return esc_html__('Pricing Table', 'meditest-extra');
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Elementor widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'fas fa-th-large';
	}

	/**
	 * 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 ['meditest_widgets'];
	}

	/**
	 * 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->layout_options();
	}

	/**
	 * Layout Options
	 */
	private function layout_options()
	{


		$this->start_controls_section(
			'layout_option',
			[
				'label' => __('Layout Options', 'meditest-extra'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'plan_title',
			[
				'label' => esc_html__('Plan Title', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Standard', 'meditest-extra'),
				'label_block' => true,
			]
		);
		$this->add_control(
			'plan_desc',
			[
				'label' => esc_html__('Plan Description', 'meditest-extra'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla venenatis tempus.', 'meditest-extra'),
				'label_block' => true,
			]
		);
		$this->add_control(
			'plan_price',
			[
				'label' => esc_html__('Plan Price', 'textdomain'),
				'type' => Controls_Manager::NUMBER,
				'default' => 99,
			]
		);
		$this->add_control(
			'plan_package',
			[
				'label' => esc_html__('Plan Packege Text', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'default' => esc_html__('Per Month', 'meditest-extra'),
			]
		);

		$this->add_control(
			'plan_features_title',
			[
				'label' => esc_html__('Features Title', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'default' => esc_html__('Features', 'meditest-extra'),
			]
		);


		$repeater = new Repeater();



		$repeater->add_control(
			'plan_features',
			[
				'label' => esc_html__('Plan Features', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Life time free update', 'meditest-extra'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'feature_lists',
			[
				'label' => esc_html__('Plan Features List', 'meditest-extra'),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'plan_features' => esc_html__('Life time free update', 'meditest-extra'),
					],
				],
				'title_field' => '{{{ plan_features }}}',
			]
		);


		$this->add_control(
			'plan_btn_text',
			[
				'label' => esc_html__('Button Text', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'default' => esc_html__('Get Started', 'meditest-extra'),
			]
		);

		$this->add_control(
			'plan_link_url',
			[
				'label' => esc_html__('Button Link', 'textdomain'),
				'type' => Controls_Manager::URL,
				'placeholder' => esc_html__('https://your-link.com', 'textdomain'),
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->add_control(
			'active_table',
			[
				'label' => esc_html__('Active Table', 'textdomain'),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__('Active', 'textdomain'),
				'label_off' => esc_html__('Deactive', 'textdomain'),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);


		$this->end_controls_section();
        $this->start_controls_section(
            'layout_Style_option',
            [
                'label' => __('Price Header Style', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header TItle Typography', 'meditest-extra'),
                'name' => 'Header_typo',
                'selector' => '{{WRAPPER}} .price-title',
            ]
        );
        $this->add_control(
            'Header_typo_color',
            [
                'label' => esc_html__('Header TItle Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .price-title' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Text Typography', 'meditest-extra'),
                'name' => 'Header_dec_typo',
                'selector' => '{{WRAPPER}} .price-desc',
            ]
        );
        $this->add_control(
            'Header_dec_typo_color',
            [
                'label' => esc_html__('Header Text Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .price-desc' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Price Typography', 'meditest-extra'),
                'name' => 'Header_price_typo',
                'selector' => '{{WRAPPER}} .plan-price',
            ]
        );
        $this->add_control(
            'Header_price_typo_color',
            [
                'label' => esc_html__('Header Price Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .plan-price span' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Price Typography', 'meditest-extra'),
                'name' => 'Header_price_typo',
                'selector' => '{{WRAPPER}} .plan-price span',
            ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'layout_body_Style_option',
            [
                'label' => __('Price Body Style', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Body Title Typography', 'meditest-extra'),
                'name' => 'Header_body_price_typo',
                'selector' => '{{WRAPPER}} .features-title',
            ]
        );
        $this->add_control(
            'Header_body_price_typo_color',
            [
                'label' => esc_html__('Header Body Title Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .features-title' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Body List Typography', 'meditest-extra'),
                'name' => 'Header_body_list_price_typo',
                'selector' => '{{WRAPPER}} .pricing-features-content .features-list ul li',
            ]
        );
        $this->add_control(
            'Header_body_list_price_typo_color',
            [
                'label' => esc_html__('Header Body List Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-features-content .features-list ul li , {{WRAPPER}} .pricing-features-content .features-list ul li i' => 'color: {{VALUE}}'
                ],
            ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'layout_body_Button_option',
            [
                'label' => __('Price Body Button', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Header Body Button Typography', 'meditest-extra'),
                'name' => 'Header_body_list_button',
                'selector' => '{{WRAPPER}} .pricing-table-content .pricing-plan-btn a',
            ]
        );
        $this->add_control(
            'Header_body_list_button_color',
            [
                'label' => esc_html__('Header Body Button Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-table-content .pricing-plan-btn a' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_control(
            'Header_body_list_button_bg_color',
            [
                'label' => esc_html__('Header Body Button BG Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-table-content .pricing-plan-btn a' => 'background-color: {{VALUE}}'
                ],
            ]
        );
        $this->add_control(
            'Header_body_list_button_bg_hover_color',
            [
                'label' => esc_html__('Header Body Button BG Hover Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing-table-content .pricing-plan-btn a:hover' => 'background-color: {{VALUE}}'
                ],
            ]
        );
        $this->end_controls_section();
	}




	protected function render()
	{


		$settings = $this->get_settings_for_display();


?>

		<div class="pricing-table-wrap <?php if ('yes' == $settings['active_table']) {
											echo esc_attr('active');
										} ?>">
			<div class="pricing-table-content">

				<div class="pricing-table-inner">

					<div class="pricing-table-head">
						<h3 class="price-title"><?php echo $settings['plan_title']; ?></h3>
						<p class="price-desc"><?php echo $settings['plan_desc']; ?></p>
						<div class="plan-price">
							<span><?php echo esc_html('$', 'meditest-extra'); ?><?php echo $settings['plan_price']; ?></span>
							<span class="plan-package"><?php echo $settings['plan_package']; ?></span>
						</div>
					</div>

					<div class="pricing-features-content">
						<h4 class="features-title"><?php echo $settings['plan_features_title']; ?></h4>

						<div class="features-list">
							<ul>
								<?php if ($settings['feature_lists']) {
									foreach ($settings['feature_lists'] as $feature) {
								?>
										<li><i class="ri-checkbox-circle-line"></i> <?php echo $feature['plan_features']; ?></li>
								<?php }
								} ?>
							</ul>
						</div>
					</div>

				</div>


				<div class="pricing-plan-btn">
					<a href="<?php echo esc_url($settings['plan_link_url']['url']); ?>"><?php echo $settings['plan_btn_text']; ?></a>
				</div>

			</div>
		</div>


<?php
	}
}


Plugin::instance()->widgets_manager->register_widget_type(new meditest_pricing_table());
