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

get_header();?>

<?php
$vimeo_id = get_field( 'vimeo_id' );
$trailer_id = get_field( 'trailer_id' );
$options = get_field('video_options');
$cover = get_field('cover_image');
$authors = get_field('author');
$gallery = get_field('gallery');
$year = get_field('year');
$duration = get_field('duration'); $duration = array_filter( $duration[0] );
$format_and_technical = get_field('format_and_technical');
$credits = get_field('credits');
$lead_description = get_field('lead_description');
$full_description = get_field('full_description');
$link = get_field('extra_content_link'); $link = $link[0];
$stills = get_field('stills');

?>
<div class="u_pt-5">
    <div class="l_container u_mv-5 wrapper-profile">
      <!-- breadcrumbs module-->
      <!-- <?php breadcrumbs_module();?> -->
      <!-- page-title module-->
      <div class="page-title u_mb-3 u_mb-md-4">
        <!-- Page title-->
        <h1 class="page-title__alpha-title"><?php the_title();?></h1>
         <!-- Artist name-->
        <h2 class="info-card__value"><?php echo get_authors_string( $authors ) ?></h2>
        
        <?php if ( !empty( $gallery ) ) : $gallery_address = get_field('address',$gallery->ID); ?>
        <!-- Gallery name-->
        <h3 class="page-title__gamma-title birth-date"><?php echo $gallery->post_title;?>, <?php echo $gallery_address[0]['city'];?></h3>
        <?php endif; ?>
      </div>


      <!--MGS Video seccion-->
      <div class="u_mb-5 wrapper-artist-video">

        <?php if ( is_array( $options ) && in_array( 'private', $options ) && !is_user_logged_in() ) : ?>

          <figure class="cover-image">
            <?php
            if ( ! empty( $cover ) ) {
              $src     = $cover['url'];
              $caption = $cover['caption'];
            } else {
              $src     = get_template_directory_uri() . '/img/horizontal-placeholder.svg';
              $caption = 'placeholder';
            }
            ?>
            <img src="<?php echo esc_url( $src ); ?>" alt="<?php echo esc_attr( $caption ); ?>">
            <?php if ( ! empty( $caption ) ) : ?>
              <figcaption class="cover-image__caption"><?php echo esc_html( $caption ); ?></figcaption>
            <?php endif; ?>
          </figure>

          <p class="u_mt-min1 u_mb-0 u_text-italic eta">&mdash;
            <a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>" class="u_bd-bottom-dotted">Log in</a>
            to watch the artist video if you have been given an access
          </p>

        <?php else : ?>

          <?php if ( ! empty( $vimeo_id ) ) : ?>

            <?php video_player_module( $vimeo_id ); ?>

          <?php else : ?>

            <?php
            // Buscar primer still
            $first_still = null;
            if ( ! empty( $stills ) && is_array( $stills ) ) {
              foreach ( $stills as $s ) {
                if ( ! empty( $s['url'] ) ) { $first_still = $s; break; }
              }
            }
            ?>

            <?php if ( $first_still ) : ?>
              <figure class="cover-image cover-image--still">
                <img src="<?php echo esc_url( $first_still['url'] ); ?>"
                    alt="<?php echo esc_attr( ! empty( $first_still['caption'] ) ? $first_still['caption'] : 'Still' ); ?>">
                <?php if ( ! empty( $first_still['caption'] ) ) : ?>
                  <figcaption class="cover-image__caption"><?php echo esc_html( $first_still['caption'] ); ?></figcaption>
                <?php endif; ?>
              </figure>

            <?php elseif ( ! empty( $cover ) ) : ?>
              <figure class="cover-image">
                <img src="<?php echo esc_url( $cover['url'] ); ?>" alt="<?php echo esc_attr( $cover['caption'] ); ?>">
                <?php if ( ! empty( $cover['caption'] ) ) : ?>
                  <figcaption class="cover-image__caption"><?php echo esc_html( $cover['caption'] ); ?></figcaption>
                <?php endif; ?>
              </figure>

            <?php else : ?>
              <figure class="cover-image">
                <img src="<?php echo esc_url( get_template_directory_uri() . '/img/horizontal-placeholder.svg' ); ?>" alt="placeholder">
                <figcaption class="cover-image__caption">placeholder</figcaption>
              </figure>
            <?php endif; ?>

          <?php endif; ?>

        <?php endif; ?>

      </div>


      <div data-sticky-sidebar-grid class="grid u_mh-min1p5">
        <div data-sticky-sidebar class="col--sm--three--seventh col--md--two--fifth u_ph-1p5">
          
          <?php if ( is_array( $options ) && in_array( 'premiere', $options ) ) : ?>
          
          <!-- premiere-mark module-->
          <div href="#" class="premiere-mark">Première</div>
          
          <?php endif; ?>
          
          <?php get_template_part( 'template-parts/infocard-artist-video' );?>
          
        </div>
        <div class="col--sm--four--seventh col--md--three--fifth u_ph-1p5">


          <!-- lead-description module-->
          <?php if ( !empty( $lead_description ) ) : ?>
      		  <p class="lead-description u_mb-2 h1 ddd"><?php echo $lead_description; ?></p>
		      <?php endif; ?>

          <!-- wysiwyg module-->
          <div class="wysiwyg">
            <!-- wysiwyg text block-->
            <?php echo $full_description;?>
          </div>
          <?php award_list_module(); ?>
          
          <?php if ( !empty( $trailer_id ) ) :?>
          <!-- section-heading module-->
          <h3 class="section-heading delta u_mt-5"><span class="u_text-underline">Trailer</span></h3>
          <?php video_player_module( $trailer_id ); endif; ?>
          
          <?php if ( !empty( $link['url'] ) ) : ?>
         
          <div class="u_mt-4"><a href="<?php echo $link['url'];?>" class="u_bd-bottom-dotted"><?php echo empty( $link['link_text'] ) ? remove_http( $link['url'] ) : $link['link_text'];?></a></div>
          
          <?php endif;?>
          
        </div>
      </div>
    </div>


    <div class="l_container l_container--wider u_mt-5">
      <!-- section-heading module-->
      <?php if(!empty($stills)):?>
      <h3 class="section-heading delta"><span class="u_text-underline">Stills</span></h3>

			<div class="archive-grid">
				<?php foreach ( $stills as $still ) : ?>
					<div class="archive-item">
						<div class="archive-new-thumb">
							<div class="archive-thumb__image-container still-image" data-pswp-image="data-pswp-image">
								<img src="<?php echo esc_url($still['url']); ?>" alt="Still">
							</div>
						</div>
					</div>
				<?php endforeach; ?>
			</div>


      <?php endif;?>
    </div>








    <?php related_artist_profile();?>
    <?php related_artist_videos_module();?>
    <?php related_galleries_module(); ?>
   



  </div>

  <!-- pswp (photoswipe) module-->
  <div class="pswp">
    <div class="pswp__bg"></div>
    <div class="pswp__scroll-wrap">
      <div class="pswp__container">
        <div class="pswp__item"></div>
        <div class="pswp__item"></div>
        <div class="pswp__item"></div>
      </div>
      <div class="pswp__ui pswp__ui--hidden">
        <div class="pswp__top-bar">
          <div class="pswp__counter"></div>
          <div class="pswp__button pswp__button--close"></div>
          <div class="pswp__button pswp__button--fs"></div>
          <div class="pswp__button pswp__button--zoom"></div>
          <div class="pswp__preloader">
            <div class="pswp__preloader__icn">
              <div class="pswp__preloader__cut">
                <div class="pswp__preloader__donut"></div>
              </div>
            </div>
          </div>
        </div>
        <button class="pswp__button pswp__button--arrow--left"></button>
        <button class="pswp__button pswp__button--arrow--right"></button>
        <div class="pswp__caption">
          <div class="pswp__caption__center"></div>
        </div>
      </div>
    </div>
  </div>

<?php get_footer();
