<?php
/**
 * Social links
 *
 * @package Multi
 */

?>
<?php
$args           = wp_parse_args( $args );
$new_tabs       = get_theme_mod( 'multi_social_new_tabs', MULTIMAGAZINE_SOCIAL_NEW_TABS );
$social_classes = multimagazine_social_classes();
$social_links   = multimagazine_get_social_links();
$hide_links     = get_theme_mod( 'multi_social_hide_links', MULTIMAGAZINE_SOCIAL_HIDE_LINKS );

if ( $args['wrap_nav'] ) :
	?>
<nav class="<?php echo esc_attr( $social_classes ); ?>">
	<ul>
<?php else : ?>
<ul class="<?php echo esc_attr( $social_classes ); ?>">
<?php endif; ?>
<?php
foreach ( $social_links as $social_link ) :
	$classes = 'social-link social-link-' . $social_link->slug;
	if ( ! empty( $args['tooltip'] ) ) {
		$classes .= ' has-tooltip';
	}
	if ( $hide_links && $new_tabs ) {
		$classes .= ' new-tab';
	}
	?>
<li class="menu-item-social">
	<?php
	if ( $hide_links ) :
		$social_link_url = $social_link->url;
		if ( is_callable( 'diagnoseo_encode_text' ) ) {
			$social_link_url = diagnoseo_encode_text( $social_link_url );
		}
		?>
		<span class="<?php echo esc_attr( $classes ); ?>" data-link="<?php echo esc_attr( $social_link_url ); ?>" title="<?php echo esc_attr( $social_link->name ); ?>"><?php // phpcs:ignore ?>
	<?php else : ?>
	<a href="<?php echo esc_url( $social_link->url ); ?>" class="<?php echo esc_attr( $classes ); ?>"
		<?php if ( ! empty( $social_link->rel ) ) : ?>
			rel="<?php echo esc_attr( $social_link->rel ); ?>"
		<?php endif; ?>
		title="<?php echo esc_attr( $social_link->name ); ?>"
		<?php if ( $new_tabs ) : ?>
			target="_blank"
		<?php endif; ?>
		>
	<?php endif; ?>
		<?php echo wp_kses_post( $social_link->content ); ?>
		<?php if ( $args['tooltip'] ) : ?>
			<span class="tooltip tooltip-pos-top tooltip-style-1"><?php echo esc_html( $social_link->name ); ?></span>
		<?php else : ?>
			<span class="screen-reader-text"><?php echo esc_html( $social_link->name ); ?></span>
		<?php endif; ?>
	<?php if ( $hide_links ) : ?>
		</span>
	<?php else : ?>
		</a>
	<?php endif; ?>
</li>
<?php endforeach; ?>

	</ul>

<?php if ( $args['wrap_nav'] ) : ?>
</nav>
<?php endif; ?>
