import{J as p,aa as f,i as D,ab as B,ac as O,K as M,ad as P,ae as E,af as H,f as R,ag as S,B as V,ah as K}from"./DpdQcRr7.js";const j=r=>r==="defer"||r===!1;function F(...r){var g;const c=typeof r[r.length-1]=="string"?r.pop():void 0;typeof r[0]!="string"&&r.unshift(c);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=p(),w=u,C=()=>f.value,b=()=>e.isHydrating?e.payload.data[t]:e.static.data[t];a.server??(a.server=!0),a.default??(a.default=C),a.getCachedData??(a.getCachedData=b),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),h=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(h?d:a.default()),pending:D(!h),error:O(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(j(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,n)=>{try{l(w(e))}catch(y){n(y)}}).then(async l=>{if(o.cancelled)return e._asyncDataPromises[t];let n=l;a.transform&&(n=await a.transform(l)),a.pick&&(n=N(n,a.pick)),e.payload.data[t]=n,s.data.value=n,s.error.value=f.errorValue,s.status.value="success"}).catch(l=>{if(o.cancelled)return e._asyncDataPromises[t];s.error.value=H(l),s.data.value=R(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=()=>z(e,t);const _=()=>s.refresh({_initial:!0}),m=a.server!==!1&&e.payload.serverRendered;{const i=K();if(i&&m&&a.immediate&&!i.sp&&(i.sp=[]),i&&!i._nuxtOnBeforeMountCbs){i._nuxtOnBeforeMountCbs=[];const n=i._nuxtOnBeforeMountCbs;S(()=>{n.forEach(y=>{y()}),n.splice(0,n.length)}),V(()=>n.splice(0,n.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(_):a.immediate&&_();const o=E();if(a.watch){const n=M(a.watch,()=>s.refresh());o&&P(n)}const l=e.hook("app:data:refresh",async n=>{(!n||n.includes(t))&&await s.refresh()});o&&P(l)}const v=Promise.resolve(e._asyncDataPromises[t]).then(()=>s);return Object.assign(v,s),v}function z(r,c){c in r.payload.data&&(r.payload.data[c]=void 0),c in r.payload._errors&&(r.payload._errors[c]=f.errorValue),r._asyncData[c]&&(r._asyncData[c].data.value=void 0,r._asyncData[c].error.value=f.errorValue,r._asyncData[c].pending.value=!1,r._asyncData[c].status.value="idle"),c in r._asyncDataPromises&&(r._asyncDataPromises[c]&&(r._asyncDataPromises[c].cancelled=!0),r._asyncDataPromises[c]=void 0)}function N(r,c){const t={};for(const u of c)t[u]=r[u];return t}export{F as u};
