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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider" >
    <?php $interior_decor_studio_slide_pages = array();
      for ( $interior_decor_studio_count = 1; $interior_decor_studio_count <= 3; $interior_decor_studio_count++ ) {
        $interior_decor_studio_mod = intval( get_theme_mod( 'interior_decor_studio_top_slider_page' . $interior_decor_studio_count ));
        if ( 'page-none-selected' != $interior_decor_studio_mod ) {
          $interior_decor_studio_slide_pages[] = $interior_decor_studio_mod;
        }
      }
      if( !empty($interior_decor_studio_slide_pages) ) :
        $interior_decor_studio_args = array(
          'post_type' => 'page',
          'post__in' => $interior_decor_studio_slide_pages,
          'orderby' => 'post__in'
        );
        $interior_decor_studio_query = new WP_Query( $interior_decor_studio_args );
        if ( $interior_decor_studio_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $interior_decor_studio_query->have_posts() ) : $interior_decor_studio_query->the_post(); ?>
        <div class="row slider-box m-0">
          <div class="col-lg-6 col-md-6 slider-content-box">
            <div class="slider-inner-box">
              <?php if ( get_theme_mod('interior_decor_studio_slider_short_heading') != "" ) {?>
                <h2 class="m-0"><?php echo esc_html(get_theme_mod('interior_decor_studio_slider_short_heading')); ?></h2>
              <?php }?>
              <h3 class="m-0"><?php the_title(); ?></h3>
              <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(),esc_attr(get_theme_mod('interior_decor_studio_slider_excerpt_length', 20)) )); ?><p>
              <div class="slide-btn mt-4">
                <?php if ( get_theme_mod('interior_decor_studio_slider_button_text') != "" || get_theme_mod('interior_decor_studio_slider_button_text') != "" ) {?>
                  <span class="extra-btn"><a href="<?php echo esc_url(get_theme_mod('interior_decor_studio_slider_button_text_url')); ?>"><?php echo esc_html(get_theme_mod('interior_decor_studio_slider_button_text')); ?></a></span>
                <?php }?>
                <span class="read-btn"><a href="<?php the_permalink(); ?>"><?php esc_html_e('Read more','interior-decor-studio'); ?></a></span>
              </div>
            </div>
          </div>
          <div class="col-lg-6 col-md-6  slider-image ps-0 pe-0 align-self-center">
            <?php if(has_post_thumbnail()){
              the_post_thumbnail();
              } else{?>
              <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
            <?php } ?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
  </section>

  <section class="featured py-5">
    <div class="container">
      <?php if(get_theme_mod('interior_decor_studio_services_sec_category','')){ ?>
        <div class="box-ser ">
          <div class="ser-heading text-start mb-4">
            <?php if(get_theme_mod('interior_decor_studio_services_title') != ''){ ?>
              <h3 class="main-heading "><?php echo esc_html(get_theme_mod('interior_decor_studio_services_title')); ?></h3>
            <?php }?>
            <?php if(get_theme_mod('interior_decor_studio_services_heading') != ''){ ?>
              <h4 class="main-heading"><?php echo esc_html(get_theme_mod('interior_decor_studio_services_heading')); ?></h4>
            <?php }?>
          </div>
          <div class="owl-carousel">
            <?php
              $interior_decor_studio_services_cat = get_theme_mod('interior_decor_studio_services_sec_category','');
              if($interior_decor_studio_services_cat){
                $interior_decor_studio_page_query5 = new WP_Query(array( 'category_name' => esc_html($interior_decor_studio_services_cat,'interior-decor-studio'),'posts_per_page' => 4));
                $i=1;
                while( $interior_decor_studio_page_query5->have_posts() ) : $interior_decor_studio_page_query5->the_post(); ?>
                  <div class="feature-box mb-3">
                    <div class="featured-img text-center">
                     <?php if (has_post_thumbnail()) { ?><img src="<?php the_post_thumbnail_url('full'); ?>" /><?php } else { ?><div class="project-bg"></div> <?php } ?>
                    </div>
                    <div class="ser-content text-center">
                      <h4 class="mb-4 mt-2 text-start"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                      <?php if( get_post_meta($post->ID, 'interior_decor_studio_text_1', true) || get_post_meta($post->ID, 'interior_decor_studio_project_address', true) ) {?>
                        <div class="row m-0">
                          <div class="col-lg-3 col-md-9 col-sm-4 col-4 ps-0 small-image align-self-center">
                            <?php
                            // Assuming you have the post ID
                            $post_id = get_the_ID();

                            // Retrieve the image URL from the custom field
                            $image_id = get_post_meta($post_id, 'interior_decor_studio_image', true);
                            $image_url = wp_get_attachment_url($image_id);
                            ?>
                            <?php if ($image_url) : ?>
                                <img src="<?php echo esc_url($image_url); ?>" alt="Project Image"/>
                            <?php endif; ?>
                          </div>
                          <div class="col-lg-9 col-md-9 col-sm-8 col-8 box-small text-start ps-0">
                            <?php if( get_post_meta($post->ID, 'interior_decor_studio_text_1', true) ) {?>
                              <h6 class="heading p-0"><?php echo esc_html(get_post_meta($post->ID,'interior_decor_studio_text_1',true)); ?></h6>
                            <?php }?>
                            <?php if( get_post_meta($post->ID, 'interior_decor_studio_project_address', true) ) {?>
                              <p class="small-text p-0 m-0"><?php echo esc_html(get_post_meta($post->ID,'interior_decor_studio_project_address',true)); ?></p>
                            <?php }?>
                          </div>
                        </div>
                      <?php }?>
                    </div>
                  </div>
                <?php $i++; endwhile;
              wp_reset_postdata();
            } ?>
          </div>
        </div>
      <?php }?>
    </div>
  </section>
  <section id="page-content">
    <div class="container">
      <div class="py-5">
        <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              the_content();
            endwhile;
          endif;
        ?>
      </div>
    </div>
  </section>
</main>

<?php get_footer(); ?>