<?php

/**
 * Single Service Icon Widget
 */


if( ! class_exists('Somalite_Single_Service_Widget')) :
class Somalite_Single_Service_Widget extends WP_Widget {
	var $defaults;
	/**
	 * Register widget with WordPress.
	 */
	function __construct() {
		parent::__construct(
			'sm_single_service_widget', // Base ID
			esc_html__( 'Soma: Single Service Icon Widget', 'somalite' ), // Name
			array( 'description' => esc_html__( 'Adds Single Service Icon', 'somalite' ),
			'panels_groups' => array('soma') ) // Args
		);	        
	}

	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget()
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
		extract( $args );
		extract( wp_parse_args( $instance, $this->defaults ) ); 

		$ins_icon = esc_html($instance['icon']);
		$ins_heading = esc_html($instance['heading']);
		$ins_content = esc_html($instance['content']);

		$icon = ! empty( $ins_icon ) ? $ins_icon : '';
        $heading = ! empty( $ins_heading ) ? $ins_heading : '';
        $content = ! empty( $ins_content ) ? $ins_content : '';      		

		?>
		<div class="service-wrapper wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.5s">
			<div class="pb-content">
				<div class="service center">
				    <div class="icon">
				    	<span class="<?php echo $icon; ?> hvr-ripple-out"></span>
				    </div>
		            <div class="content">
		                <div class="heading">
		                    <h4><?php echo $heading; ?></h4>
		                </div>
		                <div class="descr">
		                    <p><?php echo $content; ?></p>
		                </div>
		            </div>
		        </div>
		    </div>
		</div>
       <?php
    }
	
	/**
	 * Back-end widget form.
	 *
	 * @see WP_Widget::form()
	 *
	 * @param array $instance Previously saved values from database.
	 */
	public function form( $instance ) {
	$icon = ! empty( $instance['icon'] ) ? esc_html($instance['icon']) : '';
    $heading = ! empty( $instance['heading'] ) ? esc_html($instance['heading']) : '';
    $content = ! empty( $instance['content'] ) ? esc_html($instance['content']) : '';      		
    ?>  
    

		<p>
	        <label for="<?php echo esc_attr($this->get_field_id('icon')); ?>"><?php esc_html_e('Icon name: For eg For Linear icons use <b>lnr lnr-layers</b> and For Font Awesome use <b>fab fa-facebook</b> ','somalite'); ?></label>
	        <input class="widefat" id="<?php echo esc_attr($this->get_field_id('icon')); ?>" name="<?php echo esc_attr($this->get_field_name('icon')); ?>" type="text" value="<?php echo esc_html($icon); ?>" />
	    </p>    	
        <p>
	        <label for="<?php echo esc_attr($this->get_field_id('heading')); ?>"><?php esc_html_e('Heading:','somalite'); ?></label>
	        <input class="widefat" id="<?php echo esc_attr($this->get_field_id('heading')); ?>" name="<?php echo esc_attr($this->get_field_name('heading')); ?>" type="text" value="<?php echo esc_html($heading); ?>" />
	    </p>
		<p>
	        <label for="<?php echo esc_attr($this->get_field_id('content')); ?>"><?php esc_html_e('Content:','somalite'); ?></label>
	        <input class="widefat" id="<?php echo esc_attr($this->get_field_id('content')); ?>" name="<?php echo esc_attr($this->get_field_name('content')); ?>" type="text" value="<?php echo esc_html($content); ?>" />	        
	    </p>	    
       
    <?php
	}

	/**
	 * Sanitize widget form values as they are saved.
	 *
	 * @see WP_Widget::update()
	 *
	 * @param array $new_instance Values just sent to be saved.
	 * @param array $old_instance Previously saved values from database.
	 *
	 * @return array Updated safe values to be saved.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 'icon'] = esc_html( $new_instance['icon'] );
		$instance[ 'heading'] = esc_html( $new_instance['heading'] );
        $instance[ 'content'] = esc_html( $new_instance['content'] );      	
    	return $instance;
	}

}
endif;



if( ! function_exists('register_somalite_single_service_widget')) :
// register widget
function register_somalite_single_service_widget() {
    register_widget( 'Somalite_Single_Service_Widget' );
}
endif;

add_action( 'widgets_init', 'register_somalite_single_service_widget' );
