import{arrayType as e,booleanType as t,stringType as n}from"../_util/type.mjs";import r from"../_util/classNames.mjs";import{filterEmpty as i,isValidElement as a,splitAttrs as o}from"../_util/props-util/index.mjs";import s from"../_util/vue-types/index.mjs";import c from"../menu/index.mjs";import l from"../checkbox/index.mjs";import u from"../dropdown/index.mjs";import{groupKeysMap as d}from"../_util/transKeys.mjs";import f from"./ListBody.mjs";import p from"./search.mjs";import{Fragment as m,computed as h,createTextVNode as g,createVNode as _,defineComponent as v,ref as y,watchEffect as b}from"vue";import{DownOutlined as x}from"@antsoo-lib/icons";var S=()=>null;function C(e){return!!(e&&!a(e)&&Object.prototype.toString.call(e)===`[object Object]`)}function w(e){return e.filter(e=>!e.disabled).map(e=>e.key)}var T={prefixCls:String,dataSource:e([]),filter:String,filterOption:Function,checkedKeys:s.arrayOf(s.string),handleFilter:Function,handleClear:Function,renderItem:Function,showSearch:t(!1),searchPlaceholder:String,notFoundContent:s.any,itemUnit:String,itemsUnit:String,renderList:s.any,disabled:t(),direction:n(),showSelectAll:t(),remove:String,selectAll:String,selectCurrent:String,selectInvert:String,removeAll:String,removeCurrent:String,selectAllLabel:s.any,showRemove:t(),pagination:s.any,onItemSelect:Function,onItemSelectAll:Function,onItemRemove:Function,onScroll:Function},E=v({compatConfig:{MODE:3},name:`TransferList`,inheritAttrs:!1,props:T,slots:Object,setup(e,{attrs:t,slots:n}){let a=y(``),s=y(),v=y(),T=(e,t)=>{let n=e?e(t):null,r=!!n&&i(n).length>0;return r||(n=_(f,{...t,ref:v},null)),{customize:r,bodyContent:n}},E=t=>{let{renderItem:n=S}=e,r=n(t),i=C(r);return{renderedText:i?r.value:r,renderedEl:i?r.label:r,item:t}},D=y([]),O=y([]);b(()=>{let t=[],n=[];e.dataSource.forEach(e=>{let r=E(e),{renderedText:i}=r;if(a.value&&a.value.trim()&&!F(i,e))return null;t.push(e),n.push(r)}),D.value=t,O.value=n});let k=h(()=>{let{checkedKeys:t}=e;if(t.length===0)return`none`;let n=d(t);return D.value.every(e=>n.has(e.key)||!!e.disabled)?`all`:`part`}),A=h(()=>w(D.value)),j=(t,n)=>Array.from(new Set([...t,...e.checkedKeys])).filter(e=>!n.includes(e)),M=({disabled:t,prefixCls:n})=>{let r=k.value===`all`;return _(l,{disabled:e.dataSource?.length===0||t,checked:r,indeterminate:k.value===`part`,class:`${n}-checkbox`,onChange:()=>{let t=A.value;e.onItemSelectAll(j(r?[]:t,r?e.checkedKeys:[]))}},null)},N=t=>{let{target:{value:n}}=t;a.value=n,e.handleFilter?.(t)},P=t=>{a.value=``,e.handleClear?.(t)},F=(t,n)=>{let{filterOption:r}=e;return r?r(a.value,n):t.includes(a.value)},I=(t,n)=>{let{itemsUnit:r,itemUnit:i,selectAllLabel:a}=e;if(a)return typeof a==`function`?a({selectedCount:t,totalCount:n}):a;let o=n>1?r:i;return _(m,null,[(t>0?`${t}/`:``)+n,g(` `),o])},L=h(()=>Array.isArray(e.notFoundContent)?e.notFoundContent[e.direction===`left`?0:1]:e.notFoundContent),R=(n,r,i,c,l,u)=>{let d=l?_(`div`,{class:`${n}-body-search-wrapper`},[_(p,{prefixCls:`${n}-search`,onChange:N,handleClear:P,placeholder:r,value:a.value,disabled:u},null)]):null,f,{onEvents:m}=o(t),{bodyContent:h,customize:g}=T(c,{...e,filteredItems:D.value,filteredRenderItems:O.value,selectedKeys:i,...m});return f=g?_(`div`,{class:`${n}-body-customize-wrapper`},[h]):D.value.length?h:_(`div`,{class:`${n}-body-not-found`},[L.value]),_(`div`,{class:l?`${n}-body ${n}-body-with-search`:`${n}-body`,ref:s},[d,f])};return()=>{let{prefixCls:i,checkedKeys:a,disabled:o,showSearch:s,searchPlaceholder:l,selectAll:d,selectCurrent:f,selectInvert:p,removeAll:h,removeCurrent:g,renderList:y,onItemSelectAll:b,onItemRemove:S,showSelectAll:C=!0,showRemove:T,pagination:E}=e,O=n.footer?.({...e}),k=r(i,{[`${i}-with-pagination`]:!!E,[`${i}-with-footer`]:!!O}),N=R(i,l,a,y,s,o),P=O?_(`div`,{class:`${i}-footer`},[O]):null,F=!T&&!E&&M({disabled:o,prefixCls:i}),L=null;L=T?_(c,null,{default:()=>[E&&_(c.Item,{key:`removeCurrent`,onClick:()=>{let e=w((v.value.items||[]).map(e=>e.item));S?.(e)}},{default:()=>[g]}),_(c.Item,{key:`removeAll`,onClick:()=>{S?.(A.value)}},{default:()=>[h]})]}):_(c,null,{default:()=>[_(c.Item,{key:`selectAll`,onClick:()=>{let e=A.value;b(j(e,[]))}},{default:()=>[d]}),E&&_(c.Item,{onClick:()=>{let e=w((v.value.items||[]).map(e=>e.item));b(j(e,[]))}},{default:()=>[f]}),_(c.Item,{key:`selectInvert`,onClick:()=>{let e;e=E?w((v.value.items||[]).map(e=>e.item)):A.value;let t=new Set(a),n=[],r=[];e.forEach(e=>{t.has(e)?r.push(e):n.push(e)}),b(j(n,r))}},{default:()=>[p]})]});let z=_(u,{class:`${i}-header-dropdown`,overlay:L,disabled:o},{default:()=>[_(x,null,null)]});return _(`div`,{class:k,style:t.style},[_(`div`,{class:`${i}-header`},[C?_(m,null,[F,z]):null,_(`span`,{class:`${i}-header-selected`},[_(`span`,null,[I(a.length,D.value.length)]),_(`span`,{class:`${i}-header-title`},[n.titleText?.()])])]),N,P])}}});export{E as default,T as transferListProps};