<?php
includeContainer('_library_lib.php', 1);
setSessionLang();
$socInfo = getSocInfo();

// Get available langs for the website
$website_langs = getAvailableLangs();
$available_langs = $website_langs['langs'];
if (getDolGlobalString('WS_'.strtoupper($website->ref).'_' . 'SUPPORTED_LANGS')) {
    $used_langs = explode(',', getDolGlobalString('WS_'.strtoupper($website->ref).'_' . 'SUPPORTED_LANGS'));
    foreach ($available_langs as $key => $value) {
        if (!in_array($key, $used_langs)) {
            unset($available_langs[$key]);
        }
    }
}

$langs_code_shortcode = $website_langs['langs_code_shortcode'];

//$weblangs->load("website", "languages");
//$langs->load("website", "languages");
?>
<div class="site-mobile-menu site-navbar-target">
  <div class="site-mobile-menu-header">
    <div class="site-mobile-menu-close mt-3">
      <span class="icon-close2 js-menu-toggle"></span>
    </div>
  </div>
  <div class="site-mobile-menu-body"></div>
</div>

<header class="site-navbar js-sticky-header js-sticky-header-blog site-navbar-target" role="banner">

  <div class="container">
    <div class="row align-items-center">
      
      <div class="col-6 col-xl-2">
        <?php
            if(getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'USE_TEXT_LOGO')) {
                $html_logo = $mysoc->name . '<span class="text-secondary-color">.</span>';
            } else {
                $path = getImageFileNameForSize($mysoc->logo_squarred ? $mysoc->logo_squarred : $mysoc->logo, '_small');
                $html_logo = '<img class="logo img-responsive-logo img-responsive" alt="" height="42" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&file='.urlencode('logos/'.$path).'">'; 
            }
          
            
        ?>
        <h1 class="mb-0 site-logo"><a href="/index"><?php print $html_logo; ?> </a></h1>
      </div>

      <div class="col-12 col-md-10 d-none d-xl-block">
        <nav class="site-navigation position-relative text-right" role="navigation">

        <ul class="site-menu main-menu js-clone-nav mr-auto d-none d-lg-block" style="float: right;">
            <li class="has-children">
                <a class="nav-link"><?php echo $weblangs->trans("presentation"); ?></a>
                <ul class="dropdown">
                    <li><a href="/index#section-overview" class="nav-link"><?php echo $weblangs->trans("missionVision"); ?></a></li>
                    <?php if (getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'ENABLE_MEMBER_LIST_PAGE')): ?>
                        <li><a href="members-list.php" class="nav-link"><?php echo $weblangs->trans("directory"); ?></a></li>
                    <?php endif; ?>
                </ul>
            </li>
            <li class="has-children">
                <a class="nav-link"><?php echo $weblangs->trans("newsEvents"); ?></a>
                <ul class="dropdown">
                    <li><a href="index#section-news" class="nav-link"><?php echo $weblangs->trans("news"); ?></a></li>
                    <?php if (isModEnabled('eventorganization') && getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'ENABLE_EVENTS_SECTION')): ?>
                        <li><a href="index#section-events" class="nav-link"><?php echo $weblangs->trans("actionsEvents"); ?></a></li>
                    <?php endif; ?>
                </ul>
            </li>
            <li class="has-children">
                <a class="nav-link"><?php echo $weblangs->trans("commitmentSupport"); ?></a>
                <ul class="dropdown">
                    <?php if (isModEnabled('member') && getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'ENABLE_MEMBER_REGISTRATION_PAGE')): ?>
                        <li><a href="<?php print $socInfo['subscription_link']; ?>" target="new" class="nav-link"><?php echo $weblangs->trans("becomeMember"); ?></a></li>
                    <?php endif; ?>
                    
                    <?php if (isModEnabled('don') && getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'ENABLE_DONATION_PAGE')): ?>
                        <li><a href="<?php print $socInfo['link_donation']; ?>" target="new" class="nav-link"><?php echo $weblangs->trans("makeDonation"); ?></a></li>
                        <li><a href="donation-list.php" class="nav-link"><?php echo $weblangs->trans("listOfPublicDonations"); ?></a></li>
                    <?php endif; ?>
                </ul>
            </li>
            <li>
                <a href="index#section-contact" class="nav-link"><?php echo $weblangs->trans("contact"); ?></a>
            </li>
            
            <?php if (isModEnabled('webportal') && getDolGlobalInt('WS_'.strtoupper($website->ref).'_' . 'ENABLE_MEMBER_AREA_PAGE')): ?>
              <?php
              if (getDolGlobalString('WEBPORTAL_ROOT_URL')) {
                $url = getDolGlobalString('WEBPORTAL_ROOT_URL');
              } else {
                if (isModEnabled('multicompany')) {
                  $entity_qr = '?entity=' . ((int) $conf->entity);
                } else {
                  $entity_qr = '';
                }

                $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($conf->file->dol_main_url_root));
                $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
                $url = $urlwithroot . '/public/webportal/index.php' . $entity_qr;
              }
              ?>
              <li>
                <a href="<?php echo $url; ?>" target="new" class="nav-link"><i class="fa-solid fa-user"></i> <?php echo $weblangs->trans("memberArea"); ?></a>
              </li>
            <?php endif; ?>
            
            <?php
                $socialIcons = [
                  'facebook' => 'fa-facebook-f',
                  'twitter' => 'fa-x-twitter',
                  'linkedin' => 'fa-linkedin-in',
                  'instagram' => 'fa-instagram',
                  'youtube' => 'fa-youtube',
                  'skype' => 'fa-skype',
                  'whatsapp' => 'fa-whatsapp',
                  'snapchat' => 'fa-snapchat-ghost',
                ];
    
                foreach ($socialIcons as $key => $icon) {
                  if (!empty($socInfo[$key])) {
                    echo '<li class="social"><a href="' . htmlspecialchars($socInfo[$key]) . '" target="_blank" class="nav-link"><i class="fa-brands ' . $icon . '"></i></a></li>';
                  }
                }
            ?>
            
            <li class="has-children">
                <a href="#language-section" class="nav-link"><?php print trim(explode('(', $langs->trans("Language_".$langs_code_shortcode[$_SESSION['lang']['shortcode']]))[0]); ?></a>
                <ul class="dropdown lang-menu">
                    <?php if (count($available_langs) > 1): ?>
                        <?php foreach ($available_langs as $key => $value) : ?>
                            <?php $value = trim(explode('(', $langs->trans("Language_".$langs_code_shortcode[$key]))[0]); ?>
                            <?php if ($key != $_SESSION['lang']['shortcode']): ?>
                        		<li>
                                  <form id="languageForm-<?php print $key; ?>" method="post" action="#">
                                    <input type="hidden" name="l" value="<?php print $key; ?>">
                                    <a href="#" class="nav-link" title="<?php print $langs->trans("Language_".$langs_code_shortcode[$key]); ?>" onclick="
                                           const form = document.getElementById('languageForm-<?php print $key; ?>');
                                           const parser = document.createElement('a');
                                           parser.href = form.action || window.location.href;
                                           const params = new URLSearchParams(parser.search);
                                           params.delete('l');
                                           parser.search = params.toString();
                                           form.action = parser.href;
                                           form.submit();
                                           return false;
                                       ">    
                                      <?php print $value ; ?>
                                    </a>
                                  </form>
                                </li>
                        	<?php endif ?>
                        <?php endforeach ?>
                    <?php endif ?>
                </ul>
            </li>
            
        </ul>
        </nav>
      </div>


      <div class="col-6 d-inline-block d-xl-none ml-md-0 py-3" style="position: relative; top: 3px;">
        <a href="#" class="site-menu-toggle js-menu-toggle float-right">
            <i class="fas fa-bars"></i>
        </a>
      </div>

    </div>
  </div>
  
</header>