<?php
/**
 * Managed the custom functions and hooks for entire theme.
 *
 * @package Purenote
 */

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


/*------------------------------ Header Section -------------------------*/

    if ( ! function_exists( 'purenote_custom_header_html' ) ) :

        /**
         * function to get custom header markup
         * 
         * @since 1.0.0
         */
        function purenote_custom_header_html() {
            the_custom_header_markup();
        }

    endif;

    add_action( 'purenote_header_section', 'purenote_custom_header_html', 10 );

    if ( ! function_exists( 'purenote_top_header' ) ) :

        /**
         * function to display the top header section at header area.
         * 
         * @since 1.0.0
         */
        function purenote_top_header() {
            get_template_part( 'template-parts/header/top', 'header' );
        }

    endif;

    add_action( 'purenote_header_section', 'purenote_top_header', 20 );

    if ( ! function_exists( 'purenote_main_header' ) ) :

        /**
         * function to display the header section at header area.
         * 
         * @since 1.0.0
         */
        function purenote_main_header() {
            get_template_part( 'template-parts/header/main', 'header' );
        }

    endif;

    add_action( 'purenote_header_section', 'purenote_main_header', 30 );
  

    if ( ! function_exists( 'header_news_ticker_section' ) ) :

        /**
         * function to display news ticker content in header section
         * 
         * @since 1.0.0
         */
        function header_news_ticker_section() {
            if ( ! is_home() && ! is_front_page() ) {
                return;
            }
            get_template_part( 'template-parts/header/news', 'ticker' );
        }

    endif;

    add_action( 'purenote_header_section', 'header_news_ticker_section', 40 );

/*----------------------------------- Frontpage Banner Section ------------------------------*/

    if ( ! function_exists( 'purenote_frontpage_main_container' ) ) :

        /**
         * function to display the main banner section at front page.
         * 
         * @since 1.0.0
         */
        function purenote_frontpage_main_container() {
            get_template_part( 'template-parts/frontpage/main', 'container' );
        }

    endif;

    add_action( 'purenote_frontpage_section', 'purenote_frontpage_main_container', 10 );

/*----------------------------------- Frontpage Web Stories Section ------------------------------*/

    if ( ! function_exists( 'purenote_web_stories_html' ) ) :

        /**
         * function to display the web story section at front page.
         * 
         * @since 1.0.0
         */
        function purenote_web_stories_html() {
            get_template_part( 'template-parts/frontpage/web', 'story' );
        }

    endif;

    add_action( 'purenote_frontpage_section', 'purenote_web_stories_html', 20 );

/*---------------------------------- Innerpage Section ----------------------------------*/
    if ( ! function_exists( 'purenote_post_author_box' ) ) :

        /**
         * function to display the author box section in single post page.
         * 
         * @since 1.0.0
         */
        function purenote_post_author_box() {
            get_template_part( 'template-parts/partials/post/author', 'box' );
        }

    endif;

    add_action( 'purenote_after_single_post_loop_content', 'purenote_post_author_box', 10 );

    if ( ! function_exists( 'purenote_single_post_related_posts_section' ) ) :

        /**
         * function to display the related posts sections in single post page.
         * 
         * @since 1.0.0
         */
        function purenote_single_post_related_posts_section() {
            get_template_part( 'template-parts/partials/post/related', 'posts' );
        }

    endif;

    add_action( 'purenote_after_single_post_loop_content', 'purenote_single_post_related_posts_section', 20 );


    if ( ! function_exists( 'purenote_archive_title_prefix' ) ) :
        
        /**
         * Archive title prefix
         *
         * @since 1.0.0
         */
        function purenote_archive_title_prefix( $title ) {

            $title_prefix_enable = purenote_get_customizer_option_value( 'purenote_archive_title_prefix_enable' );

            if ( false === $title_prefix_enable ) {
                return preg_replace( '/^\w+: /', '', $title );
            } else {
                return $title;
            }
            
        }

    endif;

    add_filter( 'get_the_archive_title', 'purenote_archive_title_prefix' );
/*---------------------------------- Footer Section ------------------------------*/

    if ( ! function_exists( 'purenote_scroll_top_section' ) ) :

        /**
         * function to display the scroll top section in footer.
         * 
         * @since 1.0.0
         */
        function purenote_scroll_top_section() {
            get_template_part( 'template-parts/footer/scroll', 'top' );
        }

    endif;

    add_action( 'purenote_after_page', 'purenote_scroll_top_section', 10 );