<?php
/**
 * The template for displaying Negozio archive.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @author Dueper Design
 * @package Dueper Theme
 */

get_header(); ?>
<?php
$main_args = array(
  'post_type'=>'negozio',
  'posts_per_page'  => -1
);
$main_posts = new WP_Query($main_args);

$marker = get_field('marker','option');
$location = get_field('gmap_coor');
$address = get_field('address','option');
$map_controls = get_field('map_controls','option');
?>
<div class="container-fluid loop archive-store">
  <div class="map-store" id="map-store" itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
    <?php if ($main_posts->have_posts()) :
        while($main_posts->have_posts()) : $main_posts->the_post();
          $location = get_field('gmap_coor', get_the_ID());
          echo '<div class="marker"
              data-lat="'; echo $location['lat']; echo'"';
              echo 'data-lng="'; echo $location['lng']; echo '"';
              echo 'data-id="'; echo $id; echo '"';
              echo 'data-icon="'; echo get_template_directory_uri(); echo '/dist/images/ledial-marker.svg">';
              get_template_part('inc/teaser/_teaser', 'popup-marker');
          echo '</div>';
          $id;
        endwhile;
      endif; ?>
  </div>

  <div class="store-list">
    <?php if ($main_posts->have_posts()) :
      echo '<h1 class="store-number">';
        echo $main_posts->found_posts;
        echo _e(' negozi','blanka');
      echo '</h1>';
      while($main_posts->have_posts()) : $main_posts->the_post();
        // echo $location = get_field('gmap_coor', get_the_ID());
        echo '<div class="teaser-store" data-mh>';
          get_template_part('inc/teaser/_teaser', 'negozio');
        echo '</div>';
      endwhile;
    endif; ?>
    <?php if(function_exists('wp_pagenavi')):
      wp_pagenavi();
    endif;?>
  </div><!--row-->

  <?php if ($main_posts->have_posts()) :
    echo '<div class="store-number store-list-mobile">';
      echo $main_posts->found_posts;
      echo _e(' negozi','blanka');
    echo '</div>';
  endif; ?>
  <div class="row row-padding store-list-mobile">
    <?php if ($main_posts->have_posts()) :
      // echo '<div class="store-number">';
      //   echo $main_posts->found_posts;
      //   echo _e(' negozi','blanka');
      // echo '</div>';
      while($main_posts->have_posts()) : $main_posts->the_post();
        // echo $location = get_field('gmap_coor', get_the_ID());
        echo '<div class="col-1-1 col-xs-1-2 col-md-1-3 teaser-store" data-mh>';
          get_template_part('inc/teaser/_teaser', 'negozio');
        echo '</div>';
      endwhile;
    endif; ?>
  </div>
</div><!--container-->
<?php get_footer(); ?>

<script>
  (function($) {
    render_map()
  })
</script>