<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Geroz
 * @since 1.0.0
 */ 
 
class Home4_Services 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-services-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 Services', '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-services-content',
			[
				'label' => esc_html__( 'Services 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(
			'image2',
			[
				'label' => esc_html__( 'Image 2', 'geroz-core' ),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => Utils::get_placeholder_image_src(),
				],
			]
		);

		$this->add_control(
			'text',
			[
				'label' => esc_html__( 'Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Award Winning', 'geroz-core' ),
			]
		);

		$this->add_control(
			'review_text',
			[
				'label' => esc_html__( 'Review Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( '5 Star Rating', 'geroz-core' ),
			]
		);

		$this->add_control(
			'review',
			[
				'label' => esc_html__( 'Review', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( '5.0', 'geroz-core' ),
			]
		);

		$this->add_control(
			'clients_text',
			[
				'label' => esc_html__( 'Clients Text', 'geroz-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( '1000+ Happy Clients', 'geroz-core' ),
			]
		);


		$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_subtitle' => [
							'name' => 'section_subtitle',
							'label' => esc_html__('Subtitle', 'geroz-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('Subtitle', 'geroz-core'),
						],

						'section_title' => [
							'name' => 'section_title',
							'label' => esc_html__('Title', 'geroz-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('Title', 'geroz-core'),
						],

						'section_button_link' => [
							'name' => 'section_button_link',
							'label' => esc_html__('Button Link', 'geroz-core'),
							'type' => Controls_Manager::URL,
							'default' => [
								'url' => '#',
								'is_external' => '',
								'nofollow' => '',
							],
						],
						
					],
				'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="service-wrapper service-3">
			<div class="service-inner">
				<div class="award">
					<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
						<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
					<?php endif;?>
					<p class="text"><?php echo $settings['text'];?></p>
					<div class="icon d-flex align-items-center">
						<i class="fas fa-star"></i>
						<span><?php echo $settings['review_text'];?></span>
					</div>
					<div class="rating">
						<div class="star">
							<?php echo $settings['review'];?>
							<span> <i class="fas fa-star"></i></span>
							<span> <i class="fas fa-star"></i></span>
							<span> <i class="fas fa-star"></i></span>
							<span> <i class="fas fa-star"></i></span>
							<span> <i class="fas fa-star"></i></span>
						</div>
						<p><?php echo $settings['clients_text'];?></p>
					</div>

				</div>
				<div class="container-fluid">
					<div class="row">
						<div class="col-xl-6 col-lg-12 d-xl-block d-none">
							<div class="image wow fadeInLeft" data-wow-delay="400ms">
							<?php  if ( !empty(esc_url($settings['image2']['id']) )) : ?>   
								<img src="<?php echo wp_get_attachment_url($settings['image2']['id']);?>" alt=""/>
							<?php endif;?>
							</div>
						</div>
						<div class="col-xl-6 col-lg-12">
							<div class="content">
								
								<div class="service-item-grid">
								<?php foreach($settings['repeat'] as $item):?>	
									<div class="single-service-item wow fadeInUp" data-wow-delay="200ms">
										<div class="icons d-flex align-items-center justify-content-between">
											<span><i class="<?php echo str_replace("icon ", " ", esc_attr( $item['section_icons']['value']));?>"></i></span>
											<a href="<?php echo esc_url($item['section_button_link']['url']);?>"><i class="far fa-arrow-right"></i></a>
										</div>
										<div class="title">
											<p><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></p>
											<h4><?php echo wp_kses($item['section_title'], $allowed_tags);?></h4>
										</div>
									</div>		
									<?php endforeach; ?>
								</div>
								
							</div> 
						</div>
						<div class="col-xl-6 col-lg-12 d-xl-none">
							<div class="image wow fadeInLeft" data-wow-delay="400ms">
								<?php  if ( !empty(esc_url($settings['image2']['id']) )) : ?>   
								<img src="<?php echo wp_get_attachment_url($settings['image2']['id']);?>" alt=""/>
								<?php endif;?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</section>

             
		<?php 
	}


}

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