<?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 Astronomy Store
 */

get_header(); ?>

<div id="content" >
  <?php
    $astronomy_store_hidcatslide = get_theme_mod('astronomy_store_hide_categorysec', false);
    $astronomy_store_slidersection = get_theme_mod('astronomy_store_slidersection');

    if ($astronomy_store_hidcatslide && $astronomy_store_slidersection) { ?>
    <section id="slider">
      <div class="owl-carousel owl-theme slider-sec">
        <?php if( get_theme_mod('astronomy_store_slidersection',false) ) { ?>
          <?php $astronomy_store_queryvar = new WP_Query('cat='.esc_attr(get_theme_mod('astronomy_store_slidersection',false)));
            while( $astronomy_store_queryvar->have_posts() ) : $astronomy_store_queryvar->the_post(); ?>
          <div class="item">
            <div class="content d-flex align-items-center">
              <?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', 'astronomy-store'); ?>"/>
                <?php } ?>
                <div class="sliderbox">
                  <?php
                    $trimexcerpt = get_the_excerpt();
                    $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 15 );
                    echo ' <p class="text-slider text-white mb-2 text-start">' . esc_html( $shortexcerpt ) . '</p>'; 
                  ?>
                    <h1 class="title-slider text-white mb-4 text-start">
                      <a href="<?php echo esc_url( get_permalink() );?>"><?php the_title(); ?></a>
                    </h1>
                    <div class="gap-4 text-start">
                      <?php if ( get_theme_mod('astronomy_store_button_text','true') != "" || get_theme_mod('astronomy_store_button_link_slider') != '') { ?>
                        <a href="<?php echo esc_url(get_theme_mod('astronomy_store_button_link_slider')!= '') ? esc_url(get_theme_mod('astronomy_store_button_link_slider')) : esc_url(get_permalink()); ?>" class="button-slider redmor btn text-white me-2 mb-3" style="background-color: var(--first-theme-color);">
                        <?php echo esc_html(get_theme_mod('astronomy_store_button_text',__('Read More','astronomy-store'))); ?>
                      </a>
                      <?php }?>
                      <?php if ( get_theme_mod('astronomy_store_button2_text','true') != "" && get_theme_mod('astronomy_store_button2_url') != '') { ?>
                        <a href="<?php echo esc_url(get_theme_mod('astronomy_store_button2_url')); ?>" class="button-slider cont-us btn text-white mb-3" style="background-color: #46567a;">
                          <?php echo esc_html(get_theme_mod('astronomy_store_button2_text',__('Contact Us','astronomy-store'))); ?>
                        </a>
                      <?php }?>
                    </div>
                </div>
              <div class="overlayer"></div>
            </div>
          </div>
          <?php endwhile; wp_reset_postdata(); ?>
        <?php } ?>
      </div>
    </section>
  <?php } ?>

  <?php
    $astronomy_store_hidepageboxes = get_theme_mod('astronomy_store_disabled_pgboxes', false);
    $astronomy_store_services_cat = get_theme_mod('astronomy_store_services_cat');
    if( $astronomy_store_hidepageboxes && $astronomy_store_services_cat){
  ?>
    
  <section id="service" class="py-5">
    <div class="text-center w-50 mx-auto d-block">
      <?php if( get_theme_mod('astronomy_store_service_heading') != '' ){ ?>
        <h2 class="service-text mb-3 fs-5 text-capitalize" style="color: #d3363a;">
        <?php echo esc_html(get_theme_mod('astronomy_store_service_heading')); ?>
        </h2>
      <?php }?>
      <?php if( get_theme_mod('astronomy_store_service_subheading') != '' ){ ?>
        <h3 class="section-title fs-2 mb-4 fw-bolder text-uppercase" style="color: #141414;">
        <?php echo esc_html(get_theme_mod('astronomy_store_service_subheading')); ?>
        </h3>
      <?php }?>
    </div>
    <div class="pt-3">
      <div class="container">
        <div class="row">
        <?php if( get_theme_mod('astronomy_store_services_cat',false) ) { ?>
          <?php $astronomy_store_queryvar = new WP_Query('cat='.esc_attr(get_theme_mod('astronomy_store_services_cat',true)));
            while( $astronomy_store_queryvar->have_posts() ) : $astronomy_store_queryvar->the_post(); ?>

          <div class="col-lg-2 col-md-4 colume-row">
            <div class="services-box rounded-4 d-flex" style="background-image: url(<?php the_post_thumbnail_url( 'full' ); ?>);">
              <div class="content px-4 py-4 w-100 h-100">
                <div>
                  <h4 class="text-uppercase fw-semibold text-white d-block mb-3"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                </div>
              </div>
            </div>
          </div>

          <?php endwhile; wp_reset_postdata(); ?>
          <?php } ?>
        </div>
      </div>
    </div>
  </section>
  <?php }?>

</div>

<?php get_footer(); ?>