module.exports=[519536,e=>{"use strict";var t=e.i(747909),r=e.i(174017),a=e.i(996250),n=e.i(759756),s=e.i(561916),o=e.i(174677),i=e.i(869741),l=e.i(316795),u=e.i(487718),c=e.i(995169),d=e.i(47587),p=e.i(666012),h=e.i(570101),f=e.i(626937),m=e.i(10372),g=e.i(193695);e.i(52474);var R=e.i(600220),y=e.i(89171),v=e.i(306971),N=e.i(547740);async function E(e){try{let t=await (0,v.default)(e).metadata();if(e.length<512e3&&1280>(t.width||0))return{buffer:e,mimeType:`image/${t.format||"jpeg"}`};return{buffer:await (0,v.default)(e).resize({width:1280,withoutEnlargement:!0}).jpeg({quality:85,mozjpeg:!0}).toBuffer(),mimeType:"image/jpeg"}}catch{return{buffer:e,mimeType:"image/jpeg"}}}function w(e){return!!e&&/[a-zA-Z]/.test(e)}let C=`You are a Bangladeshi National ID Card (NID) OCR expert. Extract information from Bangladeshi NID card images (front side, back side, or both sides).

FIELDS TO EXTRACT:
- nameBn: Full name in Bangla script only — found after label "নাম:" on the card (e.g., "মোঃ আরিফ মিয়া")
- nameEn: Full name in English Latin letters only — found after label "Name:" on the card (e.g., "MD. ARIF MIA")
- father: Father's or husband's name in Bangla script only — found after label "পিতা:" or "স্বামী:" on the card (e.g., "মোঃ জাইদুল হক প্রধান")
- mother: Mother's name in Bangla script only — found after label "মাতা:" on the card (e.g., "মোছাঃ নুরজাহান বেগম")
- nid: NID number digits only, no spaces (e.g., "7814891813") — found after label "ID NO:" or "NID No."
- dob: Date of birth in dd/mm/yyyy format (e.g., "18/07/2002") — found after label "Date of Birth:"

CRITICAL LANGUAGE RULES:
1. nameBn, father, mother must contain ONLY Bangla Unicode script (Bengali characters). NEVER include English/Latin letters in these fields.
   - WRONG: "মোঃ আব্দুল AWAL"
   - CORRECT: "মোঃ আব্দুল আওয়াল"
2. If a Bangla name field is partially unclear, do your best to reconstruct it using only Bangla characters. If it is truly unreadable, return null — do NOT substitute with English letters.
3. IGNORE the MRZ zone (the machine-readable lines at the very bottom containing <<< characters and English transliterations). Never use MRZ data for nameBn, father, or mother fields.
4. nameEn must contain only English/Latin letters.

OTHER RULES:
5. Return ONLY valid JSON, no markdown, no code blocks, no explanation.
6. If a field is not visible or readable, set it to null.
7. For dob, always convert to dd/mm/yyyy format regardless of how it appears on the card (e.g., "18 Jul 2002" → "18/07/2002", "27 Nov 1997" → "27/11/1997").
8. For nid, remove all spaces and dashes, return digits only.
9. If both front and back sides are provided, combine information from both.

Return format:
{"nameBn":"...","nameEn":"...","father":"...","mother":"...","nid":"...","dob":"..."}`;async function b(e,t,r,a){let n,s=await fetch(`${t}?key=${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({contents:[{parts:[{text:C},{inline_data:{mime_type:a,data:r}}]}],generationConfig:{temperature:.1,maxOutputTokens:1024}})});if(!s.ok)return{success:!1,error:"OCR service error",details:await s.text(),status:502};let o=await s.json(),i=o?.candidates?.[0]?.content?.parts?.[0]?.text||"";if(!i)return{success:!1,error:"No response from OCR service",status:500};let l=i.trim();l.startsWith("```")&&(l=l.replace(/^```(?:json)?\n?/,"").replace(/\n?```$/,""));try{n=JSON.parse(l)}catch{return{success:!1,error:"Failed to parse OCR result",raw:i,status:500}}return{success:!0,data:{nameBn:n.nameBn||null,nameEn:n.nameEn||null,father:n.father||null,mother:n.mother||null,nid:n.nid?String(n.nid).replace(/[\s-]/g,""):null,dob:n.dob||null}}}async function O(e){try{let t,r,a,n,{requestToken:s}=await e.json();if(!s)return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify({success:!1,error:"Missing request token. Please encrypt your request first."}))});let o=(0,N.decryptData)(s);if(!o)return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify({success:!1,error:"Invalid or expired request token"}))});try{t=JSON.parse(o)}catch{return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify({success:!1,error:"Failed to parse request parameters"}))})}let{image:i}=t;if(!i)return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify({success:!1,error:"No image provided"}))});if(i.startsWith("data:")){let e=i.match(/^data:([^;]+);base64,(.+)$/);if(!e)return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify({success:!1,error:"Invalid data URI format"}))});a=e[1],n=e[2]}else n=i,a="image/jpeg";let l=Buffer.from(n,"base64"),{buffer:u,mimeType:c}=await E(l);r=u.toString("base64"),a=c;let d="AIzaSyA1LDCUCnYcgIIrKf_XfTZ8MuyIVBOi2c8",p=await b(d,"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent",r,a);if(!p.success){let e={success:!1,error:p.error||"OCR service error"};return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify(e))})}let h=p.data;if(w(h.nameBn)||w(h.father)||w(h.mother)){let e=await b(d,"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",r,a);e.success&&(p=e)}let f={success:!0,data:p.data};return y.NextResponse.json({success:!0,responseToken:(0,N.encryptData)(JSON.stringify(f))})}catch(e){return console.error("NID OCR error:",e),y.NextResponse.json({success:!1,error:"Internal server error",message:e.message},{status:500})}}let T=async()=>new Response(null,{status:204,headers:{"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST,OPTIONS","Access-Control-Allow-Headers":"Authorization, Content-Type, X-Requested-With"}});e.s(["OPTIONS",0,T,"POST",0,O],313245);var A=e.i(313245);let x=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/ocr/nid/route",pathname:"/api/ocr/nid",filename:"route",bundlePath:""},distDir:"_next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/ocr/nid/route.ts",nextConfigOutput:"standalone",userland:A,...{}}),{workAsyncStorage:S,workUnitAsyncStorage:I,serverHooks:D}=x;async function P(e,t,a){a.requestMeta&&(0,n.setRequestMeta)(e,a.requestMeta),x.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let y="/api/ocr/nid/route";y=y.replace(/\/index$/,"")||"/";let v=await x.prepare(e,t,{srcPage:y,multiZoneDraftMode:!1});if(!v)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:N,params:E,nextConfig:w,parsedUrl:C,isDraftMode:b,prerenderManifest:O,routerServerContext:T,isOnDemandRevalidate:A,revalidateOnlyGenerated:S,resolvedPathname:I,clientReferenceManifest:D,serverActionsManifest:P}=v,k=(0,i.normalizeAppPath)(y),B=!!(O.dynamicRoutes[k]||O.routes[I]),_=async()=>((null==T?void 0:T.render404)?await T.render404(e,t,C,!1):t.end("This page could not be found"),null);if(B&&!b){let e=!!O.routes[I],t=O.dynamicRoutes[k];if(t&&!1===t.fallback&&!e){if(w.adapterPath)return await _();throw new g.NoFallbackError}}let j=null;!B||x.isDev||b||(j="/index"===(j=I)?"/":j);let q=!0===x.isDev||!B,M=B&&!q;P&&D&&(0,o.setManifestsSingleton)({page:y,clientReferenceManifest:D,serverActionsManifest:P});let U=e.method||"GET",H=(0,s.getTracer)(),F=H.getActiveScopeSpan(),L=!!(null==T?void 0:T.isWrappedByNextServer),$=!!(0,n.getRequestMeta)(e,"minimalMode"),J=(0,n.getRequestMeta)(e,"incrementalCache")||await x.getIncrementalCache(e,w,O,$);null==J||J.resetRequestCache(),globalThis.__incrementalCache=J;let K={params:E,previewProps:O.preview,renderOpts:{experimental:{authInterrupts:!!w.experimental.authInterrupts},cacheComponents:!!w.cacheComponents,supportsDynamicResponse:q,incrementalCache:J,cacheLifeProfiles:w.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,n)=>x.onRequestError(e,t,a,n,T)},sharedContext:{buildId:N}},W=new l.NodeNextRequest(e),z=new l.NodeNextResponse(t),G=u.NextRequestAdapter.fromNodeNextRequest(W,(0,u.signalFromNodeResponse)(t));try{let n,o=async e=>x.handle(G,K).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=H.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==c.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${U} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",a),n.updateName(t))}else e.updateName(`${U} ${y}`)}),i=async n=>{var s,i;let l=async({previousCacheEntry:r})=>{try{if(!$&&A&&S&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let s=await o(n);e.fetchMetrics=K.renderOpts.fetchMetrics;let i=K.renderOpts.pendingWaitUntil;i&&a.waitUntil&&(a.waitUntil(i),i=void 0);let l=K.renderOpts.collectedTags;if(!B)return await (0,p.sendResponse)(W,z,s,K.renderOpts.pendingWaitUntil),null;{let e=await s.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(s.headers);l&&(t[m.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==K.renderOpts.collectedRevalidate&&!(K.renderOpts.collectedRevalidate>=m.INFINITE_CACHE)&&K.renderOpts.collectedRevalidate,a=void 0===K.renderOpts.collectedExpire||K.renderOpts.collectedExpire>=m.INFINITE_CACHE?void 0:K.renderOpts.collectedExpire;return{value:{kind:R.CachedRouteKind.APP_ROUTE,status:s.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await x.onRequestError(e,t,{routerKind:"App Router",routePath:y,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:A})},!1,T),t}},u=await x.handleResponse({req:e,nextConfig:w,cacheKey:j,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:O,isRoutePPREnabled:!1,isOnDemandRevalidate:A,revalidateOnlyGenerated:S,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:$});if(!B)return null;if((null==u||null==(s=u.value)?void 0:s.kind)!==R.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(i=u.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});$||t.setHeader("x-nextjs-cache",A?"REVALIDATED":u.isMiss?"MISS":u.isStale?"STALE":"HIT"),b&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let c=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return $&&B||c.delete(m.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||c.get("Cache-Control")||c.set("Cache-Control",(0,f.getCacheControlHeader)(u.cacheControl)),await (0,p.sendResponse)(W,z,new Response(u.value.body,{headers:c,status:u.value.status||200})),null};L&&F?await i(F):(n=H.getActiveScopeSpan(),await H.withPropagatedContext(e.headers,()=>H.trace(c.BaseServerSpan.handleRequest,{spanName:`${U} ${y}`,kind:s.SpanKind.SERVER,attributes:{"http.method":U,"http.target":e.url}},i),void 0,!L))}catch(t){if(t instanceof g.NoFallbackError||await x.onRequestError(e,t,{routerKind:"App Router",routePath:k,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:M,isOnDemandRevalidate:A})},!1,T),B)throw t;return await (0,p.sendResponse)(W,z,new Response(null,{status:500})),null}}e.s(["handler",0,P,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:S,workUnitAsyncStorage:I})},"routeModule",0,x,"serverHooks",0,D,"workAsyncStorage",0,S,"workUnitAsyncStorage",0,I],519536)}];

//# sourceMappingURL=node_modules_next_dist_esm_build_templates_app-route_0r~ries.js.map