<?php
/**
 * Manages custom functions and hooks for the entire Yaatra theme.
 *
 * Centralizes theme functionality and provides hooks for customization.
 *
 * @package Yaatra
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

/*------------------------------ Header Section ----------------------------*/
    
    if ( ! function_exists( 'yaatra_main_header' ) ) :

        /**
         * Displays the main header section within the overall header template.
         * 
         * This function is responsible for rendering the primary elements of the header.
         *
         * @since 1.1.0
         */
        function yaatra_main_header() {
            get_template_part( 'template-parts/header/main', 'header' );
        }

    endif;

    add_action( 'yaatra_header_section', 'yaatra_main_header', 10 );

    if ( ! function_exists( 'yaatra_inner_pages_header_element' ) ) :

        /**
         * function to start main content
         */
        function yaatra_inner_pages_header_element() {

            if ( is_page() && !is_front_page() ) {
                $inner_header_attribute = '';
                $inner_header_attribute = apply_filters( 'yaatra_inner_header_style_attribute', $inner_header_attribute );
                if ( !empty( $inner_header_attribute ) ) {
                    $header_class = 'has-bg-img';
                } else {
                    $header_class = 'no-bg-img';
                }
    ?>
                <div class="custom-header <?php echo esc_attr( $header_class ); ?>" <?php echo ( ! empty( $inner_header_attribute ) ) ? ' style="' . esc_attr( $inner_header_attribute ) . '" ' : ''; ?>>
                    <div class="cv-container">
                        <header class="entry-header">
                            <h1 class="entry-title"><?php the_title(); ?></h1>
                        </header><!-- .entry-header -->
                    </div><!-- .cv-container -->
                </div><!-- .custom-header -->
    <?php   
            }
        }

    endif;

    add_action( 'yaatra_before_page_content', 'yaatra_inner_pages_header_element', 5 );

/*------------------------------ Frontpage Section -------------------------*/
    
    if ( ! function_exists( 'yaatra_frontpage_banner_section' ) ) :

        /**
         * The function is responsible for managing the content of the frontage section.
         * 
         * @since 1.0.0
         */
        function yaatra_frontpage_banner_section() {

            $yaatra_front_banner_option = yaatra_get_customizer_option_value( 'yaatra_front_banner_option' );

            if ( false === $yaatra_front_banner_option ) {
                return;
            }

            get_template_part( 'template-parts/frontpage/content', 'banner' );
        }

    endif;

    add_action( 'yaatra_frontpage_section', 'yaatra_frontpage_banner_section', 10 );

   
/*------------------------------ Footer Section ---------------------------*/

    if ( ! function_exists( 'yaatra_scroll_top_section' ) ) :

        /**
         * Function to display the scroll-to-top button in the footer.
         * 
         * This function adds a button in the footer that allows users to quickly scroll to the top of the page.
         *
         * @since 1.1.0
         */
        function yaatra_scroll_top_section() {
            get_template_part( 'template-parts/footer/scroll', 'top' );
        }

    endif;

    add_action( 'yaatra_after_page', 'yaatra_scroll_top_section', 10 );