<?php 
// Do not allow directly accessing this file.
if (! defined('ABSPATH')) {
    exit();
}
// Breadcroumb Hook Function
if (! function_exists('glamer_breadcroumb_wrap_hook')) {
    function glamer_breadcroumb_wrap_hook() {
        // Default options
        $breadcrumb_tag = glamer_options('glamer_breadcrumb_select_html', 'h2');
        $breadcrumb_class = 'page-title';
        $breadcrumb_content = '';
        $breadcrumb_enabled = true;

        // Exclude breadcrumb on template-home.php
        if (is_page_template('template-home.php')) {
            $breadcrumb_enabled = false; // Disable breadcrumb
        }elseif (is_404()) {
            $breadcrumb_enabled = glamer_options('glamer_error_page_banner', true);
            $breadcrumb_content = glamer_options('glamer_error_page_title', esc_html__('Page Not Found', 'glamer'));
        } elseif (class_exists('woocommerce') && is_shop()) {
            $breadcrumb_enabled = glamer_options('glamer_shop_banner_enable', true);
            $breadcrumb_content = woocommerce_page_title(false);
        } elseif (is_author()) {
            $breadcrumb_enabled = false; // Disable breadcrumb for author archive pages
        } elseif (is_archive()) {
            $breadcrumb_enabled = glamer_options('glamer_archive_banner', true);
            $breadcrumb_content = get_the_archive_title();
        } elseif (is_singular('product')) {
            // For WooCommerce product pages, no meta options applied
            $breadcrumb_enabled = glamer_options('glamer_single_shop_banner_enable', true);
            if ('custom' == glamer_options('glamer_select_single_shop_title', 'custom')) {
                $breadcrumb_content = glamer_options('glamer_single_product_custom_title', esc_html__('Shop Details', 'glamer'));
            } else {
                $breadcrumb_content = get_the_title();
            }
        } elseif (is_single()) {
            $post_meta = get_post_meta(get_the_ID(), 'glamer_metabox', true);
            if (isset($post_meta['glamer_meta_enable_banner']) && $post_meta['glamer_meta_enable_banner'] == 'custom') {
                $breadcrumb_enabled = true; // Enabled as per metabox
                $breadcrumb_content = get_the_title();
            } else {
                $breadcrumb_enabled = glamer_options('glamer_single_post_banner_enable', true); // Fallback to theme options
                if ('custom' == glamer_options('glamer_select_single_title', 'custom')) {
                    $breadcrumb_content = glamer_options('glamer_single_post_title', esc_html__('Blog Details', 'glamer'));
                } else {
                    $breadcrumb_content = get_the_title();
                }
            }
        } elseif (is_page()) {
            $post_meta = get_post_meta(get_the_ID(), 'glamer_metabox', true);
            if (isset($post_meta['glamer_meta_enable_banner']) && $post_meta['glamer_meta_enable_banner'] == 'custom') {
                $breadcrumb_enabled = true; // Enabled as per metabox
                $breadcrumb_content = get_the_title();
            } else {
                $breadcrumb_enabled = true;
                $breadcrumb_content = get_the_title();
            }
        } elseif (is_home()) {
            $breadcrumb_enabled = glamer_options('glamer_blog_banner_enable', true);
            $breadcrumb_content = glamer_options('glamer_blog_title', esc_html__('Blog Standrad', 'glamer'));
        } elseif (is_search()) {
            $breadcrumb_enabled = glamer_options('glamer_search_banner', true);
            $breadcrumb_content = sprintf(esc_html__('Search Results for: %s', 'glamer'), '<span>' . get_search_query() . '</span>');
        } else {
            $breadcrumb_enabled = true;
            $breadcrumb_content = get_the_title();
        }

    // Render if banner is enabled
    if ($breadcrumb_enabled && !empty($breadcrumb_content)) {
        echo '<div class="breadcum-area">';
            echo '<div class="container">';
                echo '<div class="breadcum-content">';
                    echo ' <'.esc_attr($breadcrumb_tag).' class="'.esc_attr($breadcrumb_class).'">';
                        echo wp_kses($breadcrumb_content, glamer_allow_html());
                    echo '</'.esc_attr($breadcrumb_tag).'>';
                     if (function_exists('bcn_display')){
                        echo '<div class="bre-sub">'.bcn_display().'</div>';
                    }
                echo '</div>';
            echo '</div>';
        echo '</div>';
    }
}
}
add_action('glamer_action_breadcroumb_wrap', 'glamer_breadcroumb_wrap_hook', 10);

// Default Header Hook Function
if( ! function_exists( 'glamer_default_header_hook' ) ) {
    function glamer_default_header_hook() {
        $glamer_logo1 = glamer_options('header_default_logo');
        $glamer_enable_sticky_menu1 = glamer_options( 'glamer_enable_sticky_menu1' );
        if ( $glamer_enable_sticky_menu1 == true ) {
            $sticky = 'sticky-menu';
        } else {
            $sticky = 'no-sticky';
        }
        echo'<header class="nav-header header-layout2 site-header">';
            echo'<div class="main-menu-wrapper default">';
                echo'<div class="sticky-wrapper" id="'.esc_attr( $sticky ).'">';
                    echo'<div class="menu-area ">';
                        echo'<div class="container">';
                            echo'<div class="row align-items-center justify-content-between">';
                                echo'<div class="header-logo col-auto">';
                                    if(!empty($glamer_logo1['url'])){
                                        $logoUrl = $glamer_logo1['url'];
                                        echo'<a href="'.esc_url( home_url( '/' ) ).'">';
                                        echo'<img src="'.esc_url($logoUrl).'" alt="'.esc_attr(bloginfo( 'name' )).'">';
                                    echo'</a>';
                                    }elseif(has_custom_logo()){
                                        the_custom_logo();
                                    }else{
                                        echo'<h2>';
                                            echo'<a href="'.esc_url( home_url( '/' ) ).'" rel="home">';
                                                esc_html(bloginfo( 'name' ));
                                            echo'</a>';
                                        echo'</h2>';
                                    }
                                    $glamer_description = get_bloginfo( 'description', 'display' );
                                    if ( $glamer_description || is_customize_preview() ) {
                                        /*
                                         * Display the site description.
                                         * This ensures it shows up in the Customizer even if it's empty.
                                         */
                                        echo '<p class="site-description">' . esc_html($glamer_description) . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                                    }
                                echo'</div>';
                                echo'<div class="col-auto">';
                                    echo'<nav class="navbar navbar-expand-lg navbar-light main-navigation" id="site-navigation">';
                                        echo'<div class="navbar-collapse nav-menu">';
                                            wp_nav_menu(
                                                array(
                                                    'container'      => false,
                                                    'theme_location' => 'mainmenu',
                                                    'menu_id'        => 'default_menu',
                                                    'menu_class'      => 'sf-menu',
                                                    'echo'           => true,
                                                    'fallback_cb'    => 'glamer_Nav_Walker::fallback',
                                                    'walker'         => new glamer_Nav_Walker,
                                                )
                                            );
                                        echo'</div>';
                                    echo'</nav>';
                                echo'</div>';
                                echo'<div id="defaultmobile"></div>';
                            echo'</div>';
                        echo'</div>';
                    echo'</div>';
                echo'</div>';
            echo'<div>';
        echo'</header>';
    }
}
add_action( 'glamer_action_default_header_hook', 'glamer_default_header_hook', 10 );

// Default Footer Hook Function
if( ! function_exists( 'glamer_default_footer_hook' ) ) {
    function glamer_default_footer_hook() {
        $glamer_copyright = glamer_options( 'glamer_copyright_text' );
        echo'<div class="footer-three-wrapper footer-wrapper footer-default">';
             if ( is_active_sidebar( 'footer-1' ) || is_active_sidebar( 'footer-2' ) || is_active_sidebar( 'footer-3' ) || is_active_sidebar( 'footer-4' ) ){
            echo'<div class="footer-three-content-wrp">';
                echo'<div class="container-md">';
                    echo'<div class="row">';
                        if ( is_active_sidebar( 'footer-1' ) ){
                            echo'<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">';
                                dynamic_sidebar( 'footer-1' );
                            echo'</div><!-- .widget-area -->';
                        }

                        if ( is_active_sidebar( 'footer-2' ) ){
                            echo'<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">';
                                dynamic_sidebar( 'footer-2' );
                            echo'</div><!-- .widget-area -->';
                        }

                        if ( is_active_sidebar( 'footer-3' ) ){
                            echo'<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">';
                                dynamic_sidebar( 'footer-3' );
                            echo'</div><!-- .widget-area -->';
                        }

                        if ( is_active_sidebar( 'footer-3' ) ){
                            echo'<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6">';
                                dynamic_sidebar( 'footer-4' );
                            echo'</div><!-- .widget-area -->';
                        }
                    echo'</div>';
                echo'</div>';
            echo'</div>';
            }
        echo'</div>';
        echo'<div class="copyright-wrap text-center">';
            echo'<div class="container">';
                echo'<div class="copyright-wrapper">';
                    echo'<div class="gy-3">';
                        echo'<div class="copyright-text">';
                            if (defined('GLAMER_PRO')){
                                echo wp_kses( $glamer_copyright, 'glamer_allow_html' );
                            }else{
                                echo esc_html( 'Proudly powered by WordPress | ' ) . wp_kses_post( sprintf( esc_html__( ' Theme: Glamer by %s', 'glamer' ), '<a target="_blank" rel="dofollow" href="' . esc_url( 'https://themeuniver.com/' ) . '">Themeuniver</a>' ) );
                            }
                        echo'</div>';
                    echo'</div>';
                echo'</div>';
            echo'</div>';
        echo'</div>';
    }
}
add_action( 'glamer_action_default_footer_hook', 'glamer_default_footer_hook', 10 );

// Author info Hook Function
if( ! function_exists( 'glamer_author_info_hook' ) ) {
    function glamer_author_info_hook() {
        echo'<div class="post-box">';
            echo'<div class="author-info-wrapper">';
                echo'<div class="author-info-inner">';
                    echo'<div class="author-info-left">';
                        echo'<div class="author-img">';
                            echo get_avatar( get_the_author_meta( 'ID' ));
                        echo'</div>';
                    echo'</div>';
                    echo'<div class="author-info-right">';
                        echo'<div class="author-info-content">';
                            echo'<h2 class="author-info-title">'.get_the_author_posts_link().'</h2>';
                            echo'<div class="author-dec">'.get_the_author_meta('description').'</div>';
                            echo'<div class="footer-social-widget">';
                                echo'<ul>';
                                    $glamer_user_cm = wp_get_user_contact_methods();
                                    foreach ($glamer_user_cm as $glamer_ucm_key => $glamer_ucm_value){
                                        $glamer_cm_link = get_user_meta(get_the_author_meta('ID'), $glamer_ucm_key, true);
                                        if($glamer_cm_link){
                                            echo'<li>';
                                                echo'<a data-toggle="tooltip" data-placement="top" data-original-title="'.esc_attr($glamer_ucm_key).'" href="'.esc_url($glamer_cm_link).'"><span class="fab fa-'.esc_attr($glamer_ucm_key).'"></span>';
                                                echo'</a>';
                                            echo'</li>';
                                        }
                                    }
                                echo'</ul>';
                            echo'</div>';
                        echo'</div>';
                    echo'</div>';
                echo'</div>';
            echo'</div>';
        echo'</div>';
    }
}
add_action( 'glamer_action_author_info_hook', 'glamer_author_info_hook', 10 );