<div id="mainMenu" class="">
    {% set configuration = app['conf'].get(['registry', 'custom-links']) %}
    <div class="PNB menu-bar" style="right:auto;overflow:hidden;">
      <ol>
        <li>
            <span class="title">
              <img src="/assets/common/images/logo.png" alt="" id="mainLogo">
            </span>
        </li>
        {% if module is defined and module != "lightbox" and app.getAuthenticator().isAuthenticated() %}
          <li>
              <a target="_blank" href="{{ path('prod') }}">
                <span class="{% if module is defined and module == "prod" %}selected{% endif %}">
                  {{ 'admin::monitor: production' | trans }}
                </span>
              </a>
          </li>

          {% if app['browser'].isNewGeneration and app['conf'].get(['registry', 'modules', 'thesaurus']) == true and app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('thesaurus') %}
          <li>
            <a target="_blank" href="{{ path('thesaurus') }}">
              <span class="{% if module is defined and module == "thesaurus" %}selected{% endif %}">
              {{ 'admin::monitor: module thesaurus' | trans }}
              </span>
            </a>
          </li>
          {% endif %}


          {# MODULE #}
          {% if app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('admin') %}
          <li>
            <a target="_blank" href="{{ path('admin') }}">
              <span class="{% if module is defined and module == "admin" %}selected{% endif %}">
                {{ 'admin::monitor: module admin' | trans }}
              </span>
            </a>
          </li>
          {% endif %}

          {# MODULE #}
          {% if app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('report') %}
          <li>
            <a target="_blank" href="{{ path('report_dashboard') }}">
              <span class="{% if module is defined and module == "report" %}selected{% endif %}">
                {{ 'admin::monitor: module report' | trans }}
              </span>
            </a>
          </li>
          {% endif %}

          {# MODULE #}
          <li>
            <a id="validation_link" target="_blank" href="{{ path('lightbox') }}">
              <span>
              {{ 'admin::monitor: module validation' | trans }}
              </span>
            </a>
          </li>

          {# MODULE #}
          {% if module is defined and module == "prod" %}
              {% if app.getAclForUser(app.getAuthenticatedUser()).has_access_to_module('upload') %}
            <li>
                {% set link = path('upload_html5_form') %}

                {% if not app['browser'].supportFileAPI() %}
                    {% set link = path('upload_flash_form') %}
                {% endif %}

                <a  href="{{ link }}" class="dialog full-dialog uploader-open-action" title="{{ 'Upload' | trans }}">
                <span>
                    {{ 'admin::monitor: module upload' | trans }}
                </span>
                </a>
            </li>
            {% endif %}
          {% endif %}

          {# MODULE #}
          {% if module == "prod" %}
          <li>
            <a href="#" onclick="getHome('PUBLI');" >
              <span>
                {{ 'Publications' | trans }}
              </span>
            </a>
          </li>
          {% endif %}

          {% if module is defined and module == "prod" and app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::ORDER_MASTER')) %}
          <li>
            <a href="{{ path('prod_orders') }}" class="dialog full-dialog" title="{{ 'Orders manager' | trans }}">
              <span>
                {{ 'Commandes' | trans }}
              </span>
            </a>
          </li>
          {% endif %}

        {% endif %}
      </ol>

    </div>
    <div class="PNB right" style="left:auto;overflow:hidden;">
      <ol>

    {% if app.getAuthenticator().isAuthenticated()  and module == "prod" %}
        <li id="notification_trigger">
          <a href="#" style="font-weight:bold;text-decoration:none;">
            <span>
              <button class="counter btn btn-danger" style="visibility:{% if app['events-manager'].get_unread_notifications_number > 0 %}visible{% else %}hidden{% endif %};">
                  {% if app['events-manager'].get_unread_notifications_number > 0 %}
                    {{app['events-manager'].get_unread_notifications_number}}
                  {% endif %}
              </button>
              {{ 'Notifications' | trans }}
            </span>
          </a>
        </li>
    {% endif %}
        <li class="user">
          {% if app.getAuthenticator().isAuthenticated() %}
            {% if app.getAuthenticatedUser().isGuest %}
              <span>
                {{ 'Guest' | trans }}
              </span>
            {% else %}
              <a target="_blank" href="{{ path('account') }}" title="{{ 'login:: Mon compte' | trans }}">
                <span>
                  {{app.getAuthenticatedUser().getLogin()}}
                </span>
              </a>
            {% endif %}
          {% endif %}
        </li>
        <li>
          <a target="_blank" href="https://docs.phraseanet.com/4.0/">
            <span>
              {{ 'phraseanet:: aide' | trans }}
                <span style="display:inline-block;cursor:pointer;padding:0;border:none;padding-right:4px;padding-left:4px;"
                      id="help-trigger"> <i class="icon-caret-down"></i></span>
            </span>
          </a>
          <table cellspacing="0" cellpadding="0" style="display:none;" class="contextMenu helpcontextmenu">
              <tbody>
                  <tr>
                      <td>
                          <div class="context-menu context-menu-theme-vista">
                          {% if module is defined and module == "prod" %}
                              <div title="" class="context-menu-item menu3-custom-item">
                                  <div style="" class="context-menu-item-inner shortcuts-trigger">
                                          {{ 'phraseanet:: raccourcis clavier' | trans }}
                                  </div>
                              </div>
                          {% endif %}
                              <div title="" class="context-menu-item menu3-custom-item">
                                  <div style="" class="context-menu-item-inner infoDialog" infos="<div><span style='font-size:18px;'>PHRASEANET</span> {{ app['phraseanet.version'].getName() }} (V{{ app['phraseanet.version'].getNumber() }})</div><div></div><br/><div><a href='http://www.gnu.org/licenses/gpl.html' target='_blank'><img src='http://www.gnu.org/graphics/gplv3-88x31.png' style='vertical-align:middle;'/><span>License GNU GPL v3</span></a></div><br/><div><a href='http://www.phraseanet.com/' target='_blank'>  &copy; Copyright Alchemy 2005-{{ "now"|date("Y") }}</a><p style='margin-top: 10px' ><a href='../../gitlog.txt' target='_blank'>gitlog</a></p></div>">{{ 'phraseanet:: a propos' | trans }}</div>
                              </div>
                          </div>
                      </td>
                  </tr>
              </tbody>
          </table>
        </li>
        <li>
        {% if app.getAuthenticator().isAuthenticated() %}
          <a href="{{ path('logout', { 'redirect' : '..' ~ app['request'].getPathInfo() }) }}" target="_self">
            <span>
              {{ 'phraseanet:: deconnection' | trans }}
            </span>
          </a>
        {% endif %}
        </li>
      </ol>
    </div>
</div>

 {% if app.getAuthenticator().isAuthenticated()  and module == "prod" %}
    <div style="display:none;z-index:30000;" id="notification_box">
        {% set notifications = app['events-manager'].get_notifications %}
        {% include 'prod/notifications.html.twig' %}
    </div>
{% endif %}

<script type="text/javascript">
    $(document).ready(function () {
        // var key = 'help';
        var configurationSettingLinks = {{ configuration|json_encode|raw }};
        //seperate array based on location of link
        var seperatedLinksByLocation = _.groupBy(configurationSettingLinks, "linkLocation");

        for (key in seperatedLinksByLocation) {
            if (key === 'navigation-bar') {
                var sortedCustomLinks = _.sortBy(seperatedLinksByLocation[key], 'linkOrder');

                _.each(sortedCustomLinks, function (linksData) {
                    if (linksData.linkLanguage == 'all' || linksData.linkLanguage === '{{ app['locale'] }}') {
                        var styleAttr = "";
                        styleAttr += linksData.linkColor ? "color: " + linksData.linkColor + ";" : "";
                        styleAttr += linksData.linkBold == true ? "font-weight: bold;" : "";

                        var spanElement = $('<span />').attr('style', styleAttr).html(linksData.linkName);
                        var links = '<li><a target="_blank" href="' + linksData.linkUrl + '">' +
                            spanElement.prop("outerHTML") + '</a></li>';
                        $('#mainMenu .menu-bar ol').append(links);
                    }
                });
            } else if (key === 'help-menu') {
                var sortedCustomLinks = _.sortBy(seperatedLinksByLocation[key], 'linkOrder');

                _.each(sortedCustomLinks, function (linksData) {
                    if (linksData.linkLanguage == 'all' || linksData.linkLanguage === '{{ app['locale'] }}') {
                        var styleAttr = "";
                        styleAttr += linksData.linkColor ? "color: " + linksData.linkColor + ";" : "";
                        styleAttr += linksData.linkBold == true ? "font-weight: bold;" : "";

                        var spanElement = $('<span />').attr('style', styleAttr).html(linksData.linkName);
                        var links = '<div title="" class="context-menu-item menu3-custom-item">' +
                            '<div style="" class="context-menu-item-inner">' +
                            '<a target="_blank" href="' + linksData.linkUrl + '">' +
                            spanElement.prop("outerHTML") + '</a></div></div>';
                        $('.helpcontextmenu .context-menu-theme-vista').append(links);
                    }
                });
            }
        }


    });
</script>
