import{r as e}from"./http-error-responses-DkXnydOV.js";import{t}from"./app-prerender-static-params-DvxfrrL2.js";var n={"content-type":`application/json`};async function r(e,t){return t.pathname===`/__vinext/prerender/static-params`?a(e,t):t.pathname===`/__vinext/prerender/pages-static-paths`?t.loadPagesRoutes?o(e,t):null:t.pathname===`/__vinext/prerender/metadata-routes`&&t.getMetadataRoutePaths?i(t):null}async function i(t){if(!s(t))return e();try{return c(await t.getMetadataRoutePaths?.())}catch(e){return c({error:String(e)},500)}}async function a(n,r){if(!s(r))return e();let i=new URL(n.url),a=i.searchParams.get(`pattern`);if(!a)return new Response(`missing pattern`,{status:400});let o=r.staticParamsMap[a];if(typeof o!=`function`)return l();try{return c(await t({fn:o,params:u(i.searchParams.get(`parentParams`)),pattern:a,rootParamNamesByPattern:r.rootParamNamesByPattern??{}}))}catch(e){return c({error:String(e)},500)}}async function o(t,n){if(!s(n))return e();let r=new URL(t.url),i=r.searchParams.get(`pattern`);if(!i)return new Response(`missing pattern`,{status:400});try{let e=f(await n.loadPagesRoutes?.(),i)?.module?.getStaticPaths;return typeof e==`function`?c(await e({locales:d(r.searchParams.get(`locales`)),defaultLocale:r.searchParams.get(`defaultLocale`)??``})):l()}catch(e){return c({error:String(e)},500)}}function s(e){return e.isPrerenderEnabled?.()??!1}function c(e,t=200){return new Response(JSON.stringify(e),{headers:n,status:t})}function l(){return new Response(`null`,{headers:n,status:200})}function u(e){if(!e)return{};let t=JSON.parse(e);if(!m(t))return{};let n={};for(let[e,r]of Object.entries(t))(typeof r==`string`||r===void 0||h(r))&&(n[e]=r);return n}function d(e){if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function f(e,t){if(Array.isArray(e)){for(let n of e)if(p(n)&&n.pattern===t)return n}}function p(e){return!m(e)||typeof e.pattern!=`string`?!1:e.module===void 0?!0:m(e.module)?e.module.getStaticPaths===void 0||typeof e.module.getStaticPaths==`function`:!1}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}export{r as handleAppPrerenderEndpoint};