<?php
namespace dexen\Widget;
  use Elementor\Utils;
  use SmartDataSoft\Owl\SliderSettings\sliderSettings;


class PricingTable extends \Elementor\Widget_Base {

	public function get_name() {
		return 'dexen_prcing_table';
	}

	public function get_title() {
		return esc_html__( 'Dexen Pricing Table', 'dexen-core' );
	}

	public function get_icon() {
		return 'fa fa-object-ungroup';
	}

	public function get_categories() {
		return [ 'dexencore' ];
	}

	protected function _register_controls() {

		
		$this->start_controls_section(
			'title_settings',
			[
				'label' => __( 'Header Settings', 'dexen-core' ),
			]
		);

		$this->add_control(
			'title',
			[
				'label'   => __( 'Titile', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Title', 'dexen-core' ),

			]
		);
		$this->add_control(
			'tag_line',
			[
				'label'   => __( 'Tag Line', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Tag Line', 'dexen-core' ),

			]
		);


		$this->end_controls_section();

		$this->start_controls_section(
			'pricing_settings',
			[
				'label' => __( 'Pricing Settings', 'dexen-core' ),
			]
		);

	

		$repeater = new \Elementor\Repeater();
	
		$repeater->add_control(
			'pricing_titile',
			[
				'label'   => __( 'Pricing Titile', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Standerd Plan', 'dexen-core' ),

			]
		);

		$repeater->add_control(
			'price',
			[
				'label'   => __( 'Price', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( '$39', 'dexen-core' ),

			]
		);
		$repeater->add_control(
			'content',
			[
				'label'   => __( 'Content', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXTAREA,
				'default' => __( 'Rounded & Colored', 'dexen-core' ),

			]
		);
		$repeater->add_control(
			'button_text',
			[
				'label'   => __( 'Button Text', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Purchase Now', 'dexen-core' ),
			]
		);
		$repeater->add_control(
			'button_text_link',
			[
				'label'         => __( 'Button Url', 'dexen-core' ),
				'type'          => \Elementor\Controls_Manager::URL,
				'placeholder'   => __( 'https://your-link.com', 'plugin-domain' ),
				'show_external' => true,
				'default'       => [
					'url'         => '',
					'is_external' => true,
					'nofollow'    => true,
				],

			]
		);

		$this->add_control(
			'items1',
			[
				'label'   => __( 'Repeater List', 'dexen-core' ),
				'type'    => \Elementor\Controls_Manager::REPEATER,
				'fields'  => $repeater->get_controls(),
				'default' => [
					[
						'list_title'   => __( 'Title #1', 'dexen-core' ),
						'list_content' => __( 'Item content. Click the edit button to change this text.', 'dexen-core' ),
					],
					[
						'list_title'   => __( 'Title #2', 'dexen-core' ),
						'list_content' => __( 'Item content. Click the edit button to change this text.', 'dexen-core' ),
					],
				],
				'title_field' => '{{pricing_titile}}',
			]
		);
		$this->end_controls_section();


	}

	protected function render() {
		$settings             = $this->get_settings_for_display();
	
		$title       = $settings['title'];
		$tag_line       = $settings['tag_line'];
	
		$layout_class  = '';
		$premium_class = '';


		?> 
		<section class="price-one sec-pad sec-pad-content-margin-30 thm-gray-bg">
            <div class="container">
                <div class="block-title text-center">
                    <p class="block-title__tag-line "><?php echo wp_kses_post($tag_line); ?></p>
                    <h2 class="block-title__title"><?php echo wp_kses_post($title); ?></h2>
                </div><!-- /.block-title -->
                <div class="row">
				<?php
								foreach ( $settings['items1'] as $item ) {
									$pricing_titile       = $item['pricing_titile'];
									$pricing_sub_titile   = $item['pricing_sub_titile'];
									$price                = $item['price'];
							
									
									$button_text          = $item['button_text'];
									$button_text_link           = $item['button_text_link']['url'];
							
											$feature_name = $item['feature_name'];
				?>
                    <div class="col-lg-4">
                        <div class="price-one__single text-center content-margin-30">
                            <div class="price-one__top">
                                <p class="price-one__title"><?php echo $pricing_titile; ?></p><!-- /.price-one__title -->
                                <h3 class="price-one__price"><?php echo $price; ?></h3><!-- /.price-one__price -->
                            </div><!-- /.price-one__top -->
                            <div class="price-one__bottom">
								<?php echo wp_kses_post($item['content']); ?>
							<!-- /.price-one__feature -->
								<?php if(!empty($item['button_text_link']['url'])) :?>
                                    <a 
                                                    class="thm-btn"
                                                    href="<?php echo esc_url($item['button_text_link']['url']); ?>"
                                                    <?php
                                                        $target = $item['button_text_link']['is_external'] ? ' target=_blank' : '';
                                                        $nofollow = $item['button_text_link']['nofollow'] ? ' rel=nofollow' : '';
                                                        echo esc_attr($target . $nofollow);
                                                    ?>><?php echo wp_kses_post($item['button_text']);  ?></a>
                                    </a>   
                                <?php endif;?>
                            </div><!-- /.price-one__bottom -->
                        </div><!-- /.price-one__single -->
					</div><!-- /.col-lg-4 -->
					<?php } ?>  
                </div><!-- /.row -->
            </div><!-- /.container -->
		</section>
		<?php
	}

	protected function _content_template() {

	}
}

  \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new PricingTable() );

