{% if singleType %}
  {% import '_includes/forms.twig' as forms %}
  {{ forms.button({
    label: createButtonLabel,
    class: ['dashed', 'add', 'icon', 'wrap'],
    spinner: true,
    attributes: {
      data: {
        type: entryTypes|first.handle,
      },
      aria: {
        describedby: labelId,
      },
    },
  }) }}
{% else %}
  {% set groupedEntryTypes = collect(entryTypes).groupBy(et => (et.group ?? 'General'|t('app'))) %}
  {% if groupedEntryTypes.count() > 1 %}
    {% set btngroupDescriptionId = "btngroup-desc-#{random()}" %}
    {% set items = groupedEntryTypes.map((entryTypes, group) => [
      {hr: true, padded: false},
      {
        heading: group|t('site'),
        padded: false,
        items: entryTypes|map(entryType => {
        icon: entryType.icon,
        color: entryType.color,
        label: entryType.name|t('site'),
        value: entryType.handle,
        attributes: {
          data: {
            type: entryType.handle,
          },
        },
      }),
      },
    ]).flatten(1).all() %}
    <div class="expandable-button--collapsed">
      {{ disclosureMenu(items, {
        buttonLabel: createButtonLabel,
        buttonSpinner: true,
        buttonAttributes: {
          class: ['dashed', 'add', 'icon'],
        },
        withSearchInput: entryTypes|length > 5,
      }) }}
    </div>
    <div class="expandable-button--expanded btngroup hidden">
      {{ tag('span', {
        'id': btngroupDescriptionId,
        'hidden': true,
        'html': 'Create {type}'|t('app', {
          type: 'entry'|t('app'),
        })
      }) }}
      {% for group, entryTypes in groupedEntryTypes %}
        {% set items = entryTypes|map(entryType => {
          icon: entryType.icon,
          color: entryType.color,
          label: entryType.name|t('site'),
          value: entryType.handle,
          attributes: {
            data: {
              type: entryType.handle,
            },
          },
        }) %}
        {{ disclosureMenu(items, {
          buttonLabel: group,
          buttonSpinner: true,
          buttonAttributes: {
            class: {
              dashed: true,
              add: loop.first,
              icon: loop.first,
              'btngroup-btn-first': loop.first,
            }|filter|keys,
            aria: {
              describedby: btngroupDescriptionId,
            },
          },
        }) }}
      {% endfor %}
    </div>
  {% else %}
    {% set items = groupedEntryTypes.map((entryTypes) => entryTypes|map(entryType => {
      icon: entryType.icon,
      color: entryType.color,
      label: entryType.name|t('site'),
      value: entryType.handle,
      attributes: {
        data: {
          type: entryType.handle,
        },
      },
    })).flatten(1).all() %}
    {{ disclosureMenu(items, {
      buttonLabel: createButtonLabel,
      buttonSpinner: true,
      buttonAttributes: {
        class: ['dashed', 'add', 'icon'],
      },
      withSearchInput: entryTypes|length > 5,
    }) }}
  {% endif %}
{% endif %}
