1import{a8 as W,Z,u as j,v as J,a as U,p as M,az as X,aA as F,r as P,aB as k,H as $,R as tt,q as at,l as R,n as H}from"./4czN1GdW.js";function et(i,c){const g=c.payload.data[i];return g!==void 0?(delete c.payload.data[i],g):c.static?.data?.[i]}const ut=async({itemPath:i,hasCategory:c,categoryApiPath:g,categoryField:h,categoryQueryMode:x="filters",componentName:z,defaultPerPage:p=10,onFetchSuccess:A=()=>{},onFetchError:D=()=>{}})=>{const _=W(),{localePath:G,currentLocaleCode:O}=Z(),s=j(),{t:Y}=J(),w=R(()=>H(String(s.params.categorySlug||""))),B=R(()=>H(String(s.params.slug||""))),{getPath:K,slugPageInfo:r,getBreadcrumb:N}=U();if(s.params.slug&&!r.value)throw M({statusCode:404,statusMessage:"Page not found"});const E=_.$api,L=X(String(s.path)),y=F(`total-${L}`,()=>0),d=P(p||10),n=P(parseInt(s.query.page,10)||1),I=async t=>{let e={title:"",description:""},a=null,m=[];if(c&&g){const T=(await E(g,{query:{page:1,perPage:1e3,orderBy:"position",sortBy:"asc"}}))?.data,b=Array.isArray(T)?T:T?.data||[];if(w.value){const o=b.find(V=>V.slug===w.value);if(!o||typeof o>"u")throw M({statusCode:404,message:"Page not found"});a=o}m=[{title:Y("global.total",{},{locale:O.value}),path:G(`/${B.value}`)},...b.filter(o=>o.title!==""&&o.slug!=="").map(o=>({title:o.title,path:K({componentName:z,categorySlug:o.slug})}))],e={title:`${r.value?.topic?r.value.topic:r.value?.title}${a?` - ${a.title}`:""}`,description:r.value?.description||""}}else e={title:r.value?.topic||r.value?.title||"",description:r.value?.description||""};const u={page:t,perPage:p,status:"published"};typeof h=="string"&&(x==="direct"?u[h]=a?._id:u[`filters[${h}]`]=a?._id);const l=tt(),q=await E(i,{query:u});l.updatePreloading(!1);const C=q.data||[];return C.length&&A&&A(C),D&&!C.length&&D(new Error("Failed to fetch items")),{asyncCategory:{section:e,category:a,categoryButtonItems:m},items:C,total:q.total||0,perPage:q.perPage||p}},{data:v}=await _.runWithContext(()=>k(`ssr-page-${L}`,async()=>{const t=parseInt(s.query.page,10)||1;return I(t)},{getCachedData:(t,e)=>et(t,e)})),f=P(v.value?.asyncCategory??null),S=P(v.value?.items??[]);y.value=v.value?.total??0,d.value=v.value?.perPage??p;const Q=R(()=>N(f.value?.category?.title));return $(()=>s.query.page,t=>{const e=parseInt(t,10)||1;n.value!==e&&(n.value=e)},{immediate:!0}),$(n,async(t,e)=>{if(t===e)return;const a=await I(t);f.value=a.asyncCategory,y.value=a.total,d.value=a.perPage,S.value=a.items}),$([w,B],async([t,e],[a,m])=>{if(t===a&&e===m)return;const u=parseInt(s.query.page,10)||1;if(n.value!==u){n.value=u;return}const l=await I(u);f.value=l.asyncCategory,y.value=l.total,d.value=l.perPage,S.value=l.items}),{breadcrumbs:Q,items:S,asyncCategory:f,page:n,total:y,perPage:d,goToPage:t=>{n.value=t,at({query:{...s.query,page:t.toString()}})}}};export{ut as u}; 2//# sourceMappingURL=CAlG6Ail.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.