1import{i as ae,r,j as e,B as p,X as V,m as re,aI as ie,q as le,n as oe,u as T,a as Z,t as H,L as de}from"./index-0VLb6ULf.js";import{u as ce}from"./useMutation-u_jUy0Ke.js";import{I as k}from"./input-Xc8GPmEU.js";import{T as B}from"./textarea-D4WmB0Zu.js";import{S as O}from"./switch-Dj_Z4a7L.js";import{T as ue,a as xe,b as U,c as W}from"./tabs-BhVjUapM.js";import{a as me,d as he,e as pe}from"./surveys.functions-Cn5O2BRM.js";import{S as K,a as X,b as Q,c as G,d as J}from"./select-CTm5PKiZ.js";import{P as ee}from"./plus-OH1R297X.js";import{C as ge}from"./chevron-right-Nyaax30u.js";import{F as fe}from"./flag-BRpl0-Pf.js";import{T as je}from"./trash-2-CJQvBDy_.js";import{A as ve}from"./arrow-left-H9lWUjYM.js";import"./index-qD5aUIGa.js";import"./index-0Mw5-f3V.js";import"./index-B6zo4fIT.js";import"./index-6znq2QsO.js";import"./auth-middleware-yuYFG7e7.js";import"./index-sqLNrReF.js";import"./index-7gs3kyXR.js";import"./index-Bjh9E_vE.js";import"./check-B6tZ20Ik.js";const be=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ye=ae("save",be);const Ne=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]],te=ae("unlink",Ne),z=300,_=1400,q=2200,L={single:"Einzelauswahl",multi:"Mehrfachauswahl",text:"Freitext",scale:"Skala 1â10"};function A(i){return`${i}_${Math.random().toString(36).slice(2,9)}`}function we({graph:i,onChange:l}){const m=r.useRef(null),[d,v]=r.useState(null),[b,I]=r.useState(null),[f,h]=r.useState({}),S=t=>h(s=>({...s,[t]:!s[t]})),x=i.nodes,j=r.useMemo(()=>{const t={};for(const s of x)t[s.id]=s;return t},[x]),g=r.useCallback(t=>l(t(i)),[i,l]),u=(t,s)=>g(a=>({...a,nodes:a.nodes.map(n=>n.id===t?{...n,...s}:n)})),D=()=>{const t=A("q"),s={id:t,question:"Neue Frage",help:"",type:"single",options:[{id:A("o"),label:"Antwort A",nextId:null},{id:A("o"),label:"Antwort B",nextId:null}],nextId:null,required:!0,x:40+x.length*60%900,y:40+x.length*40};g(a=>({startId:a.startId??t,nodes:[...a.nodes,s]}))},M=t=>g(s=>({startId:s.startId===t?s.nodes.find(a=>a.id!==t)?.id??null:s.startId,nodes:s.nodes.filter(a=>a.id!==t).map(a=>({...a,nextId:a.nextId===t?null:a.nextId,options:a.options.map(n=>n.nextId===t?{...n,nextId:null}:n)}))})),P=t=>{if(d){if(d.nodeId===t){v(null);return}d.optionId?u(d.nodeId,{options:j[d.nodeId].options.map(s=>s.id===d.optionId?{...s,nextId:t}:s)}):u(d.nodeId,{nextId:t}),v(null)}},C=(t,s)=>{const a=m.current?.getBoundingClientRect();a&&I({id:s.id,dx:t.clientX-a.left-s.x,dy:t.clientY-a.top-s.y})},E=t=>{if(!b)return;const s=m.current?.getBoundingClientRect();if(!s)return;const a=Math.max(0,Math.min(q-z,t.clientX-s.left-b.dx)),n=Math.max(0,Math.min(_-80,t.clientY-s.top-b.dy));u(b.id,{x:a,y:n})},$=r.useMemo(()=>{const t=[];for(const s of x){s.type==="single"&&s.options.forEach((n,c)=>{const o=n.nextId?j[n.nextId]:void 0;o&&t.push({from:s,to:o,label:n.label,index:c,key:`${s.id}:${n.id}`})});const a=s.nextId?j[s.nextId]:void 0;a&&t.push({from:s,to:a,label:"weiter",index:-1,key:`${s.id}:default`})}return t},[x,j]),y=r.useRef(new Map),[N,F]=r.useState({}),w=r.useCallback(t=>s=>{s?y.current.set(t,s):y.current.delete(t)},[]);return r.useLayoutEffect(()=>{const t=m.current;if(!t)return;const s=t.getBoundingClientRect(),a={};y.current.forEach((n,c)=>{const o=n.getBoundingClientRect();a[c]=o.top-s.top+o.height/2}),F(n=>{const c=new Set([...Object.keys(n),...Object.keys(a)]);for(const o of c)if(Math.abs((n[o]??-1)-(a[o]??-1))>.5)return a;return n})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(p,{size:"sm",onClick:D,children:[e.jsx(ee,{className:"w-4 h-4 mr-1"})," Frage hinzufügen"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Startfrage:"," ",e.jsxs(K,{value:i.startId??"",onValueChange:t=>g(s=>({...s,startId:t})),children:[e.jsx(X,{className:"h-7 w-56 inline-flex text-xs",children:e.jsx(Q,{placeholder:"Frage wählenâ¦"})}),e.jsx(G,{children:x.map(t=>e.jsx(J,{value:t.id,children:t.question.slice(0,50)},t.id))})]})]}),d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent",children:["Ziel-Frage anklickenâ¦",e.jsx(p,{size:"sm",variant:"ghost",className:"h-6 px-2",onClick:()=>v(null),children:e.jsx(V,{className:"w-3 h-3"})})]})]}),e.jsx("div",{className:"border border-border rounded-xl overflow-auto bg-secondary/40 max-h-[75vh]",children:e.jsxs("div",{ref:m,className:"relative",style:{width:q,height:_,backgroundImage:"radial-gradient(circle, var(--border) 1px, transparent 1px)",backgroundSize:"22px 22px"},onPointerMove:E,onPointerUp:()=>I(null),onPointerLeave:()=>I(null),children:[e.jsxs("svg",{className:"absolute inset-0 pointer-events-none",width:q,height:_,children:[e.jsx("defs",{children:e.jsx("marker",{id:"survey-arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto-start-reverse",children:e.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--accent)"})})}),$.map((t,s)=>{const a=t.from.x+z,n=N[t.key],c=n!=null&&!f[t.from.id]?n:f[t.from.id]?N[`${t.from.id}
1:head`]??t.from.y+26:t.from.y+56+(t.index>=0?t.index*34:0),o=t.to.x,Y=N[`${t.to.id}:head`]??t.to.y+26,R=(a+o)/2;return e.jsx("path",{d:`M ${a} ${c} C ${R} ${c}, ${R} ${Y}, ${o} ${Y}`,fill:"none",stroke:"var(--accent)",strokeWidth:2,opacity:.8,markerEnd:"url(#survey-arrow)"},`${t.from.id}-${t.to.id}-${s}`)})]}),x.map(t=>e.jsxs("div",{className:`absolute bg-card border rounded-xl shadow-sm ${d&&d.nodeId!==t.id?"border-accent cursor-pointer ring-2 ring-accent/40":"border-border"}`,style:{left:t.x,top:t.y,width:z},onClick:()=>d&&P(t.id),children:[e.jsxs("div",{ref:w(`${t.id}:head`),className:"flex items-start gap-2 px-3 py-2 border-b border-border cursor-move select-none",onPointerDown:s=>C(s,t),children:[e.jsx(p,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",title:f[t.id]?"Aufklappen":"Zuklappen",onPointerDown:s=>s.stopPropagation(),onClick:()=>S(t.id),children:f[t.id]?e.jsx(ge,{className:"w-4 h-4"}):e.jsx(re,{className:"w-4 h-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(k,{value:t.question,onChange:s=>u(t.id,{question:s.target.value}),onPointerDown:s=>s.stopPropagation(),className:"h-7 text-sm font-medium"})}),i.startId===t.id&&e.jsx("span",{title:"Startfrage",children:e.jsx(fe,{className:"w-4 h-4 text-accent mt-1.5"})}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-7 w-7",onPointerDown:s=>s.stopPropagation(),onClick:()=>M(t.id),children:e.jsx(je,{className:"w-3.5 h-3.5 text-destructive"})})]}),f[t.id]&&e.jsxs("div",{className:"px-3 py-2 text-[11px] text-muted-foreground",children:[L[t.type],t.options.length?` · ${t.options.length} Antworten`:""]}),!f[t.id]&&e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsxs(K,{value:t.type,onValueChange:s=>u(t.id,{type:s,options:s==="single"||s==="multi"?t.options.length?t.options:[{id:A("o"),label:"Antwort A",nextId:null}]:[]}),children:[e.jsx(X,{className:"h-7 text-xs",children:e.jsx(Q,{})}),e.jsx(G,{children:Object.keys(L).map(s=>e.jsx(J,{value:s,children:L[s]},s))})]}),e.jsx(B,{value:t.help??"",onChange:s=>u(t.id,{help:s.target.value}),placeholder:"Hinweistext (optional)",className:"text-xs min-h-[48px]"}),(t.type==="single"||t.type==="multi")&&e.jsxs("div",{className:"space-y-1",children:[t.options.map(s=>e.jsxs("div",{ref:w(`${t.id}:${s.id}`),className:"flex items-center gap-1",children:[e.jsx(k,{value:s.label,onChange:a=>u(t.id,{options:t.options.map(n=>n.id===s.id?{...n,label:a.target.value}:n)}),className:"h-7 text-xs"}),t.type==="single"&&e.jsx(p,{size:"icon",variant:s.nextId?"default":"outline",className:"h-7 w-7 shrink-0",title:s.nextId?"Verbindung ändern":"Mit Folgefrage verbinden",onClick:()=>v({nodeId:t.id,optionId:s.id}),children:e.jsx("span",{className:"text-[10px]",children:"â"})}),t.type==="single"&&s.nextId&&e.jsx(p,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",title:"Verbindung lösen",onClick:()=>u(t.id,{options:t.options.map(a=>a.id===s.id?{...a,nextId:null}:a)}),children:e.jsx(te,{className:"w-3 h-3"})}),e.jsx(p,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>u(t.id,{options:t.options.filter(a=>a.id!==s.id)}),children:e.jsx(V,{className:"w-3 h-3"})})]},s.id)),e.jsxs(p,{size:"sm",variant:"outline",className:"h-7 text-xs w-full",onClick:()=>u(t.id,{options:[...t.options,{id:A("o"),label:`Antwort ${t.options.length+1}`,nextId:null}]}),children:[e.jsx(ee,{className:"w-3 h-3 mr-1"})," Antwort"]})]}),e.jsxs("div",{ref:w(`${t.id}:default`),className:"flex items-center gap-1 pt-1 border-t border-border",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground flex-1",children:t.nextId?`Danach: ${j[t.nextId]?.question.slice(0,22)??"?"}`:"Danach: Dankeseite"}),e.jsx(p,{size:"sm",variant:"outline",className:"h-6 px-2 text-[11px]",onClick:()=>v({nodeId:t.id,optionId:null}),children:"Standard-Ziel"}),t.nextId&&e.jsx(p,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:()=>u(t.id,{nextId:null}),children:e.jsx(te,{className:"w-3 h-3"})})]})]})]},t.id)),!x.length&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-sm text-muted-foreground",children:"Noch keine Fragen â oben âFrage hinzufügenâ klicken."})]})}),e.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Dankeseite (nach Abschluss)"}),e.jsx(k,{value:i.thankYou?.title??"",placeholder:"Danke für Deine Teilnahme!",onChange:t=>g(s=>({...s,thankYou:{title:t.target.value,body:s.thankYou?.body??""}}))}),e.jsx(B,{value:i.thankYou?.body??"",placeholder:"Deine Antworten sind gespeichert. Pro Person ist eine Teilnahme möglich.",className:"min-h-[90px]",onChange:t=>g(s=>({...s,thankYou:{title:s.thankYou?.title??"",body:t.target.value}}))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Bei Einzelauswahl bestimmt jede Antwort die Folgefrage (â-Button, dann Ziel-Karte anklicken). Ohne Verbindung gilt das Standard-Ziel der Frage, sonst wird die Umfrage abgeschickt und die Dankeseite gezeigt."})]})}const se={startId:null,nodes:[]};function ne(i){if(!i)return"";const l=new Date(i);if(Number.isNaN(l.getTime()))return"";const m=d=>String(d).padStart(2,"0");return`${l.getFullYear()}-${m(l.getMonth()+1)}-${m(l.getDate())}T${m(l.getHours())}:${m(l.getMinutes())}`}function Oe(){const{id:i}=ie.useParams(),l=i==="neu",m=le(),d=oe(),v=T(me),b=T(he),I=T(pe),{data:f=[]}=Z({queryKey:["admin-surveys"],queryFn:async()=>await v(),retry:!1}),h=l?null:f.find(n=>n.id===i),[S,x]=r.useState(""),[j,g]=r.useState(""),[u,D]=r.useState(!1),[M,P]=r.useState(!0),[C,E]=r.useState(""),[$,y]=r.useState(""),[N,F]=r.useState(se),[w,t]=r.useState(!1);r.useEffect(()=>{l||w||!h||(x(h.title??""),g(h.description??""),D(!!h.is_active),P(h.show_public!==!1),E(ne(h.starts_at)),y(ne(h.ends_at)),F(h.graph??se),t(!0))},[h,l,w]);const s=ce({mutationFn:()=>b({data:{...l?{}:{id:i},title:S,description:j,is_active:u,show_public:M,starts_at:C?new Date(C).toISOString():"",ends_at:$?new Date($).toISOString():"",graph:N}}),onSuccess:n=>{d.invalidateQueries({queryKey:["admin-surveys"]}),H.success("Umfrage gespeichert."),l&&n?.id&&m({to:"/admin/umfragen/$id",params:{id:n.id}})},onError:n=>H.error(n instanceof Error?n.message:"Speichern fehlgeschlagen.")}),{data:a}=Z({queryKey:["admin-survey-results",i],queryFn:()=>I({data:{id:i}}),enabled:!l,retry:!1});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-6",children:[e.jsxs(de,{to:"/admin/umfragen",className:"text-sm text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(ve,{className:"w-4 h-4"})," Zurück zur Ãbersicht"]}),e.jsxs(p,{onClick:()=>s.mutate(),disabled:!S.trim()||s.isPending,children:[e.jsx(ye,{className:"w-4 h-4 mr-1"})," Speichern"]})]}),e.jsxs(ue,{defaultValue:"editor",children:[e.jsxs(xe,{className:"mb-4",children:[e.jsx(U,{value:"editor",children:"Bearbeiten"}),e.jsxs(U,{value:"results",disabled:l,children:["Auswertung ",a?`(${a.total})`:""]})]}),e.jsxs(W,{value:"editor",className:"space-y-4",children:[e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Titel"}),e.jsx(k,{value:S,onChange:n=>x(n.target.value),placeholder:"Titel der Umfrage"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Beschreibung"}),e.jsx(B,{value:j,onChange:n=>g(n.target.value),placeholder:"Worum geht es in dieser Umfrage?"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Start (Datum / Zeit)"}),e.jsx(k,{type:"datetime-local",value:C,onChange:n=>E(n.target.value)}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Leer + aktiv = ab sofort (aktuelles Datum wird übernommen)."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Ende (Datum / Zeit)"}),e.jsx(k,{type:"datetime-local",value:$,onChange:n=>y(n.target.value)}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Leer = kein Endd
1atum, läuft bis der Schalter deaktiviert wird."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-6 pt-1",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(O,{checked:u,onCheckedChange:D})," Aktiv (im Menü sichtbar)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(O,{checked:M,onCheckedChange:P})," Auch öffentlich sichtbar"]})]})]}),e.jsx(we,{graph:N,onChange:F})]}),e.jsxs(W,{value:"results",className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a?.total??0," Teilnahmen â nur für Admins sichtbar."]}),(a?.stats??[]).map(n=>e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4",children:[e.jsx("h3",{className:"font-medium mb-1",children:n.question}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:[n.answered," Antworten",n.average!==null?` · Durchschnitt ${n.average.toFixed(2)}`:""]}),n.options.length>0&&e.jsx("div",{className:"space-y-2",children:n.options.map(c=>{const o=n.answered?Math.round(c.count/n.answered*100):0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{children:c.label}),e.jsxs("span",{className:"text-muted-foreground",children:[c.count," (",o,"%)"]})]}),e.jsx("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent",style:{width:`${o}%`}})})]},c.id)})}),n.texts.length>0&&e.jsx("ul",{className:"mt-3 space-y-1 text-sm",children:n.texts.slice(0,50).map((c,o)=>e.jsx("li",{className:"border-l-2 border-border pl-3 text-muted-foreground",children:c},o))})]},n.nodeId)),!!a?.responses?.length&&e.jsx("div",{className:"bg-card border border-border rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary text-left text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Teilnehmer"}),e.jsx("th",{className:"p-3",children:"Datum"}),e.jsx("th",{className:"p-3",children:"Antworten"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:a.responses.map(n=>e.jsxs("tr",{children:[e.jsx("td",{className:"p-3",children:n.participant}),e.jsx("td",{className:"p-3 text-muted-foreground text-xs",children:new Date(n.created_at).toLocaleString("de-DE")}),e.jsxs("td",{className:"p-3 text-xs text-muted-foreground",children:[n.answers.length," beantwortet"]})]},n.id))})]})})]})]})]})}export{Oe 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.