<?php
/**
 * Custom Contact us Widget
 */

class Immigration_Consulting_Contact_Widget extends WP_Widget {
	function __construct() {
		parent::__construct(
			'Immigration_Consulting_Contact_Widget', 
			__('VW Contact us', 'immigration-consulting'),
			array( 'description' => __( 'Widget for contact us section in sidebar', 'immigration-consulting' ), ) 
		);
	}
	
	public function widget( $immigration_consulting_args, $immigration_consulting_instance ) {
		?>
		<aside class="widget">
			<?php
			$immigration_consulting_title = isset( $immigration_consulting_instance['title'] ) ? $immigration_consulting_instance['title'] : '';
			$immigration_consulting_phone = isset( $immigration_consulting_instance['phone'] ) ? $immigration_consulting_instance['phone'] : '';
			$immigration_consulting_email = isset( $immigration_consulting_instance['email'] ) ? $immigration_consulting_instance['email'] : '';
			$immigration_consulting_address = isset( $immigration_consulting_instance['address'] ) ? $immigration_consulting_instance['address'] : '';
			$immigration_consulting_timing = isset( $immigration_consulting_instance['timing'] ) ? $immigration_consulting_instance['timing'] : '';
			$immigration_consulting_longitude = isset( $immigration_consulting_instance['longitude'] ) ? $immigration_consulting_instance['longitude'] : '';
			$immigration_consulting_latitude = isset( $immigration_consulting_instance['latitude'] ) ? $immigration_consulting_instance['latitude'] : '';
			$immigration_consulting_contact_form = isset( $immigration_consulting_instance['contact_form'] ) ? $immigration_consulting_instance['contact_form'] : '';

	        echo '<div class="custom-contact-us">';
	        if(!empty($immigration_consulting_title) ){ ?><h3 class="custom_title1"><?php echo esc_html($immigration_consulting_title); ?></h3><?php } ?>
		        <?php if(!empty($immigration_consulting_phone) ){ ?>
		        	<div class="row contact-detail">
		        		<div class="col-lg-2 col-md-2 align-self-center">
		        			<span class="custom_details"><i class="fa-solid fa-phone-volume me-2"></i></span>
		        		</div>
		        		<div class="col-lg-10 col-md-10 align-self-center">
		        			<span class="contact-title"><?php echo esc_html('Contact', 'immigration-consulting'); ?></span><span class="custom_desc"><?php echo esc_html($immigration_consulting_phone); ?></span>
		        		</div>		        		
		        	</div>
		        <?php } ?>
		        <?php if(!empty($immigration_consulting_email) ){ ?>
		        	<div class="row contact-detail">
		        		<div class="col-lg-2 col-md-2 align-self-center">
		        			<span class="custom_details"><i class="fa-regular fa-envelope me-2"></i></span>
		        		</div>
		        		<div class="col-lg-10 col-md-10 align-self-center">
		        			<span class="contact-title"><?php echo esc_html('Mail Address', 'immigration-consulting'); ?></span><span class="custom_desc"><?php echo esc_html($immigration_consulting_email); ?></span>
		        		</div>
		        	</div>
		        <?php } ?>
		        <?php if(!empty($immigration_consulting_address) ){ ?>
		        	<div class="row contact-detail">
		        		<div class="col-lg-2 col-md-2 align-self-center">
		        			<span class="custom_details"><i class="fa-solid fa-location-dot me-2"></i></span>
		        		</div>
			        	<div class="col-lg-10 col-md-10 align-self-center">
			        		<span class="contact-title"><?php echo esc_html('Location', 'immigration-consulting'); ?></span><span class="custom_desc"><?php echo esc_html($immigration_consulting_address); ?></span>
			        	</div>
			        </div>
			    <?php } ?> 
		        <?php if(!empty($immigration_consulting_timing) ){ ?><p><span class="custom_details"><?php esc_html_e('Opening Time: ','immigration-consulting'); ?></span><span class="custom_desc"><?php echo esc_html($immigration_consulting_timing); ?></span></p><?php } ?>
		        <?php if(!empty($immigration_consulting_longitude) ){ ?><embed width="100%" height="200px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=<?php echo esc_html($immigration_consulting_longitude); ?>,<?php echo esc_html($immigration_consulting_latitude); ?>&hl=es;z=14&amp;output=embed"></embed><?php } ?>
		        <?php if(!empty($immigration_consulting_contact_form) ){ ?><?php echo do_shortcode($immigration_consulting_contact_form); ?><?php } ?>
	        <?php echo '</div>';
			?>
		</aside>
		<?php
	}
	
	// Widget Backend 
	public function form( $immigration_consulting_instance ) {

		$immigration_consulting_title= ''; $immigration_consulting_phone= ''; $immigration_consulting_email = ''; $immigration_consulting_address = ''; $immigration_consulting_timing = ''; $immigration_consulting_longitude = ''; $immigration_consulting_latitude = ''; $immigration_consulting_contact_form = ''; 
		
		$immigration_consulting_title = isset( $immigration_consulting_instance['title'] ) ? $immigration_consulting_instance['title'] : '';
		$immigration_consulting_phone = isset( $immigration_consulting_instance['phone'] ) ? $immigration_consulting_instance['phone'] : '';
		$immigration_consulting_email = isset( $immigration_consulting_instance['email'] ) ? $immigration_consulting_instance['email'] : '';
		$immigration_consulting_address = isset( $immigration_consulting_instance['address'] ) ? $immigration_consulting_instance['address'] : '';
		$immigration_consulting_timing = isset( $immigration_consulting_instance['timing'] ) ? $immigration_consulting_instance['timing'] : '';
		$immigration_consulting_longitude = isset( $immigration_consulting_instance['longitude'] ) ? $immigration_consulting_instance['longitude'] : '';
		$immigration_consulting_latitude = isset( $immigration_consulting_instance['latitude'] ) ? $immigration_consulting_instance['latitude'] : '';
		$immigration_consulting_contact_form = isset( $immigration_consulting_instance['contact_form'] ) ? $immigration_consulting_instance['contact_form'] : '';
		
		?>

		<p>
        	<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_title); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('phone')); ?>"><?php esc_html_e('Phone Number:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('phone')); ?>" name="<?php echo esc_attr($this->get_field_name('phone')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_phone); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('email')); ?>"><?php esc_html_e('Email id:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('email')); ?>" name="<?php echo esc_attr($this->get_field_name('email')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_email); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('address')); ?>"><?php esc_html_e('Address:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('address')); ?>" name="<?php echo esc_attr($this->get_field_name('address')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_address); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('timing')); ?>"><?php esc_html_e('Opening Time:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('timing')); ?>" name="<?php echo esc_attr($this->get_field_name('timing')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_timing); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('longitude')); ?>"><?php esc_html_e('Longitude:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('longitude')); ?>" name="<?php echo esc_attr($this->get_field_name('longitude')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_longitude); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('latitude')); ?>"><?php esc_html_e('Latitude:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('latitude')); ?>" name="<?php echo esc_attr($this->get_field_name('latitude')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_latitude); ?>">
    	</p>
    	<p>
        	<label for="<?php echo esc_attr($this->get_field_id('contact_form')); ?>"><?php esc_html_e('Contact Form Shortcode:','immigration-consulting'); ?></label>
        	<input class="widefat" id="<?php echo esc_attr($this->get_field_id('contact_form')); ?>" name="<?php echo esc_attr($this->get_field_name('contact_form')); ?>" type="text" value="<?php echo esc_attr($immigration_consulting_contact_form); ?>">
    	</p>
		
		<?php 
	}
	
	// Updating widget replacing old instances with new
	public function update( $immigration_consulting_new_instance, $immigration_consulting_old_instance ) {
		$immigration_consulting_instance = array();	
		$immigration_consulting_instance['title'] = (!empty($immigration_consulting_new_instance['title']) ) ? strip_tags($immigration_consulting_new_instance['title']) : '';
		$immigration_consulting_instance['phone'] = (!empty($immigration_consulting_new_instance['phone']) ) ? immigration_consulting_sanitize_phone_number($immigration_consulting_new_instance['phone']) : '';
		$immigration_consulting_instance['email'] = (!empty($immigration_consulting_new_instance['email']) ) ? sanitize_email($immigration_consulting_new_instance['email']) : '';
		$immigration_consulting_instance['address'] = (!empty($immigration_consulting_new_instance['address']) ) ? strip_tags($immigration_consulting_new_instance['address']) : '';
		$immigration_consulting_instance['timing'] = (!empty($immigration_consulting_new_instance['timing']) ) ? strip_tags($immigration_consulting_new_instance['timing']) : '';
		$immigration_consulting_instance['longitude'] = (!empty($immigration_consulting_new_instance['longitude']) ) ? strip_tags($immigration_consulting_new_instance['longitude']) : '';
		$immigration_consulting_instance['latitude'] = (!empty($immigration_consulting_new_instance['latitude']) ) ? strip_tags($immigration_consulting_new_instance['latitude']) : '';
		$immigration_consulting_instance['contact_form'] = (!empty($immigration_consulting_new_instance['contact_form']) ) ? strip_tags($immigration_consulting_new_instance['contact_form']) : '';
        
		return $immigration_consulting_instance;
	}
}
// Register and load the widget
function immigration_consulting_contact_custom_load_widget() {
	register_widget( 'Immigration_Consulting_Contact_Widget' );
}
add_action( 'widgets_init', 'immigration_consulting_contact_custom_load_widget' );