<?php
/**
 * Template Name: Custom Home Page
 */
get_header(); ?>

<main id="content">
  <?php if( get_option('fashion_designer_studio_slider_arrows', false) !== 'off'){ ?>
    <section id="slider">
      <div class="container slider-overlay">
        <div class="row">
          <div class="col-lg-1 col-md-1 col-sm-1 pe-md-0 links text-center text-md-start">
            <?php if( get_option('header_social_icon_enable',false) != 'off'){ ?>
             <?php                  
                  $fashion_designer_studio_header_fb_target = esc_attr(get_option('fashion_designer_studio_header_fb_target','true'));
                  $fashion_designer_studio_header_twt_target = esc_attr(get_option('fashion_designer_studio_header_twt_target','true'));
                  $fashion_designer_studio_header_ut_target = esc_attr(get_option('fashion_designer_studio_header_ut_target','true'));
                  $fashion_designer_studio_header_ins_target = esc_attr(get_option('fashion_designer_studio_header_ins_target','true'));
                 ?> 
            <div class="linksbox">
              <?php if( get_theme_mod('fashion_designer_studio_facebook') != ''){ ?>
                <a target="<?php echo $fashion_designer_studio_header_fb_target !='off' ? '_blank' : '' ?>" href="<?php echo esc_url(get_theme_mod('fashion_designer_studio_facebook','')); ?>"><span class="me-3"><?php esc_html_e('Facebook','fashion-designer-studio'); ?></span>
                </a>
              <?php }?>
              <?php if( get_theme_mod('fashion_designer_studio_twitter') != ''){ ?>
                <a target="<?php echo $fashion_designer_studio_header_twt_target !='off' ? '_blank' : '' ?>" href="<?php echo esc_url(get_theme_mod('fashion_designer_studio_twitter','')); ?>"><span class="me-3"><?php esc_html_e('Twitter','fashion-designer-studio'); ?></span>
                </a>
              <?php }?>
              <?php if( get_theme_mod('fashion_designer_studio_youtube') != ''){ ?>
                <a target="<?php echo $fashion_designer_studio_header_ut_target !='off' ? '_blank' : '' ?>" href="<?php echo esc_url(get_theme_mod('fashion_designer_studio_youtube','')); ?>"><span class="me-3"><?php esc_html_e('Youtube','fashion-designer-studio'); ?></span>
                </a>
              <?php }?>
               <?php if( get_theme_mod('fashion_designer_studio_instagram') != ''){ ?>
                <a target="<?php echo $fashion_designer_studio_header_ins_target !='off' ? '_blank' : '' ?>" href="<?php echo esc_url(get_theme_mod('fashion_designer_studio_instagram','')); ?>"><?php esc_html_e('Instagram','fashion-designer-studio'); ?>
                </a>
              <?php }?>
            </div>
            <?php }?>
          </div>
          <div class="col-lg-11 col-md-11 col-sm-11 ps-0 pe-0">
            <div id="carouselExampleAutoplaying" class="carousel slide" data-bs-ride="carousel"> 
              <?php $fashion_designer_studio_slider_count = get_theme_mod('fashion_designer_studio_slider_count'); ?>
              <?php
                for ( $i = 1; $i <= $fashion_designer_studio_slider_count; $i++ ) {
                  $mod =  get_theme_mod( 'fashion_designer_studio_post_setting' . $i );
                  if ( 'page-none-selected' != $mod ) {
                    $fashion_designer_studio_slide_post[] = $mod;
                  }
                }
                 if( !empty($fashion_designer_studio_slide_post) ) :
                $args = array(
                  'post_type' =>array('post'),
                  'post__in' => $fashion_designer_studio_slide_post,
                  'ignore_sticky_posts'  => true, // Exclude sticky posts by default
                );

                 // Check if specific posts are selected
                if (empty($fashion_designer_studio_slide_post) && is_sticky()) {
                  $args['post__in'] = get_option('sticky_posts');
                }

                $query = new WP_Query( $args );
                if ( $query->have_posts() ) :
                  $i = 1;
              ?>
              <div class="carousel-inner" role="listbox">
                <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
                <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                   <?php if(has_post_thumbnail()){ ?>
                      <img src="<?php the_post_thumbnail_url('full'); ?>"/>
                    <?php }else{?>
                      <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/slider.jpg" alt="" />
                    <?php } ?>
                  <div class="carousel-caption slider-inner">
                    <?php if (get_theme_mod('fashion_designer_studio_slide_heading') != '') { ?>
                      <h3 class="slider-short-title"><?php echo esc_html(get_theme_mod('fashion_designer_studio_slide_heading', '')); ?></h3>
                    <?php } ?>
                    <h2 class="slider-title"><?php the_title();?></h2>
                    <?php if( get_option('fashion_designer_studio_slider_excerpt_show_hide',true) != 'off'){ ?>
                      <p class="slider-excerpt mb-0"><?php echo wp_trim_words(get_the_content(), get_theme_mod('fashion_designer_studio_slider_excerpt_count',30) );?></p>
                    <?php } ?>
                    <div class="home-btn my-4">
                      <a class="py-md-3 px-md-4 py-2 px-4" href="<?php the_permalink(); ?>"><?php echo esc_html(get_theme_mod('fashion_designer_studio_slider_read_more',__('SHOP NOW','fashion-designer-studio'))); ?></a>
                    </div>
                  </div>
                </div>
                <?php $i++; endwhile;
                wp_reset_postdata();?>
              </div>
              <?php else : ?>
              <div class="no-postfound"></div>
                <?php endif;
              endif;?>
              <a class="carousel-control-prev" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fa fa-chevron-left"></i></span>
              </a>
              <a class="carousel-control-next" type="button" data-bs-target="#carouselExampleAutoplaying" data-bs-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"><i class="fa fa-chevron-right"></i></span>
              </a>
            </div>
          </div>
        </div>
      </div>
      <div class="clearfix"></div>
    </section>
  <?php }?>
<?php if( get_option('fashion_designer_studio_section_show_hide', false) !== 'off'){ ?>
  <section id="home-mission" class="py-5">
    <div class="container">
      <div class="row pt-4">
        <?php
          $project_category=  get_theme_mod('fashion_designer_studio_mission_category_setting');
          $fashion_designer_studio_mission_order = get_theme_mod('fashion_designer_studio_mission_order_type','descending');
          if($project_category){
            $fashion_designer_studio_args = array( 

              'category_name' => esc_html($project_category ,'fashion-designer-studio'),

              'posts_per_page' => get_theme_mod('fashion_designer_studio_category_count'),

              'order'          => 'DESC',
            );
          // Adjust ordering based on user selection
            if ($fashion_designer_studio_mission_order == 'ascending') {
              $fashion_designer_studio_args['order'] = 'ASC';
            } else if ($fashion_designer_studio_mission_order == 'a-to-z') {
              $fashion_designer_studio_args['orderby'] = 'title';
              $fashion_designer_studio_args['order'] = 'ASC';
            } else if ($fashion_designer_studio_mission_order == 'z-to-a') {
              $fashion_designer_studio_args['orderby'] = 'title';
              $fashion_designer_studio_args['order'] = 'DESC';
            }
          $page_query = new WP_Query($fashion_designer_studio_args);?>
            <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
              <div class="col-lg-4 col-md-4 col-sm-4">
                <div class="box mb-4 wow zoomIn">
                  <?php if(has_post_thumbnail()){ ?>
                    <?php the_post_thumbnail(); ?>
                  <?php }?>
                  <div class="box-content">
                    <h3 class="title m-0"><?php the_title();?></h3>
                  </div>
                </div>
              </div>
            <?php endwhile;
          wp_reset_postdata();
        }?>
      </div>
    </div>
  </section>
<?php }?>
<section id="custom-page-content" <?php if ( have_posts() && trim( get_the_content() ) !== '' ) echo 'class="pt-3"'; ?>>
    <div class="container">
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; ?>
    </div>
  </section>
</main>

<?php get_footer(); ?>