{% from 'theme/comps.buttons.html.j2' import link %}


{% macro separator() %}
    <li><hr class="dropdown-divider"></li>
{% endmacro %}

{% macro dropdown(text=None,
                  design='light',
                  size=None,
                  right=False,
                  items=[]) %}

  {% set id_ = range(1,50) | random %}

  <a class="nav-link dropdown-toggle" href="#" id="{{id_}}" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    {{ text or _('Dropdown')}}
  </a>
  <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="{{id_}}">
    {% for link_text, link_url, link_separated, link_icon in items %}
      {{ separator() if link_separated and (loop.index0 != 0) }}
      {{ link(text=link_text, 
              url=url_for(link_url), 
              icon=link_icon, 
              extra_classes=['dropdown-item'])
          if current_user.has_permission(link_url) 
      }}

      {{ separator() if link_separated and (loop.index0 == 0) }}
    {% endfor %}
  </ul>
{% endmacro %}
