<?php
/**
 * The main template file.
 *
 * @package thehoot
 */
get_header(); ?>

<div class="container">
  <div class="row">
    <div class="col">
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php endwhile; else: ?>
          <?php // If no content, include the "No posts found" template.
                get_template_part('content', 'none'); ?>
            <?php endif; ?>
              <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

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

                <div class="my-3 page-image">

                <?php  the_post_thumbnail('large', array( 'class' => 'img-fluid w-100' )); ?>
                </div>
                <?php the_content(); ?>
                  <div>
                  </div>
                  <!-- /.post_class -->
                  <?php endwhile; endif; ?>

                    <?php if (get_posts_nav_link()!="") {
                    ?>
                      <div class="pagination">
                        <?php wp_link_pages(); ?>
                      </div>
                      <?php
                } ?>
    </div>

  <?php if (is_page( 'contact' )) { ; ?>

  <div class="col-12 col-lg-4 sidebar d-flex flex-column">

    <div class="" style="position: sticky;top: 5%;">

      <h2 class="h3 mt-2 mb-4">More Leeds</h2>

    <section>

        <?php
          $query = new WP_Query( array(
          'posts_per_page' => 1,
          'no_found_rows' => true,
          'include_children' => false,
          'category_name' => 'leeds'
            ) );
            $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">
              <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>
                        <?php
                          $category = get_the_category();
                          echo $category[0]->cat_name;
                          ?>
                      </p>
                      <h3 class="h5">
                              <?php echo $title; ?>
                            </h3>
                    </div>
                  </div>
                </a>
              </div>
          </div>

          <?php

              $count++ ?>

            <?php endwhile;

                  wp_reset_postdata(); ?>


                  <?php
                    $query = new WP_Query( array(
                    'posts_per_page' => 2,
                    'offset' => '1',
                    'no_found_rows' => true,
                    'include_children' => false,
                    'category_name' => 'leeds'
                      ) );
                      $count = 0;
                      while ( $query->have_posts() ) : $query->the_post();

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


                  <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 m-auto">
                          <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

                      $count++ ?>

                    <?php endwhile;

                          wp_reset_postdata(); ?>


                  </section>

    <?php get_template_part('/template-parts/audio-video'); ?>

      <section class="location-carousel mt-4">

      <?php
        $args = array(
        'post__not_in' => $exclude,
        'posts_per_page' => 3,
        'offset' => 9,
        'no_found_rows' => true,
        'include_children' => false,
        'category_name' => 'leeds',
         'category__not_in' => array(23512,9),
      );
      $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();

               $exclude[] = $post->ID;

               $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,
               'post__not_in' => $exclude,
               'offset' => 3,
               'no_found_rows' => true,
               'include_children' => false,
               'category_name' => 'leeds'
             );
                   $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(

             'posts_per_page' => 3,
             'no_found_rows' => true,
             'include_children' => false,
             'category_name' => 'eats',
            'post__not_in' => $exclude
           );
           $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,
                    'post__not_in' => $exclude,
                    'category_name' => 'eats',
                    '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="#eatsCarousel" 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>
            <!-- /#eatsCarousel-->
          </div>

          <?php wp_reset_postdata(); ?>

      </section>

      <?php get_template_part('/template-parts/eats-video'); ?>


        <section class="mt-4">

          <?php
              $args = array(
                'posts_per_page' => 4,
                'tax_query' => array(
                    array(
                        "taxonomy" => 'category',
                        'field' => 'slug',
                        'terms' => 'audio'
                         )
                      ),
                        'post__not_in' => $exclude
                 );
                 $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/audio-logo.png'); ?>" alt="AUdio Logo" />
              </div>
               <div id="audioCarousel" 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-audio 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="#audioCarousel" 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="#audioCarousel" 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(
                          'post__not_in' => $exclude,
                          'posts_per_page' => 4,
                          'tax_query' => array(
                                  array(
                                      "taxonomy" => "category",
                                      'field' => 'slug',
                                      'terms' => 'audio'
                                  )
                               )
                        );
                              $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="#audioCarousel" 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>
              <!-- /#audioCarousel-->

            </div>

            <?php wp_reset_postdata(); ?>

        </section>

        <?php get_template_part('/template-parts/audio-video'); ?>

  </div>

  </div>

<?php } ; ?>

    </div>
</div>

  <?php get_footer(); ?>
