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

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

	public function widget( $virtual_assistant_args, $virtual_assistant_instance ) { ?>
		<div class="widget">
			<?php
			$virtual_assistant_title = isset( $virtual_assistant_instance['title'] ) ? $virtual_assistant_instance['title'] : '';
			$virtual_assistant_facebook = isset( $virtual_assistant_instance['facebook'] ) ? $virtual_assistant_instance['facebook'] : '';
			$virtual_assistant_twitter = isset( $virtual_assistant_instance['twitter'] ) ? $virtual_assistant_instance['twitter'] : '';
			$virtual_assistant_instagram = isset( $virtual_assistant_instance['instagram'] ) ? $virtual_assistant_instance['instagram'] : '';
			$virtual_assistant_youtube = isset( $virtual_assistant_instance['youtube'] ) ? $virtual_assistant_instance['youtube'] : '';
			$virtual_assistant_dribbal = isset( $virtual_assistant_instance['dribbal'] ) ? $virtual_assistant_instance['dribbal'] : '';
			$virtual_assistant_linkedin = isset( $virtual_assistant_instance['linkedin'] ) ? $virtual_assistant_instance['linkedin'] : '';
			$virtual_assistant_pinterest = isset( $virtual_assistant_instance['pinterest'] ) ? $virtual_assistant_instance['pinterest'] : '';
			$virtual_assistant_tumblr = isset( $virtual_assistant_instance['tumblr'] ) ? $virtual_assistant_instance['tumblr'] : '';
			

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

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

	        <?php if(!empty($virtual_assistant_twitter) ){ ?><p class="mb-0"><a class="custom_twitter" target= "_blank" href="<?php echo esc_url($virtual_assistant_twitter); ?>"><i class="fa-brands fa-x-twitter"></i><span class="screen-reader-text"><?php esc_html_e( 'Twitter','virtual-assistant' );?></span></a></p><?php } ?>
	        
	        <?php if(!empty($virtual_assistant_instagram) ){ ?><p class="mb-0"><a class="custom_instagram" target= "_blank" href="<?php echo esc_url($virtual_assistant_instagram); ?>"><i class="fab fa-instagram"></i><span class="screen-reader-text"><?php esc_html_e( 'Instagram','virtual-assistant' );?></span></a></p><?php } ?>

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

	        <?php if(!empty($virtual_assistant_dribbal) ){ ?><p class="mb-0"><a class="custom_dribbal" target= "_blank" href="<?php echo esc_url($virtual_assistant_dribbal); ?>"><i class="fa-solid fa-basketball"></i><span class="screen-reader-text"><?php esc_html_e( 'Dribbal','virtual-assistant' );?></span></a></p><?php } ?>

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

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

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

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

		$virtual_assistant_title= ''; $virtual_assistant_facebook = ''; $virtual_assistant_twitter = ''; $virtual_assistant_linkedin = '';  $virtual_assistant_pinterest = '';$virtual_assistant_tumblr = ''; $virtual_assistant_instagram = ''; $virtual_assistant_youtube = ''; 

		$virtual_assistant_title = isset( $virtual_assistant_instance['title'] ) ? $virtual_assistant_instance['title'] : '';
		$virtual_assistant_facebook = isset( $virtual_assistant_instance['facebook'] ) ? $virtual_assistant_instance['facebook'] : '';
		$virtual_assistant_instagram = isset( $virtual_assistant_instance['instagram'] ) ? $virtual_assistant_instance['instagram'] : '';
		$virtual_assistant_twitter = isset( $virtual_assistant_instance['twitter'] ) ? $virtual_assistant_instance['twitter'] : '';
		$virtual_assistant_youtube = isset( $virtual_assistant_instance['youtube'] ) ? $virtual_assistant_instance['youtube'] : '';
		$virtual_assistant_dribbal = isset( $virtual_assistant_instance['dribbal'] ) ? $virtual_assistant_instance['dribbal'] : '';
		$virtual_assistant_linkedin = isset( $virtual_assistant_instance['linkedin'] ) ? $virtual_assistant_instance['linkedin'] : '';
		$virtual_assistant_pinterest = isset( $virtual_assistant_instance['pinterest'] ) ? $virtual_assistant_instance['pinterest'] : '';
		$virtual_assistant_tumblr = isset( $virtual_assistant_instance['tumblr'] ) ? $virtual_assistant_instance['tumblr'] : '';
		
		?>
		<p>
        <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','virtual-assistant'); ?></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($virtual_assistant_title); ?>">
    	</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('facebook')); ?>"><?php esc_html_e('Facebook:','virtual-assistant'); ?></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($virtual_assistant_facebook); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('twitter')); ?>"><?php esc_html_e('Twitter:','virtual-assistant'); ?></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($virtual_assistant_twitter); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('instagram')); ?>"><?php esc_html_e('Instagram:','virtual-assistant'); ?></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($virtual_assistant_instagram); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('youtube')); ?>"><?php esc_html_e('Youtube:','virtual-assistant'); ?></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($virtual_assistant_youtube); ?>">
		</p>
		<label for="<?php echo esc_attr($this->get_field_id('dribbal')); ?>"><?php esc_html_e('Dribbal:','virtual-assistant'); ?></label>
		<input class="widefat" id="<?php echo esc_attr($this->get_field_id('dribbal')); ?>" name="<?php echo esc_attr($this->get_field_name('dribbal')); ?>" type="text" value="<?php echo esc_attr($virtual_assistant_dribbal); ?>">
		</p>

		<label for="<?php echo esc_attr($this->get_field_id('linkedin')); ?>"><?php esc_html_e('Linkedin:','virtual-assistant'); ?></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($virtual_assistant_linkedin); ?>">
		</p>
		<p>
		
		<label for="<?php echo esc_attr($this->get_field_id('pinterest')); ?>"><?php esc_html_e('Pinterest:','virtual-assistant'); ?></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($virtual_assistant_pinterest); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('tumblr')); ?>"><?php esc_html_e('Tumblr:','virtual-assistant'); ?></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($virtual_assistant_tumblr); ?>">
		</p>
		<p>
		
		<?php 
	}
	
	public function update( $virtual_assistant_new_instance, $virtual_assistant_old_instance ) {
		$virtual_assistant_instance = array();
		$virtual_assistant_instance['title'] = (!empty($virtual_assistant_new_instance['title']) ) ? strip_tags($virtual_assistant_new_instance['title']) : '';	
        $virtual_assistant_instance['facebook'] = (!empty($virtual_assistant_new_instance['facebook']) ) ? esc_url_raw($virtual_assistant_new_instance['facebook']) : '';
        $virtual_assistant_instance['twitter'] = (!empty($virtual_assistant_new_instance['twitter']) ) ? esc_url_raw($virtual_assistant_new_instance['twitter']) : '';
        $virtual_assistant_instance['instagram'] = (!empty($virtual_assistant_new_instance['instagram']) ) ? esc_url_raw($virtual_assistant_new_instance['instagram']) : '';
        $virtual_assistant_instance['youtube'] = (!empty($virtual_assistant_new_instance['youtube']) ) ? esc_url_raw($virtual_assistant_new_instance['youtube']) : '';
        $virtual_assistant_instance['dribbal'] = (!empty($virtual_assistant_new_instance['dribbal']) ) ? esc_url_raw($virtual_assistant_new_instance['dribbal']) : '';
        $virtual_assistant_instance['linkedin'] = (!empty($virtual_assistant_new_instance['linkedin']) ) ? esc_url_raw($virtual_assistant_new_instance['linkedin']) : '';
        $virtual_assistant_instance['pinterest'] = (!empty($virtual_assistant_new_instance['pinterest']) ) ? esc_url_raw($virtual_assistant_new_instance['pinterest']) : '';
        $virtual_assistant_instance['tumblr'] = (!empty($virtual_assistant_new_instance['tumblr']) ) ? esc_url_raw($virtual_assistant_new_instance['tumblr']) : '';
     	
     	
		return $virtual_assistant_instance;
	}
}

function virtual_assistant_custom_load_widget() {
	register_widget( 'Virtual_Assistant_Social_Widget' );
}
add_action( 'widgets_init', 'virtual_assistant_custom_load_widget' );