<?php
/**
 * The template for displaying vendor dashboard header content
 *
 * This template can be overridden by copying it to yourtheme/dc-product-vendor/vebdor-dashboard/dashboard-header.php.
 *
 * HOWEVER, on occasion WC Marketplace will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @author  WC Marketplace
 * @package get_mvx_global_settings/Templates
 * @version 3.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
global $MVX;
$vendor = get_mvx_vendor(get_current_vendor_id());
if ($vendor) {
    $vendor_logo = $vendor->profile_image ? wp_get_attachment_url($vendor->profile_image) : get_avatar_url(get_current_vendor_id(), array('size' => 80));
} else {
    $vendor_logo = get_avatar_url(get_current_vendor_id(), array('size' => 80));
}
$site_logo = get_mvx_vendor_settings('mvx_new_dashboard_site_logo', 'seller_dashbaord') ? get_mvx_vendor_settings('mvx_new_dashboard_site_logo', 'seller_dashbaord') : '';
?>

<!-- Top bar -->
<div class="top-navbar white-bkg">
    <div class="navbar navbar-light p-0">
        <div class="navbar-leftside">
        <div class="topbar-left pull-left pos-rel">
            <div class="site-logo text-center pos-middle">
                <a href="<?php echo apply_filters('wcmp_vendor_dashboard_header_site_url', site_url(), $vendor); ?>">
                    <?php if ($site_logo) { ?>
                        <img src="<?php echo get_url_from_upload_field_value($site_logo); ?>"
                             alt="<?php echo bloginfo(); ?>">
                    <?php } else {
                        echo bloginfo();
                    } ?>
                </a>
            </div>
        </div>
         <div class="navbar-header mr-auto">
                <button class="navbar-toggler" type="button" data-toggle="collapse-side" data-target="#side-collapse" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
            </div>
        </div>
        <div class="navbar-rightside">
        <ul class="nav pull-right top-user-nav" style="top: 0; right: 0; position: absolute;">
            <li class="dropdown login-user">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <i class="mvx-font ico-user-icon"></i>
                    <span><i class="mvx-font ico-down-arrow-icon"></i></span>
                </a>
                <ul class="dropdown-menu dropdown-user dropdown-menu-right">
                    <li class="sidebar-logo text-center">
                        <div class="vendor-profile-pic-holder">
                            <img src="<?php echo esc_url($vendor_logo); ?>" alt="vendor logo">
                        </div>
                        <h4><?php
                            if ($vendor) {
                                echo adforest_return_echo($vendor->user_data->data->display_name);
                            } else {
                                $user = wp_get_current_user();
                                echo esc_html($user->data->user_email);
                            }
                            ?></h4>
                    </li>
                    <?php
                    $panel_nav = $MVX->vendor_dashboard->dashboard_header_right_panel_nav();
                   
              
                    if ($panel_nav) :
                        if (!$vendor) {
                            unset($panel_nav['storefront']);
                            unset($panel_nav['wp-admin']);
                            unset($panel_nav['profile']);
                        }
                        sksort($panel_nav, 'position', true);
                        foreach ($panel_nav as $key => $nav):
                            if (current_user_can($nav['capability']) || $nav['capability'] === true):
                                // print_r($nav);
                                 if($nav['label'] == "WordPress backend"){

                                    continue;
                                 }
                                ?>
                                <li class="<?php if (!empty($nav['class'])) echo esc_attr($nav['class']); ?>"><a
                                            href="<?php echo esc_url($nav['url']); ?>"
                                            target="<?php echo esc_url($nav['link_target']); ?>"><i
                                                class="<?php echo esc_url($nav['nav_icon']); ?>"></i>
                                        <span><?php echo esc_html($nav['label']); ?></span></a></li>
                            <?php
                            endif;
                        endforeach;
                    endif;
                    ?>

                    <?php do_action('wcmp_dashboard_header_right_vendor_dropdown'); ?>
                </ul>
                <!-- /.dropdown -->
            </li>
        </ul>
    </div>

        <?php
        if ($vendor)
            $header_nav = $MVX->vendor_dashboard->dashboard_header_nav();
        else
            $header_nav = false;

        if ($header_nav) :
            sksort($header_nav, 'position', true);
            ?>
            <ul class="nav navbar-top-links navbar-right pull-right btm-nav-fixed" style="padding-right: 80px;">
                <?php
                foreach ($header_nav as $key => $nav):
                    if (current_user_can($nav['capability']) || $nav['capability'] === true):
                        ?>
                        <li class="notification-link <?php if (!empty($nav['class'])) echo esc_attr($nav['class']); ?>">
                            <a href="<?php echo esc_url($nav['url']); ?>" target="<?php echo esc_attr($nav['link_target']); ?>"
                               title="<?php echo esc_attr($nav['label']); ?>">
                                <i class="<?php echo esc_attr($nav['nav_icon']); ?>"></i> <span
                                        class="hidden-sm hidden-xs"><?php echo esc_attr($nav['label']); ?></span>
                                <?php
                                if ($key == 'announcement') :
                                    $vendor_announcements = $vendor->get_announcements();
                                    if (isset($vendor_announcements['unread']) && count($vendor_announcements['unread']) > 0) {
                                        echo '<span class="notification-blink">' . count($vendor_announcements['unread']) . '</span>';
                                    }
                                endif;
                                ?>
                            </a>
                        </li>
                    <?php
                    endif;
                endforeach;
                ?>
            </ul>
        <?php endif; ?>
        <!-- /.navbar-top-links -->
    </div>
</div>