<?php
/**
 * Template part for displaying default header layout
 */
$sticky_on = bixol_get_opt( 'sticky_on', false );
$header_type_page = bixol_get_page_opt( 'header_type', 'themeoption' );

$e_header_layout = bixol_get_opt('e_header_layout');
$e_header_layout_sticky = bixol_get_opt('e_header_layout_sticky');

$e_header_layout_page = bixol_get_page_opt('e_header_layout');
if($header_type_page == 'custom' ) {
    $e_header_layout = $e_header_layout_page;
}

$e_header_layout_sticky_page = bixol_get_page_opt('e_header_layout_sticky');
if($header_type_page == 'custom' ) {
    $e_header_layout_sticky = $e_header_layout_sticky_page;
}

$logo_m = bixol_get_opt( 'logo_mobile', array( 'url' => get_template_directory_uri().'/assets/images/logo-dark.png', 'id' => '' ) );
$e_logo_mobile = bixol_get_page_opt( 'p_logo_m' );
if($header_type_page == 'custom' && !empty($e_logo_mobile['url']) ) {
    $logo_m = $e_logo_mobile;
}

if(class_exists('\Elementor\Plugin')){
    $id = get_the_ID();
    if ( is_singular() && \Elementor\Plugin::$instance->documents->get( $id )->is_built_with_elementor() ) {
        $classes = 'ct-header-content';
    } else {
        $classes = 'container';
    }
} else {
    $classes = 'container';
}

?>
<header id="ct-header-elementor" class="is-sticky">
	<?php if(isset($e_header_layout) && !empty($e_header_layout)) : ?>
		<div class="ct-header-elementor-main">
		    <div class="<?php echo esc_attr($classes); ?>">
		        <div class="row">
		        	<div class="col-12">
			            <?php $post_main = get_post($e_header_layout);
	                    if (!is_wp_error($post_main) && $post_main->ID == $e_header_layout && class_exists('Case_Theme_Core') && function_exists('ct_print_html')){
	                        $content_main = \Elementor\Plugin::$instance->frontend->get_builder_content( $e_header_layout );
	                        ct_print_html($content_main);
	                    } ?>
	                </div>
		        </div>
		    </div>
		</div>
	<?php endif; ?>
	<?php if(isset($e_header_layout_sticky) && !empty($e_header_layout_sticky)) : ?>
		<div class="ct-header-elementor-sticky">
		    <div class="container">
		        <div class="row">
		            <?php $post_sticky = get_post($e_header_layout_sticky);
	                    if (!is_wp_error($post_sticky) && $post_sticky->ID == $e_header_layout_sticky && class_exists('Case_Theme_Core') && function_exists('ct_print_html')){
	                        $content_sticky = \Elementor\Plugin::$instance->frontend->get_builder_content( $e_header_layout_sticky );
	                        ct_print_html($content_sticky);
	                    } ?>
		        </div>
		    </div>
		</div>
	<?php endif; ?>
    <div id="ct-header-mobile" class="ct-header-mobile <?php if($sticky_on == 1) { echo 'is-sticky'; } ?>">
        <div id="ct-header" class="ct-header-main">
            <div class="container">
                <div class="row">
                    <div class="ct-header-branding">
                        <?php get_template_part( 'template-parts/header-branding' ); ?>
                    </div>
                    <div class="ct-header-navigation">
                        <nav class="ct-main-navigation">
                            <div class="ct-main-navigation-inner">
                                <?php if ($logo_m['url']) { ?>
                                    <div class="ct-logo-mobile">
                                        <a href="<?php esc_url( esc_url( home_url( '/' ) ) ); ?>" title="<?php esc_attr( get_bloginfo( 'name' ) ); ?>" rel="home"><img src="<?php echo esc_url( $logo_m['url'] ); ?>" alt="<?php esc_attr( get_bloginfo( 'name' ) ); ?>"/></a>
                                    </div>
                                <?php } ?>
                                <?php bixol_header_mobile_search(); ?>
                                <?php get_template_part( 'template-parts/header-menu' ); ?>
                            </div>
                        </nav>
                    </div>
                    <div class="ct-menu-overlay"></div>
                </div>
            </div>
            <div id="ct-menu-mobile">
                <div class="ct-mobile-meta-item btn-nav-mobile open-menu">
                    <span></span>
                </div>
            </div>
        </div>
    </div>
</header>