<?php
/**
 * Header Layout
 * @package Local Supermarket
 */

$local_supermarket_defaults = local_supermarket_get_default_theme_options();

global $wp_customize;

$local_supermarket_header_phone_number = esc_html( get_theme_mod( 'local_supermarket_header_phone_number',
$local_supermarket_defaults['local_supermarket_header_phone_number'] ) );

$local_supermarket_header_email_id = esc_html( get_theme_mod( 'local_supermarket_header_email_id',
$local_supermarket_defaults['local_supermarket_header_email_id'] ) );

$local_supermarket_header_address = esc_html( get_theme_mod( 'local_supermarket_header_address',
$local_supermarket_defaults['local_supermarket_header_address'] ) );

$local_supermarket_header_layout_wishlist = esc_html( get_theme_mod( 'local_supermarket_header_layout_wishlist',
$local_supermarket_defaults['local_supermarket_header_layout_wishlist'] ) );

?>

<header id="site-header" class="site-header-layout header-layout" role="banner">
    <div class="header-navbar ">
        <div class="wrapper header-wrapper">
            <div class="row d-flex justify-content-between row-gap-3">
                <div class="col-xl-2 col-lg-2 col-md-3 col-sm-12 align-self-center d-flex justify-content-md-start justify-content-center">
                    <?php if(class_exists('woocommerce')){ ?>
                        <div class="product-category-area">
                            <button class="product-btn"><i class="fa-solid fa-bars"></i><?php esc_html_e('All Categories','local-supermarket'); ?><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512"><path d="M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41z"/></svg></button>
                            <div class="product-cat">
                                <?php
                                    $args = array(
                                        'orderby'    => 'title',
                                        'order'      => 'ASC',
                                        'hide_empty' => 0,
                                        'parent'  => 0
                                    );
                                    $product_categories = get_terms( 'product_cat', $args );
                                    $count = count($product_categories);
                                    if ( $count > 0 ){
                                        foreach ( $product_categories as $product_category ) {
                                        $product_cat_id   = $product_category->term_id;
                                        $cat_link = get_category_link( $product_cat_id );
                                        if ($product_category->category_parent == 0) { ?>
                                        <li class="drp_dwn_menu"><a href="<?php echo esc_url(get_term_link( $product_category ) ); ?>">
                                    <?php
                                }
                                echo esc_html( $product_category->name ); ?></a><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 192 512"><path d="M0 384.662V127.338c0-17.818 21.543-26.741 34.142-14.142l128.662 128.662c7.81 7.81 7.81 20.474 0 28.284L34.142 398.804C21.543 411.404 0 402.48 0 384.662z"/></svg></li>
                                <?php } } ?>
                            </div>
                        </div>
                    <?php }?>
                </div>
                <div class="col-xl-10 col-lg-10 col-md-9 col-sm-12 align-self-center d-flex justify-content-sm-between info-row flex-wrap justify-content-center gap-2">
                    <div class="top-phone">
                        <p><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M172.3 501.7C27 291 0 269.4 0 192 0 86 86 0 192 0s192 86 192 192c0 77.4-27 99-172.3 309.7-9.5 13.8-29.9 13.8-39.5 0zM192 272c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/></svg><?php echo esc_html( $local_supermarket_header_address ); ?></p>
                    </div>
                    <div class="top-phone">
                        <p><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M497.4 361.8l-112-48a24 24 0 0 0 -28 6.9l-49.6 60.6A370.7 370.7 0 0 1 130.6 204.1l60.6-49.6a23.9 23.9 0 0 0 6.9-28l-48-112A24.2 24.2 0 0 0 122.6 .6l-104 24A24 24 0 0 0 0 48c0 256.5 207.9 464 464 464a24 24 0 0 0 23.4-18.6l24-104a24.3 24.3 0 0 0 -14-27.6z"/></svg><a href="tel:<?php echo esc_attr( $local_supermarket_header_phone_number ); ?>"><?php echo esc_html( $local_supermarket_header_phone_number ); ?></a></p>
                    </div>
                    <div class="top-phone">
                        <p><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M176 216h160c8.8 0 16-7.2 16-16v-16c0-8.8-7.2-16-16-16H176c-8.8 0-16 7.2-16 16v16c0 8.8 7.2 16 16 16zm-16 80c0 8.8 7.2 16 16 16h160c8.8 0 16-7.2 16-16v-16c0-8.8-7.2-16-16-16H176c-8.8 0-16 7.2-16 16v16zm96 121.1c-16.4 0-32.8-5.1-46.9-15.2L0 250.9V464c0 26.5 21.5 48 48 48h416c26.5 0 48-21.5 48-48V250.9L302.9 401.9c-14 10.1-30.4 15.2-46.9 15.2zm237.6-254.2c-8.9-6.9-17.2-13.5-29.6-22.8V96c0-26.5-21.5-48-48-48h-77.6c-3-2.2-5.9-4.3-9-6.6C312.6 29.2 279.2-.4 256 0c-23.2-.4-56.6 29.2-73.4 41.4-3.2 2.3-6 4.4-9 6.6H96c-26.5 0-48 21.5-48 48v44.1c-12.4 9.3-20.8 15.9-29.6 22.8A48 48 0 0 0 0 200.7v10.7l96 69.4V96h320v184.7l96-69.4v-10.7c0-14.7-6.8-28.7-18.4-37.8z"/></svg><a href="mailto:<?php echo esc_attr( $local_supermarket_header_email_id ); ?>"><?php echo esc_html( $local_supermarket_header_email_id ); ?></a></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom-header wrapper header-wrapper py-3">
        <div class="row">
            <div class="col-xl-2 col-lg-3 col-md-4 col-sm-4 col-12 align-self-center">
                <div class="header-titles">
                    <?php
                    local_supermarket_site_logo();
                    local_supermarket_site_description();
                    ?>
                </div>
            </div>
            <div class="col-xl-8 col-lg-7 col-md-4 col-sm-4 col-4 align-self-center">
                <div class="theme-header-areas header-areas-right">
                    <div class="site-navigation">
                        <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'local-supermarket'); ?>" role="navigation">
                            <ul class="primary-menu theme-menu">
                                <?php
                                if (has_nav_menu('local-supermarket-primary-menu')) {
                                    wp_nav_menu(
                                        array(
                                            'container' => '',
                                            'items_wrap' => '%3$s',
                                            'theme_location' => 'local-supermarket-primary-menu',
                                        )
                                    );
                                } else {
                                    wp_list_pages(
                                        array(
                                            'match_menu_classes' => true,
                                            'show_sub_menu_icons' => true,
                                            'title_li' => false,
                                            'walker' => new Local_Supermarket_Walker_Page(),
                                        )
                                    );
                                } ?>
                            </ul>
                        </nav>
                    </div>
                    <div class="navbar-controls twp-hide-js">
                        <button type="button" class="navbar-control navbar-control-offcanvas">
                            <span class="navbar-control-trigger" tabindex="-1">
                                <?php local_supermarket_the_theme_svg('menu'); ?>
                            </span>
                        </button>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-lg-2 col-md-4 col-sm-4 col-8 align-self-center d-flex justify-content-end gap-5">
                <?php if ( get_theme_mod('local_supermarket_header_search') == true ) : ?>
                    <span class="header-search">
                        <a href="#search">
                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6 .1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"/></svg>
                        </a>
                        <!-- Search Form -->
                        <div id="search">
                            <span class="close">X</span>
                            <?php get_search_form(); ?>
                        </div>
                    </span>
                <?php endif; ?>
                <?php if( $local_supermarket_header_layout_wishlist ){ ?>
                    <span class="wishlist">
                        <a href="<?php echo esc_url( $local_supermarket_header_layout_wishlist ); ?>">
                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"/></svg>
                        </a>
                    </span>
                <?php } ?>
                <?php if(class_exists('woocommerce')){ ?>
                    <span class="cart_no">
                        <a href="<?php if(function_exists('wc_get_cart_url')){ echo esc_url(wc_get_cart_url()); } ?>" title="<?php esc_attr_e( 'shopping cart','local-supermarket' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M160 112c0-35.3 28.7-64 64-64s64 28.7 64 64l0 48-128 0 0-48zm-48 48l-64 0c-26.5 0-48 21.5-48 48L0 416c0 53 43 96 96 96l256 0c53 0 96-43 96-96l0-208c0-26.5-21.5-48-48-48l-64 0 0-48C336 50.1 285.9 0 224 0S112 50.1 112 112l0 48zm24 48a24 24 0 1 1 0 48 24 24 0 1 1 0-48zm152 24a24 24 0 1 1 48 0 24 24 0 1 1 -48 0z"/></svg></a>
                        <span class="cart-value"><?php echo wp_kses_data( WC()->cart->get_cart_contents_count() );?></span>

                    </span>
                <?php } ?>
            </div>
        </div>
    </div>
</header>