{% import 'admin-bar/_plugin-widgets-macros' as pluginWidgets %}

{% set widgetElement = widgetConfig['entrySiteLinks']|length ? 'admin-bar-button' : 'admin-bar-text' %}

{% if widgetConfig['currentSite'] %}
  {% set widgetContent %}
    {{ svg('@appicons/' ~ widgetConfig['earthIcon'] ~ '.svg')|attr({ class: 'icon', slot: "before-label" }) }}
    {{ pluginWidgets.widgetBadgeAndLabel(null, widgets[pluginHandle].name, displayWidgetLabels) }}

    {% if widgetConfig['entrySiteLinks']|length %}
      <div slot="popover">
        {% for link in widgetConfig['entrySiteLinks'] %}
          <admin-bar-button button-href="{{ link.url }}">
            <span style="--admin-bar-icon-width: 1rem">{{ svg('@appicons/' ~ widgetConfig['earthIcon'] ~ '.svg')|attr({ class: 'icon' }) }}</span>
            {{ link.title }}
          </admin-bar-button>
        {% endfor %}
      </div>
    {% endif %}
  {% endset %}
  {{ tag(widgetElement, {
    class: 'admin-bar-widget',
    'badge-content': widgetConfig['currentSite'].name,
    html: widgetContent,
    style: { '--admin-bar-icon-width': '1.5rem' }
  }) }}
{% endif %}