import{getDataAndAriaProps as e}from"../_util/util.mjs";import t from"../_util/classNames.mjs";import n from"../_util/props-util/initDefaultProps.mjs";import{flattenChildren as r,isEmptyElement as i,isValidElement as a}from"../_util/props-util/index.mjs";import o from"../config-provider/hooks/useConfigInject.mjs";import{cloneElement as s}from"../_util/vnode.mjs";import c from"../_util/firstNotUndefined.mjs";import l from"../_util/collapseMotion.mjs";import{collapseProps as u}from"./commonProps.mjs";import d from"./style/index.mjs";import{computed as f,createVNode as p,defineComponent as m,ref as h,watch as g}from"vue";import{RightOutlined as _}from"@antsoo-lib/icons";function v(e){let t=e;if(!Array.isArray(t)){let e=typeof t;t=e===`number`||e===`string`?[t]:[]}return t.map(e=>String(e))}var y=m({compatConfig:{MODE:3},name:`ACollapse`,inheritAttrs:!1,props:n(u(),{accordion:!1,destroyInactivePanel:!1,bordered:!0,expandIconPosition:`start`}),slots:Object,setup(n,{attrs:u,slots:m,emit:y}){let b=h(v(c([n.activeKey,n.defaultActiveKey])));g(()=>n.activeKey,()=>{b.value=v(n.activeKey)},{deep:!0});let{prefixCls:x,direction:S,rootPrefixCls:C}=o(`collapse`,n),[w,T]=d(x),E=f(()=>{let{expandIconPosition:e}=n;return e===void 0?S.value===`rtl`?`end`:`start`:e}),D=e=>{let{expandIcon:t=m.expandIcon}=n,r=t?t(e):p(_,{rotate:e.isActive?90:void 0},null);return p(`div`,{class:[`${x.value}-expand-icon`,T.value],onClick:()=>[`header`,`icon`].includes(n.collapsible)&&k(e.panelKey)},[a(Array.isArray(t)?r[0]:r)?s(r,{class:`${x.value}-arrow`},!1):r])},O=e=>{n.activeKey===void 0&&(b.value=e);let t=n.accordion?e[0]:e;y(`update:activeKey`,t),y(`change`,t)},k=e=>{let t=b.value;if(n.accordion)t=t[0]===e?[]:[e];else{t=[...t];let n=t.indexOf(e);n>-1?t.splice(n,1):t.push(e)}O(t)},A=(e,t)=>{if(i(e))return;let r=b.value,{accordion:a,destroyInactivePanel:o,collapsible:c,openAnimation:u}=n,d=u||l(`${C.value}-motion-collapse`),f=String(e.key??t),{header:p=e.children?.header?.(),headerClass:m,collapsible:h,disabled:g}=e.props||{},_=!1;_=a?r[0]===f:r.includes(f);let v=h??c;return(g||g===``)&&(v=`disabled`),s(e,{key:f,panelKey:f,header:p,headerClass:m,isActive:_,prefixCls:x.value,destroyInactivePanel:o,openAnimation:d,accordion:a,onItemClick:v===`disabled`?null:k,expandIcon:D,collapsible:v})},j=()=>r(m.default?.()).map(A);return()=>{let{accordion:r,bordered:i,ghost:a}=n,o=t(x.value,{[`${x.value}-borderless`]:!i,[`${x.value}-icon-position-${E.value}`]:!0,[`${x.value}-rtl`]:S.value===`rtl`,[`${x.value}-ghost`]:!!a,[u.class]:!!u.class},T.value);return w(p(`div`,{class:o,...e(u),style:u.style,role:r?`tablist`:null},[j()]))}}});export{u as collapseProps,y as default};