module.exports=[254799,(a,b,c)=>{b.exports=a.x("crypto",()=>require("crypto"))},522734,(a,b,c)=>{b.exports=a.x("fs",()=>require("fs"))},446786,(a,b,c)=>{b.exports=a.x("os",()=>require("os"))},688947,(a,b,c)=>{b.exports=a.x("stream",()=>require("stream"))},504446,(a,b,c)=>{b.exports=a.x("net",()=>require("net"))},755004,(a,b,c)=>{b.exports=a.x("tls",()=>require("tls"))},60438,(a,b,c)=>{b.exports=a.x("perf_hooks",()=>require("perf_hooks"))},847066,a=>{"use strict";var b=a.i(345146);a.i(384909),a.s(["getSessionController",()=>b.getSessionController,"logoutController",()=>b.logoutController])},25256,a=>{"use strict";var b=a.i(137936),c=a.i(594758),d=a.i(93321),e=a.i(530385),f=a.i(844037),g=a.i(231670);async function h(a){return{success:!0,statusCode:200,message:"UDC তালিকা লোড হয়েছে",data:{elevations:await c.db.select({id:f.udcElevations.id,entrepreneurId:f.udcElevations.entrepreneurId,entrepreneurName:g.users.name,entrepreneurNameBn:g.users.name_bn,entrepreneurPhone:g.users.phone,canManageNagorik:f.udcElevations.canManageNagorik,canManageSonod:f.udcElevations.canManageSonod,canApproveSonod:f.udcElevations.canApproveSonod,status:f.udcElevations.status,division:f.udcElevations.division,district:f.udcElevations.district,upazila:f.udcElevations.upazila,union:f.udcElevations.union,grantedBy:f.udcElevations.grantedBy,createdAt:f.udcElevations.created_at,revokedAt:f.udcElevations.revokedAt,revokedReason:f.udcElevations.revokedReason}).from(f.udcElevations).innerJoin(g.users,(0,d.eq)(f.udcElevations.entrepreneurId,g.users.id)).where((0,d.eq)(f.udcElevations.grantedBy,a)).orderBy((0,e.desc)(f.udcElevations.created_at))}}}async function i(a,b){let e=await c.db.select({division:g.users.division,district:g.users.district,upazila:g.users.upazila,union:g.users.union}).from(g.users).where((0,d.eq)(g.users.id,a)).limit(1);if(0===e.length)return{success:!1,statusCode:404,message:"অফিস ব্যবহারকারী পাওয়া যায়নি"};let h=await c.db.select({id:g.users.id,role:g.users.role}).from(g.users).where((0,d.eq)(g.users.phone,b.phone)).limit(1);if(0===h.length||"entrepreneur"!==h[0].role)return{success:!1,statusCode:404,message:"এই মোবাইল নম্বরে কোনো উদ্যোক্তা পাওয়া যায়নি"};let i=h[0].id;if((await c.db.select().from(f.udcElevations).where((0,d.and)((0,d.eq)(f.udcElevations.entrepreneurId,i),(0,d.eq)(f.udcElevations.grantedBy,a),(0,d.eq)(f.udcElevations.status,"active"))).limit(1)).length>0)return{success:!1,statusCode:400,message:"এই উদ্যোক্তা বর্তমানে সক্রিয় আছেন"};try{let d=await c.db.insert(f.udcElevations).values({entrepreneurId:i,grantedBy:a,division:e[0].division,district:e[0].district,upazila:e[0].upazila,union:e[0].union,canManageNagorik:b.canManageNagorik??!0,canManageSonod:b.canManageSonod??!0,canApproveSonod:b.canApproveSonod??!1,status:"active"}).returning();return{success:!0,statusCode:201,message:"UDC সফলভাবে উন্নত করা হয়েছে",data:{elevation:d[0]}}}catch(a){return console.error("Error creating UDC elevation:",a),{success:!1,statusCode:500,message:a.message||"UDC উন্নত করতে ব্যর্থ"}}}async function j(a,b,e){return 0===(await c.db.select().from(f.udcElevations).where((0,d.and)((0,d.eq)(f.udcElevations.id,a),(0,d.eq)(f.udcElevations.grantedBy,b))).limit(1)).length?{success:!1,statusCode:404,message:"UDC উন্নতি পাওয়া যায়নি"}:(await c.db.update(f.udcElevations).set({status:"revoked",revokedAt:new Date,revokedReason:e||null,updated_at:new Date}).where((0,d.eq)(f.udcElevations.id,a)),{success:!0,statusCode:200,message:"UDC সফলভাবে বাতিল করা হয়েছে"})}async function k(a){let b=await c.db.select().from(f.udcElevations).where((0,d.and)((0,d.eq)(f.udcElevations.entrepreneurId,a),(0,d.eq)(f.udcElevations.status,"active"))).limit(1);return 0===b.length?{canManageNagorik:!1,canManageSonod:!1,canApproveSonod:!1}:{canManageNagorik:b[0].canManageNagorik,canManageSonod:b[0].canManageSonod,canApproveSonod:b[0].canApproveSonod}}(0,a.i(713095).ensureServerEntryExports)([h,i,j,k]),(0,b.registerServerReference)(h,"4024ffdab0f6dc96e99c0091263646fa506c27152c",null),(0,b.registerServerReference)(i,"60d2663b5ffda76ff09eaba3cded7243eb4b40360b",null),(0,b.registerServerReference)(j,"7011239bf1cb10965f3ad9395e3f1880798804904f",null),(0,b.registerServerReference)(k,"4078ca721cf0ea6bf2bb83776743d0be1ccb4804e8",null),a.s(["checkUdcPermissions",0,k])},258261,a=>{"use strict";a.i(494415),a.i(163227);var b=a.i(351674);a.s(["count",0,function(a){return b.sql`count(${a||b.sql.raw("*")})`.mapWith(Number)}])},109242,a=>{"use strict";var b=a.i(847066),c=a.i(25256),d=a.i(137936),e=a.i(594758);a.i(444718);var f=a.i(231670),g=a.i(542548),h=a.i(349974),i=a.i(93321),j=a.i(258261),k=a.i(351674),l=a.i(530385),m=a.i(713095);async function n(){try{let a=new Date;a.setHours(0,0,0,0);let b=new Date(a);b.setDate(b.getDate()+1);let c=new Date(a);c.setDate(c.getDate()-1);let d=new Date;d.setMonth(d.getMonth()-6);let[m,n,o,p]=await Promise.all([e.db.execute(k.sql`
        WITH app_stats AS (
          SELECT
            COUNT(*) as total,
            COUNT(*) FILTER (WHERE application_type IN ('birth_registration', 'death_registration')) as new_apps,
            COUNT(*) FILTER (WHERE application_type IN ('birth_correction', 'death_correction')) as correction_apps,
            COUNT(*) FILTER (WHERE application_type = 'birth_registration') as birth_new,
            COUNT(*) FILTER (WHERE application_type = 'birth_correction') as birth_correction,
            COUNT(*) FILTER (WHERE application_type = 'death_registration') as death_new,
            COUNT(*) FILTER (WHERE application_type = 'death_correction') as death_correction,
            COUNT(*) FILTER (WHERE submitted_at >= ${a.toISOString()} AND submitted_at < ${b.toISOString()}) as today_count,
            COUNT(*) FILTER (WHERE submitted_at >= ${c.toISOString()} AND submitted_at < ${a.toISOString()}) as yesterday_count,
            COUNT(*) FILTER (WHERE source = 'web') as web_count,
            COUNT(*) FILTER (WHERE source = 'app') as app_count,
            COUNT(*) FILTER (WHERE fee = 0 OR is_45_days_free = true) as free_count,
            COUNT(*) FILTER (WHERE fee > 0 AND is_45_days_free = false) as paid_count
          FROM bdris_applications
        )
        SELECT * FROM app_stats
      `),e.db.select({month:k.sql`DATE_TRUNC('month', ${g.bdrisApplications.submittedAt})`,count:(0,j.count)()}).from(g.bdrisApplications).where((0,i.gte)(g.bdrisApplications.submittedAt,d)).groupBy(k.sql`DATE_TRUNC('month', ${g.bdrisApplications.submittedAt})`).orderBy(k.sql`DATE_TRUNC('month', ${g.bdrisApplications.submittedAt})`),e.db.select({id:g.bdrisApplications.id,applicationId:g.bdrisApplications.applicationId,applicationType:g.bdrisApplications.applicationType,submittedAt:g.bdrisApplications.submittedAt,userName:f.users.name,userPhone:f.users.phone,userProfileImage:f.users.profile_image,source:g.bdrisApplications.source,additionalInfo:g.bdrisApplications.additionalInfo,formData:g.bdrisApplications.formData,fee:g.bdrisApplications.fee,is45DaysFree:g.bdrisApplications.is45DaysFree}).from(g.bdrisApplications).leftJoin(f.users,(0,i.eq)(g.bdrisApplications.userId,f.users.id)).orderBy((0,l.desc)(g.bdrisApplications.submittedAt)).limit(10),e.db.select({userId:g.bdrisApplications.userId,userName:f.users.name,userPhone:f.users.phone,userProfileImage:f.users.profile_image,centerName:f.users.center_name,centerAddress:f.users.center_address,totalApplications:(0,j.count)(),lastApplicationDate:k.sql`MAX(${g.bdrisApplications.submittedAt})`,newApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} IN ('birth_registration', 'death_registration') THEN 1 ELSE 0 END)`,correctionApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} IN ('birth_correction', 'death_correction') THEN 1 ELSE 0 END)`,birthNewApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} = 'birth_registration' THEN 1 ELSE 0 END)`,birthCorrectionApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} = 'birth_correction' THEN 1 ELSE 0 END)`,deathNewApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} = 'death_registration' THEN 1 ELSE 0 END)`,deathCorrectionApplications:k.sql`SUM(CASE WHEN ${g.bdrisApplications.applicationType} = 'death_correction' THEN 1 ELSE 0 END)`}).from(g.bdrisApplications).leftJoin(f.users,(0,i.eq)(g.bdrisApplications.userId,f.users.id)).where(k.sql`${g.bdrisApplications.submittedAt} >= ${a.toISOString()} AND ${g.bdrisApplications.submittedAt} < ${b.toISOString()}`).groupBy(g.bdrisApplications.userId,f.users.name,f.users.phone,f.users.profile_image,f.users.center_name,f.users.center_address).orderBy((0,l.desc)(k.sql`COUNT(*)`)).limit(10)]),q=m[0],r=Number(q?.total)||0,s=Number(q?.new_apps)||0,t=Number(q?.correction_apps)||0,u=Number(q?.birth_new)||0,v=Number(q?.birth_correction)||0,w=Number(q?.death_new)||0,x=Number(q?.death_correction)||0,y=Number(q?.today_count)||0,z=Number(q?.yesterday_count)||0,A={web:Number(q?.web_count)||0,app:Number(q?.app_count)||0},B=Number(q?.free_count)||0,C=Number(q?.paid_count)||0,D=n.map(a=>({month:new Date(a.month).toLocaleDateString("en-US",{year:"numeric",month:"short"}),applications:a.count})),E=o.map(a=>{let b=a.formData||{},c=a.applicationType||"",d="",e="",f="";return"birth_registration"===c?(d=b?.["personInfoForBirth.personNameBn"]||b?.personNameBn||b?.name||"",e=b?.["personInfoForBirth.personBirthDate"]||""):"birth_correction"===c?(d=b?.applicantName||b?.personNameBn||b?.name||"",e=b?.brSearchDob||""):"death_registration"===c?(d=b?.searchResult?.nameBn||b?.personNameBn||b?.name||"",e=b?.brSearchDob||"",f=b?.personDeathDate||""):"death_correction"===c&&(d=b?.applicantName||b?.personNameBn||b?.name||"",e=b?.brSearchDob||""),{id:a.id.toString(),applicationId:a.applicationId,applicationType:c,submittedAt:a.submittedAt,userName:a.userName||"Unknown",userPhone:a.userPhone||"Unknown",userProfileImage:a.userProfileImage||void 0,source:a.source||"app",additionalInfo:a.additionalInfo,fee:a.fee??0,is45DaysFree:a.is45DaysFree??!1,applicantName:d||void 0,dateOfBirth:e||void 0,deathDate:f||void 0,applicantPhone:b?.phone||void 0,permanentAddress:b?.permAddrBn||b?.permAddrEn||void 0}}),F=p.map(a=>({userId:a.userId?.toString()||"",userName:a.userName||"Unknown",userPhone:a.userPhone||"Unknown",userProfileImage:a.userProfileImage||void 0,centerName:a.centerName||void 0,centerAddress:a.centerAddress||void 0,totalApplications:a.totalApplications,newApplications:Number(a.newApplications)||0,correctionApplications:Number(a.correctionApplications)||0,birthNewApplications:Number(a.birthNewApplications)||0,birthCorrectionApplications:Number(a.birthCorrectionApplications)||0,deathNewApplications:Number(a.deathNewApplications)||0,deathCorrectionApplications:Number(a.deathCorrectionApplications)||0,lastApplicationDate:a.lastApplicationDate})),[G,H]=await Promise.all([e.db.select({count:k.sql`count(*)::int`}).from(h.bdrisPending).where((0,i.eq)(h.bdrisPending.status,"draft")),e.db.execute(k.sql`
        WITH user_counts AS (
          SELECT
            COUNT(*) as total_users,
            COUNT(*) FILTER (WHERE status = 'active') as active_users,
            COUNT(*) FILTER (WHERE role = 'entrepreneur') as entrepreneurs
          FROM users
        )
        SELECT * FROM user_counts
      `)]),I=G[0]?.count||0,J=H[0],K=Number(J?.total_users)||0,L=Number(J?.active_users)||0,M=Number(J?.entrepreneurs)||0,N=await e.db.select({date:k.sql`DATE(${g.bdrisApplications.submittedAt})`,count:(0,j.count)()}).from(g.bdrisApplications).groupBy(k.sql`DATE(${g.bdrisApplications.submittedAt})`).orderBy((0,l.desc)((0,j.count)())).limit(1),O=N[0]?.count||0,P=N[0]?.date||"";return{totalApplications:r,pendingApplications:I,approvedApplications:r,registeredUsers:K,activeUsers:L,totalEntrepreneurs:M,todayApplications:y,yesterdayApplications:z,maxApplicationsInDay:O,maxApplicationsDate:P,sourceStats:A,freeApplications:B,paidApplications:C,newApplications:s,correctionApplications:t,birthNewApplications:u,birthCorrectionApplications:v,deathNewApplications:w,deathCorrectionApplications:x,recentApplications:E,topUsers:F,applicationsByType:{birth_registration:u,death_registration:w,birth_correction:v,death_correction:x},monthlyStats:D}}catch(a){throw console.error("Error fetching dashboard stats:",a),Error("Failed to fetch dashboard statistics")}}async function o(a=5){try{return await e.db.select({id:g.bdrisApplications.id,applicationId:g.bdrisApplications.applicationId,applicationType:g.bdrisApplications.applicationType,submittedAt:g.bdrisApplications.submittedAt,additionalInfo:g.bdrisApplications.additionalInfo,formData:g.bdrisApplications.formData,user:{name:f.users.name,phone:f.users.phone,centerName:f.users.center_name}}).from(g.bdrisApplications).leftJoin(f.users,(0,i.eq)(g.bdrisApplications.userId,f.users.id)).orderBy((0,l.desc)(g.bdrisApplications.submittedAt)).limit(a)}catch(a){throw console.error("Error fetching recent applications:",a),Error("Failed to fetch recent applications")}}(0,m.ensureServerEntryExports)([n,o]),(0,d.registerServerReference)(n,"006e4cf387ad9d94e8017cccd77329e5b0bad6f90b",null),(0,d.registerServerReference)(o,"40a248f90d7344b965cf6b26e47dab9c843c086a94",null);var p=a.i(345146);async function q(){try{let a=await (0,p.getSessionController)();if(!a)return{success:!1,statusCode:401,message:"Authentication required"};if(!["admin","super_admin"].includes(a.role))return{success:!1,statusCode:403,message:"Insufficient permissions to access dashboard statistics"};let b=await n();return{success:!0,statusCode:200,message:"Dashboard statistics retrieved successfully",data:b}}catch(a){return console.error("Dashboard stats controller error:",a),{success:!1,statusCode:500,message:"Failed to retrieve dashboard statistics",error:a instanceof Error?a.message:"Unknown error"}}}async function r(a=5){try{let b=await (0,p.getSessionController)();if(!b)return{success:!1,statusCode:401,message:"Authentication required"};if(!["admin","super_admin"].includes(b.role))return{success:!1,statusCode:403,message:"Insufficient permissions to access applications data"};let c=await o(a);return{success:!0,statusCode:200,message:"Recent applications retrieved successfully",data:c}}catch(a){return console.error("Recent applications controller error:",a),{success:!1,statusCode:500,message:"Failed to retrieve recent applications",error:a instanceof Error?a.message:"Unknown error"}}}(0,m.ensureServerEntryExports)([q,r]),(0,d.registerServerReference)(q,"00cfc884906f30b6fb4270a7676d3455e49cc023d0",null),(0,d.registerServerReference)(r,"406ef1554c9165233c7f66603a929f0d21d15b9034",null),a.s([],43499),a.i(43499),a.s(["0021b28e0e2b918f9df0bed9276c52ada9e512decb",()=>b.getSessionController,"00761d1c334752bf2926253c4a1b5dd893df746819",()=>b.logoutController,"00cfc884906f30b6fb4270a7676d3455e49cc023d0",0,q,"4078ca721cf0ea6bf2bb83776743d0be1ccb4804e8",()=>c.checkUdcPermissions],109242)}];

//# sourceMappingURL=%5Broot-of-the-server%5D__0.id8ye._.js.map