<?php get_header(); ?>
<?php setPostViews(get_the_ID()); ?>
	<div class="content inner single singleOffer">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="breadcrump breadOffer">
                <div class="container">
                    <div class="links">
                        <a href='<?php echo esc_url( home_url( '/' ) ); ?>'>Home</a>
                        <span> / </span>
                        <a href='<?php echo esc_url( home_url( '/' ) ); ?>offer/' class="js-url"><?php echo get_post_type( get_the_ID() ); ?></a>
                        <span> / </span>
                        <h2><?php  echo (get_field('name_breadcrump')? get_field('name_breadcrump') : get_the_title()); ?></h2>
                    </div>
                    <button class="bt-filter mobileFilter">Filter</button>
                    <nav class="breadcrumb__filter js-offer-filters js-filters">
                        <div class="filterHeader mobileFilter">
                            <button class="bt-closeFilter">Close</button>
                            <span>Filter</span>
                            <a href="#" class="btReset">Reset all</a>
                        </div>
                        <div class="selects">
                            <select class="js-filter-select breadcrumb__filter__select selectCategory" data-type="cat">
                                <option value="">Category</option>
                                <?php
                                    $terms = get_terms(array('taxonomy' => 'category_offer', 'hide_empty' => 1));
                                    foreach ($terms as $term) echo '<option value="'. $term->slug .'">'. $term->name .'</option>';
                                ?>
                            </select>
                        </div>
                    </nav>
                </div>
            </div>
            <article id="post-<?php the_ID(); ?>" class="post postOffer">
                <div class="container">
                    <?php
                        $classThumb =  (!have_rows('gallery') && has_post_thumbnail())? 'thumbMode' : '' ;
                    ?>
                    <div class="contentTop <?php echo  $classThumb; ?>">
                        <div class="galleryoffers">
                            <?php $count = count(get_field('gallery')); $cont=1; if( have_rows('gallery') ): ?>
                                <div class="owl-carousel owl-offer">
                                    <?php while( have_rows('gallery') ): the_row(); 
                                        $image = get_sub_field('photo');
                                    ?>
                                        <div class="item">
                                            <div class="image">
                                                <img class="owl-lazy" data-src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
                                            </div>
                                            <div class="cont">
                                                <span class="actual"><?php echo $cont; ?></span> <span class="trace">/</span> <span class="total"><?php echo $count; ?></span>
                                            </div>
                                        </div>
                                    <?php $cont++; endwhile; ?>
                                </div>
                                <span class="swipe">Swipe to see more</span>
                            <?php else: ?>
                                <?php if(has_post_thumbnail()): ?>
                                    <div class="thumb">
                                        <?php the_post_thumbnail( 'thumb-offers-single' ); ?>
                                    </div>
                                <?php endif; ?>
                            <?php endif; ?>
                        </div>
                        <div class="cardOffer">
                            <div class="topCard">
                                <div class="storeLogo"><img src="<?php the_field('store_logo'); ?>" alt="<?php the_field('store_name'); ?>" /></div>
                                <?php
                                    $terms = get_the_terms( $post->ID, 'category_offer' );
                                ?>
                                <a href="<?php echo get_term_link($terms[0]->slug, 'category_offer'); ?>" class="categoryOffer"><?php echo $terms[0]->name; ?></a>
                                <span class="boxOff"><?php the_field('offer'); ?>%OFF</span>
                            </div>
                            <header><h1 class="h4"><?php the_title(); ?></h1></header>
                            <p><?php the_field('description'); ?></p>
                            <div class="prices">
                                <span class="before">$<?php the_field('value_before'); ?></span>
                                <span class="after">$<?php the_field('value_after'); ?></span>
                            </div>
                            <div class="count">
                                <?php echo do_shortcode('[countdown date="'.get_field('ending_date').'" format="dHMS" hour="18" minutes="54" link="false"]'); ?>
                            </div>
                            <a href="#" class="btOff bt-want">
                                <span class="text">I whant this</span>
                                <span class="price">$<?php the_field('value_after'); ?></span>
                            </a>
                            <div class="share">
                                <span class="tit">Share</span>
                                <?php echo do_shortcode('[addtoany]'); ?>
                            </div>
                        </div>
                    </div>

                    <hr>
                    <div class="contentOffer">
                        <div class="entry">
                            <div class="topEntry">
                                <div class="storeLogo"><img src="<?php the_field('store_logo'); ?>" alt="<?php the_field('store_name'); ?>" /></div>
                                <h4><?php the_field('store_name'); ?></h4>
                            </div>
                            <?php the_content(); ?>
                        </div><!-- .entry -->
                        <!-- <div class="addsidepost adds"></div> -->
                    </div>
                </div>
            </article><!-- .post -->
            <div id="offerCode" class="">
                <div class="bgofferCode"></div>
                <div class="lightbox container">
                    <div class="content">
                        <div class="topCard">
                            <div class="storeLogo"><img src="<?php the_field('store_logo'); ?>" alt="<?php the_field('store_name'); ?>" /></div>
                            <?php
                                $terms = get_the_terms( $post->ID, 'category_offer' );
                            ?>
                            <a href="<?php echo get_term_link($terms[0]->slug, 'category_offer'); ?>" class="categoryOffer"><?php echo $terms[0]->name; ?></a>
                            <span class="boxOff"><?php the_field('offer'); ?>%OFF</span>
                        </div>
                        <h4><?php the_title(); ?></h4>
                        <hr>
                        <form method="post" action="<?php bloginfo('url'); ?>/?na=s" onsubmit="return newsletter_check(this)" class="formCode formEmail">
                            <p>Submit your email to release the offer code</p>
                            <div class="contentForm">
                                <input type="hidden" name="nlang" value="">
                                <input type="hidden" name="nl[]" value="<?php the_field('select_offer'); ?>" id="offerEmail" >						
                                <input type="email" name="ne" placeholder="Email">
                                <input type="submit" value="Submit">
                            </div>
                        </form>
                        <div class="formCode formCopy hide">
                            <p>Offer code</p>
                            <div class="contentForm">
                                <input type="text" name="text" id="offerCopy" value="<?php the_field('offer_code'); ?>">
                                <button class="btCopy">Copy</button>
                            </div>
                        </div>
                    </div>
                    <button class="btCloseOffer">Close</button>
                </div>
            </div>
            <hr class="container">
			<?php
				$args = array(
					'post_type' => 'offer',
					'post__not_in' => array(get_the_ID()),
					'post_status' => 'publish',
					'posts_per_page' => 4
				);
				// The Query
				$the_query = new WP_Query( $args );
				
				// The Loop
				if ( $the_query->have_posts() ):
			?>
			<section class="relatedOffers">
				<div class="container">
                    <header class="headerSection"><h3 class="sectiontitle">Related Offers</h3></header>
                    <div class="relOffers">
                        <?php	
                            while ( $the_query->have_posts() ) {
                                $the_query->the_post();
                        ?>
                            <?php loop_offer($post->ID, 'yes'); ?>
                            
                        <?php	} ?>
                    </div>
				</div>
			</section>
			<?php 
				endif;
				/* Restore original Post Data */
				wp_reset_postdata();
            ?>
            
		<?php endwhile; endif; ?>
	</div><!-- .content.inner.single -->

<?php get_footer(); ?>