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