<?php
/**
 * Breadcrumbs for Edify theme.
 *
 * @package     Edify
 * @since       Edify 1.0.0
 */

$blog_title_breadcrumb = get_theme_mod( 'blog_title_breadcrumb', __( 'Blog', 'edify' ) );
$blog_title = get_theme_mod( 'blog_title', __( 'Blog Page', 'edify' ) );


$contact_title_breadcrumb = get_theme_mod( 'contact_title_breadcrumb', __( 'Contact', 'edify' ) );
$contact_title = get_theme_mod( 'contact_title', __( 'Contact Page', 'edify' ) );

$search_title = get_search_query() ;

function edify_breadcrumb_func() {
    global $post, $title;  
    $breadcrumb_class = '';
    $breadcrumb_show = 1;

    // "Show Page Banner" switch (Appearance > Customize > Page Header).
    // This setting existed in the Customizer but was never actually read
    // anywhere, so toggling it off never hid anything. Scoped to is_page()
    // so blog/archive/search/single/shop banners keep working as before.
    if ( is_page() && get_theme_mod( 'edify_hide_banner', true ) === false ) {
        return;
    }

    if ( is_front_page() && is_home() ) {
        $title = get_theme_mod('breadcrumb_blog_title', __('Blog','edify'));
        $breadcrumb_class = 'home_front_page';
    }
    elseif ( is_front_page() ) {
        $title = get_theme_mod('breadcrumb_blog_title', __('Blog','edify'));
        $breadcrumb_show = 0;
    }
    elseif ( is_home() ) {
        if ( get_option( 'page_for_posts' ) ) {
            $title = get_the_title( get_option( 'page_for_posts') );
        }
    }

    elseif ( is_single() && 'post' == get_post_type() ) {
      $title = get_the_title();
    } 
    elseif ( is_single() && 'product' == get_post_type() ) {
        $title = get_theme_mod( 'breadcrumb_product_details', __( 'Shop', 'edify' ) );
    } 
    elseif ( is_single() && 'courses' == get_post_type() ) {
      $title = esc_html__( 'Course Details', 'edify' );
    } 
    elseif ( 'courses' == get_post_type() ) {
      $title = esc_html__( 'Courses', 'edify' );
    } 
    elseif ( is_search() ) {
        $title = esc_html__( 'Search Results for : ', 'edify' ) . get_search_query();
    } 
    elseif ( is_404() ) {
        $title = esc_html__( 'Page not Found', 'edify' );
    } 
    elseif ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
        $title = get_theme_mod( 'breadcrumb_shop', __( 'Shop', 'edify' ) );
    } 
    elseif ( is_archive() ) {
        $title = get_the_archive_title();
    } 
    else {
        $title = get_the_title();
    }
 
    $_id = get_the_ID();

    if ( is_single() && 'product' == get_post_type() ) { 
        $_id = $post->ID;
    } 
    elseif ( function_exists("is_shop") AND is_shop()  ) { 
        $_id = wc_get_page_id('shop');
    } 
    elseif ( is_home() && get_option( 'page_for_posts' ) ) {
        $_id = get_option( 'page_for_posts' );
    }
?>
     <div class="page-header" >
      <div class="container" >
            <div class="row justify-content-center">
               <div class="col-xl-10 col-lg-10 col-md-12">
                  <div class="page-banner-content text-center">
                        <!-- <ul class="list-inline breadcrumb-nav">
                           <li class="list-inline-item">
                                <a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php echo esc_html__('Home','edify');?></a>
                           </li>
                           <li class="list-inline-item"><?php echo esc_html('/');?></li>
                           <li class="list-inline-item">
                                 <?php 
                                 if(!empty($blog_title_breadcrumb )) {
                                    echo esc_html($blog_title_breadcrumb );
                              } 
                              elseif(is_search()){
                                    echo esc_html($search_title);
                                 }
                                 elseif(is_archive()){
                                    the_archive_title();
                                 }
                                 elseif(( is_404() )){
                                    printf( esc_html__( '404 not found', 'edify' ), '<span>' );
                                 }
                                 
                                 else{
                                    the_title(); 
                                 }
                                 ?>
                           </li>
                        </ul> -->
                        <?php if(function_exists('bcn_display')) {
                                    bcn_display();
                                } ?>
                     <h1 class="banner-title ">
                        <?php 
                         if(!empty($blog_title )) {
                                echo esc_html($blog_title );
                           }
                           
                          elseif(is_archive()){
                                echo get_the_archive_title();
                           }
                           elseif(is_single())
                           {
                              the_title();
                           }
                           elseif(is_search()){
                              printf( esc_html__( 'Search Results for: %s', 'edify' ), '<span>' . get_search_query() . '</span>' );
                           }
                           elseif(( is_404() )){
                              printf( esc_html__( 'edify', 'edify' ), '<span>' );
                           }
                           else{
                              the_title();
                           }
                        ?> 
                     </h1>
                        
                  </div>
               </div>
            </div>
      </div>
   </div>  

    <?php
} // function close


add_action( 'edify_header_style', 'edify_breadcrumb_func', 10 );

// edify_search_form
function edify_search_form() {
    ?>
     <div class="search-wrapper p-relative transition-3 d-none">
         <div class="search-form transition-3">
             <form method="get" action="<?php print esc_url( home_url( '/' ) );?>" >
                 <input type="search" name="s" value="<?php print esc_attr( get_search_query() )?>" placeholder="<?php print esc_attr__( 'Enter Your Keyword', 'edify' );?>" >
                 <button type="submit" class="search-btn"><i class="far fa-search"></i></button>
             </form>
             <a href="javascript:void(0);" class="search-close"><i class="far fa-times"></i></a>
         </div>
     </div>
   <?php
}

add_action( 'edify_before_main_content', 'edify_search_form' );