import e from"../config-provider/hooks/useConfigInject.mjs";import{useInjectFormItemContext as t}from"../form/FormItemContext.mjs";import n from"./style/index.mjs";import{CheckboxGroupContextKey as r,checkboxGroupProps as i}from"./interface.mjs";import a from"./Checkbox.mjs";import{computed as o,createVNode as s,defineComponent as c,provide as l,ref as u,watch as d}from"vue";var f=c({compatConfig:{MODE:3},name:`ACheckboxGroup`,inheritAttrs:!1,props:i(),setup(i,{slots:c,attrs:f,emit:p,expose:m}){let h=t(),{prefixCls:g,direction:_}=e(`checkbox`,i),v=o(()=>`${g.value}-group`),[y,b]=n(v),x=u((i.value===void 0?i.defaultValue:i.value)||[]);d(()=>i.value,()=>{x.value=i.value||[]});let S=o(()=>i.options.map(e=>typeof e==`string`||typeof e==`number`?{label:e,value:e}:e)),C=u(Symbol()),w=u(new Map),T=e=>{w.value.delete(e),C.value=Symbol()},E=(e,t)=>{w.value.set(e,t),C.value=Symbol()},D=u(new Map);return d(C,()=>{let e=new Map;for(let t of w.value.values())e.set(t,!0);D.value=e}),l(r,{cancelValue:T,registerValue:E,toggleOption:e=>{let t=x.value.indexOf(e.value),n=[...x.value];t===-1?n.push(e.value):n.splice(t,1),i.value===void 0&&(x.value=n);let r=n.filter(e=>D.value.has(e)).sort((e,t)=>S.value.findIndex(t=>t.value===e)-S.value.findIndex(e=>e.value===t));p(`update:value`,r),p(`change`,r),h.onFieldChange()},mergedValue:x,name:o(()=>i.name),disabled:o(()=>i.disabled)}),m({mergedValue:x}),()=>{let{id:e=h.id.value}=i,t=null;return S.value&&S.value.length>0&&(t=S.value.map(e=>s(a,{prefixCls:g.value,key:e.value.toString(),disabled:`disabled`in e?e.disabled:i.disabled,indeterminate:e.indeterminate,value:e.value,checked:x.value.includes(e.value),onChange:e.onChange,class:`${v.value}-item`},{default:()=>[c.label===void 0?e.label:c.label?.(e)]}))),y(s(`div`,{...f,class:[v.value,{[`${v.value}-rtl`]:_.value===`rtl`},f.class,b.value],id:e},[t||c.default?.()]))}}});export{f as default};