import{defineComponent as N,inject as E,computed as O,watchEffect as P,onBeforeUnmount as _,onMounted as B,ref as K,createVNode as s}from"vue";import f from"../_util/classNames.mjs";import{flattenChildren as R}from"../_util/props-util/index.mjs";import U from"../_util/warning.mjs";import{useInjectDisabled as H}from"../config-provider/DisabledContext.mjs";import T from"../config-provider/hooks/useConfigInject.mjs";import{useInjectFormItemContext as X,FormItemInputContext as q}from"../form/FormItemContext.mjs";import z from"../vc-checkbox/Checkbox.mjs";import{CheckboxGroupContextKey as J,checkboxProps as L}from"./interface.mjs";import Q from"./style/index.mjs";const de=N({compatConfig:{MODE:3},name:"ACheckbox",inheritAttrs:!1,__ANT_CHECKBOX:!0,props:L(),setup(n,{emit:l,attrs:h,slots:p,expose:b}){const u=X(),v=q.useInject(),{prefixCls:o,direction:C,disabled:k}=T("checkbox",n),x=H(),[g,i]=Q(o),e=E(J,void 0),d=Symbol("checkboxUniId"),m=O(()=>e?.disabled.value||k.value);P(()=>{!n.skipGroup&&e&&e.registerValue(d,n.value)}),_(()=>{e&&e.cancelValue(d)}),B(()=>{U(!!(n.checked!==void 0||e||n.value===void 0))});const I=a=>{const c=a.target.checked;l("update:checked",c),l("change",a),u.onFieldChange()},r=K();return b({focus:()=>{r.value?.focus()},blur:()=>{r.value?.blur()}}),()=>{const a=R(p.default?.()),{indeterminate:c,skipGroup:w,id:M=u.id.value,...$}=n,{onMouseenter:j,onMouseleave:y,onInput:Z,class:S,style:V,...A}=h,t={...$,id:M,prefixCls:o.value,...A,disabled:m.value};e&&!w?(t.onChange=(...G)=>{l("change",...G),e.toggleOption({label:a,value:n.value})},t.name=e.name.value,t.checked=e.mergedValue.value.includes(n.value),t.disabled=m.value||x.value,t.indeterminate=c):t.onChange=I;const D=f({[`${o.value}-wrapper`]:!0,[`${o.value}-rtl`]:C.value==="rtl",[`${o.value}-wrapper-checked`]:t.checked,[`${o.value}-wrapper-disabled`]:t.disabled,[`${o.value}-wrapper-in-form-item`]:v.isFormItemInput},S,i.value),F=f({[`${o.value}-indeterminate`]:c},i.value);return g(s("label",{class:D,style:V,onMouseenter:j,onMouseleave:y},[s(z,{"aria-checked":c?"mixed":void 0,...t,class:F,ref:r},null),a.length?s("span",null,[a]):null]))}}});export{de as default};
