<?php
if (in_array('welcome', $top_panel_top_components) && trim(seohub_get_custom_option('welcome_text'))!='') {
    ?>
        <div class="top_panel_top_contact_area">
            <?php
            echo esc_attr(seohub_get_custom_option('welcome_text'));
            ?>
        </div>
<?php
}

if (in_array('contact_info', $top_panel_top_components) && (($contact_info=trim(seohub_get_custom_option('contact_info')))!='' || ($contact_info=trim(seohub_get_custom_option('contact_phone')))!='' || ($contact_info=trim(seohub_get_custom_option('contact_email')))!='')) {
    ?>
    <div class="top_panel_top_contact_area">
        <?php echo esc_attr(seohub_get_custom_option('contact_info'));;
        ?>
        <?php if ($contact_info=trim(seohub_get_custom_option('contact_phone')) !='') { ?>
            <span class="top_phone icon-phone-1"><?php
                echo esc_attr(seohub_get_custom_option('contact_phone'));
                ?>
            </span>
        <?php
        }
        if ($contact_info=trim(seohub_get_custom_option('contact_email')) !='') {?>
            <span class="top_email"><a href="<?php esc_url(seohub_get_custom_option('contact_email'));?>">
                <?php
                echo esc_attr(seohub_get_custom_option('contact_email'));
                ?>
            </a>
        </span>
        <?php } ?>
    </div>
	<?php
}
?>

<?php
if (in_array('open_hours', $top_panel_top_components) && ($open_hours=trim(seohub_get_custom_option('contact_open_hours')))!='') {
	?>
	<div class="top_panel_top_open_hours icon-clock"><?php echo force_balance_tags($open_hours); ?></div>
	<?php
}
?>

<div class="top_panel_top_user_area">

	<?php
	if (in_array('socials', $top_panel_top_components) && seohub_get_custom_option('show_socials')=='yes') {
		?>
		<div class="top_panel_top_socials">
			<?php echo trim(seohub_sc_socials(array('size'=>'tiny'))); ?>
		</div>
		<?php
	}


	global $SEOHUB_GLOBALS;
	if (empty($SEOHUB_GLOBALS['menu_user'])) 
		$SEOHUB_GLOBALS['menu_user'] = seohub_get_nav_menu('menu_user');
	if (empty($SEOHUB_GLOBALS['menu_user'])) {
		?>
		<ul id="menu_user" class="menu_user_nav">
		<?php
	} else {
		$menu = seohub_substr($SEOHUB_GLOBALS['menu_user'], 0, seohub_strlen($SEOHUB_GLOBALS['menu_user'])-5);
		$pos = seohub_strpos($menu, '<ul');
		if ($pos!==false) $menu = seohub_substr($menu, 0, $pos+3) . ' class="menu_user_nav"' . seohub_substr($menu, $pos+3);
		echo str_replace('class=""', '', $menu);
	}
	

	if (in_array('currency', $top_panel_top_components) && function_exists('seohub_is_woocommerce_page') && seohub_is_woocommerce_page() && seohub_get_custom_option('show_currency')=='yes') {
		?>
		<li class="menu_user_currency">
			<a href="#">$</a>
			<ul>
				<li><a href="#"><b>&#36;</b> <?php esc_html_e('Dollar', 'seohub'); ?></a></li>
				<li><a href="#"><b>&euro;</b> <?php esc_html_e('Euro', 'seohub'); ?></a></li>
				<li><a href="#"><b>&pound;</b> <?php esc_html_e('Pounds', 'seohub'); ?></a></li>
			</ul>
		</li>
		<?php
	}

	if (in_array('language', $top_panel_top_components) && seohub_get_custom_option('show_languages')=='yes' && function_exists('icl_get_languages')) {
		$languages = icl_get_languages('skip_missing=1');
		if (!empty($languages) && is_array($languages)) {
			$lang_list = '';
			$lang_active = '';
			foreach ($languages as $lang) {
				$lang_title = esc_attr($lang['translated_name']);	//esc_attr($lang['native_name']);
				if ($lang['active']) {
					$lang_active = $lang_title;
				}
				$lang_list .= "\n"
					.'<li><a rel="alternate" hreflang="' . esc_attr($lang['language_code']) . '" href="' . esc_url(apply_filters('WPML_filter_link', $lang['url'], $lang)) . '">'
						.'<img src="' . esc_url($lang['country_flag_url']) . '" alt="' . esc_attr($lang_title) . '" title="' . esc_attr($lang_title) . '" />'
						. ($lang_title)
					.'</a></li>';
			}
			?>
			<li class="menu_user_language">
				<a href="#"><span><?php echo trim($lang_active); ?></span></a>
				<ul><?php echo trim($lang_list); ?></ul>
			</li>
			<?php
		}
	}

	if (in_array('bookmarks', $top_panel_top_components) && seohub_get_custom_option('show_bookmarks')=='yes') {
		// Load core messages
		seohub_enqueue_messages();
		?>
		<li class="menu_user_bookmarks"><a href="#" class="bookmarks_show icon-star" title="<?php esc_attr_e('Show bookmarks', 'seohub'); ?>"><?php esc_html_e('Bookmarks', 'seohub'); ?></a>
		<?php 
			$list = seohub_get_value_gpc('seohub_bookmarks', '');
			if (!empty($list)) $list = json_decode($list, true);
			?>
			<ul class="bookmarks_list">
				<li><a href="#" class="bookmarks_add icon-star-empty" title="<?php esc_attr_e('Add the current page into bookmarks', 'seohub'); ?>"><?php esc_html_e('Add bookmark', 'seohub'); ?></a></li>
				<?php 
				if (!empty($list) && is_array($list)) {
					foreach ($list as $bm) {
						echo '<li><a href="'.esc_url($bm['url']).'" class="bookmarks_item">'.($bm['title']).'<span class="bookmarks_delete icon-cancel" title="'.esc_attr__('Delete this bookmark', 'seohub').'"></span></a></li>';
					}
				}
				?>
			</ul>
		</li>
		<?php 
	}

	if (in_array('login', $top_panel_top_components) && seohub_get_custom_option('show_login')=='yes') {
		if ( !is_user_logged_in() ) {
			// Load core messages
			seohub_enqueue_messages();
			// Load Popup engine
			seohub_enqueue_popup();
			// Anyone can register ?
			if ( (int) get_option('users_can_register') > 0) {
			?>
			<li class="menu_user_register"><a href="#popup_registration" class="popup_link popup_register_link"><?php esc_html_e('Register for FREE!', 'seohub'); ?></a><?php
				if (seohub_get_theme_option('show_login')=='yes') {
					require_once seohub_get_file_dir('templates/headers/_parts/register.php');
				}?></li>
			<?php }


            if ( seohub_get_custom_option('show_faq')=='yes') {
                ?>
                <li class="menu_user_faq"><a href="<?php esc_url(seohub_get_custom_option('faq_link'));?>" class="faq_link"><?php esc_html_e('Support & FAQ', 'seohub'); ?></a></li>
            <?php }

            ?>
			<li class="menu_user_login"><a href="#popup_login" class="popup_link popup_login_link"><?php esc_html_e('Login', 'seohub'); ?></a><?php
				if (seohub_get_theme_option('show_login')=='yes') {
					require_once seohub_get_file_dir('templates/headers/_parts/login.php');
				}?></li>
			<?php 
		} else {
			$current_user = wp_get_current_user();
			?>
			<li class="menu_user_controls">
				<a href="#"><?php
					$user_avatar = '';
					if ($current_user->user_email) $user_avatar = get_avatar($current_user->user_email, 16*min(2, max(1, seohub_get_theme_option("retina_ready"))));
					if ($user_avatar) {
						?><span class="user_avatar"><?php echo trim($user_avatar); ?></span><?php
					}?><span class="user_name"><?php echo trim($current_user->display_name); ?></span></a>
				<ul>
					<?php if (current_user_can('publish_posts')) { ?>
					<li><a href="<?php echo esc_url( home_url( '/' ) ); ?>/wp-admin/post-new.php?post_type=post" class="icon icon-doc"><?php esc_html_e('New post', 'seohub'); ?></a></li>
					<?php } ?>
					<li><a href="<?php echo esc_url(get_edit_user_link()); ?>" class="icon icon-cog"><?php esc_html_e('Settings', 'seohub'); ?></a></li>
				</ul>
			</li>
			<li class="menu_user_logout"><a href="<?php echo wp_logout_url(esc_url( home_url( '/' ) )); ?>" class="icon icon-logout"><?php esc_html_e('Logout', 'seohub'); ?></a></li>
			<?php 
		}
	}

	if (in_array('cart', $top_panel_top_components) && function_exists('seohub_exists_woocommerce') && seohub_exists_woocommerce() && (seohub_is_woocommerce_page() && seohub_get_custom_option('show_cart')=='shop' || seohub_get_custom_option('show_cart')=='always') && !(is_checkout() || is_cart() || defined('WOOCOMMERCE_CHECKOUT') || defined('WOOCOMMERCE_CART'))) { 
		?>
		<li class="menu_user_cart">
			<?php require_once seohub_get_file_dir('templates/headers/_parts/contact-info-cart.php'); ?>
		</li>
		<?php
	}
	?>

	</ul>

</div>