const e=require("../../../vc-util/devWarning.js"),t=require("../../../_util/hooks/useState.js"),n=require("../../util.js"),r=require("./FilterDropdown.js");let i=require("vue");function a(e,t,r){let i=[];return(e||[]).forEach((e,o)=>{let s=n.getColumnPos(o,r),c=e.filterDropdown||e?.slots?.filterDropdown||e.customFilterDropdown;if(e.filters||c||`onFilter`in e)if(`filteredValue`in e){let t=e.filteredValue;c||(t=t?.map(String)??t),i.push({column:e,key:n.getColumnKey(e,s),filteredKeys:t,forceFiltered:e.filtered})}else i.push({column:e,key:n.getColumnKey(e,s),filteredKeys:t&&e.defaultFilteredValue?e.defaultFilteredValue:void 0,forceFiltered:e.filtered});`children`in e&&(i=[...i,...a(e.children,t,s)])}),i}function o(e,t,a,s,c,l,u,d){return a.map((a,f)=>{let p=n.getColumnPos(f,d),{filterMultiple:m=!0,filterMode:h,filterSearch:g}=a,_=a,v=a.filterDropdown||a?.slots?.filterDropdown||a.customFilterDropdown;if(_.filters||v){let o=n.getColumnKey(_,p),d=s.find(({key:e})=>o===e);_={..._,title:s=>(0,i.createVNode)(r.default,{tablePrefixCls:e,prefixCls:`${e}-filter`,dropdownPrefixCls:t,column:_,columnKey:o,filterState:d,filterMultiple:m,filterMode:h,filterSearch:g,triggerFilter:l,locale:c,getPopupContainer:u},{default:()=>[n.renderColumnTitle(a.title,s)]})}}return`children`in _&&(_={..._,children:o(e,t,_.children,s,c,l,u,p)}),_})}function s(e){let t=[];return(e||[]).forEach(({value:e,children:n})=>{t.push(e),n&&(t=[...t,...s(n)])}),t}function c(e){let t={};return e.forEach(({key:e,filteredKeys:n,column:r})=>{let i=r.filterDropdown||r?.slots?.filterDropdown||r.customFilterDropdown,{filters:a}=r;if(i)t[e]=n||null;else if(Array.isArray(n)){let r=s(a);t[e]=r.filter(e=>n.includes(String(e)))}else t[e]=null}),t}function l(e,t){return t.reduce((e,t)=>{let{column:{onFilter:n,filters:r},filteredKeys:i}=t;return n&&i&&i.length?e.filter(e=>i.some(t=>{let i=s(r),a=i.findIndex(e=>String(e)===String(t)),o=a===-1?t:i[a];return n(o,e)})):e},e)}function u(e){return e.flatMap(e=>`children`in e?[e,...u(e.children||[])]:[e])}function d({prefixCls:r,dropdownPrefixCls:s,mergedColumns:l,locale:d,onFilterChange:f,getPopupContainer:p}){let m=(0,i.computed)(()=>u(l.value)),[h,g]=t.default(a(m.value,!0)),_=(0,i.computed)(()=>{let t=a(m.value,!1);if(t.length===0)return t;let r=!0,i=!0;if(t.forEach(({filteredKeys:e})=>{e===void 0?i=!1:r=!1}),r){let e=(m.value||[]).map((e,t)=>n.getColumnKey(e,n.getColumnPos(t)));return h.value.filter(({key:t})=>e.includes(t)).map(t=>{let n=m.value[e.findIndex(e=>e===t.key)];return{...t,column:{...t.column,...n},forceFiltered:n.filtered}})}return e.default(i,`Table`,"Columns should all contain `filteredValue` or not contain `filteredValue`."),t}),v=(0,i.computed)(()=>c(_.value)),y=e=>{let t=_.value.filter(({key:t})=>t!==e.key);t.push(e),g(t),f(c(t),t)};return[e=>o(r.value,s.value,e,_.value,d.value,y,p.value),_,v]}exports.default=d,exports.flattenKeys=s,exports.getFilterData=l;