<?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_steps_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_steps_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 Pay Steps', '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_pay_app',
            [
                'label' => esc_html__( 'Digital Pay Feature', 'ximsa' ),
            ]
        );
		$this->add_control(
			'shape',
			[
				'label'       => __( 'Shape', 'ximsa' ),
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
		$this->add_control(
			'stepname',
			[
				'label'       => __( 'Step Name', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Step Name', 'ximsa' ),
			]
		);
		$this->add_control(
			'subtitle',
			[
				'label'       => __( 'Sub Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Sub Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Title', 'ximsa' ),
			]
		);
		$repeater = new \Elementor\Repeater();
        $repeater->add_control(
			'reoreverse',
			[
				'label' => esc_html__( 'Reverse', '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(
			'step_name',
			[
				'label' => esc_html__( 'Icon', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
			]
		);
        
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'list_styles',
			[
				'label' => esc_html__( 'List Style', 'ximsa' ),
				'type' => Controls_Manager::WYSIWYG,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'step_img',
			[
				'label' => esc_html__( 'Step Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'step_img2',
			[
				'label' => esc_html__( 'Step 2 Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        
        
        $this->add_control(
			'stepsitem',
			[
				'label' => esc_html__( 'Step Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ step_name }}}',
			]
		);
		
		$this->end_controls_section();
        $this->start_controls_section(
            'feature_info_st',
            [
                'label' => __( 'Feature Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        
        
        $this->add_control(
            'step_top_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Top Large Heading Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'lg-hbackground',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'classic', 'gradient', 'video' ],
				'selector' => '{{WRAPPER}} .steps-section .step-big-title',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'lg_h_typography',
                'label'          => esc_html__( 'large Heading Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .steps-section .step-big-title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_sub_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_sub_title_cl',
            [
                'label'     => esc_html__( 'Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fs_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feature Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_title_cl',
            [
                'label'     => esc_html__( 'Feature Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feature_title_typography',
                'label'          => esc_html__( 'Feature Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_reg_title_cl',
            [
                'label'     => esc_html__( 'Feature Reguler Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three h2 span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feature_reg_title_typography',
                'label'          => esc_html__( 'Feature Reguler Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three h2 span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'step_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Step Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'stem_cl',
            [
                'label'     => esc_html__( 'Step Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .step-block .content-column .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'step_tes_typography',
                'label'          => esc_html__( 'Feature Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .step-block .content-column .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'ste_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Step Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'step_ttl_cl',
            [
                'label'     => esc_html__( 'Feature Info Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .step-block .content-column h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'step_title_cl_typography',
                'label'          => esc_html__( 'Step Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .step-block .content-column h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'ste_list_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Step List Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'step_list_cl',
            [
                'label'     => esc_html__( 'Step List Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .step-block .steps-list li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'step_list_icon_cl',
            [
                'label'     => esc_html__( 'Step Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .step-block .steps-list li:before' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'step_list_cl_typography',
                'label'          => esc_html__( 'Step Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .step-block .steps-list li',
                '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');
    ?>
        <!-- Steps Section -->
	<section class="steps-section" style="background-image: url(<?php echo esc_url($settings
['shape']['url']);?>)">
		<div class="step-big-title"><?php echo esc_html($settings['stepname']);?></div>
		<div class="auto-container">
			<div class="sec-title-three centered">
				<div class="title"><?php echo esc_html($settings['subtitle']);?></div>
				<h2><?php echo wp_kses( $settings['title'], true );?></span></h2>
			</div>
			
            
            <?php foreach($settings['stepsitem'] as $item):?>
			<!-- Step Block -->
			<div class="step-block">
				<div class="inner-box">
					<div class="row clearfix <?php if($item['reoreverse'] == 'yes'){echo esc_attr('flex-row-reverse');}?>">
						<!-- Content Column -->
						<div class="content-column col-lg-6 col-md-12 col-sm-12">
							<div class="inner-column">
								<div class="title"><?php echo esc_html($item['step_name']);?></div>
								<h2><?php echo wp_kses( $item['title'], true );?></h2>
								<div class="steps-list">
                                    <?php echo wp_kses( $item['list_styles'], true );?>
								</div>
							</div>
						</div>
						
						<!-- Image Column -->
						<div class="image-column col-lg-6 col-md-12 col-sm-12">
							<div class="inner-column">

                                <?php if(!empty($item['step_img']['url'])):?>
                                    <div class="image wow fadeInRight" data-wow-delay="0ms" data-wow-duration="1500ms">
                                        <img src="<?php echo esc_url($item['step_img']['url']);?>" alt="" />
                                    </div>
                                <?php endif;?>

                                <?php if(!empty($item['step_img2']['url'])):?>
                                    <div class="image-two wow fadeInRight" data-wow-delay="300ms" data-wow-duration="1500ms">
                                        <img src="<?php echo esc_url($item['step_img2']['url']);?>" alt="" />
                                    </div>
                                <?php endif;?>

							</div>
						</div>
						
					</div>
				</div>
			</div>
			<!-- End Step Block -->
			<?php endforeach;?>
			
		</div>
	</section>
	<!-- End Steps Section -->
 
        <?php
    }
}
