<?php
/**
 * Template Name: Location Template
 * Template Post Type: page
 *
 * @package thehoot
 */


get_header(); ?>

  <div class="col-12 col-lg-8 pe-lg-5" data-aos="fade-up">

    <?php
  if ( function_exists('yoast_breadcrumb') ) { ?>
      <div class="mb-4">

        <?php echo do_shortcode("[wpseo_breadcrumb]"); ?>

      </div>

      <?php  }
  ?>
        <?php
	$location_title = get_field('location_title');
  $location_intro_text = get_field('location_intro_text');
  $location_header = get_field('location_header');
	$location_content = get_field('location_detail');

  if ($location_title) : ?>

          <h1><?php echo esc_html($location_title); ?></h1>

          <?php endif; ?>

            <?php get_template_part( 'template-parts/location-nav' ); ?>

              <?php
      if ($location_intro_text) : ?>

                <?php echo '<div class="lead">' ?>

                  <?php echo wp_kses_post ($location_intro_text); ?>

                    <?php echo '</div>' ?>

                      <?php endif;

          if ($location_header) : ?>

                        <img class="img-fluid w-100 mb-4" src="<?php echo esc_url($location_header['url']); ?>" alt="<?php echo esc_attr($location_header['alt']); ?>">

                        <?php endif;

          if ($location_content) : ?>

                          <div class="content mb-5" id="content">
                            <?php echo wp_kses_post ($location_content); ?>
                              <div class="text-center">
                                <a class="m-auto btn" id="shower">Continue Reading</a>
                                <a class="m-auto" id="hider">Close Continue Reading</a>
                              </div>
                          </div>

                        <?php endif; ?>

            <div class="row" data-aos="fade-up" data-aos-anchor="#content">

                              <?php
            $term = get_field('choose_your_category', $post->post_parent);
						$cat = get_field('choose_your_category');
            $cats = get_the_category($cat);
            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;


							$query = new WP_Query( array(
                  'posts_per_page' => 4,
                  'paged' => $paged,
                  'tax_query' => array(
                    array(
                      'taxonomy' => 'category',
                      'terms' => $cat
                    ),
                  ),
								) );

							while ( $query->have_posts() ) : $query->the_post();
              $exclude[] = get_the_ID();


							?>
                                <div class="col-12 col-md-6 more-stories mb-4">
                                  <a href="<?php the_permalink (); ?>">

                                    <?php the_post_thumbnail('full', array( 'class' => 'img-fluid w-100' )) ?>

                                      <?php
              $category = get_the_category();
              echo '<div class="mt-4">';
              echo esc_html($location_title);
              echo '</div>';
              ?>

                                        <h3><?php the_title(); ?></h3>

                                        <p>
                                          <?php echo get_the_date('d/m/Y'); ?>
                                        </p>
                                  </a>

                                </div>
                                <?php endwhile; ?>

                                  <?php
            			wp_reset_postdata()	?>

                            </div>
  </div>

  <div class="col-12 col-lg-4">

    <h2 class="h3 mt-2 mb-4">More <?php echo esc_html($location_title); ?></h2>

    <section>

      <?php
    							$cat = get_field('choose_your_category');
    							$query = new WP_Query( array(

                    'posts_per_page' => 3,
                    'offset' => 4,
                    'tax_query' => array(
                      array(
                        'taxonomy' => 'category',
                        'terms' => $cat
                      ),
                    ),
    								) );
                    $count = 0;
    							while ( $query->have_posts() ) : $query->the_post();

                  $exclude[] = $post->ID;
                  $permalink = get_the_permalink();
                  $title = get_the_title();
    							?>

        <div class="col-12 p-0 mb-4">

          <?php 	if ( $count == 0 ) { ?>

            <div class="more-wrap post-<?php echo $count; ?>">
              <a class="col-12 p-0 mb-4 no-transition-link" href="<?php echo $permalink; ?>">
                <div class="row">
                  <div class="col-12 image relative mb-4">

                    <?php
                                if ( has_post_thumbnail() ) {
                                the_post_thumbnail('medium', array( 'class' => 'img-fluid w-100' ));
                                  }
                                  else {
                                  echo '<img class="img-fluid w-100" src="' . get_bloginfo( 'stylesheet_directory' )
                                    . '/src/assets/images/default-image.jpg" />';
                                  } ?>

                  </div>
                  <div class="col-8 absolute roundel grow">
                    <p class="mb-0">
                      <?php
                          $category = get_the_category();
                          echo $category[0]->cat_name;
                          ?>
                    </p>
                    <h3 class="h5">
                              <?php echo $title; ?>
                            </h3>
                  </div>
                </div>
              </a>
            </div>

            <?php	}

                      else { ?>
              <div class="more-wrap post-<?php echo $count; ?>">
                <a class="mb-4" href="<?php echo $permalink; ?>">
                  <div class="row">
                    <div class="col-4 image p-0 <?php	if ( $count == 2 ) { echo 'order-5'; }?>">

                      <?php
                              if ( has_post_thumbnail() ) {
                              the_post_thumbnail('medium', array( 'class' => 'img-fluid w-100' ));
                                }
                                else {
                                echo '<img class="img-fluid w-100" src="' . get_bloginfo( 'stylesheet_directory' )
                                  . '/src/assets/images/default-image.jpg" />';
                                } ?>

                    </div>
                    <div class="col-8">
                      <p class="mb-0">
                        <?php
                        $category = get_the_category();
                        echo $category[0]->cat_name;
                        ?>
                      </p>
                      <h3 class="h5">
                            <?php echo $title; ?>
                          </h3>
                    </div>
                  </div>
                </a>
              </div>

              <?php } ?>


        </div>

        <?php

              $count++ ?>

          <?php endwhile;

									wp_reset_postdata()

									?>

    </section>


    <section class="location-carousel">
      <?php
      $cat = get_field('choose_your_category');
       $args = array(
         'posts_per_page' => 3,
         'offset' => 7,
          'category__not_in' => array(23512,9),
         'tax_query' => array(
           array(
             'taxonomy' => 'category',
             'terms' => $cat
           ),
         ),
       );
       $loop = new WP_Query( $args ); ?>

        <div class="row mx-auto my-auto">
          <div id="locationCarousel" class="carousel slide w-100" data-bs-interval="false" data-ride="carousel">
            <div class="carousel-inner col-10 mx-auto" role="listbox">
              <?php
                $c = 0;
                $class = '';
                while ( $loop->have_posts() ) : $loop->the_post();
                $c++;
                if ( $c == 1 ) $class .= ' active';
                else $class = '';
                ?>
                <div class="carousel-item <?php echo $class; ?>">

                  <a href="<?php the_permalink(); ?>">

                    <?php if(has_post_thumbnail()){

          the_post_thumbnail('medium', array( 'class' => 'img-fluid d-block w-100' ));

      } ?>

                      <div class="bg-black pt-5 pb-3 text-center">
                        <p class="text-white">

                          <?php
        $category = get_the_category();
        echo $category[0]->cat_name;
        ?>

                        </p>
                        <h3 class="h6 text-white text-center px-4">

          <?php the_title(); ?>

        </h3>
                      </div>
                  </a>
                </div>
                <?php
       endwhile;
       ?>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#locationCarousel" data-bs-slide="prev">
              <span class="carousel-control-prev-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#locationCarousel" data-bs-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Next</span>
            </button>
            <div class="carousel-indicators pt-2">

              <?php
              $args = array(
                'posts_per_page' => 3,
                'category_name' => 'audio',
                'offset' => 7,
              );
                    $query = new WP_Query( $args );
                    ?>
                <?php if($query->have_posts()) : ?>
                  <?php $i = 0; ?>
                    <?php while($query->have_posts()) : $query->the_post(); ?>



                      <button type="button" data-bs-target="#locationCarousel" data-bs-slide-to="<?php echo $i ?>" class="<?php if($i === 0): ?>active<?php endif; ?>" aria-current="true" aria-label="Slide <?php echo $i ?>"></button>

                      <?php $i++; ?>

                        <?php endwhile ?>
                          <?php endif ?>
                            <?php wp_reset_postdata(); ?>

            </div>

          </div>
          <!-- /#locationCarousel-->

        </div>

        <?php wp_reset_postdata(); ?>

    </section>


    <section class="eats-carousel mt-5">
      <?php
             $args = array(
               'post__not_in' => $exclude,
               'posts_per_page' => 3,
               'category_name' => 'eats'
             );
             $loop = new WP_Query( $args ); ?>

        <div class="row mx-auto my-auto">
          <div class="eats-logo text-center">
            <img class="img-fluid" src="<?php echo esc_url( get_template_directory_uri() . '/src/assets/images/eats-logo.png'); ?>" alt="Eats Logo"/>
          </div>
          <div id="eatsCarousel" class="carousel slide w-100" data-bs-interval="false" data-ride="carousel">
            <div class="carousel-inner col-10 mx-auto" role="listbox">
              <?php
                      $c = 0;
                      $class = '';
                      while ( $loop->have_posts() ) : $loop->the_post();
                      $c++;
                      if ( $c == 1 ) $class .= ' active';
                      else $class = '';
                      ?>
                <div class="carousel-item <?php echo $class; ?>">

                  <a href="<?php the_permalink(); ?>">

                    <?php if(has_post_thumbnail()){

                the_post_thumbnail('medium', array( 'class' => 'img-fluid d-block w-100' ));

            } ?>


                      <div class="bg-eats pt-5 pb-3 text-center">
                        <h3 class="h6 text-white text-center px-4">

                <?php the_title(); ?>

              </h3>
                      </div>


                  </a>
                </div>
                <?php
             endwhile;
             ?>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#eatsCarousel" data-bs-slide="prev">
              <span class="carousel-control-prev-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#eatsCarousel" data-bs-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="visually-hidden">Next</span>
            </button>
            <div class="carousel-indicators pt-2">

              <?php
                    $args = array(
                      'posts_per_page' => 3,
                      'category_name' => 'audio',
                      'offset' => 7,
                    );
                          $query = new WP_Query( $args );
                          ?>
                <?php if($query->have_posts()) : ?>
                  <?php $i = 0; ?>
                    <?php while($query->have_posts()) : $query->the_post() ?>

                      <button type="button" data-bs-target="#locationCarousel" data-bs-slide-to="<?php echo $i ?>" class="<?php if($i === 0): ?>active<?php endif; ?>" aria-current="true" aria-label="Slide <?php echo $i ?>"></button>

                      <?php $i++; ?>

                        <?php endwhile ?>
                          <?php endif ?>
                            <?php wp_reset_postdata(); ?>

            </div>

          </div>
          <!-- /#locationCarousel-->

        </div>

        <?php wp_reset_postdata(); ?>

    </section>

  </div>

  <?php get_footer(); ?>
