1import{u as F,b as _,r as i,s as C,f as u,j as e,B as x,A,C as h,y as B,z as H,e as D,I,a as j,N as p,h as f,F as J}from"./index-DO0ZNUzu.js";import{u as L}from"./useDebounce-i_d-TPaQ.js";import{S as q}from"./search-DfJrq0Pb.js";import{L as z}from"./loader-circle-CZ_geqae.js";import{C as O}from"./calendar-Dodd1r6N.js";import{T as $}from"./trash-2-VtFXnL4x.js";import{f as y}from"./format-Cn6ElKJ8.js";import"./en-US-CXXYYhpC.js";const X=()=>{const{user:l}=F(),g=_(),[o,N]=i.useState([]),[M,v]=i.useState(!0),[t,w]=i.useState(""),[a,b]=i.useState(""),[r,S]=i.useState(""),c=L(t,300);i.useEffect(()=>{l&&k()},[l,c,a,r]);const k=async()=>{if(l)try{v(!0);let s=C.from("journal_entries").select("*").eq("user_id",l.id).order("created_at",{ascending:!1});if(c&&(s=s.or(`content.ilike.%${c}%,prompt.ilike.%${c}%`)),a&&(s=s.gte("created_at",new Date(a).toISOString())),r){const m=new Date(r);m.setHours(23,59,59,999),s=s.lte("created_at",m.toISOString())}const{data:n,error:d}=await s;if(d)throw d;N(n||[])}catch(s){console.error("Error fetching journal entries:",s),u.error("Failed to load journal entries")}finally{v(!1)}},T=async s=>{if(confirm("Are you sure you want to delete this journal entry?"))try{const{error:n}=await C.from("journal_entries").delete().eq("id",s);if(n)throw n;N(d=>d.filter(m=>m.id!==s)),u.success("Journal entry deleted")}catch(n){console.error("Error deleting entry:",n),u.error("Failed to delete entry")}},E=()=>{w(""),b(""),S("")};return l?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs(x,{variant:"ghost",onClick:()=>g("/dashboard"),className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"Back to Dashboard"]})}),e.jsxs("div",{className:"max-w-4xl xl:max-w-5xl mx-auto space-y-6",children:[e.jsxs(h,{children:[e.jsxs(B,{children:[e.jsxs(H,{
1className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-5 w-5"}),"Journal History"]}),e.jsx(I,{children:"Search and browse your journal entries"})]}),e.jsxs(j,{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(p,{placeholder:"Search journal entries...",value:t,onChange:s=>w(s.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"From Date"}),e.jsx(p,{type:"date",value:a,onChange:s=>b(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"To Date"}),e.jsx(p,{type:"date",value:r,onChange:s=>S(s.target.value)})]})]}),(t||a||r)&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Active filters:"}),t&&e.jsxs(f,{variant:"secondary",children:["Search: ",t]}),a&&e.jsxs(f,{variant:"secondary",children:["From: ",y(new Date(a),"MMM d, yyyy")]}),r&&e.jsxs(f,{variant:"secondary",children:["To: ",y(new Date(r),"MMM d, yyyy")]}),e.jsx(x,{variant:"ghost",size:"sm",onClick:E,children:"Clear all"})]})]})]}),M?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(z,{className:"h-8 w-8 animate-spin text-primary"})}):o.length===0?e.jsx(h,{children:e.jsxs(j,{className:"text-center py-12",children:[e.jsx(D,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"No journal entries found"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:t||a||r?"Try adjusting your filters":"Start journaling to see your entries here"}),!t&&!a&&!r&&e.jsx(x,{onClick:()=>g("/dashboard"),children:"Start Journaling"})]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Found ",o.length," ",o.length===1?"entry":"entries"]}),o.map(s=>e.jsx(h,{className:"border-l-4 border-l-primary",children:e.jsx(j,{className:"pt-6",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(O,{className:"h-4 w-4"}),y(new Date(s.created_at),"MMMM d, yyyy ⢠h:mm a")]}),e.jsx(x,{variant:"ghost",size:"sm",onClick:()=>T(s.id),className:"text-destructive hover:text-destructive",children:e.jsx($,{className:"h-4 w-4"})})]}),s.prompt&&e.jsx("div",{className:"p-3 bg-primary/5 rounded-lg border border-primary/20",children:e.jsxs("p",{className:"text-sm font-medium italic text-primary",children:['Prompt: "',s.prompt,'"']})}),e.jsx("div",{className:"prose prose-sm max-w-none",children:e.jsx("p",{className:"whitespace-pre-wrap text-foreground",children:s.content})})]})})},s.id))]})]})]}),e.jsx(J,{})]}):null};export{X as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.