(()=>{var a={};a.id=1375,a.ids=[1375],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},11723:a=>{"use strict";a.exports=require("querystring")},12412:a=>{"use strict";a.exports=require("assert")},12909:(a,b,c)=>{"use strict";c.d(b,{N:()=>k});var d=c(13581),e=c(36344),f=c(66699),g=c(16467),h=c(31183),i=c(85663),j=c(96330);let k={adapter:(0,g.y)(h.prisma),session:{strategy:"jwt",maxAge:2592e3},jwt:{maxAge:2592e3},cookies:{sessionToken:{name:"next-auth.session-token",options:{httpOnly:!0,sameSite:"lax",path:"/",secure:!1,maxAge:2592e3}}},pages:{signIn:"/login",signOut:"/",error:"/auth/error"},providers:[(0,d.A)({name:"credentials",credentials:{email:{label:"Email",type:"email"},password:{label:"Password",type:"password"},remember:{label:"Remember Me",type:"text"}},async authorize(a){if(!a?.email||!a?.password)throw Error("Invalid credentials");let b=await h.prisma.user.findUnique({where:{email:a.email},include:{profile:!0}});if(!b||!b.password||!await i.Ay.compare(a.password,b.password))throw Error("Invalid credentials");let c=b.profile?`${b.profile.firstName||""} ${b.profile.lastName||""}`.trim():b.email?.split("@")[0]||"User";return{id:b.id,email:b.email,name:c,role:b.role,image:b.profile?.profileImage||b.image,remember:"true"===a.remember}}}),(0,e.A)({clientId:process.env.GOOGLE_CLIENT_ID,clientSecret:process.env.GOOGLE_CLIENT_SECRET}),(0,f.A)({clientId:process.env.FACEBOOK_CLIENT_ID,clientSecret:process.env.FACEBOOK_CLIENT_SECRET})],callbacks:{async jwt({token:a,user:b,account:c}){if(b){a.id=b.id,a.name=b.name,a.role=b.role,a.remember=b.remember;let c=Math.floor(Date.now()/1e3);b.remember?a.exp=c+2592e3:a.exp=c+86400}if(c&&(a.provider=c.provider),!b&&a.remember&&a.exp&&"number"==typeof a.exp){let b=Math.floor(Date.now()/1e3);a.exp-b<3600&&(a.exp=b+2592e3)}return a},session:async({session:a,token:b})=>(a.user&&(a.user.id=b.id,a.user.name=b.name,a.user.role=b.role,a.user.provider=b.provider,a.user.remember=b.remember),a),async signIn({user:a,account:b}){if(b?.provider==="google"||b?.provider==="facebook")try{if(!await h.prisma.user.findUnique({where:{email:a.email}})){let c=await h.prisma.user.create({data:{email:a.email,image:a.image,provider:b.provider,providerId:b.providerAccountId,role:j.UserRole.FREELANCER,emailVerified:new Date}});if(a.name){let b=a.name.split(" "),d=b[0]||"",e=b.slice(1).join(" ")||"";await h.prisma.profile.create({data:{userId:c.id,firstName:d,lastName:e,profileImage:a.image,countryId:"switzerland"}})}}}catch(a){return console.error("Error in signIn callback:",a),!1}return!0}}}},28354:a=>{"use strict";a.exports=require("util")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},31183:(a,b,c)=>{"use strict";c.r(b),c.d(b,{prisma:()=>e});var d=c(96330);let e=global.prisma||new d.PrismaClient},44870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},55511:a=>{"use strict";a.exports=require("crypto")},55591:a=>{"use strict";a.exports=require("https")},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},74075:a=>{"use strict";a.exports=require("zlib")},75385:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>E,patchFetch:()=>D,routeModule:()=>z,serverHooks:()=>C,workAsyncStorage:()=>A,workUnitAsyncStorage:()=>B});var d={};c.r(d),c.d(d,{GET:()=>y});var e=c(96559),f=c(48088),g=c(37719),h=c(26191),i=c(81289),j=c(261),k=c(92603),l=c(39893),m=c(14823),n=c(47220),o=c(66946),p=c(47912),q=c(99786),r=c(46143),s=c(86439),t=c(43365),u=c(32190),v=c(19854),w=c(12909),x=c(31183);async function y(a){try{let a=await (0,v.getServerSession)(w.N);if(!a?.user?.email)return u.NextResponse.json({error:"Unauthorized"},{status:401});let b=await x.prisma.user.findUnique({where:{email:a.user.email}});if(!b)return u.NextResponse.json({error:"User not found"},{status:404});let c=await x.prisma.$queryRaw`
      SELECT DISTINCT
        CASE 
          WHEN m.senderId = ${b.id} THEN m.receiverId
          ELSE m.senderId
        END as contactId,
        MAX(m.createdAt) as lastMessageTime,
        COUNT(CASE WHEN m.receiverId = ${b.id} AND m.isRead = false THEN 1 END) as unreadCount
      FROM Message m
      WHERE m.senderId = ${b.id} OR m.receiverId = ${b.id}
      GROUP BY contactId
      ORDER BY lastMessageTime DESC
    `,d=await Promise.all(c.map(async a=>{let c=await x.prisma.user.findUnique({where:{id:a.contactId},include:{profile:!0}}),d=await x.prisma.message.findFirst({where:{OR:[{senderId:b.id,receiverId:a.contactId},{senderId:a.contactId,receiverId:b.id}]},orderBy:{createdAt:"desc"},include:{project:{select:{id:!0,title:!0}}}});return{contactId:a.contactId,contact:c,lastMessage:d,lastMessageTime:a.lastMessageTime,unreadCount:Number(a.unreadCount)}}));return u.NextResponse.json({success:!0,data:d.filter(a=>a.contact)})}catch(a){return console.error("Error fetching conversations:",a),u.NextResponse.json({error:a instanceof Error?a.message:"Failed to fetch conversations",type:"server_error"},{status:500})}}let z=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/messages/conversations/route",pathname:"/api/messages/conversations",filename:"route",bundlePath:"app/api/messages/conversations/route"},distDir:".next",projectDir:"",resolvedPagePath:"D:\\node_project\\smile24\\smile24-nextjs-be-code\\src\\app\\api\\messages\\conversations\\route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:A,workUnitAsyncStorage:B,serverHooks:C}=z;function D(){return(0,g.patchFetch)({workAsyncStorage:A,workUnitAsyncStorage:B})}async function E(a,b,c){var d;let e="/api/messages/conversations/route";"/index"===e&&(e="/");let g=await z.prepare(a,b,{srcPage:e,multiZoneDraftMode:"false"});if(!g)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:u,params:v,nextConfig:w,isDraftMode:x,prerenderManifest:y,routerServerContext:A,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,resolvedPathname:D}=g,E=(0,j.normalizeAppPath)(e),F=!!(y.dynamicRoutes[E]||y.routes[D]);if(F&&!x){let a=!!y.routes[D],b=y.dynamicRoutes[E];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let G=null;!F||z.isDev||x||(G="/index"===(G=D)?"/":G);let H=!0===z.isDev||!F,I=F&&!H,J=a.method||"GET",K=(0,i.getTracer)(),L=K.getActiveScopeSpan(),M={params:v,prerenderManifest:y,renderOpts:{experimental:{dynamicIO:!!w.experimental.dynamicIO,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:H,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:I,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>z.onRequestError(a,b,d,A)},sharedContext:{buildId:u}},N=new k.NodeNextRequest(a),O=new k.NodeNextResponse(b),P=l.NextRequestAdapter.fromNodeNextRequest(N,(0,l.signalFromNodeResponse)(b));try{let d=async c=>z.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=K.getRootSpanAttributes();if(!d)return;if(d.get("next.span_type")!==m.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${d.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=d.get("next.route");if(e){let a=`${J} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${J} ${a.url}`)}),g=async g=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!(0,h.getRequestMeta)(a,"minimalMode")&&B&&C&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let e=await d(g);a.fetchMetrics=M.renderOpts.fetchMetrics;let i=M.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=M.renderOpts.collectedTags;if(!F)return await (0,o.I)(N,O,e,M.renderOpts.pendingWaitUntil),null;{let a=await e.blob(),b=(0,p.toNodeOutgoingHttpHeaders)(e.headers);j&&(b[r.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==M.renderOpts.collectedRevalidate&&!(M.renderOpts.collectedRevalidate>=r.INFINITE_CACHE)&&M.renderOpts.collectedRevalidate,d=void 0===M.renderOpts.collectedExpire||M.renderOpts.collectedExpire>=r.INFINITE_CACHE?void 0:M.renderOpts.collectedExpire;return{value:{kind:t.CachedRouteKind.APP_ROUTE,status:e.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:d}}}}catch(b){throw(null==f?void 0:f.isStale)&&await z.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})},A),b}},l=await z.handleResponse({req:a,nextConfig:w,cacheKey:G,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:y,isRoutePPREnabled:!1,isOnDemandRevalidate:B,revalidateOnlyGenerated:C,responseGenerator:k,waitUntil:c.waitUntil});if(!F)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==t.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(j=l.value)?void 0:j.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});(0,h.getRequestMeta)(a,"minimalMode")||b.setHeader("x-nextjs-cache",B?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),x&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,p.fromNodeOutgoingHttpHeaders)(l.value.headers);return(0,h.getRequestMeta)(a,"minimalMode")&&F||m.delete(r.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,q.getCacheControlHeader)(l.cacheControl)),await (0,o.I)(N,O,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};L?await g(L):await K.withPropagatedContext(a.headers,()=>K.trace(m.BaseServerSpan.handleRequest,{spanName:`${J} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":J,"http.target":a.url}},g))}catch(b){if(L||b instanceof s.NoFallbackError||await z.onRequestError(a,b,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})}),F)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},78335:()=>{},79428:a=>{"use strict";a.exports=require("buffer")},79551:a=>{"use strict";a.exports=require("url")},81630:a=>{"use strict";a.exports=require("http")},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},94735:a=>{"use strict";a.exports=require("events")},96330:a=>{"use strict";a.exports=require("@prisma/client")},96487:()=>{}};var b=require("../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[431,4999,6055,5663,2001],()=>b(b.s=75385));module.exports=c})();