<?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 Attorney
 */

get_header(); ?>

<div id="content" >
    <?php
        $classic_attorney_hidepageboxes = get_theme_mod('classic_attorney_slider', false);
        $classic_attorney_catData = get_theme_mod('classic_attorney_slider_cat');
        if ($classic_attorney_hidepageboxes && $classic_attorney_catData) { ?>
        <section id="slider-cat" class="position-relative">
            <div class="sliderbox">
                <div class="owl-carousel m-0">
                    <?php
                        $classic_attorney_page_query = new WP_Query(
                            array(
                                'category_name' => esc_attr($classic_attorney_catData),
                                'posts_per_page' => 3, 
                            )
                        );
                        while ($classic_attorney_page_query->have_posts()) : $classic_attorney_page_query->the_post(); ?>
                            <div class="text-content">
                                <div class="container">
                                    <div class="text-main-box position-relative">
                                        <div class="text-box position-relative pb-4">
                                            <div class="row">
                                                <div class="col-xl-6 col-lg-6 col-md-6 col-12 subheading-box position-relative">
                                                    <?php if(get_theme_mod('classic_attorney_slider_subhead') != ''){ ?>
                                                        <div class="slider-subhead">
                                                            <p class="mb-0"><?php echo esc_html(get_theme_mod ('classic_attorney_slider_subhead','classic-attorney')); ?></p>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                                <div class="col-xl-6 col-lg-6 col-md-6 col-12">
                                                    <h1 class="slider-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="slider-content p-2 text-center">
                                            <?php
                                            $classic_attorney_trimexcerpt  = get_the_excerpt();
                                            $classic_attorney_shortexcerpt = wp_trim_words($classic_attorney_trimexcerpt, $classic_attorney_num_words = 50);
                                            echo '<p class="mb-0">' . esc_html($classic_attorney_shortexcerpt) . '</p>';
                                            ?>
                                        </div>
                                        <div class="sliderbtn position-absolute">
                                            <a href="<?php the_permalink(); ?>"><i class="<?php echo esc_attr(get_theme_mod('classic_attorney_services_icon', 'fa-solid fa-scale-balanced')); ?>"></i></a>
                                        </div>
                                        <div class="btm-border position-absolute"></div>
                                    </div>
                                </div>
                                <div class="imagebox">
                                    <?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', 'classic-attorney'); ?>"/>
                                    <?php } ?>
                                </div>
                            </div>
                        <?php endwhile;
                        wp_reset_postdata();
                    ?>
                </div>
            </div>
            <a href="#footer-scroll" class="footer-down"><i class="fa-solid fa-arrow-down"></i></a>
        </section>
    <?php } ?>

    <!-- Services Section -->
    <?php 
        $classic_attorney_hide_services_section = get_theme_mod('classic_attorney_disabled_services_section', false);
        $classic_attorney_about_pageboxes = get_theme_mod('classic_attorney_about_pageboxes', false);
        $classic_attorney_services_catData = get_theme_mod('classic_attorney_services_sec_cat', false);
        if ($classic_attorney_hide_services_section || $classic_attorney_services_catData || $classic_attorney_about_pageboxes){ ?>
        <section id="services-section" class="py-4">
            <div class="container">
                <div class="blog-bx mb-2">
                    <?php if (get_theme_mod('classic_attorney_services_title') != "") { ?>
                        <h2 class="services-title pb-3 text-uppercase position-relative"><?php echo esc_html(get_theme_mod('classic_attorney_services_title')); ?></h2>
                    <?php } ?>
                </div>
                <div class="row">
                    <div class="col-xl-7 col-lg-6 col-md-12 col-12">
                        <?php
                        $classic_attorney_about_page_id = esc_attr(get_theme_mod('classic_attorney_about_pageboxes', false));
                        if ($classic_attorney_about_page_id) {
                            $classic_attorney_querymed = new WP_Query(array(
                                'page_id' => $classic_attorney_about_page_id
                            ));
                            
                            while ($classic_attorney_querymed->have_posts()) : $classic_attorney_querymed->the_post(); ?>
                                <div class="service-page position-relative">
                                    <div class="service-img position-relative">
                                        <?php if (has_post_thumbnail()) : ?>
                                            <?php the_post_thumbnail('full'); ?>
                                        <?php else : ?>
                                            <div class="post-color"></div>
                                        <?php endif; ?>
                                    </div>
                                    <div class="text-inner-box position-absolute p-3">
                                        <div class="heading-box">
                                            <h4 class="service-page-title text-capitalize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                        </div>
                                        <p class="main-para mb-0 text-lg-end text-md-end text-center"><?php echo esc_html(wp_trim_words(get_the_content(), 75, '')); ?></p>
                                    </div>
                                </div>
                            <?php endwhile;
                            wp_reset_postdata();
                        }
                        ?>
                    </div>
                    <div class="col-xl-5 col-lg-6 col-md-12 col-12">
                        <div class="services-boxes">
                            <?php
                                if (!empty($classic_attorney_services_catData) && $classic_attorney_services_catData !== '0') {
                                    $classic_attorney_page_query = new WP_Query(
                                        array(
                                            'category_name' => esc_attr($classic_attorney_services_catData),
                                        )
                                    );
                                    while ($classic_attorney_page_query->have_posts()) : $classic_attorney_page_query->the_post(); ?>
                                        <div class="services-content p-3 position-relative">
                                            <h3 class="services-title text-capitalize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                            <p class="post-excerpt mb-0">
                                                <?php echo wp_trim_words(get_the_excerpt(), 25, '...'); ?>
                                            </p>
                                            <a class="service-btn position-absolute" href="<?php echo esc_url(get_permalink($post->ID)); ?>"><i class="fa-solid fa-arrow-right"></i></a>
                                        </div>
                                    <?php endwhile; ?>
                                <?php }
                                wp_reset_postdata();
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>