<?php
/**
 * @package Legacy Wellness Coach
 */

/**
 * Footer
 */
if (! function_exists( 'legacy_wellness_coach_footer_copyrights' ) ):
    function legacy_wellness_coach_footer_copyrights() {
        ?>
            <div class="row">
                <div class="copyrights">
                    <p>
                        <?php
                            if("" != esc_html(get_theme_mod( 'legacy_wellness_coach_footer_copyright_text'))) :
                                echo esc_html(get_theme_mod( 'legacy_wellness_coach_footer_copyright_text'));
                                if(get_theme_mod('legacy_wellness_coach_en_footer_credits',true)) :
                                    ?> 
                                    <span class="copyrg-link"><a href="<?php echo esc_url(LEGACY_WELLNESS_COACH_AUT); ?>" target="_blank" rel="nofollow noopener"><?php esc_html_e(' | Legacy Wellness Coach WordPress Theme','legacy-wellness-coach') ?></a><?php esc_html_e(' by Legacy Themes','legacy-wellness-coach') ?></span>
                                    <?php   
                                endif;
                            else :
                                echo date_i18n(
                                    /* translators: Copyright date format, see https://secure.php.net/date */
                                    _x( 'Y', 'copyright date format', 'legacy-wellness-coach' )
                                );
                                ?>
                                    <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>
                                    <span class="copyrg-link"><a href="<?php echo esc_url(LEGACY_WELLNESS_COACH_AUT); ?>" target="_blank" rel="nofollow noopener"><?php esc_html_e(' | Legacy Wellness Coach WordPress Theme','legacy-wellness-coach') ?></a><?php esc_html_e(' by Legacy Themes','legacy-wellness-coach') ?></span>
                                <?php
                            endif;
                        ?>
                    </p>
                </div>
            </div>
        <?php    
    }
endif;
add_action( 'legacy_wellness_coach_action_footer', 'legacy_wellness_coach_footer_copyrights' );

/**
 * Page Title Settings
 */
if ( ! function_exists( 'legacy_wellness_coach_show_page_title' ) ) :
    function legacy_wellness_coach_show_page_title() {
        if ( ! is_front_page() ) {
            ?>
            <div class="page-title"> 
                <div class="content-section img-overlay">
                    <div class="container">
                        <div class="row text-center">
                            <div class="col-md-12">
                                <div class="section-title"> 
                                    <?php
                                    // WooCommerce Pages
                                    if ( function_exists( 'is_shop' ) && is_shop() ) {
                                        // Shop Page
                                        echo '<h1 class="main-title">' . esc_html__( 'Shop Page', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( function_exists( 'is_product' ) && is_product() ) {
                                        // Single Product Page
                                        echo '<h1 class="main-title">' . esc_html__( 'Single Product Page', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( function_exists( 'is_checkout' ) && is_checkout() ) {
                                        // Checkout Page
                                        echo '<h1 class="main-title">' . esc_html__( 'Checkout', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( function_exists( 'is_account_page' ) && is_account_page() ) {
                                        // My Account Page
                                        echo '<h1 class="main-title">' . esc_html__( 'My Account', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( is_home() ) {
                                        // Blog Index Page
                                        echo '<h1 class="main-title">' . esc_html__( 'Blog Page', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( is_singular( 'post' ) ) {
                                        // Single Blog Post
                                        echo '<h1 class="main-title">' . get_the_title() . '</h1>';

                                    } elseif ( is_category() ) {
                                        echo '<h1 class="main-title">' . single_cat_title( '', false ) . '</h1>';

                                    } elseif ( is_tag() ) {
                                        echo '<h1 class="main-title">' . single_tag_title( '', false ) . '</h1>';

                                    } elseif ( is_author() ) {
                                        echo '<h1 class="main-title">' . get_the_author() . '</h1>';

                                    } elseif ( is_archive() ) {
                                        echo '<h1 class="main-title">' . get_the_archive_title() . '</h1>';

                                    } elseif ( is_search() ) {
                                        echo '<h1 class="main-title">' . esc_html__( 'Search Results', 'legacy-wellness-coach' ) . '</h1>';

                                    } elseif ( is_404() ) {
                                        echo '<h1 class="main-title">' . esc_html__( 'Page Not Found', 'legacy-wellness-coach' ) . '</h1>';

                                    } else {
                                        // Default for all other pages
                                        echo '<h1 class="main-title">' . get_the_title() . '</h1>';
                                    }
                                    ?>
                                </div>                      
                            </div>
                        </div>
                    </div>  
                </div>
            </div>  <!-- End page-title --> 
            <?php
        }
    }
endif;

// Register page title action globally
add_action( 'legacy_wellness_coach_get_page_title', 'legacy_wellness_coach_show_page_title' );


/**
 * Home Banner Section
 */
if (! function_exists( 'legacy_wellness_coach_home_banner_section' ) ):
    function legacy_wellness_coach_home_banner_section() {
        ?>
<section id="main-banner-wrap" class="life-coach-slider">
    <div class="container-fluid">
    <div class="slider-sec">
        <div class="owl-carousel main-slider">
            <?php 
            $legacy_wellness_coach_slide_number = get_theme_mod("legacy_wellness_coach_slide_number"); 
            for ($i = 1; $i <= $legacy_wellness_coach_slide_number; $i++) { 
                $legacy_wellness_coach_slide_image = get_theme_mod('legacy_wellness_coach_slide_image'.$i, '');
                if (!empty($legacy_wellness_coach_slide_image)) { ?>
                    <div class="slide-item position-relative">
                        <div class="overlay-slider"></div>
                        <img class="slide-bg" src="<?php echo esc_url($legacy_wellness_coach_slide_image); ?>">
                        <div class="slide-content">
                            <?php 
                            // Sub Heading
                            $legacy_wellness_coach_sub_heading = get_theme_mod('legacy_wellness_coach_slide_sub_heading'.$i, '');
                            if (!empty($legacy_wellness_coach_sub_heading)) { ?>
                                <h6 class="slider-sub-heading"><?php echo esc_html($legacy_wellness_coach_sub_heading); ?></h6>
                            <?php } ?>

                            <?php 
                            // Main Heading
                            $legacy_wellness_coach_heading = get_theme_mod('legacy_wellness_coach_slide_heading'.$i, '');
                            if (!empty($legacy_wellness_coach_heading)) { ?>
                                <h1 class="slider-heading"><?php echo esc_html($legacy_wellness_coach_heading); ?></h1>
                            <?php } ?>

                            <?php 
                            // Paragraph
                            $legacy_wellness_coach_paragraph = get_theme_mod('legacy_wellness_coach_slide_text'.$i, '');
                            if (!empty($legacy_wellness_coach_paragraph)) { ?>
                                <p class="slider-paragraph"><?php echo esc_html($legacy_wellness_coach_paragraph); ?></p>
                            <?php } ?>  

                            <?php 
                            // Button
                            $legacy_wellness_coach_button_url  = get_theme_mod('legacy_wellness_coach_slide_btnurl'.$i, '');
                            $legacy_wellness_coach_button_text = get_theme_mod('legacy_wellness_coach_slide_btntext'.$i, '');
                            if (!empty($legacy_wellness_coach_button_url) || !empty($legacy_wellness_coach_button_text)) { ?>
                                <a class="slider-button btn" href="<?php echo esc_url($legacy_wellness_coach_button_url); ?>">
                                    <?php echo esc_html($legacy_wellness_coach_button_text); ?>
                                </a>
                            <?php } ?>  
                        </div>
                    </div>
                <?php }
            } ?>
        </div>

        <!-- Thumbnail Navigation -->
        <div class="owl-thumbs custom-thumbs">
            <?php 
            for ($i = 1; $i <= $legacy_wellness_coach_slide_number; $i++) { 
                $legacy_wellness_coach_thumb_image = get_theme_mod('legacy_wellness_coach_slide_image'.$i, '');
                $legacy_wellness_coach_thumb_title = get_theme_mod('legacy_wellness_coach_slide_image_title'.$i, '');
                if (!empty($legacy_wellness_coach_thumb_image)) { ?>
                    <div class="img-box">
                        <button class="owl-thumb" role="button">
                            <img src="<?php echo esc_url($legacy_wellness_coach_thumb_image); ?>">
                            <?php if (!empty($legacy_wellness_coach_thumb_title)) { ?>
                                <div class="thumb-title"><p><?php echo esc_html($legacy_wellness_coach_thumb_title); ?></p></div>
                            <?php } ?>
                        </button>  
                    </div>
            <?php } } ?>
        </div>
    </div>
</div>
</section>
     <?php
    }
endif;
add_action( 'legacy_wellness_coach_action_home_banner', 'legacy_wellness_coach_home_banner_section' );


/**
 * Home destination Section
 */
if ( ! function_exists( 'legacy_wellness_coach_home_destination_section' ) ) :
    function legacy_wellness_coach_home_destination_section() {
        ?>
        <section id="destination-wrap">
            <div class="container">
                <div class="inner-wrap">
                    <div class="destination-head-box text-center mb-5">
                        <?php
                        $legacy_wellness_coach_destination_small_heading = get_theme_mod( 'legacy_wellness_coach_destination_small_heading', '' );
                        if ( ! empty( $legacy_wellness_coach_destination_small_heading ) ) { ?>
                            <h6 class="destn-sm-hd"><?php echo esc_html( $legacy_wellness_coach_destination_small_heading ); ?></h6>
                        <?php } ?>

                        <?php
                        $legacy_wellness_coach_destination_main_heading = get_theme_mod( 'legacy_wellness_coach_destination_main_heading', '' );
                        if ( ! empty( $legacy_wellness_coach_destination_main_heading ) ) { ?>
                            <h3 class="destn-main-hd pt-0"><?php echo esc_html( $legacy_wellness_coach_destination_main_heading ); ?></h3>
                        <?php } ?>
                    </div>

                    <div class="destination-box">
                        <div class="owl-carousel center-slider">
                            <?php
                            $legacy_wellness_coach_selected_category = get_theme_mod( 'legacy_wellness_coach_destination_category', '' );                               
                            $legacy_wellness_coach_destination_topics_number = get_theme_mod( 'legacy_wellness_coach_destination_topics_number', 8 );  

                            if ( $legacy_wellness_coach_selected_category ) {               
                                $args = array(
                                    'post_type'      => 'post',
                                    'posts_per_page' => $legacy_wellness_coach_destination_topics_number,
                                    'order'          => 'ASC',
                                    'category_name'  => sanitize_text_field( $legacy_wellness_coach_selected_category ),    
                                );                                
                                $legacy_wellness_coach_loop = new WP_Query( $args );

                                $legacy_wellness_coach_post_count = 0; 
                                while ( $legacy_wellness_coach_loop->have_posts() ) : 
                                    $legacy_wellness_coach_loop->the_post(); 
                                    $legacy_wellness_coach_post_count++;
                                    ?>                         
                                    <div class="destination-inn text-center">
                                        <div class="img-box-destn">
                                            <a href="<?php echo esc_url( get_permalink() ); ?>">
                                                <?php 
                                                if ( has_post_thumbnail() ) { 
                                                    echo get_the_post_thumbnail( get_the_ID(), 'full' ); 
                                                } else { 
                                                    echo '<img src="' . esc_url( get_template_directory_uri() . '/img/default.png' ) . '"/>';
                                                } 
                                                ?>
                                            </a>
                                        <div class="box-content">
                                            <span class="post-count"><?php echo sprintf('%02d', $legacy_wellness_coach_post_count); ?></span>
                                            <h4 class="title mb-2 p-0">    <a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title(); ?></a></h4>
                                        </div>
                                        </div>
                                    </div>                                                 
                                <?php 
                                endwhile; 
                                wp_reset_postdata(); 
                            } 
                            ?>
                        </div> 
                    </div>
                </div>                
            </div>
        </section>
        <?php    
    }
endif;
add_action( 'legacy_wellness_coach_action_home_destination', 'legacy_wellness_coach_home_destination_section' );

/**
 * Home page another adding Section
 */
if (! function_exists( 'legacy_wellness_coach_home_extra_section' ) ):
    function legacy_wellness_coach_home_extra_section() {
        ?>
        <div id="custom-home-extra-content">
            <div class="container">
              <?php while ( have_posts() ) : the_post(); ?>
                <?php the_content(); ?>
              <?php endwhile; ?>
            </div>
        </div>
        <?php    
    }
endif;
add_action( 'legacy_wellness_coach_action_home_extra', 'legacy_wellness_coach_home_extra_section' );