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

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

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

$language_list = gigneo_term_list( array( 'taxonomy' => 'gigneo_language' ), false );
$levels        = gigneo_language_levels( false );

?>
<div class="gn-section gn-languages-section">
	<div class="gn-head">
		<h4 class="gn-title"><?php esc_html_e( 'Languages', 'gigneo' ); ?></h4>
	</div>
	<div class="gn-body">
		<ul class="gn-profile-languages gn-language-cards">
			<?php
			foreach ( $languages as $language ) {
				$lang_name  = isset( $language['name'] ) && isset( $language_list[ $language['name'] ] ) ? $language_list[ $language['name'] ] : '';
				$lang_level = isset( $language['level'] ) && isset( $levels[ $language['level'] ] ) ? $levels[ $language['level'] ] : '';
				if ( ! empty( $lang_name ) && ! empty( $lang_level ) ) {
					?>
					<li class="gn-language">
						<?php echo esc_html( $lang_name ); ?><span class="gn-level">(<?php echo esc_html( $lang_level ); ?>)</span>
					</li>
					<?php
				}
			}
			?>
		</ul>
	</div>
</div>
