PageSourceSearch

https://notionary-notes.vercel.app/_next/static/chunks/3681.597d00d40b19341e.js

js notionary-notes.vercel.app collected 2026-10-03 07:24:59 UTC 65,412 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3681],{3681:(e,t,r)=>{r.r(t),r.d(t,{default:()=>ee});var n=r(5818),l=r(6418),o=r(6640),s=r(2441),i=r(7372),a=r(3970),d=r(818),c=r(4373),u=r(8416),m=r(9312),h=r(6474),f=r(3597),x=r(9229),g=r(8137),p=r(2488),v=r(7821),w=r(414),_=r(8044),b=r(5337),j=r(747),N=r(1200),y=r(4003),k=r(1448),S=r(4369),C=r(1981),A=r(5821),E=r(2755),U=r(2343),I=r(2550),M=r(9850),q=r(8300),z=r(8821),P=r(4996),F=r(3131),T=r(6761),$=r(6528),D=r(1567),L=r(4154),O=r(9778),R=r(3413),B=r(8750),J=r(2519),Z=r(7045),Q=r(1003),W=r.n(Q);let G=async e=>{try{let t=(0,B.UU)();await t.from("independent_notes").delete().eq("note_id",e);let{error:r}=await t.from("notes").delete().eq("id",e);if(r)throw r;window.location.reload()}catch(e){console.error("Error deleting note:",e)}};var Y=r(783),V=r(7008),H=r(8889),K=r(1606),X=r(7463);function ee(e){var t,r,Q,ee,et,er,en,el;let{initialNotes:eo,user:es,editNoteId:ei}=e,{showAlert:ea,showNotification:ed}=(0,X.n)(),[ec,eu]=(0,l.useState)(Array.isArray(eo)?eo:[]),[em,eh]=(0,l.useState)(()=>{if(null==es?void 0:es.id)try{let e="independentNotes:".concat(es.id),t=sessionStorage.getItem(e);if(t){let e=JSON.parse(t);if(e&&Array.isArray(e.data)&&e.data.length>0)return e.data}}catch(e){}return[]}),ef=(0,l.useRef)(!1),[ex,eg]=(0,l.useState)(0),[ep,ev]=(0,l.useState)(!0),[ew,e_]=(0,l.useState)(!1),eb=(0,l.useRef)(null),[ej,eN]=(0,l.useState)(0),[ey,ek]=(0,l.useState)(!0),[eS,eC]=(0,l.useState)(!1),eA=(0,l.useRef)(null);(0,l.useEffect)(()=>{if((null==es?void 0:es.id)&&!ef.current)try{let e="independentNotes:".concat(es.id),t=sessionStorage.getItem(e);if(t){let e=JSON.parse(t);e&&Array.isArray(e.data)&&e.data.length>0&&(ef.current=!0)}}catch(e){}},[null==es?void 0:es.id]);let[eE,eU]=(0,l.useState)(""),eI=function(e,t){let[r,n]=(0,l.useState)(e);return(0,l.useEffect)(()=>{let t=setTimeout(()=>n(e),500);return()=>clearTimeout(t)},[e,500]),r}(eE,500),[eM,eq]=(0,l.useState)({isOpen:!1,noteId:"",noteTitle:""}),[ez,eP]=(0,l.useState)([]),[eF,eT]=(0,l.useState)(!1);(0,l.useEffect)(()=>{console.log("Search results changed to:",ez,"Length:",ez.length)},[ez]);let[e$,eD]=(0,l.useState)(!1),[eL,eO]=(0,l.useState)("all"),[eR,eB]=(0,l.useState)("words"),[eJ,eZ]=(0,l.useState)("system"),[eQ,eW]=(0,l.useState)("light"),[eG,eY]=(0,l.useState)(()=>"independent-notes"===localStorage.getItem("currentSection")),[eV,eH]=(0,l.useState)(!1),[eK,eX]=(0,l.useState)(()=>localStorage.getItem("currentSection")||"dashboard"),[e0,e1]=(0,l.useState)(null);(0,l.useEffect)(()=>{(async()=>{if(!eI.trim()){console.log("Search query is empty, clearing results"),eP([]);return}console.log("Search triggered with query:",eI,"showIndependentNotes:",eG,"searchFilter:",eR),console.log("Search query length:",eI.length,"Trimmed length:",eI.trim().length),eD(!0);try{let i=(0,B.UU)();if(eG){var e,t,r,n,l,o,s;console.log("Searching independent notes with query:",eI,"filter:",eR);let a=[],d=null;if("user"===eR){let{data:e,error:n}=await i.from("profiles").select("id, username, full_name, avatar_url, bio").or("full_name.ilike.%".concat(eI,"%,username.ilike.%").concat(eI,"%")).limit(20);if(n)d=n;else if(e&&e.length>0){let n=e.map(e=>e.id),[l,o]=await Promise.all([i.from("follows").select("following_id, follower_id").in("following_id",n),i.from("follows").select("following_id, follower_id").in("follower_id",n)]);l.error&&(d=l.error),o.error&&(d=o.error);let s=new Map;null===(t=l.data)||void 0===t||t.forEach(e=>{s.set(e.following_id,(s.get(e.following_id)||0)+1)});let c=new Map;null===(r=o.data)||void 0===r||r.forEach(e=>{c.set(e.follower_id,(c.get(e.follower_id)||0)+1)}),a=e.map(e=>({resultType:"user",id:e.id,username:e.username,full_name:e.full_name,avatar_url:e.avatar_url,bio:e.bio,followers_count:s.get(e.id)||0,following_count:c.get(e.id)||0}))}}else{let e=i.from("notes").select("id");e="title"===eR?e.ilike("title","%".concat(eI,"%")):e.or("title.ilike.%".concat(eI,"%,content.ilike.%").concat(eI,"%"));let{data:t,error:r}=await e.limit(20);if(r)d=r;else if(t&&t.length>0){let e=t.map(e=>e.id),{data:r,error:n}=await i.from("independent_notes").select("*").in("note_id",e).order("created_at",{ascending:!1}).limit(20);a=r||[],d=n}}if(d)throw console.error("Independent notes search error:",d),d;if(0===a.length){eP([]);return}if((null===(e=a[0])||void 0===e?void 0:e.resultType)==="user")eP(a);else{let e=a.map(e=>e.note_id),t=a.map(e=>e.user_id),{data:{user:r}}=await i.auth.getUser(),[d,c,u,m,h,f]=await Promise.all([i.from("notes").select("id, title, content, created_at, background_color").in("id",e),i.from("profiles").select("id, username, full_name, avatar_url, bio").in("id",t),e.length?
1i.from("note_likes").select("note_id").in("note_id",e):Promise.resolve({data:[],error:null}),r?i.from("note_likes").select("note_id").eq("user_id",r.id).in("note_id",e):Promise.resolve({data:[],error:null}),t.length?i.from("follows").select("following_id, follower_id").in("following_id",t):Promise.resolve({data:[],error:null}),t.length?i.from("follows").select("following_id, follower_id").in("follower_id",t):Promise.resolve({data:[],error:null})]);if(d.error)throw d.error;if(c.error)throw c.error;if(u&&"error"in u&&u.error)throw u.error;if(m.error)throw m.error;if(h.error)throw h.error;if(f.error)throw f.error;let x=new Map;null==u||null===(n=u.data)||void 0===n||n.forEach(e=>{x.set(e.note_id,(x.get(e.note_id)||0)+1)});let g=new Set((null===(l=m.data)||void 0===l?void 0:l.map(e=>e.note_id))||[]),p=new Map;null==h||null===(o=h.data)||void 0===o||o.forEach(e=>{p.set(e.following_id,(p.get(e.following_id)||0)+1)});let v=new Map;null==f||null===(s=f.data)||void 0===s||s.forEach(e=>{v.set(e.follower_id,(v.get(e.follower_id)||0)+1)});let w=a.map(e=>{var t,r;return{...e,notes:null===(t=d.data)||void 0===t?void 0:t.find(t=>t.id===e.note_id),profiles:null===(r=c.data)||void 0===r?void 0:r.find(t=>t.id===e.user_id),likes_count:x.get(e.note_id)||0,subnotes_count:Math.max(0,e.subnotes_count||0),is_liked:g.has(e.note_id)}}).filter(e=>e.notes);eP(w||[])}}else{let{data:{user:e}}=await i.auth.getUser();if(!e){console.log("No current user found for My Notes search"),eP([]);return}let{data:t,error:r}=await i.from("notes").select("*").eq("user_id",e.id).or("title.ilike.%".concat(eI,"%,content.ilike.%").concat(eI,"%")).order("created_at",{ascending:!1}).limit(20);if(r)throw console.error("My notes search error:",r),r;eP(t||[])}}catch(e){console.error("Search error:",e),eP([])}finally{eD(!1)}})()},[eI,eG,eR]),(0,l.useEffect)(()=>{console.log("Search query changed to:",eE,"showIndependentNotes:",eG)},[eE,eG]);let[e2,e3]=(0,l.useState)(""),[e5,e4]=(0,l.useState)(""),[e6,e8]=(0,l.useState)({name:"Default Warm Beige",value:"defaultWarmBeige",class:"",color:K.fJ,oppositeColor:"#1a1a1a"}),[e7,e9]=(0,l.useState)(0),[te,tt]=(0,l.useState)(0),[tr,tn]=(0,l.useState)(!1),[tl,to]=(0,l.useState)(""),[ts,ti]=(0,l.useState)(!1),[ta,td]=(0,l.useState)({bold:!1,italic:!1,underline:!1}),[tc,tu]=(0,l.useState)(!1),[tm,th]=(0,l.useState)(""),[tf,tx]=(0,l.useState)(!1),[tg,tp]=(0,l.useState)(""),[tv,tw]=(0,l.useState)(!1),[t_,tb]=(0,l.useState)(!1),[tj,tN]=(0,l.useState)(!1),[ty,tk]=(0,l.useState)(null),[tS,tC]=(0,l.useState)(!1),[tA,tE]=(0,l.useState)(!1),[tU,tI]=(0,l.useState)({x:0,y:0}),[tM,tq]=(0,l.useState)(0),[tz,tP]=(0,l.useState)(null),[tF,tT]=(0,l.useState)(!1),t$=(0,l.useRef)(new Map),[tD,tL]=(0,l.useState)(new Set),[tO,tR]=(0,l.useState)(new Set),[tB,tJ]=(0,l.useState)(!1),[tZ,tQ]=(0,l.useState)(!1),[tW,tG]=(0,l.useState)(!1),[tY,tV]=(0,l.useState)([]),[tH,tK]=(0,l.useState)([]),[tX,t0]=(0,l.useState)(!1),[t1,t2]=(0,l.useState)(null),[t3,t5]=(0,l.useState)(null),[t4,t6]=(0,l.useState)(null),[t8,t7]=(0,l.useState)("newest"),[t9,re]=(0,l.useState)(!1),[rt,rr]=(0,l.useState)(0),rn=(0,l.useRef)((()=>{try{let e=sessionStorage.getItem("independentCountsCache");if(!e)return new Map;let t=JSON.parse(e),r=new Map;return Object.entries(t).forEach(e=>{let[t,n]=e;return r.set(t,{likes:Math.max(0,n.likes||0),subnotes:Math.max(0,n.subnotes||0)})}),r}catch(e){return new Map}})());(0,l.useEffect)(()=>{try{let e=sessionStorage.getItem("independentCountsCache");if(e){let t=JSON.parse(e),r=new Map;Object.entries(t).forEach(e=>{let[t,n]=e;return r.set(t,{likes:Math.max(0,n.likes||0),subnotes:Math.max(0,n.subnotes||0)})}),rn.current=r}}catch(e){}},[]);let rl=()=>{try{let e={};rn.current.forEach((t,r)=>{e[r]={likes:Math.max(0,t.likes||0),subnotes:Math.max(0,t.subnotes||0)}}),sessionStorage.setItem("independentCountsCache",JSON.stringify(e))}catch(e){}};(0,l.useEffect)(()=>{var e;let t=localStorage.getItem("theme");t&&(eZ(t),r_(t));let r=localStorage.getItem("currentSection"),n=null===(e=performance.getEntriesByType("navigation")[0])||void 0===e?void 0:e.type;if("independent-notes"===r){if(("reload"===n||"navigate"===n)&&(null==es?void 0:es.id))try{let e="independentNotes:".concat(es.id),t=sessionStorage.getItem(e);if(t){let e=JSON.parse(t);e&&Array.isArray(e.data)&&e.data.length>0?eT(!1):eT(!0)}else eT(!0)}catch(e){eT(!0)}else eT(!1);eX("independent-notes"),eY(!0)}else eX("dashboard"),eY(!1),eT(!1)},[]),(0,l.useEffect)(()=>{((null==e6?void 0:e6.value)==="defaultWarmBeige"||(null==e6?void 0:e6.value)==="defaultCharcoal")&&("dark"===eQ&&e6.color!==K.tj&&e8({name:"Default Charcoal",value:"defaultCharcoal",class:"",color:K.tj,oppositeColor:"#ffffff"}),"light"===eQ&&e6.color!==K.fJ&&e8({name:"Default Warm Beige",value:"defaultWarmBeige",class:"",color:K.fJ,oppositeColor:"#1a1a1a"}))},[eQ]);let ro=async e=>{if(!e){t6((0,Y.sQ)());return}if((0,Y.vZ)(e))try{let t=(0,B.UU)(),r=(0,V.EP)(es.id,e);
1if(r)try{if((await fetch(r,{method:"HEAD"})).ok){t6(r);return}console.log("Cached avatar URL is invalid, refreshing...")}catch(e){console.log("Cached avatar URL failed to load, refreshing...")}let n=await (0,Y.$w)(e,t);n?(t6(n),(0,V.Ih)(es.id,e,n)):t6((0,Y.sQ)())}catch(e){console.error("Failed to load current user avatar:",e),t6((0,Y.sQ)())}else t6((0,Y.sQ)())};(0,l.useEffect)(()=>{(async()=>{if(null==es?void 0:es.id)try{let e=(0,B.UU)(),{data:t}=await e.from("profiles").select("id, full_name, username, avatar_url").eq("id",es.id).maybeSingle();t&&(t5(t),await ro(t.avatar_url))}catch(e){console.error("Error loading current user profile:",e)}})()},[null==es?void 0:es.id]),(0,l.useEffect)(()=>{if(eG&&es&&!ef.current)try{let e="independentNotes:".concat(es.id),t=sessionStorage.getItem(e);if(t){let e=JSON.parse(t);if(e&&Array.isArray(e.data)&&e.data.length>0){eh(e.data),ef.current=!0,eT(!1);return}}}catch(e){}if(eG&&es){if(ef.current&&em.length>0)return;ef.current&&0!==em.length||(0===em.length&&eT(!0),rm())}},[eG,es]),(0,l.useEffect)(()=>{let e=()=>{let e=document.documentElement.classList.contains("dark")?"dark":"light";eW(e);let t="dark"===e?K.uZ:K.qI,r=Math.min(Math.max("number"==typeof te?te:0,0),t.length-1);e8(t[r])};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,l.useEffect)(()=>{es&&(rh(),rc(),ru(),"requestIdleCallback"in window?requestIdleCallback(()=>{ri()}):setTimeout(()=>ri(),100),"requestIdleCallback"in window?requestIdleCallback(()=>{rs()},{timeout:2e3}):setTimeout(()=>rs(),500))},[es]);let rs=()=>{if(!(null==es?void 0:es.id))return;let e=(0,B.UU)(),t=e.channel("user-likes:".concat(es.id)).on("postgres_changes",{event:"*",schema:"public",table:"note_likes"},e=>{console.log("Real-time like update:",e),rc(),rh(),rm()}).subscribe(),r=e.channel("user-follows:".concat(es.id)).on("postgres_changes",{event:"*",schema:"public",table:"follows"},e=>{console.log("Real-time follow update:",e),ru()}).subscribe(),n=e.channel("user-notes:".concat(es.id)).on("postgres_changes",{event:"*",schema:"public",table:"notes",filter:"user_id=eq.".concat(es.id)},e=>{console.log("Real-time notes update:",e),rh()}).subscribe(),l=e.channel("independent-notes:".concat(es.id)).on("postgres_changes",{event:"*",schema:"public",table:"independent_notes"},e=>{console.log("Real-time independent notes update:",e),rm()}).subscribe();return()=>{e.removeChannel(t),e.removeChannel(r),e.removeChannel(n),e.removeChannel(l)}};(0,l.useEffect)(()=>{let e=()=>{"undefined"!=typeof document&&"visible"===document.visibilityState&&(eG?rm(0):rh(0))};return"undefined"!=typeof document&&document.addEventListener("visibilitychange",e),()=>{"undefined"!=typeof document&&document.removeEventListener("visibilitychange",e)}},[eG]),(0,l.useEffect)(()=>{if(eG||!eA.current||!ey||eS)return;let e=new IntersectionObserver(e=>{if(e[0].isIntersecting){let e=ej+1;eN(e),rh(e)}},{root:null,rootMargin:"400px 0px",threshold:.1}),t=eA.current;return e.observe(t),()=>e.unobserve(t)},[eG,ey,eS,ej,ec.length]),(0,l.useEffect)(()=>{if(ei&&ec.length>0){let e=ec.find(e=>e.id===ei);e&&ry(e)}},[ei,ec]);let ri=async()=>{if(null==es?void 0:es.id)try{let e=(0,B.UU)(),{data:t}=await e.from("notes").select("id").eq("user_id",es.id),r=(null==t?void 0:t.map(e=>e.id))||[],[n,l]=await Promise.all([r.length>0?e.from("note_likes").select("id",{count:"exact",head:!0}).in("note_id",r).gte("created_at",new Date(Date.now()-6048e5).toISOString()):{count:0},e.from("follows").select("id",{count:"exact",head:!0}).eq("following_id",es.id).gte("created_at",new Date(Date.now()-6048e5).toISOString())]),o=n.count||0,s=l.count||0;tq(o+s)}catch(e){console.error("Error loading unread notifications count:",e)}},ra=()=>{"independent-notes"!==eK&&(console.log("Switching to independent notes section"),eY(!0),eX("independent-notes"),localStorage.setItem("currentSection","independent-notes"),eg(0),ev(!0),e_(!1),ef.current&&em.length>0||ef.current&&0!==em.length||(eT(!0),rm()))},rd=()=>{eY(!1),eX("dashboard"),localStorage.setItem("currentSection","dashboard"),eN(0),ek(!0),eC(!1)};(0,l.useEffect)(()=>{let e=ec.map(e=>{if(e.background_color){let t,r=K.qI.findIndex(t=>t.color===e.background_color);if(-1!==r?t="dark"===eQ?K.uZ[r]:K.qI[r]:-1!==(r=K.uZ.findIndex(t=>t.color===e.background_color))&&(t="light"===eQ?K.qI[r]:K.uZ[r]),t)return{...e,background_color:t.color}}return e}),t=em.map(e=>{var t;if(null===(t=e.notes)||void 0===t?void 0:t.background_color){let t,r=K.qI.findIndex(t=>t.color===e.notes.background_color);if(-1!==r?t="dark"===eQ?K.uZ[r]:K.qI[r]:-1!==(r=K.uZ.findIndex(t=>t.color===e.notes.background_color))&&(t="light"===eQ?K.qI[r]:K.uZ[r]),t)return{...e,notes:{...e.notes,background_color:t.color}}}return e});eu(e),eh(t)},[eQ]);let rc=async()=>
1{if(es)try{let e=(0,B.UU)(),{data:t,error:r}=await e.from("note_likes").select("note_id").eq("user_id",es.id);if(r)throw r;tL(new Set((null==t?void 0:t.map(e=>e.note_id))||[]))}catch(e){console.error("Error fetching user likes:",e)}},ru=async()=>{if(es)try{let e=(0,B.UU)(),{data:t,error:r}=await e.from("follows").select("following_id").eq("follower_id",es.id);if(r)throw r;tR(new Set((null==t?void 0:t.map(e=>e.following_id))||[]))}catch(e){console.error("Error fetching user follows:",e)}},rm=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(0===e&&ef.current&&em.length>0)return;let t=em.length>0;0===e?t||eT(!0):e_(!0);try{let r=(0,B.UU)(),{data:{user:n}}=await r.auth.getUser();if(!n){t||eT(!1);return}let{data:l,error:o}=await r.from("independent_notes").select("\n          id,\n          note_id,\n          user_id,\n          created_at,\n          granted_by,\n          likes_count\n        ").order("created_at",{ascending:!1}).range(24*e,24*e+24-1);if(o)throw o;let s=(null==l?void 0:l.map(e=>e.note_id))||[],i=(null==l?void 0:l.map(e=>e.user_id))||[],[a,d]=await Promise.all([r.from("notes").select("id, title, content, created_at, background_color").in("id",s),r.from("profiles").select("id, username, full_name, avatar_url, bio").in("id",i)]);if(a.error)throw a.error;if(d.error)throw d.error;let c=new Map;em.forEach(e=>{c.set(e.note_id,{likes:Math.max(0,e.likes_count||0),subnotes:Math.max(0,e.subnotes_count||0)})});let u=(null==l?void 0:l.map(e=>{var t,r,n,l,o,s;let i=c.get(e.note_id),u=rn.current.get(e.note_id),m=Number.isFinite(e.likes_count)?e.likes_count:0,h=Math.max(0,m,null!==(n=null==i?void 0:i.likes)&&void 0!==n?n:0,null!==(l=null==u?void 0:u.likes)&&void 0!==l?l:0),f=Math.max(0,null!==(o=null==i?void 0:i.subnotes)&&void 0!==o?o:0,null!==(s=null==u?void 0:u.subnotes)&&void 0!==s?s:0);return{...e,notes:null===(t=a.data)||void 0===t?void 0:t.find(t=>t.id===e.note_id),profiles:null===(r=d.data)||void 0===r?void 0:r.find(t=>t.id===e.user_id),likes_count:h,subnotes_count:f,is_liked:tD.has(e.note_id)}}))||[],m=(Array.isArray(u)?u:[]).filter(e=>(null==e?void 0:e.notes)!==void 0);eh(t=>0===e?m:[...t,...m.filter(e=>!t.some(t=>t.note_id===e.note_id))]),ef.current=!0,ev(24===((null==m?void 0:m.length)||0)),0===e&&eg(0);try{sessionStorage.setItem("independentNotes:".concat(n.id),JSON.stringify({t:Date.now(),data:m}))}catch(e){}(async()=>{try{var e,t,l;let[o,i,a]=await Promise.all([s.length?r.from("note_likes").select("note_id").in("note_id",s):Promise.resolve({data:[],error:null}),r.from("note_likes").select("note_id").eq("user_id",n.id).in("note_id",s),r.from("subnotes").select("note_id").in("note_id",s)]);if(null==o?void 0:o.error)throw o.error;if(null==i?void 0:i.error)throw i.error;if(null==a?void 0:a.error)throw a.error;let d=new Map;null==o||null===(e=o.data)||void 0===e||e.forEach(e=>{d.set(e.note_id,(d.get(e.note_id)||0)+1)});let c=new Map;null==a||null===(t=a.data)||void 0===t||t.forEach(e=>{c.set(e.note_id,(c.get(e.note_id)||0)+1)});let u=new Set((null==i?void 0:null===(l=i.data)||void 0===l?void 0:l.map(e=>e.note_id))||[]),m=new Set([...Array.from(u),...Array.from(tD)]);eh(e=>{let t=e.map(e=>{let t=d.has(e.note_id)?d.get(e.note_id):e.likes_count||0,r=c.has(e.note_id)?c.get(e.note_id):e.subnotes_count||0;return{...e,likes_count:Math.max(e.likes_count||0,t),subnotes_count:Math.max(e.subnotes_count||0,r),is_liked:m.has(e.note_id)}});try{sessionStorage.setItem("independentNotes:".concat(n.id),JSON.stringify({t:Date.now(),data:t}))}catch(e){}return t.forEach(e=>{var t,r,n,l;let o=rn.current.get(e.note_id)||{likes:0,subnotes:0},s={likes:Math.max(0,null!==(r=null!==(t=e.likes_count)&&void 0!==t?t:o.likes)&&void 0!==r?r:0),subnotes:Math.max(0,null!==(l=null!==(n=e.subnotes_count)&&void 0!==n?n:o.subnotes)&&void 0!==l?l:0)};rn.current.set(e.note_id,s)}),rl(),t})}catch(e){console.log("Background enrichment failed:",e)}})()}catch(e){console.error("Error fetching independent notes:",e),0===em.length&&eT(!1)}finally{0===e?eT(!1):e_(!1)}};(0,l.useEffect)(()=>{if(!eG||!eb.current||!ep||ew)return;let e=new IntersectionObserver(e=>{if(e[0].isIntersecting){let e=ex+1;eg(e),rm(e)}},{root:null,rootMargin:"400px 0px",threshold:.1}),t=eb.current;return e.observe(t),()=>e.unobserve(t)},[eG,ep,ew,ex,em.length]);let rh=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(es)try{var t;let r=(0,B.UU)();e>0&&eC(!0);let{data:n,error:l}=await r.from("notes").select("*").eq("user_id",es.id).order("updated_at",{ascending:!1}).range(24*e,24*e+24-1);if(l)throw l;let o=(null==n?void 0:n.map(e=>e.id))||[],s=o.length?await r.from("note_likes").select("note_id").in("note_id",o):{data:[],error:null};if(s.error)throw s.error;let i=new Map;
1null===(t=s.data)||void 0===t||t.forEach(e=>{i.set(e.note_id,(i.get(e.note_id)||0)+1)});let{data:a,error:d}=await r.from("subnotes").select("note_id").in("note_id",o);if(d)throw d;let c=new Map;null==a||a.forEach(e=>{c.set(e.note_id,(c.get(e.note_id)||0)+1)});let u=(n||[]).map(e=>{let t=i.get(e.id)||0,r=c.get(e.id)||0,n=tD.has(e.id);return{...e,likes_count:t,subnotes_count:r,is_liked:n}});eu(t=>0===e?u:[...t,...u.filter(e=>!t.some(t=>t.id===e.id))]),ek(24===u.length),0===e&&eN(0)}catch(e){console.error("Error fetching notes:",e)}finally{e>0&&eC(!1)}},rf=async e=>{if(es)try{let t=(0,B.UU)(),r=tD.has(e);if(r){let{error:r}=await t.from("note_likes").delete().eq("note_id",e).eq("user_id",es.id);if(r)throw r;tL(t=>{let r=new Set(t);return r.delete(e),r})}else{let{error:r}=await t.from("note_likes").insert([{note_id:e,user_id:es.id}]);if(r)throw r;tL(t=>new Set([...t,e]))}eh(t=>t.map(t=>t.note_id===e?{...t,likes_count:r?t.likes_count-1:t.likes_count+1,is_liked:!r}:t)),eu(t=>t.map(t=>t.id===e?{...t,likes_count:r?(t.likes_count||0)-1:(t.likes_count||0)+1,is_liked:!r}:t));try{let{data:e}=await t.from("note_likes").select("note_id").eq("user_id",es.id),r=new Set((e||[]).map(e=>e.note_id));tL(r)}catch(e){console.warn("Failed to refresh likes set",e)}}catch(e){console.error("Error toggling like:",e)}},rx=async e=>{try{let t=t$.current.get(e);if(t){tP(t),tT(!0);return}let r=(0,B.UU)(),{data:n,error:l}=await r.from("profiles").select("id, username, full_name, avatar_url, bio").eq("id",e).single();if(l)throw l;let[o,s,i,a]=await Promise.all([r.from("notes").select("id",{count:"exact"}).eq("user_id",e),r.from("independent_notes").select("id",{count:"exact"}).eq("user_id",e),r.from("follows").select("id",{count:"exact"}).eq("following_id",e),r.from("follows").select("id",{count:"exact"}).eq("follower_id",e)]),d={...n,notes_count:o.count||0,independent_notes_count:s.count||0,followers_count:i.count||0,following_count:a.count||0,is_following:tO.has(e)};t$.current.set(e,d),tP(d),tT(!0)}catch(e){console.error("Error fetching user profile:",e)}},rg=async e=>{t0(!0);try{let t=(0,B.UU)(),{data:r,error:n}=await t.from("follows").select("\n          follower_id,\n          created_at,\n          profiles!inner(id, username, full_name, avatar_url, bio, created_at)\n        ").eq("following_id",e).order("created_at",{ascending:!1}).limit(50);if(n){console.error("Error fetching followers:",n),tV([]);return}let l=(null==r?void 0:r.map(e=>({id:e.profiles.id,username:e.profiles.username,full_name:e.profiles.full_name,avatar_url:e.profiles.avatar_url,bio:e.profiles.bio,followed_at:e.created_at})))||[],o=await rv(l);tV(o),console.log("Fetched ".concat(o.length," followers for user ").concat(e))}catch(e){console.error("Error fetching followers:",e),tV([])}finally{t0(!1)}},rp=async e=>{t0(!0);try{let t=(0,B.UU)(),{data:r,error:n}=await t.from("follows").select("\n          following_id,\n          created_at,\n          profiles!inner(id, username, full_name, avatar_url, bio, created_at)\n        ").eq("follower_id",e).order("created_at",{ascending:!1}).limit(50);if(n){console.error("Error fetching following:",n),tK([]);return}let l=(null==r?void 0:r.map(e=>({id:e.profiles.id,username:e.profiles.username,full_name:e.profiles.full_name,avatar_url:e.profiles.avatar_url,bio:e.profiles.bio,followed_at:e.created_at})))||[],o=await rv(l);tK(o),console.log("Fetched ".concat(o.length," following for user ").concat(e))}catch(e){console.error("Error fetching following:",e),tK([])}finally{t0(!1)}},rv=async e=>{if(!e||0===e.length)return[];let t=(0,B.UU)(),r=e.map(e=>e.id),{data:n}=await t.from("profiles").select("id, followers_count, following_count").in("id",r),l={};(n||[]).forEach(e=>{l[e.id]={followers_count:e.followers_count,following_count:e.following_count}});let o=e.some(e=>{var t,r;return(null===(t=l[e.id])||void 0===t?void 0:t.followers_count)===void 0||(null===(r=l[e.id])||void 0===r?void 0:r.following_count)===void 0}),s={},i={};if(o){let[{data:e},{data:n}]=await Promise.all([t.from("follows").select("following_id").in("following_id",r),t.from("follows").select("follower_id").in("follower_id",r)]);s=(e||[]).reduce((e,t)=>
1(e[t.following_id]=(e[t.following_id]||0)+1,e),{}),i=(n||[]).reduce((e,t)=>(e[t.follower_id]=(e[t.follower_id]||0)+1,e),{})}return e.map(e=>{var t,r,n,o,a,d;return{...e,followers_count:null!==(o=null!==(n=null===(t=l[e.id])||void 0===t?void 0:t.followers_count)&&void 0!==n?n:s[e.id])&&void 0!==o?o:0,following_count:null!==(d=null!==(a=null===(r=l[e.id])||void 0===r?void 0:r.following_count)&&void 0!==a?a:i[e.id])&&void 0!==d?d:0}})},rw=async e=>{if(es&&!tB)try{tJ(!0);let t=(0,B.UU)(),r=tO.has(e);if(r){let{error:r}=await t.from("follows").delete().eq("follower_id",es.id).eq("following_id",e);if(r)throw r;tR(t=>{let r=new Set(t);return r.delete(e),r})}else{let{error:r}=await t.from("follows").insert([{follower_id:es.id,following_id:e}]);if(r)throw r;tR(t=>new Set([...t,e]))}let n=r?-1:1;if((null==tz?void 0:tz.id)===e){let t={...tz,followers_count:(tz.followers_count||0)+n,is_following:!r};tP(t),t$.current.set(e,t)}else{let t=t$.current.get(e);t&&t$.current.set(e,{...t,followers_count:(t.followers_count||0)+n,is_following:!r})}(null==tz?void 0:tz.id)===es.id&&tP(e=>e?{...e,following_count:(e.following_count||0)+n}:e);let l=t$.current.get(es.id);l&&t$.current.set(es.id,{...l,following_count:(l.following_count||0)+n})}catch(e){console.error("Error toggling follow:",e)}finally{tJ(!1)}},r_=e=>{let t=window.document.documentElement;if(t.classList.remove("light","dark"),"system"===e){let e=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";t.classList.add(e)}else t.classList.add(e)},rb=e=>{eZ(e),localStorage.setItem("theme",e),r_(e)},rj=[...(Array.isArray(ec)?ec:[]).filter(e=>{var t;let r=(null===(t=e.title)||void 0===t?void 0:t.toLowerCase().includes(eE.toLowerCase()))||e.content.toLowerCase().includes(eE.toLowerCase());return"public"===eL?r&&!e.is_private:r})].sort((e,t)=>{let r=new Date(e.created_at||0).getTime();return new Date(t.created_at||0).getTime()-r}),rN=()=>{e3(""),e4(""),e8("dark"===eQ?K.uZ[0]:K.qI[0]),e1(null),tn(!1),to(""),tu(!1),tw(!1),td({bold:!1,italic:!1,underline:!1}),eH(!0)},ry=e=>{e1(e),e3(e.title||""),e4(e.content);let t=K.qI.findIndex(t=>t.color===e.background_color);if(-1===t){let r=K.uZ.findIndex(t=>t.color===e.background_color);-1!==r&&(t=r)}let r=-1===t?0:Math.min(t,K.qI.length-1);tt(r),e8("dark"===eQ?K.uZ[r]:K.qI[r]),td({bold:!1,italic:!1,underline:!1}),to(""),tu(!0),eH(!0),rS(e.id).then(e=>{tw(e)})},rk=async()=>{if(!e2.trim()){to("Title is required");return}if(e2.length>70){to("Title must be 70 characters or less");return}if(e5.trim()){to("");try{let e={title:e2,content:e5,is_private:!tv,user_id:es.id,background_color:e6.color};if(null==e0?void 0:e0.id){let t=(0,B.UU)(),{error:r}=await t.from("notes").update(e).eq("id",e0.id);if(r){console.error("Error updating note:",r),tp("Failed to update note. Please try again."),tx(!0),setTimeout(()=>tx(!1),3e3);return}tp("Note updated successfully!"),tx(!0),setTimeout(()=>tx(!1),2e3)}else{let t=(0,B.UU)(),{data:r,error:n}=await t.from("notes").insert([e]).select().single();if(n){console.error("Error creating note:",n),tp("Failed to create note. Please try again."),tx(!0),setTimeout(()=>tx(!1),3e3);return}e1(r),tp("Note saved successfully!"),tx(!0),setTimeout(()=>tx(!1),2e3)}if(tu(!0),null==e0?void 0:e0.id){let e=await rS(e0.id);tw(e),e&&rm()}else tv&&rm();rh()}catch(e){console.error("Error saving note:",e),tp("An unexpected error occurred. Please try again."),tx(!0),setTimeout(()=>tx(!1),3e3)}}},rS=async e=>{if(!e)return!1;try{let t=(0,B.UU)(),{data:r,error:n}=await t.from("independent_notes").select("id").eq("note_id",e).single();if(n&&"PGRST116"!==n.code)return console.error("Error checking note status:",n),!1;return!!r}catch(e){return console.error("Error checking note status:",e),!1}},rC=async()=>{e0&&es&&ea({title:"Grant Independence",description:"Are you sure you want to grant independence to your note? It will make your note public and visible to everyone.",variant:"warning",confirmText:"Make Public",cancelText:"Cancel",persistent:!1,onConfirm:async()=>{var e,t,r;if(!e0.id)return;let n={id:"temp-".concat(e0.id),note_id:e0.id,user_id:es.id,created_at:new Date().toISOString(),granted_by:es.id,notes:e0,profiles:{id:es.id,username:(null===(e=es.user_metadata)||void 0===e?void 0:e.username)||(null==t3?void 0:t3.username)||"",full_name:(null===(t=es.user_metadata)||void 0===t?void 0:t.full_name)||(null==t3?void 0:t3.full_name)||"",avatar_url:(null===(r=es.user_metadata)||void 0===r?void 0:r.avatar_url)||(null==t3?void 0:t3.avatar_url)||"",bio:""},likes_count:0,subnotes_count:0,is_liked:!1}
1;eh(e=>[n,...e]),tw(!0),tu(!1);try{let e=(0,B.UU)(),{error:t}=await e.from("notes").update({is_private:!1}).eq("id",e0.id);if(t){console.error("Error updating note privacy:",t),eh(e=>e.filter(e=>e.id!=="temp-".concat(e0.id))),tw(!1),ed({title:"Failed",description:"Failed to make note public. Please try again.",variant:"destructive"});return}let{error:r}=await e.from("independent_notes").insert({note_id:e0.id,user_id:es.id,granted_by:es.id});if(r){console.error("Error creating independent note:",r),eh(e=>e.filter(e=>e.id!=="temp-".concat(e0.id))),tw(!1),ed({title:"Failed",description:"Failed to grant independence. Please try again.",variant:"destructive"});return}ed({title:"Note Made Public",description:"Your note has been successfully made public.",variant:"success"}),tu(!1),eH(!1),rh(),rm()}catch(e){console.error("Error granting independence:",e),eh(e=>e.filter(e=>e.id!=="temp-".concat(e0.id))),tw(!1),ed({title:"An unexpected error occurred. Please try again.",variant:"destructive"})}}})},rA=async()=>{if(e0&&es)try{let e=(0,B.UU)(),{error:t}=await e.from("independent_notes").delete().eq("note_id",e0.id);if(t){console.error("Error removing from independent notes:",t),ed({title:"Failed",description:"Failed to make note private. Please try again.",variant:"destructive"});return}let{error:r}=await e.from("notes").update({is_private:!0}).eq("id",e0.id);if(r){console.error("Error updating note privacy:",r),ed({title:"Failed",description:"Failed to make note private. Please try again.",variant:"destructive"});return}ed({title:"Note Made Private",description:"Your note has been successfully made private.",variant:"success"}),tw(!1),rh(),rm()}catch(e){console.error("Error making note private:",e),ed({title:"An unexpected error occurred. Please try again.",variant:"destructive"})}},rE=async e=>{let t=ec.find(t=>t.id===e),r=(null==t?void 0:t.title)||"Untitled";ea({title:"Delete Note",description:'Are you sure you want to delete "'.concat(r,'"? This action cannot be undone.'),variant:"destructive",confirmText:"Delete",cancelText:"Cancel",persistent:!0,onConfirm:async()=>{tb(!0),tk(e);try{await G(e),ed({title:"Note Deleted",description:"Your note has been successfully deleted.",variant:"success"}),rh()}catch(e){console.error("Error deleting note:",e),ed({title:"Delete Failed",description:"Failed to delete the note. Please try again.",variant:"destructive"})}finally{tb(!1),tk(null)}}})},rU=async e=>{let t=em.find(t=>t.notes.id===e),r=(null==t?void 0:t.notes.title)||"Untitled";ea({title:"Delete Note",description:'Are you sure you want to delete "'.concat(r,'"? This action cannot be undone.'),variant:"destructive",confirmText:"Delete",cancelText:"Cancel",persistent:!0,onConfirm:async()=>{let t=em.find(t=>t.notes.id===e);eh(t=>t.filter(t=>t.notes.id!==e)),tb(!0),tk(e);try{await G(e),ed({title:"Note Deleted",description:"Your note has been successfully deleted.",variant:"success"}),rm()}catch(e){console.error("Error deleting independent note:",e),t&&eh(e=>[...e,t]),ed({title:"Delete Failed",description:"Failed to delete the note. Please try again.",variant:"destructive"})}finally{tb(!1),tk(null)}}})},rI=e=>{let t=new Date(e);return{time:t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}),day:t.toLocaleDateString("en-US",{month:"short",day:"numeric"})}},rM=e=>e&&"object"==typeof e&&"note_id"in e,rq=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(m.lG,{open:tF,onOpenChange:tT,children:(0,n.jsx)(m.Cf,{className:"w-full max-w-md 
1sm:max-w-sm p-0 overflow-hidden rounded-2xl shadow-xl",children:tz&&(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("div",{className:"relative h-32 bg-gradient-to-br from-pink-400 via-red-500 to-orange-500",children:(0,n.jsx)("div",{className:"absolute bottom-0 left-1/2 transform -translate-x-1/2 translate-y-1/2",children:(0,n.jsx)(u.F,{src:tz.avatar_url,alt:tz.username,fallback:(null===(t=tz.username)||void 0===t?void 0:t.charAt(0).toUpperCase())||"U",size:"xl",userId:tz.id})})}),(0,n.jsxs)("div",{className:"pt-16 pb-6 px-6 text-center",children:[(0,n.jsxs)("h2",{className:"text-2xl font-bold mb-1",children:["@",tz.username]}),tz.full_name&&(0,n.jsx)("p",{className:"text-muted-foreground mb-4",children:tz.full_name}),tz.bio&&(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:tz.bio}),(0,n.jsxs)("div",{className:"flex items-center justify-center gap-6 mb-4 border-y py-3",children:[(0,n.jsxs)("button",{onClick:()=>{rg(tz.id),tQ(!0)},className:"text-center hover:text-primary transition-colors cursor-pointer",children:[(0,n.jsx)("div",{className:"text-xl font-bold",children:tz.followers_count||0}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:"Followers"})]}),(0,n.jsxs)("button",{onClick:()=>{rp(tz.id),tG(!0)},className:"text-center hover:text-primary transition-colors cursor-pointer",children:[(0,n.jsx)("div",{className:"text-xl font-bold",children:tz.following_count||0}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:"Following"})]})]}),tz.id!==(null==es?void 0:es.id)&&(0,n.jsxs)("div",{className:"flex gap-2 justify-center",children:[(0,n.jsx)(o.$,{onClick:()=>rw(tz.id),variant:tz.is_following?"outline":"default",size:"sm",className:"flex-1 text-sm",children:tz.is_following?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(b.A,{className:"h-3 w-3 mr-1.5"}),"Following"]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.A,{className:"h-3 w-3 mr-1.5"}),"Follow"]})}),(0,n.jsx)(W(),{href:"/profile/".concat(tz.username),children:(0,n.jsxs)(o.$,{variant:"outline",size:"sm",className:"flex-1 text-sm",children:[(0,n.jsx)(N.A,{className:"h-3 w-3 mr-1.5"}),"View Profile"]})})]})]})]})})}),(0,n.jsx)(m.lG,{open:!!t1,onOpenChange:()=>t2(null),children:(0,n.jsxs)(m.Cf,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[(0,n.jsx)(m.c7,{className:"pr-12",children:(()=>{var e;if(!t1)return null;let t=ec.find(e=>e.id===t1)||em.find(e=>e.id===t1);if(!t)return(0,n.jsx)(m.L3,{children:"Note Details"});let r=rM(t),l=r?t.note_id:t.id;return(0,n.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0",children:r&&t.profiles?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(u.F,{src:t.profiles.avatar_url,alt:t.profiles.username,fallback:(null===(e=t.profiles.username)||void 0===e?void 0:e.charAt(0).toUpperCase())||"U",size:"sm",userId:t.profiles.id}),(0,n.jsx)("div",{className:"min-w-0",children:(0,n.jsxs)(m.L3,{className:"mb-0 truncate",children:["@",t.profiles.username]})})]}):(0,n.jsx)(m.L3,{className:"mb-0 truncate",children:"Note Details"})}),(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:e=>{e.stopPropagation(),window.location.href="/note/".concat(l)},className:"px-2 py-1 text-xs bg-gradient-to-r from-blue-500 to-purple-600 hover:from-blue-600 hover:to-purple-700 text-white border-0 shadow-md shrink-0",children:[(0,n.jsx)(x.A,{className:"h-3.5 w-3.5 mr-1"}),"Reader Mode"]})]})})()}),(()=>{var e,t,r;if(!t1)return null;let l=ec.find(e=>e.id===t1)||em.find(e=>e.id===t1);if(!l)return null;let s=rM(l),i=s?l.notes:l,{time:a,day:d}=rI(i.created_at);return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xl font-semibold mb-2",children:i.title||"Untitled"}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground mb-4",children:[(0,n.jsx)(g.A,{className:"h-3 w-3"}),(0,n.jsx)("span",{children:d}),(0,n.jsx)("span",{children:"•"}),(0,n.jsx)("span",{children:a}),!i.is_private&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"•"}),(0,n.jsx)(p.A,{className:"h-3 w-3 text-blue-500"}),(0,n.jsx)("span",{className:"text-blue-500",children:"Public"})]})]}),(0,n.jsx)("div",{className:"prose prose-sm max-w-none p-4 rounded-lg border overflow-hidden",style:{backgroundImage:(0,K.Cl)(null!==(r=i.background_color)&&void 0!==r?r:null,eQ)||""},children:(0,n.jsx)("p",{className:"whitespace-pre-wrap leading-relaxed text-base break-words",children:i.content||"No content"})})]}),(0,n.jsxs)("div",{className:"flex justify-between gap-2 pt-4 border-t",children:[(0,n.jsx)("div",{children:s&&(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:async()=>{try{let e=(0,B.UU)(),t=s?l.note_id:l.id;s&&l.is_liked?(await e.from("note_likes").delete().eq("user_id",es.id).eq("note_id",t),eh(e=>e.map(e=>e.id===l.id?{...e,is_liked:!1,likes_count:Math.max(0,(e.likes_count||0)-1)}:e))):(await e.from("note_likes").insert({user_id:es.id,note_id:t}),eh(e=>e.map(e=>e.id===l.id?{...e,is_liked:!0,likes_count:(e.likes_count||0)+1}:e)))}catch(e){console.error("Error toggling like:",e)}},className:"flex items-center gap-2 ".concat(s&&l.is_liked?"text-red-500 border-red-200":"text-muted-foreground"),children:[(0,n.jsx)(v.A,{className:"h-4 w-4 ".concat(s&&l.is_liked?"fill-current":"")}),(0,n.jsx)("span",{children:s&&l.is_liked?"Liked":"Like"}),(0,n.jsxs)("span",{className:"ml-1",children:["(",(s?l.likes_count:i.likes_count)||0,")"]})]})}),(0,n.jsxs)("div",{className:"flex gap-2",children:[!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:()=>{t2(null),ry(i)},className:"transition-all duration-200 hover:scale-105",children:[(0,n.jsx)(w.A,{className:"h-4 w-4 mr-2"}),"Edit Note"]}),(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:()=>{t2(null),rE(i.id)},className:"text-red-600 border-red-200 hover:bg-red-50 hover:text-red-700 hover:border-red-300 transition-all duration-200 hover:scale-105",children:[(0,n.jsx)(_.A,{className:"h-4 w-4 mr-2"}),"Delete Note"]})]}),s&&(null===(t=em.find(e=>e.id===t1))||void 0===t?void 0:null===(e=t.profiles)||void 0===e?void 0:e.id)===(null==es?void 0:es.id)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:()=>{t2(null),ry(i)},children:[(0,n.jsx)(w.A,{className:"h-4 w-4 mr-2"}),"Edit Note"]}),(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:()=>{t2(null),rU(i.id)},className:"text-red-600 border-red-200 hover:bg-red-50 hover:text-red-700 hover:border-red-300 transition-all duration-200 hover:scale-105",children:[(0,n.jsx)(_.A,{className:"h-4 w-4 mr-2"}),"Delete Note"]})]}),(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:()=>t2(null),className:"transition-all duration-200 hover:scale-105",children:"Close"})]})]})]})})()]})}),(0,n.jsx)(H.A,{isOpen:eM.isOpen,onClose:()=>eq({isOpen:!1,noteId:"",noteTitle:""}),noteId:eM.noteId,noteTitle:eM.noteTitle,currentUser:es}),(0,n.jsx)(h.A,{isOpen:tZ,onClose:()=>tQ(!1),title:"Followers",users:tY,isLoading:tX,currentUserId:null==es?void 0:es.id}),(0,n.jsx)(h.A,{isOpen:tW,onClose:()=>tG(!1),title:"Following",users:tH,isLoading:tX,currentUserId:null==es?void 0:es.id})]});if((0,l.useEffect)(()=>{(async()=>
1{if(!eG||0===em.length)return;let e=(0,B.UU)(),t=em.map(e=>e.note_id);try{var r,n;let[l,o]=await Promise.all([t.length?e.from("note_likes").select("note_id").in("note_id",t):Promise.resolve({data:[],error:null}),t.length?e.from("subnotes").select("note_id").in("note_id",t):Promise.resolve({data:[],error:null})]),s=new Map;null==l||null===(r=l.data)||void 0===r||r.forEach(e=>{s.set(e.note_id,(s.get(e.note_id)||0)+1)});let i=new Map;null==o||null===(n=o.data)||void 0===n||n.forEach(e=>{i.set(e.note_id,(i.get(e.note_id)||0)+1)}),eh(e=>e.map(e=>{var t,r,n,l;let o=null!==(r=null!==(t=s.get(e.note_id))&&void 0!==t?t:e.likes_count)&&void 0!==r?r:0,a=null!==(l=null!==(n=i.get(e.note_id))&&void 0!==n?n:e.subnotes_count)&&void 0!==l?l:0;return rn.current.set(e.note_id,{likes:Math.max(0,o),subnotes:Math.max(0,a)}),{...e,likes_count:Math.max(0,o),subnotes_count:Math.max(0,a)}})),rl()}catch(e){console.warn("Failed to enrich visible independent counts",e)}})()},[eG,em.length]),eV){let e=Math.max(120,Math.min(400,24*e5.split("\n").length+60)),t="dark"===eQ?K.uZ:K.qI;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,n.jsx)("header",{className:"border-b border-border bg-card/80 backdrop-blur-md sticky top-0 z-50",children:(0,n.jsx)("div",{className:"max-w-4xl mx-auto flex items-center justify-between px-6 py-4",children:(0,n.jsxs)("div",{className:"flex items-center gap-4",children:[(0,n.jsxs)(o.$,{variant:"ghost",size:"sm",onClick:()=>eH(!1),className:"gap-2 hover:bg-muted/50",children:[(0,n.jsx)(I.A,{className:"h-4 w-4"}),"Back"]}),(0,n.jsx)("div",{className:"h-6 w-px bg-border"}),(0,n.jsx)(J.default,{src:"/images/notionary-logo.png",alt:"Notionary",width:32,height:32,className:"h-8 w-8"}),(0,n.jsx)("h1",{className:"text-lg font-medium text-foreground",children:(null==e0?void 0:e0.id)?"Edit Note":"New Note"})]})})}),(0,n.jsxs)("main",{className:"max-w-2xl mx-auto p-6 space-y-6",children:[tf&&(0,n.jsx)("div",{className:"fixed top-20 left-1/2 transform -translate-x-1/2 z-50 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 text-green-800 dark:text-green-200 px-6 py-4 rounded-lg shadow-lg text-center animate-in slide-in-from-top-2 duration-300",children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-lg",children:"✓"}),(0,n.jsx)("span",{className:"font-medium",children:tg})]})}),tm&&(0,n.jsx)("div",{className:"bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 text-green-800 dark:text-green-200 px-4 py-3 rounded-lg text-center",children:tm}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"text-lg font-semibold text-foreground",children:["Title ",(0,n.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsxs)(o.$,{variant:"outline",size:"sm",onClick:()=>ti(!ts),className:"gap-2 transition-all duration-200 hover:scale-105",children:[(0,n.jsx)(M.A,{className:"h-4 w-4"}),"Choose Color"]})})]}),(0,n.jsx)(i.p,{placeholder:"Enter your note title...",value:e2,maxLength:70,onChange:e=>{let t=e.target.value;t.length<=70&&(e3(t),tl&&to(""))},className:"text-xl font-semibold h-14 transition-all duration-200 focus:ring-2 focus:ring-pink-400 ".concat(tl?"border-red-500 focus-visible:ring-red-500":"")}),(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[tl&&(0,n.jsx)("p",{className:"text-red-500 text-sm",children:tl}),(0,n.jsxs)("p",{className:"text-xs text-muted-foreground ml-auto",children:[e2.length,"/70 characters"]})]}),ts&&(0,n.jsxs)("div",{className:"p-4 bg-card border border-border rounded-lg",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsx)("p",{className:"text-sm font-medium",children:"Choose background color:"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:()=>e9(Math.max(0,e7-1)),disabled:0===e7,className:"h-8 w-8 p-0",children:(0,n.jsx)(q.A,{className:"h-4 w-4"})}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[e7+1," / ",Math.ceil(t.length/6)]}),(0,n.jsx)(o.$,{variant:"outline",size:"sm",onClick:()=>e9(Math.min(Math.ceil(t.length/6)-1,e7+1)),disabled:e7>=Math.ceil(t.length/6)-1,className:"h-8 w-8 p-0",children:(0,n.jsx)(z.A,{className:"h-4 w-4"})})]})]}),(0,n.jsx)("div",{className:"grid grid-cols-6 gap-3",children:t.slice(6*e7,(e7+1)*6).map(e=>(0,n.jsx)("button",{onClick:()=>{let r=t.findIndex(t=>t.value===e.value);tt(-1===r?0:r),e8(e),ti(!1);let n=document.querySelector(".note-background");n&&(n.classList.add("color-changing"),setTimeout(()=>{n.classList.remove("color-changing")},600))},className:"w-12 h-12 rounded-full border-2 transition-all duration-300 hover:scale-125 ".concat(e6.value===e.value?"border-primary shadow-lg ring-2 ring-primary/20 scale-125":"border-border/30 hover:border-border hover:scale-110"),style:{backgroundImage:e.color},title:e.name},e.value))})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-muted/30 rounded-lg",children:[(0,n.jsx)("span",{className:"text-sm font-medium mr-2",children:"Font Style:"}),(0,n.jsx)(o.$,{variant:ta.bold?"default":"outline",size:"sm",onClick:()=>td(e=>({...e,bold:!e.bold})),className:"transition-all duration-200 hover:scale-105",children:(0,n.jsx)(P.A,{className:"h-4 w-4"})}),(0,n.jsx)(o.$,{variant:ta.italic?"default":"outline",size:"sm",onClick:()=>td(e=>({...e,italic:!e.italic})),className:"transition-all duration-200 hover:scale-105",children:(0,n.jsx)(F.A,{className:"h-4 w-4"})}),(0,n.jsx)(o.$,{variant:ta.underline?"default":"outline",size:"sm",onClick:()=>td(e=>({...e,underline:!e.underline})),className:"transition-all duration-200 hover:scale-105",children:(0,n.jsx)(T.A,{className:"h-4 w-4"})})]}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Start writing your thoughts"}),(0,n.jsx)("div",{className:"rounded-xl transition-all duration-500 ease-in-out overflow-hidden",style:{backgroundColor:"transparent",boxShadow:"none",border:"none"},children:(0,n.jsx)("div",{className:"p-0",children:(0,n.jsx)(a.T,{placeholder:"Start writing your thoughts...",value:e5,onChange:e=>e4(e.target.value),style:{height:"".concat(e,"px"),backgroundImage:(0,K.Cl)(e6.color,eQ)||""},className:"border-none ring-0 outline-none shadow-none rounded-xl p-4 resize-none leading-relaxed placeholder:text-muted-foreground
1/60 focus-visible:ring-0 focus:ring-0 transition-all duration-500 ease-in-out text-base ".concat(ta.bold?"font-bold":""," ").concat(ta.italic?"italic":""," ").concat(ta.underline?"underline":"")})})})]}),(0,n.jsxs)("div",{className:"space-y-4 pt-6 border-t border-border",children:[(0,n.jsx)("div",{className:"flex justify-center",children:(0,n.jsx)(o.$,{onClick:rk,size:"lg",className:"px-12 bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 text-white shadow-lg transition-all duration-300 hover:scale-105 transform",children:(null==e0?void 0:e0.id)?"Update Note":"Save Note"})}),tc&&(0,n.jsx)("div",{className:"flex justify-center",children:(0,n.jsx)(o.$,{onClick:tv?rA:rC,variant:"outline",size:"lg",className:"px-8 border-primary text-primary hover:bg-primary hover:text-white transition-all duration-300 bg-transparent hover:scale-105 transform ".concat(tv?"border-orange-500 text-orange-600 hover:bg-orange-500 hover:text-white":""),children:tv?"Make Private":"Grant Independence"})})]})]})]})]}),rq]})}return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{className:"min-h-screen bg-background",children:[(0,n.jsx)("header",{className:"border-b border-border bg-card/50 backdrop-blur-sm sticky top-0 z-50",children:(0,n.jsxs)("div",{className:"grid grid-cols-[auto,1fr,auto] items-center px-4 sm:px-6 py-4 sm:flex sm:items-center sm:justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 sm:gap-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 shrink-0",children:[(0,n.jsx)(J.default,{src:"/images/notionary-logo.png",alt:"Notionary Logo",width:32,height:32,className:"h-7 w-7 sm:h-8 sm:w-8 max-[380px]:h-6 max-[330px]:w-6",priority:!0,placeholder:"blur",blurDataURL:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="}),(0,n.jsx)("h1",{className:"text-lg sm:text-2xl font-bold text-foreground max-[380px]:text-base max-[330px]:text-sm",children:"Notionary"})]}),(0,n.jsxs)("nav",{className:"hidden sm:flex items-center gap-3 ml-4",children:[(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:rd,className:"rounded-md overflow-hidden px-5 py-1.5 font-medium transition-all duration-300 focus-visible:ring-0 ".concat(eG?"border text-foreground/70 hover:text-foreground hover:bg-muted/50":"border-none text-white bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 shadow-md"),children:"My Notes"}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:ra,className:"rounded-md overflow-hidden px-5 py-1.5 font-medium transition-all duration-300 focus-visible:ring-0 ".concat(eG?"border-none text-white bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 shadow-md":"border text-foreground/70 hover:text-foreground hover:bg-muted/50"),children:"Independent Notes"})]})]}),(0,n.jsxs)("nav",{className:"col-start-2 col-end-3 flex items-center justify-center gap-3 min-w-0 sm:hidden max-[380px]:gap-2 max-[330px]:gap-1",children:[(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:rd,className:"rounded-md border px-3 py-1.5 text-xs font-medium max-[380px]:px-2.5 max-[380px]:text-[11px] max-[330px]:px-2 max-[330px]:text-[10px] ".concat(eG?"border-border text-foreground/70":"border-transparent text-white bg-gradient-to-r from-pink-400 to-red-500"),children:"My Notes"}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:ra,className:"rounded-md border px-2.5 py-1.5 text-xs font-medium max-[380px]:px-2 max-[380px]:text-[11px] max-[330px]:px-1.5 max-[330px]:text-[10px] ".concat(eG?"border-transparent text-white bg-gradient-to-r from-pink-400 to-red-500":"border-border text-foreground/70"),children:"Independent"})]}),(0,n.jsx)("div",{className:"col-start-3 col-end-4 justify-self-end flex items-center gap-2 sm:gap-4",children:(0,n.jsxs)(f.rI,{children:[(0,n.jsx)(f.ty,{asChild:!0,children:(0,n.jsx)(o.$,{variant:"ghost",className:"relative h-10 w-10 rounded-full transition-all duration-200 hover:scale-110",children:(0,n.jsxs)(c.eu,{className:"h-10 w-10 select-none pointer-events-none",children:[(0,n.jsx)(c.BK,{src:t4||(0,Y.sQ)(),alt:null==es?void 0:es.email,style:{pointerEvents:"none",userSelect:"none"}}),(0,n.jsx)(c.q5,{className:"bg-primary text-primary-foreground",children:(null==t3?void 0:null===(r=t3.full_name)||void 0===r?void 0:r.charAt(0))||(null==es?void 0:null===(ee=es.user_metadata)||void 0===ee?void 0:null===(Q=ee.full_name)||void 0===Q?void 0:Q.charAt(0))||(null==es?void 0:null===(et=es.email)||void 0===et?void 0:et.charAt(0).toUpperCase())})]})})}),(0,n.jsxs)(f.SQ,{className:"w-56",align:"end",forceMount:!0,sideOffset:5,children:[(0,n.jsx)("div",{className:"flex items-center justify-start gap-2 p-2",children:(0,n.jsxs)("div",{className:"flex flex-col space-y-1 leading-none",children:[(0,n.jsx)("p",{className:"font-medium",children:(null==t3?void 0:t3.full_name)||(null==es?void 0:null===(er=es.user_metadata)||void 0===er?void 0:er.full_name)||"User"}),(0,n.jsxs)("p",{className:"w-[200px] truncate text-sm text-muted-foreground",children:["@",(null==t3?void 0:t3.username)||(null==es?void 0:null===(en=es.user_metadata)||void 0===en?void 0:en.username)||(null==es?void 0:null===(el=es.email)||void 0===el?void 0:el.split("@")[0])||"username"]})]})}),(0,n.jsx)(f.mB,{}),(0,n.jsx)(W(),{href:"/profile",children:(0,n.jsxs)(f._2,{children:[(0,n.jsx)($.A,{className:"mr-2 h-4 w-4"}),(0,n.jsx)("span",{children:"Profile"})]})}),(0,n.jsx)(f.mB,{}),(0,n.jsxs)(f._2,{onClick:()=>rb("light"),children:[(0,n.jsx)(D.A,{className:"mr-2 h-4 w-4"}),(0,n.jsx)("span",{children:"Light Theme"}),"light"===eJ&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsxs)(f._2,{onClick:()=>rb("dark"),children:[(0,n.jsx)(L.A,{className:"mr-2 h-4 w-4"}),(0,n.jsx)("span",{children:"Dark Theme"}),"dark"===eJ&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsx)(f.mB,{}),(0,n.jsx)("form",{action:Z.C,children:(0,n.jsx)(f._2,{asChild:!0,children:(0,n.jsxs)("button",{type:"submit",className:"w-full",children:[(0,n.jsx)(O.A,{className:"mr-2 h-4 w-4"}),(0,n.jsx)("span",{children:"Sign Out"})]})})})]})]})})]})}),tS&&(0,n.jsxs)("div",{className:"fixed top-4 right-4 z-50 bg-green-600 text-white px-4 py-2 rounded-md shadow-md flex items-center gap-2",children:[(0,n.jsx)(R.A,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"text-sm",children:"Note deleted successfully"})]}),(0,n.jsx)("main",{className:"p-4 sm:p-6 w-full min-h-screen",children:eG?(()=>{let e=[...em].sort((e,t)=>
1{switch(t8){case"highest-likes":return(t.likes_count||0)-(e.likes_count||0);case"lowest-likes":return(e.likes_count||0)-(t.likes_count||0);case"oldest":return new Date(e.created_at).getTime()-new Date(t.created_at).getTime();default:return new Date(t.created_at).getTime()-new Date(e.created_at).getTime()}}),t="following"===t8?(Array.isArray(e)?e:[]).filter(e=>{var t;return tO.has(null===(t=e.profiles)||void 0===t?void 0:t.id)}):Array.isArray(e)?e:[];return(0,n.jsxs)("div",{className:"mx-auto w-full max-w-none",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-3xl font-bold mb-2",children:"Independent Notes"}),(0,n.jsx)("p",{className:"text-muted-foreground",children:"Discover bold thoughts from the Notionary community"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(o.$,{variant:"ghost",size:"icon",onClick:()=>{eg(0),ev(!0),e_(!1),ef.current=!1,eh([]),eT(!0),rm(0)},title:"Refresh",children:(0,n.jsx)(y.A,{className:"h-5 w-5"})}),(0,n.jsxs)(f.rI,{children:[(0,n.jsx)(f.ty,{asChild:!0,children:(0,n.jsx)(o.$,{variant:"ghost",size:"icon",children:(0,n.jsx)(k.A,{className:"h-5 w-5"})})}),(0,n.jsxs)(f.SQ,{align:"end",children:[(0,n.jsxs)(f._2,{onClick:()=>t7("highest-likes"),children:[(0,n.jsx)("span",{children:"Highest Likes"}),"highest-likes"===t8&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsxs)(f._2,{onClick:()=>t7("lowest-likes"),children:[(0,n.jsx)("span",{children:"Lowest Likes"}),"lowest-likes"===t8&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsxs)(f._2,{onClick:()=>t7("newest"),children:[(0,n.jsx)("span",{children:"Newly Posted"}),"newest"===t8&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsxs)(f._2,{onClick:()=>t7("oldest"),children:[(0,n.jsx)("span",{children:"Oldest Post"}),"oldest"===t8&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]}),(0,n.jsx)(f.mB,{}),(0,n.jsxs)(f._2,{onClick:()=>t7("following"),children:[(0,n.jsx)("span",{children:"Posts by People You Follow"}),"following"===t8&&(0,n.jsx)("span",{className:"ml-auto",children:"✓"})]})]})]})]})]}),eF||!ef.current?(0,n.jsxs)("div",{className:"text-center py-16",children:[(0,n.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4"}),(0,n.jsx)("p",{className:"text-muted-foreground",children:"Loading independent notes..."})]}):t.length>0?(0,n.jsxs)("div",{className:"w-full grid gap-4 auto-rows-max [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:[(Array.isArray(t)?t:[]).map(e=>{var t,r,l;let{time:s,day:i}=rI(e.created_at),a=e.profiles;return(0,n.jsxs)(d.Zp,{className:"group cursor-pointer note-card card-interactive ".concat(t1===e.id?"h-96 expanded":"h-64"),style:{backgroundImage:(0,K.Cl)(null!==(l=e.notes.background_color)&&void 0!==l?l:null,eQ)||""},onClick:()=>t2(t1===e.id?null:e.id),children:[(0,n.jsxs)(d.aR,{className:"pb-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2 cursor-pointer hover:bg-muted/50 p-1 rounded avatar-hover",onClick:e=>{e.stopPropagation(),(null==a?void 0:a.id)&&rx(a.id)},children:[(0,n.jsx)(u.F,{src:null==a?void 0:a.avatar_url,alt:(null==a?void 0:a.username)||"User",fallback:(null==a?void 0:null===(t=a.username)||void 0===t?void 0:t.charAt(0).toUpperCase())||"U",size:"sm",userId:null==a?void 0:a.id,className:"select-none pointer-events-none"}),(0,n.jsxs)("span",{className:"text-sm font-medium hover:text-primary",children:["@",(null==a?void 0:a.username)||"anonymous"]})]}),(0,n.jsxs)("div",{className:"flex items-start justify-between",children:[(0,n.jsx)("h3",{className:"font-semibold text-sm line-clamp-2 flex-1 mr-2 group-hover:text-primary",children:e.notes.title||"Untitled"}),(0,n.jsx)("div",{className:"flex items-center gap-1 ml-2 shrink-0 z-10 pointer-events-auto absolute top-2 right-2",children:(null==a?void 0:a.id)===(null==es?void 0:es.id)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),ry(e.notes)},className:"h-6 w-6 p-0 hover:scale-105 hover:bg-blue-50",children:(0,n.jsx)(w.A,{className:"h-3 w-3"})}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),rU(e.notes.id)},className:"h-6 w-6 p-0 hover:scale-105 hover:bg-red-50",children:(0,n.jsx)(_.A,{className:"h-3 w-3"})})]})})]})]}),(0,n.jsxs)(d.Wu,{className:"pt-0 flex flex-col justify-between h-full",children:[(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4 flex-1 note-content group-hover:text-foreground break-words overflow-hidden ".concat(t1===e.id?"overflow-y-auto text-expand text-base":"line-clamp-4"),children:e.notes.content||"No content"}),(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:i}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:s}),(null===(r=e.notes)||void 0===r?void 0:r.content)&&e.notes.content.length>200&&(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),t2(t1===e.id?null:e.id)},className:"h-6 w-6 p-0 maximize-button hover:scale-105 hover:bg-gray-50",children:(0,n.jsx)(S.A,{className:"h-3 w-3"})}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),rf(e.note_id)},className:"h-6 w-6 p-0 hover:scale-105 ".concat(e.is_liked?"text-red-500 hover:text-red-600":"text-muted-foreground hover:text-red-500"),children:(0,n.jsx)(v.A,{className:"h-3 w-3 ".concat(e.is_liked?"fill-current":"")})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:Math.max(0,e.likes_count||0)}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),eq({isOpen:!0,noteId:e.notes.id,noteTitle:e.notes.title||"Note"})},className:"h-6 px-1 text-muted-foreground hover:text-foreground",title:"View subnotes",children:(0,n.jsx)(C.A,{className:"h-3 w-3"})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:Math.max(0,e.subnotes_count||0)})]})]})]})]},"".concat(e.id,"-").concat(eQ))}),ep&&(0,n.jsx)("div",{ref:eb,className:"col-span-full flex justify-center py-6",children:ew?(0,n.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}):(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Scroll to load more…"})})]}):(0,n.jsxs)("div",{className:"text-center py-16",children:[(0,n.jsx)(A.A,{className:"h-20 w-20 mx-auto mb-6 text-muted-foreground
1/30"}),(0,n.jsx)("h3",{className:"text-2xl font-semibold mb-2",children:"No independent notes yet"}),(0,n.jsx)("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:"Be the first to share your bold thoughts with the community by granting independence to your notes."})]})]})})():(0,n.jsxs)("div",{className:"mx-auto w-full max-w-none",children:[(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsxs)("div",{className:"md:hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,n.jsx)("h2",{className:"text-xl font-bold",children:"My Notes"}),(0,n.jsxs)(o.$,{onClick:rN,size:"sm",className:"gap-2 bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 text-white hover:scale-105",children:[(0,n.jsx)(E.A,{className:"h-4 w-4"}),"Create New"]})]}),(0,n.jsxs)("div",{className:"flex justify-center gap-3 mb-4",children:[(0,n.jsx)(o.$,{variant:"all"===eL?"default":"outline",size:"sm",className:"flex-1 h-10 rounded-md hover:scale-105",onClick:()=>eO("all"),children:"All Notes"}),(0,n.jsxs)(o.$,{variant:"public"===eL?"default":"outline",size:"sm",className:"flex-1 h-10 rounded-md hover:scale-105",onClick:()=>eO("public"),children:[(0,n.jsx)(p.A,{className:"h-3 w-3 mr-1"}),"Public"]})]})]}),(0,n.jsxs)("div",{className:"hidden md:flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-4",children:[(0,n.jsx)("h2",{className:"text-3xl font-bold",children:"My Notes"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(o.$,{variant:"all"===eL?"default":"outline",size:"sm",onClick:()=>eO("all"),className:"hover:scale-105",children:"All Notes"}),(0,n.jsxs)(o.$,{variant:"public"===eL?"default":"outline",size:"sm",onClick:()=>eO("public"),className:"hover:scale-105",children:[(0,n.jsx)(p.A,{className:"h-3 w-3 mr-1"}),"Public"]})]})]}),(0,n.jsxs)(o.$,{onClick:rN,size:"lg",className:"gap-2 bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 text-white hover:scale-105",children:[(0,n.jsx)(E.A,{className:"h-5 w-5"}),"Create New Note"]})]})]}),rj.length>0?(0,n.jsxs)("div",{className:"w-full grid gap-4 auto-rows-max [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:[rj.map(e=>{var t;let{time:r,day:l}=rI(e.created_at);return(0,n.jsxs)(d.Zp,{className:"group cursor-pointer note-card card-interactive ".concat(t1===e.id?"h-96 expanded":"h-64"),style:{backgroundImage:(0,K.Cl)(null!==(t=e.background_color)&&void 0!==t?t:null,eQ)||""},onClick:()=>t2(t1===e.id?null:e.id),children:[(0,n.jsx)(d.aR,{className:"pb-2 relative",children:(0,n.jsxs)("div",{className:"flex items-start justify-between",children:[(0,n.jsx)("h3",{className:"font-semibold text-sm line-clamp-2 flex-1 mr-2",children:e.title||"Untitled"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 ml-2 shrink-0 z-10 pointer-events-auto absolute top-2 right-2",children:[(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),ry(e)},className:"h-6 w-6 p-0 hover:scale-105 hover:bg-blue-50",children:(0,n.jsx)(w.A,{className:"h-3 w-3"})}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),rE(e.id)},className:"h-6 w-6 p-0 hover:scale-105 hover:bg-red-50",children:(0,n.jsx)(_.A,{className:"h-3 w-3"})})]})]})}),(0,n.jsxs)(d.Wu,{className:"pt-0 flex flex-col justify-between h-full",children:[(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4 flex-1 note-content group-hover:text-foreground break-words overflow-hidden ".concat(t1===e.id?"overflow-y-auto text-expand text-base":"line-clamp-4"),children:e.content||"No content"}),(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:l}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:r}),e.content.length>200&&(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),t2(t1===e.id?null:e.id)},className:"h-6 w-6 p-0 maximize-button hover:scale-105 hover:bg-gray-50",children:(0,n.jsx)(S.A,{className:"h-3 w-3"})}),!e.is_private&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(p.A,{className:"h-3 w-3 text-blue-500"}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),rf(e.id)},className:"h-6 w-6 p-0 hover:scale-105 ".concat(e.is_liked?"text-red-500 hover:text-red-600":"text-muted-foreground hover:text-red-500"),children:(0,n.jsx)(v.A,{className:"h-3 w-3 ".concat(e.is_liked?"fill-current":"")})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:Math.max(0,e.likes_count||0)}),(0,n.jsx)(o.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),eq({isOpen:!0,noteId:e.id,noteTitle:e.title||"Note"})},className:"h-6 px-1 text-muted-foreground hover:text-foreground",title:"View subnotes",children:(0,n.jsx)(C.A,{className:"h-3 w-3"})}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground group-hover:text-foreground",children:Math.max(0,e.subnotes_count||0)})]})]})]})]})]},"".concat(e.id,"-").concat(eQ))}),ey&&(0,n.jsx)("div",{ref:eA,className:"col-span-full flex justify-center py-6",children:eS?(0,n.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}):(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Scroll to load more…"})})]}):(0,n.jsxs)("div",{className:"text-center py-16",children:[(0,n.jsx)(U.A,{className:"h-20 w-20 mx-auto mb-6 text-muted-foreground
1/30"}),(0,n.jsx)("h3",{className:"text-2xl font-semibold mb-2",children:"No notes yet"}),(0,n.jsx)("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:"Start capturing your bold thoughts and ideas. Create your first note to get started on your journey."}),(0,n.jsxs)(o.$,{onClick:rN,size:"lg",className:"gap-2 bg-gradient-to-r from-pink-400 to-red-500 hover:from-pink-500 hover:to-red-600 text-white hover:scale-105",children:[(0,n.jsx)(E.A,{className:"h-5 w-5"}),"Create Your First Note"]})]})]})}),(0,n.jsx)(s.A,{value:eE,onChange:eU,placeholder:eG?"search notes":"search your notes",showFilters:eG,searchResults:ez,onResultClick:e=>{if(eG)if((null==e?void 0:e.resultType)==="user"&&(null==e?void 0:e.username))window.location.href="/profile/".concat(e.username);else{let t=e.note_id||e.id;window.location.href="/note/".concat(t)}else{let t=e.id;window.location.href="/note/".concat(t)}eU(""),eP([])},isSearching:e$,userId:null==es?void 0:es.id,isIndependentNotes:eG,filter:eR,onFilterChange:e=>{console.log("Search filter changed to:",e),eB(e)}}),rq]})})}},7045:(e,t,r)=>{r.d(t,{C:()=>l});var n=r(2734);let l=(0,n.createServerReference)("009fb005d2ff39d9b2cffe7f43dd5f45913587ce34",n.callServer,void 0,n.findSourceMapURL,"signOut")}}]);

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.