"use strict";(()=>{var a={};a.id=460,a.ids=[460],a.modules={261:a=>{a.exports=require("next/dist/shared/lib/router/utils/app-paths")},846:a=>{a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},1421:a=>{a.exports=require("node:child_process")},1820:a=>{a.exports=require("os")},3033:a=>{a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},3295:a=>{a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},3873:a=>{a.exports=require("path")},4870:a=>{a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},6439:a=>{a.exports=require("next/dist/shared/lib/no-fallback-error.external")},7228:(a,b,c)=>{c.d(b,{G8:()=>g,NG:()=>k,VU:()=>f,bU:()=>j,en:()=>i,kh:()=>h,y4:()=>l});var d=c(5440),e=c(5359);function f(a){return(0,d.L)().prepare("SELECT * FROM sub_projects WHERE project_id = ? ORDER BY sort_order ASC").all(a)}function g(a){return(0,d.L)().prepare("SELECT * FROM sub_projects WHERE id = ?").get(a)}function h(a){let b=(0,d.L)();return b.prepare("SELECT * FROM sub_projects WHERE project_id = ? ORDER BY sort_order ASC").all(a).map(a=>{let c=b.prepare(`
      SELECT
        COUNT(*) as task_count,
        SUM(CASE WHEN status IN ('doing','submitted','testing') THEN 1 ELSE 0 END) as active_count,
        SUM(CASE WHEN status IN ('idea','writing') THEN 1 ELSE 0 END) as pending_count,
        SUM(CASE WHEN status = 'done' THEN 1 ELSE 0 END) as done_count,
        SUM(CASE WHEN status = 'problem' THEN 1 ELSE 0 END) as problem_count,
        MAX(updated_at) as last_activity
      FROM tasks WHERE sub_project_id = ? AND is_archived = 0
    `).get(a.id),d=b.prepare(`SELECT title, status FROM tasks WHERE sub_project_id = ? AND is_archived = 0
       ORDER BY CASE status
         WHEN 'doing' THEN 0 WHEN 'submitted' THEN 1 WHEN 'testing' THEN 2 WHEN 'writing' THEN 3
         WHEN 'idea' THEN 4 WHEN 'problem' THEN 5 WHEN 'done' THEN 6
       END, sort_order ASC LIMIT 5`).all(a.id);return{...a,task_count:c.task_count??0,active_count:c.active_count??0,pending_count:c.pending_count??0,done_count:c.done_count??0,problem_count:c.problem_count??0,last_activity:c.last_activity,preview_tasks:d}})}function i(a){let b=(0,d.L)(),c=(0,e.$)(),f=new Date().toISOString(),h=b.prepare("SELECT MAX(sort_order) as max_order FROM sub_projects WHERE project_id = ?").get(a.project_id),i=(h?.max_order??-1)+1;return b.prepare(`INSERT INTO sub_projects (id, project_id, name, description, folder_path, sort_order, created_at, updated_at)
     VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(c,a.project_id,a.name,a.description??"",a.folder_path??null,i,f,f),g(c)}function j(a,b){let c=(0,d.L)(),e=g(a);if(!e)return;let f=new Date().toISOString();return c.prepare("UPDATE sub_projects SET name = ?, description = ?, folder_path = ?, updated_at = ? WHERE id = ?").run(b.name??e.name,b.description??e.description,void 0!==b.folder_path?b.folder_path:e.folder_path,f,a),g(a)}function k(a){return(0,d.L)().prepare("DELETE FROM sub_projects WHERE id = ?").run(a).changes>0}function l(a,b){let c=(0,d.L)(),e=c.prepare("UPDATE sub_projects SET sort_order = ? WHERE id = ? AND project_id = ?");c.transaction(()=>{b.forEach((b,c)=>e.run(c,b,a))})()}},7598:a=>{a.exports=require("node:crypto")},8707:(a,b,c)=>{c.r(b),c.d(b,{handler:()=>G,patchFetch:()=>F,routeModule:()=>B,serverHooks:()=>E,workAsyncStorage:()=>C,workUnitAsyncStorage:()=>D});var d={};c.r(d),c.d(d,{DELETE:()=>A,GET:()=>y,PUT:()=>z});var e=c(9225),f=c(4006),g=c(8317),h=c(9373),i=c(4775),j=c(4235),k=c(261),l=c(4365),m=c(771),n=c(3461),o=c(7798),p=c(2280),q=c(2018),r=c(5696),s=c(7929),t=c(6439),u=c(7527),v=c(5592),w=c(7228),x=c(5440);async function y(a,{params:b}){await (0,x.t)();let{subId:c}=await b,d=(0,w.G8)(c);return d?v.NextResponse.json(d):v.NextResponse.json({error:"Sub-project not found"},{status:404})}async function z(a,{params:b}){await (0,x.t)();let{subId:c}=await b,d=await a.json(),e=(0,w.bU)(c,d);return e?v.NextResponse.json(e):v.NextResponse.json({error:"Sub-project not found"},{status:404})}async function A(a,{params:b}){await (0,x.t)();let{subId:c}=await b;return(0,w.NG)(c)?v.NextResponse.json({success:!0}):v.NextResponse.json({error:"Sub-project not found"},{status:404})}let B=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/projects/[id]/sub-projects/[subId]/route",pathname:"/api/projects/[id]/sub-projects/[subId]",filename:"route",bundlePath:"app/api/projects/[id]/sub-projects/[subId]/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/Users/young/Toy/idea-manager/src/app/api/projects/[id]/sub-projects/[subId]/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:C,workUnitAsyncStorage:D,serverHooks:E}=B;function F(){return(0,g.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:D})}async function G(a,b,c){B.isDev&&(0,h.addRequestMeta)(a,"devRequestTimingInternalsEnd",process.hrtime.bigint());let d="/api/projects/[id]/sub-projects/[subId]/route";"/index"===d&&(d="/");let e=await B.prepare(a,b,{srcPage:d,multiZoneDraftMode:!1});if(!e)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:g,params:v,nextConfig:w,parsedUrl:x,isDraftMode:y,prerenderManifest:z,routerServerContext:A,isOnDemandRevalidate:C,revalidateOnlyGenerated:D,resolvedPathname:E,clientReferenceManifest:F,serverActionsManifest:G}=e,H=(0,k.normalizeAppPath)(d),I=!!(z.dynamicRoutes[H]||z.routes[E]),J=async()=>((null==A?void 0:A.render404)?await A.render404(a,b,x,!1):b.end("This page could not be found"),null);if(I&&!y){let a=!!z.routes[E],b=z.dynamicRoutes[H];if(b&&!1===b.fallback&&!a){if(w.experimental.adapterPath)return await J();throw new t.NoFallbackError}}let K=null;!I||B.isDev||y||(K="/index"===(K=E)?"/":K);let L=!0===B.isDev||!I,M=I&&!L;G&&F&&(0,j.setManifestsSingleton)({page:d,clientReferenceManifest:F,serverActionsManifest:G});let N=a.method||"GET",O=(0,i.getTracer)(),P=O.getActiveScopeSpan(),Q={params:v,prerenderManifest:z,renderOpts:{experimental:{authInterrupts:!!w.experimental.authInterrupts},cacheComponents:!!w.cacheComponents,supportsDynamicResponse:L,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:w.cacheLife,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d,e)=>B.onRequestError(a,b,d,e,A)},sharedContext:{buildId:g}},R=new l.NodeNextRequest(a),S=new l.NodeNextResponse(b),T=m.NextRequestAdapter.fromNodeNextRequest(R,(0,m.signalFromNodeResponse)(b));try{let e=async a=>B.handle(T,Q).finally(()=>{if(!a)return;a.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let c=O.getRootSpanAttributes();if(!c)return;if(c.get("next.span_type")!==n.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${c.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=c.get("next.route");if(e){let b=`${N} ${e}`;a.setAttributes({"next.route":e,"http.route":e,"next.span_name":b}),a.updateName(b)}else a.updateName(`${N} ${d}`)}),g=!!(0,h.getRequestMeta)(a,"minimalMode"),j=async h=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!g&&C&&D&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let d=await e(h);a.fetchMetrics=Q.renderOpts.fetchMetrics;let i=Q.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=Q.renderOpts.collectedTags;if(!I)return await (0,p.I)(R,S,d,Q.renderOpts.pendingWaitUntil),null;{let a=await d.blob(),b=(0,q.toNodeOutgoingHttpHeaders)(d.headers);j&&(b[s.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==Q.renderOpts.collectedRevalidate&&!(Q.renderOpts.collectedRevalidate>=s.INFINITE_CACHE)&&Q.renderOpts.collectedRevalidate,e=void 0===Q.renderOpts.collectedExpire||Q.renderOpts.collectedExpire>=s.INFINITE_CACHE?void 0:Q.renderOpts.collectedExpire;return{value:{kind:u.CachedRouteKind.APP_ROUTE,status:d.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:e}}}}catch(b){throw(null==f?void 0:f.isStale)&&await B.onRequestError(a,b,{routerKind:"App Router",routePath:d,routeType:"route",revalidateReason:(0,o.c)({isStaticGeneration:M,isOnDemandRevalidate:C})},!1,A),b}},l=await B.handleResponse({req:a,nextConfig:w,cacheKey:K,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:z,isRoutePPREnabled:!1,isOnDemandRevalidate:C,revalidateOnlyGenerated:D,responseGenerator:k,waitUntil:c.waitUntil,isMinimalMode:g});if(!I)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==u.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});g||b.setHeader("x-nextjs-cache",C?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),y&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,q.fromNodeOutgoingHttpHeaders)(l.value.headers);return g&&I||m.delete(s.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,r.getCacheControlHeader)(l.cacheControl)),await (0,p.I)(R,S,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};P?await j(P):await O.withPropagatedContext(a.headers,()=>O.trace(n.BaseServerSpan.handleRequest,{spanName:`${N} ${d}`,kind:i.SpanKind.SERVER,attributes:{"http.method":N,"http.target":a.url}},j))}catch(b){if(b instanceof t.NoFallbackError||await B.onRequestError(a,b,{routerKind:"App Router",routePath:H,routeType:"route",revalidateReason:(0,o.c)({isStaticGeneration:M,isOnDemandRevalidate:C})},!1,A),I)throw b;return await (0,p.I)(R,S,new Response(null,{status:500})),null}}},9021:a=>{a.exports=require("fs")},9294:a=>{a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},9661:a=>{a.exports=require("sql.js/dist/sql-wasm.js")}};var b=require("../../../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[445,813,166],()=>b(b.s=8707));module.exports=c})();