<:define tag="bs-check-group:div"
class="mb-3"
role="group"
// parameters
::legend=${null}
::type=${'radio'}
::options=${[]}
::value=${type === 'radio' ? null : []}
::inline=${false}
::disabled=${false}
// private
:_name=${`bs-check-group-${$id}`}
:_legendId=${`bs-check-group-legend-${$id}`}
:_multi=${type !== 'radio'}
// a lone value read as a list of one, the way `:options` reads a lone
// string as an entry: passing `:value="Slack"` to a checkbox group says
// something unambiguous, and spreading a string into characters is not it
:_selected=${!_multi ? [] : Array.isArray(value) ? value : value == null ? [] : [value]}
aria-labelledby=${legend ? _legendId : null}
:_options=${options.map(o =>
typeof o === 'object' && o !== null
? { name: o.name, value: o.value ?? o.name, disabled: !!o.disabled }
: { name: o, value: o, disabled: false })}
>
${legend}
{
if (!_multi) { value = ev.target.value; return; }
const on = ev.target.checked;
const hit = ev.target.value;
value = _options
.filter(o => (o.value === hit ? on : _selected.includes(o.value)))
.map(o => o.value);
}}>