import{C as e,h as t}from"./cookie-serialize-CgV1qMZJ.js";import{$ as n,Z as r,o as i,ot as a,s as o}from"./implicit-tags-BJP8ZwY0.js";import{i as s,o as c}from"./isr-cache-BYWAvUsA.js";import{o as l,t as u}from"./text-stream-TM9xO6G4.js";function d(e,t,r={}){n(e,{cacheControl:e.get(`Cache-Control`)??``,pendingDynamicCheck:!0,tags:t}),p(e,r)}function f(e,t={}){n(e,{cacheControl:r}),p(e,{...t,preserveMissingCacheState:!0})}function p(n,r={}){let i=n.has(`X-Vinext-Cache`)||n.has(`x-nextjs-cache`);if(r.omitCacheState===!0||r.preserveMissingCacheState===!0&&!i){n.delete(e),n.delete(t);return}o(n,`MISS`)}function m(e){let t=e.revalidateSeconds,n=e.expireSeconds,r=e.requestCacheLife;return r?.revalidate!==void 0&&(t=t===null?r.revalidate:Math.min(t,r.revalidate)),r?.expire!==void 0&&(n=r.expire),t===null||Number.isNaN(t)||t<=0?null:c(t,{expireSeconds:n,staleSeconds:a(r)})}function h(e,t){if(!e.body)return e;let[n,r]=e.body.tee(),a=t.isrHtmlKey(t.cleanPathname),o=t.isrRscKey(t.cleanPathname,null,void 0,t.interceptionContext,t.interceptionId),c=new Headers(e.headers);t.preserveClientResponseHeaders!==!0&&d(c,t.getPageTags(),{omitCacheState:t.omitPendingDynamicCacheState===!0});let f=(async()=>{try{let e=await u(r);if(t.capturedDynamicUsageBeforeContextCleanup?.()===!0||t.consumeDynamicUsage()){t.isrDebug?.(`HTML cache write skipped (dynamic usage during render)`,a);return}let n=m({expireSeconds:t.expireSeconds,requestCacheLife:t.getRequestCacheLife?.(),revalidateSeconds:t.revalidateSeconds});if(!n){t.isrDebug?.(`HTML cache write skipped (no cache policy)`,a);return}let i=t.getPageTags(),c=t.consumeRenderObservationState?.()??l(),d=t.createHtmlRenderObservation?.({cacheTags:i,state:c}),f=t.createRscRenderObservation?.({cacheTags:i,state:c}),p=t.linkHeader,h=[t.isrSet(a,s(e,void 0,200,d,p?{link:p}:void 0),{cacheControl:n,tags:i})];t.capturedRscDataPromise&&h.push(t.capturedRscDataPromise.then(e=>t.isrSet(o,s(``,e,200,f),{cacheControl:n,tags:i}))),await Promise.all(h),t.isrDebug?.(`HTML cache written`,a)}catch(e){console.error(`[vinext] ISR cache write error:`,e)}})();t.waitUntil?.(f);let p=new Response(n,{status:e.status,statusText:e.statusText,headers:c});return i(p.headers,t.linkHeader),p}function g(e,t){_(t);let n=!!t.mountedSlotsHeader;if(t.preserveClientResponseHeaders===!0&&!n)return e;let r=new Headers(e.headers);return n?f(r,{omitCacheState:t.omitPendingDynamicCacheState===!0}):d(r,t.getPageTags(),{omitCacheState:t.omitPendingDynamicCacheState===!0}),new Response(e.body,{status:e.status,statusText:e.statusText,headers:r})}function _(e){let t=e.capturedRscDataPromise;if(!t||e.dynamicUsedDuringBuild||e.mountedSlotsHeader)return!1;let n=e.isrRscKey(e.cleanPathname,null,e.renderMode,e.interceptionContext,e.interceptionId),r=(async()=>{try{let r=await t;if(e.consumeDynamicUsage()){e.isrDebug?.(`RSC cache write skipped (dynamic usage during render)`,n);return}let i=m({expireSeconds:e.expireSeconds,requestCacheLife:e.getRequestCacheLife?.(),revalidateSeconds:e.revalidateSeconds});if(!i){e.isrDebug?.(`RSC cache write skipped (no cache policy)`,n);return}let a=e.getPageTags(),o=e.consumeRenderObservationState?.()??l(),c=e.createRscRenderObservation?.({cacheTags:a,state:o});await e.isrSet(n,s(``,r,200,c),{cacheControl:i,tags:a}),e.isrDebug?.(`RSC cache written`,n)}catch(e){console.error(`[vinext] ISR RSC cache write error:`,e)}})();return e.waitUntil?.(r),!0}export{g as n,_ as r,h as t};