<?php
/**
 * @package far_loop
 */

get_header();?>

<?php
$portrait = get_field('portait');
$year_of_birth = get_field('year_of_birth');
$place_of_birth = get_field('place_of_birth');
$biography = get_field('biography');
$website = get_field('website');
$profile_types = get_the_terms( get_the_ID(), 'profile-type' );
$profile_id = get_the_ID();
?>
  <div class="u_pt-5">
    <div class="l_container u_mv-0 wrapper-profile">

      <div class="page-title u_mb-2">
        <!-- Page title-->
        <h1 class="page-title__alpha-title u_mb-0p5"><?php echo get_the_title();?></h1>

            <dl class="info-card__list">
                  <?php if (!empty($profile_types)) :?>
                  <!-- info-card list item-->
                  <?php if ( !empty( $profile_types ) && !is_wp_error( $profile_types ) ) {
                        $unique_terms = array();
                        $displayed_terms = array();

                        foreach ( $profile_types as $term ) {
                            // Usa el 'term_id' o el 'slug' base del término, quitando el sufijo del idioma (e.g., '-ca', '-es')
                            $base_slug = preg_replace('/-[a-z]{2}$/', '', $term->slug);

                            // Verifica si ya tenemos el término base en la lista, y si no, lo añadimos
                            if ( !in_array( $base_slug, $displayed_terms ) ) {
                                $unique_terms[] = $term;
                                $displayed_terms[] = $base_slug;
                            }
                        }
                        // Función para convertir los términos en una cadena para mostrar
                        echo '<dd class="info-card__value">' . esc_html( get_terms_string( $unique_terms ) ) . '</dd>';
                    } ?>
                  <?php
	              endif; // profile_types
                  if ( !empty( $website ) ) : ?>
                    <dd class="info-card__value"><a href="<?php echo $website;?>"><?php echo remove_http( $website );?></a>
                  <?php endif; ?>
                  </dd>
            </dl>



        
        <?php if( !empty( $year_of_birth ) || !empty( $place_of_birth ) ) :?>
        
        <!-- Artist's birthdate-->
        <h3 class="page-title__gamma-title birth-date">
	        <?php
		    
		    if ( !empty( $year_of_birth ) ) echo $year_of_birth;
		    if( !empty( $year_of_birth ) && !empty( $place_of_birth ) ) echo ', ';
		    if ( !empty( $place_of_birth ) ) echo $place_of_birth;
		    
		    ?>
	    </h3>
        
        <?php endif;?>
        
      </div>
      <div class="grid u_mh-min1p5">
        <div class="col--md--two--ninth u_ph-1p5">
          <div class="grid u_mh-min1p5">

              <div class="col--sm--one u_ph-1p5">
                  <?php
                  if ( !empty( $portrait ) ) {
                      $src = $portrait['sizes']['squared'];
                      $img_class = '';
                  } else {
                      $src = get_template_directory_uri() . '/img/square-placeholder.svg';
                      $img_class = 'no-image';
                  }
                  ?>
                  <figure class="cover-image u_m-0">
                      <img src="<?php echo esc_url($src); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" <?php echo $img_class ? 'class="' . esc_attr($img_class) . '"' : ''; ?>>
                  </figure>
              </div>
           
          </div>
        </div>
        <div class="col--md--seven--ninth u_ph-1p5 description-profile">
          <div class="grid">
            <div class="col--lg--seven--eighth">
              
                <!-- wysiwyg module-->
                <div class="wysiwyg">
                  <!-- wysiwyg text block-->
                  <?php echo $biography;?>
                </div>
             
            </div>
          </div>
        </div>
      </div>
    </div>




    
    <?php related_artist_videos_module();?>
    <?php related_galleries_module(); ?>
    
    <!-- <?php related_artists_module(); ?> -->
    <?php related_activities_module(); ?>


    <?php related_pages_module_pages_only(); ?>

    
    
  </div>

<?php get_footer();