{% macro onsCheckbox(params) %}
    {% from "components/label/_macro.njk" import onsLabel %}

    <span
        class="ons-checkbox{{ ' ons-checkbox--no-label' if params.hideLabel == true }}{{ ' ' + params.classes if params.classes else '' }}"
    >
        <input
            type="checkbox"
            id="{{ params.id }}"
            class="ons-checkbox__input ons-js-checkbox{{ ' ' + params.inputClasses if params.inputClasses else '' }}"
            value="{{ params.value }}"
            {% if params.disabled == true %}disabled aria-disabled="true"{% endif %}
            {% if params.name %}{{ ' ' }}name="{{ params.name }}"{% endif %}
            {% if params.checked %}{{ ' ' }}checked{% endif %}
            {% if params.other and not params.other.open %}{{ ' ' }}aria-controls="{{ params.id }}-other-wrap" aria-haspopup="true"{% endif %}
            {% if params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ ' ' }}{{ attribute }}{% if value %}="{{ value }}"{% endif %}{% endfor %}{% endif %}
            {% if params.deselectMessage %}{{ ' ' }}data-deselect-message="{{ params.deselectMessage }}"{% endif %}
        />

        {{
            onsLabel({
                "id": params.id + "-label",
                "for": params.id,
                "inputType": "checkbox",
                "text": params.label.text,
                "classes": "ons-checkbox__label" + (' ' + params.label.classes if params.label.classes else ''),
                "description": params.label.description
            })
        }}

        {% if params.other %}
            {% set otherType = params.other.otherType | default('input') %}
            <span class="ons-checkbox__other{{ ' ons-checkbox__other--open' if params.other.open }}" id="{{ params.id }}-other-wrap">
                {% if otherType == "input" %}
                    {% from "components/input/_macro.njk" import onsInput %}
                    {{
                        onsInput({
                            "id": params.other.id,
                            "name": params.other.name,
                            "type": params.other.type,
                            "classes": params.other.classes | default(''),
                            "width": params.other.width | default('auto'),
                            "attributes": params.other.attributes,
                            "label": {
                                "id": params.other.id + "-label",
                                "text": params.other.label.text,
                                "classes": 'ons-u-fw-n'
                            },
                            "dontWrap": true,
                            "value": params.other.value
                        })
                    }}
                {% elif otherType == "select" %}
                    {% from "components/select/_macro.njk" import onsSelect %}
                    {{
                        onsSelect({
                            "id": params.other.id,
                            "name": params.other.name,
                            "options": params.other.options,
                            "classes": params.other.classes,
                            "label": {
                                "id": params.other.id + "-label",
                                "text": params.other.label.text,
                                "classes": 'ons-u-fw-n'
                            },
                            "dontWrap": true,
                            "value": params.other.value
                        })
                    }}
                {% elif otherType == "checkboxes" %}
                    {% from "components/checkboxes/_macro.njk" import onsCheckboxes %}
                    {{
                        onsCheckboxes({
                            "id": params.other.id,
                            "name": params.other.name,
                            "checked": params.other.checked,
                            "borderlessParent": true if params.borderless == true else false,
                            "borderless": true,
                            "legend": params.other.legend,
                            "legendClasses": params.other.legendClasses,
                            "attributes": params.other.attributes,
                            "classes": "ons-js-other-fieldset-checkbox",
                            "checkboxes": params.other.checkboxes,
                            "autoSelect": params.other.autoSelect
                        })
                    }}
                {% elif otherType == "radios" %}
                    {% from "components/radios/_macro.njk" import onsRadios %}
                    {{
                        onsRadios({
                            "id": params.other.id,
                            "name": params.other.name,
                            "borderless": true,
                            "legend": params.other.legend,
                            "legendClasses": params.other.legendClasses,
                            "attributes": params.other.attributes,
                            "classes": "ons-js-other-fieldset-checkbox",
                            "radios": params.other.radios
                        })
                    }}
                {% elif otherType == "textarea" %}
                    {% from "components/textarea/_macro.njk" import onsTextarea %}
                    {{
                        onsTextarea({
                            "id": params.other.id,
                            "name": params.other.name,
                            "value": params.other.value,
                            "label": {
                                "id": params.other.id + "-label",
                                "text": params.other.label.text,
                                "description": params.other.label.description,
                                "classes": 'ons-u-fw-n'
                            },
                            "charCheckLimit": {
                                "limit": params.other.charCheckLimit.limit,
                                "charCountSingular": params.other.charCheckLimit.charCountSingular,
                                "charCountPlural": params.other.charCheckLimit.charCountPlural
                            }
                        })
                    }}
                {% endif %}
            </span>
        {% endif %}
    </span>
{% endmacro %}
