(()=>{var a={};a.id=2915,a.ids=[2915],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(31183),h=c(85663),i=c(96330),j=c(44999);let k={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 g.prisma.user.findUnique({where:{email:a.email},include:{profile:!0}});if(!b||!b.password||!await h.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,authorization:{url:"https://accounts.google.com/o/oauth2/v2/auth",params:{prompt:"select_account",access_type:"offline"}}}),(0,f.A)({clientId:process.env.FACEBOOK_CLIENT_ID,clientSecret:process.env.FACEBOOK_CLIENT_SECRET,authorization:{params:{scope:"email public_profile"}}})],callbacks:{async jwt({token:a,user:b,account:c}){if(b){if(b.role)a.role=b.role;else{let c=await g.prisma.user.findUnique({where:{email:b.email},select:{id:!0,role:!0}});a.role=c?.role||a.role||i.UserRole.FREELANCER}a.id=b.id,a.name=b.name,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}){let c=(0,j.cookies)(),d=(await c).get("country")?.value;if(b?.provider==="google"||b?.provider==="facebook")try{if(!await g.prisma.user.findUnique({where:{email:a.email}})){let c=await g.prisma.user.create({data:{email:a.email,image:a.image,provider:b.provider,providerId:b.providerAccountId,role:i.UserRole.FREELANCER,emailVerified:new Date}});if(a.name){let b=a.name.split(" "),e=b[0]||"",f=b.slice(1).join(" ")||"";await g.prisma.profile.create({data:{userId:c.id,firstName:e,lastName:f,profileImage:a.image,countryId:d||"switzerland"}})}}}catch(a){return console.error("Error in signIn callback:",a),!1}return!0}}}},21111:(a,b,c)=>{"use strict";c.d(b,{_:()=>e});let d={PROJECT_AWARDED:a=>({subject:`🎉 Congratulations! Your bid was selected for "${a.projectTitle}"`,html:`
      <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
        <h2 style="color: #4CAF50;">Congratulations ${a.freelancerName}!</h2>
        <p>Great news! Your bid has been selected for the project:</p>
        
        <div style="background: #f5f5f5; padding: 20px; margin: 20px 0; border-radius: 8px;">
          <h3 style="margin: 0 0 10px 0; color: #333;">${a.projectTitle}</h3>
          <p style="margin: 5px 0;"><strong>Client:</strong> ${a.clientName}</p>
          <p style="margin: 5px 0;"><strong>Your Winning Bid:</strong> €${a.bidAmount}</p>
        </div>
        
        <p>You can now start working on this project. Please:</p>
        <ul>
          <li>Review the project requirements carefully</li>
          <li>Communicate with the client through the project chat</li>
          <li>Deliver high-quality work on time</li>
        </ul>
        
        <a href="${a.projectUrl}" style="display: inline-block; background: #4CAF50; color: white; padding: 12px 24px; text-decoration: none; border-radius: 5px; margin: 20px 0;">
          View Project
        </a>
        
        <p style="color: #666; font-size: 14px; margin-top: 30px;">
          Best of luck with your project!<br>
          The Smile24 Team
        </p>
      </div>
    `}),PROJECT_CANCELLED:a=>({subject:`Project "${a.projectTitle}" has been cancelled`,html:`
      <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
        <h2 style="color: #FF6B35;">Project Cancelled</h2>
        <p>Hi ${a.freelancerName},</p>
        <p>We're sorry to inform you that the project you bid on has been cancelled:</p>
        
        <div style="background: #f5f5f5; padding: 20px; margin: 20px 0; border-radius: 8px;">
          <h3 style="margin: 0 0 10px 0; color: #333;">${a.projectTitle}</h3>
          <p style="margin: 5px 0;"><strong>Client:</strong> ${a.clientName}</p>
          <p style="margin: 5px 0;"><strong>Reason:</strong> ${a.reason}</p>
          ${a.bidAmount?`<p style="margin: 5px 0;"><strong>Your Bid:</strong> €${a.bidAmount}</p>`:""}
        </div>
        
        <p>Don't worry! There are many other great projects available. Keep applying to projects that match your skills.</p>
        
        <a href="/freelancer/projects" style="display: inline-block; background: #4CAF50; color: white; padding: 12px 24px; text-decoration: none; border-radius: 5px; margin: 20px 0;">
          Find New Projects
        </a>
        
        <p style="color: #666; font-size: 14px; margin-top: 30px;">
          Thank you for your understanding.<br>
          The Smile24 Team
        </p>
      </div>
    `}),BID_RECEIVED:a=>({subject:`New bid received for "${a.projectTitle}"`,html:`
      <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
        <h2 style="color: #4CAF50;">New Bid Received!</h2>
        <p>Hi ${a.clientName},</p>
        <p>You've received a new bid for your project:</p>
        
        <div style="background: #f5f5f5; padding: 20px; margin: 20px 0; border-radius: 8px;">
          <h3 style="margin: 0 0 10px 0; color: #333;">${a.projectTitle}</h3>
          <p style="margin: 5px 0;"><strong>Freelancer:</strong> ${a.freelancerName}</p>
          <p style="margin: 5px 0;"><strong>Bid Amount:</strong> €${a.bidAmount}</p>
        </div>
        
        <p>Review the bid details and freelancer profile to make an informed decision.</p>
        
        <a href="${a.projectUrl}" style="display: inline-block; background: #4CAF50; color: white; padding: 12px 24px; text-decoration: none; border-radius: 5px; margin: 20px 0;">
          Review Bid
        </a>
        
        <p style="color: #666; font-size: 14px; margin-top: 30px;">
          Happy hiring!<br>
          The Smile24 Team
        </p>
      </div>
    `})};class e{static async sendProjectAwardedEmail(a,b){let c=d.PROJECT_AWARDED(b);return this.sendEmail({to:a,subject:c.subject,template:c.html,data:b})}static async sendProjectCancelledEmail(a,b){let c=d.PROJECT_CANCELLED(b);return this.sendEmail({to:a,subject:c.subject,template:c.html,data:b})}static async sendBidReceivedEmail(a,b){let c=d.BID_RECEIVED(b);return this.sendEmail({to:a,subject:c.subject,template:c.html,data:b})}static async sendEmail(a){try{return console.log("\uD83D\uDCE7 Email would be sent:",{to:a.to,subject:a.subject,html:a.template}),!0}catch(a){return console.error("Failed to send email:",a),!1}}}},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},43360:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>F,patchFetch:()=>E,routeModule:()=>A,serverHooks:()=>D,workAsyncStorage:()=>B,workUnitAsyncStorage:()=>C});var d={};c.r(d),c.d(d,{POST:()=>z});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),y=c(21111);async function z(a,{params:b}){try{let{projectId:c}=await b,d=await (0,v.getServerSession)(w.N);if(!d?.user)return u.NextResponse.json({error:"Unauthorized"},{status:401});if("FREELANCER"!==d.user.role)return u.NextResponse.json({error:"Forbidden",message:"Only freelancers can place bids on projects."},{status:403});let{amount:e,deliveryTime:f,proposal:g}=await a.json();if(!e)return u.NextResponse.json({error:"Validation failed",message:"Bid amount is required. Please enter a valid amount."},{status:400});if(!f)return u.NextResponse.json({error:"Validation failed",message:"Delivery time is required. Please specify how many days you need."},{status:400});if(!g||0===g.trim().length)return u.NextResponse.json({error:"Validation failed",message:"Proposal description is required. Please describe your approach."},{status:400});let h=parseFloat(e),i=parseInt(f);if(isNaN(h)||h<=0)return u.NextResponse.json({error:"Validation failed",message:"Please enter a valid bid amount greater than 0."},{status:400});if(isNaN(i)||i<=0)return u.NextResponse.json({error:"Validation failed",message:"Please enter a valid delivery time greater than 0 days."},{status:400});if(g.trim().length<10)return u.NextResponse.json({error:"Validation failed",message:"Proposal must be at least 10 characters long."},{status:400});if(!x.prisma)return u.NextResponse.json({error:"Service unavailable",message:"Database service is currently unavailable. Please try again later."},{status:503});try{let a=d.user.id;if(await x.prisma.bid.findFirst({where:{projectId:c,freelancerId:a}}))return u.NextResponse.json({error:"Duplicate bid",message:"You have already submitted a bid for this project. You can update your existing bid instead."},{status:409});let b=await x.prisma.project.findUnique({where:{id:c},include:{category:!0,client:{include:{profile:!0}}}});if(!b)return u.NextResponse.json({error:"Project not found",message:"The project you are trying to bid on does not exist or has been removed."},{status:404});if("OPEN"!==b.status){let a="This project is no longer accepting bids.";return"IN_PROGRESS"===b.status?a="This project has already been awarded to another freelancer.":"COMPLETED"===b.status?a="This project has been completed.":"CANCELLED"===b.status&&(a="This project has been cancelled by the client."),u.NextResponse.json({error:"Project unavailable",message:a},{status:400})}if(!await x.prisma.categorySubscription.findFirst({where:{userId:a,categoryId:b.categoryId,status:"ACTIVE",endDate:{gte:new Date}}}))return u.NextResponse.json({error:"Subscription required",message:`You need an active subscription for the "${b.category.name}" category to place bids on this project. Please purchase a subscription first.`,requiresSubscription:!0,categoryId:b.categoryId,categoryName:b.category.name},{status:403});let e=await x.prisma.bid.create({data:{projectId:c,freelancerId:a,amount:h,duration:i,proposal:g,status:"PENDING"},include:{freelancer:{select:{id:!0,email:!0,image:!0,profile:{select:{firstName:!0,lastName:!0}}}}}});try{await x.prisma.message.create({data:{content:`Hi! I've placed a bid on your project "${b.title}". I'd be happy to discuss the requirements in more detail.`,senderId:a,receiverId:b.clientId,projectId:c,bidId:e.id,messageType:"text"}}),console.log("Chat initialized with welcome message for bid:",e.id)}catch(a){console.error("Failed to initialize chat:",a)}try{await x.prisma.notification.create({data:{userId:b.clientId,type:"bid_received",title:"New Bid Received",message:`${e.freelancer.profile?.firstName||"A freelancer"} placed a bid on your project "${b.title}"`,data:JSON.stringify({projectId:c,bidId:e.id,freelancerId:a,amount:h})}});try{await y._.sendBidReceivedEmail(b.clientId,{clientName:`${b.client.profile?.firstName||""} ${b.client.profile?.lastName||""}`.trim()||"Client",projectTitle:b.title,freelancerName:`${e.freelancer.profile?.firstName||""} ${e.freelancer.profile?.lastName||""}`.trim()||"Freelancer",bidAmount:h,projectUrl:`https://smile24.hipl-staging2.com/client/project-details?id=${c}`})}catch(a){console.error("Failed to send bid received email:",a)}}catch(a){console.error("Failed to create notification:",a)}return u.NextResponse.json({success:!0,message:"Bid submitted successfully",bid:{id:e.id,projectId:e.projectId,freelancerId:e.freelancerId,amount:e.amount,days:e.duration,proposal:e.proposal,status:e.status,createdAt:e.createdAt.toISOString(),freelancer:e.freelancer}})}catch(a){return console.error("Database error:",a),u.NextResponse.json({error:"Database operation failed",message:"Unable to submit bid due to a database error. Please try again later.",details:void 0},{status:500})}}catch(a){return console.error("Error submitting bid:",a),u.NextResponse.json({error:"Server error",message:"An unexpected error occurred while submitting your bid. Please try again later.",details:void 0},{status:500})}}let A=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/projects/[projectId]/bid/route",pathname:"/api/projects/[projectId]/bid",filename:"route",bundlePath:"app/api/projects/[projectId]/bid/route"},distDir:".next",projectDir:"",resolvedPagePath:"D:\\node_project\\smile24\\smile24-nextjs-be-code\\src\\app\\api\\projects\\[projectId]\\bid\\route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:B,workUnitAsyncStorage:C,serverHooks:D}=A;function E(){return(0,g.patchFetch)({workAsyncStorage:B,workUnitAsyncStorage:C})}async function F(a,b,c){var d;let e="/api/projects/[projectId]/bid/route";"/index"===e&&(e="/");let g=await A.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:z,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||A.isDev||x||(G="/index"===(G=D)?"/":G);let H=!0===A.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)=>A.onRequestError(a,b,d,z)},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=>A.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 A.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:B})},z),b}},l=await A.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 A.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}}},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")},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,6403],()=>b(b.s=43360));module.exports=c})();