<?php
/**
 * Social link functions
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}
/**
 * Retrieves social links
 */
function multimagazine_get_social_links() {
	$new_tabs = get_theme_mod( 'multi_social_new_tabs', MULTIMAGAZINE_SOCIAL_NEW_TABS );
	$color    = get_theme_mod( 'multi_social_links_color', MULTIMAGAZINE_SOCIAL_LINKS_COLOR );
	if ( empty( $color ) ) {
		$color = false;
	}
	$socials       = array( 'facebook', 'twitter', 'pinterest', 'rss', 'instagram', 'tiktok', 'skype', 'tumblr', 'linkedin', 'flickr', 'vimeo', 'behance', 'youtube', 'dribbble', 'github', 'stumbleupon', 'lastfm', 'tripadvisor', 'snapchat', 'whatsapp', 'discord', 'threads', 'producthunt', 'email' );
	$socials_names = array( 'Facebook', 'Twitter', 'Pinterest', 'RSS', 'Instagram', 'TikTok', 'Skype', 'Tumblr', 'LinkedIn', 'Flickr', 'Vimeo', 'Behance', 'YouTube', 'Dribbble', 'GitHub', 'StumbleUpon', 'Last.fm', 'TripAdvisor', 'Snapchat', 'WhatsApp', 'Discord', 'Threads', 'ProductHunt', 'E-mail' );

	$social_links = array();
	foreach ( $socials as $k => $v ) {
		if ( 'rss' === $v && get_theme_mod( 'multi_show_rss_link', MULTIMAGAZINE_SHOW_RSS_LINK ) ) {
			$link           = new stdClass();
			$link->slug     = $v;
			$link->name     = $socials_names[ $k ];
			$link->url      = get_theme_mod( 'multi_social_customrss' ) ? get_theme_mod( 'multi_social_customrss' ) : get_bloginfo( 'rss2_url' );
			$link->content  = multimagazine_social_icon( $v, $color );
			$link->rel      = $new_tabs ? 'noopener' : '';
			$social_links[] = $link;
		} else {
			$url = get_theme_mod( 'multi_social_' . $v );
			if ( $url ) {
				$link           = new stdClass();
				$link->slug     = $v;
				$link->name     = $socials_names[ $k ];
				$link->url      = $url;
				$link->content  = multimagazine_social_icon( $v, $color );
				$link->rel      = $new_tabs ? 'noopener' : '';
				$social_links[] = $link;
			}
		}
	}
	return $social_links;
}

/**
 * Prepares markup of social link's icon
 *
 * @param string $site Social site slug.
 */
function multimagazine_social_icon( $site ) {
	switch ( $site ) {
		case 'email':
			$html = '<i class="m-icon m-icon-envelope" aria-hidden="true"></i>';
			break;
		default:
			$html = '<i class="m-icon m-icon-' . $site . '" aria-hidden="true"></i>';
			break;
	}
	return $html;
}

/**
 * Prepares a list of classes for the social links based on settings
 */
function multimagazine_social_classes() {
	$social_options = array(
		'social',
		get_theme_mod( 'multi_social_links_size', 'normal' ),
		get_theme_mod( 'multi_social_links_color', MULTIMAGAZINE_SOCIAL_LINKS_COLOR ),
		get_theme_mod( 'multi_social_text_shadow', MULTIMAGAZINE_SOCIAL_TEXT_SHADOW ) ? 'with-text-shadow' : '',
		get_theme_mod( 'multi_social_box_shadow', MULTIMAGAZINE_SOCIAL_BOX_SHADOW ) ? 'with-box-shadow' : '',
		get_theme_mod( 'multi_social_hide_links', MULTIMAGAZINE_SOCIAL_HIDE_LINKS ) ? 'social-links-hidden' : '',
	);

	$classes = implode( ' ', $social_options );
	return $classes;
}
