<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$profile_id = $args['profile_id'] ?? '';
$socials    = gigneo_post_meta( $profile_id, '_gigneo_pm_socials' );
$socials    = ! empty( $socials ) ? $socials : array();

if ( empty( $socials ) ) {
	return;
}

$social_list = gigneo_social_profiles( 'active' );
?>

<div class="gn-section gn-socials-section">
	<div class="gn-head">
		<h4 class="gn-title"><?php esc_html_e( 'Social links', 'gigneo' ); ?></h4>
	</div>
	<div class="gn-body">
		<?php
		foreach ( $socials as $social ) {
			$social_type = isset( $social['type'] ) && isset( $social_list[ $social['type'] ] ) ? $social_list[ $social['type'] ] : '';
			$social_url  = ! empty( $social['url'] ) ? $social['url'] : '';
			if ( ! empty( $social_type ) && ! empty( $social_url ) ) {
				$social_type_icon = strtolower( $social_type );
				$logo_path        = GIGNEO_DIR_PATH . "assets/img/icon/$social_type_icon.png";
				$logo_url         = GIGNEO_DIR_URL . "assets/img/icon/$social_type_icon.png";
				$logo             = file_exists( $logo_path ) ? $logo_url : GIGNEO_DIR_URL . 'assets/img/icon/link.png';
				?>
				<a href="<?php echo esc_url( $social_url ); ?>" target="_blank" class="gn-social-tag gn-social-<?php echo esc_attr( $social_type ); ?>">
					<img src="<?php echo esc_url( $logo ); ?>" alt="<?php echo esc_attr( $social_type ); ?>">
					<?php echo esc_html( $social_type ); ?>
				</a>
				<?php
			}
		}
		?>
	</div>
</div>
