1import{d as V,j as e,u as le,U as re,t as he}from"./index-b1g_5Tpl.js";import{r as s,L as ge,u as fe,c as be,e as je}from"./vendor-react-CO4_mtH0.js";import{u as we}from"./useLogout-BjJ-kJuB.js";import{S as oe,C as ne,p as se,a as ye}from"./ConfirmationDialog-Dfz098me.js";import{s as ce}from"./study-plans-J9Xr10Qy.js";import{g as L}from"./utils-CHcZDCx0.js";import{p as J,i as me,E as ve,D as Ne}from"./index-CPGz38F8.js";import"./button-DXM6MrAY.js";const K={async uploadDocuments(t,n){const r=new FormData;return t.forEach(i=>{r.append("documents[]",i)}),n!==void 0&&r.append("project_id",n.toString()),(await V.post("/upload-documents",r,{headers:{"Content-Type":"multipart/form-data"}})).data},async checkUrl(t){const n={url:t};return(await V.post("/check-url",n)).data},async uploadWeblinks(t,n){const r=n!==void 0?{weblinks:t,project_id:n}:{weblinks:t};return(await V.post("/upload-weblinks",r)).data},async saveProjectNotes(t){return(await V.post("/save-project-notes",t)).data},async downloadDocument(t){return(await V.post("/download-document",t,{responseType:"blob"})).data},async deleteDocument(t){const n=btoa(t);return(await V.delete(`/delete-document/${n}`)).data},async deleteWeblink(t){const n=btoa(t);return(await V.delete(`/delete-weblink/${n}`)).data},async editWeblink(t,n,r){return(await V.put(`/update-weblink/${t}`,{title:n,description:r})).data},async editDocument(t,n,r){return(await V.put(`/update-document/${t}`,{title:n,description:r})).data},async uploadRawText(t){const n={content:t.content};return t.title!==void 0&&(n.title=t.title),t.project_id!==void 0&&(n.project_id=t.project_id),(await V.post("/upload-raw-text",n)).data},async updateRawText(t,n){return(await V.put(`/update-raw-text/${t}`,n)).data},async deleteRawText(t){return(await V.delete(`/delete-raw-text/${t}`)).data}};function xe({title:t,description:n,onTitleChange:r,onDescriptionChange:m,onSave:i,onCancel:j,error:v,isLoading:p=!1}){return e.jsxs("div",{className:"p-3 bg-blue-50 rounded-lg border border-blue-200 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-700 mb-1",children:"Title (optional, but useful for prompting our AI systems)"}),e.jsx("input",{type:"text",value:t,onChange:f=>r(f.target.value),placeholder:"Enter title",className:"w-full rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 focus:border-blue-500 focus:outline-none",disabled:p})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-700 mb-1",children:"Description (optional, but useful for prompting our AI systems)"}),e.jsx("textarea",{value:n,onChange:f=>m(f.target.value),placeholder:"Enter description",className:"w-full rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-900 focus:border-blue-500 focus:outline-none resize-none",rows:3,disabled:p})]}),v&&e.jsx("div",{className:"rounded-lg border border-red-300 bg-red-50 p-3",children:e.jsx("p",{className:"text-sm font-medium text-red-900",children:v})}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:j,disabled:p,className:"rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 hover:bg-slate-50 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Cancel"}),e.jsx("button",{onClick:i,disabled:p,className:"rounded-lg border border-blue-300 bg-blue-50 px-3 py-2 text-sm font-medium text-blue-900 hover:bg-blue-100 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:p?"Saving...":"Save"})]})]})}function pe({title:t,description:n,displayText:r,metadata:m,href:i,onPrimaryAction:j,onEdit:v,onDelete:p,icon:f,isEditing:w,editForm:h}
1){if(w&&h)return e.jsx("li",{children:h});const g=i?"a":"button",u=i?{href:i,target:"_blank",rel:"nofollow noreferrer"}:{onClick:j};return e.jsx("li",{children:e.jsxs("div",{className:"flex items-start justify-between p-3 bg-slate-50 rounded-lg border border-slate-200 hover:bg-slate-100 hover:border-slate-300 transition-all group",children:[e.jsxs(g,{...u,className:"flex items-start gap-3 flex-1 min-w-0 text-left",children:[f,e.jsxs("div",{className:"flex-1 min-w-0",children:[t&&e.jsx("p",{className:"text-sm font-medium text-slate-900 truncate",children:t}),n&&e.jsx("p",{className:"text-xs text-slate-600 line-clamp-2 mt-1",children:n}),!t&&!n&&e.jsx("p",{className:"text-sm font-medium text-slate-900 truncate",children:r}),m&&e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:m})]})]}),e.jsxs("div",{className:"flex gap-2 ml-2 sm:ml-4",children:[e.jsxs("button",{onClick:v,className:"flex items-center gap-1 sm:gap-2 px-2 py-1.5 text-sm font-medium text-slate-600 bg-slate-100 border border-slate-200 rounded hover:bg-slate-200 hover:text-blue-600 hover:border-slate-300 flex-shrink-0 transition-all mr-1 sm:mr-3",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),e.jsxs("span",{className:"hidden sm:inline",children:[!t&&!n?"Add":"Edit"," Title and Description"]}),e.jsx("span",{className:"sm:hidden",children:!t&&!n?"Add":"Edit"})]}),e.jsx("button",{onClick:p,className:"p-2 text-slate-400 hover:text-red-600 flex-shrink-0 transition-colors",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})})}const ke=new Set(["application/pdf","text/plain","text/markdown","text/x-markdown","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.oasis.opendocument.text","image/jpeg","image/png","image/webp","image/tiff","image/bmp"]),Se=new Set(["pdf","txt","doc","docx","xls","xlsx","md","ppt","pptx","jpg","jpeg","png","webp","tiff","bmp","odt"]),ue=t=>{const n=t.name.split(".").pop()?.toLowerCase()??"";return ke.has(t.type)||Se.has(n)};function Ce({project:t,maxDocumentsAllowed:n,maxDocumentSize:r,hasExistingStudyPlan:m,onDocumentsUploaded:i,onDownloadDocument:j,onDeleteDocument:v,onEditDocument:p}){const{user:f,refetchUser:w}=le(),[h,g]=s.useState([]),[u,k]=s.useState(!1),[l,y]=s.useState(!1),[b,D]=s.useState(null),[_,A]=s.useState(!1),[U,T]=s.useState(null),[$,O]=s.useState(""),[I,R]=s.useState(""),[P,B]=s.useState(null),[W,M]=s.useState(null),[F,S]=s.useState(null),[C,H]=s.useState(null),Y=f?.plan?.max_document_size,E=a=>Y?a.size<=Y*1024:!0,q=a=>{const x=Y?Math.round(Y/1024):0,z=a.map(Q=>Q.name).join(", ");return e.jsxs(e.Fragment,{children:["The file",a.length>1?"s":""," ",e.jsx("strong",{children:z})," ",a.length>1?"are":"is"," too large for your current"," ",f?.plan?.name||""," plan (limit: ",x," MB per file)."," ",e.jsx("button",{onClick:()=>{window.location.href="/#pricing"},className:"underline font-semibold hover:opacity-80",children:"Upgrade Plan"})]})},ee=a=>{const x=Array.from(a.target.files||[]).filter(ue),z=x.filter(ae=>!E(ae));if(z.length>0){D(q(z)),a.target.value="";return}D(null);const Q=[...h,...x].slice(0,n);g(Q)},X=a=>{a.preventDefault(),a.stopPropagation(),k(!0)},c=a=>{a.preventDefault(),a.stopPropagation(),k(!1)},G=a=>{a.preventDefault(),a.stopPropagation()},Z=a=>{a.preventDefault(),a.stopPropagation(),k(!1);const x=Array.from(a.dataTransfer.files).filter(ue),z=x.filter(ae=>!E(ae));if(z.length>0){D(q(z));return}const Q=[...h,...x];if(Q.length>n){D(`Maximum ${n} files allowed.`);return}D(null),g(Q.slice(0,n))},te=async()=>{y(!0),D(null);try{await K.uploadDocuments(h,t?.id),await w(),g([]),M("Document uploaded successfully!"),setTimeout(()=>M(null),5e3),await i?.()}catch(a){const x=L(a,"Failed to upload documents");D(J(x))}finally{y(!1)}},ie=async()=>
1{if(h.length!==0){if(t?.id&&m){A(!0);return}await te()}},de=async()=>{A(!1),await te()},o=()=>{F&&(v(F),S(null),M("Document deleted successfully!"),setTimeout(()=>M(null),5e3))},d=async(a,x,z)=>{B(null);try{await p(a,x,z),T(null),M("Document updated successfully!"),setTimeout(()=>M(null),3e3)}catch(Q){B(J(L(Q,"Failed to update document")))}},N=async(a,x)=>{H(null);try{await j(a,x)}catch(z){H(L(z,"Failed to download document"))}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{onDragEnter:X,onDragLeave:c,onDragOver:G,onDrop:Z,className:["relative rounded-lg border-2 border-dashed p-6 text-center transition-all duration-200 cursor-pointer",u?"border-blue-400 bg-blue-50":"border-slate-200 bg-white hover:border-slate-300 hover:bg-slate-50"].join(" "),children:[e.jsx("input",{type:"file",accept:".pdf,.txt,.doc,.docx,.xls,.xlsx,.md,.ppt,.pptx,.jpg,.jpeg,.png,.webp,.tiff,.bmp,.odt",multiple:!0,onChange:ee,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),e.jsxs("div",{className:"pointer-events-none flex flex-col items-center gap-2",children:[e.jsx("svg",{className:`h-10 w-10 transition-colors ${u?"text-blue-400":"text-slate-300"}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})}),e.jsx("p",{className:"text-sm text-slate-600",children:u?e.jsx("span",{className:"font-semibold text-blue-600",children:"Drop files here"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-semibold",children:"Click to upload"})," or drag & drop"]})}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Photos of book pages · Infographics · Diagrams · Notes · Slides · Books â Images (JPG/PNG/WEBP), PDF, Word, Excel, PowerPoint, ODT, TXT, MD · up to ",n," file",n!==1?"s":""," (",f?.plan?.name||"current"," plan)"]})]})]}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs text-slate-500 text-center",children:[h.length," of ",n," file",h.length!==1?"s":""," selected"]}),h.map((a,x)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2",children:[e.jsx("svg",{className:"h-4 w-4 text-slate-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),e.jsx("span",{className:"flex-1 text-sm text-slate-700 truncate",children:a.name}),e.jsxs("span",{className:"text-xs text-slate-400 flex-shrink-0",children:[(a.size/1024).toFixed(0)," KB"]}),e.jsx("button",{onClick:()=>g(z=>z.filter((Q,ae)=>ae!==x)),disabled:l,className:"text-slate-400 hover:text-red-500 disabled:opacity-40 transition-colors",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},x)),e.jsx("button",{onClick:ie,disabled:l,className:"w-full rounded-lg bg-blue-700 px-4 py-2.5 text-sm font-semibold text-white hover:bg-blue-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:l?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8z"})]}),"Uploadingâ¦"]}):`Upload ${h.length} file${h.length!==1?"s":""}`})]}),b&&e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:b}),e.jsx("button",{onClick:()=>D(null),className:"ml-2 flex-shrink-0 text-red-400 hover:text-red-600",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),W&&e.jsx(oe,{message:W,onDismiss:()=>M(null),showStudyPlanWarning:m}),C&&e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:C}),e.jsx("button",{onClick:()=>H(null),className:"ml-2 flex-shrink-0 text-red-400 hover:text-red-600",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"bg-white rounded-lg border border-slate-200 p-4 min-h-16",children:t?.documents&&t.documents.length>0?e.jsxs("div",{children:[e.jsx("ul",{className:"space-y-2",children:t.documents.map((a,x)=>
1e.jsx(pe,{title:a.title,description:a.description,displayText:a.original_filename,metadata:`${a.original_filename} · ${a.mime_type} · ${(a.size/1024).toFixed(2)} KB`,onPrimaryAction:()=>N(a.path,a.original_filename),onEdit:()=>{T(a.path),O(a.title||""),R(a.description||""),B(null)},onDelete:()=>S(a.path),icon:e.jsx("svg",{className:"w-5 h-5 text-slate-500 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),isEditing:U===a.path,editForm:e.jsx(xe,{title:$,description:I,onTitleChange:O,onDescriptionChange:R,onSave:()=>d(a.id,$,I),onCancel:()=>{T(null),B(null)},error:P})},x))}),e.jsx("div",{className:"mt-4 text-right",children:e.jsxs("p",{className:"text-sm text-slate-700",children:[e.jsx("span",{className:"font-medium mr-3",children:"Total Size:"}),e.jsxs("span",{className:"font-semibold text-slate-900 mr-1",children:[(t.documents.reduce((a,x)=>a+x.size,0)/(1024*1024)).toFixed(2)," MB"]}),e.jsxs("span",{className:"text-xs mr-3",children:["of ",((r||0)/1e3).toFixed()," MB available."]}),e.jsx(re,{})]})})]}):e.jsx("div",{className:"flex items-center justify-center h-full py-2",children:e.jsx("p",{className:"text-sm text-slate-400",children:"No documents imported yet"})})}),e.jsx(ne,{isOpen:_,onConfirm:de,onCancel:()=>A(!1),title:"Upload New Document",message:"You already have a study plan for this project. Uploading new documents will require regenerating your study plan.",confirmText:"Upload Anyway",cancelText:"Cancel",variant:"warning",showStudyPlanWarning:!0}),e.jsx(ne,{isOpen:F!==null,onConfirm:o,onCancel:()=>S(null),title:"Delete Document",message:"Are you sure you want to delete this document? This action cannot be undone.",confirmText:"Delete",cancelText:"Cancel",variant:"danger",showStudyPlanWarning:m})]})}function De({project:t,maxWeblinksAllowed:n,hasExistingStudyPlan:r,onWeblinksUploaded:m,onDeleteWeblink:i,onEditWeblink:j}){const{user:v}=le(),[p,f]=s.useState(""),[w,h]=s.useState(!1),[g,u]=s.useState(!1),[k,l]=s.useState(null),[y,b]=s.useState(null),[D,_]=s.useState(!1),[A,U]=s.useState(null),[T,$]=s.useState(""),[O,I]=s.useState(""),[R,P]=s.useState(null),[B,W]=s.useState(null),[M,F]=s.useState(null),S=t?.weblinks?.length??0,C=async c=>{u(!0),b(null);try{await K.uploadWeblinks([c],t?.id),W("Web link added successfully!"),setTimeout(()=>W(null),5e3),await m?.()}catch(G){b(J(L(G,"Failed to save web link")))}finally{u(!1)}},H=async()=>{const c=p.trim();if(!(!c||!n||X)){try{new URL(c)}catch{b("Please enter a valid URL");return}h(!0),b(null);try{const G=await K.checkUrl(c),Z={url:c,title:G.title,description:G.description};f(""),r&&t?.id?(l(Z),_(!0)):await C(Z)}catch(G){b(J(L(G,"Failed to check URL")))}finally{h(!1)}}},Y=c=>{c.key==="Enter"&&(c.preventDefault(),H())},E=async()=>{_(!1),k&&(await C(k),l(null))},q=()=>{M&&(i(M),F(null),W("Web link deleted successfully!"),setTimeout(()=>W(null),5e3))},ee=async(c,G,Z)=>{P(null);try{await j(c,G,Z),U(null),W("Web link updated successfully!"),setTimeout(()=>W(null),3e3)}catch(te){P(J(L(te,"Failed to update web link")))}},X=S>=n;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"url",value:p,onChange:c=>f(c.target.value),onKeyDown:Y,placeholder:"https://example.com",disabled:X||w||g,className:"flex-1 rounded-lg border border-slate-200 bg-white px-4 py-2.5 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-100 disabled:bg-slate-50 disabled:text-slate-400"}),e.jsx("button",{onClick:H,disabled:!p.trim()||X||w||g,className:"w-full sm:w-auto rounded-lg bg-blue-700 px-5 py-2.5 text-sm font-semibold text-white hover:bg-blue-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:w||g?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8z"})]}),w?"Checkingâ¦":"Savingâ¦"]}):"Add"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-1",children:["Only pure HTML pages supported",e.jsxs("span",{className:"relative group inline-block align-middle focus:outline-none",tabIndex:0,"aria-label":"More info",children:[e.jsx("svg",{className:"h-3.5 w-3.5 text-slate-400 cursor-help",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-56 rounded-lg bg-slate-900 px-3 py-2 text-xs text-white/80 opacity-0 group-hover:opacity-100 group-focus:opacity-100 transition-opacity pointer-events-none z-10 whitespace-normal",children:"JavaScript-rendered pages (SPAs) may not import
1correctly."})]})]}),e.jsxs("span",{children:[S," / ",n," links"]})]})]}),y&&e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:y}),e.jsx("button",{onClick:()=>b(null),className:"ml-2 flex-shrink-0 text-red-400 hover:text-red-600",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),B&&e.jsx(oe,{message:B,onDismiss:()=>W(null),showStudyPlanWarning:r}),e.jsx("div",{className:"bg-white rounded-lg border border-slate-200 p-4 min-h-16",children:t?.weblinks&&t.weblinks.length>0?e.jsxs("div",{children:[e.jsx("ul",{className:"space-y-2",children:t.weblinks.map((c,G)=>e.jsx(pe,{title:c.title,description:c.description,displayText:c.link,metadata:c.link,href:c.link,onEdit:()=>{U(c.link),$(c.title||""),I(c.description||""),P(null)},onDelete:()=>F(c.link),icon:e.jsx("svg",{className:"w-5 h-5 text-slate-500 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.658 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})}),isEditing:A===c.link,editForm:e.jsx(xe,{title:T,description:O,onTitleChange:$,onDescriptionChange:I,onSave:()=>ee(c.id,T,O),onCancel:()=>{U(null),P(null)},error:R})},G))}),e.jsx("div",{className:"mt-4 text-right",children:e.jsxs("p",{className:"text-sm text-slate-700",children:[e.jsx("span",{className:"font-medium mr-2",children:"Total Web Links:"}),e.jsx("span",{className:"font-semibold text-slate-900",children:t.weblinks.length}),e.jsxs("span",{className:"text-xs ml-1 mr-2",children:["of ",v?.plan.max_weblinks_number," available."]}),e.jsx(re,{})]})})]}):e.jsx("div",{className:"flex items-center justify-center py-2",children:e.jsx("p",{className:"text-sm text-slate-400",children:"No web links saved yet"})})}),e.jsx(ne,{isOpen:D,onConfirm:E,onCancel:()=>_(!1),title:"Add New Web Links",message:"You already have a study plan for this project. Adding new web links will require regenerating your study plan to include the new content.",confirmText:"Add Anyway",cancelText:"Cancel",variant:"warning",showStudyPlanWarning:!0}),e.jsx(ne,{isOpen:M!==null,onConfirm:q,onCancel:()=>F(null),title:"Delete Web Link",message:"Are you sure you want to delete this web link? This action cannot be undone.",confirmText:"Delete",cancelText:"Cancel",variant:"danger",showStudyPlanWarning:r})]})}function Ee({project:t,hasExistingStudyPlan:n,onRawTextUploaded:r}){const[m,i]=s.useState(""),[j,v]=s.useState(""),[p,f]=s.useState(!1),[w,h]=s.useState(null),[g,u]=s.useState(!1),[k,l]=s.useState(null),[y,b]=s.useState(!1),[D,_]=s.useState(""),[A,U]=s.useState(""),[T,$]=s.useState(!1),[O,I]=s.useState(null),[R,P]=s.useState(!1),[B,W]=s.useState(!1),M=t?.raw_texts?.[0]??null,[F,S]=s.useState(null);s.useEffect(()=>{S(null)},[t?.raw_texts]);const C=F===null?M:F==="deleted"?null:M?{...M,title:F.title,content:F.content}:null,H=!!C,Y=async()=>{f(!0),h(null);try{await K.uploadRawText({title:m.trim()||void 0,content:j.trim(),project_id:t?.id}),i(""),v(""),l("Raw text saved successfully!"),setTimeout(()=>l(null),5e3),await r?.()}catch(c){h(J(L(c,"Failed to save raw text")))}finally{f(!1)}},E=async()=>{if(j.trim()){if(n){u(!0);return}await Y()}},q=()=>{C&&(_(C.title??""),U(C.content),I(null),b(!0))},ee=async()=>{if(!(!C||!A.trim())){$(!0),I(null);try{await K.updateRawText(C.id,{title:D.trim()||void 0,content:A.trim()}),S({title:D.trim()||void 0,content:A.trim()}),b(!1),l("Raw text updated successfully!"),setTimeout(()=>l(null),4e3),r?.()}catch(c){I(J(L(c,"Failed to update raw text")))}finally{$(!1)}}},X=async()=>{if(C){W(!0);try{await K.deleteRawText(C.id),S("deleted"),P(!1),b(!1),l("Raw text deleted successfully!"),setTimeout(()=>l(null),5e3),r?.()}catch(c){P(!1),h(J(L(c,"Failed to delete raw text")))}finally{W(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[!H&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",value:m,onChange:c=>i(c.target.value),placeholder:"Title (optional)",disabled:p,className:"w-full rounded-lg border border-slate-200 bg-white px-4 py-2.5 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-100 disabled:bg-slate-50 disabled:text-slate-400"}),e.jsx("textarea",{value:j,onChange:c=>v(c.target.value),placeholder:"Paste or type your text hereâ¦",rows:10,disabled:p,className:"w-full rounded-lg border border-slate-200 bg-white px-4 py-3 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-100 disabled:bg-slate-50 disabled:text-slate-400 resize-y"}),e.jsx("button",{onClick:E,disabled:!j.trim()||p,className:"w-full rounded-lg bg-blue-700 px-4 py-2.5 text-sm font-semibold text-white hover:bg-blue-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:p?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v8z"})]}),"Savingâ¦"]}):"Save"})]}),C&&e.jsx("div",{className:"bg-white rounded-lg border border-slate-200 p-4",children:y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"text",value:D,onChange:c=>_(c.target.value),placeholder:"Title (optional)",disabled:T,className:"w-full rounded-lg border border-slate-200 bg-white px-4 py-2 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-100 disabled:bg-slate-50"}),e.jsx("textarea",{value:A,onChange:c=>U(c.target.value),rows:10,disabled:T,className:"w-full rounded-lg border border-slate-200 bg-white px-4 py-3 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-100 disabled:bg-slate-50 resize-y"}),O&&e.jsx("p",{className:"text-xs text-red-600",children:O}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:ee,disabled:!A.trim()||T,className:"flex-1 rounded-lg bg-blue-700 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:T?"Savingâ¦":"Save changes"}),e.jsx("button",{onClick:()=>b(!1),disabled:T,className:"rounded-lg border border-slate-200 px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-50 disabled:opacity-50 transition-colors",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[C.title&&e.jsx("p",{className:"text-sm font-medium text-slate-800 mb-1",children:C.title}),e.jsx("div",{className:"max-h-96 overflow-y-auto rounded border border-slate-100 bg-slate-50 px-3 py-2 text-xs text-slate-600 whitespace-pre-wrap leading-relaxed",children:C.content})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs("button",{onClick:q,className:"flex items-center gap-1 px-2 py-1.5 text-sm font-medium text-slate-600 bg-slate-100 border border-slate-200 rounded hover:bg-slate-200 hover:text-blue-600 transition-all",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),e.jsx("span",{className:"hidden sm:inline",children:"Edit"})]}),e.jsx("button",{onClick:()=>P(!0),disabled:B,className:"p-1.5 text-slate-400 hover:text-red-600 disabled:opacity-40 transition-colors",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})}),w&&e.jsxs("div",{className:"flex items-start justify-between gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:[e.jsx("span",{children:w}),e.jsx("button",{onClick:()=>h(null),className:"ml-2 flex-shrink-0 text-red-400 hover:text-red-600",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),k&&e.jsx(oe,{message:k,onDismiss:()=>l(null),showStudyPlanWarning:n}),e.jsx(ne,{isOpen:g,onConfirm:async()=>{u(!1),await Y()},onCancel:()=>u(!1),title:"Add Raw Text",message:"You already have a study plan for this project. Adding new content will require regenerating your study plan.",confirmText:"Save Anyway",cancelText:"Cancel",variant:"warning",showStudyPlanWarning:!0}),e.jsx(ne,{isOpen:R,onConfirm:X,onCancel:()=>P(!1),title:"Delete Raw Text",message:"Are you sure you want to delete this text snippet? This action cannot be undone.",confirmText:"Delete",cancelText:"Cancel",variant:"danger",showStudyPlanWarning:n})]})}const Le=[{id:"documents",label:"Import Documents",shortLabel:"Documents"},{id:"weblinks",label:"Import from Web Links",shortLabel:"Web Links"},{id:"text",label:"Import raw Text",shortLabel:"Raw Text"}];function Pe({project:t,maxDocumentsAllowed:n,maxDocumentSize:r,maxWeblinksAllowed:m,hasExistingStudyPlan:i,onDocumentsUploaded:j,onDownloadDocument:v,onDeleteDocument:p,onEditDocument:f,onWeblinksUploaded:w,onDeleteWeblink:h,onEditWeblink:g,onRawTextUploaded:u}){const[k,l]=s.useState("documents"),y={documents:t?.documents?.length??0,weblinks:t?.weblinks?.length??0,text:t?.raw_texts?.length??0};return e.jsxs("div",{className:"border border-slate-200 rounded-lg bg-white overflow-hidden",children:[e.jsx("div",{className:"flex border-b border-slate-200 bg-slate-50 px-2 sm:px-4 pt-3 pb-0 gap-1 sm:gap-2",children:Le.map(b=>e.jsxs("button",{onClick:()=>l(b.id),className:["flex-1 sm:flex-none px-2 sm:px-4 py-2 text-xs sm:text-sm font-medium rounded-t-lg border border-b-0 transition-colors text-center",k===b.id?"border-slate-300 bg-white text-blue-700 -mb-px":"border-transparent text-slate-500 hover:text-slate-700 hover:border-slate-200"].join(" "),children:[e.jsx("span",{className:"sm:hidden",children:b.shortLabel}),e.jsx("span",{className:"hidden sm:inline",children:b.label}),y[b.id]>0&&e.jsx("span",{className:["ml-1.5 inline-flex items-center justify-center rounded-full px-1.5 py-0.5 text-xs font-semibold leading-none",k===b.id?"bg-blue-100 text-blue-700":"bg-slate-200 text-slate-600"].join(" "),children:y[b.id]})]},b.id))}),e.jsxs("div",{className:"p-4 sm:p-6",children:[k==="documents"&&e.jsx(Ce,{project:t,maxDocumentsAllowed:n,maxDocumentSize:r,hasExistingStudyPlan:i,onDocumentsUploaded:j,onDownloadDocument:v,onDeleteDocument:p,onEditDocument:f}),k==="weblinks"&&e.jsx(De,{project:t,maxWeblinksAllowed:m,hasExistingStudyPlan:i,onWeblinksUploaded:w,onDeleteWeblink:h,onEditWeblink:g}),k==="text"&&e.jsx(Ee,{project:t,hasExistingStudyPlan:i,onRawTextUploaded:u})]})]})}function Me({notes:t,onNotesChange:n,onSave:r,isSaving:m,successMessage:i,errorMessage:j,hasSelectedProject:v,hasExistingStudyPlan:p,onDismissSuccess:f}){return e.jsxs("div",{className:"mt-8 sm:mt-18",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("svg",{className:"w-5 h-5 text-slate-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),e.jsxs("label",{className:"text-sm font-medium text-slate-700",children:["My Personal Notes",e.jsx("small",{className:"ml-1",children:"(optional, but useful for prompting our AI systems)"})]})]}),e.jsxs("div",{className:"text-xs text-slate-500 mb-3 mx-2 sm:mx-7 space-y-1",children:[e.jsx("p",{children:"My learning goals and context for this project. Include:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-2",children:[e.jsx("li",{children:"Who am I? Student, professional, ..."}),e.jsx("li",{children:"My specific objectives and goals"}),e.jsx("li",{children:"Why do I want to study this topic?"}),e.jsx("li",{children:"Desired proficiency level: Basic, Intermediate, or Advanced"}),e.jsx("li",{children:"Context: Professional, School, or Private"}),e.jsx("li",{children:"Key information to focus on or prioritize"})]})]}),i&&e.jsx(oe,{message:i,onDismiss:f,showStudyPlanWarning:p}),j&&e.jsx("div",{className:"rounded-lg border border-red-300 bg-red-50 p-3 mb-3",children:e.jsx("p",{className:"text-sm font-medium text-red-900",children:j})}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("textarea",{value:t,onChange:w=>n(w.target.value),disabled:m,placeholder:"Write your personal notes, insights, or summaries here...",className:"w-full rounded-lg border-2 border-slate-200 bg-white px-4 py-3 text-sm text-slate-900 transition-all focus:border-blue-500 focus:outline-none disabled:bg-slate-100 resize-none",rows:4}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:r,disabled:m||!t.trim()&&!v,className:"rounded-lg border-2 border-green-300 bg-green-50 px-4 py-2 text-sm font-medium text-green-900 hover:bg-green-100 hover:border-green-400 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:m?"Saving...":"Save Notes"})})]})]})}function Te({projectId:t,personalNotes:n,hasExistingStudyPlan:r,hasDocumentsOrWeblinks:m,onGenerateSuccess:i}){const{user:j}=le(),v=j?me(j):!1,[p,f]=s.useState(!1),[w,h]=s.useState(!1),[g,u]=s.useState(null),[k,l]=s.useState(null),[y,b]=s.useState(null),[D,_]=s.useState(0),[A,U]=s.useState(null),[T,$]=s.useState(r),[O,I]=s.useState(!1),R=s.useRef(0),P=s.useRef(0);s.useEffect(()=>{$(r)},[r]),s.useEffect(()=>{if(!y){R.current=0,P.current=0,I(!1);return}const S=120,C=5,H=60,Y=setInterval(async()=>
1{if(R.current>=S){console.error("Polling timeout: Maximum polling time (10 minutes) exceeded"),l("Study plan generation is taking longer than expected. We will send you an e-mail when ready."),u(null),b(null);return}if(P.current>=C){console.error("Polling stopped: Too many consecutive errors"),u("Unable to check study plan status due to repeated errors. Please try again later."),b(null),h(!1),l(null);return}R.current+=1,R.current===H&&(I(!0),console.log("Study plan generation taking longer than 5 minutes"));try{const E=await ce.checkStatus(y,t);if(console.log("Study plan status:",E),P.current=0,E.failed){b(null),h(!1),l(null),u(J(E.error||"Study plan generation failed. Please try again."));return}E.progress!==void 0&&E.progress!==null&&typeof E.progress=="number"?(_(E.progress),U(E.progress_stage??null),console.log(`Progress updated: ${E.progress}% (Stage: ${E.progress_stage||"N/A"})`)):console.log("No valid progress in response:",E.progress),E.ready&&(b(null),_(100),h(!1),$(!0),l("Your study plan is ready!"),R.current=0,P.current=0,console.log("Study plan ready:",E),he("study_plan_generated",{project_id:t}),i&&i())}catch(E){const q=L(E,"Failed to check status");console.error(`Failed to check study plan status (attempt ${R.current}):`,q),P.current+=1,console.error("Error details:",E)}},5e3);return()=>clearInterval(Y)},[y,i,t]);const B=async()=>{h(!0),u(null),l(null),_(0),U(null),$(!1),I(!1),R.current=0,P.current=0;try{const S=await ce.generateStudyPlan({project_id:t,personal_notes:n});S.job_id&&S.status==="queued"?(l("Your study plan generation started. It may take some time. Wait inline or you will be notified via mail when your Personal Plan is ready."),b(S.job_id),console.log("Study plan generation started:",S)):h(!1)}catch(S){const C=L(S,"Failed to generate study plan");u(J(C)),console.error("Failed to generate study plan:",C),S?.response?.status!==409&&h(!1)}},W=()=>{if(!m){u("Add at least one Document, Web Link, or Raw Text to elaborate your Study Plan. What do you want to study?");return}n.trim()?B():f(!0)},M=()=>{f(!1);const S=document.querySelector('textarea[placeholder*="Write your personal notes"]');S&&(S.focus(),S.scrollIntoView({behavior:"smooth",block:"center"}))},F=()=>{f(!1),B()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-8",children:[y&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-sm font-medium text-slate-700",children:["Generating your study plan... ",e.jsxs("small",{children:["(",A?.replace(/_/g," "),")"]})]}),e.jsxs("span",{className:"text-sm font-semibold text-green-600",children:[D,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-200 rounded-full h-3 overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-green-500 to-green-600 h-3 rounded-full transition-all duration-500 ease-out",style:{width:`${D}%`}})})]}),k&&e.jsx("div",{className:"rounded-lg border border-green-300 bg-green-50 p-3 mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[y&&e.jsxs("svg",{className:"animate-spin h-5 w-5 text-green-600",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),e.jsx("p",{className:"text-sm font-medium text-green-900",children:k})]})}),O&&e.jsx("div",{className:"rounded-lg border border-blue-300 bg-blue-50 p-3 mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("svg",{className:"w-5 h-5 text-blue-600 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm font-medium text-blue-900",children:"Your study plan creation is taking longer. You will be notified via email when it's ready."})]})}),g&&e.jsx("div",{className:"rounded-lg border border-red-300 bg-red-50 p-3 mb-4",children:e.jsx("p",{className:"text-sm font-medium text-red-900",children:g})}),e.jsx("div",{className:"flex flex-col items-center gap-3",children:v?e.jsxs("div",{className:"w-full max-w-2xl rounded-lg border border-red-200 bg-red-50 px-4 py-4 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-red-700 mb-3",children:"Your access has expired. Purchase a new pack to generate study plans."}),e.jsx(re,{children:"Pick a Pack"})]}):T?e.jsxs(e.Fragment,{children:[e.jsx(ge,{to:`/study-plan/pr/${t}`,className:"w-full max-w-2xl rounded-lg bg-blue-800 px-4 sm:px-8 py-4 sm:py-6 text-base sm:text-xl font-bold text-white uppercase hover:bg-blue-700 transition-all shadow-lg hover:shadow-xl text-center",children:"GO TO STUDY PLAN"}),e.jsx("button",{onClick:W,disabled:w||!!y,className:"text-sm text-slate-600 hover:text-blue-600 underline transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Re-generate Study Plan"})]}):e.jsx("button",{onClick:W,disabled:w||!!y,className:"w-full max-w-2xl rounded-lg bg-green-600 px-4 sm:px-8 py-4 sm:py-6 text-base sm:text-xl font-bold text-white uppercase hover:bg-green-700 transition-all shadow-lg hover:shadow-xl disabled:opacity-50 disabled:cursor-not-allowed",children:w?"GENERATING STUDY PLAN...":"GENERATE YOUR STUDY PLAN"})})]}),p&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 p-4",children:e.jsxs("div",{className:"max-w-lg w-full rounded-lg bg-white p-4 sm:p-6 shadow-xl",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 mb-4",children:"Personal Notes Recommended"}),e.jsx("p",{className:"text-sm text-slate-700 mb-6",children:"Before you proceed, it would be useful for you to add some personal notes. They are not mandatory, but can be helpful in defining the right context information and achieving more coherent output."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:justify-end",children:[e.jsx("button",{onClick:M,className:"rounded-lg bg-green-600 px-6 py-3 text-sm font-semibold text-white hover:bg-green-700 transition-all",children:"Add Personal Notes and Context Info"}),e.jsx("button",{onClick:F,className:"rounded-lg border-2 border-slate-300 bg-white px-6 py-3 text-sm font-semibold text-slate-900 hover:bg-slate-50 transition-all",children:"Proceed Anyway"})]})]})})]})}function We({selectedProject:t,personalNotes:n,setPersonalNotes:r,isSavingNotes:m,successMessage:i,errorMessage:j,hasExistingStudyPlan:v,onDownloadDocument:p,onDeleteDocument:f,onDeleteWeblink:w,onEditWeblink:h,onEditDocument:g,onSaveNotes:u,onWeblinksSuccess:k,onDocumentsSuccess:l,onRawTextSuccess:y,onDismissNotesSuccess:b}){const{user:D}=le(),_=D?.plan?.max_documents_number??0,A=D?.plan?.max_document_size??0,U=D?.plan?.max_weblinks_number??0,T=(t?.documents?.length??0)>0||(t?.weblinks?.length??0)>0||(t?.raw_texts?.length??0)>0;return e.jsxs("div",{className:"border border-slate-200 rounded-lg bg-slate-50 mt-8 p-4 sm:p-6",children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide mb-6",children:"My Learning Sources"}
1),e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsx(Pe,{project:t,maxDocumentsAllowed:_,maxDocumentSize:A,maxWeblinksAllowed:U,hasExistingStudyPlan:v,onDocumentsUploaded:l,onDownloadDocument:p,onDeleteDocument:f,onEditDocument:g,onWeblinksUploaded:k,onDeleteWeblink:w,onEditWeblink:h,onRawTextUploaded:y}),e.jsx(Me,{notes:n,onNotesChange:r,onSave:u,isSaving:m,successMessage:i,errorMessage:j??null,hasSelectedProject:!!t,hasExistingStudyPlan:v,onDismissSuccess:b}),t&&e.jsx(Te,{projectId:t.id,personalNotes:n,hasExistingStudyPlan:v,hasDocumentsOrWeblinks:T,onGenerateSuccess:l})]})]})}function _e({onProjectCreated:t}){const[n,r]=s.useState(!1),[m,i]=s.useState(""),[j,v]=s.useState(!1),[p,f]=s.useState(null),w=()=>{const g=new Date,u=l=>String(l).padStart(2,"0"),k=`${g.getFullYear()}-${u(g.getMonth()+1)}-${u(g.getDate())} ${u(g.getHours())}:${u(g.getMinutes())}:${u(g.getSeconds())}`;i(`Unnamed Project ${k}`),f(null),r(!0)},h=async()=>{const g=m.trim()||m;v(!0);try{const u=await se.createProject({name:g});r(!1),t(u)}catch(u){f(L(u,"Failed to create project"))}finally{v(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:w,className:"rounded-lg bg-green-500 px-6 py-3 text-base font-semibold text-white hover:bg-green-600 transition-all shadow-md hover:shadow-lg uppercase flex items-center gap-2",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Start new Project or GOAL"]}),n&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>r(!1),children:e.jsxs("div",{className:"w-full max-w-md rounded-xl bg-white p-6 shadow-xl mx-4",onClick:g=>g.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-900 mb-4",children:"New Project Name"}),e.jsx("input",{type:"text",value:m,onChange:g=>i(g.target.value),onKeyDown:g=>{g.key==="Enter"&&h(),g.key==="Escape"&&r(!1)},disabled:j,autoFocus:!0,className:"w-full rounded-lg border-2 border-slate-200 bg-white px-4 py-2 text-sm text-slate-900 focus:border-green-500 focus:outline-none disabled:bg-slate-100",placeholder:"Enter project name or goal..."}),p&&e.jsx("p",{className:"mt-3 text-sm text-red-600",children:p}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>r(!1),disabled:j,className:"rounded-lg border border-slate-200 px-4 py-2 text-sm font-medium text-slate-600 hover:bg-slate-50 transition-all disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:h,disabled:j,className:"rounded-lg bg-green-500 px-4 py-2 text-sm font-semibold text-white hover:bg-green-600 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:j?"Creating...":"Continue"})]})]})})]})}function Ae({user:t}){if(!t.access_ends_at)return null;const n=new Date(t.access_ends_at),r=new Date,m=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24)),i=n<=r,j=!i&&m<=ve;return!i&&!j?null:e.jsxs("div",{className:`mb-6 rounded-lg border px-4 py-4 ${i?"border-red-200 bg-red-50":"border-amber-200 bg-amber-50"}`,children:[e.jsx("p",{className:`mb-1 text-xs font-medium uppercase tracking-wide ${i?"text-red-500":"text-amber-500"}`,children:i?"Access Expired":"Expiring Soon"}),e.jsx("p",{className:`text-lg font-bold ${i?"text-red-800":"text-amber-800"}`,children:i?`Expired on ${n.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})}`:`Expires ${n.toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})} (${m}d left)`}),e.jsx("p",{className:`mt-1 text-sm ${i?"text-red-700":"text-amber-700"}`,children:i?"Your access has ended. Purchase a new pack to continue studying.":"Expiring soon â get another pack to extend your access seamlessly."}),e.jsx("div",{className:"mt-3",children:e.jsx(re,{children:i?"Pick a Pack":"Extend Access"})})]})}function Fe({project:t,onRename:n}){const[r,m]=s.useState(!1),[i,j]=s.useState(!1),[v,p]=s.useState(""),f=async()=>{if(v.trim()){j(!0);try{const w=await se.updateProject(t.id,{name:v});n(w),m(!1),p("")}catch(w){console.error("Failed to rename project:",L(w,"Failed to rename project"))}finally{j(!1)}}};return r?e.jsxs("div",{className:"flex gap-3 w-full items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-500 uppercase tracking-wide mb-2",children:"New Project Name"}
1),e.jsx("input",{type:"text",value:v,onChange:w=>p(w.target.value),onKeyDown:w=>{w.key==="Enter"&&f()},disabled:i,autoFocus:!0,className:"w-full rounded-lg border-2 border-slate-200 bg-white px-4 py-2 text-sm text-slate-900 transition-all focus:border-green-500 focus:outline-none disabled:bg-slate-100",placeholder:"Enter new Project Name or Goal. Example: CCIE Exam, AI Certification, etc.."})]}),e.jsx("button",{onClick:f,disabled:!v.trim()||i,className:"rounded-lg border-2 border-green-300 bg-green-50 px-4 py-2 text-sm font-medium text-green-900 hover:bg-green-100 hover:border-green-400 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:i?"Saving...":"Save"}),e.jsx("button",{onClick:()=>{m(!1),p("")},disabled:i,className:"rounded-lg border-2 border-slate-300 bg-white px-4 py-2 text-sm font-medium text-slate-900 hover:bg-slate-50 hover:border-slate-400 transition-all disabled:opacity-50",children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border border-slate-200 rounded-lg bg-slate-50 mt-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-slate-500 uppercase tracking-wide",children:"Project Name"}),e.jsx("p",{className:"text-lg font-semibold text-slate-900 mt-1",children:t.name})]}),e.jsx("button",{onClick:()=>{p(t.name),m(!0)},className:"rounded-lg border-1 border-green-300 bg-green-50 px-4 py-2 text-sm font-medium text-green-600 hover:bg-green-100 hover:border-green-400 transition-all",children:"Rename Project"})]})}function He(){const t=fe(),n=be(),[r,m]=je(),{user:i,isLoading:j,refetchUser:v}=le(),[p,f]=s.useState(null),[w,h]=s.useState(null),g=we(),[u,k]=s.useState([]),[l,y]=s.useState(null),b=s.useRef(!1),D=s.useRef(null),[_,A]=s.useState(""),[U,T]=s.useState(!1),[$,O]=s.useState(null),[I,R]=s.useState(null),[P,B]=s.useState(!1),[W,M]=s.useState(0),[F,S]=s.useState(!1),C=async()=>{const o=await se.getProjects();k(o),o.length>0&&y(o[0]),M(d=>d+1)},H=async()=>{await v(),await C()};s.useEffect(()=>{if(!localStorage.getItem("auth_token")){t("/login");return}},[t]),s.useEffect(()=>{i&&(async()=>{try{const d=await se.getProjects();k(d),d.length>0&&y(d[0])}catch(d){console.error("Failed to fetch projects:",L(d,"Failed to load projects"))}})()},[i]),s.useEffect(()=>{const o=n.state;if(o?.selectedProjectId&&u.length>0&&!b.current){const d=u.find(N=>N.id===o.selectedProjectId);d&&(y(d),b.current=!0,t(n.pathname,{replace:!0,state:{}}))}},[n.state,u,t,n.pathname]),s.useEffect(()=>{b.current=!1},[n.pathname]),s.useEffect(()=>{const o=r.get("gdrive_import");if(o==="success"){const d=r.get("gdrive_filename");f(`Document "${d}" correctly imported from Google Drive. Proceed creating your study Plan.`)}else if(o==="error"){const d=r.get("gdrive_message");h(d||"Google Drive import failed. Please try again.")}o&&(r.delete("gdrive_import"),r.delete("gdrive_filename"),r.delete("gdrive_message"),m(r,{replace:!0}))},[]),s.useEffect(()=>{if(!p)return;const o=setTimeout(()=>f(null),6e3);return()=>clearTimeout(o)},[p]),s.useEffect(()=>{l?D.current!==l.id&&(A(l.note?.notes||""),D.current=l.id):D.current=null},[l]),s.useEffect(()=>{(async()=>{if(!l){S(!1);return}try{const d=await ce.getStudyPlan(l.id);S(!!d.study_plan)}catch(d){S(!1),console.log("No study plan found for project:",L(d,"No study plan"))}})()},[l]);const Y=o=>{y(o),k(d=>d.map(N=>N.id===o.id?o:N))},E=async()=>{if(!(!l&&!_.trim())){T(!0);try{const o=await K.saveProjectNotes({project_id:l?.id,notes:_});O((o.newProject?"New Project started and ":"")+"Notes saved successfully!"),setTimeout(()=>O(null),4e3),o.newProject&&await H()}catch(o){console.error("Failed to save notes:",L(o,"Failed to save notes")),R(J(L(o,"Failed to save notes")))}finally{T(!1)}}},q=async()=>{const o=await se.getProjects();if(k(o),l){const d=o.find(N=>N.id===l.id);y(d??l)}else o.length>0&&y(o[0])},ee=q,X=q,c=async()=>{await C()},G=async(o,d)=>{try{const N=await K.downloadDocument({path:o}),a=window.URL.createObjectURL(N),x=document.createElement("a");x.href=a,x.download=d,document.body.appendChild(x),x.click(),window.URL.revokeObjectURL(a),document.body.removeChild(x)}catch(N){const a=N;if(a?.response?.data instanceof Blob)try{const x=await a.response.data.text(),z=JSON.parse(x);throw new Error(z.message||"Failed to download document")}
1catch(x){if(x instanceof Error&&x.message!=="Failed to download document")throw x}throw new Error(L(N,"Failed to download document"))}},Z=async o=>{try{if(await K.deleteDocument(o),l?.documents){const d=l.documents.filter(N=>N.path!==o);y({...l,documents:d})}}catch(d){console.error("Failed to delete document:",L(d,"Failed to delete document"))}},te=async o=>{try{if(await K.deleteWeblink(o),l?.weblinks){const d=l.weblinks.filter(N=>N.link!==o);y({...l,weblinks:d})}}catch(d){console.error("Failed to delete weblink:",L(d,"Failed to delete weblink"))}},ie=async(o,d,N)=>{try{if(await K.editWeblink(o,d,N),l?.weblinks){const a=l.weblinks.map(x=>x.id===o?{...x,title:d,description:N}:x);y({...l,weblinks:a})}}catch(a){throw console.error("Failed to edit weblink:",L(a,"Failed to edit weblink")),a}},de=async(o,d,N)=>{try{if(await K.editDocument(o,d,N),l?.documents){const a=l.documents.map(x=>x.id===o?{...x,title:d,description:N}:x);y({...l,documents:a})}}catch(a){throw console.error("Failed to edit document:",L(a,"Failed to edit document")),a}};return j||!i?e.jsx("div",{className:"flex min-h-screen items-center justify-center",children:e.jsx("div",{className:"text-slate-600",children:"Loading..."})}):e.jsxs("div",{className:"min-h-screen bg-slate-50",children:[p&&e.jsx("div",{className:"fixed top-4 left-1/2 -translate-x-1/2 z-[60] w-full max-w-xl px-4",children:e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-green-300 bg-green-50 px-4 py-3 shadow-lg",children:[e.jsx("svg",{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"text-sm font-medium text-green-800",children:p}),e.jsx("button",{onClick:()=>f(null),className:"ml-auto shrink-0 text-green-500 hover:text-green-700",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),w&&e.jsx("div",{className:"fixed top-4 left-1/2 -translate-x-1/2 z-[60] w-full max-w-xl px-4",children:e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-red-300 bg-red-50 px-4 py-3 shadow-lg",children:[e.jsx("svg",{className:"mt-0.5 h-5 w-5 shrink-0 text-red-600",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),e.jsx("p",{className:"text-sm font-medium text-red-800",children:w}),e.jsx("button",{onClick:()=>h(null),className:"ml-auto shrink-0 text-red-400 hover:text-red-600",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsx(Ne,{user:i,onLogout:g,isMobileMenuOpen:P,onMobileMenuChange:B},W),e.jsxs("div",{className:"flex flex-col md:flex-row gap-8 px-2 py-8 sm:px-6 lg:px-8",children:[e.jsx(ye,{user:i,projects:u,selectedProjectId:l?.id??null,onProjectSelect:o=>{const d=u.find(N=>N.id===o);y(d||null)},onLogout:g,isMobileMenuOpen:P,onMobileMenuChange:B}),e.jsx("main",{className:"flex-1 md:mt-0 mt-12",children:e.jsx("div",{className:"mx-auto",children:e.jsxs("div",{className:"rounded-lg bg-white p-2 sm:p-8 shadow-sm",children:[e.jsx(Ae,{user:i}),e.jsx("div",{className:"flex items-start justify-start",children:e.jsx(_e,{onProjectCreated:async o=>{const d=await se.getProjects();k(d),y(d.find(N=>N.id===o.id)||o),M(N=>N+1)}})}),e.jsxs("div",{className:"mt-8 space-y-4",children:[u.length>0&&e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("label",{className:"text-md font-medium text-slate-700 uppercase",children:"Select the Project"}),e.jsx("select",{value:l?.id||"",onChange:o=>{const d=u.find(N=>N.id===parseInt(o.target.value));y(d||null)},className:"w-auto max-w-xs truncate rounded-lg border-2 border-slate-200 bg-white px-4 py-3 text-sm text-slate-900 transition-all focus:border-blue-500 focus:outline-none",children:u.map(o=>e.jsx("option",{value:o.id,children:o.name},o.id))})]}),l&&F&&!me(i)&&e.jsx("div",{className:"flex justify-center mt-2",children:e.jsxs("button",{onClick:()=>t(`/study-plan/pr/${l.id}`),className:"inline-flex items-center gap-2 rounded-lg bg-blue-700 px-6 py-3 text-sm font-semibold text-white shadow-md hover:bg-blue-800 transition-all",children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),"Go to Study Plan"]})}),l&&e.jsx(Fe,{project:l,onRename:Y}),e.jsx(We,{selectedProject:l,personalNotes:_,setPersonalNotes:A,isSavingNotes:U,successMessage:$,errorMessage:I,hasExistingStudyPlan:F,onDownloadDocument:G,onDeleteDocument:Z,onDeleteWeblink:te,onEditWeblink:ie,onEditDocument:de,onSaveNotes:E,onWeblinksSuccess:ee,onDocumentsSuccess:c,onRawTextSuccess:X,onDismissNotesSuccess:()=>O(null)},W)]})]})})})]})]})}export{He as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.