<?php
/**
* Views: Social Icons
*/
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$position = 'fl_left';
if ( isset( $fl_social_icons_settings['bar_position'] ) ) {
	$position = $fl_social_icons_settings['bar_position'];
}
?>
<div class="floating_next_prev_wrap fl_social_icons_bar fl_social_icons_wrap fl_<?php echo esc_attr( $position ); ?>">
	<div class="floating_links">
		<div id="fl_social_icons_inner_wrap" class="fl_inner_wrap">
		<?php
		do_action( 'fl_before_social_icons_bar', $fl_social_icons_settings );
		// Ensure networks exist - use defaults if not set (for free users with no saved settings)
		if ( ! isset( $fl_social_icons_settings['networks'] ) || empty( $fl_social_icons_settings['networks'] ) ) {
			$fl_social_icons_settings['networks'] = fl_social_networks_defaults();
		}
		if ( isset( $fl_social_icons_settings['networks'] ) ) {
			$social_icons   = ( isset( $fl_social_icons_settings['networks']['sort'] ) )
				? wp_parse_args( fl_social_networks_defaults(), $fl_social_icons_settings['networks']['sort'] )
				: $fl_social_icons_settings['networks'];
			$show_minimizer = false;
			$twitter_svg    = '<svg xmlns="http://www.w3.org/2000/svg" fill="#fff" viewBox="0 0 512 512">
				<path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 
				26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/>
			</svg>';

			$fl_settings = get_option( 'fl_settings', array() );
			foreach ( $social_icons as $key => $social_icon ) {
				// Check if network is enabled - use the social_icon array first, then fallback to settings
				$is_enabled = isset( $social_icon['enabled'] ) ? $social_icon['enabled'] : ( isset( $fl_social_icons_settings['networks'][ $key ]['enabled'] ) ? $fl_social_icons_settings['networks'][ $key ]['enabled'] : 'on' );
				if ( 'on' !== $is_enabled ) {
					continue;
				}
				// Use $social_icon array directly to avoid undefined key errors
				$fl_network_id       = isset( $social_icon['id'] ) ? $social_icon['id'] : $key;
				$fl_network_name     = isset( $social_icon['name'] ) ? $social_icon['name'] : ucfirst( $fl_network_id );
				$fl_network_icon     = isset( $social_icon['icon'] ) ? $social_icon['icon'] : '';
				$fl_network_url      = isset( $fl_settings['social_icons'][ $fl_network_id . '_url' ] )
				? $fl_settings['social_icons'][ $fl_network_id . '_url' ]
				: '';
				$fl_googleplus_url   = isset( $fl_settings['social_icons']['googleplus_url'] ) ? $fl_settings['social_icons']['googleplus_url'] : '';
				$fl_social_share_url = fl_social_share_url( $fl_network_id );
				?>
					<?php if ( 'googleplus' === $fl_network_id ) : ?>
					<a id="fl_social_googleplus"
						target="_blank"
						rel="noopener noreferrer nofollow"
						href="<?php echo esc_url( ! empty( $fl_googleplus_url ) ? $fl_googleplus_url : $fl_social_share_url ); ?>"
						title="<?php echo esc_attr( $fl_network_name ); ?>"
						class="fl_social_googleplus fl_icon_holder">
						<i class="fl_googleplus_icon <?php echo esc_attr( $fl_network_icon ); ?>"></i>
					</a>
				<?php else : ?>

					<a id="fl_social_<?php echo esc_attr( $fl_network_id ); ?>"
						target="_blank"
						rel="noopener noreferrer nofollow"
						href="<?php echo esc_url( ! empty( $fl_network_url ) ? $fl_network_url : $fl_social_share_url ); ?>"
						title="<?php echo esc_attr( $fl_network_name ); ?>"
						class="fl_social_<?php echo esc_attr( $fl_network_id ); ?> fl_icon_holder">
						<?php if ( 'twitter' === $fl_network_id ) : ?>
							<?php if ( empty( $fl_network_icon ) || 'svg' === $fl_network_icon ) : ?>
								<?php
								echo $twitter_svg;
								?>
							<?php else : ?>
								<i class="fl_twitter_icon <?php echo esc_attr( $fl_network_icon ); ?>"></i>
							<?php endif; ?>
						<?php else : ?>
							<i class="fl_<?php echo esc_attr( $fl_network_id ); ?>_icon <?php echo esc_attr( $fl_network_icon ); ?>"></i>
						<?php endif; ?>
					</a>
				<?php endif; ?>
						<?php
						$show_minimizer = true;
			}
		}

		do_action( 'fl_after_social_icons_bar', $fl_social_icons_settings );
		?>
		</div>
	<?php if ( isset( $fl_social_icons_settings['enable_minimizer'] ) && 'on' === $fl_social_icons_settings['enable_minimizer'] && $show_minimizer ) { ?>
		<div id="fl_slimer_social_wrap" class="fl_slimer_Wrap">
			<i class="fl_slimmer_icon fl_minimizer_icon fa fa-close"></i>
			<i class="fl_slimer_close_icon fl_hide fl_minimizer_icon fa fa-crosshairs"></i>
		</div>
	<?php } ?>
	</div>	
</div>
