<?php
$enable_header_top_bar = get_theme_mod('edumodo_header_enable_top_bar', 'no');
$enable_header_top_menu = get_theme_mod('edumodo_header_enable_menu', 'no');
$header_top_menu       = get_theme_mod('edumodo_header_right_menu', 'no');
$enable_login          = get_theme_mod('edumodo_header_enable_login', 'yes');
$enable_social         = get_theme_mod('edumodo_header_social_enable', 'yes');
$phone_number          = get_theme_mod('edumodo_top_bar_phone', '0123456789');
$email                 = get_theme_mod('edumodo_top_bar_email', 'hello@admin.com');
$login_text            = get_theme_mod('edumodo_top_bar_login_text', 'Login');
$login_url             = get_theme_mod('edumodo_top_bar_login_url', '#');
$registration_text     = get_theme_mod('edumodo_top_bar_register_text', 'Register');
$registration_url      = get_theme_mod('edumodo_top_bar_register_url', '#');
$profile_text          = get_theme_mod('edumodo_top_bar_profile_text', 'Profile');
$profile_url           = get_theme_mod('edumodo_top_bar_profile_url', '#');
$facebook              = get_theme_mod('edumodo_social_facebook_url', '#');
$twitter               = get_theme_mod('edumodo_social_twitter_url', '#');
$instagram             = get_theme_mod('edumodo_social_instagram_url', '#');
$linkedin              = get_theme_mod('edumodo_social_linkedin_url', '#');
$whatsapp              = get_theme_mod('edumodo_social_whatsapp_url', '#');
$youtube               = get_theme_mod('edumodo_social_youtube_url', '#');
$skype                 = get_theme_mod('edumodo_social_skype_url', '#');
$snapchat              = get_theme_mod('edumodo_social_snapchat_url', '#');
$enable_cart           = get_theme_mod('edumodo_header_cart', 'off');
$enable_search         = get_theme_mod('edumodo_header_search', 'off');
?>

<?php if ('yes' == $enable_header_top_bar) : ?>
    <div id="top-header" class="top-header" class="hidden-xs">
        <div class="container <?php echo esc_attr($enable_header_top_menu == 'yes' ? 'enabled-menu ' : 'disabled-menu '); ?><?php echo esc_attr($enable_login == 'yes' ? 'enabled-login ' : 'disbaled-login '); ?><?php echo esc_attr($enable_social == 'yes' ? 'enabled-social' : 'disbaled-social'); ?>">
            <div class="left-side tophead-left col-md-4">
                <div class="tophead-contact">
                    <div class="top-lists">
                        <?php if (!empty($phone_number)) : ?>
                            <span>
                                <i class="glyph-icon flaticon-telephone-handle-silhouette"></i>
                                <a class="top-phone" href="tel:<?php echo esc_attr__($phone_number, 'edumodo'); ?>"><?php echo esc_html__($phone_number, 'edumodo'); ?></a>
                            </span>
                            <span class="topbar-seperator">|</span>
                        <?php endif; ?>
                        <?php if (!empty($email)) : ?>
                            <span>
                                <i class="glyph-icon flaticon-message-closed-envelope"></i>
                                <a class="top-email" href="mailto:<?php echo esc_attr__($email, 'edumodo') ?>"><?php echo esc_html__($email, 'edumodo') ?></a>
                            </span>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div class="right-side tophead-right col-md-8 text-right">
                <?php if ('yes' == $enable_header_top_menu) : ?>
                    <div class="header-top-menu">
                        <?php
                        wp_nav_menu([
                            'menu' => $header_top_menu,
                            'menu_class' => 'header-top-bar-menu',
                            'container_class' => 'header-top-bar-menu-wrapper'
                        ]);
                        ?>
                    </div>
                <?php endif; ?>
                <?php if ('yes' == $enable_social) : ?>
                    <div class="header-social-icons">
                        <ul>
                            <?php if (!empty($facebook)) : ?>
                                <li><a href="<?php echo esc_url($facebook); ?>"><i class="fa fa-facebook"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($twitter)) : ?>
                                <li><a href="<?php echo esc_url($twitter); ?>"><i class="fa fa-twitter"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($instagram)) : ?>
                                <li><a href="<?php echo esc_url($instagram); ?>"><i class="fa fa-instagram"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($linkedin)) : ?>
                                <li><a href="<?php echo esc_url($linkedin); ?>"><i class="fa fa-linkedin"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($whatsapp)) : ?>
                                <li><a href="<?php echo esc_url($whatsapp); ?>"><i class="fa fa-whatsapp"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($youtube)) : ?>
                                <li><a href="<?php echo esc_url($youtube); ?>"><i class="fa fa-youtube"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($skype)) : ?>
                                <li><a href="<?php echo esc_url($skype); ?>"><i class="fa fa-skype"></i></a></li>
                            <?php endif; ?>
                            <?php if (!empty($snapchat)) : ?>
                                <li><a href="<?php echo esc_url($snapchat); ?>"><i class="fa fa-snapchat"></i></a></li>
                            <?php endif; ?>
                        </ul>
                    </div>
                <?php endif; ?>
                <?php if ('yes' == $enable_login) : ?>
                    <div class="login-reg-btn">
                        <ul>
                            <?php if (is_user_logged_in()) : ?>
                                <li>
                                    <a href="<?php echo wp_logout_url(); ?>"><i class="fa fa-unlock"></i>
                                        <?php _e('Logout', 'edumodo') ?></a>
                                </li>
                                <?php if (!empty($profile_text)) : ?>
                                    <li><small></small></li>
                                    <li>
                                        <a href="<?php echo esc_url($profile_url) ?>"><i class="fa fa-user"></i> <?php echo esc_html__($profile_text, 'edumodo') ?></a>
                                    </li>
                                <?php endif; ?>

                            <?php else : ?>
                                <?php if (!empty($login_url)) : ?>
                                    <li>
                                        <a href="<?php echo esc_url($login_url) ?>"><i class="fa fa-lock"></i>
                                            <?php echo esc_html__($login_text, 'edumodo') ?></a>
                                    </li>
                                    <li><small></small></li>
                                <?php endif; ?>

                                <?php if (!empty($registration_url)) : ?>
                                    <li>
                                        <a href="<?php echo esc_url($registration_url) ?>"><i class="fa fa-user"></i>
                                            <?php echo esc_html__($registration_text, 'edumodo') ?></a>
                                    </li>
                                <?php endif; ?>
                            <?php endif; ?>
                        </ul>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endif; ?>

<?php
global $woocommerce;
function edumodo_add_to_cart_fragment($fragments)
{
    ob_start();

    edumodo_wc_mini_cart();

    $fragments['a.cart-button'] = ob_get_clean();

    return $fragments;
}
function edumodo_wc_mini_cart()
{
?>
    <a class="mini-cart" href="<?php echo esc_attr(wc_get_cart_url()); ?>">
        <i class="fa fa-shopping-cart"></i>
        <span class="cart-total-number"><?php echo esc_html(WC()->cart->cart_contents_count); ?></span>
    </a>
<?php
}

add_filter('add_to_cart_fragments', 'edumodo_add_to_cart_fragment');

// header custom search form 
function edumodo_search_form($form)
{
    $form = '
            <form role="search" method="get" id="searchform" class="searchform" action="' . home_url('/') . '" >
                <div>
                    <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . esc_attr__('Search', 'edumodo') . '"/>
                    <button type="submit" id="searchsubmit"><i class="fa fa-search"></i></button>
                </div>
            </form>';

    return $form;
}
add_filter('get_search_form', 'edumodo_search_form');

?>

<div id="edumodo-mainnav" class="navbar-v1 edumodo-mainnav">
    <div class="container">
        <div class="row">
            <div class="nav-logo-align">
                <div class="logo">
                    <div class="navbar-header">
                        <?php $description = get_bloginfo('description', 'display'); ?>
                        <div class="logo-wrapper">
                            <?php
                            if (has_custom_logo()) {
                                the_custom_logo();
                            }

                            if ($description || is_customize_preview()) : ?>
                                <h2 class="site-title">
                                    <a href="<?php echo esc_url(home_url('/')); ?>">
                                        <?php bloginfo('name'); ?>
                                    </a>
                                </h2>
                                <h6 class="site-description"><?php bloginfo('description'); ?></h6>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div class="menu-wrapper pull-right text-right hidden-xs hidden-sm <?php echo esc_attr('on' == $enable_cart ? '' : 'cart-off');
                                                                                    echo esc_attr('on' == $enable_search ? '' : ' serach-off '); ?>">
                    <?php
                    wp_nav_menu(array(
                        'menu'              => 'primary',
                        'theme_location'    => 'primary',
                        'depth'             => 0,
                        'menu_class'        => 'navigation-main hidden-sm hidden-xs',
                        'fallback_cb'       => 'tx_megamenu_navwalker::fallback',
                        'walker'            => new tx_megamenu_navwalker()
                    ));
                    ?>

                </div>

                <div class="pull-right text-right visible-xs visible-sm hidden-md hidden-lg">
                    <div id="mobile-menu-wrapper" class="mmenu-wrapper">
                        <div class="header-toggle-btn">
                            <a class="sidebar-toggle-btn">
                                <i class="fa fa-bars"></i>
                            </a>
                        </div>
                        <nav id="mmenu" class="main-menu">
                            <?php
                            wp_nav_menu(array(
                                'menu' => 'mobile_menu',
                                'theme_location' => 'primary',
                            ));
                            ?>
                        </nav>
                    </div>
                </div>
                <?php if ('on' == $enable_cart || 'on' == $enable_search) : ?>
                    <div class="mini-cart-search text-right">
                        <?php if ('on' == $enable_cart) : ?>
                            <?php if (class_exists('woocommerce')) : ?>
                                <div class="mini-cart-wrap">
                                    <?php edumodo_wc_mini_cart(); ?>
                                </div>
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php if ('on' == $enable_search) : ?>
                            <div class="header-search-wrap">
                                <div class="search-icon">
                                    <span><i class="fa fa-search"></i><i class="fa fa-times"></i></span>
                                </div>
                                <div class="header-search-form">
                                    <?php get_search_form(); ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>