module.exports=[67931,e=>{"use strict";var t=e.i(47909),a=e.i(74017),r=e.i(96250),n=e.i(59756),i=e.i(61916),o=e.i(74677),s=e.i(69741),l=e.i(16795),d=e.i(87718),u=e.i(95169),p=e.i(47587),c=e.i(66012),h=e.i(70101),m=e.i(26937),f=e.i(10372),N=e.i(93695);e.i(52474);var R=e.i(220),E=e.i(89171),g=e.i(98043),v=e.i(50737);async function y(e){let t={rawInput:"",afterBengaliConversion:"",normalizedQuery:"",matchedFormat:null,parsedValues:null,dateCondition:null};try{let a=await e.json(),r=a.name||"",n=a.dateOfBirth||"",i=a.upazila||"",o=a.union||a.unionWard||"",s=parseInt(a.page||"1"),l=parseInt(a.limit||"20"),d=(s-1)*l;if(!r||!n||!i||!o){let e=[];return r||e.push("নাম"),n||e.push("জন্ম তারিখ"),i||e.push("এলাকা"),o||e.push("ওয়ার্ড/ইউনিয়ন"),E.NextResponse.json({data:[],total:0,page:s,limit:l,totalPages:0,message:`অনুগ্রহ করে ${e.join(", ")} দিন`,_debug:t})}let u=function(e,t){let a;t.rawInput=e;let r=e.trim();["০","১","২","৩","৪","৫","৬","৭","৮","৯"].forEach((e,t)=>{r=r.replace(RegExp(e,"g"),t.toString())}),t.afterBengaliConversion=r;let n=(a=e.trim(),["০","১","২","৩","৪","৫","৬","৭","৮","৯"].forEach((e,t)=>{a=a.replace(RegExp(e,"g"),t.toString())}),a=(a=(a=a.replace(/[^\d]+/g,"/")).replace(/\/+/g,"/")).replace(/^\/|\/$/g,""));if(t.normalizedQuery=n,/^\d{4}$/.test(n)){let e=parseInt(n);return t.matchedFormat="YYYY (year only)",t.parsedValues={year:e},t.dateCondition=`YEAR(dateOfBirth) = ${e}`,{type:"year",year:e}}let i=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);if(i){let[,e,a,r]=i,n=parseInt(e),o=parseInt(a),s=parseInt(r);if(t.matchedFormat="DD/MM/YYYY",t.parsedValues={day:n,month:o,year:s},o>=1&&o<=12&&n>=1&&n<=31){let e=`${s}-${String(o).padStart(2,"0")}-${String(n).padStart(2,"0")}`;return t.dateCondition=`DATE(dateOfBirth) = '${e}'`,{type:"exact",dateStr:e}}}let o=n.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/);if(o){let[,e,a,r]=o,n=parseInt(e),i=parseInt(a),s=parseInt(r);if(t.matchedFormat="YYYY/MM/DD (ISO)",t.parsedValues={day:s,month:i,year:n},i>=1&&i<=12&&s>=1&&s<=31){let e=`${n}-${String(i).padStart(2,"0")}-${String(s).padStart(2,"0")}`;return t.dateCondition=`DATE(dateOfBirth) = '${e}'`,{type:"exact",dateStr:e}}}let s=n.match(/^(\d{1,2})\/(\d{4})$/);if(s){let[,e,a]=s,r=parseInt(a),n=parseInt(e);if(t.matchedFormat="MM/YYYY (month+year)",t.parsedValues={month:n,year:r},n>=1&&n<=12)return t.dateCondition=`YEAR(dateOfBirth) = ${r} AND MONTH(dateOfBirth) = ${n}`,{type:"month",year:r,month:n}}let l=n.match(/\d+/g);if(l&&3===l.length){let e=parseInt(l[0]),a=parseInt(l[1]),r=parseInt(l[2]);if(t.matchedFormat="Fallback DD/MM/YYYY (from digits)",t.parsedValues={day:e,month:a,year:r},r>=1900&&r<=2100&&a>=1&&a<=12&&e>=1&&e<=31){let n=`${r}-${String(a).padStart(2,"0")}-${String(e).padStart(2,"0")}`;return t.dateCondition=`DATE(dateOfBirth) = '${n}'`,{type:"exact",dateStr:n}}}else if(l&&2===l.length){let e=parseInt(l[0]),a=parseInt(l[1]);if(t.matchedFormat="Fallback MM/YYYY (from digits)",t.parsedValues={month:e,year:a},a>=1900&&a<=2100&&e>=1&&e<=12)return t.dateCondition=`YEAR(dateOfBirth) = ${a} AND MONTH(dateOfBirth) = ${e}`,{type:"month",year:a,month:e}}return t.matchedFormat="NONE - no pattern matched",t.parsedValues=null,t.dateCondition=null,null}(n,t);if(!u)return E.NextResponse.json({data:[],total:0,page:s,limit:l,totalPages:0,message:"জন্ম তারিখের ফরম্যাট সঠিক নয়",_debug:t});let p=[],c=[];r.trim().split(/\s+/).filter(e=>e.length>0).forEach(e=>{let t=(0,v.generateSearchPatterns)(e);if(1===t.length)p.push("v.name LIKE ?"),c.push(`%${t[0]}%`);else{let e=t.map(()=>"v.name LIKE ?").join(" OR ");p.push(`(${e})`),t.forEach(e=>c.push(`%${e}%`))}}),"exact"===u.type?(p.push("DATE(v.dateOfBirth) = ?"),c.push(u.dateStr)):"month"===u.type?(p.push("YEAR(v.dateOfBirth) = ? AND MONTH(v.dateOfBirth) = ?"),c.push(u.year,u.month)):"year"===u.type&&(p.push("YEAR(v.dateOfBirth) = ?"),c.push(u.year));let h=(0,v.generateSearchPatterns)(i);if(1===h.length)p.push("a.upazila LIKE ?"),c.push(`%${h[0]}%`);else{let e=h.map(()=>"a.upazila LIKE ?").join(" OR ");p.push(`(${e})`),h.forEach(e=>c.push(`%${e}%`))}let m=(0,v.generateSearchPatterns)(o);if(1===m.length)p.push("a.unionWard LIKE ?"),c.push(`%${m[0]}%`);else{let e=m.map(()=>"a.unionWard LIKE ?").join(" OR ");p.push(`(${e})`),m.forEach(e=>c.push(`%${e}%`))}let f=p.join(" AND "),N=`
      SELECT COUNT(*) as total
      FROM Voter v
      INNER JOIN VoterList l ON v.listId = l.id
      INNER JOIN VoterArea a ON l.areaId = a.id
      WHERE ${f}
    `,R=`
      SELECT
        v.id, v.entryNumber, v.pageNumber, v.voterNumber, v.name,
        v.fatherName, v.motherName, v.occupation, v.dateOfBirth,
        v.address, v.mobileNumber, v.listId,
        l.id as list_id, l.fileName as list_fileName, l.listType as list_listType,
        l.totalVoters as list_totalVoters, l.areaId as list_areaId,
        a.id as area_id, a.areaCode as area_areaCode, a.areaName as area_areaName,
        a.district as area_district, a.upazila as area_upazila,
        a.cityCorporation as area_cityCorporation, a.unionWard as area_unionWard,
        a.wardNumberUnion as area_wardNumberUnion, a.postOffice as area_postOffice
      FROM Voter v
      INNER JOIN VoterList l ON v.listId = l.id
      INNER JOIN VoterArea a ON l.areaId = a.id
      WHERE ${f}
      ORDER BY v.entryNumber ASC
      LIMIT ? OFFSET ?
    `,y=await g.default.$queryRawUnsafe(N,...c),O=Number(y[0].total),I=(await g.default.$queryRawUnsafe(R,...c,l,d)).map(e=>({id:e.id,entryNumber:e.entryNumber,pageNumber:e.pageNumber,voterNumber:e.voterNumber,name:e.name,fatherName:e.fatherName,motherName:e.motherName,occupation:e.occupation,dateOfBirth:e.dateOfBirth,address:e.address,mobileNumber:e.mobileNumber,listId:e.listId,list:{id:e.list_id,fileName:e.list_fileName,listType:e.list_listType,totalVoters:e.list_totalVoters,areaId:e.list_areaId,area:{id:e.area_id,areaCode:e.area_areaCode,areaName:e.area_areaName,district:e.area_district,upazila:e.area_upazila,cityCorporation:e.area_cityCorporation,unionWard:e.area_unionWard,wardNumberUnion:e.area_wardNumberUnion,postOffice:e.area_postOffice}}}));return E.NextResponse.json({data:I,total:O,page:s,limit:l,totalPages:Math.ceil(O/l),_debug:t})}catch(e){return console.error("Error in public search:",e),E.NextResponse.json({error:"সার্চ করতে সমস্যা হয়েছে",_debug:t},{status:500})}}e.s(["POST",()=>y],72603);var O=e.i(72603);let I=new t.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/public/search/route",pathname:"/api/public/search",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/public/search/route.ts",nextConfigOutput:"standalone",userland:O}),{workAsyncStorage:C,workUnitAsyncStorage:b,serverHooks:_}=I;function w(){return(0,r.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:b})}async function A(e,t,r){I.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let E="/api/public/search/route";E=E.replace(/\/index$/,"")||"/";let g=await I.prepare(e,t,{srcPage:E,multiZoneDraftMode:!1});if(!g)return t.statusCode=400,t.end("Bad Request"),null==r.waitUntil||r.waitUntil.call(r,Promise.resolve()),null;let{buildId:v,params:y,nextConfig:O,parsedUrl:C,isDraftMode:b,prerenderManifest:_,routerServerContext:w,isOnDemandRevalidate:A,revalidateOnlyGenerated:$,resolvedPathname:S,clientReferenceManifest:x,serverActionsManifest:T}=g,P=(0,s.normalizeAppPath)(E),Y=!!(_.dynamicRoutes[P]||_.routes[S]),M=async()=>((null==w?void 0:w.render404)?await w.render404(e,t,C,!1):t.end("This page could not be found"),null);if(Y&&!b){let e=!!_.routes[S],t=_.dynamicRoutes[P];if(t&&!1===t.fallback&&!e){if(O.experimental.adapterPath)return await M();throw new N.NoFallbackError}}let D=null;!Y||I.isDev||b||(D="/index"===(D=S)?"/":D);let B=!0===I.isDev||!Y,U=Y&&!B;T&&x&&(0,o.setManifestsSingleton)({page:E,clientReferenceManifest:x,serverActionsManifest:T});let F=e.method||"GET",H=(0,i.getTracer)(),V=H.getActiveScopeSpan(),j={params:y,prerenderManifest:_,renderOpts:{experimental:{authInterrupts:!!O.experimental.authInterrupts},cacheComponents:!!O.cacheComponents,supportsDynamicResponse:B,incrementalCache:(0,n.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:O.cacheLife,waitUntil:r.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,a,r,n)=>I.onRequestError(e,t,r,n,w)},sharedContext:{buildId:v}},q=new l.NodeNextRequest(e),L=new l.NodeNextResponse(t),k=d.NextRequestAdapter.fromNodeNextRequest(q,(0,d.signalFromNodeResponse)(t));try{let o=async e=>I.handle(k,j).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let a=H.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let r=a.get("next.route");if(r){let t=`${F} ${r}`;e.setAttributes({"next.route":r,"http.route":r,"next.span_name":t}),e.updateName(t)}else e.updateName(`${F} ${E}`)}),s=!!(0,n.getRequestMeta)(e,"minimalMode"),l=async n=>{var i,l;let d=async({previousCacheEntry:a})=>{try{if(!s&&A&&$&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let i=await o(n);e.fetchMetrics=j.renderOpts.fetchMetrics;let l=j.renderOpts.pendingWaitUntil;l&&r.waitUntil&&(r.waitUntil(l),l=void 0);let d=j.renderOpts.collectedTags;if(!Y)return await (0,c.sendResponse)(q,L,i,j.renderOpts.pendingWaitUntil),null;{let e=await i.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(i.headers);d&&(t[f.NEXT_CACHE_TAGS_HEADER]=d),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let a=void 0!==j.renderOpts.collectedRevalidate&&!(j.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&j.renderOpts.collectedRevalidate,r=void 0===j.renderOpts.collectedExpire||j.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:j.renderOpts.collectedExpire;return{value:{kind:R.CachedRouteKind.APP_ROUTE,status:i.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:a,expire:r}}}}catch(t){throw(null==a?void 0:a.isStale)&&await I.onRequestError(e,t,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,p.getRevalidateReason)({isStaticGeneration:U,isOnDemandRevalidate:A})},!1,w),t}},u=await I.handleResponse({req:e,nextConfig:O,cacheKey:D,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:_,isRoutePPREnabled:!1,isOnDemandRevalidate:A,revalidateOnlyGenerated:$,responseGenerator:d,waitUntil:r.waitUntil,isMinimalMode:s});if(!Y)return null;if((null==u||null==(i=u.value)?void 0:i.kind)!==R.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==u||null==(l=u.value)?void 0:l.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});s||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 N=(0,h.fromNodeOutgoingHttpHeaders)(u.value.headers);return s&&Y||N.delete(f.NEXT_CACHE_TAGS_HEADER),!u.cacheControl||t.getHeader("Cache-Control")||N.get("Cache-Control")||N.set("Cache-Control",(0,m.getCacheControlHeader)(u.cacheControl)),await (0,c.sendResponse)(q,L,new Response(u.value.body,{headers:N,status:u.value.status||200})),null};V?await l(V):await H.withPropagatedContext(e.headers,()=>H.trace(u.BaseServerSpan.handleRequest,{spanName:`${F} ${E}`,kind:i.SpanKind.SERVER,attributes:{"http.method":F,"http.target":e.url}},l))}catch(t){if(t instanceof N.NoFallbackError||await I.onRequestError(e,t,{routerKind:"App Router",routePath:P,routeType:"route",revalidateReason:(0,p.getRevalidateReason)({isStaticGeneration:U,isOnDemandRevalidate:A})},!1,w),Y)throw t;return await (0,c.sendResponse)(q,L,new Response(null,{status:500})),null}}e.s(["handler",()=>A,"patchFetch",()=>w,"routeModule",()=>I,"serverHooks",()=>_,"workAsyncStorage",()=>C,"workUnitAsyncStorage",()=>b],67931)}];

//# sourceMappingURL=node_modules_next_dist_esm_build_templates_app-route_afdb988e.js.map