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