<?php
/**
 * benqu Mainmenu
 */
function benqu_mainmenu(){
    wp_nav_menu( [
        'theme_location' => 'main_menu',
        'menu_class'     => 'navigation clearfix',
        'container'      => '',
        'fallback_cb'    => 'WP_benqu_Navwalker::fallback',
    ] );
}
function benqu_footer_nav(){
    wp_nav_menu( [
        'theme_location' => 'footer-nav',
        'menu_class'     => 'navigation clearfix',
        'fallback_cb'    => 'WP_benqu_Navwalker::fallback',
    ] );
}

function benqu_mobile_nav(){
    echo str_replace(['menu-item-has-children'], ['dropdown'], wp_nav_menu( array( 
        'echo' => false,
        'theme_location' => 'main_menu', 
        'menu_id'     => 'pfy-mobile-menu',
    )) );
}


function benqu_preloader_opt(){         
    $preloader_enable = cs_get_option( 'preloader_enable' );
    if($preloader_enable == true):
?>
    <div class="benqu_preloader">
        <div id="loading">
            <div id="loading-center">
                <div id="loading-center-absolute">
                    <div class="object" id="object_one"></div>
                    <div class="object" id="object_two"></div>
                    <div class="object" id="object_three"></div>
                    <div class="object" id="object_four"></div>
                </div>
            </div>        
        </div>
    </div>
<?php 
endif;
}

function benqu_accept_cookies(){ 
    $bnq_cookie_content = cs_get_option( 'bnq-cookie-content' );	    
    $bnq_cookie_btn = cs_get_option( 'bnq_cookie_btn' );
    $cooki_enable_disable = cs_get_option( 'cooki_enable_disable' );
if( $cooki_enable_disable == true && !empty($bnq_cookie_content) && !empty($bnq_cookie_btn)):	    
?>
<div class="bnq__cookie_area">
    <?php echo wp_kses(wpautop($bnq_cookie_content), true);?>
    <div>
        <button class="bnq__cookie_btn"><?php echo esc_html($bnq_cookie_btn);?></button>
    </div>
</div>
<?php 
endif;
}

/**
 * 
 */
function benqu_header_option(){

	if( 'header-style-one' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'one' );
	} elseif( 'header-style-two' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'two' );
	} elseif( 'header-style-three' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'three' );
	} elseif( 'header-style-four' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'four' );
	} elseif( 'header-style-five' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'five' );
	} elseif( 'header-style-six' === benqu_site_header() ) {
		get_template_part( 'template-parts/header/header', 'six' );
	} else {
		get_template_part( 'template-parts/header/header', 'one' );
	}
}

/**
 * Footer Layout
 */
function pfy_footer_option(){

	if( 'footer-style-one' === benqu_site_footer() ) {
		get_template_part( 'template-parts/footer/footer', 'one' );
	} elseif( 'footer-style-two' === benqu_site_footer() ) {
		get_template_part( 'template-parts/footer/footer', 'two' );
	} elseif( 'footer-style-three' === benqu_site_footer() ) {
		get_template_part( 'template-parts/footer/footer', 'three' );
	} else {
		get_template_part( 'template-parts/footer/footer', 'one' );
	}
}
/**
 * benqu Header Search
 */
function benqu_header_search(){ 
    $enable_header_search = cs_get_option( 'enable_header_search' );
    if($enable_header_search == true):
    ?>
    <form method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
        <input type="search" name="s" id="search" value="<?php the_search_query();?>" placeholder="<?php esc_attr_e( 'Search ...', 'benqu' )?>" />        
        <button type="submit"><i class="far fa-search"></i></button>
    </form>
<?php 
endif;
}

/**
 * benqu Page Loop
 */
function benqu_page_loop(){
    while ( have_posts() ) :
        the_post();

        get_template_part( 'template-parts/content', 'page' );

        // If comments are open or we have at least one comment, load up the comment template.
        if ( comments_open() || get_comments_number() ) :
            comments_template();
        endif;

    endwhile; // End of the loop.
}

/**
 * Single Team
 */
function benqu_single_team(){
    while ( have_posts() ) :
        the_post();

        get_template_part( 'template-parts/content', 'team' );

    endwhile;
}

function pfy_post_main_loop(){
    if ( have_posts() ) :
    /* Start the Loop */
    while ( have_posts() ) :
        the_post();

        /*
            * Include the Post-Type-specific template for the content.
            * If you want to override this in a child theme, then include a file
            * called content-___.php (where ___ is the Post Type name) and that will be used instead.
            */
        get_template_part( 'template-parts/post-formats/content', get_post_format() );

    endwhile; ?>

    <div class="pfy-pagination">
        <?php benqu_pagination();?>
    </div>

<?php else :

    get_template_part( 'template-parts/content', 'none' );

endif;
}
/***
 * Post Single Loop
 */
function pfy_post_single_loop(){
    $single_post_global = cs_get_option( 'post_single_global_layout' );	
	$single_post_local = get_post_meta( get_the_ID(),'benqu_post_layout_meta', true );

	$post_single_meta = isset($single_post_local['post_single_layout']) && !empty($single_post_local['post_single_layout']) ? $single_post_local['post_single_layout'] : '';

    if( !empty( $single_post_local  ) ) {	 
		get_template_part( 'template-parts/single/'.$post_single_meta.'' ); 	
	} elseif ( class_exists( 'CSF' ) && !empty( $single_post_global ) ) {		
		get_template_part( 'template-parts/single/'.$single_post_global.'' );  		
	} else {		
		get_template_part( 'template-parts/single/single-one' );  
	}
}

/**
 * benqu Breadvrumb
 *
 * @return void
 */
function benqu_get_breadcrumb(){
	$benqu_br_off_on = cs_get_option( 'benqu_br_off_on' );
	$benqu_br_off_on = is_null($benqu_br_off_on) ? true : $benqu_br_off_on;
	if($benqu_br_off_on == true):
?>
  <div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
					<?php echo benqu_breadcrumb();?>
				</div>
			</div>
		</div>
	</div>
<?php
	endif;
}

/**
 * Header Seach
 */

 function papyrfy_header_search_two(){ ?>
    <div class="benqu_header_search">
        <div class="container">
            <div class="row d-flex justify-content-center">
                <div class="col-md-12">
                    <form method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                        <input type="search" name="s" id="search" value="<?php the_search_query();?>" placeholder="<?php esc_attr_e( 'Search Headlines, News...', 'benqu' )?>" />
                        <i class="close-btn fal fa-times"></i>
                    </form>
                </div>
            </div>
        </div>
    </div>
 <?php
} 

/**
 * benqu Blog Breadcrumb
 *
 * @return void
 */
function benqu_display_blog_breadcrumb(){ 
	$blog_br_text = cs_get_option( 'blog_br_text' );	
	$blog_br_off_on = cs_get_option( 'blog_br_off_on' );
	if($blog_br_off_on == true): 
?>
  <div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
						<div class="breadcrumb-item">
								<?php 
									if(function_exists('bcn_display')){
											bcn_display();
									} else {
								?>
									<ol class="breadcrumb-item">
										<li><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php esc_html_e( 'Home', 'benqu' );?></a></li> 
										<li> 
											<?php
													if(!empty($blog_br_text)){
															echo esc_html($blog_br_text);
													} else {
															esc_html_e( 'Blog', 'benqu' );
													}
											?>
										</li>
									</ol>
								<?php } ?>
						</div>
				</div>
			</div>
		</div>
	</div>
<?php 
	endif;
}

/**
 * benqu ARchive Breadcrumb
 *
 * @return void
 */
function benqu_display_archive_breadcrumb(){
	$benqu_br_off_on = cs_get_option( 'benqu_br_off_on' );
	$benqu_root_br_text = cs_get_option( 'benqu_root_br_text' );
	$benqu_br_off_on = is_null($benqu_br_off_on) ? true : $benqu_br_off_on;
	if($benqu_br_off_on == true):
?>
  <div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
						<div class="breadcrumb-item">
								<?php 
								if(function_exists('bcn_display')){
										bcn_display();
								} else { ?>
								<ol class="breadcrumb-item">
										<li>
											<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
												<?php
													if(!empty($benqu_root_br_text)){
															esc_html_e($benqu_root_br_text);
													} else {
															esc_html_e( 'Home', 'benqu' );
													}
												?>
											</a>
										</li>
										<li> <?php the_archive_title();the_archive_description( '<div class="archive-description">', '</div>' );?> </li>
								</ol>
								<?php } ?>
						</div>
				</div>
			</div>
		</div>
	</div>
<?php
	endif;
}

/**
 * benqu Single Breadcrumb
 *
 * @return void
 */
function benqu_display_single_breadcrumb(){
	$benqu_br_off_on = cs_get_option( 'benqu_br_off_on' );
	$benqu_root_br_text = cs_get_option( 'benqu_root_br_text' );
	$benqu_br_off_on = is_null($benqu_br_off_on) ? true : $benqu_br_off_on;
	if($benqu_br_off_on == true):	
?>
  <div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
						<div class="breadcrumb-item">
								<?php 
								if(function_exists('bcn_display')){
										bcn_display();
								} else { ?>
								<ol class="breadcrumb-item">
										<li>
											<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
												<?php
													if(!empty($benqu_root_br_text)){
															esc_html_e($benqu_root_br_text);
													} else {
															esc_html_e( 'Home', 'benqu' );
													}
												?>
											</a>
										</li>
										<li> <?php the_title();?> </li>
								</ol>
								<?php } ?>
						</div>
				</div>
			</div>
		</div>
	</div>
<?php
	endif;
}

/**
 * benqu Page Breadcrumb
 *
 * @return void
 */
function benqu_page_display_breadcrumb(){
	$benqu_br_off_on = cs_get_option( 'benqu_br_off_on' );
	$benqu_root_br_text = cs_get_option( 'benqu_root_br_text' );
	$benqu_br_off_on = is_null($benqu_br_off_on) ? true : $benqu_br_off_on;
	if($benqu_br_off_on == true):	
	?>
  <div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
					<div class="breadcrumb-item">
							<?php 
							if(function_exists('bcn_display')){
									bcn_display();
							} else { ?>
							<ol class="breadcrumb-item">
									<li>
										<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
											<?php
												if(!empty($benqu_root_br_text)){
														esc_html_e($benqu_root_br_text);
												} else {
														esc_html_e( 'Home', 'benqu' );
												}
											?>
										</a>
									</li>
									<li> <?php the_title();?> </li>
							</ol>
							<?php } ?>
					</div>
				</div>
			</div>
		</div>
	</div>
<?php
	endif;
}

/**
 * Search Breadcrumb
 */
function papuefy_search_breadcrumb(){
	$benqu_br_off_on = cs_get_option( 'benqu_br_off_on' );
	$benqu_br_off_on = is_null($benqu_br_off_on) ? true : $benqu_br_off_on;
	if($benqu_br_off_on == true):
?>
	<div class="benqu-breadcrumb">
		<div class="container">
			<div class="row">
				<div class="col-lg-12">
					<?php echo benqu_breadcrumb();?>
				</div>
			</div>
		</div>
	</div>
<?php
	endif;
}

/**
 * benqu Error Info
 */
function benqu_error_info(){ 
    $error_imge = cs_get_option('error_imge');    
    $error_title = cs_get_option('error_title');    
    $error_button = cs_get_option('error_button');

    $erro_img_url = '';

    if(!empty($error_imge['url'])){
        $erro_img_url = $error_imge['url'];
    }else{
        $erro_img_url = get_template_directory_uri(). "/assets/img/error-code.png";
    }
?>
    <div class="pfy__error_content text-center">
        <img src="<?php echo esc_url($erro_img_url);?>" alt="<?php esc_attr_e( '404', 'benqu' );?>">
        <h1>
        <?php
            if($error_title){
                echo esc_html($error_title);
            }else {
                esc_html_e( '404', 'benqu' );
            }             
            ?>
        </h1>
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="pfy-btn pfy-btn-primery">
            <?php 
                if($error_button){
                    echo esc_html($error_button);
                }else {
                    esc_html_e( 'Back To Home', 'benqu' );
                }
                
            ?>
        </a>
    </div>
<?php }

/**
 * Search Page Loop
 */
function benqu_search_loop(){
    if ( have_posts() ) : 
			/* Start the Loop */
			while ( have_posts() ) :
				the_post();

				/**
				 * Run the loop for the search to output the results.
				 * If you want to overload this in a child theme then include a file
				 * called content-search.php and that will be used instead.
				 */
				get_template_part( 'template-parts/content', 'search' );

			endwhile; ?>

			<div class="pfy-pagination">
                <?php benqu_pagination();?>
            </div>

		<?php else :

			get_template_part( 'template-parts/content', 'none' );

		endif;
}


/**
 * benqu Dark Stiwch
 */
function benqu_dark_switch(){ 
    $enable_darkmode = cs_get_option( 'enable_darkmode' ); 
    $enable_d_darkmode = cs_get_option( 'enable_d_darkmode' ); 
    if($enable_d_darkmode == false):
    if($enable_darkmode == true):   
?>
    <!-- benqu-switch-box -->
        <div class="benqu-switch-box-wrap">
            <div class="benqu-switch-box">
            <label class="benqu-switch-box__label" for="themeSwitchCheckbox">
                <input class="benqu-switch-box__input" type="checkbox" name="themeSwitchCheckbox"
                    id="themeSwitchCheckbox">
            </label>
            </div>
        </div>
        <!-- end benqu-switch-box -->
    <?php 
    endif;
    endif;
}

function benqu_archive_loop(){ ?>
    <?php if ( have_posts() ) : ?>

			<?php
			/* Start the Loop */
			while ( have_posts() ) :
				the_post();

				/*
				 * Include the Post-Type-specific template for the content.
				 * If you want to override this in a child theme, then include a file
				 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
				 */
				get_template_part( 'template-parts/post-formats/content', get_post_format() );

			endwhile;

			the_posts_navigation();

		else :

			get_template_part( 'template-parts/content', 'none' );

		endif;
		?>
<?php }


function bnqu_newsletter_popup(){
    $newsletter_popup_enable = cs_get_option('newsletter_popup_enable');   
    $newsletter_img = cs_get_option('newsletter_img');   
    $newsletter_title = cs_get_option('newsletter_title');   
    $newsletter_info = cs_get_option('newsletter_info');   
    $newsletter_shortcode = cs_get_option('newsletter_shortcode');   

    if($newsletter_popup_enable == true):
?>
 <div class="bnqu__popup_wrap">
    <div class="bnqu__popup_sec">
        <div class="bnqu__popup_ineer">
            <button class="btn newsletter-close-btn"><i class="fal fa-times"></i></button>
            <?php if(!empty($newsletter_img['url'])):?>
            <div class="img-holder">
                <img src="<?php echo esc_url($newsletter_img['url']);?>" alt="<?php echo esc_attr($newsletter_img['alt']);?>">
            </div>
            <?php endif;?>
            <div class="details">
                <?php if($newsletter_title):?>
                <h1><?php echo wp_kses( $newsletter_title, true );?></h1>
                <?php endif;?>

                <?php if($newsletter_info):?>
                    <p><?php echo wp_kses( $newsletter_info, true );?></p>
                <?php endif;?>
                <?php if(!empty($newsletter_shortcode)):?>
                    <?php echo do_shortcode( $newsletter_shortcode );?>
                <?php endif;?>
            </div>
        </div>
    </div> 
</div>
<?php 
endif;
}