<?php
/**
 * Custom Social Widget
 */

class Courier_Services_Social_Widget extends WP_Widget {
	
	function __construct() {
		parent::__construct(
			'Courier_Services_Social_Widget',
			__('VW Social Icon', 'courier-services'),
			array( 'description' => __( 'Widget for Social icons section', 'courier-services' ), ) 
		);
	}

	public function widget( $courier_services_args, $courier_services_instance ) { ?>
		<div class="widget">
			<?php
			$courier_services_title = isset( $courier_services_instance['title'] ) ? $courier_services_instance['title'] : '';
			$courier_services_facebook = isset( $courier_services_instance['facebook'] ) ? $courier_services_instance['facebook'] : '';
			$courier_services_instagram = isset( $courier_services_instance['instagram'] ) ? $courier_services_instance['instagram'] : '';
			$courier_services_twitter = isset( $courier_services_instance['twitter'] ) ? $courier_services_instance['twitter'] : '';
			$courier_services_linkedin = isset( $courier_services_instance['linkedin'] ) ? $courier_services_instance['linkedin'] : '';
			$courier_services_pinterest = isset( $courier_services_instance['pinterest'] ) ? $courier_services_instance['pinterest'] : '';
			$courier_services_tumblr = isset( $courier_services_instance['tumblr'] ) ? $courier_services_instance['tumblr'] : '';
			$courier_services_youtube = isset( $courier_services_instance['youtube'] ) ? $courier_services_instance['youtube'] : '';
			$courier_services_whatsapp = isset( $courier_services_instance['whatsapp'] ) ? $courier_services_instance['whatsapp'] : '';

	        echo '<div class="custom-social-icons">';

	        if(!empty($courier_services_title) ){ ?><h3 class="custom_title"><?php echo esc_html($courier_services_title); ?></h3><?php } ?>
	        <?php if(!empty($courier_services_facebook) ){ ?><p class="mb-0"><a class="custom_facebook fff" target= "_blank" href="<?php echo esc_url($courier_services_facebook); ?>"><i class="fab fa-facebook-f"></i><span class="screen-reader-text"><?php esc_html_e( 'Facebook','courier-services' );?></span></a></p><?php } ?>

	        <?php if(!empty($courier_services_twitter) ){ ?><p class="mb-0"><a class="custom_twitter" target= "_blank" href="<?php echo esc_url($courier_services_twitter); ?>"><i class="fab fa-twitter"></i><span class="screen-reader-text"><?php esc_html_e( 'Twitter','courier-services' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($courier_services_linkedin) ){ ?><p class="mb-0"><a class="custom_linkedin" target= "_blank" href="<?php echo esc_url($courier_services_linkedin); ?>"><i class="fab fa-linkedin-in"></i><span class="screen-reader-text"><?php esc_html_e( 'Linkedin','courier-services' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($courier_services_pinterest) ){ ?><p class="mb-0"><a class="custom_pinterest" target= "_blank" href="<?php echo esc_url($courier_services_pinterest); ?>"><i class="fab fa-pinterest-p"></i><span class="screen-reader-text"><?php esc_html_e( 'Pinterest','courier-services' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($courier_services_tumblr) ){ ?><p class="mb-0"><a class="custom_tumblr" target= "_blank" href="<?php echo esc_url($courier_services_tumblr); ?>"><i class="fab fa-tumblr"></i><span class="screen-reader-text"><?php esc_html_e( 'Tumblr','courier-services' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($courier_services_instagram) ){ ?><p class="mb-0"><a class="custom_instagram" target= "_blank" href="<?php echo esc_url($courier_services_instagram); ?>"><i class="fab fa-instagram"></i><span class="screen-reader-text"><?php esc_html_e( 'Instagram','courier-services' );?></span></a></p><?php } ?>
	        

	        <?php if(!empty($courier_services_youtube) ){ ?><p class="mb-0"><a class="custom_youtube" target= "_blank" href="<?php echo esc_url($courier_services_youtube); ?>"><i class="fab fa-youtube"></i><span class="screen-reader-text"><?php esc_html_e( 'Youtube','courier-services' );?></span></a></p><?php } ?>

	        <?php if(!empty($courier_services_whatsapp) ){ ?><p class="mb-0"><a class="custom_whatsapp" target= "_blank" href="<?php echo esc_url($courier_services_whatsapp); ?>"><i class="fa-brands fa-whatsapp"></i><span class="screen-reader-text"><?php esc_html_e( 'Whatsapp','courier-services' );?></span></a></p><?php } ?>

	        <?php echo '</div>';
			?>
		</div>
		<?php
	}
	
	// Widget Backend 
	public function form( $courier_services_instance ) {

		$courier_services_title= ''; $courier_services_facebook = ''; $courier_services_twitter = ''; $courier_services_linkedin = '';  $courier_services_pinterest = '';$courier_services_tumblr = ''; $courier_services_instagram = ''; $courier_services_youtube = ''; 

		$courier_services_title = isset( $courier_services_instance['title'] ) ? $courier_services_instance['title'] : '';
		$courier_services_facebook = isset( $courier_services_instance['facebook'] ) ? $courier_services_instance['facebook'] : '';
		$courier_services_instagram = isset( $courier_services_instance['instagram'] ) ? $courier_services_instance['instagram'] : '';
		$courier_services_twitter = isset( $courier_services_instance['twitter'] ) ? $courier_services_instance['twitter'] : '';
		$courier_services_linkedin = isset( $courier_services_instance['linkedin'] ) ? $courier_services_instance['linkedin'] : '';
		$courier_services_pinterest = isset( $courier_services_instance['pinterest'] ) ? $courier_services_instance['pinterest'] : '';
		$courier_services_tumblr = isset( $courier_services_instance['tumblr'] ) ? $courier_services_instance['tumblr'] : '';
		$courier_services_youtube = isset( $courier_services_instance['youtube'] ) ? $courier_services_instance['youtube'] : '';
		$courier_services_whatsapp = isset( $courier_services_instance['whatsapp'] ) ? $courier_services_instance['whatsapp'] : '';
		?>
		<p>
        <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','courier-services'); ?></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($courier_services_title); ?>">
    	</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('facebook')); ?>"><?php esc_html_e('Facebook:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('facebook')); ?>" name="<?php echo esc_attr($this->get_field_name('facebook')); ?>" type="text" value="<?php echo esc_attr($courier_services_facebook); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('twitter')); ?>"><?php esc_html_e('Twitter:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('twitter')); ?>" name="<?php echo esc_attr($this->get_field_name('twitter')); ?>" type="text" value="<?php echo esc_attr($courier_services_twitter); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('linkedin')); ?>"><?php esc_html_e('Linkedin:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('linkedin')); ?>" name="<?php echo esc_attr($this->get_field_name('linkedin')); ?>" type="text" value="<?php echo esc_attr($courier_services_linkedin); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('instagram')); ?>"><?php esc_html_e('Instagram:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('instagram')); ?>" name="<?php echo esc_attr($this->get_field_name('instagram')); ?>" type="text" value="<?php echo esc_attr($courier_services_instagram); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('pinterest')); ?>"><?php esc_html_e('Pinterest:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('pinterest')); ?>" name="<?php echo esc_attr($this->get_field_name('pinterest')); ?>" type="text" value="<?php echo esc_attr($courier_services_pinterest); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('tumblr')); ?>"><?php esc_html_e('Tumblr:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('tumblr')); ?>" name="<?php echo esc_attr($this->get_field_name('tumblr')); ?>" type="text" value="<?php echo esc_attr($courier_services_tumblr); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('youtube')); ?>"><?php esc_html_e('Youtube:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('youtube')); ?>" name="<?php echo esc_attr($this->get_field_name('youtube')); ?>" type="text" value="<?php echo esc_attr($courier_services_youtube); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('whatsapp')); ?>"><?php esc_html_e('Whatsapp:','courier-services'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('whatsapp')); ?>" name="<?php echo esc_attr($this->get_field_name('whatsapp')); ?>" type="text" value="<?php echo esc_attr($courier_services_whatsapp); ?>">
		</p>
		<?php 
	}
	
	public function update( $courier_services_new_instance, $courier_services_old_instance ) {
		$courier_services_instance = array();
		$courier_services_instance['title'] = (!empty($courier_services_new_instance['title']) ) ? strip_tags($courier_services_new_instance['title']) : '';	
        $courier_services_instance['facebook'] = (!empty($courier_services_new_instance['facebook']) ) ? esc_url_raw($courier_services_new_instance['facebook']) : '';
        $courier_services_instance['twitter'] = (!empty($courier_services_new_instance['twitter']) ) ? esc_url_raw($courier_services_new_instance['twitter']) : '';
        $courier_services_instance['instagram'] = (!empty($courier_services_new_instance['instagram']) ) ? esc_url_raw($courier_services_new_instance['instagram']) : '';
        $courier_services_instance['linkedin'] = (!empty($courier_services_new_instance['linkedin']) ) ? esc_url_raw($courier_services_new_instance['linkedin']) : '';
        $courier_services_instance['pinterest'] = (!empty($courier_services_new_instance['pinterest']) ) ? esc_url_raw($courier_services_new_instance['pinterest']) : '';
        $courier_services_instance['tumblr'] = (!empty($courier_services_new_instance['tumblr']) ) ? esc_url_raw($courier_services_new_instance['tumblr']) : '';
     	$courier_services_instance['youtube'] = (!empty($courier_services_new_instance['youtube']) ) ? esc_url_raw($courier_services_new_instance['youtube']) : '';
     	$courier_services_instance['whatsapp'] = (!empty($courier_services_new_instance['whatsapp']) ) ? esc_url_raw($courier_services_new_instance['whatsapp']) : '';
     	
		return $courier_services_instance;
	}
}

function courier_services_custom_load_widget() {
	register_widget( 'Courier_Services_Social_Widget' );
}
add_action( 'widgets_init', 'courier_services_custom_load_widget' );