<?php
$logo_img = get_template_directory_uri() . '/dist/images/label_ledial_big.png';
$icon_user = get_template_directory_uri() . '/dist/images/icon-user.png';
$blogname = get_bloginfo('name');
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
// $portagioie = get_field('favs_page', 'option');
$negozi = get_field('stores_page', 'option');
$current_user = wp_get_current_user();
?>

<nav id="main-header">
  <div class="header-area left">
    <?php if (is_user_logged_in()) { ?>
      <span style="padding-right: 15px;"><?= __('Buongiorno ', 'blanka'); ?> <strong> <?= $current_user->user_firstname ?> </strong></span>
    <?php } ?>
    <!-- <a class="with-icon" href="<?php if ($negozi) {
                                      echo $negozi['url'];
                                    } ?>">
      <img src="<?php echo get_template_directory_uri(); ?>/dist/images/icon_negozi.png" />
    </a>
    <a class="custom-underline" href="<?php // if ($negozi) {
                                      // echo $negozi['url'];
                                      // } 
                                      ?>">
      <?php // if ($negozi) {
      // echo $negozi['title'];
      // } 
      ?>
    </a> -->
    <?php get_search_form(); ?>
  </div>
  <a class="logo-header" href="<?php echo esc_url(home_url('/')); ?>">
    <?php echo "<img width='110' height='99' src='{$logo_img}' alt='{$blogname}' longdesc='{$blogname}' title ='{$blogname}'/>"; ?>
  </a>

  <?php
  if (!get_field('disallow_shop', 'option')  /*|| current_user_can('edit_pages')*/) : ?>
    <div class="header-area right">
      <?php if (function_exists('custom_lang_selector')) echo custom_lang_selector(); ?>
      <div class="user-access">
        <?php if (is_user_logged_in()) { ?>
          <span class="user-img">
            <a class="custom-underline" href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>" title="<?php _e('My Account', 'woothemes'); ?>">
              <img width="30" height="30" src="<?= $icon_user ?>" />
            </a>
          </span>
          <span class="header-greetings" style="padding-right: 15px;"><?= __('Buongiorno ', 'blanka'); ?> <strong> <?= $current_user->user_firstname ?> </strong></span>
        <?php } else { ?>
          <span class="user-img">
            <a class="custom-underline login-panel-toggler" href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>" title="<?php _e('Login / Register', 'woothemes'); ?>">
              <img width="30" height="30" src="<?= $icon_user ?>" />
            </a>
          </span>
        <?php } ?>
      </div>
      <div class="register-block">
        <?php if (is_user_logged_in()) { ?>
          <a class="custom-underline" href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>" title="<?php _e('My Account', 'woothemes'); ?>"><?php _e('Account', 'woothemes'); ?></a>
          <span class="divider"> | </span>
          <a class="custom-underline" href="<?= wp_logout_url(get_permalink(wc_get_page_id('myaccount'))) ?>">Log Out</a></li>
        <?php } else { ?>
          <a class="custom-underline login-panel-toggler" href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>" title="<?php _e('Login / Register', 'woothemes'); ?>"><?php _e('Accedi o Registrati', 'woothemes'); ?></a>
          <div class="login-panel" id="customer_login">
            <form method="post" class="woocommerce-form woocommerce-form-register register">
              <?php do_action('woocommerce_login_form_start'); ?>
              <!-- MAIL -->
              <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="username"><?php esc_html_e('Username or email address', 'woocommerce'); ?>&nbsp;<span class="required">*</span></label>
                <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="<?php echo (!empty($_POST['username'])) ? esc_attr(wp_unslash($_POST['username'])) : ''; ?>" /><?php // @codingStandardsIgnoreLine 
                                                                                                                                                                                                                                                            ?>
              </p>
              <!-- PWD -->
              <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="reg_password"><?php esc_html_e('Password', 'woocommerce'); ?>&nbsp;<span class="required">*</span></label>
                <input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" autocomplete="new-password" />
              </p>
              <?php wp_nonce_field('woocommerce-login', 'woocommerce-login-nonce'); ?>
              <button type="submit" class="btn btn-primary boxed" name="login" value="<?php esc_attr_e('Log in', 'woocommerce'); ?>"><span><?php esc_html_e('Log in', 'woocommerce'); ?></span></button>
              <!-- LOST PWD -->
              <p class="woocommerce-LostPassword lost_password">
                <small><?php _e('Did you forget the password?', 'blanka'); ?></small>
                <a href="<?php echo esc_url(wp_lostpassword_url()); ?>"><?php esc_html_e('Reset your password', 'woocommerce'); ?></a>
              </p>
              <?php do_action('woocommerce_login_form'); ?>
              <!-- REGISTER -->
              <a href="<?php echo esc_url(home_url('/my-account')); ?>" class="btn btn-primary boxed"><span><?php _e('Register', 'blanka'); ?></span></a>
            </form>
          </div>
        <?php } ?>
      </div>
      <div class="clearfix"></div>
      <?php if ($portagioie) : ?>
        <a class="with-icon" href="<?php echo $portagioie['url']; ?>">
          <?php get_template_part('inc/svg/_box'); ?>
          <!-- <img src="<?php //echo get_template_directory_uri();
                          ?>/dist/images/icon_portagioie_2.png" /> -->
          <label><?php echo $portagioie['title']; ?></label>
        </a>
      <?php endif; ?>
      <a class="with-icon" href="<?php echo $cart_url; ?>">
        <?php get_template_part('inc/svg/_cart'); ?>
        <!-- <img src="<?php //echo get_template_directory_uri();
                        ?>/dist/images/icon_cart.png" /> -->
        <?php echo '<span class="count">' . WC()->cart->get_cart_contents_count() . '</span>'; ?>
      </a>
    </div>
  <?php endif; ?>

  <div class="container">
    <div class="row">
      <?php
      $args = array(
        'theme_location' => 'main-menu',
        'menu_class' => 'dropmenu',
        'fallback_cb' => '',
        'menu_id' => 'main-menu',
      );
      wp_nav_menu($args);
      ?>
      <button class="hamburger hamburger--collapse collapsed menu-toggler" type="button">
        <span class="hamburger-box">
          <span class="hamburger-inner"></span>
        </span>
      </button>
    </div><!-- /.row -->
  </div><!-- /.container_class -->
  <?php get_template_part('inc/header/_shop-panel'); ?>
</nav>