import{c as h,aa as S,r as c,j as e,ab as z,L as g,N as M,ac as C,a9 as D,ad as A,ae as B,af as Z,e as E,ag as L,u as q,b as R,g as k,q as T}from"./index-CgQUayy8.js";/**
 * @license lucide-react v0.460.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const y=h("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]);/**
 * @license lucide-react v0.460.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=h("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/**
 * @license lucide-react v0.460.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const U=h("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
 * @license lucide-react v0.460.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const H=h("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]);/**
 * @license lucide-react v0.460.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const j=h("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),O={sentry:{icon:Z,label:"Health-Wächter",cls:"text-red-300 bg-red-500/10 border-red-500/25"},alarm:{icon:B,label:"Alarm",cls:"text-red-200 bg-red-500/15 border-red-500/40"},notify:{icon:$,label:"Meldung",cls:"text-sky-300 bg-sky-500/10 border-sky-500/25"},"chef-gutachter":{icon:A,label:"Morgenlage",cls:"text-violet-300 bg-violet-500/10 border-violet-500/25"},radar:{icon:H,label:"Radar",cls:"text-teal-300 bg-teal-500/10 border-teal-500/25"},auftragsbuch:{icon:D,label:"Auftragsbuch",cls:"text-primary bg-primary/10 border-primary/25"},zeitmaschine:{icon:j,label:"Zeitmaschine",cls:"text-amber-300 bg-amber-500/10 border-amber-500/25"},reminder:{icon:C,label:"Erinnerung",cls:"text-amber-300 bg-amber-500/10 border-amber-500/25"},traum:{icon:M,label:"Traum",cls:"text-violet-300 bg-violet-500/10 border-violet-500/25"}},P={icon:U,label:"Box",cls:"text-muted-foreground bg-background/40 border-border/50"};function W(r){return new Date(r*1e3).toLocaleDateString("de-DE",{weekday:"long",day:"2-digit",month:"long"})}function _(){const{data:r=[],isLoading:u}=S(),[i,x]=c.useState(!0),b=c.useMemo(()=>{const o=[];for(const n of r){const a=W(n.ts),l=o[o.length-1];l&&l.day===a?l.items.push(n):o.push({day:a,items:[n]})}return o},[r]);return e.jsxs("div",{className:"space-y-7",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"bg-gradient-to-r from-foreground via-foreground to-primary bg-clip-text font-space text-2xl font-bold tracking-tight text-transparent",children:"Chronik"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Was deine Box von allein getan und gemeldet hat — und die Zeitmaschine, falls du zu einem früheren Stand zurück willst."})]}),e.jsx(J,{}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:[e.jsx(z,{className:"h-3.5 w-3.5"})," Verlauf"]}),u&&e.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border border-border/60 bg-card/30 p-6 text-xs text-muted-foreground",children:[e.jsx(g,{className:"h-4 w-4 animate-spin"})," Chronik wird geladen …"]}),!u&&r.length===0&&e.jsx("div",{className:"rounded-2xl border border-dashed border-border/60 bg-card/20 p-8 text-center text-xs text-muted-foreground",children:"Noch keine Einträge. Sobald die Box etwas von allein tut oder meldet (Updates, Wächter, Träume), steht es hier."}),b.map(({day:o,items:n})=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-bold text-foreground/70",children:o}),e.jsxs("div",{className:"space-y-2 border-l-2 border-border/40 pl-4",children:[(i?n.slice(0,8):n).map(a=>{const l=O[a.source]??P,m=l.icon;return e.jsxs("div",{className:"relative rounded-xl border border-border/50 bg-card/40 p-3 backdrop-blur-sm",children:[e.jsx("span",{className:"absolute -left-[23px] top-4 h-2.5 w-2.5 rounded-full bg-border ring-4 ring-background/60"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:E("flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-[10px] font-bold",l.cls),children:[e.jsx(m,{className:"h-3 w-3"})," ",l.label]}),a.subject&&e.jsx("span",{className:"text-[10px] font-semibold text-muted-foreground",children:a.subject}),e.jsx("span",{className:"ml-auto font-mono text-[10px] text-muted-foreground/60",children:new Date(a.ts*1e3).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"})})]}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-xs leading-relaxed text-foreground/85",children:a.text})]},a.id)}),i&&n.length>8&&e.jsxs("button",{onClick:()=>x(!1),className:"text-[11px] text-muted-foreground underline hover:text-foreground",children:[n.length-8," weitere anzeigen"]})]})]},o))]})]})}function J(){const{data:r}=L(),u=q(),{showAlert:i,showConfirm:x,dialogElement:b}=R(),[o,n]=c.useState(null),[a,l]=c.useState(!1),[m,v]=c.useState(!1),d=(r==null?void 0:r.backups)??[],p=m?d:d.slice(0,4);function f(t){const s=t.snapshot.match(/^(\d{4})-?(\d{2})-?(\d{2})[T_-](\d{2})[-:]?(\d{2})/);return s?`${s[3]}.${s[2]}.${s[1]}, ${s[4]}:${s[5]} Uhr`:t.snapshot}async function w(t){n(t.file);try{await k("/api/zeitmaschine/restore",{method:"POST",body:JSON.stringify({file:t.file})}),i("Zeitmaschine läuft","Die Wiederherstellung wurde gestartet. Die Dienste starten gleich neu — die Zentrale ist kurz weg und meldet sich von selbst zurück. Vorher wurde automatisch ein Sicherheits-Backup des jetzigen Zustands gemacht.")}catch(s){i("Start fehlgeschlagen",String((s==null?void 0:s.message)||s))}finally{n(null)}}async function N(){l(!0);try{const t=await k("/api/system/backup",{method:"POST"});t.ok?i("Gesichert",`Snapshot ${t.snapshot} wurde angelegt.`):i("Backup fehlgeschlagen",t.error||"Unbekannter Fehler"),u.invalidateQueries({queryKey:T.zeitmaschine})}catch(t){i("Backup fehlgeschlagen",String((t==null?void 0:t.message)||t))}finally{l(!1)}}return e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:[e.jsx(y,{className:"h-3.5 w-3.5"})," Zeitmaschine — gesicherte Stände"]}),e.jsxs("button",{onClick:N,disabled:a||!(r!=null&&r.available),className:"flex h-8 items-center gap-1.5 rounded-lg border border-border/60 bg-card/45 px-2.5 text-[11px] font-semibold text-muted-foreground hover:text-foreground hover:border-primary/40 transition-all cursor-pointer disabled:opacity-50",children:[a?e.jsx(g,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(y,{className:"h-3.5 w-3.5"})," Jetzt sichern"]})]}),r&&!r.available&&e.jsx("div",{className:"rounded-2xl border border-amber-500/30 bg-amber-500/5 p-4 text-xs text-amber-300",children:"Die Snapshots liegen auf der Box — im lokalen Dev-Modus nicht verfügbar."}),(r==null?void 0:r.available)&&d.length===0&&e.jsx("div",{className:"rounded-2xl border border-dashed border-border/60 bg-card/20 p-5 text-center text-xs text-muted-foreground",children:'Noch keine Snapshots. Das nächtliche Backup (03:30) legt sie automatisch an — oder „Jetzt sichern".'}),p.length>0&&e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:p.map((t,s)=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-border/50 bg-card/40 p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-xs font-semibold text-foreground",children:[f(t)," ",s===0&&e.jsx("span",{className:"ml-1 rounded bg-emerald-500/10 px-1.5 py-0.5 text-[9px] font-bold text-emerald-300",children:"neuester"})]}),e.jsxs("p",{className:"font-mono text-[10px] text-muted-foreground/70 truncate",title:t.file,children:[t.size_mb.toLocaleString("de-DE")," MB · ",t.file]})]}),e.jsxs("button",{disabled:o!==null,onClick:()=>x("Wirklich zu diesem Stand zurück?",`Die Box wird auf den Snapshot vom ${f(t)} zurückgesetzt (Gedächtnis, Hermes-Config, Modell-Router). Der JETZIGE Zustand wird vorher automatisch gesichert — der Schritt ist also umkehrbar. Die Dienste starten neu, die Zentrale ist kurz weg.`,()=>w(t)),className:"flex h-8 shrink-0 items-center gap-1.5 rounded-lg border border-amber-500/40 bg-amber-500/10 px-2.5 text-[10px] font-bold uppercase tracking-wide text-amber-300 transition-all hover:bg-amber-500/20 cursor-pointer disabled:opacity-50",children:[o===t.file?e.jsx(g,{className:"h-3 w-3 animate-spin"}):e.jsx(j,{className:"h-3 w-3"})," Zurück"]})]},t.file))}),d.length>4&&!m&&e.jsxs("button",{onClick:()=>v(!0),className:"text-[11px] text-muted-foreground underline hover:text-foreground",children:["Alle ",d.length," Snapshots anzeigen"]}),b]})}export{_ as ChronikView};
