1import{r as p,b as v,ch as G,e as M,j as e,c3 as Z,c4 as U,z as W,ci as X,c6 as Y,bo as F,ao as ee,l as R,cj as q,ck as te,cl as se,cm as re,a3 as C,ae as _,cn as ae,co as ne,cp as ie,cq as de,cr as oe,cs as le,ct as ce,cu as ue,cv as me,cw as xe,cx as he,cy as ge,cz as pe,cA as be,cB as fe,cC as je}from"./index-B4mWWRqi.js";import{u as ye}from"./polling-config-BilNHsrp.js";import{b as B,a as T,c as D,d as ve,f as Ne,C as ke}from"./calendar-CFbf3IdQ.js";import{u as J}from"./use-booking-seen-BU5LjSnx.js";const $={lessThanXSeconds:{standalone:{one:"weniger als 1 Sekunde",other:"weniger als {{count}} Sekunden"},withPreposition:{one:"weniger als 1 Sekunde",other:"weniger als {{count}} Sekunden"}},xSeconds:{standalone:{one:"1 Sekunde",other:"{{count}} Sekunden"},withPreposition:{one:"1 Sekunde",other:"{{count}} Sekunden"}},halfAMinute:{standalone:"eine halbe Minute",withPreposition:"einer halben Minute"},lessThanXMinutes:{standalone:{one:"weniger als 1 Minute",other:"weniger als {{count}} Minuten"},withPreposition:{one:"weniger als 1 Minute",other:"weniger als {{count}} Minuten"}},xMinutes:{standalone:{one:"1 Minute",other:"{{count}} Minuten"},withPreposition:{one:"1 Minute",other:"{{count}} Minuten"}},aboutXHours:{standalone:{one:"etwa 1 Stunde",other:"etwa {{count}} Stunden"},withPreposition:{one:"etwa 1 Stunde",other:"etwa {{count}} Stunden"}},xHours:{standalone:{one:"1 Stunde",other:"{{count}} Stunden"},withPreposition:{one:"1 Stunde",other:"{{count}} Stunden"}},xDays:{standalone:{one:"1 Tag",other:"{{count}} Tage"},withPreposition:{one:"1 Tag",other:"{{count}} Tagen"}},aboutXWeeks:{standalone:{one:"etwa 1 Woche",other:"etwa {{count}} Wochen"},withPreposition:{one:"etwa 1 Woche",other:"etwa {{count}} Wochen"}},xWeeks:{standalone:{one:"1 Woche",other:"{{count}} Wochen"},withPreposition:{one:"1 Woche",other:"{{count}} Wochen"}},aboutXMonths:{standalone:{one:"etwa 1 Monat",other:"etwa {{count}} Monate"},withPreposition:{one:"etwa 1 Monat",other:"etwa {{count}} Monaten"}},xMonths:{standalone:{one:"1 Monat",other:"{{count}} Monate"},withPreposition:{one:"1 Monat",other:"{{count}} Monaten"}},aboutXYears:{standalone:{one:"etwa 1 Jahr",other:"etwa {{count}} Jahre"},withPreposition:{one:"etwa 1 Jahr",other:"etwa {{count}} Jahren"}},xYears:{standalone:{one:"1 Jahr",other:"{{count}} Jahre"},withPreposition:{one:"1 Jahr",other:"{{count}} Jahren"}},overXYears:{standalone:{one:"mehr als 1 Jahr",other:"mehr als {{count}} Jahre"},withPreposition:{one:"mehr als 1 Jahr",other:"mehr als {{count}} Jahren"}},almostXYears:{standalone:{one:"fast 1 Jahr",other:"fast {{count}} Jahre"},withPreposition:{one:"fast 1 Jahr",other:"fast {{count}} Jahren"}}},we=(t,l,c)=>{let a;const n=c?.addSuffix?$[t].withPreposition:$[t].standalone;return typeof n=="string"?a=n:l===1?a=n.one:a=n.other.replace("{{count}}",String(l)),c?.addSuffix?c.comparison&&c.comparison>0?"in "+a:"vor "+a:a},_e={full:"EEEE, do MMMM y",long:"do MMMM y",medium:"do MMM y",short:"dd.MM.y"},Me={full:"HH:mm:ss zzzz",long:"HH:mm:ss z",medium:"HH:mm:ss",short:"HH:mm"},Se={full:"{{date}} 'um' {{time}}",long:"{{date}} 'um' {{time}}",medium:"{{date}} {{time}}",short:"{{date}} {{time}}"},Ce={date:B({formats:_e,defaultWidth:"full"}),time:B({formats:Me,defaultWidth:"full"}),dateTime:B({formats:Se,defaultWidth:"full"})},Pe={lastWeek:"'letzten' eeee 'um' p",yesterday:"'gestern um' p",today:"'heute um' p",tomorrow:"'morgen um' p",nextWeek:"eeee 'um' p",other:"P"},Te=(t,l,c,a)=>Pe[t],De={narrow:["v.Chr.","n.Chr."],abbreviated:["v.Chr.","n.Chr."],wide:["vor Christus","nach Christus"]},Ee={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1. Quartal","2. Quartal","3. Quartal","4. Quartal"]},z={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],wide:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]},Fe={narrow:z.narrow,abbreviated:["Jan.","Feb.","März","Apr.","Mai","Juni","Juli","Aug.","Sep.","Okt.","Nov.","Dez."],wide:z.wide},Be={narrow:["S","M","D","M","D","F","S"],short:["So","Mo","Di","Mi","Do","Fr","Sa"],abbreviated:["So.","Mo.","Di.","Mi.","Do.","Fr.","Sa."],wide:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"]},Le={narrow:{am:"vm.",pm:"nm.",midnight:"Mitternacht",noon:"Mittag",morning:"Morgen",afternoon:"Nac
1hm.",evening:"Abend",night:"Nacht"},abbreviated:{am:"vorm.",pm:"nachm.",midnight:"Mitternacht",noon:"Mittag",morning:"Morgen",afternoon:"Nachmittag",evening:"Abend",night:"Nacht"},wide:{am:"vormittags",pm:"nachmittags",midnight:"Mitternacht",noon:"Mittag",morning:"Morgen",afternoon:"Nachmittag",evening:"Abend",night:"Nacht"}},ze={narrow:{am:"vm.",pm:"nm.",midnight:"Mitternacht",noon:"Mittag",morning:"morgens",afternoon:"nachm.",evening:"abends",night:"nachts"},abbreviated:{am:"vorm.",pm:"nachm.",midnight:"Mitternacht",noon:"Mittag",morning:"morgens",afternoon:"nachmittags",evening:"abends",night:"nachts"},wide:{am:"vormittags",pm:"nachmittags",midnight:"Mitternacht",noon:"Mittag",morning:"morgens",afternoon:"nachmittags",evening:"abends",night:"nachts"}},qe=t=>Number(t)+".",Ae={ordinalNumber:qe,era:T({values:De,defaultWidth:"wide"}),quarter:T({values:Ee,defaultWidth:"wide",argumentCallback:t=>t-1}),month:T({values:z,formattingValues:Fe,defaultWidth:"wide"}),day:T({values:Be,defaultWidth:"wide"}),dayPeriod:T({values:Le,defaultWidth:"wide",formattingValues:ze,defaultFormattingWidth:"wide"})},Ke=/^(\d+)(\.)?/i,Oe=/\d+/i,We={narrow:/^(v\.? ?Chr\.?|n\.? ?Chr\.?)/i,abbreviated:/^(v\.? ?Chr\.?|n\.? ?Chr\.?)/i,wide:/^(vor Christus|vor unserer Zeitrechnung|nach Christus|unserer Zeitrechnung)/i},$e={any:[/^v/i,/^n/i]},Ve={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](\.)? Quartal/i},Qe={any:[/1/i,/2/i,/3/i,/4/i]},Ie={narrow:/^[jfmasond]/i,abbreviated:/^(j[aä]n|feb|mär[z]?|apr|mai|jun[i]?|jul[i]?|aug|sep|okt|nov|dez)\.?/i,wide:/^(januar|februar|märz|april|mai|juni|juli|august|september|oktober|november|dezember)/i},Re={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^j[aä]/i,/^f/i,/^mär/i,/^ap/i,/^mai/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Je={narrow:/^[smdmf]/i,short:/^(so|mo|di|mi|do|fr|sa)/i,abbreviated:/^(son?|mon?|die?|mit?|don?|fre?|sam?)\.?/i,wide:/^(sonntag|montag|dienstag|mittwoch|donnerstag|freitag|samstag)/i},He={any:[/^so/i,/^mo/i,/^di/i,/^mi/i,/^do/i,/^f/i,/^sa/i]},Ge={narrow:/^(vm\.?|nm\.?|Mitternacht|Mittag|morgens|nachm\.?|abends|nachts)/i,abbreviated:/^(vorm\.?|nachm\.?|Mitternacht|Mittag|morgens|nachm\.?|abends|nachts)/i,wide:/^(vormittags|nachmittags|Mitternacht|Mittag|morgens|nachmittags|abends|nachts)/i},Ze={any:{am:/^v/i,pm:/^n/i,midnight:/^Mitte/i,noon:/^Mitta/i,morning:/morgens/i,afternoon:/nachmittags/i,evening:/abends/i,night:/nachts/i}},Ue={ordinalNumber:ve({matchPattern:Ke,parsePattern:Oe,valueCallback:t=>parseInt(t)}),era:D({matchPatterns:We,defaultMatchWidth:"wide",parsePatterns:$e,defaultParseWidth:"any"}),quarter:D({matchPatterns:Ve,defaultMatchWidth:"wide",parsePatterns:Qe,defaultParseWidth:"any",valueCallback:t=>t+1}),month:D({matchPatterns:Ie,defaultMatchWidth:"wide",parsePatterns:Re,defaultParseWidth:"any"}),day:D({matchPatterns:Je,defaultMatchWidth:"wide",parsePatterns:He,defaultParseWidth:"any"}),dayPeriod:D({matchPatterns:Ge,defaultMatchWidth:"wide",parsePatterns:Ze,defaultParseWidth:"any"})},Xe={code:"de",formatDistance:we,formatLong:Ce,formatRelative:Te,localize:Ae,match:Ue,options:{weekStartsOn:1,firstWeekContainsDate:4}},Ye={busy:"Belegt",tentative:"Vorläufig",oof:"Abwesend",workingElsewhere:"Anderswo",pending:"Ausstehend",unknown:"Unbekannt"};function et(t){const l=t.getFullYear(),c=String(t.getMonth()+1).padStart(2,"0"),a=String(t.getDate()).padStart(2,"0");return`${l}-${c}-${a}`}function tt({staffId:t}){const[l,c]=p.useState(new Date),a=v(G),n=et(l),d=M({queryKey:["booking","staff-day",t,n],queryFn:()=>a({data:{staffId:t,date:n}}),staleTime:3e4}),r=d.data?.meta?.timezone??"Europe/Berlin",o=p.useMemo(()=>new Intl.DateTimeFormat("de-DE",{hour:"2-digit",minute:"2-digit",timeZone:r}),[r]);return e.jsxs("div",{className:"mt-3 rounded-lg border border-border bg-background/50 p-3 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Z,{children:[e.jsx(U,{asChild:!0,children:e.jsxs(W,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(X,{className:"h-4 w-4"}),Ne(l,"EEEE, dd.MM.yyyy",{locale:Xe})]})}),e.jsx(Y,{className:"w-auto p-0",align:"start",children:e.jsx(ke,{mode:"single",selected:l,onSelect:i=>i&&c(i),initialFocus:!0,className:F("p-3 pointer-events-auto")})})]}),e.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>d.refetch(),disabled:d.isFetching,className:"gap-2",children:[e.jsx(ee,{className:F("h-4 w-4",d.isFetching&&"animate-spin")}),"Aktualisieren"]}),d.data?.meta&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Arbeitszeit ",d.data.meta.workWindowStart.slice(0,5),"â",d.data.meta.workWindowEnd.slice(0,5)," · ",d.data.meta.timezone," · Slot"," ",d.data.meta.slotMinutes," min"]})]}),d.isLoading&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Lade Kalenderâ¦"}),d.data&&!d.data.ok&&e.jsxs("p",{className:"text-sm text-destructive",children:["Graph-Fehler: ",d.data.error]}),d.data?.meta&&d.data.meta.isEnabled===!1&&e.jsx("p",{className:"text-xs text-amber-600 dar
1k:text-amber-400",children:"Hinweis: Mitarbeiter ist nicht freigeschaltet â Ansicht nur zur Kontrolle."}),d.data?.ok&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-1.5",children:[d.data.slots.map(i=>{const g=i.reason==="free"?"bg-emerald-500/15 border-emerald-500/40 text-emerald-700 dark:text-emerald-300":i.reason==="overlap"?"bg-destructive/15 border-destructive/40 text-destructive":"bg-muted border-border text-muted-foreground",j=i.reason==="free"?"Frei":i.reason==="overlap"?"Belegt":"Vorlaufzeit";return e.jsxs("div",{className:F("rounded-md border px-2 py-1.5 text-xs flex items-center justify-between gap-2",g),title:`${o.format(new Date(i.start))}â${o.format(new Date(i.end))} · ${j}`,children:[e.jsx("span",{className:"font-medium tabular-nums",children:o.format(new Date(i.start))}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide",children:j})]},i.start)}),d.data.slots.length===0&&e.jsx("p",{className:"col-span-full text-xs text-muted-foreground",children:"Keine Slots im Arbeitszeitfenster."})]}),d.data.busy.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-xs font-semibold text-muted-foreground",children:"Outlook-Blöcke"}),e.jsx("ul",{className:"text-xs space-y-0.5",children:d.data.busy.map((i,g)=>e.jsxs("li",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"tabular-nums",children:[o.format(new Date(i.start)),"â",o.format(new Date(i.end))]}),e.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide",children:Ye[i.status]??i.status})]},`${i.start}-${g}`))})]})]})]})}function jt(){const[t,l]=p.useState("log"),c=v(R),a=M({queryKey:["booking","requests","badge"],queryFn:()=>c({data:{limit:100}}),refetchInterval:6e4}),{seenSet:n}=J(),d=(Array.isArray(a.data)?a.data:[]).filter(r=>r.status==="confirmed"&&r.created_at&&!n.has(r.id)).length;return e.jsxs("div",{className:"w-full max-w-none space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Terminbuchung"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Microsoft-Bookings-Integration für âJetzt Demo vereinbaren".'})]}),e.jsx("div",{className:"flex gap-2 border-b border-border",children:[["connection","Verbindung & Service"],["staff","Mitarbeiter"],["window","Buchungsfenster"],["mails","E-Mail-Texte"],["log","Buchungen"],["diagnostics","Diagnose & Logs"]].map(([r,o])=>e.jsx("button",{onClick:()=>l(r),className:`px-3 py-2 text-sm border-b-2 -mb-px ${t===r?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[o,r==="log"&&d>0&&e.jsx("span",{className:"inline-flex min-w-[1.25rem] items-center justify-center rounded-full bg-emerald-500 px-1.5 text-[10px] font-semibold text-white shadow-[0_0_0_3px_rgba(16,185,129,0.15)] animate-pulse",title:`${d} neue Buchung${d===1?"":"en"}`,children:d})]})},r))}),t==="connection"&&e.jsx(st,{}),t==="staff"&&e.jsx(at,{}),t==="window"&&e.jsx(nt,{}),t==="mails"&&e.jsx(it,{}),t==="log"&&e.jsx(ct,{}),t==="diagnostics"&&e.jsx(xt,{})]})}function A(){const t=v(xe);return M({queryKey:["booking","settings"],queryFn:()=>t()})}function K({onSave:t,pending:l,success:c,error:a}){return e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("button",{onClick:t,disabled:l,className:"rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium disabled:opacity-50",children:l?"Speichernâ¦":"Speichern"}),c&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Gespeichert."}),a&&e.jsx("span",{className:"text-xs text-destructive",children:a})]})}function st(){const t=A(),l=v(q),c=v(te),a=v(se),n=v(re),d=C(),[r,o]=p.useState(null);p.useEffect(()=>{t.data&&!r&&o(t.data)},[t.data,r]);const i=M({queryKey:["booking","biz"],queryFn:()=>c(),retry:!1}),g=M({queryKey:["booking","services",r?.business_id],queryFn:()=>a({data:{businessId:r.business_id}}),enabled:!!r?.business_id,retry:!1}),j=_({mutationFn:()=>l({data:O(r)}),onSuccess:()=>{d.invalidateQueries({queryKey:["booking","settings"]}),d.invalidateQueries({queryKey:["admin","graph-permissions-diagnostics"]})}}),u=_({mutationFn:()=>n(),onSuccess:()=>{d.invalidateQueries({queryKey:["booking","staff","list"]}),d.invalidateQueries({queryKey:["admin","graph-permissions-diagnostics"]})}});if(t.isError)return e.jsxs("div",{className:"rounded-md border border-destructive bg-destructive/10 p-3 text-sm",children:["Booking-Einstellungen konnten nicht geladen werden.",e.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:t.error.message})]});if(!r)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"});const s="setup_error"in r?String(r.setup_error):null,N=i.data?.items??[],x=i.data?.error??null,k=g.data?.items??[],h=g.data?.error??null,f="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm";return e.jsxs("section",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Microsoft-Bookings-Verbindung"}),s&&e.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-3 text-sm",children:s}),(i.isError||x)&&e.jsxs("div",{className:"rounded-md border border-destructive bg-destructive/10 p-3 text-sm",children:["Verbindung zu Microsoft Graph fehlgeschlagen. Bitte Secrets (MS_GRAPH_TENANT_ID / CLIENT_ID / CLIENT_SECRET) und API-Berechtigung",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"Bookings.Read.All"}),"/",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"Bookings.ReadWrite.All"}),"mit Admin-Consent prüfen.",e.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:x??i.error.message})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Booking-Page"}),e.jsxs("select",{value:r.business_id??"",onChange:b=>{const m=b.target.value||null,w=N.find(P=>P.id===m);o({...r,business_id:m,business_display_name:w?.displayName??null,service_id:null,
1service_display_name:null})},className:f,disabled:i.isLoading||i.isError||!!x,children:[e.jsx("option",{value:"",children:"â bitte wählen â"}),N.map(b=>e.jsx("option",{value:b.id,children:b.displayName},b.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Service / Termintyp"}),e.jsxs("select",{value:r.service_id??"",onChange:b=>{const m=b.target.value||null,w=k.find(P=>P.id===m);o({...r,service_id:m,service_display_name:w?.displayName??null,slot_minutes:w?.defaultDurationMinutes&&[15,30,45,60].includes(w.defaultDurationMinutes)?w.defaultDurationMinutes:r.slot_minutes})},className:f,disabled:!r.business_id||g.isLoading,children:[e.jsx("option",{value:"",children:"â bitte wählen â"}),k.map(b=>e.jsxs("option",{value:b.id,children:[b.displayName," (",b.defaultDurationMinutes," Min)"]},b.id))]}),h&&e.jsx("p",{className:"mt-2 text-xs text-destructive",children:h})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:r.is_active,onChange:b=>o({...r,is_active:b.target.checked})}),"Online-Terminbuchung aktiv (für Besucher sichtbar)"]}),e.jsx(K,{onSave:()=>j.mutate(),pending:j.isPending,success:j.isSuccess,error:j.error instanceof Error?j.error.message:null})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Mitarbeiter synchronisieren"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Lädt alle in der gewählten Booking-Page hinterlegten Mitarbeiter und legt sie als deaktivierte Einträge an. Im Tab âMitarbeiter" lassen sie sich freischalten.'}),e.jsx("button",{onClick:()=>u.mutate(),disabled:!r.business_id||u.isPending,className:"rounded-md border border-border px-4 py-2 text-sm hover:bg-background disabled:opacity-50",children:u.isPending?"Synchronisiereâ¦":"Jetzt synchronisieren"}),u.isSuccess&&u.data&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u.data.added," neu · ",u.data.updated," aktualisiert."]}),u.error&&e.jsx("p",{className:"text-xs text-destructive",children:u.error.message})]})]})}function rt({onCreate:t}){const[l,c]=p.useState(!1),[a,n]=p.useState(""),[d,r]=p.useState(""),[o,i]=p.useState(""),[g,j]=p.useState(""),[u,s]=p.useState(!0),[N,x]=p.useState(!1),[k,h]=p.useState(null),f=()=>{n(""),r(""),i(""),j(""),s(!0),h(null)},b=async()=>{x(!0),h(null);try{await t({display_name:a.trim(),graph_email:d.trim().toLowerCase(),role:o.trim()?o.trim():null,photo_url:g.trim()?g.trim():null,is_enabled:u}),f(),c(!1)}catch(m){h(m instanceof Error?m.message:String(m))}finally{x(!1)}};return e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Mitarbeiter hinzufügen"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Für die öffentliche Terminbuchungsseite. Termine landen direkt im Outlook-Kalender des Mitarbeiters â ein Eintrag in MS Bookings ist nicht nötig."})]}),e.jsx("button",{type:"button",onClick:()=>c(m=>!m),className:"rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:opacity-90",children:l?"SchlieÃen":"+ Neuer Mitarbeiter"})]}),e.jsxs("details",{className:"text-xs",open:l,children:[e.jsx("summary",{className:"cursor-pointer select-none text-muted-foreground hover:text-foreground",children:"Voraussetzungen & Schritt-für-Schritt-Anleitung"}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1.5 pl-5 text-muted-foreground",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Postfach in Entra/Microsoft 365 vorhanden."})," Die Person braucht eine lizenzierte Mailbox (z. B.",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"[email protected]"}),") im selben Tenant wie die App-Registrierung."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Graph-Berechtigung deckt das Postfach ab."})," Die Anwendungsrechte",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"Calendars.ReadWrite"}),"und",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"OnlineMeetings.ReadWrite.All"}),'müssen für dieses Postfach greifen (ggf. via Application-Access-Policy). Prüfe das im Tab âVerbindung & Service" â Diagnose.']}),e.jsxs("li",{children:[e.jsx("strong",{children:"Unten die Felder ausfüllen"})," â Anzeigename, Rolle, Postfach-E-Mail und optional Foto-URL â und speichern."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Freischalten"})," aktivieren, damit der Mitarbeiter auf der öffentlichen Buchungsseite (",e.jsx("code",{className:"mx-1 rounded bg-muted px-1",children:"/buchen"}),") sicht- und wählbar ist."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Testbuchung"})," auf ",e.jsx("code",{children:"/buchen"})," ausführen;
1 der Termin sollte im Outlook-Kalender des Mitarbeiters mit Teams-Link erscheinen. Im Fehlerfall Diagnose-Tab prüfen."]})]})]}),l&&e.jsxs("div",{className:"space-y-3 border-t border-border pt-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"space-y-1 text-xs",children:[e.jsx("span",{className:"font-medium",children:"Anzeigename *"}),e.jsx("input",{value:a,onChange:m=>n(m.target.value),placeholder:"Max Mustermann",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm"})]}),e.jsxs("label",{className:"space-y-1 text-xs",children:[e.jsx("span",{className:"font-medium",children:"Postfach-E-Mail (Entra) *"}),e.jsx("input",{value:d,onChange:m=>r(m.target.value),placeholder:"[email protected]",type:"email",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm"})]}),e.jsxs("label",{className:"space-y-1 text-xs",children:[e.jsx("span",{className:"font-medium",children:"Rolle / Position"}),e.jsx("input",{value:o,onChange:m=>i(m.target.value),placeholder:"Sales, Consulting, â¦",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm"})]}),e.jsxs("label",{className:"space-y-1 text-xs",children:[e.jsx("span",{className:"font-medium",children:"Foto-URL (optional)"}),e.jsx("input",{value:g,onChange:m=>j(m.target.value),placeholder:"https://â¦",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:m=>s(m.target.checked)}),"Sofort für die Buchungsseite freischalten"]}),k&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:k}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{f(),c(!1)},className:"rounded-md border border-border px-3 py-1.5 text-sm hover:bg-muted",children:"Abbrechen"}),e.jsx("button",{type:"button",disabled:N||!a.trim()||!d.trim(),onClick:b,className:"rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50",children:N?"Speichereâ¦":"Mitarbeiter anlegen"})]})]})]})}function at(){const t=v(ae),l=v(ne),c=v(ie),a=v(de),n=C(),[d,r]=p.useState(new Set),o=u=>r(s=>{const N=new Set(s);return N.has(u)?N.delete(u):N.add(u),N}),i=M({queryKey:["booking","staff","list"],queryFn:()=>t()}),g=_({mutationFn:u=>l({data:u}),onSuccess:()=>{n.invalidateQueries({queryKey:["booking","staff","list"]}),n.invalidateQueries({queryKey:["admin","graph-permissions-diagnostics"]})}}),j=_({mutationFn:u=>c({data:{id:u}}),onSuccess:()=>n.invalidateQueries({queryKey:["booking","staff","list"]})});return i.isLoading?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"}):e.jsxs("section",{className:"space-y-3",children:[e.jsx(rt,{onCreate:async u=>{await a({data:u}),n.invalidateQueries({queryKey:["booking","staff","list"]}),n.invalidateQueries({queryKey:["admin","graph-permissions-diagnostics"]})}}),(i.data??[]).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:'Noch keine Mitarbeiter synchronisiert. Wechsel zu âVerbindung & Service" und klicke âJetzt synchronisieren".'}),e.jsx("div",{className:"space-y-2",children:(i.data??[]).map(u=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[1fr_1fr_120px_auto] gap-3 items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{defaultValue:u.display_name,onBlur:s=>s.target.value!==u.display_name&&g.mutate({id:u.id,display_name:s.target.value}),className:"w-full rounded-md border border-border bg-background px-2 py-1 text-sm font-medium"}),e.jsx("input",{defaultValue:u.role??"",placeholder:"Rolle / Position",onBlur:s=>(s.target.value||null)!==u.role&&g.mutate({id:u.id,role:s.target.value||null}),className:"w-full rounded-md border border-border bg-background px-2 py-1 text-xs text-muted-foreground"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:u.graph_email??"â"})]}),e.jsx("input",{defaultValue:u.photo_url??"",placeholder:"Foto-URL (https://â¦)",onBlur:s=>(s.target.value||null)!==u.photo_url&&g.mutate({id:u.id,photo_url:s.target.value||null}),className:"w-full rounded-md border border-border bg-background px-2 py-1 text-xs"}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:u.is_enabled,onChange:s=>g.mutate({id:u.id,is_enabled:s.target.checked})}),"Freischalten"]}),e.jsxs("div",{className:"flex justify-end",children:[e.jsx("button",{onClick:()=>o(u.id),className:"text-xs text-primary hover:underline mr-3",children:d.has(u.id)?"Kalender ausblenden":"Kalender"}),e.jsx("button",{onClick:()=>{confirm(`â${u.display_name}" wirklich löschen?`)&&j.mutate(u.id)},className:"text-xs text-destructive hover:underline",children:"Löschen"})]})]}),d.has(u.id)&&e.jsx(tt,{staffId:u.id})]},u.id))})]})}function nt(){const t=A(),l=v(q),c=C(),[a,n]=p.useState(null);p.useEffect(()=>{t.data&&!a&&n(t.data)},[t.data,a]);const d=_({mutationFn:()=>l({data:O(a)}),onSuccess:()=>c.invalidateQueries({queryKey:["booking","settings"]})});if(!a)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"});const r="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm";return e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Buchungsfenster"}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Slot-Dauer (Minuten)"}),e.jsxs("select",{value:a.slot_minutes,onChange:o=>n({...a,slot_minutes:Number(o.target.value)}),className:r,children:[e.jsx("option",{value:15,children:"15"}),e.jsx("option",{value:30,children:"30"}),e.jsx("option",{value:45,children:"45"}),e.jsx("option",{value:60,children:"60"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Zeitzone"}),e.jsx("input",{value:a.timezone,onChange:o=>n({...a,timezone:o.target.value}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Vorlaufzeit (Minuten)"}),e.jsx("input",{type:"number",value:a.lead_time_minutes,onChange:o=>n({...a,lead_time_minutes:Number(o.target.value)}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Buchungshorizont (Tage)"}),e.jsx("input",{type:"number",value:a.booking_horizon_days,onChange:o=>n({...a,booking_horizon_days:Number(o.target.value)}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Puffer vorher (Min)"}),e.jsx("input",{type:"number",value:a.buffer_before_minutes,onChange:o=>n({...a,buffer_before_minutes:Number(o.target.value)}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Puffer danach (Min)"}),e.jsx("input",{type:"number",value:a.buffer_after_minutes,onChange:o=>n({...a,buffer_after_minutes:Number(o.target.value)}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Arbeitsbeginn (HH:MM)"}),e.jsx("input",{type:"time",value:a.work_window_start.slice(0,5),onChange:o=>n({...a,work_window_start:o.target.value}),className:r})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Arbeitsende (HH:MM)"}),e.jsx("input",{type:"time",value:a.work_window_end.slice(0,5),onChange:o=>n({...a,work_window_end:o.target.value}),className:r})]})]}),e.jsx(K,{onSave:()=>d.mutate(),pending:d.isPending,success:d.isSuccess,error:d.error instanceof Error?d.error.message:null})]})}function it(){const t=A(),l=v(q),c=C(),[a,n]=p.useState(null);p.useEffect(()=>{t.data&&!a&&n(t.data)},[t.data,a]);const d=_({mutationFn:()=>l({data:O(a)}),onSuccess:()=>c.invalidateQueries({queryKey:["booking","settings"]})});if(!a)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"});const r="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm";return e.jsxs("section",{className:"space-y-6",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Platzhalter: ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{name}}"}),","," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{start_local}}"}),","," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{end_local}}"}),","," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{staff}}"}),","," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{topic}}"}),","," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{join_url}}"})," ",e.jsx("span",{className:"opacity-70",children:"(Teams-Meeting-Link, leer falls nicht verfügbar)"}),"."," ","Optional konditional einsetzbar als"," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{#if join_url}}â¦{{/if}}"}),"."]}),e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Bestätigungs-Mail"}),e.jsx("input",{value:a.confirmation_subject,onChange:o=>n({...a,confirmation_subject:o.target.value}),className:r}),e.jsx("textarea",{rows:8,value:a.confirmation_html,onChange:o=>n({...a,confirmation_html:o.target.value}),className:`${r} font-mono`})]}),e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Erinnerungs-Mail (24h vorher)"}),e.jsx("input",{value:a.reminder_subject,onChange:o=>n({...a,reminder_subject:o.target.value}),className:r}),e.jsx("textarea",{rows:6,value:a.reminder_html,onChange:o=>n({...a,reminder_html:o.target.value}),className:`${r} font-mono`})]}),e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Widget-Texte"}),e.jsxs("label",{className:"text-sm",children:["Erfolgsmeldung",e.jsx("textarea",{rows:2,value:a.success_text,onChange:o=>n({...a,success_text:o.target.value}),className:r})]}),e.jsxs("label",{className:"text-sm",children:["Fehlermeldung",e.jsx("textarea",{rows:2,value:a.error_text,onChange:o=>n({...a,error_text:o.target.value}),className:r})]})]}),e.jsx(lt,{inputCls:r}),e.jsx(K,{onSave:()=>d.mutate(),pending:d.isPending,success:d.isSuccess,error:d.error instanceof Error?d.error.message:null})]})}const dt=[{code:"de",label:"Deutsch"},{code:"en",label:"English"},{code:"fr",label:"Français"},{code:"tr",label:"Türkçe"},{code:"it",label:"Italiano"}],ot=[{code:"reschedule_customer",label:"Terminänderung â Kunde"},{code:"reschedule_staff",label:"Terminänderung â Mitarbeitende"}];function lt({inputCls:t}){const l=v(he),c=v(ge),a=v(pe),n=v(be),[d,r]=p.useState(""),o=C(),[i,g]=p.useState("de"),[j,u]=p.useState("reschedule_customer"),[s,N]=p.useState(null),x=M({queryKey:["booking","email-templates"],queryFn:()=>l()}),k=(x.data??[]).find(m=>m.kind===j&&m.locale===i);p.useEffect(()=>{N(k?{subject:k.subject,html:k.html}:null)},[j,i,x.dataUpdatedAt]);const h=_({mutationFn:()=>c({data:{kind:j,locale:i,subject:s?.subject??"",html:s?.html??""}}),onSuccess:()=>o.invalidateQueries({queryKey:["booking","email-templates"]})}),f=_({mutationFn:()=>a({data:{kind:j,locale:i}}),onSuccess:()=>o.invalidateQueries({queryKey:["booking","email-templates"]})}),b=_({mutationFn:()=>n({data:{kind:j,locale:i,to:d.trim(),subject:s?.subject??"",html:s?.html??""}})});return e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Terminänderungs-Mails"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Platzhalter: ","{{name}}",", ","{{customer_email}}",", ","{{staff}}",","," ","{{topic}}",", ","{{old_start_local}}",", ","{{start_local}}",","," ","{{end_local}}",", ","{{join_url}}"," â konditional als"," ",e.jsx("code",{className:"rounded bg-muted px-1",children:"{{#if join_url}}â¦{{/if}}"}),". Die Sprache richtet sich nach der Buchung (Fallback: Deutsch)."]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ot.map(m=>e.jsx("button",{onClick:()=>u(m.code),className:`rounded-md border px-3 py-1 text-sm ${j===m.code?"border-primary bg-primary/10 text-primary":"border-border"}`,children:m.label},m.code))}),e.jsx("div",{className:"flex flex-wrap gap-2",children:dt.map(m=>e.jsx("button",{onClick:()=>g(m.code),className:`rounded-md border px-2 py-1 text-xs ${i===m.code?"border-primary bg-primary/10 text-primary":"border-border"}`,children:m.label},m.code))}),x.isLoading||!s?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Lade Vorlagen â¦"}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block text-sm",children:["Betreff",e.jsx("input",{value:s.subject,onChange:m=>N({...s,subject:m.target.value}),className:t})]}),e.jsxs("label",{className:"block text-sm",children:["HTML-Text",e.jsx("textarea",{rows:10,value:s.html,onChange:m=>N({...s,html:m.target.value}),className:`${t} font-mono`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>h.mutate(),disabled:h.isPending,className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:h.isPending?"Speichert â¦":"Vorlage speichern"}),e.jsx("button",{onClick:()=>f.mutate(),disabled:f.isPending,className:"rounded-md border border-border px-3 py-2 text-sm",children:"Auf Standard zurücksetzen"}),h.isSuccess&&e.jsx("span",{className:"text-xs text-emerald-600",children:"Gespeichert"}),h.error&&e.jsx("span",{className:"text-xs text-destructive",children:h.error instanceof Error?h.error.message:String(h.error)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border border-border p-3",children:[e.jsx("span",{className:"text-sm",children:"Test-E-Mail an"}),e.jsx("input",{type:"email",value:d,onChange:m=>r(m.target.value),placeholder:"[email protected]",className:"min-w-[14rem] flex-1 rounded-md border border-border bg-background px-2 py-1 text-sm"}),e.jsx("button",{onClick:()=>b.mutate(),disabled:b.isPending||!/.+@.+\..+/.test(d.trim()),className:"rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-sm font-medium text-primary disabled:opacity-50",children:b.isPending?"Sendet â¦":"Testmail senden"}),e.jsx("span",{className:"w-full text-xs text-muted-foreground",children:"Sendet die aktuell im Editor stehende Fassung mit Beispielwerten für alle Variablen (Betreff mit Präfix [Test])."}),b.isSuccess&&e.jsxs("span",{className:"text-xs text-emerald-600",children:["Gesendet nach ",b.data.attempts," Versuch(en)."]}),b.error&&e.jsx("span",{className:"text-xs text-destructive",children:b.error instanceof Error?b.error.message:String(b.error)})]}),e.jsxs("details",{className:"rounded-md border border-border p-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm",children:"Vorschau"}),e.jsx("div",{className:"prose prose-sm mt-2 max-w-none dark:prose-invert",dangerouslySetInnerHTML:{__html:s.html.replace(/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g,"$2").replace(/\{\{name\}\}/g,"Max Mustermann").replace(/\{\{customer_email\}\}/g,"[email protected]").replace(/\{\{staff\}\}/g,"Michael Böcher").replace(/\{\{topic\}\}/g,"Produktdemo").replace(/\{\{old_start_local\}\}/g,"01.10.2026, 10:00").replace(/\{\{start_local\}\}/g,"03.10.2026, 14:00").replace(/\{\{end_local\}\}/g,"03.10.2026, 14:30").replace(/\{\{join_url\}\}/g,"https://teams.microsoft.com/l/meetup-join/demo")}})]})]})]})}function ct(){const t=v(R),l=v(oe),c=ye(),a=p.useRef(null),n=C(),{seenSet:d,markSeen:r}=J(),o=M({queryKey:["booking","requests"],queryFn:()=>t({data:{limit:100}}),refetchInterval:s=>{const N=s.state.data,x=Date.now();return(N??[]).some(f=>f?.status==="confirmed"&&!f?.join_url&&f?.start_at&&new Date(f.start_at).getTime()>x)?(a.current===null&&(a.current=Date.now()),Date.now()-a.current>c.maxRuntimeMinutes*6e4?!1:c.pollingIntervalSeconds*1e3):(a.current=null,!1)}
1,refetchIntervalInBackground:!1}),i=_({mutationFn:()=>l({data:{horizonDays:60,lookbackDays:1}}),onSuccess:()=>{n.invalidateQueries({queryKey:["booking","requests"]}),n.invalidateQueries({queryKey:["booking","requests","badge"]})}});if(o.isLoading)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"});const g=Array.isArray(o.data)?o.data:[],j=g.filter(s=>s.status==="confirmed"&&!d.has(s.id)),u=()=>{r(g.map(s=>s.id)),n.invalidateQueries({queryKey:["booking","requests","badge"]})};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Zeigt alle Portal-Buchungen und alle Outlook-Kalendertermine der Mitarbeiter, bei denen ein CRM-Kontakt eingeladen ist."}),e.jsxs("div",{className:"flex items-center gap-2",children:[i.data&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Sync: ",i.data.staffProcessed," MA · ",i.data.externalInserted," neu · ",i.data.externalUpdated," akt. · ",i.data.cancelledMarked," abgesagt",i.data.staffFailed.length>0&&` · ${i.data.staffFailed.length} Fehler`]}),e.jsx("button",{onClick:()=>i.mutate(),disabled:i.isPending,className:"rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/20 disabled:opacity-60",children:i.isPending?"Synchronisiereâ¦":"Kalender synchronisieren"})]})]}),i.error&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:i.error instanceof Error?i.error.message:String(i.error)}),g.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Noch keine Buchungen."}),g.length>0&&e.jsxs(e.Fragment,{children:[j.length>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-md border border-emerald-500/40 bg-emerald-500/5 px-3 py-2 text-sm",children:[e.jsxs("span",{children:[j.length," neue Buchung",j.length===1?"":"en"," eingegangen."]}),e.jsx("button",{onClick:u,className:"rounded-md border border-border bg-background px-2 py-1 text-xs hover:bg-accent",children:"Alle als gelesen markieren"})]}),e.jsx("div",{className:"space-y-3 lg:hidden",children:g.map(s=>{const N=Date.now(),x=s.start_at?new Date(s.start_at).getTime():0,k=x>0&&x<N,h=s.status==="cancelled",f=s.status==="confirmed"&&!k,b=s.status==="failed",m=s.status==="confirmed"&&!d.has(s.id),w=h?"bg-destructive/10":f?"bg-emerald-500/5":k&&!b?"bg-muted/40 text-muted-foreground":"bg-card";return e.jsxs("div",{className:`rounded-2xl border border-border p-3 text-sm ${w}`,children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto] items-start gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[m&&e.jsx("span",{className:"inline-block h-2 w-2 shrink-0 rounded-full bg-emerald-500 animate-pulse","aria-label":"Neue Buchung"}),e.jsx("span",{className:"truncate font-medium",children:new Date(s.start_at).toLocaleString("de-DE")})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1",children:[e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${s.status==="confirmed"?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":s.status==="cancelled"?"bg-destructive/20 text-destructive":s.status==="failed"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:s.status}),e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${s.source==="external"?"bg-sky-500/15 text-sky-700 dark:text-sky-300":"bg-muted text-muted-foreground"}`,children:s.source==="external"?"Outlook":"Portal"})]})]}),e.jsxs("div",{className:"mt-2 min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:s.customer_name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.customer_email}),s.customer_company&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.customer_company})]}),e.jsxs("dl",{className:"mt-2 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Mitarbeiter"}),e.jsx("dd",{className:"min-w-0 break-words",children:s.staff_name??"â"}),e.jsx("dt",{className:"text-muted-foreground",children:"Thema"}),e.jsx("dd",{className:"min-w-0 break-words",children:s.topic??"â"})]}),s.error_message&&e.jsx("div",{className:"mt-2 text-xs text-destructive break-words",children:s.error_message}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[s.join_url?e.jsx("a",{href:s.join_url,target:"_blank",rel:"noopener noreferrer",className:"inline-block rounded-md border border-primary/40 px-2 py-1 text-xs text-primary hover:bg-primary/10",children:"Beitreten"}):e.jsx("span",{className:"text-xs italic text-muted-foreground",children:"Link n/v"}),!h&&e.jsx(Q,{row:s,onDone:()=>{n.invalidateQueries({queryKey:["booking","requests"]}),n.invalidateQueries({queryKey:["booking","upcoming"]})}})]}),e.jsx(V,{bookingId:s.id})]},s.id)})}),e.jsx("div",{className:"hidden overflow-x-auto rounded-2xl border border-border lg:block",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/30 text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Termin"}),e.jsx("th",{className:"px-3 py-2",children:"Kunde"}),e.jsx("th",{className:"px-3 py-2",children:"Mitarbeiter"}),e.jsx("th",{className:"px-3 py-2",children:"Thema"}),e.jsx("th",{className:"px-3 py-2",children:"Teams-Meeting"}),e.jsx("th",{className:"px-3 py-2",children:"Status"}),e.jsx("th",{className:"px-3 py-2",children:"Quelle"}),e.jsx("th",{className:"px-3 py-2 sticky right-0 z-10 bg-muted/95 backdrop-blur",children:"Aktion"})]})}),e.jsx("tbody",{children:g.map(s=>{const N=Date.now(),x=s.start_at?new Date(s.start_at).getTime():0,k=x>0&&x<N,h=s.status==="cancelled",f=s.status==="confirmed"&&!k,b=s.status==="failed",m=s.status==="confirmed"&&!d.has(s.id),w=h?"bg-destructive/10":f?"bg-emerald-500/5":k&&!b?"bg-muted/40 text-muted-foreground opacity-70":"";return e.jsxs("tr",{className:`border-t border-border ${w}`,children:[e.jsx("td",{className:"px-3 py-2",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[m&&e.jsx("span",{className:"inline-block h-2 w-2 shrink-0 rounded-full bg-emerald-500 shadow-[0_0_0_3px_rgba(16,185,129,0.15)] animate-pulse",title:"Neue Buchung","aria-label":"Neue Buchung"}
1),new Date(s.start_at).toLocaleString("de-DE")]})}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium",children:s.customer_name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.customer_email}),s.customer_company&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.customer_company})]}),e.jsx("td",{className:"px-3 py-2 text-xs",children:s.staff_name??"â"}),e.jsx("td",{className:"px-3 py-2 text-xs max-w-xs truncate",children:s.topic??"â"}),e.jsx("td",{className:"px-3 py-2",children:s.join_url?e.jsx("a",{href:s.join_url,target:"_blank",rel:"noopener noreferrer",className:"inline-block rounded-md border border-primary/40 text-primary px-2 py-1 text-xs hover:bg-primary/10",children:"Beitreten"}):e.jsx("span",{className:"text-xs text-muted-foreground italic",title:"Microsoft Teams hat noch keinen Meeting-Link für diesen Termin bereitgestellt.",children:"Link n/v"})}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${s.status==="confirmed"?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":s.status==="cancelled"?"bg-destructive/20 text-destructive":s.status==="failed"?"bg-destructive/10 text-destructive":"bg-muted text-muted-foreground"}`,children:s.status}),s.error_message&&e.jsx("div",{className:"text-xs text-destructive mt-1",children:s.error_message})]}),e.jsx("td",{className:"px-3 py-2",children:s.source==="external"?e.jsx("span",{className:"inline-block rounded-full bg-sky-500/15 px-2 py-0.5 text-xs text-sky-700 dark:text-sky-300",title:"Aus Outlook-Kalender eines Mitarbeiters",children:"Outlook"}):e.jsx("span",{className:"inline-block rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground",children:"Portal"})}),e.jsxs("td",{className:"px-3 py-2 sticky right-0 z-10 bg-background/95 backdrop-blur",children:[!h&&e.jsx(Q,{row:s,onDone:()=>{n.invalidateQueries({queryKey:["booking","requests"]}),n.invalidateQueries({queryKey:["booking","upcoming"]})}}),e.jsx(V,{bookingId:s.id})]})]},s.id)})})]})})]})]})}const ut={reschedule_customer_crm:"Ãnderung â Kunde",reschedule_customer_outlook:"Outlook-Ãnderung â Kunde",reschedule_staff_crm:"Ãnderung â Mitarbeiter",reschedule_staff_outlook:"Outlook-Ãnderung â Mitarbeiter"};function V({bookingId:t}){const[l,c]=p.useState(!1),a=v(je),n=M({queryKey:["booking","notifications",t],queryFn:()=>a({data:{bookingId:t}}),enabled:l,refetchInterval:l?15e3:!1});if(!l)return e.jsx("button",{onClick:()=>c(!0),className:"mb-1 block rounded-md border border-border bg-background px-2 py-1 text-xs hover:bg-accent",children:"Zustellstatus"});const d=n.data??[];return e.jsxs("div",{className:"mb-2 min-w-[18rem] space-y-1 rounded-md border border-border bg-background p-2 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:"Zustellstatus"}),e.jsx("button",{onClick:()=>c(!1),className:"text-muted-foreground hover:text-foreground",children:"schlieÃen"})]}),n.isLoading&&e.jsx("p",{className:"text-muted-foreground",children:"Ladeâ¦"}),n.error&&e.jsx("p",{className:"text-destructive",children:n.error instanceof Error?n.error.message:String(n.error)}),!n.isLoading&&d.length===0&&e.jsx("p",{className:"text-muted-foreground",children:"Noch keine Benachrichtigungen versendet."}),d.map(r=>e.jsxs("div",{className:"rounded border border-border/60 p-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{children:ut[r.kind]??r.kind}),e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] ${r.status==="sent"?"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400":r.status==="failed"?"bg-destructive/10 text-destructive":"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400"}`,children:r.status==="sent"?"Zugestellt":r.status==="failed"?"Fehlgeschlagen":"In Zustellung"})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[r.recipient," · ",r.attempts," Versuch(e) ·"," ",E(r.sent_at??r.created_at)]}),r.last_error&&e.jsx("div",{className:"mt-1 break-words rounded bg-destructive/5 p-1 text-[10px] text-destructive",children:r.last_error})]},r.id))]})}function mt(t){const l=new Date(t),c=a=>String(a).padStart(2,"0");return`${l.getFullYear()}-${c(l.getMonth()+1)}-${c(l.getDate())}T${c(l.getHours())}:${c(l.getMinutes())}`}function Q({row:t,onDone:l}){const[c,a]=p.useState(!1),n=v(fe),d=Math.max(5,Math.round((new Date(t.end_at).getTime()-new Date(t.start_at).getTime())/6e4)||30),[r,o]=p.useState(()=>mt(t.start_at)),[i,g]=p.useState(d),[j,u]=p.useState(t.topic??""),[s,N]=p.useState(!0),[x,k]=p.useState(!1),h=_({mutationFn:f=>n({data:{id:t.id,startIso:new Date(r).toISOString(),durationMinutes:i,topic:j,notifyCustomer:s,force:f?.force??x}}),onSuccess:()=>{a(!1),l()}});return c?e.jsxs("div",{className:"min-w-[16rem] space-y-2 rounded-md border border-border bg-background p-2",children:[e.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Neuer Start",e.jsx("input",{type:"datetime-local",value:r,onChange:f=>o(f.target.value),className:"mt-1 w-full rounded-md border border-border bg-background px-2 py-1 text-xs"})]}),e.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Dauer (Min.)",e.jsx("input",{type:"number",min:5,max:600,step:5,value:i,onChange:f=>g(Number(f.target.value)||30),className:"mt-1 w-full rounded-md border border-border bg-background px-2 py-1 text-xs"})]}),e.jsxs("label",{className:"block text-xs text-muted-foreground",children:["Thema",e.jsx("input",{value:j,onChange:f=>u(f.target.value),className:"mt-1 w-full rounded-md border border-border bg-background px-2 py-1 text-xs"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:f=>N(f.target.checked)}),"Kunde per E-Mail informieren"]}),t.conflict_note&&e.jsx("div",{className:"rounded-md bg-amber-500/10 px-2 py-1 text-xs text-amber-700 dark:text-amber-300",children:t.conflict_note}),h.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs text-destructive",children:h.error instanceof Error?h.error.message:String(h.error)}),/Konflikt/i.test(h.error instanceof Error?h.error.message:String(h.error))&&e.jsx("button",{onClick:()=>{k(!0),h.mutate({force:!0})},className:"rounded-md border border-destructive/40 px-2 py-1 text-xs text-destructive hover:bg-destructive/10",children:"Trotzdem überschreiben"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>h.mutate({force:x}),disabled:h.isPending||!r,className:"rounded-md border border-primary/40 bg-primary/10 px-2 py-1 text-xs font-medium text-primary hover:bg-primary/20 disabled:opacity-60",children:h.isPending?"Speichereâ¦":"Speichern"}),e.jsx("button",{onClick:()=>a(!1),className:"rounded-md border border-border px-2 py-1 text-xs hover:bg-accent",children:"Abbrechen"})]})]}):e.jsx("button",{onClick:()=>a(!0),className:"rounded-md border border-primary/40 bg-primary/10 px-2 py-1 text-xs font-medium text-primary hover:bg-primary/20",children:"Verschieben"})}function O(t){return{business_id:t.business_id,business_display_name:t.business_display_name,service_id:t.service_id,service_display_name:t.service_display_name,slot_minutes:t.slot_minutes,buffer_before_minutes:t.buffer_before_minutes,buffer_after_minutes:t.buffer_after_minutes,lead_time_minutes:t.lead_time_minutes,booking_horizon_days:t.booking_horizon_days,work_window_start:t.work_window_start.slice(0,5),work_window_end:t.work_window_end.slice(0,5),timezone:t.timezone,confirmation_subject:t.confirmation_subject,confirmation_html:t.confirmation_html,reminder_subject:t.reminder_subject,reminder_html:t.reminder_html,success_text:t.success_text,error_text:t.error_text,is_active:t.is_active}}const L={token:"Verbindungstest (Token)",list_businesses:"Booking-Pages abrufen",list_services:"Services abrufen",list_staff:"Mitarbeiter abrufen",sync_staff:"Mitarbeiter-Sync",create_appointment:"Termin erstellt",send_confirmation:"Bestätigungs-Mail",send_reminder:"Erinnerungs-Mail",reminder_run:"Erinnerungs-Cron"};
1function E(t){return t?new Date(t).toLocaleString("de-DE",{dateStyle:"medium",timeStyle:"short"}):"â"}function H(t){if(!t)return"noch nie";const l=Date.now()-new Date(t).getTime(),c=Math.round(l/6e4);if(c<1)return"gerade eben";if(c<60)return`vor ${c} Min`;const a=Math.round(c/60);return a<24?`vor ${a} Std`:`vor ${Math.round(a/24)} Tagen`}function xt(){const t=v(le),l=v(ce),c=C(),a=M({queryKey:["booking","diagnostics"],queryFn:()=>t(),refetchOnWindowFocus:!1}),n=_({mutationFn:()=>l(),onSettled:()=>c.invalidateQueries({queryKey:["booking","diagnostics"]})}),d=v(ue),r=_({mutationFn:()=>d(),onSettled:()=>c.invalidateQueries({queryKey:["booking"]})}),o=v(me),i=_({mutationFn:()=>o(),onSettled:()=>c.invalidateQueries({queryKey:["booking","diagnostics"]})}),g=10,[j,u]=p.useState(1),[s,N]=p.useState(1);if(a.isLoading)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ladeâ¦"});if(a.isError)return e.jsxs("p",{className:"text-sm text-destructive",children:["Diagnose konnte nicht geladen werden: ",a.error.message]});const x=a.data,k=Object.keys(L),h=Math.max(1,Math.ceil(k.length/g)),f=Math.min(j,h),b=k.slice((f-1)*g,f*g),m=Math.max(1,Math.ceil(x.recentLogs.length/g)),w=Math.min(s,m),P=x.recentLogs.slice((w-1)*g,w*g);return e.jsxs("section",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Microsoft-Graph-Verbindung"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status der App-Registrierung und letzter Verbindungstest."})]}),e.jsx("button",{onClick:()=>n.mutate(),disabled:n.isPending,className:"rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium disabled:opacity-50",children:n.isPending?"Testeâ¦":"Verbindung jetzt testen"})]}),e.jsxs("div",{className:"grid sm:grid-cols-3 gap-3 text-sm",children:[e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Secrets"}),e.jsx("div",{className:`font-medium ${x.graphConfigured?"text-primary":"text-destructive"}`,children:x.graphConfigured?"Vollständig":"Unvollständig"}),!x.graphConfigured&&e.jsxs("div",{className:"text-xs text-destructive mt-1",children:["Fehlt: ",x.missingSecrets.join(", ")]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Termine (nächste 30 Tage)"}),e.jsx("div",{className:"font-medium",children:x.counts.confirmedNext30d})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Fehlgeschlagen (7 Tage)"}),e.jsx("div",{className:`font-medium ${x.counts.failedLast7d>0?"text-destructive":""}`,children:x.counts.failedLast7d})]})]}),n.isError&&e.jsx("p",{className:"text-xs text-destructive",children:n.error.message}),n.isSuccess&&n.data&&n.data.ok&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Test OK · ",n.data.businesses," Booking-Pages gefunden."]}),n.isSuccess&&n.data&&!n.data.ok&&e.jsx("p",{className:"text-xs text-destructive",children:n.data.error})]}),e.jsx(ht,{cron:x.reminderCron}
1),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Geteiltes Bookings-Postfach"}),e.jsxs("p",{className:"text-sm text-muted-foreground max-w-2xl",children:["Adressen aus ",e.jsx("code",{children:"MS_BOOKINGS_SHARED_MAILBOX"})," werden als optionale Teilnehmer eingeladen, damit Termine im gemeinsamen Outlook-Kalender sichtbar sind. Kommagetrennt, gültiges E-Mail-Format."]})]}),!x.sharedMailbox.configured||x.sharedMailbox.error?e.jsx("div",{className:"rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:x.sharedMailbox.error??"MS_BOOKINGS_SHARED_MAILBOX ist nicht gesetzt."}):e.jsxs("div",{className:"rounded-lg border border-border p-3 text-sm",children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-1",children:["Gültige Adressen (",x.sharedMailbox.valid.length,")"]}),e.jsx("ul",{className:"list-disc list-inside space-y-0.5",children:x.sharedMailbox.valid.map(y=>e.jsx("li",{className:"font-mono text-xs",children:y},y))})]}),x.sharedMailbox.invalid.length>0&&e.jsxs("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/5 p-3 text-xs text-amber-700 dark:text-amber-400 space-y-1",children:[e.jsxs("div",{className:"font-medium",children:["Ungültige Einträge (",x.sharedMailbox.invalid.length,") â werden ignoriert:"]}),e.jsx("ul",{className:"list-disc list-inside",children:x.sharedMailbox.invalid.map(y=>e.jsx("li",{className:"font-mono",children:y},y))})]})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Zukünftige Termine auf Mitarbeiter-Kalender migrieren"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-2xl",children:"Verschiebt bestätigte kommende Termine aus Microsoft Bookings direkt in den Outlook-Kalender des jeweiligen Mitarbeiters. Der Mitarbeiter wird dadurch Organisator und kann das Teams-Meeting starten. Der Kunde erhält eine aktualisierte Mail mit dem neuen Teams-Link; der alte Bookings-Termin wird storniert."})]}),e.jsx("button",{onClick:()=>r.mutate(),disabled:r.isPending,className:"rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium disabled:opacity-50",children:r.isPending?"Migriereâ¦":"Jetzt migrieren"})]}),r.isError&&e.jsx("p",{className:"text-xs text-destructive",children:r.error.message}),r.isSuccess&&r.data&&e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("p",{children:["Geprüft: ",r.data.scanned," · Migriert:"," ",e.jsx("span",{className:"text-primary font-medium",children:r.data.migrated})," · Ãbersprungen: ",r.data.skipped," · Fehlgeschlagen:"," ",e.jsx("span",{className:r.data.failed>0?"text-destructive font-medium":"",children:r.data.failed})]}),r.data.errors.length>0&&e.jsx("ul",{className:"list-disc pl-5",children:r.data.errors.map(y=>e.jsxs("li",{className:"text-destructive",children:[y.id,": ",y.error]},y.id))})]})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Letzte Sync-Zeitpunkte"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[k.length," Vorgänge"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-2 pr-3",children:"Vorgang"}),e.jsx("th",{className:"py-2 pr-3",children:"Letzter Lauf"}),e.jsx("th",{className:"py-2 pr-3",children:"Wann"}),e.jsx("th",{className:"py-2 pr-3",children:"Status"}),e.jsx("th",{className:"py-2 pr-3",children:"Dauer"}),e.jsx("th",{className:"py-2 pr-3",children:"Meldung"})]})}),e.jsx("tbody",{children:b.map(y=>{const S=x.lastByKind[y];return e.jsxs("tr",{className:"border-t border-border align-top",children:[e.jsx("td",{className:"py-2 pr-3 font-medium",children:L[y]}),e.jsx("td",{className:"py-2 pr-3",children:E(S?.created_at)}),e.jsx("td",{className:"py-2 pr-3 text-muted-foreground",children:H(S?.created_at)}),e.jsx("td",{className:"py-2 pr-3",children:S?e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${S.success?"bg-primary/10 text-primary":"bg-destructive/10 text-destructive"}`,children:S.success?"OK":"Fehler"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"})}),e.jsx("td",{className:"py-2 pr-3 text-xs text-muted-foreground",children:S?.duration_ms!=null?`${S.duration_ms} ms`:"â"}),e.jsx("td",{className:"py-2 pr-3 text-xs max-w-sm truncate",children:S?.message??"â"})]},y)})})]})}),e.jsx(I,{page:f,totalPages:h,onChange:u})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Letzte Admin-Logs"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[x.recentLogs.length," Einträge"]}),e.jsx("button",{onClick:()=>{confirm("Alle Admin-Log-Einträge älter als 30 Tage endgültig löschen?")&&i.mutate()},disabled:i.isPending,className:"rounded-md border border-destructive/50 text-destructive px-3 py-1.5 text-xs font-medium hover:bg-destructive/10 disabled:opacity-50",children:i.isPending?"Löscheâ¦":"Einträge älter als 30 Tage löschen"})]})]}),i.isError&&e.jsx("p",{className:"text-xs text-destructive",children:i.error.message}),i.isSuccess&&i.data&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.data.deleted," Einträge gelöscht."]}),x.recentLogs.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Noch keine Einträge. Logs entstehen bei jedem Graph-Aufruf, Sync und jeder Termin-Erstellung."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-2 pr-3",children:"Zeit"}),e.jsx("th",{className:"py-2 pr-3",children:"Vorgang"}),e.jsx("th",{className:"py-2 pr-3",children:"Status"}),e.jsx("th",{className:"py-2 pr-3",children:"Dauer"}),e.jsx("th",{className:"py-2 pr-3",children:"Meldung"})]})}),e.jsx("tbody",{children:P.map(y=>e.jsxs("tr",{className:"border-t border-border align-top",children:[e.jsx("td",{className:"py-2 pr-3 whitespace-nowrap",children:E(y.created_at)}),e.jsx("td",{className:"py-2 pr-3",children:L[y.kind]??y.kind}),e.jsx("td",{className:"py-2 pr-3",children:e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${y.level==="error"?"bg-destructive/10 text-destructive":y.level==="warn"?"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400":"bg-primary/10 text-primary"}`,children:y.success?"OK":y.level==="warn"?"Warnung":"Fehler"})}),e.jsx("td",{className:"py-2 pr-3 text-xs text-muted-foreground",children:y.duration_ms!=null?`${y.duration_ms} ms`:"â"}),e.jsxs("td",{className:"py-2 pr-3 text-xs max-w-md",children:[e.jsx("div",{className:"truncate",children:y.message??"â"}),y.details&&e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[10px] text-muted-foreground",children:"Details"}),e.jsx("pre",{className:"mt-1 whitespace-pre-wrap break-all rounded bg-muted/30 p-2 text-[10px]",children:JSON.stringify(y.details,null,2)})]})]})]},y.id))})]})}),x.recentLogs.length>0&&e.jsx(I,{page:w,totalPages:m,onChange:N})]})]})}function I({page:t,totalPages:l,onChange:c}){return l<=1?null:e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2 text-xs",children:[e.jsx("button",{onClick:()=>c(Math.max(1,t-1)),disabled:t<=1,className:"rounded border border-border px-2 py-1 disabled:opacity-40",children:"Zurück"}),e.jsxs("span",{className:"text-muted-foreground",children:["Seite ",t," / ",l]}),e.jsx("button",{onClick:()=>c(Math.min(l,t+1)),disabled:t>=l,className:"rounded border border-border px-2 py-1 disabled:opacity-40",children:"Weiter"})]})}function ht({cron:t}){const l=t.exists&&t.active===!0,c=t.lastStatus==="succeeded";return e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Erinnerungs-Cron"}),e.jsxs("p",{className:"text-sm text-muted-foreground max-w-2xl",children:["Der Job ",e.jsx("code",{children:"booking-reminders-hourly"}
1)," ruft stündlich"," ",e.jsx("code",{children:"/api/public/booking-reminders"})," auf und verschickt fällige Termin-Erinnerungen."]})]}),t.exists?e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Status"}),e.jsx("div",{className:`font-medium ${l?"text-primary":"text-destructive"}`,children:l?"Aktiv":"Inaktiv"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 font-mono",children:t.schedule??"â"})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Letzter Lauf"}),e.jsx("div",{className:"font-medium",children:E(t.lastStart)}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1",children:H(t.lastStart)})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ergebnis"}),t.lastStatus?e.jsx("span",{className:`inline-block rounded-full px-2 py-0.5 text-xs ${c?"bg-primary/10 text-primary":"bg-destructive/10 text-destructive"}`,children:t.lastStatus}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"noch kein Lauf"}),t.lastEnd&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Ende: ",E(t.lastEnd)]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-3 sm:col-span-2 lg:col-span-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Rückmeldung"}),e.jsx("div",{className:"text-xs font-mono break-all line-clamp-3",children:t.lastReturn?.trim()?t.lastReturn:"â"})]})]}):e.jsxs("div",{className:"rounded-lg border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive",children:["Cronjob ",e.jsx("code",{children:"booking-reminders-hourly"})," ist nicht eingerichtet."]})]})}export{jt as component};
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.