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

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

	public function widget( $summer_camp_args, $summer_camp_instance ) { ?>
		<div class="widget">
			<?php
			$summer_camp_title = isset( $summer_camp_instance['title'] ) ? $summer_camp_instance['title'] : '';
			$summer_camp_facebook = isset( $summer_camp_instance['facebook'] ) ? $summer_camp_instance['facebook'] : '';
			$summer_camp_instagram = isset( $summer_camp_instance['instagram'] ) ? $summer_camp_instance['instagram'] : '';
			$summer_camp_twitter = isset( $summer_camp_instance['twitter'] ) ? $summer_camp_instance['twitter'] : '';
			$summer_camp_linkedin = isset( $summer_camp_instance['linkedin'] ) ? $summer_camp_instance['linkedin'] : '';
			$summer_camp_pinterest = isset( $summer_camp_instance['pinterest'] ) ? $summer_camp_instance['pinterest'] : '';
			$summer_camp_tumblr = isset( $summer_camp_instance['tumblr'] ) ? $summer_camp_instance['tumblr'] : '';
			$summer_camp_youtube = isset( $summer_camp_instance['youtube'] ) ? $summer_camp_instance['youtube'] : '';

	        echo '<div class="custom-social-icons">';
	        if(!empty($summer_camp_title) ){ ?><h3 class="custom_title"><?php echo esc_html($summer_camp_title); ?></h3><?php } ?>
	        <?php if(!empty($summer_camp_facebook) ){ ?><p class="mb-0"><a class="custom_facebook fff" target= "_blank" href="<?php echo esc_url($summer_camp_facebook); ?>"><i class="fab fa-facebook-f"></i><span class="screen-reader-text"><?php esc_html_e( 'Facebook','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_twitter) ){ ?><p class="mb-0"><a class="custom_twitter" target= "_blank" href="<?php echo esc_url($summer_camp_twitter); ?>"><i class="fab fa-twitter"></i><span class="screen-reader-text"><?php esc_html_e( 'Twitter','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_linkedin) ){ ?><p class="mb-0"><a class="custom_linkedin" target= "_blank" href="<?php echo esc_url($summer_camp_linkedin); ?>"><i class="fab fa-linkedin-in"></i><span class="screen-reader-text"><?php esc_html_e( 'Linkedin','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_pinterest) ){ ?><p class="mb-0"><a class="custom_pinterest" target= "_blank" href="<?php echo esc_url($summer_camp_pinterest); ?>"><i class="fab fa-pinterest-p"></i><span class="screen-reader-text"><?php esc_html_e( 'Pinterest','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_tumblr) ){ ?><p class="mb-0"><a class="custom_tumblr" target= "_blank" href="<?php echo esc_url($summer_camp_tumblr); ?>"><i class="fab fa-tumblr"></i><span class="screen-reader-text"><?php esc_html_e( 'Tumblr','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_instagram) ){ ?><p class="mb-0"><a class="custom_instagram" target= "_blank" href="<?php echo esc_url($summer_camp_instagram); ?>"><i class="fab fa-instagram"></i><span class="screen-reader-text"><?php esc_html_e( 'Instagram','summer-camp' );?></span></a></p><?php } ?>
	        <?php if(!empty($summer_camp_youtube) ){ ?><p class="mb-0"><a class="custom_youtube" target= "_blank" href="<?php echo esc_url($summer_camp_youtube); ?>"><i class="fab fa-youtube"></i><span class="screen-reader-text"><?php esc_html_e( 'Youtube','summer-camp' );?></span></a></p><?php } ?>
	        <?php echo '</div>';
			?>
		</div>
		<?php
	}
	
	// Widget Backend 
	public function form( $summer_camp_instance ) {

		$summer_camp_title= ''; $summer_camp_facebook = ''; $summer_camp_twitter = ''; $summer_camp_linkedin = '';  $summer_camp_pinterest = '';$summer_camp_tumblr = ''; $summer_camp_instagram = ''; $summer_camp_youtube = ''; 

		$summer_camp_title = isset( $summer_camp_instance['title'] ) ? $summer_camp_instance['title'] : '';
		$summer_camp_facebook = isset( $summer_camp_instance['facebook'] ) ? $summer_camp_instance['facebook'] : '';
		$summer_camp_instagram = isset( $summer_camp_instance['instagram'] ) ? $summer_camp_instance['instagram'] : '';
		$summer_camp_twitter = isset( $summer_camp_instance['twitter'] ) ? $summer_camp_instance['twitter'] : '';
		$summer_camp_linkedin = isset( $summer_camp_instance['linkedin'] ) ? $summer_camp_instance['linkedin'] : '';
		$summer_camp_pinterest = isset( $summer_camp_instance['pinterest'] ) ? $summer_camp_instance['pinterest'] : '';
		$summer_camp_tumblr = isset( $summer_camp_instance['tumblr'] ) ? $summer_camp_instance['tumblr'] : '';
		$summer_camp_youtube = isset( $summer_camp_instance['youtube'] ) ? $summer_camp_instance['youtube'] : '';
		?>
		<p>
        <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:','summer-camp'); ?></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($summer_camp_title); ?>">
    	</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('facebook')); ?>"><?php esc_html_e('Facebook:','summer-camp'); ?></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($summer_camp_facebook); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('twitter')); ?>"><?php esc_html_e('Twitter:','summer-camp'); ?></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($summer_camp_twitter); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('linkedin')); ?>"><?php esc_html_e('Linkedin:','summer-camp'); ?></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($summer_camp_linkedin); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('instagram')); ?>"><?php esc_html_e('Instagram:','summer-camp'); ?></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($summer_camp_instagram); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('pinterest')); ?>"><?php esc_html_e('Pinterest:','summer-camp'); ?></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($summer_camp_pinterest); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('tumblr')); ?>"><?php esc_html_e('Tumblr:','summer-camp'); ?></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($summer_camp_tumblr); ?>">
		</p>
		<p>
		<label for="<?php echo esc_attr($this->get_field_id('youtube')); ?>"><?php esc_html_e('Youtube:','summer-camp'); ?></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($summer_camp_youtube); ?>">
		</p>
		<?php 
	}
	
	public function update( $summer_camp_new_instance, $summer_camp_old_instance ) {
		$summer_camp_instance = array();
		$summer_camp_instance['title'] = (!empty($summer_camp_new_instance['title']) ) ? strip_tags($summer_camp_new_instance['title']) : '';	
        $summer_camp_instance['facebook'] = (!empty($summer_camp_new_instance['facebook']) ) ? esc_url_raw($summer_camp_new_instance['facebook']) : '';
        $summer_camp_instance['twitter'] = (!empty($summer_camp_new_instance['twitter']) ) ? esc_url_raw($summer_camp_new_instance['twitter']) : '';
        $summer_camp_instance['instagram'] = (!empty($summer_camp_new_instance['instagram']) ) ? esc_url_raw($summer_camp_new_instance['instagram']) : '';
        $summer_camp_instance['linkedin'] = (!empty($summer_camp_new_instance['linkedin']) ) ? esc_url_raw($summer_camp_new_instance['linkedin']) : '';
        $summer_camp_instance['pinterest'] = (!empty($summer_camp_new_instance['pinterest']) ) ? esc_url_raw($summer_camp_new_instance['pinterest']) : '';
        $summer_camp_instance['tumblr'] = (!empty($summer_camp_new_instance['tumblr']) ) ? esc_url_raw($summer_camp_new_instance['tumblr']) : '';
     	$summer_camp_instance['youtube'] = (!empty($summer_camp_new_instance['youtube']) ) ? esc_url_raw($summer_camp_new_instance['youtube']) : '';
     	
		return $summer_camp_instance;
	}
}

function summer_camp_custom_load_widget() {
	register_widget( 'Summer_Camp_Social_Widget' );
}
add_action( 'widgets_init', 'summer_camp_custom_load_widget' );