(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9700],{6748:(e,s,t)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/sessions/[userId]",function(){return t(34455)}])},34455:(e,s,t)=>{"use strict";t.r(s),t.d(s,{default:()=>p});var l=t(77528),a=t(74848),i=t(81924),r=t(98536),n=t(29080),o=t(72748),c=t(59639),d=t(14516),f=t(69231),u=t(23825),x=t(22424),w=t(33016),h=t(15445),m=t(37399),g=t(86715),j=t(96540);let p=()=>{let e=(0,g.useRouter)(),{userId:s}=e.query,[t,p]=(0,j.useState)([]),[k,y]=(0,j.useState)({}),[_,N]=(0,j.useState)(!0),[v,b]=(0,j.useState)(1),[S,E]=(0,j.useState)(!0),[C,P]=(0,j.useState)(!1),[I,L]=(0,j.useState)(null),z=(s,t)=>{switch(t){case"workflow":return s.workflow_id&&k[s.workflow_id]?(0,a.jsx)(r.R,{size:"sm",variant:"flat",className:"cursor-pointer",onClick:()=>e.push("/workflows/".concat(s.workflow_id)),children:k[s.workflow_id].name}):"N/A";case"messages":return(0,a.jsxs)(r.R,{size:"sm",variant:"flat",className:"cursor-pointer",onClick:()=>R(s.id),children:[s.messages.length.toString()," messages"]});case"action":return(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)(m.In,{icon:"lucide:eye",className:"cursor-pointer text-default-400",height:18,width:18,onClick:()=>R(s.id),"aria-label":"View Session"})});case"created_at":case"updated_at":return D(s[t]);default:var l;return(null===(l=s[t])||void 0===l?void 0:l.toString())||""}};(0,j.useEffect)(()=>{s&&"string"==typeof s&&M()},[s]);let M=async()=>{if(s&&"string"==typeof s)try{N(!0),L(null);let e=await (0,i.GW)(0,10,s);p(e.sessions),E(e.total>e.sessions.length);let t={};await Promise.all(e.sessions.map(async e=>{if(e.workflow_id){let s=await (0,i.Mw)(e.workflow_id);t[e.workflow_id]=s}})),y(t)}catch(e){console.error("Error fetching sessions:",e),L("Failed to fetch sessions. Please try again.")}finally{N(!1)}},T=async()=>{if(s&&"string"==typeof s)try{P(!0),L(null);let e=v+1,a=await (0,i.GW)((e-1)*10,10,s),r=(0,l._)({},k);await Promise.all(a.sessions.map(async e=>{if(e.workflow_id&&!r[e.workflow_id]){let s=await (0,i.Mw)(e.workflow_id);r[e.workflow_id]=s}})),p(e=>[...e,...a.sessions]),y(r),b(e),E(a.total>a.sessions.length+t.length)}catch(e){console.error("Error loading more sessions:",e),L("Failed to load more sessions. Please try again.")}finally{P(!1)}},D=e=>new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),R=t=>{s&&"string"==typeof s&&e.push("/sessions/".concat(s,"/").concat(t))};return s?(0,a.jsxs)("div",{className:"flex flex-col gap-2 max-w-7xl w-full mx-auto pt-2 px-6",children:[(0,a.jsx)("header",{className:"mb-6",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("h1",{className:"text-lg font-bold text-default-900 lg:text-2xl",children:"User Sessions"}),(0,a.jsxs)("p",{className:"text-small text-default-400 lg:text-medium",children:["Viewing sessions for user: ",s]})]}),(0,a.jsx)(o.T,{className:"bg-foreground text-background",startContent:(0,a.jsx)(m.In,{icon:"lucide:arrow-left",width:16}),onPress:()=>e.push("/dashboard"),children:"Back to Dashboard"})]})}),I&&(0,a.jsx)(c.B,{className:"mb-4",color:"danger",variant:"flat",children:I}),_?(0,a.jsx)("div",{className:"flex justify-center p-4",children:(0,a.jsx)(n.o,{size:"lg"})}):t.length>0?(0,a.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,a.jsxs)(d.j,{"aria-label":"Sessions",isHeaderSticky:!0,children:[(0,a.jsx)(f.X,{columns:[{key:"id",label:"Session ID"},{key:"workflow",label:"Workflow"},{key:"messages",label:"Messages"},{key:"created_at",label:"Created"},{key:"updated_at",label:"Last Updated"},{key:"action",label:"Actions"}],children:e=>(0,a.jsx)(u.e,{children:e.label},e.key)}),(0,a.jsx)(x.E,{items:t,children:e=>(0,a.jsx)(w.s,{children:s=>(0,a.jsx)(h.w,{children:z(e,s.toString())})},e.id)})]}),S&&(0,a.jsx)("div",{className:"flex justify-center mt-4",children:(0,a.jsx)(o.T,{variant:"flat",onPress:T,isLoading:C,startContent:!C&&(0,a.jsx)(m.In,{icon:"lucide:plus",width:16}),children:C?"Loading...":"Load More"})})]}):(0,a.jsx)("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:(0,a.jsx)("p",{className:"text-muted-foreground",children:"No sessions found for this user."})})]}):(0,a.jsx)("div",{className:"flex flex-col gap-2 max-w-7xl w-full mx-auto pt-2 px-6",children:(0,a.jsx)("div",{className:"flex justify-center p-4",children:(0,a.jsx)(n.o,{size:"lg"})})})}}},e=>{var s=s=>e(e.s=s);e.O(0,[8660,7354,636,6593,8792],()=>s(6748)),_N_E=e.O()}]);