<?php
/**
 * Template Name: Home
 *
 * Template for displaying a page without sidebar even if a sidebar widget is published.
 *
 * @package BBase_Code
 */


defined( 'ABSPATH' ) || exit;

get_header(); the_post(); ?>

<?php if( have_rows('s1_slider_list') ): ?>
<div id="home-s1" class="home-slider" data-aos="fade-up">
    <ul class="list-slider">
        <?php while( have_rows('s1_slider_list') ) : the_row(); ?>
        <li class="img">
            <a href="<?php the_sub_field( 'link' ) ?>">
                <img src="<?php the_sub_field( 'image' ) ?>" alt="Slide">
            </a>
        </li>
        <?php endwhile; ?>
    </ul>
</div>
<?php endif; ?>

<?php 
$terms = get_terms( array(
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
) );
if( $terms ): ?>
<div id="home-new-s2" class="home-new-cat">
    <div class="container">
        <h2 class="title"><?php the_field( 's4_title' ) ?></h2>
        <div class="list-new-cat">
        <?php foreach ( $terms as $term ) { ?>
            <div class="item">
                <div class="img">
                    <a href="<?php echo get_term_link( $term ) ?>"><img src="<?php echo get_field( 'images', $term ) ?>" alt="<?php echo $term->name; ?>"></a>
                </div>
                <a href="<?php echo get_term_link( $term ) ?>" class="name"><?php echo $term->name; ?></a>
            </div>
        <?php } ?>
        </div>
    </div>
</div>
<?php endif; ?>

<div id="home-s5" class="home-product-featured">
    <div class="container">
        <h2 class="title" data-aos="zoom-in-up"><?php the_field( 's5_title' ) ?></h2>

        <div class="product-list">
            <?php 
                $s5_products = get_field( 's5_products' );
                $args = array(
                    'post_type'              => array( 'product' ),
                    'posts_per_page'         => '8',
                    'post__in'               => $s5_products
                );

                $query_featured = new WP_Query( $args );
                if ( $query_featured->have_posts() ) {
                    while ( $query_featured->have_posts() ) { $query_featured->the_post();
                        get_template_part( 'template-parts/content', 'product' );
                    }
                }
                wp_reset_postdata();
                wp_reset_query();
            ?>
        </div>
    </div>
</div>

<div id="home-s11" class="home-product-new">
    <div class="container">
        <h2 class="title" data-aos="zoom-in-up"><?php the_field( 's11_title' ) ?></h2>

        <div class="product-list">
            <?php 
                $args = array(
                    'post_type'              => array( 'product' ),
                    'posts_per_page'         => '8',
                );

                $query_new = new WP_Query( $args );
                if ( $query_new->have_posts() ) {
                    while ( $query_new->have_posts() ) { $query_new->the_post();
                        get_template_part( 'template-parts/content', 'product' );
                    }
                }
                wp_reset_postdata();
                wp_reset_query();
            ?>
        </div>
    </div>
</div>

<div id="home-s6" class="home-partner">
    <div class="container">
        <h2 class="title" data-aos="fade-up"><?php the_field( 's6_title' ) ?></h2>
    </div>

    <div class="wrap">
        <div class="left img" data-aos="fade-right">
            <a href="#" class="video-wrap">
                <img src="<?php the_field( 's6_image' ) ?>" alt="<?php the_field( 's6_title' ) ?>" />
            </a>
        </div>
        <div class="right" data-aos="fade-left">
            <div class="content"><?php the_field( 's6_content' ) ?></div>
        </div>
    </div>
</div>

<div id="home-s3" class="home-used">
    <div class="container">
        <h2 class="title" data-aos="zoom-in-up"><?php the_field( 's3_title' ) ?></h2>

        <?php if( have_rows('s3_list_used') ): ?>
        <div class="list-used" data-aos-delay="100">

            <?php while( have_rows('s3_list_used') ) : the_row(); ?>
            <div class="item" data-aos="fade-up">
                <div class="img"><img src="<?php the_sub_field( 'image' ) ?>" alt="<?php esc_html( get_sub_field( 'title' ) ) ?>"></div>
                <h4><?php the_sub_field( 'title' ) ?></h4>
                <div class="des"><?php the_sub_field( 'description' ) ?></div>
            </div>
            <?php endwhile; ?>

        </div>
        <?php endif; ?>
    </div>
</div>

<div id="home-s7" class="home-news">
    <div class="container">
        <h2 class="title" data-aos="fade-up"><?php the_field( 's7_title' ) ?></h2>

        <div class="list-news" data-aos="fade-up">
        <?php 
            $args = array(
                'post_type'              => array( 'post' ),
                'posts_per_page'         => '3',
            );

            $query = new WP_Query( $args );
            if ( $query->have_posts() ) {
                while ( $query->have_posts() ) { $query->the_post();
                    get_template_part( 'template-parts/content', get_post_type() );
                }
            }
            wp_reset_postdata();
        ?>
        </div>

        <?php render_link( get_field( 's7_link' ), 'viewmore' ) ?>
    </div>
</div>

<div id="home-s9" class="home-faqs">
    <div class="container">
        <h2 class="title" data-aos="fade-up"><?php the_field( 's9_title' ) ?></h2>

        <div class="content" data-aos="fade-up">
            <img src="<?php the_field( 's9_image' ) ?>" alt="<?php esc_html( get_field( 's9_title' ) ) ?>" />
            <h2 class="h1"><?php the_field( 's9_title_2' ) ?></h2>

            <?php if( have_rows('s_9list_faqs') ): ?>
            <div class="accordion" id="accordionExample">
                <?php while( have_rows('s_9list_faqs') ) : the_row(); ?>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="heading<?php echo get_row_index(); ?>">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<?php echo get_row_index(); ?>" aria-expanded="true" aria-controls="collapse-<?php echo get_row_index(); ?>">
                            <?php the_sub_field( 'question' ) ?>
                        </button>
                    </h2>
                    <div id="collapse-<?php echo get_row_index(); ?>" class="accordion-collapse collapse" aria-labelledby="heading-<?php echo get_row_index(); ?>" data-bs-parent="#accordionExample">
                        <div class="accordion-body"><?php the_sub_field( 'answer' ) ?></div>
                    </div>
                </div>
                <?php endwhile; ?>

            </div>
            <?php endif; ?>

        </div>
    </div>
</div>

<div id="home-s10" class="home-contact">
    <div class="container">
        <h2 class="title"><?php the_field( 's10_title' ) ?></h2>
        
        <div class="row">
            <div class="col-md-5" data-aos="fade-left">                
                <div class="text"><?php the_field( 's10_description' ) ?></div>

                <ul class="site-info">
                    <li class="address"><?php the_field( 'address', 'option' ) ?></li>
                    <li class="email"><?php the_field( 'header_email', 'option' ) ?></li>
                    <li class="website"><?php the_field( 'header_fax', 'option' ) ?></li>
                    <li class="phone"><?php the_field( 'header_phone', 'option' ) ?></li>
                </ul>
            </div>

            <div class="col-md-7" data-aos="fade-right">
                <div class="contact-form"><?php echo do_shortcode( get_field( 's10_contact_form_shortcode' ) ) ?></div>
            </div>
        </div>
    </div>
</div>

<?php get_footer() ?>