import{d as q,af as g,E as C,a7 as S,G as b,J as _,V as k,ad as A,ae as N}from"./BvNnk7SS.js";import{q as c}from"./BJLPbHX2.js";import"./DQ_4YmnO.js";import"./DGhmaXto.js";const O=q({name:"ContentQuery",props:{path:{type:String,required:!1,default:void 0},only:{type:Array,required:!1,default:void 0},without:{type:Array,required:!1,default:void 0},where:{type:Object,required:!1,default:void 0},sort:{type:Object,required:!1,default:void 0},limit:{type:Number,required:!1,default:void 0},skip:{type:Number,required:!1,default:void 0},locale:{type:String,required:!1,default:void 0},find:{type:String,required:!1,default:void 0}},async setup(a){const{path:t,only:r,without:o,where:i,sort:l,limit:s,skip:d,locale:f,find:p}=g(a),y=C(()=>t.value?.includes("/_")),h=!S().public.content.experimental.advanceQuery;b(()=>a,()=>u(),{deep:!0});const n=e=>h?e?.surround?e.surround:e?._id||Array.isArray(e)?e:e?.result:e.result,{data:v,refresh:u}=await _(`content-query-${k(a)}`,()=>{let e;return t.value?e=c(t.value):e=c(),r.value&&(e=e.only(r.value)),o.value&&(e=e.without(o.value)),i.value&&(e=e.where(i.value)),l.value&&(e=e.sort(l.value)),s.value&&(e=e.limit(s.value)),d.value&&(e=e.skip(d.value)),f.value&&(e=e.where({_locale:f.value})),p.value==="one"?e.findOne().then(n):p.value==="surround"?t.value?h?e.findSurround(t.value):e.withSurround(t.value).findOne().then(n):(console.warn("[Content] Surround queries requires `path` prop to be set."),console.warn("[Content] Query without `path` will return regular `find()` results."),e.find().then(n)):e.find().then(n)});return{isPartial:y,data:v,refresh:u}},render(a){const t=A(),{data:r,refresh:o,isPartial:i,path:l,only:s,without:d,where:f,sort:p,limit:y,skip:h,locale:n,find:v}=a,u={path:l,only:s,without:d,where:f,sort:p,limit:y,skip:h,locale:n,find:v};if(u.find==="one"){if(!r&&t?.["not-found"])return t["not-found"]({props:u,...this.$attrs});if(t?.empty&&r?._type==="markdown"&&!r?.body?.children.length)return t.empty({props:u,...this.$attrs})}else if((!r||!r.length)&&t?.["not-found"])return t["not-found"]({props:u,...this.$attrs});return t?.default?t.default({data:r,refresh:o,isPartial:i,props:u,...this.$attrs}):((m,w)=>N("pre",null,JSON.stringify({message:"You should use slots with <ContentQuery>!",slot:m,data:w},null,2)))("default",{data:r,props:u,isPartial:i})}}),x=O;export{x as default};
