(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[731],{72431:function(){},94046:function(e,t,r){"use strict";r.d(t,{j:function(){return s},w:function(){return n}}),r(74590);var a=r(58064),s=(0,a.$)("b9599954ed51964534f762474f31014ce28e5677"),n=(0,a.$)("1ddd4fca908ff08465700fac5ac0bb6d0b10df91")},34168:function(e,t,r){"use strict";r.d(t,{Z:function(){return d}});var a=r(57437),s=r(93073),n=r(56935),l=r(44867),o=r(2265),i=r(27776);function d(){let[e,t]=(0,o.useState)(!1),r=async()=>{t(!0);try{let e=await fetch("/api/create-portal-session",{method:"POST"});if(!e.ok)throw Error("Failed to create portal session");let t=await e.json();if(t.url)window.location.href=t.url;else throw Error("No URL returned from create-portal-session")}catch(e){console.error("Error in handleManageSubscription:",e),i.Am.error("Failed to open subscription management. Please try again.")}finally{t(!1)}};return(0,a.jsx)(s.l8,{afterSignOutUrl:"/",children:(0,a.jsxs)(s.l8.MenuItems,{children:[(0,a.jsx)(s.l8.Action,{label:"Manage subscription",labelIcon:(0,a.jsx)(n.Z,{className:"w-4 h-4"}),onClick:r}),(0,a.jsx)(s.l8.Link,{label:"Pricing",labelIcon:(0,a.jsx)(l.Z,{className:"w-4 h-4"}),href:"/pricing"})]})})}},22445:function(e,t,r){"use strict";r.d(t,{Z:function(){return R}});var a=r(57437),s=r(2265),n=r(45188),l=r(6649),o=r(10883),i=r(66588),d=r(92513),c=r(69373),u=r(23402),m=r(33907),x=r(81622),f=r(19666),h=r(6285),p=r(93073),g=r(87138),b=r(27776),j=r(76669),y=r(37440),N=r(50495);let w=j.fC;j.xz;let v=j.h_,z=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)(j.aV,{className:(0,y.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...s,ref:t})});z.displayName=j.aV.displayName;let k=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsxs)(v,{children:[(0,a.jsx)(z,{}),(0,a.jsx)(j.VY,{ref:t,className:(0,y.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),...s})]})});k.displayName=j.VY.displayName;let C=e=>{let{className:t,...r}=e;return(0,a.jsx)("div",{className:(0,y.cn)("flex flex-col space-y-2 text-center sm:text-left",t),...r})};C.displayName="AlertDialogHeader";let D=e=>{let{className:t,...r}=e;return(0,a.jsx)("div",{className:(0,y.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...r})};D.displayName="AlertDialogFooter";let I=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)(j.Dx,{ref:t,className:(0,y.cn)("text-lg font-semibold",r),...s})});I.displayName=j.Dx.displayName;let O=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)(j.dk,{ref:t,className:(0,y.cn)("text-sm text-muted-foreground",r),...s})});O.displayName=j.dk.displayName;let A=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)(j.aU,{ref:t,className:(0,y.cn)((0,N.d)(),r),...s})});A.displayName=j.aU.displayName;let Z=s.forwardRef((e,t)=>{let{className:r,...s}=e;return(0,a.jsx)(j.$j,{ref:t,className:(0,y.cn)((0,N.d)({variant:"outline"}),"mt-2 sm:mt-0",r),...s})});Z.displayName=j.$j.displayName;var S=r(6881),E=r(16463);function R(e){let{chats:t=[],isSidebarOpen:r=!1,setIsSidebarOpen:j=()=>{},handleCreateChat:y=async()=>{},handleChatSelect:N=()=>{},setChats:v=()=>{},currentChatId:z}=e,R=(0,E.useRouter)(),[J,M]=(0,s.useState)(null),[V,P]=(0,s.useState)(null),[U,_]=(0,s.useState)(""),B=(0,s.useRef)(null),F=(0,s.useMemo)(()=>{let e=new Date,r=new Date(e.getTime()-6048e5),a=new Date(e.getTime()-2592e6);return{last7Days:t.filter(e=>new Date(e.createdAt)>r),last30Days:t.filter(e=>new Date(e.createdAt)<=r&&new Date(e.createdAt)>a),olderByMonth:t.filter(e=>new Date(e.createdAt)<=a).reduce((e,t)=>{let r=new Date(t.createdAt).toLocaleString("default",{month:"long",year:"numeric"});return e[r]||(e[r]=[]),e[r].push(t),e},{})}},[t]),Y=e=>(0,a.jsxs)("div",{className:"mx-2 my-1 p-2 text-white cursor-pointer hover:bg-neutral-800 relative group flex items-center rounded-lg",children:[(0,a.jsx)("div",{onClick:()=>N(e.id),className:"flex-grow overflow-hidden",children:(0,a.jsx)("span",{className:"text-sm truncate block",children:e.name})}),(0,a.jsxs)(x.fC,{children:[(0,a.jsx)(x.xz,{asChild:!0,children:(0,a.jsx)("button",{className:"text-neutral-400 hover:text-white transition-colors ml-2 p-1",children:(0,a.jsx)(n.Z,{size:16})})}),(0,a.jsx)(x.Uv,{children:(0,a.jsxs)(x.VY,{className:"min-w-[200px] bg-neutral-800 rounded-md p-1 z-50 border border-neutral-700",sideOffset:-24,align:"start",alignOffset:48,side:"right",children:[(0,a.jsxs)(x.ck,{className:"text-neutral-200 p-2 cursor-pointer rounded flex items-center transition-colors duration-200 ease-in-out hover:bg-neutral-700 focus:outline-none focus:bg-neutral-700",onSelect:()=>{P(e.id),_(e.name)},children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),"Rename"]}),(0,a.jsxs)(x.ck,{className:"text-red-400 p-2 cursor-pointer rounded flex items-center transition-colors duration-200 ease-in-out hover:bg-neutral-700 focus:outline-none focus:bg-neutral-700",onSelect:()=>M(e.id),children:[(0,a.jsx)(o.Z,{size:16,className:"mr-2"}),"Delete"]})]})})]})]},e.id),L=async e=>{try{let{error:t}=await S.O.from("chats").update({deleted:!0}).eq("id",e);if(t)throw t;v(t=>t.filter(t=>t.id!==e)),M(null);let r=JSON.parse(localStorage.getItem("chatIds")||"[]").filter(t=>t!==e);localStorage.setItem("chatIds",JSON.stringify(r)),e===z&&R.push("/"),b.Am.success("Chat deleted",{description:"The chat has been successfully deleted."})}catch(e){console.error("Error deleting chat:",e),b.Am.error("Error",{description:"An error occurred while deleting the chat. Please try again."})}},T=async(e,t)=>{try{let{error:r}=await S.O.from("chats").update({name:t}).eq("id",e);if(r)throw r;v(r=>r.map(r=>r.id===e?{...r,name:t}:r)),P(null),_(""),b.Am.success("Chat renamed",{description:"The chat has been successfully renamed."})}catch(e){console.error("Error renaming chat:",e),b.Am.error("Error",{description:"An error occurred while renaming the chat. Please try again."})}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"fixed top-0 left-0 z-50 flex items-center h-14 px-4 md:w-[300px] justify-between",children:(0,a.jsx)(f.pn,{children:(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsxs)(f.u,{children:[(0,a.jsx)(f.aJ,{asChild:!0,children:(0,a.jsx)("button",{onClick:()=>j(!r),className:"p-2 text-neutral-300 hover:bg-neutral-800 flex items-center justify-center rounded-md",children:(0,a.jsx)(i.Z,{size:20})})}),(0,a.jsx)(f._v,{side:"bottom",className:"bg-neutral-800 text-white border-neutral-700",children:r?"Close sidebar":"Open sidebar"})]}),(0,a.jsxs)(f.u,{children:[(0,a.jsx)(f.aJ,{asChild:!0,children:(0,a.jsx)("button",{onClick:()=>y(),className:"p-2 text-neutral-300 hover:bg-neutral-800 flex items-center justify-center rounded-md",children:(0,a.jsx)(d.Z,{size:20})})}),(0,a.jsx)(f._v,{side:"bottom",className:"bg-neutral-800 text-white border-neutral-700",children:"New chat"})]})]})})}),(0,a.jsxs)("div",{className:"fixed inset-y-0 left-0 z-30 w-[300px] bg-neutral-950 border-r border-neutral-800 transform transition-transform duration-300 ease-in-out ".concat(r?"translate-x-0":"-translate-x-full"," flex flex-col pt-14"),children:[(0,a.jsxs)("div",{className:"flex flex-col h-[calc(100%-81px)]",children:[(0,a.jsx)(g.default,{href:"/",className:"block px-2 py-1",children:(0,a.jsxs)("div",{className:"flex items-center px-2 py-2 text-white cursor-pointer hover:bg-neutral-800 rounded-lg mt-2 ms-2",children:[(0,a.jsx)(c.Z,{size:20,className:"mr-3 text-neutral-400"}),(0,a.jsx)("span",{className:"text-md font-medium",children:"Home"})]})}),(0,a.jsx)(g.default,{href:"/library",className:"block px-2 py-1",children:(0,a.jsxs)("div",{className:"flex items-center px-2 py-2 text-white cursor-pointer hover:bg-neutral-800 rounded-lg mb-2 ms-2",children:[(0,a.jsx)(u.Z,{size:20,className:"mr-3 text-neutral-400"}),(0,a.jsx)("span",{className:"text-md font-medium",children:"Library"})]})}),(0,a.jsxs)("div",{className:"overflow-y-auto flex-1 px-2 py-1",children:[F.last7Days.length>0&&(0,a.jsxs)("div",{className:"mt-2",children:[(0,a.jsx)("h3",{className:"px-4 py-2 text-xs font-semibold text-neutral-400 uppercase tracking-wider",children:"Previous 7 Days"}),F.last7Days.map(Y)]}),F.last30Days.length>0&&(0,a.jsxs)("div",{className:"mt-4",children:[(0,a.jsx)("h3",{className:"px-4 py-2 text-xs font-semibold text-neutral-400 uppercase tracking-wider",children:"Previous 30 Days"}),F.last30Days.map(Y)]}),Object.entries(F.olderByMonth).map(e=>{let[t,r]=e;return(0,a.jsxs)("div",{className:"mt-4",children:[(0,a.jsx)("h3",{className:"px-4 py-2 text-xs font-semibold text-neutral-400 uppercase tracking-wider",children:t}),r.map(Y)]},t)})]})]}),(0,a.jsx)(w,{open:!!J,onOpenChange:()=>M(null),children:(0,a.jsxs)(k,{className:"bg-neutral-800 border border-neutral-700 !rounded-xl overflow-hidden",children:[(0,a.jsxs)(C,{children:[(0,a.jsx)(I,{className:"text-neutral-100",children:"Delete Chat"}),(0,a.jsx)(O,{className:"text-neutral-400",children:"Are you sure you want to delete this chat? This action cannot be undone."})]}),(0,a.jsxs)(D,{children:[(0,a.jsx)(Z,{className:"bg-neutral-700 text-neutral-100 hover:bg-neutral-600 border border-neutral-700 hover:text-white !rounded-lg",children:"Cancel"}),(0,a.jsx)(A,{onClick:()=>J&&L(J),className:"bg-red-600 text-white hover:bg-red-700 !rounded-lg",children:"Delete"})]})]})}),(0,a.jsx)(w,{open:!!V,onOpenChange:()=>P(null),children:(0,a.jsxs)(k,{className:"bg-neutral-800 border border-neutral-700 !rounded-xl overflow-hidden",children:[(0,a.jsxs)(C,{children:[(0,a.jsx)(I,{className:"text-neutral-100",children:"Rename Chat"}),(0,a.jsx)(O,{className:"text-neutral-400",children:"Enter a new name for this chat."})]}),(0,a.jsx)("input",{ref:B,type:"text",value:U,onChange:e=>_(e.target.value),onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&(e.preventDefault(),V&&T(V,U))},className:"w-full p-2 mb-4 bg-neutral-700 text-neutral-100 border border-neutral-600 !rounded-lg focus:outline-none focus:ring-2 focus:ring-neutral-600",placeholder:"New chat name",autoFocus:!0}),(0,a.jsxs)(D,{children:[(0,a.jsx)(Z,{className:"bg-neutral-700 text-neutral-100 hover:bg-neutral-600 border border-neutral-700 hover:text-white !rounded-lg",children:"Cancel"}),(0,a.jsx)(A,{onClick:()=>V&&T(V,U),className:"bg-neutral-100 text-neutral-900 hover:bg-neutral-200 !rounded-lg",children:"Rename"})]})]})}),(0,a.jsxs)("div",{className:"bg-neutral-950 h-[81px] flex items-center px-6",children:[(0,a.jsx)(h.CH,{children:(0,a.jsx)(g.default,{href:"/pricing",className:"w-full",children:(0,a.jsxs)("button",{className:"w-full bg-neutral-950 text-neutral-300 rounded-lg py-2 px-3 flex items-center justify-center hover:bg-neutral-900 hover:text-white transition-colors text-sm border border-neutral-700",children:[(0,a.jsx)(m.Z,{size:16,className:"mr-2 text-neutral-400"}),"Upgrade to Pro"]})})}),(0,a.jsx)(h.tj,{children:(0,a.jsx)(p.$d,{mode:"modal",children:(0,a.jsxs)("button",{className:"w-full bg-neutral-950 text-neutral-300 rounded-lg py-2 px-3 flex items-center justify-center hover:bg-neutral-900 hover:text-white transition-colors text-sm border border-neutral-700",children:[(0,a.jsx)(m.Z,{size:16,className:"mr-2 text-neutral-400"}),"Upgrade to Pro"]})})})]})]})]})}},94456:function(e,t,r){"use strict";r.d(t,{A:function(){return s}});var a=r(2265);function s(){let[e,t]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{let e=()=>{t(window.innerWidth>=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),{isSidebarOpen:e,toggleSidebar:()=>{t(e=>!e)}}}},50495:function(e,t,r){"use strict";r.d(t,{d:function(){return i},z:function(){return d}});var a=r(57437),s=r(2265),n=r(71538),l=r(12218),o=r(37440);let i=(0,l.j)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),d=s.forwardRef((e,t)=>{let{className:r,variant:s,size:l,asChild:d=!1,...c}=e,u=d?n.g7:"button";return(0,a.jsx)(u,{className:(0,o.cn)(i({variant:s,size:l,className:r})),ref:t,...c})});d.displayName="Button"},98775:function(e,t,r){"use strict";r.d(t,{Toaster:function(){return l}});var a=r(57437),s=r(79512),n=r(27776);let l=e=>{let{...t}=e,{theme:r="system"}=(0,s.F)();return(0,a.jsx)(n.x7,{theme:r,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...t})}},19666:function(e,t,r){"use strict";r.d(t,{_v:function(){return c},aJ:function(){return d},pn:function(){return o},u:function(){return i}});var a=r(57437),s=r(2265),n=r(27071),l=r(37440);let o=n.zt,i=n.fC,d=n.xz,c=s.forwardRef((e,t)=>{let{className:r,sideOffset:s=4,...o}=e;return(0,a.jsx)(n.VY,{ref:t,sideOffset:s,className:(0,l.cn)("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",r),...o})});c.displayName=n.VY.displayName},6881:function(e,t,r){"use strict";r.d(t,{O:function(){return a}});let a=(0,r(84593).eI)("https://etwoeifjnikirptshwzt.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV0d29laWZqbmlraXJwdHNod3p0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjQ5MjY3ODEsImV4cCI6MjA0MDUwMjc4MX0.IqfD3s24ho_jqhOZQdy9BPmXyZsgBg3m-bv84UaN_wQ")},37440:function(e,t,r){"use strict";r.d(t,{cn:function(){return n}});var a=r(44839),s=r(96164);function n(){for(var e=arguments.length,t=Array(e),r=0;r