1 line
33 KiB
JavaScript
1 line
33 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5253],{53999:(e,t,a)=>{"use strict";a.d(t,{cn:()=>l});var r=a(52596),n=a(39688);function l(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];return(0,n.QP)((0,r.$)(t))}},79195:(e,t,a)=>{Promise.resolve().then(a.bind(a,85798))},85798:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>z});var r=a(95155),n=a(12115),l=a(12108),s=a(35695),o=a(57434),c=a(69074),i=a(51976),d=a(17580),u=a(47924),m=a(54416),x=a(13052),h=a(88482);let f={Notes:{icon:o.A,order:1,displayName:"Bloc-notes"},Diary:{icon:c.A,order:2,displayName:"Journal"},Health:{icon:i.A,order:3,displayName:"Carnet de sant\xe9"},Contacts:{icon:d.A,order:4,displayName:"Carnet d'adresses"}};function p(e){let{nextcloudFolders:t,onFolderSelect:a}=e,[l,s]=(0,n.useState)(""),[c,i]=(0,n.useState)(!1),[d,p]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1);(0,n.useEffect)(()=>{console.log("Navigation folders received:",t)},[t]);let N=(t&&t.length>0?[...new Set([...t])]:["Notes","Diary","Health","Contacts"]).sort((e,t)=>{var a,r;return((null==(a=f[e])?void 0:a.order)||999)-((null==(r=f[t])?void 0:r.order)||999)}),j=async()=>{try{v(!0);let e=await fetch("/api/storage/files?folder=contacts");if(e.ok){let t=await e.json();console.log("Received ".concat(t.length," files from storage"));let a=t.filter(e=>{var t,a;return(null==(t=e.basename)?void 0:t.endsWith(".vcf"))||(null==(a=e.title)?void 0:a.endsWith(".vcf"))}).map(e=>({id:e.etag||e.id,filename:e.filename||e.id,basename:e.basename||e.title,lastmod:e.lastmod||e.lastModified}));console.log("Processed ".concat(a.length," VCF files")),p(a)}else console.error("Error fetching contact files:",await e.text()),p([])}catch(e){console.error("Error fetching contact files:",e),p([])}finally{v(!1)}};return(0,n.useEffect)(()=>{c&&j()},[c]),(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-sidebar",children:[(0,r.jsx)(h.Zp,{className:"p-4",children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(o.A,{className:"h-6 w-6 text-carnet-text-primary"}),(0,r.jsx)("span",{className:"text-xl font-semibold text-carnet-text-primary",children:"PAGES"})]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:"text",value:l,onChange:e=>s(e.target.value),placeholder:"Recherche...",className:"w-full pl-8 pr-4 py-1.5 bg-white border border-carnet-border rounded-md text-sm text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none focus:ring-1 focus:ring-primary"}),(0,r.jsx)(u.A,{className:"absolute left-2 top-1.5 h-3.5 w-3.5 text-carnet-text-muted"}),l&&(0,r.jsx)("button",{onClick:()=>s(""),className:"absolute right-2 top-1.5 text-carnet-text-muted hover:text-carnet-text-primary",children:(0,r.jsx)(m.A,{className:"h-3.5 w-3.5"})})]})]})}),(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[(0,r.jsx)("h2",{className:"text-xs font-semibold text-carnet-text-primary mb-2",children:"VUES"}),(0,r.jsx)("div",{className:"space-y-1",children:0===N.length?(0,r.jsx)("div",{className:"text-xs text-carnet-text-muted py-1 px-2",children:"Chargement des dossiers..."}):N.map(e=>{let t=f[e],n=(null==t?void 0:t.icon)||o.A,l=(null==t?void 0:t.displayName)||e;return(0,r.jsxs)("div",{children:[(0,r.jsxs)("button",{onClick:()=>{"Contacts"===e?i(!c):a(e)},className:"w-full flex items-center px-2 py-1.5 text-sm rounded-md text-carnet-text-primary hover:bg-carnet-hover",children:[(0,r.jsx)(n,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,r.jsx)("span",{className:"ml-2 truncate",children:l}),"Contacts"===e&&(0,r.jsx)(x.A,{className:"h-3.5 w-3.5 flex-shrink-0 ml-auto transition-transform ".concat(c?"transform rotate-90":"")})]}),"Contacts"===e&&c&&(0,r.jsx)("div",{className:"ml-4 mt-1 space-y-1",children:g?(0,r.jsx)("div",{className:"px-3 py-2 text-sm text-carnet-text-muted",children:"Chargement..."}):0===d.length?(0,r.jsx)("div",{className:"px-3 py-2 text-sm text-carnet-text-muted",children:"Aucun contact"}):d.map(e=>(0,r.jsx)("button",{onClick:()=>{a("Contacts")},className:"w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-muted hover:bg-carnet-hover",children:(0,r.jsx)("span",{children:e.basename.replace(".vcf","")})},e.id))})]},e)})})]})]})}var g=a(84616),v=a(81189),N=a(61982),j=a(16946);let y={Notes:"Bloc-notes",Diary:"Journal",Health:"Carnet de sant\xe9",Contacts:"Carnet d'adresses"},b=e=>{let{notes:t,onNoteSelect:a,currentFolder:l="Notes",onNewNote:s,loading:x=!1,onDeleteNote:h}=e,[f,p]=(0,n.useState)(""),[b,w]=(0,n.useState)(null),[C,S]=(0,n.useState)(null),E=e=>(0,v.GP)(new Date(e),"EEEE d MMM yyyy",{locale:j.fr}),A=e=>{if("Diary"===l||"Health"===l){let t=e.title.match(/^(\d{4}-\d{2}-\d{2})/);if(t)return(0,N.qg)(t[1],"yyyy-MM-dd",new Date),e.title.replace(t[1],"").trim()}return e.title},D=(e=>{switch(e){case"Notes":default:return o.A;case"Diary":return c.A;case"Health":return i.A;case"Contacts":return d.A}})(l);return(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-bg border-r border-carnet-border",children:[C&&(0,r.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:(0,r.jsxs)("div",{className:"bg-carnet-bg p-6 rounded-lg shadow-lg max-w-md w-full",children:[(0,r.jsx)("h3",{className:"text-lg font-semibold text-carnet-text-primary mb-4",children:"Supprimer la note"}),(0,r.jsxs)("p",{className:"text-carnet-text-muted mb-6",children:['\xcates-vous s\xfbr de vouloir supprimer la note "',C.title,'" ? Cette action est irr\xe9versible.']}),(0,r.jsxs)("div",{className:"flex justify-end space-x-4",children:[(0,r.jsx)("button",{onClick:()=>S(null),className:"px-4 py-2 text-carnet-text-primary hover:bg-carnet-hover rounded-md",children:"Annuler"}),(0,r.jsx)("button",{onClick:()=>{null==h||h(C),S(null)},className:"px-4 py-2 bg-red-500 text-white hover:bg-red-600 rounded-md",children:"Supprimer"})]})]})}),(0,r.jsxs)("div",{className:"p-4 border-b border-carnet-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(D,{className:"h-5 w-5 text-carnet-text-primary"}),(0,r.jsx)("h2",{className:"text-lg font-semibold text-carnet-text-primary",children:y[l]||l})]}),(0,r.jsx)("button",{onClick:s,className:"p-2 text-carnet-text-primary hover:bg-carnet-hover rounded-md",children:(0,r.jsx)(g.A,{className:"h-5 w-5"})})]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:"text",value:f,onChange:e=>p(e.target.value),placeholder:"Rechercher des notes...",className:"w-full pl-9 pr-4 py-2 bg-white border border-carnet-border rounded-md text-sm text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none focus:ring-1 focus:ring-primary"}),(0,r.jsx)(u.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-carnet-text-muted"}),f&&(0,r.jsx)("button",{onClick:()=>p(""),className:"absolute right-3 top-2.5 text-carnet-text-muted hover:text-carnet-text-primary",children:(0,r.jsx)(m.A,{className:"h-4 w-4"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto",children:x?(0,r.jsx)("div",{className:"p-4 text-center text-carnet-text-muted",children:"Chargement..."}):0===t.length?(0,r.jsx)("div",{className:"p-4 text-center text-carnet-text-muted",children:"Aucune note"}):(0,r.jsx)("ul",{className:"divide-y divide-carnet-border",children:[...t].sort((e,t)=>{if("Diary"===l||"Health"===l){let a=e.title.match(/^(\d{4}-\d{2}-\d{2})/),r=t.title.match(/^(\d{4}-\d{2}-\d{2})/);if(a&&r)return new Date(r[1]).getTime()-new Date(a[1]).getTime()}return new Date(t.lastModified).getTime()-new Date(e.lastModified).getTime()}).map(e=>(0,r.jsx)("li",{onMouseEnter:()=>w(e.id),onMouseLeave:()=>w(null),className:"p-4 hover:bg-carnet-hover cursor-pointer group",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-2 flex-1",onClick:()=>null==a?void 0:a(e),children:[(0,r.jsx)(D,{className:"h-4 w-4 text-carnet-text-muted"}),(0,r.jsx)("div",{className:"flex-1",children:"Diary"===l||"Health"===l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-carnet-text-primary",children:E(e.lastModified)}),(0,r.jsx)("div",{className:"text-sm text-carnet-text-muted",children:A(e)})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"text-sm font-medium text-carnet-text-primary",children:e.title}),(0,r.jsx)("div",{className:"text-xs text-carnet-text-muted",children:E(e.lastModified)})]})})]}),"Notes"===l&&b===e.id&&(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),S(e)},className:"p-1 text-carnet-text-muted hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,r.jsx)(m.A,{className:"h-4 w-4"})})]})},e.id))})})]})},w=e=>{let{note:t,onSave:a,currentFolder:c="Notes",onRefresh:i}=e,[d,u]=(0,n.useState)((null==t?void 0:t.title)||""),[m,x]=(0,n.useState)((null==t?void 0:t.content)||""),[h,f]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!1),[v,N]=(0,n.useState)(null),j=(0,n.useRef)(),y=(0,s.useRouter)(),{data:b,status:w}=(0,l.useSession)(),C=(0,n.useRef)({});(0,n.useEffect)(()=>{"unauthenticated"===w&&y.push("/signin")},[w,y]),(0,n.useEffect)(()=>{let e=async()=>{if(null==t?void 0:t.id){g(!0),N(null);let e=C.current[t.id];if(e&&Date.now()-e.timestamp<9e5){console.log("Using cached content for note ".concat(t.title)),x(e.content),g(!1);return}try{let e="note-content-".concat(t.id),a=localStorage.getItem(e);if(a){let{content:e,timestamp:r}=JSON.parse(a);if(Date.now()-r<9e5){console.log("Using localStorage cached content for note ".concat(t.title)),x(e),C.current[t.id]={content:e,timestamp:r},g(!1);return}}}catch(e){console.error("Error accessing localStorage content cache:",e)}try{let e=await fetch("/api/storage/files/content?path=".concat(encodeURIComponent(t.id)));if(401===e.status){console.error("Authentication error, redirecting to login"),y.push("/signin");return}if(!e.ok){let t=await e.text();throw Error("Failed to fetch note content: ".concat(e.status," ").concat(t))}let a=await e.json();x(a.content);let r=Date.now();C.current[t.id]={content:a.content,timestamp:r};try{localStorage.setItem("note-content-".concat(t.id),JSON.stringify({content:a.content,timestamp:r}))}catch(e){console.error("Error saving content to localStorage:",e)}}catch(e){console.error("Error fetching note content:",e),N("Failed to load note content. Please try again later.")}finally{g(!1)}}};t?(u(t.title),t.id?e():x("")):(u(""),x(""))},[t,y,9e5]);let S=()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{E()},1e3)},E=async()=>{if(d&&m){if(!b){console.error("No active session, cannot save"),N("You must be logged in to save notes");return}f(!0),N(null);try{let e=(null==t?void 0:t.id)||"user-".concat(b.user.id,"/").concat(c.toLowerCase(),"/").concat(d).concat(d.endsWith(".md")?"":".md"),r=(null==t?void 0:t.id)?"PUT":"POST";console.log("Saving note:",{id:e,title:d,folder:c,contentLength:m.length});let n=await fetch("/api/storage/files",{method:r,headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,title:d,content:m,folder:c.toLowerCase()})});if(401===n.status){console.error("Authentication error, redirecting to login"),y.push("/signin");return}if(!n.ok){let e=await n.text();throw console.error("Failed to save note:",{status:n.status,statusText:n.statusText,data:e}),N("Failed to save note: ".concat(n.statusText)),Error("Failed to save note: ".concat(n.status," ").concat(n.statusText))}let l=await n.json();console.log("Note saved successfully:",l);let s=Date.now();C.current[e]={content:m,timestamp:s};try{localStorage.setItem("note-content-".concat(e),JSON.stringify({content:m,timestamp:s}))}catch(e){console.error("Error updating content cache in localStorage:",e)}N(null),null==a||a({...l,content:m}),null==i||i()}catch(e){console.error("Error saving note:",e)}finally{f(!1)}}};return b||"loading"===w?t?(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-bg",children:[(0,r.jsx)("div",{className:"p-4 border-b border-carnet-border",children:(0,r.jsx)("input",{type:"text",value:d,onChange:e=>{u(e.target.value),S()},placeholder:"Titre",className:"w-full text-xl font-semibold text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none bg-transparent"})}),v&&(0,r.jsx)("div",{className:"p-2 m-2 bg-red-100 border border-red-400 text-red-700 rounded",children:v}),(0,r.jsx)("div",{className:"flex-1 p-4",children:p?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-primary"})}):(0,r.jsx)("textarea",{value:m,onChange:e=>{x(e.target.value),S()},placeholder:"Ecrire...",className:"w-full h-full resize-none focus:outline-none bg-transparent text-carnet-text-primary placeholder-carnet-text-muted"})}),h&&(0,r.jsx)("div",{className:"absolute bottom-4 right-4 text-sm text-carnet-text-muted",children:"Enregistrement..."})]}):(0,r.jsx)("div",{className:"flex flex-col h-full bg-carnet-bg items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)(o.A,{className:"h-12 w-12 text-carnet-text-muted mx-auto mb-4"}),(0,r.jsx)("h2",{className:"text-xl font-semibold text-carnet-text-primary mb-2",children:"S\xe9lectionnez une note"}),(0,r.jsx)("p",{className:"text-carnet-text-muted",children:"Choisissez une note existante ou cr\xe9ez-en une nouvelle"})]})}):(0,r.jsx)("div",{className:"flex flex-col h-full bg-carnet-bg items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("h2",{className:"text-xl font-semibold text-carnet-text-primary mb-2",children:"Authentication Required"}),(0,r.jsx)("p",{className:"text-carnet-text-muted mb-4",children:"Please log in to access your notes"}),(0,r.jsx)("button",{onClick:()=>y.push("/signin"),className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600",children:"Go to Login"})]})})},C=e=>{let{isDragging:t,onDragStart:a,onDragEnd:n,onDrag:l}=e;return(0,r.jsx)("div",{className:"w-1 bg-border cursor-col-resize hover:bg-info transition-colors ".concat(t?"bg-info":""),onMouseDown:e=>{e.preventDefault(),a(),document.addEventListener("mousemove",l),document.addEventListener("mouseup",n)}})};function S(e){let[t,a]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{let t=window.matchMedia(e);a(t.matches);let r=e=>{a(e.matches)};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[e]),t}var E=a(71007);let A=e=>{let{contacts:t,onContactSelect:a,selectedContact:l,loading:s=!1}=e,[o,c]=(0,n.useState)(""),i=t.filter(e=>{var t,a,r;let n=o.toLowerCase();return((null==(t=e.fullName)?void 0:t.toLowerCase())||"").includes(n)||((null==(a=e.email)?void 0:a.toLowerCase())||"").includes(n)||((null==(r=e.organization)?void 0:r.toLowerCase())||"").includes(n)});return(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-bg border-r border-carnet-border",children:[(0,r.jsxs)("div",{className:"p-4 border-b border-carnet-border",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(d.A,{className:"h-5 w-5 text-carnet-text-primary"}),(0,r.jsx)("h2",{className:"text-lg font-semibold text-carnet-text-primary",children:"Carnet d'adresses"})]}),(0,r.jsx)("button",{onClick:()=>a({id:Math.random().toString(36).substr(2,9),fullName:"",email:"",phone:"",organization:"",address:"",notes:"",group:""}),className:"p-2 text-carnet-text-primary hover:bg-carnet-hover rounded-md",children:(0,r.jsx)(g.A,{className:"h-5 w-5"})})]}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{type:"text",value:o,onChange:e=>c(e.target.value),placeholder:"Rechercher un contact...",className:"w-full pl-9 pr-4 py-2 bg-white border border-carnet-border rounded-md text-sm text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none focus:ring-1 focus:ring-primary"}),(0,r.jsx)(u.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-carnet-text-muted"})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto",children:s?(0,r.jsx)("div",{className:"p-4 text-center text-carnet-text-muted",children:"Chargement..."}):0===i.length?(0,r.jsx)("div",{className:"p-4 text-center text-carnet-text-muted",children:"Aucun contact trouv\xe9"}):(0,r.jsx)("ul",{className:"divide-y divide-carnet-border",children:i.map(e=>(0,r.jsx)("li",{onClick:()=>a(e),className:"p-4 cursor-pointer hover:bg-carnet-hover ".concat((null==l?void 0:l.id)===e.id?"bg-carnet-hover":""),children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,r.jsx)("div",{className:"h-10 w-10 rounded-full bg-primary/10 flex items-center justify-center",children:(0,r.jsx)(E.A,{className:"h-5 w-5 text-primary"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"font-medium text-carnet-text-primary",children:e.fullName||e.email||"Sans nom"}),e.email&&(0,r.jsx)("div",{className:"text-sm text-carnet-text-muted",children:e.email})]})]}),(0,r.jsx)(x.A,{className:"h-4 w-4 text-carnet-text-muted"})]})},e.id))})})]})};var D=a(74783),k=a(4229),R=a(56287),T=a(28883),I=a(19420),F=a(48136),L=a(4516);let O=e=>{let{contact:t,onSave:a,onDelete:l}=e,[s,o]=(0,n.useState)(!1),[c,i]=(0,n.useState)(null);if(n.useEffect(()=>{i(t),o(!1)},[t]),!t)return(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-bg items-center justify-center text-carnet-text-muted",children:[(0,r.jsx)(E.A,{className:"h-16 w-16 mb-4 opacity-20"}),(0,r.jsx)("p",{children:"S\xe9lectionnez un contact pour voir les d\xe9tails"})]});let d=(e,t,a,n)=>(0,r.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,r.jsx)("div",{className:"h-8 w-8 rounded-full ".concat({email:"bg-blue-50",phone:"bg-green-50",organization:"bg-purple-50",address:"bg-orange-50"}[a]||"bg-gray-50"," flex items-center justify-center"),children:(0,r.jsx)("div",{className:{email:"text-blue-500",phone:"text-green-500",organization:"text-purple-500",address:"text-orange-500"}[a]||"text-gray-500",children:n})}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsx)("p",{className:"text-xs text-carnet-text-muted",children:e}),s?(0,r.jsx)("input",{type:"text",value:(null==c?void 0:c[a])||"",onChange:e=>i(t=>t?{...t,[a]:e.target.value}:null),className:"w-full text-sm text-carnet-text-primary bg-transparent border-b border-primary focus:outline-none"}):(0,r.jsx)("p",{className:"text-sm text-carnet-text-primary",children:t})]})]});return(0,r.jsxs)("div",{className:"flex flex-col h-full bg-carnet-bg p-6",children:[(0,r.jsxs)("div",{className:"flex justify-between items-start mb-6",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)("div",{className:"h-16 w-16 rounded-full bg-primary/10 flex items-center justify-center",children:(0,r.jsx)(E.A,{className:"h-8 w-8 text-primary"})}),(0,r.jsx)("div",{children:s?(0,r.jsx)("input",{type:"text",value:(null==c?void 0:c.fullName)||"",onChange:e=>i(t=>t?{...t,fullName:e.target.value}:null),className:"text-xl font-semibold text-carnet-text-primary bg-transparent border-b border-primary focus:outline-none",placeholder:"Nom complet"}):(0,r.jsx)("h2",{className:"text-xl font-semibold text-carnet-text-primary",children:(null==t?void 0:t.fullName)||(null==t?void 0:t.email)||"Sans nom"})})]}),(0,r.jsx)("div",{className:"flex space-x-2",children:s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>{c&&a&&(a(c),o(!1))},className:"p-2 rounded-full hover:bg-primary/10 text-primary",title:"Enregistrer",children:(0,r.jsx)(k.A,{className:"h-5 w-5"})}),(0,r.jsx)("button",{onClick:()=>{i(t),o(!1)},className:"p-2 rounded-full hover:bg-red-100 text-red-500",title:"Annuler",children:(0,r.jsx)(m.A,{className:"h-5 w-5"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>o(!0),className:"p-2 rounded-full hover:bg-primary/10 text-primary",title:"Modifier",children:(0,r.jsx)(R.A,{className:"h-5 w-5"})}),l&&(0,r.jsx)("button",{onClick:()=>l(t),className:"p-2 rounded-full hover:bg-red-100 text-red-500",title:"Supprimer",children:(0,r.jsx)(m.A,{className:"h-5 w-5"})})]})})]}),(0,r.jsxs)("div",{className:"space-y-4",children:[d("Email",null==t?void 0:t.email,"email",(0,r.jsx)(T.A,{className:"h-4 w-4"})),d("T\xe9l\xe9phone",null==t?void 0:t.phone,"phone",(0,r.jsx)(I.A,{className:"h-4 w-4"})),d("Organisation",null==t?void 0:t.organization,"organization",(0,r.jsx)(F.A,{className:"h-4 w-4"})),d("Adresse",null==t?void 0:t.address,"address",(0,r.jsx)(L.A,{className:"h-4 w-4"}))]}),(0,r.jsxs)("div",{className:"mt-6",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-carnet-text-primary mb-2",children:"Notes"}),s?(0,r.jsx)("textarea",{value:(null==c?void 0:c.notes)||"",onChange:e=>i(t=>t?{...t,notes:e.target.value}:null),className:"w-full h-32 text-sm text-carnet-text-muted bg-transparent border rounded-md p-2 focus:outline-none focus:border-primary",placeholder:"Ajouter des notes..."}):(0,r.jsx)("p",{className:"text-sm text-carnet-text-muted whitespace-pre-wrap",children:null==t?void 0:t.notes})]})]})};var P=a(33960);function z(){var e,t;let{data:a,status:o}=(0,l.useSession)(),[c,i]=(0,n.useState)(!0),[d,u]=(0,n.useState)(!1),[x,h]=(0,n.useState)("item-selection"),[f,g]=(0,n.useState)(null),[v,N]=(0,n.useState)(!1),[j,y]=(0,n.useState)(!0),[E,k]=(0,n.useState)(!0),[R,T]=(0,n.useState)([]),[I,F]=(0,n.useState)("Notes"),[L,z]=(0,n.useState)([]),[M,V]=(0,n.useState)(!0),[U,J]=(0,n.useState)([]),[B,G]=(0,n.useState)(null),[W,_]=(0,n.useState)(!0),[H,Y]=(0,n.useState)(220),[q,Z]=(0,n.useState)(400),[X,Q]=(0,n.useState)(!1),[$,K]=(0,n.useState)(!1),ee=S("(max-width: 768px)"),et=S("(max-width: 1024px)"),ea=(0,n.useRef)(null),er=(0,n.useRef)({}),en=(0,n.useRef)({});(0,n.useEffect)(()=>{try{localStorage.removeItem("nextcloud_folders"),console.log("Cleared folder cache")}catch(e){console.error("Error clearing folder cache:",e)}},[]),(0,n.useEffect)(()=>{let e=async()=>{let e=localStorage.getItem("nextcloud_folders");if(e){let{folders:t,timestamp:a}=JSON.parse(e);if(Date.now()-a<3e5)return void T(t)}try{let e=await fetch("/api/nextcloud/status");if(!e.ok)throw Error("Failed to fetch Nextcloud folders");let t=(await e.json()).folders||[];localStorage.setItem("nextcloud_folders",JSON.stringify({folders:t,timestamp:Date.now()})),ea.current={folders:t,timestamp:Date.now()},T(t)}catch(e){console.error("Error fetching Nextcloud folders:",e),T([])}};"authenticated"===o&&e()},[o]),(0,n.useEffect)(()=>{var e;"unauthenticated"===o&&(0,s.redirect)("/signin"),"authenticated"===o&&(null==a||null==(e=a.user)?void 0:e.id)&&fetch("/api/storage/init",{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>{e.ok?console.log("All folders initialized successfully"):console.error("Failed to initialize folders")}).catch(e=>{console.error("Error initializing folders:",e)}),"loading"!==o&&i(!1)},[o,null==a||null==(e=a.user)?void 0:e.id]),(0,n.useEffect)(()=>{ee?(N(!0),y(!1),k(!1)):et?(N(!1),y(!0),k(!1)):(N(!1),y(!0),k(!0))},[ee,et]),(0,n.useEffect)(()=>{"Contacts"===I?es("Contacts"):I.endsWith(".vcf")?es(I):eo()},[I,null==a||null==(t=a.user)?void 0:t.id]);let el=e=>{try{return e.split("BEGIN:VCARD").filter(e=>e.trim()).map(e=>{var t,a,r,n,l,s,o,c,i,d,u,m,x,h,f,p;let g=(0,P.parse)("BEGIN:VCARD"+e),v=null==(a=g.uid)||null==(t=a[0])?void 0:t.value,N=null==(n=g.fn)||null==(r=n[0])?void 0:r.value,j=null==(s=g.email)||null==(l=s[0])?void 0:l.value,y=null==(c=g.tel)||null==(o=c[0])?void 0:o.value,b=null==(d=g.org)||null==(i=d[0])?void 0:i.value,w=null==(m=g.adr)||null==(u=m[0])?void 0:u.value,C=null==(h=g.note)||null==(x=h[0])?void 0:x.value,S=null==(p=g.categories)||null==(f=p[0])?void 0:f.value;return{id:v||Math.random().toString(36).substr(2,9),fullName:N||"Unknown Contact",email:j||"",phone:y||"",organization:b||"",address:w||"",notes:C||"",group:S||""}})}catch(e){return console.error("Error parsing VCF content:",e),[]}},es=async e=>{try{_(!0);let r=e.toLowerCase();if(e.endsWith(".vcf")){var t;let n=await fetch("/api/storage/files/content?path=".concat(encodeURIComponent("user-".concat(null==a||null==(t=a.user)?void 0:t.id,"/").concat(r,"/").concat(e))));if(n.ok){let{content:t}=await n.json(),a=el(t);J(a.map(t=>({...t,group:e.replace(".vcf","")})))}}else{let e=await fetch("/api/storage/files?folder=".concat(r));if(e.ok){let t=(await e.json()).filter(e=>{var t,a;return(null==(t=e.basename)?void 0:t.endsWith(".vcf"))||(null==(a=e.title)?void 0:a.endsWith(".vcf"))}),a=await Promise.all(t.map(async e=>{try{let t=await fetch("/api/storage/files/content?path=".concat(encodeURIComponent(e.id)));if(t.ok){let{content:a}=await t.json();return el(a).map(t=>{var a;return{...t,group:null==(a=e.basename||e.title)?void 0:a.replace(".vcf","")}})}return[]}catch(e){return console.error("Error fetching VCF content:",e),[]}}));J(a.flat().filter(Boolean))}}}catch(e){console.error("Error fetching contacts:",e),J([])}finally{_(!1)}},eo=async()=>{try{var e;V(!0);let t=I.toLowerCase();console.log("Fetching notes from folder: ".concat(t));let r="".concat(null==a||null==(e=a.user)?void 0:e.id,"-").concat(t),n=er.current[r];if(n&&Date.now()-n.timestamp<3e5){console.log("Using cached notes for ".concat(t," folder")),z(n.notes),V(!1);return}try{let e=localStorage.getItem("notes-cache-".concat(r));if(e){let{notes:a,timestamp:n}=JSON.parse(e);if(Date.now()-n<3e5){console.log("Using localStorage cached notes for ".concat(t," folder")),z(a),er.current[r]={notes:a,timestamp:n},V(!1);return}}}catch(e){console.error("Error accessing localStorage notes cache:",e)}let l=await fetch("/api/storage/files?folder=".concat(t));if(l.ok){let e=await l.json();console.log("Fetched ".concat(e.length," notes from ").concat(t," folder")),z(e);let a=Date.now();er.current[r]={notes:e,timestamp:a};try{localStorage.setItem("notes-cache-".concat(r),JSON.stringify({notes:e,timestamp:a}))}catch(e){console.error("Error saving notes to localStorage:",e)}}else console.error("Error fetching notes:",await l.text()),z([])}catch(e){console.error("Error fetching notes:",e),z([])}finally{V(!1)}},ec=async e=>{try{var t,r;u(!0);let n={id:e.id||"user-".concat(null==a||null==(t=a.user)?void 0:t.id,"/").concat(I.toLowerCase(),"/").concat(e.title).concat(e.title.endsWith(".md")?"":".md"),title:e.title,content:e.content,folder:I.toLowerCase(),mime:"text/markdown"},l=e.id?"PUT":"POST";console.log("Saving note to ".concat(I.toLowerCase()," using ").concat(l));let s=await fetch("/api/storage/files",{method:l,headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(s.ok){let e="".concat(null==a||null==(r=a.user)?void 0:r.id,"-").concat(I.toLowerCase());er.current[e]&&delete er.current[e];try{localStorage.removeItem("notes-cache-".concat(e))}catch(e){console.error("Error removing notes from localStorage:",e)}if(n.id){en.current[n.id]={content:n.content,timestamp:Date.now()};try{localStorage.setItem("note-content-".concat(n.id),JSON.stringify({content:n.content,timestamp:Date.now()}))}catch(e){console.error("Error saving note content to localStorage:",e)}}eo()}else console.error("Error saving note:",await s.text())}catch(e){console.error("Error saving note:",e)}finally{u(!1)}},ei=async e=>{console.log("Selected folder:",e),F(e),h("item-selection"),G(null);try{let t=e.toLowerCase();console.log("Ensuring folder exists: ".concat(t));let a=await fetch("/api/storage/init/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({folder:t})});a.ok||console.warn("Failed to create folder ".concat(t,": ").concat(await a.text()))}catch(e){console.error("Error creating folder:",e)}},ed=async e=>{try{if(!(await fetch("/api/nextcloud/files",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,folder:I})})).ok)throw Error("Failed to delete note");let t=await fetch("/api/nextcloud/files?folder=".concat(I));if(t.ok){let e=await t.json();z(e)}(null==f?void 0:f.id)===e.id&&g(null)}catch(e){console.error("Error deleting note:",e)}},eu=async e=>{var t,r,n;if(null==a||null==(t=a.user)?void 0:t.id)try{i(!0);let t="/files/cube-".concat(a.user.id,"/Private/Contacts"),l="Allemanique.vcf",s="".concat(t,"/").concat(l),o="",c=[];try{let e=await fetch("/api/nextcloud/files/content?path=".concat(encodeURIComponent(s)));if(e.ok){let{content:t}=await e.json();c=t.split("BEGIN:VCARD").filter(e=>e.trim()).map(e=>"BEGIN:VCARD"+e.trim())}}catch(e){console.log("No existing VCF file found, will create a new one")}let d=[],u=!1;for(let t of c)if((null==(n=(0,P.parse)(t).uid)||null==(r=n[0])?void 0:r.value)===e.id){let t=["BEGIN:VCARD","VERSION:3.0","UID:".concat(e.id),"FN:".concat(e.fullName||""),...e.email?["EMAIL;TYPE=INTERNET:".concat(e.email)]:[],...e.phone?["TEL;TYPE=CELL:".concat(e.phone)]:[],...e.organization?["ORG:".concat(e.organization)]:[],...e.address?["ADR:".concat(e.address)]:[],...e.notes?["NOTE:".concat(e.notes)]:[],"END:VCARD"].join("\n");d.push(t),u=!0}else d.push(t);if(!u){let t=["BEGIN:VCARD","VERSION:3.0","UID:".concat(e.id),"FN:".concat(e.fullName||""),...e.email?["EMAIL;TYPE=INTERNET:".concat(e.email)]:[],...e.phone?["TEL;TYPE=CELL:".concat(e.phone)]:[],...e.organization?["ORG:".concat(e.organization)]:[],...e.address?["ADR:".concat(e.address)]:[],...e.notes?["NOTE:".concat(e.notes)]:[],"END:VCARD"].join("\n");d.push(t)}if(o=d.join("\n\n"),!(await fetch("/api/nextcloud/files",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:s,title:l,content:o,folder:"Contacts",mime:"text/vcard"})})).ok)throw Error("Failed to save contact");await es(I),u&&G(e)}catch(e){console.error("Error saving contact:",e)}finally{i(!1)}},em=async e=>{if(confirm("\xcates-vous s\xfbr de vouloir supprimer ce contact ?"))try{var t;i(!0);let r="/files/cube-".concat(null==a||null==(t=a.user)?void 0:t.id,"/Private/Contacts"),n=e.group?"".concat(e.group,".vcf"):"contacts.vcf",l="".concat(r,"/").concat(n),s=await fetch("/api/nextcloud/files/content?path=".concat(encodeURIComponent(l)));if(!s.ok)throw Error("Failed to fetch contacts");let{content:o}=await s.json(),c=o.split("BEGIN:VCARD").filter(e=>e.trim()).filter(t=>{var a,r;return(null==(r=(0,P.parse)("BEGIN:VCARD"+t).uid)||null==(a=r[0])?void 0:a.value)!==e.id}).map(e=>"BEGIN:VCARD"+e).join("\n");if(!(await fetch("/api/nextcloud/files",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l,title:n,content:c,folder:"Contacts",mime:"text/vcard"})})).ok)throw Error("Failed to delete contact");G(null),await es(I)}catch(e){console.error("Error deleting contact:",e)}finally{i(!1)}};return c?(0,r.jsx)("div",{className:"flex h-screen items-center justify-center",children:(0,r.jsx)("div",{className:"h-32 w-32 animate-spin rounded-full border-t-2 border-b-2 border-gray-900"})}):(0,r.jsx)("main",{className:"w-full h-screen bg-black",children:(0,r.jsx)("div",{className:"w-full h-full px-4 pt-12 pb-4",children:(0,r.jsxs)("div",{className:"flex h-full bg-carnet-bg",children:[j&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex-none",style:{width:H},children:(0,r.jsx)(p,{nextcloudFolders:R,onFolderSelect:ei})}),(0,r.jsx)(C,{isDragging:X,onDragStart:()=>Q(!0),onDragEnd:()=>Q(!1),onDrag:e=>{if(!X)return;let t=e.clientX;t>=48&&t<=400&&Y(t)}})]}),E&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:"Contacts"===I?(0,r.jsx)(A,{contacts:U,onContactSelect:e=>{G(e),v&&k(!1)},selectedContact:B,loading:M}):(0,r.jsx)(b,{notes:L,loading:M,onNoteSelect:e=>{g(e),v&&k(!1)},currentFolder:I,onNewNote:()=>{g({id:"",title:"",content:"",lastModified:new Date().toISOString(),type:"file",mime:"text/markdown",etag:""}),v&&k(!1)},onDeleteNote:ed})}),(0,r.jsx)(C,{isDragging:$,onDragStart:()=>K(!0),onDragEnd:()=>K(!1),onDrag:e=>{if(!$)return;let t=e.clientX-H-2;t>=200&&Z(t)}})]}),(0,r.jsx)("div",{className:"flex-1 overflow-hidden",children:"Contacts"===I||I.endsWith(".vcf")?(0,r.jsx)(O,{contact:B,onSave:eu,onDelete:em}):(0,r.jsx)(w,{note:f,onSave:ec,currentFolder:I,onRefresh:()=>{eo()}})}),v&&(0,r.jsx)("button",{onClick:()=>y(!j),className:"fixed bottom-4 right-4 bg-primary text-white p-3 rounded-full shadow-lg",children:j?(0,r.jsx)(m.A,{className:"h-6 w-6"}):(0,r.jsx)(D.A,{className:"h-6 w-6"})})]})})})}},88482:(e,t,a)=>{"use strict";a.d(t,{BT:()=>i,Wu:()=>d,ZB:()=>c,Zp:()=>s,aR:()=>o});var r=a(95155),n=a(12115),l=a(53999);let s=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("rounded-lg border bg-card text-card-foreground shadow-sm",a),...n})});s.displayName="Card";let o=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("flex flex-col space-y-1.5 p-6",a),...n})});o.displayName="CardHeader";let c=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("text-2xl font-semibold leading-none tracking-tight",a),...n})});c.displayName="CardTitle";let i=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("text-sm text-muted-foreground",a),...n})});i.displayName="CardDescription";let d=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("p-6 pt-0",a),...n})});d.displayName="CardContent",n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,r.jsx)("div",{ref:t,className:(0,l.cn)("flex items-center p-6 pt-0",a),...n})}).displayName="CardFooter"}},e=>{var t=t=>e(e.s=t);e.O(0,[4277,2108,1334,1680,8441,1684,7358],()=>t(79195)),_N_E=e.O()}]); |