import{aG as O,aH as f,j as D,aI as B,aJ as M,k as H,aK as P,aL as E,aM as R,g as w,aN as S,aO as V,a9 as j}from"./dVzHJMF1.js";const K=r=>r==="defer"||r===!1;function T(...r){var g;const n=typeof r[r.length-1]=="string"?r.pop():void 0;typeof r[0]!="string"&&r.unshift(n);let[t,u,a={}]=r;if(typeof t!="string")throw new TypeError("[nuxt] [asyncData] key must be a string.");if(typeof u!="function")throw new TypeError("[nuxt] [asyncData] handler must be a function.");const e=O(),C=u,b=()=>f.value,p=()=>e.isHydrating?e.payload.data[t]:e.static.data[t];a.server??(a.server=!0),a.default??(a.default=b),a.getCachedData??(a.getCachedData=p),a.lazy??(a.lazy=!1),a.immediate??(a.immediate=!0),a.deep??(a.deep=f.deep),a.dedupe??(a.dedupe="cancel");const d=a.getCachedData(t,e),_=d!=null;if(!e._asyncData[t]||!a.immediate){(g=e.payload._errors)[t]??(g[t]=f.errorValue);const i=a.deep?D:B;e._asyncData[t]={data:i(_?d:a.default()),pending:D(!_),error:M(e.payload._errors,t),status:D("idle"),_default:a.default}}const s={...e._asyncData[t]};delete s._default,s.refresh=s.execute=(i={})=>{if(e._asyncDataPromises[t]){if(K(i.dedupe??a.dedupe))return e._asyncDataPromises[t];e._asyncDataPromises[t].cancelled=!0}if(i._initial||e.isHydrating&&i._initial!==!1){const l=i._initial?d:a.getCachedData(t,e);if(l!=null)return Promise.resolve(l)}s.pending.value=!0,s.status.value="pending";const o=new Promise((l,c)=>{try{l(C(e))}catch(y){c(y)}}).then(async l=>{if(o.cancelled)return e._asyncDataPromises[t];let c=l;a.transform&&(c=await a.transform(l)),a.pick&&(c=z(c,a.pick)),e.payload.data[t]=c,s.data.value=c,s.error.value=f.errorValue,s.status.value="success"}).catch(l=>{if(o.cancelled)return e._asyncDataPromises[t];s.error.value=R(l),s.data.value=w(a.default()),s.status.value="error"}).finally(()=>{o.cancelled||(s.pending.value=!1,delete e._asyncDataPromises[t])});return e._asyncDataPromises[t]=o,e._asyncDataPromises[t]},s.clear=()=>N(e,t);const h=()=>s.refresh({_initial:!0}),m=a.server!==!1&&e.payload.serverRendered;{const i=S();if(i&&m&&a.immediate&&!i.sp&&(i.sp=[]),i&&!i._nuxtOnBeforeMountCbs){i._nuxtOnBeforeMountCbs=[];const c=i._nuxtOnBeforeMountCbs;V(()=>{c.forEach(y=>{y()}),c.splice(0,c.length)}),j(()=>c.splice(0,c.length))}m&&e.isHydrating&&(s.error.value||d!=null)?(s.pending.value=!1,s.status.value=s.error.value?"error":"success"):i&&(e.payload.serverRendered&&e.isHydrating||a.lazy)&&a.immediate?i._nuxtOnBeforeMountCbs.push(h):a.immediate&&h();const o=E();if(a.watch){const c=H(a.watch,()=>s.refresh());o&&P(c)}const l=e.hook("app:data:refresh",async c=>{(!c||c.includes(t))&&await s.refresh()});o&&P(l)}const v=Promise.resolve(e._asyncDataPromises[t]).then(()=>s);return Object.assign(v,s),v}function N(r,n){n in r.payload.data&&(r.payload.data[n]=void 0),n in r.payload._errors&&(r.payload._errors[n]=f.errorValue),r._asyncData[n]&&(r._asyncData[n].data.value=w(r._asyncData[n]._default()),r._asyncData[n].error.value=f.errorValue,r._asyncData[n].pending.value=!1,r._asyncData[n].status.value="idle"),n in r._asyncDataPromises&&(r._asyncDataPromises[n]&&(r._asyncDataPromises[n].cancelled=!0),r._asyncDataPromises[n]=void 0)}function z(r,n){const t={};for(const u of n)t[u]=r[u];return t}export{T as u};
