// @bun
var{defineProperty:o,getOwnPropertyNames:O,getOwnPropertyDescriptor:S}=Object,R=Object.prototype.hasOwnProperty;function h(e){return this[e]}var N=(e)=>{var t=(d??=new WeakMap).get(e),i;if(t)return t;if(t=o({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var r of O(e))if(!R.call(t,r))o(t,r,{get:h.bind(e,r),enumerable:!(i=S(e,r))||i.enumerable})}return d.set(e,t),t},d;var m=(e)=>e;function k(e,t){this[e]=m.bind(null,t)}var T=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0,configurable:!0,set:k.bind(t,i)})};var A=(e,t)=>()=>(e&&(t=e(e=0)),t);var V=new Set(["gt","gte"]),w=new Set(["lt","lte"]),b=new Set(["gt","gte","lt","lte","between"]);function M({filters:e=[],scope:t,user:i}){let r=new Map(e.map((f)=>[f.key,f])),a=F(i??t?.initial??{}),n=F(t?.locked??{}),l=c(n,r),u=C(a,r,l);return{user:u,locked:n,effective:[...c(u,r),...l],lockedChips:t?.lockedChips??"visible-disabled"}}function F(e){return Object.fromEntries(Object.entries(e).map(([t,i])=>[t,s(i)]).filter((t)=>Boolean(t[1])))}function c(e,t){return Object.entries(e).flatMap(([i,r])=>{if(!r)return[];return D(i,r,t.get(i))})}function p(e,t){return e.filter((i)=>!t.some((r)=>x(i,r)))}function C(e,t,i){return Object.fromEntries(Object.entries(e).flatMap(([r,a])=>{let n=E(r,a,t.get(r),i);return n?[[r,n]]:[]}))}function s(e){if(!e)return;if(e.kind==="single")return e.value==null||e.value===""?void 0:e;if(e.kind==="multi"){let i=e.values.filter((r)=>r!=="");return i.length?{...e,values:i}:void 0}if(e.kind==="range")return e.from==null&&e.to==null?void 0:e;let t=e.clauses.map((i)=>({...i,value:s(i.value)})).filter((i)=>i.value!==void 0||i.operator==="isNull"||i.operator==="isNotNull");return t.length?{...e,clauses:t}:void 0}function D(e,t,i){if(t.kind==="composite")return t.clauses;let r=i?.field??e,a=i?.operator??y(t,i?.type);if(t.kind!=="range")return[{filterKey:e,field:r,operator:a,value:t}];let n=g(t);return n?[{filterKey:e,field:r,operator:n,value:t}]:[]}function E(e,t,i,r){let a=s(t);if(!a)return;if(a.kind==="composite"){let l=p(a.clauses,r);return l.length?{...a,clauses:l}:void 0}return p(D(e,a,i),r).length?a:void 0}function y(e,t){if(e.kind==="multi")return"in";if(e.kind==="range")return g(e)??"between";if(t==="search")return"contains";return"eq"}function g(e){let t=e.from!=null,i=e.to!=null;if(t&&i)return"between";if(t)return e.includeFrom===!1?"gt":"gte";if(i)return e.includeTo===!1?"lt":"lte";return}function x(e,t){if(e.field!==t.field)return!1;if(e.operator===t.operator)return!0;if(t.operator==="between")return b.has(e.operator);if(V.has(t.operator))return V.has(e.operator);if(w.has(t.operator))return w.has(e.operator);return!1}export{F as sanitizeDataViewFilterSet,M as resolveDataViewFilters,C as pruneDataViewFilterSet,p as pruneDataViewFilterClauses,c as filterSetToClauses};
