:: multiselectWidget[widget]
<<widget 'multiselect' container>>

	<<set _receiver = _args[0]>>
	<<set _fields = _args[1]>>
    <<set _ms_contents = _contents>>
    <<set _style = '--entryCount:'+_fields.length>>
    <div class="multiselect" @style="_style">

    <<set _currenctReceiverState = State.getVar(_receiver)>>
    <<if _currenctReceiverState === undefined>>
        <<run State.setVar(_receiver,[])>>
        <<set _currenctReceiverState = []>>
    <</if>>

	<<for _field range _fields>>
		<<if typeof _field == 'object'>>
			<<set _label = _field.label>>
			<<set _id = _field.id>>
		<<else>>
			<<set _label = _field>>
			<<set _id = _field>>
		<</if>>
		<<set _css_id = 'ms_btn_'+_receiver.replace('$','_').replace('.','_')+'_'+_id>>


        <<set _class = 'selector '>>
        <<set _class += _currenctReceiverState.includes(_id) ? 'selected' : ''>>

		<div @class="_class" @id="_css_id">
			<<capture _receiver,_id,_css_id,_ms_contents>>
				<<link _label>>
					<<set _currenctReceiverState = State.getVar(_receiver)>>
					<<if _currenctReceiverState.includes(_id)>>
						<<set _currenctReceiverState = _currenctReceiverState.delete(_id)>>
						<<removeclass `'#'+_css_id` 'selected'>>
					<<else>>
						<<run _currenctReceiverState.push(_id)>>
						<<addclass `'#'+_css_id` 'selected'>>
					<</if>>
                    _ms_contents
				<</link>>
			<</capture>>
		</div>
	<</for>>
    </div>
<</widget>>
