<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Geroz
 * @since 1.0.0
 */ 
 
class Home1_Price 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 'geroz-home1-price-widget';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Home 1 Price', 'geroz-core' );
	}

	/**
	 * Get widget icon.
	 * Retrieve button widget icon.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-flash';
	}

	/**
	 * 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 ['geroz_widgets'];
    }
	
	/**
	 * 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(
			'home1-price-content',
			[
				'label' => esc_html__( 'Price Content', 'geroz-core' ),
			]
		);	

		$this->add_control(
			'image',
			[
				'label' => esc_html__( 'Image', 'geroz-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => Utils::get_placeholder_image_src(),
				],
			]
		);

		$this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'geroz-core' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'We are here to help you', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your title here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'subtitle',
			[
				'label' => esc_html__( 'Subtitle', 'geroz-core' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'We are here to help you', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your subtitle here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'text',
			[
				'label' => esc_html__( 'Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your text here', 'geroz-core' ),
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'home1-tab-content',
			[
				'label' => esc_html__( 'Tab Content', 'geroz-core' ),
			]
		);	

		$this->add_control(
			'tab_title',
			[
				'label' => esc_html__( 'Tab Title', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Tab 1', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab title here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'tab_title2',
			[
				'label' => esc_html__( 'Tab Title 2', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Tab 2', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab title here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'tab_title3',
			[
				'label' => esc_html__( 'Tab Title 3', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Tab 3', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab title here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'tab_title4',
			[
				'label' => esc_html__( 'Tab Title 4', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Tab 4', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab title here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'id_name',
			[
				'label' => esc_html__( 'Tab ID Name', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'tab1', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab ID name here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'id_name2',
			[
				'label' => esc_html__( 'Tab ID Name 2', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'tab2', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab ID name here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'id_name3',
			[
				'label' => esc_html__( 'Tab ID Name 3', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'tab3', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab ID name here', 'geroz-core' ),
			]
		);

		$this->add_control(
			'id_name4',
			[
				'label' => esc_html__( 'Tab ID Name 4', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'tab4', 'geroz-core' ),
				'placeholder' => esc_html__( 'Type your tab ID name here', 'geroz-core' ),
			]
		);

		$this->end_controls_section();

		// Tab Start - 3

		$this->start_controls_section(
			'content_section',
			[
				'label' => __( 'Block', 'geroz-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);
		$this->add_control(
		  'repeat', 
			[
				'type' => Controls_Manager::REPEATER,
				'separator' => 'before',
				'default' => 
					[
						['section_title' => esc_html__('Hello World', 'geroz-core')],
					],
				'fields' => 
					[	
						
						[
							'name' => 'section_id',
							'label' => esc_html__( 'Section ID', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( 'section1', 'geroz-core' ),
							'placeholder' => esc_html__( 'Type your section ID here', 'geroz-core' ),
						],
						[
							'name' => 'section_subtitle',
							'label' => esc_html__( 'Section Subtitle', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( 'Basic Plan', 'geroz-core' ),
						],
						[
							'name' => 'section_title',
							'label' => esc_html__( 'Section Title', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '$99.00', 'geroz-core' ),
						],
						[
							'name' => 'section_text',
							'label' => esc_html__( 'Section Text', 'geroz-core' ),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__( '<ul><li>Feature 1</li><li>Feature 2</li><li>Feature 3</li></ul>', 'geroz-core' ),
						],
						[
							'name' => 'section_button',
							'label' => esc_html__( 'Section Button Text', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( 'Order Now', 'geroz-core' ),
						],
						[
							'name' => 'section_button_link',
							'label' => esc_html__( 'Section Button Link', 'geroz-core' ),
							'type' => Controls_Manager::URL,
						],
						[
							'name' => 'section_delivery',
							'label' => esc_html__( 'Delivery Time', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '3 Days Delivery', 'geroz-core'),
						],
						[
							'name' => 'section_revision',
							'label' => esc_html__( 'Revision', 'geroz-core'),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '2 Revisions', 'geroz-core'),
						],
						[
							'name' => 'section_subtitle2',
							'label' => esc_html__( 'Section Subtitle 2', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( 'Premium Plan', 'geroz-core' ),
						],
						[
							'name' => 'section_title2',
							'label' => esc_html__( 'Section Title 2', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '$199.00', 'geroz-core' ),
						],
						[
							'name' => 'section_text2',
							'label' => esc_html__( 'Section Text 2', 'geroz-core' ),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__( '<ul><li>Feature A</li><li>Feature B</li><li>Feature C</li></ul>', 'geroz-core' ),
						],
						[
							'name' => 'section_button2',
							'label' => esc_html__( 'Section Button Text 2', 'geroz-core' ),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( 'Order Now', 'geroz-core' ),
						],
						[
							'name' => 'section_button_link2',
							'label' => esc_html__( 'Section Button Link 2', 'geroz-core' ),
							'type' => Controls_Manager::URL,
						],
						[
							'name' => 'section_delivery2',
							'label' => esc_html__( 'Delivery Time 2', 'geroz-core'),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '5 Days Delivery', 'geroz-core'),
						],
						[
							'name' => 'section_revision2',
							'label' => esc_html__( 'Revision 2', 'geroz-core'),
							'type' => Controls_Manager::TEXT,
							'default' => esc_html__( '3 Revisions', 'geroz-core'),
						],
						
					],
				'title_field' => '{{section_title}}',
			 ]
	);
		
		
	$this->end_controls_section();	


			// ===== Tab Start - 4: Section Sub Title Settings =====

		$this->start_controls_section(
			'section_subtitle_settings',
			[
				'label' => __( 'Section Sub Title Setting', 'geroz-core' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'show_section_subtitle',
			[
				'label'   => esc_html__( 'Show Section Sub Title', 'geroz-core' ),
				'type'    => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => esc_html__( 'Show', 'geroz-core' ),
						'icon'  => 'eicon-check-circle',
					],
					'none' => [
						'title' => esc_html__( 'Hide', 'geroz-core' ),
						'icon'  => 'eicon-close-circle',
					],
				],
				'default'   => 'show',
				'selectors' => [
					'{{WRAPPER}} .section-title .sub-title span' => 'display: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'section_subtitle_alignment',
			[
				'label'     => esc_html__( 'Alignment', 'geroz-core' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => [
					'left' => [
						'title' => esc_html__( 'Left', 'geroz-core' ),
						'icon'  => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'geroz-core' ),
						'icon'  => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'geroz-core' ),
						'icon'  => 'eicon-text-align-right',
					],
				],
				'toggle'    => true,
				'condition' => [ 'show_section_subtitle' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .section-title .sub-title span' => 'text-align: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'section_subtitle_margin',
			[
				'label'      => __( 'Margin', 'geroz-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_section_subtitle' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .section-title .sub-title span' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_control(
			'section_subtitle_padding',
			[
				'label'      => __( 'Padding', 'geroz-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_section_subtitle' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .section-title .sub-title span' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name'      => 'section_subtitle_typography',
				'label'     => __( 'Typography', 'geroz-core' ),
				'selector'  => '{{WRAPPER}} .section-title .sub-title span',
				'condition' => [ 'show_section_subtitle' => 'show' ],
			]
		);

		$this->add_control(
			'section_subtitle_color',
			[
				'label'     => __( 'Color', 'geroz-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'separator' => 'after',
				'condition' => [ 'show_section_subtitle' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .section-title .sub-title span' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->end_controls_section();

		// ===== End Tab - 4: Section Sub Title Settings =====


				// Section Title ==================
		$this->start_controls_section(
			'section_title_settings',
			[
				'label' => __( 'Section Title Setting', 'geroz-core' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'show_section_title',
			[
				'label'   => esc_html__( 'Show Section Title', 'geroz-core' ),
				'type'    => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => esc_html__( 'Show', 'geroz-core' ),
						'icon'  => 'eicon-check-circle',
					],
					'none' => [
						'title' => esc_html__( 'Hide', 'geroz-core' ),
						'icon'  => 'eicon-close-circle',
					],
				],
				'default'   => 'show',
				'selectors' => [
					'{{WRAPPER}} .section-title h2' => 'display: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'section_title_alignment',
			[
				'label'     => esc_html__( 'Alignment', 'geroz-core' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => [
					'left' => [
						'title' => esc_html__( 'Left', 'geroz-core' ),
						'icon'  => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'geroz-core' ),
						'icon'  => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'geroz-core' ),
						'icon'  => 'eicon-text-align-right',
					],
				],
				'toggle'    => true,
				'condition' => [ 'show_section_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .section-title h2' => 'text-align: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'section_title_margin',
			[
				'label'      => __( 'Margin', 'geroz-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_section_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .section-title h2' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_control(
			'section_title_padding',
			[
				'label'      => __( 'Padding', 'geroz-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_section_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .section-title h2' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name'      => 'section_title_typography',
				'label'     => __( 'Typography', 'geroz-core' ),
				'selector'  => '{{WRAPPER}} .section-title h2',
				'condition' => [ 'show_section_title' => 'show' ],
			]
		);

		$this->add_control(
			'section_title_color',
			[
				'label'     => __( 'Color', 'geroz-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'condition' => [ 'show_section_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .section-title h2' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->end_controls_section();
		// End of Title ==================

	
		}

	/**
	 * 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');
		?>

			<section class="choose-us-wrapper choose-us-1 ">
                <div class="choose-arrow">
                    <svg width="221" height="231" viewBox="0 0 221 231" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path class="arrow-path"
                            d="M200.956 230.256C243.969 146.16 204.393 15.262 134.731 82.9955C91.2556 125.267 194.605 112.384 158.591 58.117C129.78 14.7032 47.3001 9.5528 9.66192 12.4046L33.6163 31.6248C23.3413 26.8738 2.57491 16.4044 1.70807 12.5339C0.841222 8.66335 24.2437 4.00447 36.0529 2.15841"
                            stroke="#D9D9D9" stroke-width="3" />
                    </svg>

                </div>
                <div class="shape">
					<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
						<img class="shape-1" src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
					<?php endif;?>
                </div>
                <div class="container">
                    <div class="section-title text-center pb-4">
                        <div class="sub-title">
                            <div class="dot"></div> <span><?php echo $settings['subtitle'];?></span>
                        </div>
                        <h2 class="tp-char-animation"><?php echo $settings['title'];?></h2>
                        <p class="text pt-4 mx-auto"><?php echo $settings['text'];?></p>
                    </div>
                    <div class="product-header mt-4 mt-md-0">
                        <ul class="nav">
                            <li class="nav-item wow fadeInUp" data-wow-delay=".2s">
                                <a href="<?php echo esc_attr($settings['id_name']);?>" data-bs-toggle="tab" class="nav-link">
                                    <?php echo $settings['tab_title'];?>
                                </a>
                            </li>
                            <li class="nav-item wow fadeInUp" data-wow-delay=".4s">
                                <a href="<?php echo esc_attr($settings['id_name2']);?>" data-bs-toggle="tab" class="nav-link">
                                    <?php echo $settings['tab_title2'];?>
                                </a>
                            </li>
                            <li class="nav-item wow fadeInUp" data-wow-delay=".5s">
                                <a href="<?php echo esc_attr($settings['id_name3']);?>" data-bs-toggle="tab" class="nav-link active">
                                    <?php echo $settings['tab_title3'];?>
                                </a>
                            </li>
                            <li class="nav-item wow fadeInUp" data-wow-delay=".s">
                                <a href="<?php echo esc_attr($settings['id_name4']);?>" data-bs-toggle="tab" class="nav-link">
                                    <?php echo $settings['tab_title4'];?>
                                </a>
                            </li>
                        </ul>
                    </div>

                    <div class="tab-content wow fadeInUp" data-wow-delay="400ms">
						<?php foreach($settings['repeat'] as $key=>$item):?>
                        <div id="<?php echo esc_attr($item['section_id']);?>" class="tab-pane fade price-1 <?php if($key == 1) echo 'show active';?>">
                            <div class="row">
                                <div class="col-xl-6 col-lg-6 col-md-12 ">
                                    <div class="single-pricing-item">
                                        <div class="icon">
                                            <i class="fal fa-cog"></i>
                                        </div>
                                        <div class="header">
                                            <h4><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></h4>
                                        </div>
                                        <div class="price"><?php echo wp_kses($item['section_title'], $allowed_tags);?></div>
                                        <div class="list">
                                            <?php echo wp_kses($item['section_text'], $allowed_tags);?>
                                        </div>
                                        <a href="<?php echo esc_url($item['section_button_link']['url']);?>" class="theme-btn"><span><?php echo wp_kses($item['section_button'], $allowed_tags);?></span></a>
                                        <div class="tag d-flex align-items-center pt-4">
                                            <span><i class="fal fa-clock"></i><?php echo wp_kses($item['section_delivery'], $allowed_tags);?></span>                                            |
                                            <span><?php echo wp_kses($item['section_revision'], $allowed_tags);?></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xl-6 col-lg-6 col-md-12 ">
                                    <div class="single-pricing-item">
                                        <div class="icon">
                                            <i class="flaticon-premium"></i>
                                        </div>
                                        <div class="header">
                                            <h4><?php echo wp_kses($item['section_subtitle2'], $allowed_tags);?></h4>
                                        </div>
                                        <div class="price"><?php echo wp_kses($item['section_title2'], $allowed_tags);?></div>
                                        <div class="list">
                                          <?php echo wp_kses($item['section_text2'], $allowed_tags);?>
                                        </div>
                                        <a href="<?php echo esc_url($item['section_button_link2']['url']);?>" class="theme-btn"><span><?php echo wp_kses($item['section_button2'], $allowed_tags);?></span></a>
                                        <div class="tag d-flex align-items-center pt-4">
                                            <span><i class="fal fa-clock"></i><?php echo wp_kses($item['section_delivery2'], $allowed_tags);?></span>                                            |
                                            <span><?php echo wp_kses($item['section_revision2'], $allowed_tags);?></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
						<?php endforeach; ?>
                    </div>
                </div>
            </section>

             
		<?php 
	}


}

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