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

    /**
     * Get widget title.
     * Retrieve button widget title.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Digital Card Section', '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(
            'digital_card_discount',
            [
                'label' => esc_html__( 'Digital Card', 'ximsa' ),
            ]
        );
		$this->add_control(
			'shape',
			[
				'label'       => __( 'Shape', 'ximsa' ),
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
		
		$repeater = new \Elementor\Repeater();

        $repeater->add_control(
			'is_active',
			[
				'label' => esc_html__( 'Is Active', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'YES', 'ximsa' ),
				'label_off' => esc_html__( 'NO', 'ximsa' ),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);
        $repeater->add_control(
			'tab_title',
			[
				'label'       => __( 'Tab Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'tab_content',
			[
				'label'       => __( 'Tab Content', 'ximsa' ),
				'type'        => Controls_Manager::WYSIWYG,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'card_img',
			[
				'label'       => __( 'Card Image', 'ximsa' ),
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'sponsor',
			[
				'label'       => __( 'Sponsor', 'ximsa' ),
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        
        $this->add_control(
			'tabsitems',
			[
				'label' => esc_html__( 'Tabs Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
                'title_field' => '{{{ tab_title }}}',
			]
		);
		
		$this->end_controls_section();
        $this->start_controls_section(
            'tab_style-se',
            [
                'label' => __( 'Tab Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'tab_title_hed',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'tab_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .cards-tabs .tab-btns .tab-btn' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tab_active_title_cl',
            [
                'label'     => esc_html__( 'Title Active Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .cards-tabs .tab-btns .tab-btn:hover, .cards-tabs .tab-btns .tab-btn.active-btn' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'tab_active_bg_title_cl',
            [
                'label'     => esc_html__( 'Title Active BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .cards-tabs .tab-btns .tab-btn:hover, .cards-tabs .tab-btns .tab-btn.active-btn' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tab_title_typography',
                'label'          => esc_html__( 'Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .cards-tabs .tab-btns .tab-btn',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

        $this->add_control(
            'tab_content_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Content Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'tb_content_title_cl',
            [
                'label'     => esc_html__( 'Tab Content Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .cards-tabs h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tb_cont_title_typography',
                'label'          => esc_html__( 'Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .cards-tabs h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tb_content_txt',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Tab Content Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'tb_text_cl',
            [
                'label'     => esc_html__( 'Tab Text Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .cards-tabs p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tb_content_text_typography',
                'label'          => esc_html__( 'Text Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .cards-tabs p',
                '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');
    ?>
       <!-- Finance Cards Section -->
        <section class="finance-cards-section">
            <div class="auto-container">
                <!-- Cards Info Tabs -->
                <div class="cards-info-tabs">
                    <div class="pattern-layer" style="background-image: url(<?php echo esc_url($settings['shape']['url']);?>)"></div>
                    <!-- Cards Tabs -->
                    <div class="cards-tabs tabs-box">
                        
                        <!-- Tab Btns -->
                        <ul class="tab-btns tab-buttons clearfix">
                            <?php foreach($settings['tabsitems'] as $item):?>
                                <li data-tab="#prod-<?php echo esc_attr($item['_id']);?>" class="tab-btn  <?php if($item['is_active'] == 'yes'){echo esc_attr('active-btn');} ?>"><?php echo esc_html($item['tab_title']);?></li>
                            <?php endforeach;?>
                        </ul>
                        
                        <!-- Tabs Container -->
                        <div class="tabs-content">
                            <?php foreach($settings['tabsitems'] as $item):?>
                            <!-- Tab / Active Tab -->
                            <div class="tab <?php if($item['is_active'] == 'yes'){echo esc_attr('active-tab');} ?>  " id="prod-<?php echo esc_attr($item['_id']);?>">
                                <div class="content">
                                    <div class="row clearfix">
                                        <!-- Image Column -->
                                        <div class="image-column col-lg-5 col-md-12 col-sm-12">
                                            <div class="image">
                                                <img src="<?php echo esc_url($item['card_img']['url']);?>" alt="" />
                                            </div>
                                        </div>
                                        <!-- Content Column -->
                                        <div class="content-column col-lg-7 col-md-12 col-sm-12">
                                            <h3><?php echo esc_html($item['tab_title']);?></h3>
                                            <?php echo wp_kses( $item['tab_content'], true );?>
                                            <div class="company">
                                                <img src="<?php echo esc_url($item['sponsor']['url']);?>" alt="" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php endforeach;?>
                        </div>
                    </div>
                </div>
                    
                </div>
            </section>
            <!-- End Finance Cards Section -->
 
        <?php
    }
}
