{%- set options = (options is defined ? options : []) %}
{%- set values = (values is defined ? values : []) -%}

{%- set showAllOption = showAllOption ?? false %}
{%- if showAllOption %}
    {%- set allLabel = allLabel ?? "All"|t('app') %}
    {%- set allValue = allValue ?? '*' %}
    {%- set allChecked = (values == allValue) %}
{%- endif %}

<div class="checkbox-select{% if class is defined %} {{ class }}{% endif %}"
        {%- if block('attr') is defined %} {{ block('attr') }}{% endif %}>
    {%- if showAllOption %}
        <div>
            {% include "_includes/forms/checkbox" with {
                id:        (id is defined ? id : null),
                class:     'all',
                label:     '<b>' ~ allLabel ~ '</b>',
                name:      (name is defined ? name : null),
                value:     allValue,
                checked:   allChecked,
                autofocus: (autofocus is defined and autofocus and not craft.app.request.isMobileBrowser(true))
            } only %}
        </div>
    {%- endif %}
    {%- for key, option in options %}
        {%- if option is not iterable %}
            {%- set option = {label: option, value: key} %}
        {%- endif %}
        {% if not showAllOption or option.value is not defined or option.value != allValue %}
            <div>
                {% include "_includes/forms/checkbox" with {
                    name:     (name is defined ? name~'[]' : null),
                    checked:  ((showAllOption and allChecked) or (option.value is defined and option.value in values)),
                    disabled: (showAllOption and allChecked)
                }|merge(option) only %}
            </div>
        {% endif %}
    {% endfor %}
</div>
