<?php

	$header_have_social = have_rows( 'global_header_menu_social_links', 'option' );
	$mobile_social_position = StockieSettings::get( 'header_mobile_social_position', 'global' );
	$links = StockieSettings::get( 'side_panel_social', 'global' );
	$social_enable = StockieSettings::get( 'side_panel_social_enable', 'global' );
	$show_share_on_mobile = StockieSettings::get( 'side_panel_show_share_on_mobile', 'global' );
    $header_menu_style = StockieSettings::header_menu_style();
	$allowed_html = array(
	    'a' => array(
	        'href' =>true
	    ),
	    'i' => array(
	        'class' => true
	    )
	);

if ($links && is_array( $links )){

	ob_start();

	foreach ( $links as $link ) {
		switch ( $link ) {
			case 'facebook':
				echo '<a href="https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( get_permalink() ) . '"><i class="fa fa-facebook"></i></a>';
				break;
			case 'twitter':
				echo '<a href="https://twitter.com/intent/tweet?text=' . rawurlencode( get_permalink() ) . '"><i class="fa fa-twitter"></i></a>';
				break;
			case 'googleplus':
				echo '<a href="https://plus.google.com/share?url=' . rawurlencode( get_permalink() ) . '"><i class="fa fa-google"></i></a>';
				break;
			case 'dribbble':
				echo '<a href="http://pinterest.com/pin/create/button/?url=' . urlencode( get_permalink() ) . '&description=' . urlencode( 'title' ) . '"><i class="fa fa-dribbble"></i></a>';
				break;
			case 'linkedin':
				echo '<a href="https://www.linkedin.com/shareArticle?mini=true&url=' . rawurlencode( get_permalink() ) . '&title=' . urlencode( the_title( '', '', false ) ) . '&source=' . urlencode( get_bloginfo( 'name' ) ) . '"><i class="fa fa-linkedin"></i></a>';
				break;
			case 'pinterest':
				echo '<a href="http://pinterest.com/pin/create/button/?url=' . rawurlencode( get_permalink() ) . '"><i class="fa fa-pinterest-p"></i></a>';
				break;
			case 'vk':
				echo '<a href="http://vk.com/share.php?url=' . rawurlencode( get_permalink() ) . '"><i class="fa fa-vk"></i></a>';
				break;
		}
	}

	$social_html = ob_get_clean();
}
?>

<?php if ( is_array( $links ) && $social_enable ) : ?>

	<?php if ( $show_share_on_mobile ) : ?>

		<div class="share-bar<?php 
			if ( $header_menu_style == 'style6' ) { echo ' header-6'; } 
			if ( $header_menu_style == 'style7' ) { echo ' header-8'; } ?>" tabindex="1">

			<div class="title btn-round">
				<i class="ion brand-bg-color brand-color-hover ion-md-add"></i>
				<span class="name font-titles"><?php esc_html_e( 'Share', 'stockie' ); ?></span>
			</div>
			<div class="links">
				<?php echo  wp_kses( $social_html, $allowed_html); ?>
			</div>
		</div>

	<?php endif; ?>

<?php endif; ?>

<?php if ( $header_have_social ) : ?>
	<div class="social-bar<?php if ( $mobile_social_position == 'inside' ) { echo ' inside'; } ?>">
		<div class="small socialbar">
		<?php while( have_rows( 'global_header_menu_social_links', 'option' ) ): the_row(); ?>
			<?php switch ( get_sub_field( 'social_network' ) ) {
				case 'facebook':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="facebook brand-color-hover"><i class="icon fa fa-facebook"></i></a>';
					break;
				case 'twitter':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="twitter brand-color-hover"><i class="icon fa fa-twitter"></i></a>';
					break;
				case 'googleplus':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="googleplus brand-color-hover"><i class="icon fa fa-google-plus"></i></a>';
					break;
				case 'instagram':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="instagram brand-color-hover"><i class="icon fa fa-instagram"></i></a>';
					break;
				case 'dribbble':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="dribbble brand-color-hover"><i class="icon fa fa-dribbble"></i></a>';
					break;
				case 'github':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="github brand-color-hover"><i class="icon fa fa-github-alt"></i></a>';
					break;
				case 'linkedin':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="linkedin brand-color-hover"><i class="icon fa fa-linkedin"></i></a>';
					break;
				case 'vimeo':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="vimeo brand-color-hover"><i class="icon fa fa-vimeo"></i></a>';
					break;
				case 'youtube':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="youtube brand-color-hover"><i class="icon fa fa-youtube"></i></a>';
					break;
				case 'vk':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="vk brand-color-hover"><i class="icon fa fa-vk"></i></a>';
					break;
				case 'behance':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="behance brand-color-hover"><i class="icon fa fa-behance"></i></a>';
					break;
				case 'flickr':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="flickr brand-color-hover"><i class="icon fa fa-flickr"></i></a>';
					break;
				case 'reddit':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="reddit brand-color-hover"><i class="icon fa fa-reddit-alien"></i></a>';
					break;
				case 'snapchat':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="snapchat brand-color-hover"><i class="icon fa fa-snapchat"></i></a>';
					break;
				case 'whatsapp':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="whatsapp brand-color-hover"><i class="icon fa fa-whatsapp"></i></a>';
					break;
				case 'quora':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="quora brand-color-hover"><i class="icon fa fa-quora"></i></a>';
					break;
				case 'vine':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="vine brand-color-hover"><i class="icon fa fa-vine"></i></a>';
					break;
				case 'digg':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="digg brand-color-hover"><i class="icon fa fa-digg"></i></a>';
					break;
				case 'foursqure':
					echo '<a target="_blank" href="' . esc_url( get_sub_field( 'url' ) ) . '" class="foursquare brand-color-hover"><i class="icon fa fa-foursquare"></i></a>';
					break;
			} ?>
			<?php endwhile; ?>

		</div>
	</div>
	<?php endif; ?>