<?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 Marketing Agency
 */

get_header(); ?>

<div id="content" >

<?php
$classic_marketing_agency_hidepageboxes = get_theme_mod('classic_marketing_agency_slider', false);
$classic_marketing_agency_catData = get_theme_mod('classic_marketing_agency_slider_catData');

if ($classic_marketing_agency_hidepageboxes && $classic_marketing_agency_catData) {
    $classic_marketing_agency_slidepage_query = new WP_Query(array(
        'category_name' => esc_attr($classic_marketing_agency_catData),
        'posts_per_page' => -1,
    ));
    if ($classic_marketing_agency_slidepage_query->have_posts()) :
?>
    <section id="slider-cat">
        <div class="slideimg">
            <div class="container sliderbox">
                <div class="row m-0">
                    <div class="col-lg-6 col-md-6 col-12">
                        <div class="text-content slider-slide-content">
                            <div class="owl-carousel">
                                <?php while ($classic_marketing_agency_slidepage_query->have_posts()) : $classic_marketing_agency_slidepage_query->the_post(); ?>
                                    <div class="item">
                                        <?php if (get_theme_mod('classic_marketing_agency_slider_small_title', 'classic-marketing-agency') != '') { ?>
                                            <p class="slider-smalltitle text-uppercase"><?php echo esc_html(get_theme_mod('classic_marketing_agency_slider_small_title', 'classic-marketing-agency')); ?></p>
                                        <?php } ?>
                                        <div class="text-inner-box">
                                            <h1 class="text-uppercase"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                            <div class="search-box">
                                                <?php get_search_form(); ?>
                                            </div>
                                            <div class="services-categories mt-lg-4 mt-2">
                                                <span class="category text-uppercase"><?php esc_html_e('POPULAR SEARCH', 'classic-marketing-agency'); ?></span>
                                                <?php 
                                                $classic_marketing_agency_num_service_categories = get_theme_mod('classic_marketing_agency_num_service_categories', 5);

                                                $classic_marketing_agency_service_categories = get_terms(array(
                                                    'taxonomy' => 'category', 
                                                    'hide_empty' => false,
                                                    'number' => $classic_marketing_agency_num_service_categories, 
                                                ));

                                                if (!empty($classic_marketing_agency_service_categories) && !is_wp_error($classic_marketing_agency_service_categories)) {
                                                    foreach ($classic_marketing_agency_service_categories as $classic_marketing_agency_service_category) {
                                                        echo '<a href="' . esc_url(get_term_link($classic_marketing_agency_service_category)) . '" class="category-link">' . esc_html($classic_marketing_agency_service_category->name) . '</a> ';
                                                    }
                                                } else {
                                                    echo '<span class="no-category">' . esc_html__('No service categories found.', 'classic-marketing-agency') . '</span>';
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>
                        <div class="slide-cat mb-3">
                            <div class="owl-carousel owl-theme">
                                <?php rewind_posts(); // Reset the loop ?>
                                <?php while ($classic_marketing_agency_slidepage_query->have_posts()) : $classic_marketing_agency_slidepage_query->the_post(); ?>
                                    <div class="slider-imagebox owl-item">
                                        <?php if (has_post_thumbnail()) : ?>
                                            <a href="<?php the_permalink(); ?>" class="thumbnail-link">
                                                <?php the_post_thumbnail('thumbnail-size', array('class' => 'thumbnail-img')); ?>
                                                <div class="hover-overlay"></div> 
                                            </a>
                                        <?php else : ?>
                                            <div class="slide-img-color"><div class="hover-overlay"></div></div>
                                        <?php endif; ?>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-12 slider-img-col">
                        <div class="imagebox slider-slide-content">
                            <div class="owl-carousel">
                                <?php rewind_posts(); // Reset the loop ?>
                                <?php while ($classic_marketing_agency_slidepage_query->have_posts()) : $classic_marketing_agency_slidepage_query->the_post(); ?>
                                    <div class="items">
                                        <div class="slide-thumbbx">
                                            <?php if (has_post_thumbnail()) {
                                                the_post_thumbnail();
                                            } else {
                                                echo '<div class="slide-thumbbx-color"></div>';
                                            } ?>
                                        </div>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php
    endif; // end have_posts check
    wp_reset_postdata(); // Reset post data
}
?>

<?php
$classic_marketing_agency_hidepageboxes = get_theme_mod('classic_marketing_agency_disabled_pgboxes', false);
$classic_marketing_agency_blog_cat = get_theme_mod('classic_marketing_agency_blog_cat');
$classic_marketing_agency_num_services = get_theme_mod('classic_marketing_agency_num_services', 3);

if ($classic_marketing_agency_hidepageboxes && $classic_marketing_agency_blog_cat) {
?>
    <section id="service_section" class="my-5 text-center">
        <div class="container">
            <div class="blog_bx mx-lg-5 px-lg-5 text-center">
                <?php if (get_theme_mod('classic_marketing_agency_headingtext1') != "") { ?>
                    <p class="subhed mb-2 text-uppercase"><?php echo esc_html(get_theme_mod('classic_marketing_agency_headingtext1', 'classic-marketing-agency')); ?></p>
                <?php } ?>
                <?php if (get_theme_mod('classic_marketing_agency_headingtext_para') != "") { ?>
                    <h2 class="mb-3 text-capitalize"><?php echo esc_html(get_theme_mod('classic_marketing_agency_headingtext_para', 'classic-marketing-agency')); ?></h2>
                <?php } ?>
            </div>
            <div class="row">
                <?php
                $classic_marketing_agency_queryvar = new WP_Query(array(
                    'cat' => esc_attr($classic_marketing_agency_blog_cat),
                    'posts_per_page' => $classic_marketing_agency_num_services,
                ));
                $classic_marketing_agency_post_count = 0;
                while ($classic_marketing_agency_queryvar->have_posts()) : $classic_marketing_agency_queryvar->the_post();
                    $classic_marketing_agency_post_count++;
                    $classic_marketing_agency_reviewer_image = get_theme_mod('classic_marketing_agency_reviewer_image' . $classic_marketing_agency_post_count, '');
                ?>

                    <div class="col-lg-4 col-md-6 service-box my-3">
                        <div class="serv-content position-relative">
                            <?php if (has_post_thumbnail()) { 
                                the_post_thumbnail('full'); 
                            } else { ?>
                                <div class="post-color"></div>
                            <?php } ?>
                            <span class="heart-icon"><i class="fas fa-heart"></i></span>
                            <div class="row">
                                <div class="col-lg-4 col-md-4 col-4 align-self-center text-center">
                                    <div class="service-category-name my-2">
                                        <i class="fas fa-tag me-2"></i><?php the_category(); ?>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4 col-4 align-self-center text-center">
                                  <?php if ($classic_marketing_agency_reviewer_image) { ?>
                                    <div class="reviewer-image">
                                        <img src="<?php echo esc_url($classic_marketing_agency_reviewer_image); ?>" alt="Reviewer Image" class="img-fluid">
                                    </div>
                                  <?php } ?>
                                    <?php if (get_theme_mod('classic_marketing_agency_reviwer_name' . $classic_marketing_agency_post_count) != '') { ?>
                                        <p class="reviwer-name my-2"><?php echo esc_html(get_theme_mod('classic_marketing_agency_reviwer_name' . $classic_marketing_agency_post_count, '')); ?></p>
                                    <?php } ?>
                                    <?php 
                                    $classic_marketing_agency_star_rating = get_theme_mod('classic_marketing_agency_star_rating' . $classic_marketing_agency_post_count, ''); 
                                    if (!empty($classic_marketing_agency_star_rating)) { ?>
                                        <div class="star-rating mt-1">
                                            <?php for ($classic_marketing_agency_i = 1; $classic_marketing_agency_i <= 5; $classic_marketing_agency_i++) {
                                                if ($classic_marketing_agency_i <= $classic_marketing_agency_star_rating) {
                                                    echo '<i class="fas fa-star"></i>';
                                                } else {
                                                    echo '<i class="far fa-star"></i>';
                                                }
                                            } ?>
                                        </div>
                                    <?php } ?>
                                </div>
                                <div class="col-lg-4 col-md-4 col-4 align-self-center text-center">
                                    <?php if (get_theme_mod('classic_marketing_agency_courses_prices' . $classic_marketing_agency_post_count) != '') { ?>
                                        <p class="service-price my-2"><?php echo esc_html(get_theme_mod('classic_marketing_agency_courses_prices' . $classic_marketing_agency_post_count, '')); ?></p>
                                    <?php } ?>
                                </div>
                            </div>
                            <div class="blog-content text-center <?php if (!has_post_thumbnail()) echo ' no-thumbnail'; ?>">
                                <h3 class="mt-md-3 mt-2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                <div class="more-btn mt-3">
                                  <a href="<?php the_permalink(); ?>"><?php esc_html_e('Book Now','classic-marketing-agency'); ?></a>
                                </div>
                            </div>
                        </div>
                    </div>

                <?php endwhile; wp_reset_postdata(); ?>
            </div>
            <div class="mt-4 text-center">
                <?php if ( get_theme_mod('classic_marketing_agency_contact_us_text', 'View All') != "" && get_theme_mod('classic_marketing_agency_contact_us_url') != "") { ?> 
                  <div class="contact-us text-center">
                    <a href="<?php echo esc_url(get_theme_mod ('classic_marketing_agency_contact_us_url','')); ?>"><?php echo esc_html(get_theme_mod ('classic_marketing_agency_contact_us_text', 'View All','classic-marketing-agency')); ?><i class="ms-2 fas fa-arrow-right"></i></a>
                  </div>
                <?php }?>
            </div>
        </div>
    </section>
<?php } ?>

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