const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BI5b1mi2.js","./BvNnk7SS.js","./entry.Le7YthGh.css","./DpJXNNLA.js","./DGhmaXto.js","./DQ_4YmnO.js"])))=>i.map(i=>d[i]);
import{a7 as y,ah as w,cb as m,cc as _,V as h,a3 as $}from"./BvNnk7SS.js";import{w as p,s as P}from"./DQ_4YmnO.js";import{u as C}from"./DGhmaXto.js";const l=(t,e)=>e.split(".").reduce((n,s)=>n&&n[s],t),f=(t,e)=>Object.keys(t).filter(e).reduce((n,s)=>Object.assign(n,{[s]:t[s]}),{}),T=t=>e=>t&&t.length?f(e,n=>!t.includes(n)):e,L=t=>e=>Array.isArray(e)?e.map(n=>t(n)):t(e),d=t=>{const e=[],n=[];for(const s of t)["$","_"].includes(s)?e.push(s):n.push(s);return{prefixes:e,properties:n}},j=(t=[])=>e=>{if(t.length===0||!e)return e;const{prefixes:n,properties:s}=d(t);return f(e,i=>!s.includes(i)&&!n.includes(i[0]))},q=(t=[])=>e=>{if(t.length===0||!e)return e;const{prefixes:n,properties:s}=d(t);return f(e,i=>s.includes(i)||n.includes(i[0]))},D=(t,e)=>{const n=new Intl.Collator(e.$locale,{numeric:e.$numeric,caseFirst:e.$caseFirst,sensitivity:e.$sensitivity}),s=Object.keys(e).filter(i=>!i.startsWith("$"));for(const i of s)t=t.sort((o,r)=>{const a=[l(o,i),l(r,i)].map(c=>{if(c!==null)return c instanceof Date?c.toISOString():c});return e[i]===-1&&a.reverse(),n.compare(a[0],a[1])});return t},v=(t,e="Expected an array")=>{if(!Array.isArray(t))throw new TypeError(e)},u=t=>Array.isArray(t)?t:[void 0,null].includes(t)?[]:[t],S=["sort","where","only","without"];function E(t,e={}){const n={};for(const r of Object.keys(e.initialParams||{}))n[r]=S.includes(r)?u(e.initialParams[r]):e.initialParams[r];const s=(r,a=c=>c)=>(...c)=>(n[r]=a(...c),o),i=r=>e.legacy?r?.surround?r.surround:r&&(r?.dirConfig&&(r.result={_path:r.dirConfig?._path,...r.result,_dir:r.dirConfig}),r?._path||Array.isArray(r)||!Object.prototype.hasOwnProperty.call(r,"result")?r:r?.result):r,o={params:()=>({...n,...n.where?{where:[...u(n.where)]}:{},...n.sort?{sort:[...u(n.sort)]}:{}}),only:s("only",u),without:s("without",u),where:s("where",r=>[...u(n.where),...u(r)]),sort:s("sort",r=>[...u(n.sort),...u(r)]),limit:s("limit",r=>parseInt(String(r),10)),skip:s("skip",r=>parseInt(String(r),10)),find:()=>t(o).then(i),findOne:()=>t(s("first")(!0)).then(i),count:()=>t(s("count")(!0)).then(i),locale:r=>o.where({_locale:r}),withSurround:s("surround",(r,a)=>({query:r,...a})),withDirConfig:()=>s("dirConfig")(!0)};return e.legacy&&(o.findSurround=(r,a)=>o.withSurround(r,a).find().then(i)),o}function g(t){return JSON.stringify(t,A)}function A(t,e){return e instanceof RegExp?`--REGEX ${e.toString()}`:e}const O=t=>{let e=g(t);return e=typeof Buffer<"u"?Buffer.from(e).toString("base64"):btoa(e),e=e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),(e.match(/.{1,100}/g)||[]).join("/")},x=()=>async t=>{const{content:e}=y().public,n=t.params(),s=e.experimental.stripQueryParameters?p(`/query/${`${h(n)}.${e.integrity}`}/${O(n)}.json`):p(`/query/${h(n)}.${e.integrity}.json`);if(P())return(await $(()=>import("./BI5b1mi2.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(r=>r.useContentDatabase())).fetch(t);const i=await $fetch(s,{method:"GET",responseType:"json",params:e.experimental.stripQueryParameters?void 0:{_params:g(n),previewToken:C().getPreviewToken()}});if(typeof i=="string"&&i.startsWith("<!DOCTYPE html>"))throw new Error("Not found");return i};function B(t,...e){const{content:n}=y().public,s=E(x(),{initialParams:typeof t!="string"?t:{},legacy:!0});let i;typeof t=="string"&&(i=w(m(t,...e)));const o=s.params;return s.params=()=>{const r=o();return i&&(r.where=r.where||[],r.first&&(r.where||[]).length===0?r.where.push({_path:_(i)}):r.where.push({_path:new RegExp(`^${i.replace(/[-[\]{}()*+.,^$\s/]/g,"\\$&")}`)})),r.sort?.length||(r.sort=[{_stem:1,$numeric:!0}]),n.locales.length&&(r.where?.find(c=>c._locale)?._locale||(r.where=r.where||[],r.where.push({_locale:n.defaultLocale}))),r},s}export{v as a,u as b,L as c,q as d,O as e,E as f,l as g,g as j,T as o,B as q,D as s,j as w};
