<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Geroz
 * @since 1.0.0
 */ 
 
class Home4_Contact 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-home4-contact-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 4 Contact', '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(
			'home4-contact-content',
			[
				'label' => esc_html__( 'Contact Content', 'geroz-core' ),
			]
		);	

		$this->add_control(
			'subtitle',
			[
				'label' => esc_html__( 'Subtitle', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Contact Me', 'geroz-core' ),
			]
		);

		$this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Let’s Talk About Your Project', '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' ),
			]
		);

		$this->add_control(
			'subtitle2',
			[
				'label' => esc_html__( 'Subtitle 2', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Subtitle', 'geroz-core' ),
			]
		);	

		$this->add_control(
			'button',
			[
				'label' => esc_html__( 'Button Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Contact Me', 'geroz-core' ),
			]
		);

		$this->add_control(
			'button_link',
			[
				'label' => esc_html__( 'Button Link', 'geroz-core' ),
				'type' => Controls_Manager::URL,
				'default' => [
					'url' => '#',
				],
				'show_external' => true,
			]
		);

		$this->add_control(
			'form_text',
			[
				'label' => esc_html__( 'Form Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Contact Form', 'geroz-core' ),
			]
		);

		$this->add_control(
			'contact_form',
			[
				'label' => esc_html__( 'Contact Form 7 Shortcode', 'geroz-core' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => '[contact-form-7 id="123" title="Contact form 1"]',
				'description' => esc_html__( 'Enter the Contact Form 7 shortcode here.', 'geroz-core' ),
			]
		);

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

		$this->end_controls_section();


		$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' => 
					[	
						'section_icons'=> [
							'name' => 'section_icons',
							'label' => esc_html__('Enter The icons', 'geroz-core'),
							'type' => Controls_Manager::ICONS,							
						],

						'section_button_link'=> [
							'name' => 'section_button_link',
							'label' => esc_html__('Button Link', 'geroz-core'),
							'type' => Controls_Manager::URL,
							'default' => [
								'url' => '#',
							],
							'show_external' => true,
						],
						
					],
				'title_field' => '{{section_title}}',
			 ]
		);
			
			
		$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');
		?>

		<section class="contact-us-wrapper contact-us-1 style-3">
			<div class="container">
				<div class="row">
					<div class="col-xl-5 pe-xl-5">
						<div class="section-title">
							<div class="sub-title">
								<div class="dot"></div> <span><?php echo $settings['subtitle'];?></span>
							</div>
							<h2 class="tp-char-animation"><?php echo $settings['title'];?>

							<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
								<img class="hand-shape wow fadeInRight" data-wow-delay="1600ms" src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
							<?php endif;?>

							</h2>
						</div>
						<div class="info mt-4">
							<h4 class="has_text_reveal_anim"><?php echo $settings['subtitle2'];?></h4>
							<p class="has_text_move_anim"><?php echo $settings['text'];?></p>
						</div>
						<div class="social-icon has_fade_anim">
							<p>Follow Me</p>
							<?php foreach($settings['repeat'] as $item):?>	
								<a href="<?php echo esc_url($item['section_button_link']['url']);?>"><i class="<?php echo str_replace("icon ", " ", esc_attr( $item['section_icons']['value']));?>"></i></a>
							<?php endforeach; ?>
						</div>
					</div>
					<div class="col-xl-7">
						<div class="icons mb-xl-5 pb-5 d-flex justify-content-end align-items-end">
							<div class="arrow mt-5">
								<svg width="151" height="125" viewBox="0 0 151 125" fill="none"
									xmlns="http://www.w3.org/2000/svg">
									<path class="arrow-path"
										d="M6.09355 124.062C-11.6906 68.5966 25.4436 -7.08712 61.0748 41.0868C83.3115 71.1511 21.7135 52.9821 49.0381 23.5652C70.8979 0.0317053 121.596 5.14324 144.213 10.6409L127.721 19.9401C134.447 18.0766 148.126 13.7828 149.04 11.5146C149.953 9.24638 136.178 4.07241 129.177 1.76872"
										stroke="currentColor" stroke-opacity="0.13" stroke-width="3" />
								</svg>
							</div>
							<a href="<?php echo esc_url($settings['button_link']['url']);?>" class="circle">
								<div class="circle-icon"><i class="far fa-long-arrow-right"></i></div>
								<div class="circle-text">
									<p>
										<?php echo $settings['button'];?>
									</p>
								</div>
							</a>
						</div>
						<div class="contact-right ps-xl-5 mt-4 mt-md-0 has_fade_anim">
							<h3><?php echo $settings['form_text'];?></h3>
							<?php echo do_shortcode( $settings['contact_form'] );?>
						</div>
					</div>
				</div>
			</div>
		</section>

             
		<?php 
	}


}

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