<?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 Christmas Event
 */

get_header(); ?>

<div id="content">
    <?php
    $classic_events_hidepageboxes = get_theme_mod('classic_events_slider', true);
    $classic_events_catData = get_theme_mod('classic_events_slider_cat');

    if ($classic_events_hidepageboxes && $classic_events_catData) { ?>
    <section id="slider-cat">
        <div class="slideimg">
            <div class="container sliderbox">
                <div class="owl-carousel m-0">
                    <?php
                    $classic_events_page_query = new WP_Query(
                        array(
                            'category_name' => esc_attr($classic_events_catData),
                            'posts_per_page' => -1, 
                        )
                    );
                    while ($classic_events_page_query->have_posts()) : $classic_events_page_query->the_post(); ?>
                        <div class="row">
                            <div class="col-lg-7 col-md-6 mb-md-5 mb-2 align-self-center">
                                <div class="text-content">
                                    <?php if(get_theme_mod('classic_events_slider_top_text') != ''){ ?>
                                        <p class="slider-text mb-lg-2 mb-0"><?php echo esc_html(get_theme_mod('classic_events_slider_top_text')); ?></p>
                                    <?php }?>
                                    <h1 class="my-lg-2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                    <?php
                                    $classic_events_trimexcerpt  = get_the_excerpt();
                                    $classic_events_shortexcerpt = wp_trim_words($classic_events_trimexcerpt, $num_words = 45);
                                    echo '<p class="slider-content mt-3">' . esc_html($classic_events_shortexcerpt) . '</p>';
                                    ?>
                                    <div class="sliderbtn mt-lg-4">
                                        <?php 
                                        $classic_events_button_text = get_theme_mod('classic_events_button_text', 'Online Request');
                                        $classic_events_button_link = get_theme_mod('classic_events_button_link_slider', ''); 
                                        if (empty($classic_events_button_link)) {
                                            $classic_events_button_link = get_permalink();
                                        }
                                        if (!empty($classic_events_button_text) || !empty($classic_events_button_link)) { ?>
                                            <div class="slide-btn">
                                                <a href="<?php echo esc_url($classic_events_button_link); ?>">
                                                    <?php echo esc_html($classic_events_button_text); ?>
                                                    <span class="screen-reader-text"><?php echo esc_html($classic_events_button_text); ?></span>
                                                </a>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-5 col-md-6 col-12 mb-5 align-self-center">
                                <div class="imagebox">
                                    <?php if(has_post_thumbnail()){
                                      the_post_thumbnail('full');
                                      } else{?>
                                      <img src="<?php echo esc_url(get_theme_file_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'christmas-event'); ?>"/>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php endwhile;
                    wp_reset_postdata();
                    ?>
                </div>
            </div>
        </div>
        <div class="dot-image"></div>
    </section>
    <?php } ?>

    <!-- Our Services -->
    <section id="about_section" class="my-5 mx-md-0 mx-3">
        <div class="container">
            <div class="blog_bx text-center mb-2">
                <?php if (get_theme_mod('christmas_event_category_sec_text') != '') { ?>
                    <p class="services-text mb-2 text-uppercase">
                        <?php echo esc_html(get_theme_mod('christmas_event_category_sec_text')); ?>
                    </p>
                <?php } ?>
                <?php if (get_theme_mod('christmas_event_category_sec_title') != "") { ?>
                    <h2 class="services-title mb-1 text-capitalize"><?php echo esc_html(get_theme_mod('christmas_event_category_sec_title', 'christmas-event')); ?></h2>
                <?php } ?>
            </div>
            <div class="row">
                <?php
                $args = array(
                  'taxonomy'   => 'category',
                  'orderby'    => 'name',
                  'order'      => 'ASC',
                  'hide_empty' => 0,
                  'parent'     => 0
                );
                $christmas_event_post_categories = get_terms($args);
                $christmas_event_count = count($christmas_event_post_categories);
                $christmas_event_counter = 0;

                if ($christmas_event_count > 0) {
                    foreach ($christmas_event_post_categories as $christmas_event_post_category) {
                        $christmas_event_post_cat_id = $christmas_event_post_category->term_id;
                        $christmas_event_cat_link = get_category_link($christmas_event_post_cat_id);
                        $christmas_event_thumbnail_id = get_term_meta($christmas_event_post_cat_id, 'category_image', true);
                        $christmas_event_counter++;

                        if ($christmas_event_post_category->parent == 0) { ?>
                            <div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 mb-4">
                                <div class="cat-box">
                                    <?php
                                    if ($christmas_event_thumbnail_id) {
                                        echo '<img class="thumb_img img-fluid" src="' . esc_url($christmas_event_thumbnail_id) . '" />';
                                    } else { ?>
                                        <div class="default-bg thumb_img"></div>
                                    <?php } ?>
                                    <div class="articles mt-3">
                                        <a href="<?php echo esc_url(get_term_link($christmas_event_post_category)); ?>">
                                            <h3><?php echo esc_html($christmas_event_post_category->name); ?></h3>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        <?php }
                    }
                } ?>
            </div>
            <?php if ( get_theme_mod('christmas_event_info_btn_text') != "") { ?>
                <div class="info-btn text-center">
                    <a href="<?php echo esc_url(get_theme_mod ('christmas_event_info_btn_url','')); ?>"><?php echo esc_html(get_theme_mod ('christmas_event_info_btn_text','Download CV','christmas-event')); ?></a>
                </div>
            <?php }?>
        </div>
    </section>
</div>

<?php get_footer(); ?>