(()=>{var e={};e.id=2058,e.ids=[2058],e.modules={10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},80388:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>R,routeModule:()=>c,serverHooks:()=>f,workAsyncStorage:()=>l,workUnitAsyncStorage:()=>E});var s={};r.r(s),r.d(s,{GET:()=>d,runtime:()=>p});var n=r(42706),o=r(28203),i=r(45994),a=r(39187),u=r(8089);let p="nodejs";async function d(e,{params:t}){let r=t.id;if(!r)return a.NextResponse.json({error:"Test ID is required"},{status:400});try{let t;let{db:s,auth:n,storage:o}=(0,u.j)(),i=(e.headers.get("authorization")||"").match(/^Bearer\s+(.+)$/i);if(!i)return a.NextResponse.json({error:"Missing Authorization Bearer token"},{status:401});try{t=await n.verifyIdToken(i[1])}catch(e){return a.NextResponse.json({error:`Invalid auth token: ${e.message}`},{status:401})}let p=await s.doc(`tests/${r}`).get();if(!p.exists)return a.NextResponse.json({error:"Test not found"},{status:404});let d=p.data(),c=(d?.pdfPath||"").trim();if(!c)return a.NextResponse.json({error:"pdfPath not found in test"},{status:404});let l=await s.doc(`users/${t.uid}`).get(),E=l.exists?l.data()?.orgId:null;if(!E||E!==d.orgId)return a.NextResponse.json({error:"Forbidden (org mismatch)"},{status:403});let f=o.bucket(),R=function(e){let t=(e||"").trim();if(t.startsWith("gs://")){let e=t.slice(5),r=e.indexOf("/");r>=0&&(t=e.slice(r+1))}if(t.startsWith("http://")||t.startsWith("https://"))try{let e=new URL(t).pathname.match(/\/o\/(.+)$/);e?.[1]&&(t=decodeURIComponent(e[1]))}catch{}t.startsWith("/")&&(t=t.slice(1));let r=t.indexOf("?");return r>=0&&(t=t.slice(0,r)),t}(c),h=f.file(R),[g]=await h.exists();if(!g)return a.NextResponse.json({error:`PDF not found: ${R}`},{status:404});let[_]=await h.download();return new a.NextResponse(new Uint8Array(_),{status:200,headers:{"Content-Type":"application/pdf","Cache-Control":"no-store"}})}catch(e){return console.error("[/api/tests/[id]/pdf] error:",e),a.NextResponse.json({error:`Internal Server Error: ${e?.message??String(e)}`},{status:500})}}let c=new n.AppRouteRouteModule({definition:{kind:o.RouteKind.APP_ROUTE,page:"/api/tests/[id]/pdf/route",pathname:"/api/tests/[id]/pdf",filename:"route",bundlePath:"app/api/tests/[id]/pdf/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\tests\\[id]\\pdf\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:l,workUnitAsyncStorage:E,serverHooks:f}=c;function R(){return(0,i.patchFetch)({workAsyncStorage:l,workUnitAsyncStorage:E})}},96487:()=>{},78335:()=>{},8089:(e,t,r)=>{"use strict";r.d(t,{j:()=>o});let s=require("firebase-admin");function n(e){return(process.env[e]||"").trim()}function o(){if(s.apps.length){let e=s.app();return{db:s.firestore(e),auth:s.auth(e),storage:s.storage(e),app:e}}let e=function(){let e=process.env.FIREBASE_CONFIG||"";if(!e)return{};try{return JSON.parse(e)||{}}catch{return{}}}(),t=n("FIREBASE_PROJECT_ID")||n("NEXT_PUBLIC_FIREBASE_PROJECT_ID")||n("GOOGLE_CLOUD_PROJECT")||n("GCLOUD_PROJECT")||String(e.projectId||"").trim(),r=n("FIREBASE_STORAGE_BUCKET")||n("NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET")||String(e.storageBucket||"").trim(),o=n("FIREBASE_CLIENT_EMAIL"),i=(process.env.FIREBASE_PRIVATE_KEY||"").replace(/\\n/g,"\n").replace(/^"|"$/g,"");if(!t)throw Error("Missing projectId env (FIREBASE_PROJECT_ID or NEXT_PUBLIC_FIREBASE_PROJECT_ID)");if(!r)throw Error("Missing storage bucket env (FIREBASE_STORAGE_BUCKET or NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET)");let a=!!(o&&i),u=s.initializeApp({credential:a?s.credential.cert({projectId:t,clientEmail:o,privateKey:i}):s.credential.applicationDefault(),projectId:t,storageBucket:r});return{db:s.firestore(u),auth:s.auth(u),storage:s.storage(u),app:u}}}};var t=require("../../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[1989,5452],()=>r(80388));module.exports=s})();