<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Classic Barbershop
 */

get_header(); ?>

<div id="content" >

  <?php
    $classic_barbershop_hidepageboxes = get_theme_mod('classic_barbershop_slider', false);
    $classic_barbershop_catData = get_theme_mod('classic_barbershop_slider_cat');

    if ($classic_barbershop_hidepageboxes && $classic_barbershop_catData) { ?>
    <section id="slider-cat">
        <div class="slideimg">
            <div class="container sliderbox">
                <div class="owl-carousel m-0">
                    <?php
                    $classic_barbershop_page_query = new WP_Query(
                        array(
                            'category_name' => esc_attr($classic_barbershop_catData),
                            'posts_per_page' => -1, 
                        )
                    );
                    while ($classic_barbershop_page_query->have_posts()) : $classic_barbershop_page_query->the_post(); ?>
                        <div class="row">
                            <div class="col-lg-7 col-md-6 col-12 align-self-center mb-md-5 mb-2">
                                <div class="text-content pe-lg-5">
                                    <?php if(get_theme_mod('classic_barbershop_slider_top_text') != ''){ ?>
                                        <p class="slider-text mb-0"><?php echo esc_html(get_theme_mod('classic_barbershop_slider_top_text')); ?></p>
                                    <?php }?>
                                    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                    <?php
                                    $classic_barbershop_trimexcerpt  = get_the_excerpt();
                                    $classic_barbershop_shortexcerpt = wp_trim_words($classic_barbershop_trimexcerpt, $num_words = 50);
                                    echo '<p class="slider-content mt-3">' . esc_html($classic_barbershop_shortexcerpt) . '</p>';
                                    ?>
                                    <div class="sliderbtn mt-lg-4">
                                        <?php 
                                        $classic_barbershop_button_text = get_theme_mod('classic_barbershop_button_text', 'Discover More Us');
                                        $classic_barbershop_button_link = get_theme_mod('classic_barbershop_button_link_slider', ''); 
                                        if (empty($classic_barbershop_button_link)) {
                                            $classic_barbershop_button_link = get_permalink();
                                        }
                                        if (!empty($classic_barbershop_button_text) || !empty($classic_barbershop_button_link)) { ?>
                                            <div class="slide-btn">
                                                <a href="<?php echo esc_url($classic_barbershop_button_link); ?>">
                                                    <?php echo esc_html($classic_barbershop_button_text); ?>
                                                    <span class="screen-reader-text"><?php echo esc_html($classic_barbershop_button_text); ?></span>
                                                </a>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-5 col-md-6 col-12 align-self-center mb-5">
                                <div class="imagebox">
                                    <?php if(has_post_thumbnail()){
                                      the_post_thumbnail('full');
                                      } else{?>
                                      <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'classic-barbershop'); ?>"/>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php endwhile;
                    wp_reset_postdata();
                    ?>
                </div>
            </div>
        </div>
    </section>
  <?php } ?>

  <?php
    $classic_barbershop_hidepageboxes = get_theme_mod('classic_barbershop_disabled_pgboxes',false);
    if( $classic_barbershop_hidepageboxes != ''){
  ?>
  <div id="about_section" class="my-5 mx-3 mx-md-0">
    <div class="container">
      <div class="row">
        <?php if( get_theme_mod('classic_barbershop_about_pageboxes',false)) { ?>
          <?php $classic_barbershop_querymed = new WP_query('page_id='.esc_attr(get_theme_mod('classic_barbershop_about_pageboxes',false)) ); ?>
            <?php while( $classic_barbershop_querymed->have_posts() ) : $classic_barbershop_querymed->the_post(); ?>
            <div class="col-lg-6 col-md-6 pe-md-5"> 
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-6">
                        <div class="product-img">
                            <div class="mb-3">
                                <?php if (empty(get_theme_mod('classic_barbershop_discount_sale_img1'))) { ?>
                                    <div class="default-bg"></div>
                                <?php } else { ?>
                                    <img src="<?php echo esc_url(get_theme_mod('classic_barbershop_discount_sale_img1')); ?>" alt="<?php echo esc_attr( 'image', 'classic-barbershop'); ?>" />
                                <?php } ?>
                            </div>
                            <div class="mb-3">
                                <?php if (empty(get_theme_mod('classic_barbershop_discount_sale_img2'))) { ?>
                                    <div class="default-bg"></div>
                                <?php } else { ?>
                                    <img src="<?php echo esc_url(get_theme_mod('classic_barbershop_discount_sale_img2')); ?>" alt="<?php echo esc_attr( 'image', 'classic-barbershop'); ?>" />
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-6">
                        <div class="product-img mt-4">
                            <div class="mb-3">
                                <?php if (empty(get_theme_mod('classic_barbershop_discount_sale_img3'))) { ?>
                                    <div class="default-bg"></div>
                                <?php } else { ?>
                                    <img src="<?php echo esc_url(get_theme_mod('classic_barbershop_discount_sale_img3')); ?>" alt="<?php echo esc_attr( 'image', 'classic-barbershop'); ?>" />
                                <?php } ?>
                            </div>
                            <div class="mb-3">
                                <?php if (empty(get_theme_mod('classic_barbershop_discount_sale_img4'))) { ?>
                                    <div class="default-bg"></div>
                                <?php } else { ?>
                                    <img src="<?php echo esc_url(get_theme_mod('classic_barbershop_discount_sale_img4')); ?>" alt="<?php echo esc_attr( 'image', 'classic-barbershop'); ?>" />
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 col-md-6 my-3">
                <div class="text-inner-box">
                    <?php if( get_theme_mod('classic_barbershop_about_title') != '' ){ ?>
                        <i class="head-icon fas fa-cut ps-4 mb-2"></i>
                        <p class="abt-title mb-3 text-uppercase">
                        <?php echo esc_html(get_theme_mod('classic_barbershop_about_title')); ?>
                      </p>
                    <?php }?>
                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                    <p><?php echo esc_html( wp_trim_words( get_the_content(), 60, '...' ) );  ?></p>
                    <div class="abt-btn mt-4">
                      <a href="<?php the_permalink(); ?>"><?php esc_html_e('More About Us','classic-barbershop'); ?></a><span class="screen-reader-text"><?php esc_html_e('More About Us','classic-barbershop'); ?></span>
                    </div>
                </div>
            </div>
          <?php endwhile; wp_reset_postdata(); ?>
        <?php }?>
        <div class="clear"></div>
      </div>
    </div>
  </div>
  <?php }?>

</div>
<?php get_footer(); ?>