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