<?php


use Elementor\Utils;
use Elementor\Controls_Manager;
use Elementor\Widget_Base;
use Elementor\Plugin;
use Elementor\Repeater;

class wpsection_table_Widget extends \Elementor\Widget_Base {
	public function get_name() {
		return 'wpsection_table';
	}

	public function get_title() {
		return __( 'Table', 'wpsectionsupport' );
	}

	public function get_icon() {
		 return 'wpsd dashicons dashicons-nametag';
	}

	public function get_keywords() {
		return [ 'wpsection', 'table' ];
	}

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

	

	protected function register_controls() {
		$this->start_controls_section(
			'general',
			[
				'label' => __( 'General', 'wpsectionsupport' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

        $repeater = new Repeater();

        $repeater->add_control(
            'text_left',
            [
                'label' => esc_html__('Text', 'wpsectionsupport'),
                'label_block' => true,
                'type' => Controls_Manager::TEXT,
                'default' => __('', 'wpsectionsupport'),
            ]
        );

        $repeater->add_control(
            'text_right',
            [
                'label' => esc_html__('Text', 'wpsectionsupport'),
                'label_block' => true,
                'type' => Controls_Manager::TEXT,
                'default' => __('', 'wpsectionsupport'),
            ]
        );

        $this->add_control(
            'items',
            [
                'label' => esc_html__('Repeater List', 'wpsectionsupport'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'list_title' => esc_html__('Title #1', 'wpsectionsupport'),
                        'list_content' => esc_html__('Item content. Click the edit button to change this text.', 'wpsectionsupport'),
                    ],
                ],
            ]
        );

        $this->end_controls_section();

        // Title 	==================			
		$this->start_controls_section(
			'title_settings',
			array(
				'label' => __( 'Title Setting', 'wpsectionsupport' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);
				

		$this->add_control(
			'table_padding',
			array(
				'label'     => __( 'Padding', 'wpsectionsupport' ),
				'type'      => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' =>  ['px', '%', 'em' ],
			
				'selectors' => array(
					'{{WRAPPER}} table tr td' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important',
				),
			)
		);
		
		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'     => 'table_typography',
				'label'    => __( 'Typography', 'wpsectionsupport' ),
				'selector' => '{{WRAPPER}} table tr td',
			)
		);
		
		$this->add_control(
			'table_color',
			array(
				'label'     => __( 'Color', 'wpsectionsupport' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} table tr td' => 'color: {{VALUE}} !important',
		
				),
			)
		);

        $this->end_controls_section();	


	}

	protected function render() {
		global $plugin_root;
		$settings = $this->get_settings_for_display();

?>

   <section class="defunt_ten ">
        <table>
        <?php
            $i = 1;
            foreach ($settings["items"] as $item) { ?>
            <tr>
                <td><?php echo wp_kses($item['text_left'], true); ?></td>
                <td><?php echo wp_kses($item['text_right'], true); ?></td>
            </tr>
            <?php $i++;
            } ?>
        </table>
 </section>




        <?php

	}
}

// Register widget
Plugin::instance()->widgets_manager->register( new \wpsection_table_Widget() );