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