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