<?php
/**
 * Template Name: Home Page
 */

get_header();
?>

<main id="primary">
    <?php 
    $writer_portfolio_main_slider_wrap = absint(get_theme_mod('writer_portfolio_enable_slider', 0));
    if($writer_portfolio_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="owl-carousel">
                <?php for ($writer_portfolio_main_i=1; $writer_portfolio_main_i <= 3; $writer_portfolio_main_i++): ?>
                    <?php if ($writer_portfolio_slider_image = get_theme_mod('writer_portfolio_slider_image'.$writer_portfolio_main_i)): ?>
                        <div class="main-slider-inner-box">
                            <img src="<?php echo esc_url($writer_portfolio_slider_image); ?>" alt="<?php echo esc_attr( get_theme_mod('writer_portfolio_slider_heading'.$writer_portfolio_main_i) ); ?>">
                            <div class="main-slider-content-box wow zoomIn" data-wow-duration="2s">
                                <?php if ($writer_portfolio_heading = get_theme_mod('writer_portfolio_slider_heading' . $writer_portfolio_main_i)): ?>
                                    <h1><?php echo esc_html($writer_portfolio_heading); ?></h1>
                                <?php endif; ?>
                                <?php if ($writer_portfolio_text = get_theme_mod('writer_portfolio_slider_text'.$writer_portfolio_main_i)): ?>
                                    <p class="slider-content"><?php echo esc_html($writer_portfolio_text); ?></p>
                                <?php endif; ?>
                                <div class="main-slider-button">
                                    <?php if ( get_theme_mod('writer_portfolio_slider_button1_link'.$writer_portfolio_main_i) ||  get_theme_mod('writer_portfolio_slider_button1_text'.$writer_portfolio_main_i )) : ?><a class="slide-btn-1" href="<?php echo esc_url( get_theme_mod('writer_portfolio_slider_button1_link'.$writer_portfolio_main_i) ); ?>"><?php echo esc_html( get_theme_mod('writer_portfolio_slider_button1_text'.$writer_portfolio_main_i) ); ?></a><?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endfor; ?>
            </div>
        </section>
    <?php endif; ?>
    
   <?php 
    $writer_portfolio_main_expert_wrap = absint(get_theme_mod('writer_portfolio_enable_product_section', 0));
    if($writer_portfolio_main_expert_wrap == 1){ 
    ?>
        <section id="main-expert-wrap">
            <div class="container">
                <div class="feature-left">
                    <?php if ( get_theme_mod('writer_portfolio_product_section_heading') ) : ?><h2><?php echo esc_html( get_theme_mod('writer_portfolio_product_section_heading') ); ?></h2><?php endif; ?>
                </div>
                <div class="flex-row">
                  <?php if ( class_exists( 'WooCommerce' ) ) {
                    $args = array( 
                      'post_type' => 'product',
                      'product_cat' => get_theme_mod('writer_portfolio_product_category'),
                      'order' => 'ASC',
                      'posts_per_page' => '10'
                    );
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>         
                        <div class="product-box wow zoomIn" data-wow-duration="2s">  
                              <div class="product-box-content">
                                <div class="product-outer">
                                    <div class="product-image">
                                        <?php 
                                            if ( has_post_thumbnail() ) {
                                                echo get_the_post_thumbnail( get_the_ID(), 'shop_catalog' );
                                            } else {
                                                echo '<img src="' . esc_url(wc_placeholder_img_src()) . '" alt="Placeholder" />';
                                            }
                                        ?>
                                    </div>
                                </div>
                                <div class="main-pro-content">
                                    <h3 class="product-heading-text"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h3>
                                    <div class="price-prod">
                                         <p class="product-price">
                                            <?php echo $product->get_price_html(); ?>
                                        </p>
                                    </div>
                                </div>
                              </div>
                        </div> 
                    <?php endwhile; wp_reset_postdata(); ?>
                    <?php } ?>
                </div>
            </div>
        </section>
    <?php } ?>  
</main>
<?php
get_footer();
?>