<?php
/**
 * Product Category page.
 * @version   1.1.0
 */
get_header();
?>
<?php
$queried_object = get_queried_object();
$term_queried_slug = $queried_object->slug;
$term_id = $queried_object->term_id;
?>
<style>
    .masonry-column {
        padding: 0 1px;
    }

    .masonry-grid > div .thumbnail {
        margin: 5px 1px;
    }
</style>
<div class="container">

    <div class="row">
        <?php
        while (have_rows('designer_section', 20031)) : the_row();
            $banner_image = get_sub_field('banner_image', 20031);

            $hover_image = get_sub_field('designer_image', 20031);
            $term_id_post = get_sub_field('brand_name', 20031);
            if ($term_id_post == $term_id) {
                if ($banner_image) {
                    $banner_image_url = $banner_image;
                } else {
                    $banner_image_url = 'https://j11.moda/wp-content/uploads/2018/05/banner-1.jpg';
                }
                if ($hover_image) {
                    $hover_image_url = $hover_image;
                } else {
                    $hover_image_url = 'https://j11.moda/wp-content/uploads/2017/08/8-1.jpg';
                }
                ?>
                <div class="col-md-12 col-lg-12 main-img-brand" >

                    <a href="javascript:void(0)" id="banner_image_do_hover"><img src="<?php echo $banner_image_url; ?>"></a>
                    <div id="hover_show_div" class="main-div-hover" style="display:none;">
                    <img src="<?php echo $hover_image_url; ?>">
                </div>
                </div>
                
                <?php
            }


        endwhile;
        ?>
    </div>
    <div class="row masonry-grid">

        <?php
        $counter = 1;
        $limitless = 1;
        $count_pro = 1;
        $args_category = array(
            'post_type' => 'product',
            'orderby' => 'rand',
            'posts_per_page' => -1,
            'tax_query' => array(
                array(
                    'taxonomy' => 'brand',
                    'field' => 'slug',
                    'terms' => $term_queried_slug,
                ),
            ),
        );
        $wp_query_cat = new WP_Query($args_category);
        $count_posts = $wp_query_cat->post_count;
        $divide_into_three = floor($count_posts / 4);
        if($divide_into_three == 0 ){
            $divided= 1;
        }else{
            $divided=$divide_into_three;
        }
        while ($wp_query_cat->have_posts()) : $wp_query_cat->the_post();
            $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));

            if ($counter == 1) {
                ?>
                <div class="col-md-4 col-lg-3 masonry-column">
                <?php } ?>
                <div id="button_hover1<?php echo $count_pro; ?>" class="inner-div-item">
                    <a href="<?php the_permalink(); ?>" class="thumbnail"><img src="<?php echo $url; ?>"></a>
                    <div class="">

                        <div class="wish-list">
                            <?php if (( class_exists('YITH_WCWL') && class_exists('YITH_WCWL_Shortcode') ) || etheme_get_option('quick_view')) : ?>

                                <?php echo et_wishlist_btn(__('Wishlist', ETHEME_DOMAIN)); ?>
                                <?php if (etheme_get_option('quick_view')): ?>
                                    <span class="show-quickly" data-prodid="<?php echo $wp_query->ID; ?>"><?php _e('Quick View', ETHEME_DOMAIN) ?></span>
                                <?php endif ?>
                            <?php endif; ?>
                        </div>

                        <div class="pro-title">
                            <a class="pro-titlee" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </div>

                        <div class="wish-price">
                            <?php
                            /**
                             * woocommerce_after_shop_loop_item_title hook
                             *
                             * @hooked woocommerce_template_loop_rating - 5
                             * @hooked woocommerce_template_loop_price - 10
                             */
                            if (etheme_get_option('product_page_price')) {
                                do_action('woocommerce_after_shop_loop_item_title');
                            }
                            ?>
                        </div>
                        

                    </div>
                    <div class="clearfix"></div>
                    <div class="footer-btn" id="button_hover_show1<?php echo $count_pro . $slider_class; ?>" style="display:none;"> 
                        <center>
                            <a href="<?php the_field('page_url'); ?>" class="btn border-grey  product_type_" >SHOP</a>
                        </center>
                    </div>
                    <script>
                        jQuery(function () {
                            jQuery('#button_hover1<?php echo $count_pro; ?>').mouseover(function () {

                                jQuery('#button_hover_show1<?php echo $count_pro; ?>').show(50);

                            });
                            jQuery('#button_hover1<?php echo $count_pro; ?>').mouseleave(function () {

                                jQuery('#button_hover_show1<?php echo $count_pro; ?>').hide(50);

                            });

                        });
                    </script>
                </div>
                <?php if ($counter == $divided || ($limitless == $count_posts)) { ?>
                </div><?php } ?>
            <?php
            // the_title();
            $limitless++;
            $counter++;
            $count_pro ++;
            if ($counter == $divided + 1 ) {
                $counter = 1;
            }
        endwhile;
        wp_reset_query();
        ?>

    </div>
</div>
<script type="text/javascript">
    jQuery(function ()
    {
        jQuery(function () {
            jQuery('#banner_image_do_hover').mouseover(function () {

                jQuery('#hover_show_div').show();

            });
            jQuery('#banner_image_do_hover').mouseleave(function () {

                jQuery('#hover_show_div').hide();

            });

        });
    });
</script>
<?php get_footer(); ?>
