"use strict";(()=>{var e={};e.id=129,e.ids=[129],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")},8109:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>T,requestAsyncStorage:()=>k,routeModule:()=>g,serverHooks:()=>w,staticGenerationAsyncStorage:()=>S});var n={};r.r(n),r.d(n,{GET:()=>v});var a=r(49303),o=r(88716),i=r(60670),s=r(87070),u=r(14184),d=r(29045),l=r(33624),c=r(95456),p=r(56310),y=r(63814),m=r(92383);function h(e){let[t,r]=e.split(":").map(Number);return 60*t+r}function f(e){return Math.round(e/60*10)/10}async function v(e){try{let{valid:t,error:r}=(0,c.Gl)(e);if(!t)return s.NextResponse.json({success:!1,error:r},{status:401});await (0,u.Z)();let n=(0,p.z)(new Date,{weekStartsOn:1}),a=(0,y.E)(n,6),o=(0,m.WU)(n,"yyyy-MM-dd"),i=(0,m.WU)(a,"yyyy-MM-dd"),[v,g]=await Promise.all([d.Z.find().sort({dayOfWeek:1,startTime:1}),l.Z.find({date:{$gte:o,$lte:i}})]),k={},S=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],w={};S.forEach(e=>{w[e]={}}),v.forEach(e=>{let t=h(e.endTime)-h(e.startTime),r=f(Math.max(0,t)),n=e.blockType;k[n]=(k[n]||0)+r,w[e.dayOfWeek]&&(w[e.dayOfWeek][n]=(w[e.dayOfWeek][n]||0)+r)});let x=g.length,T=g.filter(e=>!0===e.completed).length,q=["Course","Work","Web Dev","webdev","course","work"],M=[];S.forEach((e,t)=>{let r=(0,m.WU)((0,y.E)(n,t),"yyyy-MM-dd"),a=v.filter(t=>t.dayOfWeek===e).filter(e=>q.some(t=>e.blockType.toLowerCase().includes(t.toLowerCase()))).reduce((e,t)=>{let r=h(t.endTime)-h(t.startTime);return e+f(Math.max(0,r))},0);M.push({day:e,date:r,hours:Math.round(10*a)/10})});let W=(k.Sleep||k.sleep||0)/7,b=k.Bus||k.bus||0;return s.NextResponse.json({success:!0,data:{hoursByType:k,dailyBreakdown:w,dailyProductivity:M,weekSummary:{totalProductiveHours:Math.round(10*(k.Course||0)+10*(k.Work||0)+10*(k["Web Dev"]||k.webdev||0))/10,sleepHoursAvg:Math.round(10*W)/10,commuteHours:Math.round(10*b)/10,completionRate:x>0?Math.round(T/x*100):0,totalBlocks:v.length,weekStartDate:o,weekEndDate:i}}})}catch(e){return s.NextResponse.json({success:!1,error:e instanceof Error?e.message:"Failed to fetch analytics data"},{status:500})}}let g=new a.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/analytics/week/route",pathname:"/api/analytics/week",filename:"route",bundlePath:"app/api/analytics/week/route"},resolvedPagePath:"E:\\WEB Project\\My Plan\\src\\app\\api\\analytics\\week\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:k,staticGenerationAsyncStorage:S,serverHooks:w}=g,x="/api/analytics/week/route";function T(){return(0,i.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:S})}},95456:(e,t,r)=>{r.d(t,{Gl:()=>s,fT:()=>i});var n=r(41482),a=r.n(n);let o=process.env.JWT_SECRET||"my-plan-app-secret-key-change-this";function i(e,t){return a().sign(e,t||o,{expiresIn:"30d"})}function s(e){var t;let r=(t=e.headers.get("Authorization"))&&t.startsWith("Bearer ")?t.slice(7):null;return r?!function(e,t){try{return a().verify(e,t||o)}catch{return null}}(r,process.env.JWT_SECRET||o)?{valid:!1,error:"Invalid or expired token"}:{valid:!0}:{valid:!1,error:"No token provided"}}},14184:(e,t,r)=>{r.d(t,{Z:()=>s});var n=r(11185),a=r.n(n);let o=process.env.MONGODB_URI;if(!o)throw Error("Please define the MONGODB_URI environment variable inside .env.local");let i=global.mongoose;i||(i=global.mongoose={conn:null,promise:null});let s=async function(){if(i.conn)return i.conn;i.promise||(i.promise=a().connect(o,{bufferCommands:!1}));try{i.conn=await i.promise}catch(e){throw i.promise=null,e}return i.conn}},29045:(e,t,r)=>{r.d(t,{Z:()=>i});var n=r(11185),a=r.n(n);let o=new n.Schema({dayOfWeek:{type:String,required:!0},startTime:{type:String,required:!0},endTime:{type:String,required:!0},activityName:{type:String,required:!0},blockType:{type:String,required:!0},color:{type:String,required:!0}}),i=a().models.ScheduleBlock||a().model("ScheduleBlock",o)},33624:(e,t,r)=>{r.d(t,{Z:()=>i});var n=r(11185),a=r.n(n);let o=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}});o.index({date:1,scheduledStart:1,activityName:1},{unique:!0});let i=a().models.TaskCompletion||a().model("TaskCompletion",o)}};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(8109));module.exports=n})();