(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4216],{30635:function(){},49080:function(){},57588:function(){},3071:function(){},15232:function(){},95574:function(e,t,o){Promise.resolve().then(o.bind(o,58387))},58387:function(e,t,o){"use strict";o.r(t);var r=o(57437),i=o(2265),a=o(97082),s=o(54281),n=o(26554);o(36556);var l=o(70996),c=o(78796),d=o(13449),u=o(72760),p=o(26262),h=o(10883),x=o(32191),g=o(25810),m=o(58055),b=o(4360),f=o(60187),j=o(25730),y=o(69340),C=o(22811),w=o(76405),S=o(13821),v=o(48860),k=o(34096),z=o(49270),T=o(27924),E=o(16152),I=o(16595),O=o(31631),D=o(20517),U=o(35088),F=o(70246),L=o(25230),P=o(61576),R=o(16814),W=o(96840),B=o(47749),A=o(238),N=o(37996),Y=o(49089),_=o(22744),M=o(18913),V=o(45202),H=o(63400),Z=o(14700),J=o(34161),q=o.n(J),G=o(47553),Q=o(79637),X=o(70351);o(99882),o(18746);var K=o(64131),$=o(73732),ee=o(14123),et=o(60002),eo=o(93425);X.default.GlobalWorkerOptions.workerSrc="//cdnjs.cloudflare.com/ajax/libs/pdf.js/".concat(X.default.version,"/pdf.worker.js");let er=(0,A.E)(l.xu),ei=new(q()).graphlib.Graph;ei.setDefaultEdgeLabel(()=>({}));let ea=(e,t)=>{ei.setGraph({rankdir:"LR",nodesep:100,ranksep:200}),e.forEach(e=>{ei.setNode(e.id,{width:"centralTopic"===e.type?300:250,height:"centralTopic"===e.type?200:150})}),t.forEach(e=>{ei.setEdge(e.source,e.target)}),q().layout(ei);let o=e.find(e=>"centralTopic"===e.type),r=e.map(e=>{let t=ei.node(e.id);return"centralTopic"===e.type?e.position={x:0,y:0}:e.position={x:t.x-125,y:t.y-75},e});if(o){let e=o.position;r.forEach(t=>{"centralTopic"!==t.type&&(t.position.x-=e.x,t.position.y-=e.y)})}return{nodes:r,edges:t}},es=e=>{let{source:t,onClick:o}=e,{colorMode:i}=(0,ee.If)(),a=(0,et.x)(i);return(0,r.jsx)(l.xu,{bg:"dark"===i?"blue.800":"blue.100",p:2,borderRadius:"md",transition:"all 0.2s",_hover:{transform:"scale(1.05)",boxShadow:"md"},onClick:o,cursor:"pointer",children:(0,r.jsxs)(p.g,{spacing:1,align:"center",color:a.textColor,children:["pdf"===t.type&&(0,r.jsx)(H.ih9,{size:24}),"text"===t.type&&(0,r.jsx)(H.wEQ,{size:24}),"image"===t.type&&(0,r.jsx)(Y.H3h,{size:24}),"youtube"===t.type&&(0,r.jsx)(Y.V2E,{size:24}),"website"===t.type&&(0,r.jsx)(Y.ssk,{size:24}),(0,r.jsx)(b.x,{fontSize:"xs",isTruncated:!0,children:t.name})]})})},en=e=>{let{isOpen:t,onClose:o,source:i}=e,{colorMode:a}=(0,ee.If)(),s=(0,et.x)(a);return i?(0,r.jsxs)(S.u_,{isOpen:t,onClose:o,size:"xl",isCentered:!0,children:[(0,r.jsx)(v.Z,{bg:"dark"===a?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(2px)"}),(0,r.jsxs)(k.h,{bg:s.cardBgColor,children:[(0,r.jsx)(z.x,{color:s.textColor,children:i.name}),(0,r.jsx)(T.o,{color:s.textColor}),(0,r.jsxs)(E.f,{children:["pdf"===i.type&&(0,r.jsx)("iframe",{src:"https://docs.google.com/viewer?url=".concat(encodeURIComponent(i.url),"&embedded=true"),width:"100%",height:"500px"}),"text"===i.type&&(0,r.jsx)(b.x,{whiteSpace:"pre-wrap",color:s.textColor,children:i.content}),"image"===i.type&&(0,r.jsx)(I.E,{src:i.url,alt:i.name,maxW:"100%"}),"youtube"===i.type&&(0,r.jsx)("iframe",{width:"100%",height:"315",src:"https://www.youtube.com/embed/".concat(i.videoId),frameBorder:"0",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0}),"website"===i.type&&(0,r.jsx)("iframe",{src:i.url,width:"100%",height:"500px"})]})]})]}):null},el={customTopic:e=>{let{id:t,data:o}=e,[s,n]=(0,i.useState)(!1),[l,y]=(0,i.useState)(o.label),[C,w]=(0,i.useState)(o.details),{setNodes:S,setEdges:v}=(0,a._K)(),k=(0,c.p)(),{colorMode:z}=(0,ee.If)(),T=(0,et.x)(z),E=(0,i.useCallback)(()=>{n(!1),S(e=>e.map(e=>e.id===t?{...e,data:{...e.data,label:l,details:C}}:e)),k({title:"Topic updated",status:"success",duration:2e3,isClosable:!0})},[t,l,C,S,k]),I=(0,i.useCallback)(()=>{S(e=>e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!0}}:e)),fetch("/api/generate-mindmap",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"elaborate",nodeId:t,nodeContent:"".concat(l,"\n").concat(C)})}).then(e=>e.json()).then(e=>{let o=e.map((e,o)=>({id:"".concat(t,"-elab-").concat(o),type:"customTopic",data:{label:e.label,details:e.details},position:{x:0,y:0}})),r=o.map(e=>({id:"e".concat(t,"-").concat(e.id),source:t,target:e.id}));S(e=>{let{nodes:i,edges:a}=ea([...e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!1}}:e),...o],[...r]);return v(e=>[...e,...a]),i}),k({title:"Topic elaborated",status:"success",duration:2e3,isClosable:!0})}).catch(e=>{console.error("Error elaborating topic:",e),S(e=>e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!1,error:"Failed to elaborate"}}:e)),k({title:"Failed to elaborate topic",status:"error",duration:2e3,isClosable:!0})})},[t,l,C,S,v,k]),O=(0,i.useCallback)(()=>{S(e=>e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!0}}:e)),fetch("/api/generate-mindmap",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"split",nodeId:t,nodeContent:"".concat(l,"\n").concat(C)})}).then(e=>e.json()).then(e=>{let o=e.map((e,o)=>({id:"".concat(t,"-split-").concat(o),type:"customTopic",data:{label:e.label,details:e.details},position:{x:0,y:0}})),r=o.map(e=>({id:"e".concat(t,"-").concat(e.id),source:t,target:e.id}));S(e=>{let{nodes:i,edges:a}=ea([...e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!1}}:e),...o],[...r]);return v(e=>[...e,...a]),i}),k({title:"Topic split",status:"success",duration:2e3,isClosable:!0})}).catch(e=>{console.error("Error splitting topic:",e),S(e=>e.map(e=>e.id===t?{...e,data:{...e.data,isLoading:!1,error:"Failed to split"}}:e)),k({title:"Failed to split topic",status:"error",duration:2e3,isClosable:!0})})},[t,l,C,S,v,k]),D=(0,i.useCallback)(()=>{S(e=>e.filter(e=>e.id!==t&&!e.id.startsWith("".concat(t,"-")))),v(e=>e.filter(e=>e.source!==t&&e.target!==t)),k({title:"Topic deleted",status:"info",duration:2e3,isClosable:!0})},[t,S,v,k]);return(0,r.jsxs)(er,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.3},padding:"4",borderRadius:"md",bg:T.cardBgColor,boxShadow:"lg",border:"2px",borderColor:T.borderColor,width:"250px",fontFamily:"Arial, sans-serif",position:"relative",children:[(0,r.jsx)(a.HH,{type:"target",position:a.Ly.Top,style:{background:"#3182ce",width:"10px",height:"10px"}}),o.isLoading?(0,r.jsx)(d.k,{justify:"center",align:"center",height:"100px",children:(0,r.jsx)(u.$,{size:"lg",color:"purple.500"})}):s?(0,r.jsxs)(p.g,{spacing:2,align:"stretch",children:[(0,r.jsx)(h.I,{value:l,onChange:e=>y(e.target.value),size:"sm",className:"nodrag",placeholder:"Title",bg:T.inputBgColor,color:T.textColor,borderColor:T.borderColor}),(0,r.jsx)(x.g,{value:C,onChange:e=>w(e.target.value),size:"sm",minH:"100px",className:"nodrag",placeholder:"Description",bg:T.inputBgColor,color:T.textColor,borderColor:T.borderColor}),(0,r.jsx)(g.z,{onClick:E,size:"sm",colorScheme:"purple",width:"full",children:"Save"})]}):(0,r.jsxs)(p.g,{spacing:2,align:"stretch",children:[(0,r.jsxs)(m.U,{justify:"space-between",children:[(0,r.jsx)(b.x,{fontWeight:"bold",fontSize:"md",color:T.textColor,children:l}),(0,r.jsx)(f.u,{label:"Delete Topic",children:(0,r.jsx)(j.h,{"aria-label":"Delete Topic",icon:(0,r.jsx)(N.Ybf,{}),size:"sm",variant:"ghost",colorScheme:"red",onClick:D,className:"nodrag"})})]}),(0,r.jsx)(b.x,{fontSize:"sm",color:T.textColor,noOfLines:3,children:C}),o.error&&(0,r.jsx)(b.x,{color:"red.500",fontSize:"sm",children:o.error}),(0,r.jsxs)(m.U,{spacing:2,children:[(0,r.jsx)(f.u,{label:"Edit Topic",children:(0,r.jsx)(j.h,{"aria-label":"Edit Topic",icon:(0,r.jsx)(_.zmo,{}),size:"xl",variant:"ghost",colorScheme:"yellow",onClick:()=>n(!0),className:"nodrag"})}),(0,r.jsx)(f.u,{label:"Elaborate Topic",children:(0,r.jsx)(j.h,{"aria-label":"Elaborate Topic",icon:(0,r.jsx)(_.Yc6,{}),size:"xl",variant:"ghost",colorScheme:"green",onClick:I,isLoading:o.isLoading,className:"nodrag"})}),(0,r.jsx)(f.u,{label:"Split Topic",children:(0,r.jsx)(j.h,{"aria-label":"Split Topic",icon:(0,r.jsx)(_.njj,{}),size:"xl",variant:"ghost",colorScheme:"purple",onClick:O,isLoading:o.isLoading,className:"nodrag"})})]})]}),(0,r.jsx)(a.HH,{type:"source",position:a.Ly.Bottom,style:{background:"#3182ce",width:"10px",height:"10px"}})]})},centralTopic:e=>{let{data:t}=e,[o,a]=(0,i.useState)(null),{isOpen:s,onOpen:n,onClose:l}=(0,y.q)(),{colorMode:c}=(0,ee.If)(),d=(0,et.x)(c),u=e=>{a(e),n()};return(0,r.jsxs)(er,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.5},padding:"6",borderRadius:"lg",bg:"dark"===c?"blue.900":"blue.100",borderWidth:"2px",borderColor:"dark"===c?"blue.700":"blue.300",width:"300px",fontFamily:"Arial, sans-serif",position:"relative",color:d.textColor,children:[(0,r.jsxs)(p.g,{spacing:3,align:"stretch",children:[(0,r.jsx)(b.x,{fontWeight:"bold",fontSize:"xl",textAlign:"center",children:t.label}),(0,r.jsx)(C.i,{borderColor:"dark"===c?"blue.700":"blue.300"}),(0,r.jsx)(b.x,{fontSize:"sm",fontWeight:"medium",children:"Sources:"}),(0,r.jsx)(w.M,{columns:2,spacing:2,children:t.sources.map((e,t)=>(0,r.jsx)(es,{source:e,onClick:()=>u(e)},t))})]}),(0,r.jsx)(en,{isOpen:s,onClose:l,source:o})]})},sourceNode:e=>{let{data:t}=e,[o,s]=(0,i.useState)(!1),{colorMode:n}=(0,ee.If)(),l=(0,et.x)(n);return(0,r.jsxs)(er,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{duration:.3},padding:"4",borderRadius:"md",bg:"dark"===n?"blue.900":"blue.100",boxShadow:"md",border:"2px",borderColor:"dark"===n?"blue.700":"blue.300",width:"200px",fontFamily:"Arial, sans-serif",position:"relative",onClick:()=>s(!0),cursor:"pointer",_hover:{boxShadow:"lg",transform:"translateY(-2px)"},children:[(0,r.jsxs)(p.g,{spacing:2,align:"center",children:["pdf"===t.type&&(0,r.jsx)(H.ih9,{size:24,color:l.iconColor}),"text"===t.type&&(0,r.jsx)(H.wEQ,{size:24,color:l.iconColor}),"image"===t.type&&(0,r.jsx)(Y.H3h,{size:24,color:l.iconColor}),"youtube"===t.type&&(0,r.jsx)(Y.V2E,{size:24,color:l.iconColor}),"website"===t.type&&(0,r.jsx)(Y.ssk,{size:24,color:l.iconColor}),(0,r.jsx)(b.x,{fontWeight:"bold",fontSize:"sm",color:l.textColor,children:t.name}),(0,r.jsx)(b.x,{fontSize:"xs",color:l.textColor,noOfLines:2,children:(()=>{switch(t.type){case"pdf":case"text":return t.name;case"image":return"Image file";case"youtube":return"YouTube Video";case"website":return t.url;default:return"Unknown source"}})()})]}),(0,r.jsx)(a.HH,{type:"target",position:a.Ly.Top,style:{background:"#3182CE"}}),(0,r.jsx)(en,{isOpen:o,onClose:()=>s(!1),source:t})]})}},ec=async e=>{let t=await e.arrayBuffer();return new Blob([eo.ZP.deflate(new Uint8Array(t))],{type:"application/octet-stream"})},ed=e=>{let{isOpen:t,onClose:o}=e,{colorMode:i}=(0,ee.If)(),a=(0,et.x)(i);return(0,r.jsxs)(S.u_,{isOpen:t,onClose:o,isCentered:!0,size:"xl",mx:"1rem",children:[(0,r.jsx)(v.Z,{bg:"dark"===i?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(3px)"}),(0,r.jsxs)(k.h,{bg:a.cardBgColor,borderRadius:"lg",overflow:"hidden",boxShadow:"xl",mx:"1rem",children:[(0,r.jsx)(T.o,{color:a.textColor}),(0,r.jsx)(E.f,{py:8,children:(0,r.jsxs)(p.g,{spacing:6,align:"stretch",children:[(0,r.jsx)(O.X,{fontSize:"2xl",color:"dark"===i?"white":"purple.600",textAlign:"center",children:"AI Mindmap Creator"}),(0,r.jsx)(b.x,{fontSize:"md",textAlign:"center",color:a.textColor,children:"Explore, expand, and enrich your thoughts with AI-powered mind mapping."}),(0,r.jsxs)(w.M,{columns:2,spacing:6,children:[(0,r.jsx)(eu,{icon:Y.Tlm,title:"Expand Topics",description:"Dive deeper into any topic with AI suggestions."}),(0,r.jsx)(eu,{icon:Y.Gq2,title:"Smart Upload",description:"Analyze and integrate various file types."}),(0,r.jsx)(eu,{icon:Y.ssk,title:"Web Insights",description:"Add web content to your map instantly."}),(0,r.jsx)(eu,{icon:Y.V2E,title:"Video Integration",description:"Extract key points from YouTube videos."})]})]})}),(0,r.jsx)(D.m,{bg:"dark"===i?"gray.800":"gray.50",children:(0,r.jsx)(g.z,{colorScheme:"purple",size:"md",width:"full",onClick:o,_hover:{bg:"purple.500"},_active:{bg:"purple.600"},children:"Get Started"})})]})]})},eu=e=>{let{icon:t,title:o,description:i}=e,{colorMode:a}=(0,ee.If)(),s=(0,et.x)(a);return(0,r.jsxs)(m.U,{align:"start",spacing:3,children:[(0,r.jsx)(l.xu,{color:"purple.500",children:(0,r.jsx)(t,{size:24})}),(0,r.jsxs)(p.g,{align:"start",spacing:1,children:[(0,r.jsx)(b.x,{fontWeight:"semibold",fontSize:"sm",color:s.textColor,children:o}),(0,r.jsx)(b.x,{fontSize:"xs",color:"dark"===a?"gray.400":"gray.500",children:i})]})]})},ep=e=>{let{isOpen:t,onClose:o,attachmentType:i,websiteUrl:a,setWebsiteUrl:s,youtubeUrl:n,setYoutubeUrl:l,handleWebsiteScrape:c,handleYoutubeTranscript:d,isLoading:u}=e,{colorMode:x}=(0,ee.If)(),m=(0,et.x)(x),b=e=>{"Enter"===e.key&&(e.preventDefault(),"website"===i?c():"youtube"===i&&d())};return(0,r.jsxs)(S.u_,{isOpen:t,onClose:o,isCentered:!0,size:"md",children:[(0,r.jsx)(v.Z,{bg:"dark"===x?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)"}),(0,r.jsxs)(k.h,{bg:m.cardBgColor,borderRadius:"lg",children:[(0,r.jsxs)(z.x,{fontSize:"lg",color:m.textColor,children:["website"===i&&"Upload Website","youtube"===i&&"Upload a YouTube video"]}),(0,r.jsx)(T.o,{color:m.textColor}),(0,r.jsxs)(E.f,{pb:4,children:["website"===i&&(0,r.jsxs)(p.g,{spacing:3,align:"stretch",children:[(0,r.jsx)(h.I,{rounded:"md",value:a,onChange:e=>s(e.target.value),onKeyPress:b,placeholder:"https://example.com",size:"sm",bg:m.inputBgColor,color:m.textColor,borderColor:m.borderColor}),(0,r.jsx)(g.z,{colorScheme:"blue",size:"sm",onClick:c,isLoading:u,loadingText:"Scraping...",leftIcon:(0,r.jsx)(Y.ssk,{}),width:"full",children:"Upload Site"})]}),"youtube"===i&&(0,r.jsxs)(p.g,{spacing:3,align:"stretch",children:[(0,r.jsx)(h.I,{value:n,onChange:e=>l(e.target.value),onKeyPress:b,placeholder:"https://www.youtube.com/watch?v=...",size:"sm",bg:m.inputBgColor,color:m.textColor,borderColor:m.borderColor}),(0,r.jsx)(g.z,{colorScheme:"red",size:"sm",onClick:d,isLoading:u,loadingText:"Fetching Transcript...",leftIcon:(0,r.jsx)(Y.V2E,{}),width:"full",children:"Upload Video"})]})]})]})]})},eh=()=>{let[e,t,o]=(0,a.Rr)([]),[x,C,w]=(0,a.ll)([]),[S,v]=(0,i.useState)(""),[k,z]=(0,i.useState)(!1),T=(0,c.p)(),E=(0,i.useRef)(null),[D,A]=(0,i.useState)(null),[_,J]=(0,i.useState)([]),[q,eo]=(0,i.useState)(null),[er,ei]=(0,i.useState)(null),[es,en]=(0,i.useState)(""),[eu,eh]=(0,i.useState)(null),[eg,em]=(0,i.useState)(0),[eb,ef]=(0,i.useState)(!1),ej=(0,i.useRef)(null),ey=(0,i.useRef)(null),eC=(0,i.useRef)(null),{isOpen:ew,onOpen:eS,onClose:ev}=(0,y.q)(),[ek,ez]=(0,i.useState)(""),[eT,eE]=(0,i.useState)(""),{isOpen:eI,onOpen:eO,onClose:eD}=(0,y.q)(),[eU,eF]=(0,i.useState)([]),[eL,eP]=(0,i.useState)(!1),[eR,eW]=(0,i.useState)(!1),[eB,eA]=(0,i.useState)(null),{isOpen:eN,onOpen:eY,onClose:e_}=(0,y.q)(),[eM,eV]=(0,i.useState)(""),[eH,eZ]=(0,i.useState)(!1),eJ=(0,i.useRef)(null),[eq,eG]=(0,i.useState)(!1);(0,a._K)();let[eQ,eX]=(0,i.useState)(!1),{colorMode:eK}=(0,ee.If)(),e$=(0,et.x)(eK),e0=(0,ee.ff)("gray.700","gray.200");(0,i.useEffect)(()=>{K.Z.get("hasSeenMindmapWelcome")||eZ(!0)},[]),(0,i.useEffect)(()=>{(async()=>{try{let e=await fetch("/api/get-user"),t=await e.json();A(t.messagesPerMonth)}catch(e){console.error("Error fetching mindmap credits:",e),T({title:"Error",description:"Failed to fetch remaining credits. Please try again.",status:"error",duration:3e3,isClosable:!0})}})()},[T]);let e1=(0,i.useCallback)(async e=>{try{let t=await fetch("/api/decrement-messages",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({amount:e})});if(!t.ok)throw Error("Failed to decrement messages");let o=await t.json();A(o.messagesRemaining)}catch(e){console.error("Error decrementing messages:",e),T({title:"Error",description:"Failed to update message count. Please try again.",status:"error",duration:3e3,isClosable:!0})}},[T]),e2=async e=>{try{let t=await X.default.getDocument(URL.createObjectURL(e)).promise;eh(t.numPages);let o="";for(let e=1;e<=t.numPages;e++){let r=await t.getPage(e),i=await r.getTextContent();o+=i.items.map(e=>"str"in e?e.str:"").join(" ")+"\n",em(e/t.numPages*100)}return o}catch(e){throw console.error("Error extracting text from PDF:",e),Error("Failed to extract text from PDF: ".concat(e.message))}},e3=async e=>{let t=e[0];if(t){eP(!0);try{eo(t);let e=new FileReader;e.onloadend=()=>{ei(e.result),eP(!1),e_()},e.readAsDataURL(t)}catch(e){console.error("Error processing image:",e),T({title:"Error",description:"Failed to process the image. Please try again.",status:"error",duration:3e3,isClosable:!0}),eP(!1)}}},e5=async e=>{if(e.length+_.length>3){T({title:"Maximum of 3 files can be attached",status:"warning",duration:3e3,isClosable:!0});return}eW(!0);let t=[];for(let o of e){if(o.size>10485760){T({title:"File size too large",description:"".concat(o.name," is too large. (over 10MB)"),status:"error",duration:3e3,isClosable:!0});continue}em(0);let e="";try{if("text/plain"===o.type||o.type.includes("javascript")||o.type.includes("python"))e=(await o.text()).split("\n").slice(0,100).join("\n");else if("application/pdf"===o.type){let t=await e2(o);e=t.split(" ").slice(0,200).join(" "),en(t)}else e=o.type.startsWith("image/")?"Image file":await o.text();let r=await ec(o);t.push({file:r,name:o.name,type:o.type,previewContent:e,isCode:o.type.includes("javascript")||o.type.includes("python")}),em(100)}catch(e){console.error("Error processing file:",e),T({title:"Error",description:"Failed to process ".concat(o.name,". ").concat(e.message),status:"error",duration:3e3,isClosable:!0})}}J(e=>[...e,...t]),eW(!1),e_()},e4=e=>{J(t=>t.filter((t,o)=>o!==e))},e6=async()=>{if(!eT){T({title:"Please enter a valid URL",status:"warning",duration:2e3,isClosable:!0});return}z(!0);try{let e=await fetch("/api/scrape-website",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:eT})});if(!e.ok)throw Error("Failed to scrape website");let t=await e.json();eF(e=>[...e,{url:eT,content:t.text}]),T({title:"Website scraped successfully",status:"success",duration:2e3,isClosable:!0}),eD()}catch(e){console.error("Error scraping website:",e),T({title:"Failed to scrape website",description:e.message,status:"error",duration:2e3,isClosable:!0})}finally{z(!1)}},e7=e=>{eF(t=>t.filter((t,o)=>o!==e))},e8=e=>{var t,o;"website"===e?(eA("website"),eY()):"image"===e?null===(t=ey.current)||void 0===t||t.click():"document"===e?null===(o=ej.current)||void 0===o||o.click():"youtube"===e&&(eA("youtube"),eY())},e9=async()=>{if(!eM){T({title:"Please enter a valid YouTube URL",status:"warning",duration:2e3,isClosable:!0});return}z(!0);try{let e=await fetch("/api/youtube-transcript",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:eM})});if(!e.ok)throw Error("Failed to fetch YouTube transcript");let t=await e.json();eF(e=>[...e,{url:eM,content:"YouTube Summary: ".concat(t.summary,"\n\nTranscript Preview: ").concat(t.transcriptPreview)}]),T({title:"YouTube transcript fetched and summarized successfully",status:"success",duration:2e3,isClosable:!0}),e_()}catch(e){console.error("Error fetching YouTube transcript:",e),T({title:"Failed to fetch YouTube transcript",description:e.message,status:"error",duration:2e3,isClosable:!0})}finally{z(!1)}},te=(0,i.useCallback)(()=>{t([]),C([]),eG(!1),eX(!1),T({title:"Mindmap cleaned up",status:"info",duration:2e3,isClosable:!0})},[t,C,T]),tt=(0,i.useCallback)(()=>{null!==E.current&&(0,$.YM)(E.current,{filter:e=>{var t,o;return!((null==e?void 0:null===(t=e.classList)||void 0===t?void 0:t.contains("react-flow__minimap"))||(null==e?void 0:null===(o=e.classList)||void 0===o?void 0:o.contains("react-flow__controls")))}}).then(e=>{let t=document.createElement("a");t.download="mindmap.png",t.href=e,t.click()})},[]),to=async()=>{if(!S.trim()&&0===_.length&&!q&&0===eU.length){T({title:"Please enter a topic, attach files, or scrape a website",status:"warning",duration:2e3,isClosable:!0});return}if(D<=0){eS();return}z(!0);try{let e="",o="";for(let t of _)if("application/pdf"===t.type)e+="PDF Content (".concat(t.name,"): ").concat(es,"\n\n"),o+="\uD83D\uDCC4 ".concat(t.name,"\n");else if("text/plain"===t.type||t.isCode){let r=await t.file.text();e+="File Content (".concat(t.name,"): ").concat(r,"\n\n"),o+="\uD83D\uDCDD ".concat(t.name,"\n")}let r="";if(q){let t=new FormData;t.append("image",q),t.append("messages",JSON.stringify([{role:"user",content:S}]));let i=await fetch("/api/image-reader",{method:"POST",body:t});i.ok&&(r=await i.text(),e+="Image Description: ".concat(r,"\n\n"),o+="\uD83D\uDDBC️ Uploaded Image\n")}for(let t of eU)e+="Scraped Website Content (".concat(t.url,"): ").concat(t.content,"\n\n"),o+="\uD83C\uDF10 ".concat(t.url,"\n");let i="".concat(S,"\n\nContext:\n").concat(e),a=await fetch("/api/generate-mindmap",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"generate",topic:i})});if(!a.ok)throw Error("Failed to generate mindmap");let s=await a.json(),n=[],l=[],c=[];for(let e of _){let t={id:"source-".concat(n.length),type:"sourceNode",data:{type:"application/pdf"===e.type?"pdf":"text",name:e.name,url:URL.createObjectURL(e.file),preview:e.previewContent.slice(0,100)+"...",content:"application/pdf"===e.type?es:await e.file.text()},position:{x:0,y:0}};n.push(t.data),l.push(t),c.push({id:"e-central-".concat(t.id),source:"central-node",target:t.id})}if(q){let e={id:"source-".concat(n.length),type:"sourceNode",data:{type:"image",name:q.name,url:URL.createObjectURL(q),preview:"Image file"},position:{x:0,y:0}};n.push(e.data),l.push(e),c.push({id:"e-central-".concat(e.id),source:"central-node",target:e.id})}for(let e of eU){let t={id:"source-".concat(n.length),type:"sourceNode",data:{type:e.url.includes("youtube.com")||e.url.includes("youtu.be")?"youtube":"website",name:e.url.includes("youtube.com")||e.url.includes("youtu.be")?"YouTube Video":new URL(e.url).hostname,url:e.url,videoId:e.url.includes("youtube.com")||e.url.includes("youtu.be")?ex(e.url):null,preview:e.content.slice(0,100)+"...",content:e.content},position:{x:0,y:0}};n.push(t.data),l.push(t),c.push({id:"e-central-".concat(t.id),source:"central-node",target:t.id})}let d=[{id:"central-node",type:"centralTopic",data:{label:S||"Mindmap",sources:n},position:{x:0,y:0}},...l,...s.nodes.map(e=>({...e,type:"customTopic"}))],u=[...c,...s.edges],{nodes:p,edges:h}=ea(d,u);t(p),C(h),eX(!0),T({title:"Your mindmap is ready!",status:"success",duration:2e3,isClosable:!0}),v(""),J([]),eo(null),ei(null),eF([]),e1(5),eG(!0);let x=await fetch("/api/save-mindmap",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({nodes:s.nodes,edges:s.edges,title:S||"Untitled Mindmap"})});if(!x.ok)throw Error("Failed to save mindmap");let{threadId:g}=await x.json();T({title:"Mindmap generated and saved",status:"success",duration:2e3,isClosable:!0})}catch(e){console.error("Error generating mindmap:",e),T({title:"Oops! Something went wrong",description:"We couldn't create your mindmap. Please try again.",status:"error",duration:3e3,isClosable:!0})}finally{z(!1)}},tr=(0,i.useCallback)(o=>{let{nodes:r,edges:i}=ea(e,(0,a.Z_)(o,x));C(i),t(r)},[e,x,C,t]);return(0,r.jsxs)(d.k,{height:"100vh",bg:e$.bgColor,direction:"row",children:[(0,r.jsx)(G.Z,{}),(0,r.jsxs)(d.k,{flex:"1",direction:"column",position:"relative",children:[(0,r.jsxs)(l.xu,{bg:e$.cardBgColor,px:8,py:4,boxShadow:"sm",zIndex:1e3,children:[(0,r.jsxs)(m.U,{maxW:"1200px",mx:"auto",align:"center",children:[(0,r.jsxs)(m.U,{spacing:3,children:[(0,r.jsx)(V.DQb,{size:24,color:e$.iconColor}),(0,r.jsx)(O.X,{as:"h1",size:"md",color:e0,children:"AI Mindmap Creator"})]}),(0,r.jsx)(U.L,{}),(0,r.jsxs)(m.U,{spacing:4,children:[null!==D&&(0,r.jsx)(f.u,{label:"Available Credits",children:(0,r.jsx)(g.z,{leftIcon:(0,r.jsx)(M.wT4,{}),onClick:eS,variant:"outline",size:"sm",colorScheme:"purple",children:D})}),eq&&(0,r.jsx)(f.u,{label:"Start Fresh",children:(0,r.jsx)(j.h,{icon:(0,r.jsx)(Y.mz2,{}),onClick:te,variant:"outline",size:"sm",colorScheme:"red","aria-label":"Start fresh"})}),eQ&&(0,r.jsx)(f.u,{label:"Save as Image",children:(0,r.jsx)(j.h,{icon:(0,r.jsx)(Y.aBF,{}),onClick:tt,variant:"outline",size:"sm",colorScheme:"green","aria-label":"Save as image"})})]})]}),(0,r.jsxs)(m.U,{as:"form",onSubmit:e=>{e.preventDefault(),to()},width:"100%",mt:4,spacing:4,ref:eC,onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),ef(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation();let t=eC.current.getBoundingClientRect();(e.clientX<t.left||e.clientX>=t.right||e.clientY<t.top||e.clientY>=t.bottom)&&ef(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:e=>{e.preventDefault(),e.stopPropagation(),ef(!1);let t=[...e.dataTransfer.files];t.some(e=>e.type.startsWith("image/"))?e3(t.filter(e=>e.type.startsWith("image/"))):e5(t)},borderWidth:2,borderStyle:"dashed",borderColor:eb?"purple.500":"transparent",borderRadius:"md",transition:"all 0.2s",bg:eb?e$.hoverBgColor:"transparent",py:2,children:[(0,r.jsx)(h.I,{ref:eJ,value:S,onChange:e=>v(e.target.value),placeholder:"What would you like to create a mindmap about?",size:"md",variant:"filled",bg:e$.inputBgColor,_hover:{bg:e$.hoverBgColor},_focus:{bg:e$.cardBgColor,borderColor:"purple.500"},color:e$.textColor}),(0,r.jsxs)(F.J,{children:[(0,r.jsx)(L.x,{children:(0,r.jsx)(j.h,{icon:(0,r.jsx)(Z.U,{}),"aria-label":"Add content",size:"md",colorScheme:"blue",variant:"outline"})}),(0,r.jsxs)(P.y,{bg:e$.cardBgColor,borderColor:e$.borderColor,children:[(0,r.jsx)(R.Q,{bg:e$.cardBgColor}),(0,r.jsx)(W.b,{py:"1rem",children:(0,r.jsxs)(p.g,{spacing:2,align:"stretch",children:[(0,r.jsx)(g.z,{leftIcon:(0,r.jsx)(Y.ssk,{}),onClick:()=>e8("website"),variant:"outline",colorScheme:"blue",children:"Add Website Content"}),(0,r.jsx)(g.z,{leftIcon:(0,r.jsx)(Y.H3h,{}),onClick:()=>e8("image"),variant:"outline",colorScheme:"purple",children:"Add Image"}),(0,r.jsx)(g.z,{leftIcon:(0,r.jsx)(Y.pPO,{}),onClick:()=>e8("document"),variant:"outline",colorScheme:"orange",children:"Add File"}),(0,r.jsx)(g.z,{leftIcon:(0,r.jsx)(Y.V2E,{}),onClick:()=>e8("youtube"),variant:"outline",colorScheme:"red",children:"Add YouTube Video"})]})})]})]}),(0,r.jsx)(f.u,{label:"Create Mindmap",children:(0,r.jsx)(j.h,{type:"submit",icon:(0,r.jsx)(Y.Y2X,{}),isLoading:k,colorScheme:"purple","aria-label":"Create mindmap"})})]}),(0,r.jsx)("input",{type:"file",accept:".txt,.pdf,.js,.jsx,.ts,.tsx,.py,.java,.c,.cpp",multiple:!0,onChange:e=>e5(Array.from(e.target.files)),ref:ej,style:{display:"none"}}),(0,r.jsx)("input",{type:"file",accept:"image/*",onChange:e=>e3(Array.from(e.target.files)),ref:ey,style:{display:"none"}}),_.length>0&&(0,r.jsx)(p.g,{mt:4,align:"stretch",children:_.map((e,t)=>(0,r.jsxs)(m.U,{justify:"space-between",bg:e$.hoverBgColor,p:2,borderRadius:"md",children:[(0,r.jsxs)(m.U,{children:["application/pdf"===e.type?(0,r.jsx)(H.ih9,{color:e$.iconColor}):"text/plain"===e.type?(0,r.jsx)(H.wEQ,{color:e$.iconColor}):(0,r.jsx)(H.opy,{color:e$.iconColor}),(0,r.jsx)(b.x,{color:e$.textColor,children:e.name})]}),(0,r.jsx)(j.h,{icon:(0,r.jsx)(N.Ybf,{}),size:"sm",variant:"ghost",colorScheme:"red",onClick:()=>e4(t)})]},t))}),eU.length>0&&(0,r.jsx)(p.g,{mt:4,align:"stretch",children:eU.map((e,t)=>(0,r.jsxs)(m.U,{justify:"space-between",bg:e$.hoverBgColor,p:2,borderRadius:"md",children:[(0,r.jsxs)(m.U,{children:[(0,r.jsx)(Y.ssk,{color:e$.iconColor}),(0,r.jsx)(b.x,{color:e$.textColor,children:e.url})]}),(0,r.jsx)(j.h,{icon:(0,r.jsx)(N.Ybf,{}),size:"sm",variant:"ghost",colorScheme:"red",onClick:()=>e7(t)})]},t))}),er&&(0,r.jsx)(l.xu,{mt:4,children:(0,r.jsx)(I.E,{src:er,alt:"Uploaded image",rounded:"xl",maxH:"100px",objectFit:"contain"})}),eg>0&&eg<100&&(0,r.jsx)(B.E,{value:eg,size:"sm",colorScheme:"purple",mt:2})]}),(0,r.jsx)(l.xu,{flex:"1",width:"100%",height:"100%",ref:E,children:(0,r.jsxs)(a.x$,{nodes:e,edges:x,onNodesChange:o,onEdgesChange:w,onConnect:tr,nodeTypes:el,fitView:!0,attributionPosition:"bottom-right",children:[(0,r.jsx)(s.A,{color:"dark"===eK?"#333":"#aaa",gap:16}),(0,r.jsx)(n.Z,{})]})}),(0,r.jsx)(ep,{isOpen:eN,onClose:e_,attachmentType:eB,websiteUrl:eT,setWebsiteUrl:eE,youtubeUrl:eM,setYoutubeUrl:eV,handleWebsiteScrape:e6,handleYoutubeTranscript:e9,isLoading:k}),k&&(0,r.jsxs)(d.k,{position:"absolute",top:0,left:0,right:0,bottom:0,bg:"dark"===eK?"rgba(0, 0, 0, 0.8)":"rgba(255, 255, 255, 0.8)",justifyContent:"center",alignItems:"center",zIndex:10,direction:"column",children:[(0,r.jsx)(u.$,{size:"xl",color:"purple.500",mb:4}),(0,r.jsx)(b.x,{fontSize:"2xl",fontWeight:"bold",color:e$.textColor,children:"Creating your mindmap..."})]}),(0,r.jsx)(ed,{isOpen:eH,onClose:()=>{eZ(!1),K.Z.set("hasSeenMindmapWelcome","true",{expires:365}),eJ.current&&eJ.current.focus()}})]}),(0,r.jsx)(Q.Z,{isOpen:ew,onClose:ev})]})},ex=e=>{let t=e.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/);return t&&11===t[2].length?t[2]:null};t.default=()=>(0,r.jsx)(a.tV,{children:(0,r.jsx)(eh,{})})}},function(e){e.O(0,[1627,2046,7699,8310,5505,3665,9212,5452,8422,9956,5129,3125,7259,6051,780,9997,6137,6580,1760,9784,6971,5567,2972,5878,6349,605,4680,210,5401,5250,7553,2971,2117,1744],function(){return e(e.s=95574)}),_N_E=e.O()}]);