import{x as j,ab as L,h as S,f as y,af as v,aa as O,X as x,e as K,J as _,F as A}from"./index-CTxlYqj4.js";const C=(t,r,e)=>{if(t==null||r==null)return-1;if(!r.length)return 0;t=t.toString().toLocaleLowerCase(),r=r.toString().toLocaleLowerCase();const l=[];let f=t.indexOf(r);for(;~f;)l.push([f,f+r.length]),f=t.indexOf(r,f+r.length);return l.length?l:-1};function w(t,r){if(!(t==null||typeof t=="boolean"||t===-1))return typeof t=="number"?[[t,t+r.length]]:Array.isArray(t[0])?t:[t]}const E=j({customFilter:Function,customKeyFilter:Object,filterKeys:[Array,String],filterMode:{type:String,default:"intersection"},noFilter:Boolean},"filter");function $(t,r,e){var m;const l=[],f=(e==null?void 0:e.default)??C,u=e!=null&&e.filterKeys?O(e.filterKeys):!1,a=Object.keys((e==null?void 0:e.customKeyFilter)??{}).length;if(!(t!=null&&t.length))return l;e:for(let n=0;n<t.length;n++){const[s,M=s]=O(t[n]),d={},i={};let c=-1;if((r||a>0)&&!(e!=null&&e.noFilter)){if(typeof s=="object"){const k=u||Object.keys(M);for(const g of k){const I=x(M,g),b=(m=e==null?void 0:e.customKeyFilter)==null?void 0:m[g];if(c=b?b(I,r,s):f(I,r,s),c!==-1&&c!==!1)b?d[g]=w(c,r):i[g]=w(c,r);else if((e==null?void 0:e.filterMode)==="every")continue e}}else c=f(s,r,s),c!==-1&&c!==!1&&(i.title=w(c,r));const h=Object.keys(i).length,F=Object.keys(d).length;if(!h&&!F||(e==null?void 0:e.filterMode)==="union"&&F!==a&&!h||(e==null?void 0:e.filterMode)==="intersection"&&(F!==a||!h))continue}l.push({index:n,matches:{...i,...d}})}return l}function P(t,r,e,l){const f=L([]),u=L(new Map),a=S(()=>l!=null&&l.transform?y(r).map(n=>[n,l.transform(n)]):y(r));v(()=>{const n=typeof e=="function"?e():y(e),s=typeof n!="string"&&typeof n!="number"?"":String(n),M=$(a.value,s,{customKeyFilter:{...t.customKeyFilter,...y(l==null?void 0:l.customKeyFilter)},default:t.customFilter,filterKeys:t.filterKeys,filterMode:t.filterMode,noFilter:t.noFilter}),d=y(r),i=[],c=new Map;M.forEach(h=>{let{index:F,matches:k}=h;const g=d[F];i.push(g),c.set(g.value,k)}),f.value=i,u.value=c});function m(n){return u.value.get(n.value)}return{filteredItems:f,filteredMatches:u,getMatches:m}}function R(t,r,e){return e==null||!e.length?r:e.map((l,f)=>{const u=f===0?0:e[f-1][1],a=[K("span",{class:_(`${t}__unmask`)},[r.slice(u,l[0])]),K("span",{class:_(`${t}__mask`)},[r.slice(l[0],l[1])])];return f===e.length-1&&a.push(K("span",{class:_(`${t}__unmask`)},[r.slice(l[1])])),K(A,null,[a])})}export{R as h,E as m,P as u};
