"use strict";(()=>{var e={};e.id=229,e.ids=[229],e.modules={11185:e=>{e.exports=require("mongoose")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},66530:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>k,requestAsyncStorage:()=>h,routeModule:()=>f,serverHooks:()=>g,staticGenerationAsyncStorage:()=>v});var n={};r.r(n),r.d(n,{GET:()=>y});var o=r(49303),a=r(88716),s=r(60670),i=r(87070),l=r(14184),u=r(33624),d=r(95456),p=r(92383),c=r(63814);function m(e,t,r){return(0,c.E)(e,-t,r)}async function y(e){try{let{valid:t,error:r}=(0,d.Gl)(e);if(!t)return i.NextResponse.json({success:!1,error:r},{status:401});await (0,l.Z)();let n=(0,p.WU)(new Date,"yyyy-MM-dd"),o=(0,p.WU)(m(new Date,60),"yyyy-MM-dd"),a=await u.Z.find({date:{$gte:o,$lte:n},completed:!0}).select("date").sort({date:-1}),s=new Set(a.map(e=>e.date)),c=0,y=new Date;for(let e=0;e<=60;e++){let t=(0,p.WU)(m(y,e),"yyyy-MM-dd");if(s.has(t))c++;else{if(0===e)continue;break}}let f=[];for(let e=13;e>=0;e--){let t=(0,p.WU)(m(new Date,e),"yyyy-MM-dd"),r=await u.Z.find({date:t}),n=r.filter(e=>!0===e.completed).length,o=r.length;f.push({date:t,completed:n,total:o,rate:o>0?Math.round(n/o*100):0})}return i.NextResponse.json({success:!0,data:{currentStreak:c,todayDate:n,history:f}})}catch(e){return i.NextResponse.json({success:!1,error:e instanceof Error?e.message:"Failed to fetch streak data"},{status:500})}}let f=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/completions/streak/route",pathname:"/api/completions/streak",filename:"route",bundlePath:"app/api/completions/streak/route"},resolvedPagePath:"E:\\WEB Project\\My Plan\\src\\app\\api\\completions\\streak\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:h,staticGenerationAsyncStorage:v,serverHooks:g}=f,x="/api/completions/streak/route";function k(){return(0,s.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:v})}},95456:(e,t,r)=>{r.d(t,{Gl:()=>i,fT:()=>s});var n=r(41482),o=r.n(n);let a=process.env.JWT_SECRET||"my-plan-app-secret-key-change-this";function s(e,t){return o().sign(e,t||a,{expiresIn:"30d"})}function i(e){var t;let r=(t=e.headers.get("Authorization"))&&t.startsWith("Bearer ")?t.slice(7):null;return r?!function(e,t){try{return o().verify(e,t||a)}catch{return null}}(r,process.env.JWT_SECRET||a)?{valid:!1,error:"Invalid or expired token"}:{valid:!0}:{valid:!1,error:"No token provided"}}},14184:(e,t,r)=>{r.d(t,{Z:()=>i});var n=r(11185),o=r.n(n);let a=process.env.MONGODB_URI;if(!a)throw Error("Please define the MONGODB_URI environment variable inside .env.local");let s=global.mongoose;s||(s=global.mongoose={conn:null,promise:null});let i=async function(){if(s.conn)return s.conn;s.promise||(s.promise=o().connect(a,{bufferCommands:!1}));try{s.conn=await s.promise}catch(e){throw s.promise=null,e}return s.conn}},33624:(e,t,r)=>{r.d(t,{Z:()=>s});var n=r(11185),o=r.n(n);let a=new n.Schema({date:{type:String,required:!0},blockType:{type:String,required:!0},activityName:{type:String,required:!0},scheduledStart:{type:String,required:!0},scheduledEnd:{type:String,required:!0},completed:{type:Boolean,default:null},completedAt:{type:Date},note:{type:String}});a.index({date:1,scheduledStart:1,activityName:1},{unique:!0});let s=o().models.TaskCompletion||o().model("TaskCompletion",a)}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[948,972,843,482,167],()=>r(66530));module.exports=n})();