<?php
/**
 * Displays main header
 *
 * @package Timber Work
 */
?>
<?php if ( function_exists( 'wp_body_open' ) ) { wp_body_open();} else { do_action( 'wp_body_open' ); }
  $timber_work_sticky_header = get_theme_mod('timber_work_sticky_header');
  $timber_work_data_sticky = "false";
  if ($timber_work_sticky_header) {
      $timber_work_data_sticky = "true";
  }
?>
<div class="main-header text-center text-md-start">
    <div class="container">
        <div class="row nav-box">
            <div class="col-xl-3 col-lg-4 col-md-4 logo-box align-self-center">
                <div class="navbar-brand ">
                    <?php if ( has_custom_logo() ) : ?>
                        <div class="site-logo"><?php the_custom_logo(); ?></div>
                    <?php endif; ?>
                    <?php $timber_work_blog_info = get_bloginfo( 'name' ); ?>
                        <?php if ( ! empty( $timber_work_blog_info ) ) : ?>
                            <?php if ( is_front_page() && is_home() ) : ?>
                                <?php if( get_theme_mod('timber_work_logo_title_text',true) != ''){ ?>
                                    <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
                                <?php } ?>
                            <?php else : ?>
                                <?php if( get_theme_mod('timber_work_logo_title_text',true) != ''){ ?>
                                    <p class="site-title "><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
                                <?php } ?>
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php
                            $timber_work_description = get_bloginfo( 'description', 'display' );
                            if ( $timber_work_description || is_customize_preview() ) :
                        ?>
                        <?php if( get_theme_mod('timber_work_theme_description',false) != ''){ ?>
                            <p class="site-description pb-2"><?php echo esc_html($timber_work_description); ?></p>
                        <?php } ?>
                    <?php endif; ?>
                </div>
            </div>
            <div class="col-xl-9 col-lg-8 col-md-8">
                <div class="main-nav" data-sticky="<?php echo esc_attr($timber_work_data_sticky); ?>">
                    <div class="row">
                        <div class="col-xl-8 col-lg-7 col-md-5 align-self-center">
                            <?php get_template_part('template-parts/navigation/nav'); ?>
                        </div>
                        <div class="col-xl-4 col-lg-5 col-md-4 col-md-7 align-self-center header-search d-flex justify-content-md-end justify-content-center">
                            <?php if (get_theme_mod('timber_work_header_search_setting', false) != false) { ?>
                                <span class="head-search align-self-center">
                                    <span class="header-search-wrapper">
                                        <a href="#" class="search-main"><i class="fa fa-search"></i></a>
                                        <div class="search-form-main clearfix">
                                            <form method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                                                <input type="hidden" name="post_type" value="<?php echo esc_attr( get_search_query() ); ?>"> <!-- Set post type to product for WooCommerce products -->
                                                <label>
                                                    <input type="search" class="search-field form-control" placeholder="Search 
                                                    ..." value="<?php echo get_search_query(); ?>" name="s">
                                                </label>
                                                <input type="submit" class="search-submit btn btn-primary mt-3" value="Search">
                                            </form>
                                        </div>
                                    </span>
                                </span>
                            <?php } ?>
                            <?php if (get_theme_mod('timber_work_header_sidebar_setting', false) != '') { ?>
                                <div class="bar-icon">
                                    <button onclick="timber_work_openSidebar()"><i class="fas fa-th"></i></button>
                                    <div class="header-widgets">
                                        <a href="javascript:void(0)" class="closebtn" onclick="timber_work_closeSidebar()"><i class="fas fa-times"></i></a>
                                        <div class="sidebar">
                                            <?php if( is_active_sidebar('header-sidebar') ) : ?>
                                                <?php dynamic_sidebar( 'header-sidebar' );?>
                                            <?php else : ?>
                                                <h4><?php esc_html_e('Add Widgets Here.', 'timber-work'); ?></h4>
                                            <?php endif;?>
                                        </div>
                                    </div>
                                </div>
                            <?php }?>
                            <?php if(get_theme_mod('timber_work_header_btn_text') != '' || get_theme_mod('timber_work_header_btn_url') != ''){?>
                                <div class="headbtn">
                                <a href="<?php echo esc_url(get_theme_mod('timber_work_header_btn_url')); ?>" class="header-btn"><?php echo esc_html(get_theme_mod('timber_work_header_btn_text')); ?></a>
                                </div>
                            <?php }?>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>
