<?php

function jenny_social_icons( $wp_customize ) {

	/**
	 * Social Settings Section
	 */
	$wp_customize->add_section( 'jenny_social_section', array(
		'title'                 =>  esc_html__( 'Social Settings', 'jenny' ),
		'panel'                 =>  'jenny_panel'
	) );

	/**
	 * Facebook Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_facebook_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
        array(
	        'sanitize_callback'     =>  'esc_url_raw',
        )
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_facebook_social_input',
			array(
				'label'         =>  esc_html__( 'Facebook', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_facebook_handle',
				'type'          =>  'url'
			)
		)
	);

	/**
	 * Twitter Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_twitter_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
		array(
			'sanitize_callback'     =>  'esc_url_raw',
		)
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_twitter_social_input',
			array(
				'label'         =>  esc_html__( 'Twitter', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_twitter_handle',
				'type'          =>  'url'
			)
		)
	);

	/**
	 * Linkedin Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_linkedin_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
		array(
			'sanitize_callback'     =>  'esc_url_raw',
		)
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_linkedin_social_input',
			array(
				'label'         =>  esc_html__( 'Linkedin', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_linkedin_handle',
				'type'          =>  'url'
			)
		)
	);

	/**
	 * Instagram Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_instagram_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
		array(
			'sanitize_callback'     =>  'esc_url_raw',
		)
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_instagram_social_input',
			array(
				'label'         =>  esc_html__( 'Instagram', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_instagram_handle',
				'type'          =>  'url'
			)
		)
	);


	/**
	 * Pinterest Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_pinterest_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
		array(
			'sanitize_callback'     =>  'esc_url_raw',
		)
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_pinterest_social_input',
			array(
				'label'         =>  esc_html__( 'Pinterest', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_pinterest_handle',
				'type'          =>  'url'
			)
		)
	);

	/**
	 * Email Social Handle Setting
	 */
	$wp_customize->add_setting( 'jenny_email_handle', array(
		'default'               =>  '',
		'transport'             =>  'refresh',
		array(
			'sanitize_callback' => 'sanitize_email'
		)
	) );

	$wp_customize->add_control(
		new WP_Customize_Control(
			$wp_customize,
			'jenny_email_social_input',
			array(
				'label'         =>  esc_html__( 'Email', 'jenny' ),
				'section'       =>  'jenny_social_section',
				'settings'      =>  'jenny_email_handle',
				'type'          =>  'email'
			)
		)
	);

}

function jenny_social_icons_output() {
	$jenny_facebook_handle       =   get_theme_mod( 'jenny_facebook_handle' );
	$jenny_twitter_handle        =   get_theme_mod( 'jenny_twitter_handle' );
	$jenny_linkedin_handle       =   get_theme_mod( 'jenny_linkedin_handle' );
	$jenny_instagram_handle      =   get_theme_mod( 'jenny_instagram_handle' );
	$jenny_pinterest_handle      =   get_theme_mod( 'jenny_pinterest_handle' );
	$jenny_email_handle          =   get_theme_mod( 'jenny_email_handle' );

	if( $jenny_facebook_handle || $jenny_twitter_handle || $jenny_linkedin_handle || $jenny_instagram_handle || $jenny_pinterest_handle ) : ?>
		<div class="social-links">
			<?php if( $jenny_facebook_handle ) : ?>
				<a href="<?php echo esc_url( $jenny_facebook_handle ); ?>" target="_blank"><span class="fa fa-facebook"></span></a>
			<?php endif; ?>

			<?php if( $jenny_twitter_handle ) : ?>
				<a href="<?php echo esc_url( $jenny_twitter_handle ); ?>" target="_blank"><span class="fa fa-twitter"></span></a>
			<?php endif; ?>

			<?php if( $jenny_linkedin_handle ) : ?>
				<a href="<?php echo esc_url( $jenny_linkedin_handle ); ?>" target="_blank"><span class="fa fa-linkedin"></span></a>
			<?php endif; ?>

			<?php if( $jenny_instagram_handle ) : ?>
				<a href="<?php echo esc_url( $jenny_instagram_handle ); ?>" target="_blank"><span class="fa fa-instagram"></span></a>
			<?php endif; ?>

			<?php if( $jenny_pinterest_handle ) : ?>
				<a href="<?php echo esc_url( $jenny_pinterest_handle ); ?>" target="_blank"><span class="fa fa-pinterest"></span></a>
			<?php endif; ?>

			<?php if( $jenny_email_handle ) : ?>
				<a href="mailto:<?php echo sanitize_email($jenny_email_handle); ?>" title="<?php echo esc_attr($jenny_email_handle); ?>"><span class="fa fa-envelope"></span></a>
			<?php endif; ?>
		</div>
	<?php
    else :
	    return null;
	endif;
}