<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div class="container">
 *
 * @package Classic Toy Store
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<?php if ( function_exists( 'wp_body_open' ) ) {
  wp_body_open();
} else {
  do_action( 'wp_body_open' );
} ?>

<?php if ( get_theme_mod('classic_toy_store_preloader', false) != "") { ?>
  <div id="preloader">
    <div id="status">&nbsp;</div>
  </div>
<?php }?>

<a class="screen-reader-text skip-link" href="#content"><?php esc_html_e( 'Skip to content', 'classic-toy-store' ); ?></a>

<div id="pageholder" <?php if( get_theme_mod( 'classic_toy_store_box_layout', false) != "" ) { echo 'class="boxlayout"'; } ?>>

<?php 
  $classic_toy_store_topbar_img = file_get_contents(get_template_directory_uri() . '/images/top-img.svg'); 
?>

<div class="mainhead">
  <div class="main-header">
    <?php if(get_theme_mod('classic_toy_store_topbar_text') != ''){ ?>
      <div class="header-sec position-relative">
        <div class="container">
          <p class="mb-0 text-center text-capitalize"><?php echo esc_html(get_theme_mod ('classic_toy_store_topbar_text','classic-toy-store')); ?></p>
        </div>
        <div class="topbar-img position-absolute"><?php echo $classic_toy_store_topbar_img; ?></div>
      </div>
    <?php } ?>
    <div class="product-top-sec py-lg-2 py-3">
      <div class="container">
        <div class="row">
          <div class="col-xxl-2 col-xl-2 col-lg-2 col-md-12 col-sm-12 col-12 align-self-center">
            <div class="classic-toy-store-logo">
              <?php if (get_theme_mod('classic_toy_store_logo_enable', true)) { ?>
                <?php classic_toy_store_the_custom_logo(); ?>
              <?php } ?>
              <div class="site-branding-text">
                <?php if (get_theme_mod('classic_toy_store_title_enable', false)) { ?>
                  <?php if (is_front_page() && is_home()) : ?>
                    <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>"><?php bloginfo('name'); ?></a></h1>
                  <?php else : ?>
                    <p class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>"><?php bloginfo('name'); ?></a></p>
                  <?php endif; ?>
                <?php } ?>
                <?php $classic_toy_store_description = get_bloginfo('description', 'display');
                if ($classic_toy_store_description || is_customize_preview()) : ?>
                  <?php if (get_theme_mod('classic_toy_store_tagline_enable', false)) { ?>
                    <span class="site-description"><?php echo esc_html($classic_toy_store_description); ?></span>
                  <?php } ?>
                <?php endif; ?>
              </div>
            </div>
          </div>
          <div class="col-xxl-6 col-xl-5 col-lg-4 col-md-7 col-sm-12 col-12 py-lg-0 py-3 align-items-center d-flex">
            <?php if(class_exists('woocommerce')){ ?>
              <div class=" position-relative">
                <button class="product-btn text-lg-start text-md-start text-center"><span class="cat-btn-text"><?php esc_html_e('Categories','classic-toy-store'); ?></span><i class="fa-solid fa-list-ul"></i></button>
                  <div class="product-categories">
                    <?php
                      $classic_toy_store_args = array(
                        'orderby'    => 'title',
                        'order'      => 'ASC',
                        'hide_empty' => 0,
                        'parent'  => 0
                      );
                      $classic_toy_store_product_categories = get_terms( 'product_cat', $classic_toy_store_args );
                      $classic_toy_store_count = count($classic_toy_store_product_categories);
                      if ( $classic_toy_store_count > 0 ){
                          foreach ( $classic_toy_store_product_categories as $classic_toy_store_product_category ) {
                            $classic_toy_store_product_cat_id = $classic_toy_store_product_category->term_id;
                            $classic_toy_store_cat_link = get_category_link( $classic_toy_store_product_cat_id );
                            if ($classic_toy_store_product_category->category_parent == 0) { ?>
                          <li class="drp_dwn_menu"><a href="<?php echo esc_url(get_term_link( $classic_toy_store_product_category ) ); ?>">
                          <?php
                        }
                        echo esc_html( $classic_toy_store_product_category->name ); ?></a></li>
                    <?php } } ?>
                  </div>
              </div>
            <?php }?>

            <?php if (class_exists('WooCommerce')): ?>
              <div class="search_box">
                <?php echo get_product_search_form(); ?>
              </div>
            <?php else: ?>
              <div class="search_box">
                <?php echo get_search_form(); ?>
              </div>
            <?php endif; ?>
          </div>
          <div class="offset-xxl-1 offset-xl-2 offset-lg-2 col-xxl-2 col-xl-2 col-lg-3 col-md-3 col-sm-5 col-7 align-self-center">
            <?php if (get_theme_mod('classic_toy_store_phone_icon') != "" || get_theme_mod('classic_toy_store_phone_title') != "" || get_theme_mod('classic_toy_store_phone_number') != "") { ?>
              <div class="phone-sec">
                <div class="row">
                  <div class="col-xxl-2 col-xl-2 col-lg-2 col-md-2 col-sm-2 col-2 align-self-center phone-icon">
                    <?php $classic_toy_store_icon = get_theme_mod('classic_toy_store_phone_icon', ''); ?><i class="<?php echo esc_attr($classic_toy_store_icon); ?>"></i>
                  </div>
                  <div class="col-xxl-10 col-xl-10 col-lg-10 col-md-10 col-sm-10 col-10 align-self-center">
                    <p class="phone-title text-capitalize mb-0"><?php echo esc_html(get_theme_mod('classic_toy_store_phone_title')); ?></p><a class="phone-no" href="tel:<?php echo esc_attr( get_theme_mod('classic_toy_store_phone_number','' )); ?>"><?php echo esc_html(get_theme_mod ('classic_toy_store_phone_number','')); ?></a>
                  </div>
                </div>
              </div>
            <?php } ?>
          </div>
          <div class="col-xxl-1 col-xl-1 col-lg-1 col-md-2 col-sm-7 col-5 align-items-center d-flex justify-content-end gap-1 top-btn">
            <?php if (class_exists('woocommerce')) { ?>
              <span class="product-cart">
                <a href="<?php if(function_exists('wc_get_cart_url')){ echo esc_url(wc_get_cart_url()); } ?>" title="<?php esc_attr_e( 'shopping cart','classic-toy-store' ); ?>"><i class="fas fa-shopping-bag"></i></a>
              </span>
              <span class="wishlist">
                <?php 
                  if (defined('YITH_WCWL') && class_exists('YITH_WCWL_Wishlists')) {?>
                  <a class="wishlist_view position-relative" href="<?php echo esc_url(YITH_WCWL()->get_wishlist_url()); ?>">
                    <i class="fa-solid fa-heart"></i>
                  </a>
                <?php }?>
              </span>
              <span class="product-account text-center">
                <?php if (is_user_logged_in()) { ?>
                  <a href="<?php echo esc_url(get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>" title="<?php esc_attr_e('My Account', 'classic-toy-store'); ?>"><i class="fa-solid fa-user"></i></a>
                <?php } else { ?>
                  <a href="<?php echo esc_url(get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>" title="<?php esc_attr_e('Login / Register', 'classic-toy-store'); ?>"><i class="fa-solid fa-user"></i></a>
                <?php } ?>
              </span>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
    <div class="menu-sec <?php if( get_theme_mod( 'classic_toy_store_sticky_header', false) == 1 ) { ?> header-sticky"<?php } else { ?>close-sticky <?php } ?>">
      <div class="toggle-nav text-center">
        <?php if (has_nav_menu('primary')) { ?>
          <button role="tab"><?php esc_html_e('Menu', 'classic-toy-store'); ?></button>
        <?php } ?>
      </div>
      <div id="mySidenav" class="nav sidenav">
        <nav id="site-navigation" class="main-nav" role="navigation" aria-label="<?php esc_attr_e('Top Menu', 'classic-toy-store'); ?>">
          <ul class="mobile_nav">
            <?php wp_nav_menu(array(
              'theme_location' => 'primary',
              'container_class' => 'main-menu',
              'items_wrap' => '%3$s',
              'fallback_cb' => 'wp_page_menu',
            )); ?>
          </ul>
          <a href="javascript:void(0)" class="close-button"><?php esc_html_e('CLOSE', 'classic-toy-store'); ?></a>
        </nav>
      </div>
    </div>
  </div>
</div>