1import{as as ln,at as cn,r as u,au as dn,a4 as e,ae as sn,ay as un,az as Oe,aG as At,aA as wn,aC as vt,kn as In,k0 as Jn,k5 as Vt,kw as $t,ka as Ne,j$ as pn,kb as zt,kx as Bt,aW as xe,km as Ot,aD as Je,ky as xn,av as Dt,aU as se,kz as Nt,kA as Ft,kB as Gt,kC as Xn,kD as Yn,kE as Zn,k3 as Re,k8 as Ht,k7 as Ut,k1 as Qt,k2 as Kt,k4 as Jt}from"./index-Bw1_3nkz.js";import{j as k,d as Wn,B as Xt,S as Te,O as en,bh as nn,I as Xe,R as tn,P as Se,H as U,ab as Tn,U as Un,a2 as Yt,aa as ge,E as Zt,K as Pn,a9 as Qn,ag as _t,cU as pt,J as on,bd as es}from"./Root-BY7ucel4.js";import{r as ns,g as ts,e as Dn,c as ss,b as rs,h as as}from"./routing-Ba3r-gg2.js";import{c as Ke,r as Rn,g as ve,b as gt,s as mn,d as qn,i as xt,e as An,f as En,h as is,m as os,j as rn,k as mt,n as yt,o as ls,p as ft,q as cs,t as ds,u as Vn,v as us,w as hs,x as vs,l as _s,S as $n,y as ps}from"./SurveyRecipientMultiSelect-CyimqBV4.js";import{r as Nn}from"./useAuthoringGovernedSurveyCatalog-D6w5Tt3j.js";import{an as Fn,a5 as de,S as y,a1 as K,k as fe,af as hn,am as bn,l as vn,a2 as Fe,Q as gn,ag as Kn,ah as Ye,ak as gs,al as xs,s as ms,at as jt,au as et}from"./index-lCvTI3l-.js";import{c as Me,ai as ys,i as fs,l as me,k as je,S as be,a8 as nt}from"./index-qkmnlOmN.js";import{G as js}from"./GovernedSurveyDeleteAction-BQD_Bveo.js";import{A as tt}from"./ArrowBack-wtacKAv3.js";import{L as bt}from"./ListItemButton-Bh1gPyeY.js";import{L as Gn}from"./ListItemText-J22LWWTJ.js";import{A as wt,a as Ct}from"./ArrowUpward-BIIRy-oW.js";import{R as bs}from"./RestartAlt-BllFl16i.js";import{A as yn,a as fn,b as jn}from"./AccordionSummary-p8qeWObH.js";import{D as st}from"./DeleteOutline-CMdMtkUi.js";import{r as ws}from"./usePublishedGovernedSurveyCatalog-emzz3aDY.js";import{O as Cs}from"./OpenInNew-D4H8lO1R.js";import{g as Ss,b as ks,a as Is,c as Ps}from"./codebookValidation-CXY-hAIa.js";import"./useQuery-Cu_Unqz4.js";import"./index-D-W0Qqc-.js";function Rs(n){return ln("MuiDialogContentText",n)}cn("MuiDialogContentText",["root"]);const qs=n=>{const{classes:t}=n,i=un({root:["root"]},Rs,t);return{...t,...i}},Es=Oe(k,{shouldForwardProp:n=>At(n)||n==="classes",name:"MuiDialogContentText",slot:"Root",overridesResolver:(n,t)=>t.root})({}),rt=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiDialogContentText"}),{children:_,className:s,...o}=i,a=qs(o);return e.jsx(Es,{component:"p",variant:"body1",color:"textSecondary",ref:r,ownerState:o,className:sn(a.root,s),...i,classes:a})}),Cn=u.createContext({}),Mn=u.createContext({});function Ts(n){return ln("MuiStep",n)}cn("MuiStep",["root","horizontal","vertical","alternativeLabel","completed"]);const Ms=n=>{const{classes:t,orientation:r,alternativeLabel:i,completed:_}=n;return un({root:["root",r,i&&"alternativeLabel",_&&"completed"]},Ts,t)},Ls=Oe("div",{name:"MuiStep",slot:"Root",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[t.root,t[r.orientation],r.alternativeLabel&&t.alternativeLabel,r.completed&&t.completed]}})({variants:[{props:{orientation:"horizontal"},style:{paddingLeft:8,paddingRight:8}},{props:{alternativeLabel:!0},style:{flex:1,position:"relative"}}]}),Ws=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStep"}),{active:_,children:s,className:o,component:a="div",completed:d,disabled:w,expanded:v=!1,index:f,last:p,...z}=i,{activeStep:C,connector:N,alternativeLabel:G,orientation:J,nonLinear:L}=u.useContext(Cn);let[I=!1,V=!1,X=!1]=[_,d,w];C===f?I=_!==void 0?_:!0:!L&&C>f?V=d!==void 0?d:!0:!L&&C<f&&(X=w!==void 0?w:!0);const Y=u.useMemo(()=>({index:f,last:p,expanded:v,icon:f+1,active:I,completed:V,disabled:X}),[f,p,v,I,V,X]),ne={...i,active:I,orientation:J,alternativeLabel:G,completed:V,disabled:X,expanded:v,component:a},W=Ms(ne),Z=e.jsxs(Ls,{as:a,className:sn(W.root,o),ref:r,ownerState:ne,...z,children:[N&&G&&f!==0?N:null,s]});return e.jsx(Mn.Provider,{value:Y,children:N&&!G&&f!==0?e.jsxs(u.Fragment,{children:[N,Z]}):Z})}),As=Me(e.jsx("path",{d:"M12 0a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm-2 17l-5-5 1.4-1.4 3.6 3.6 7.6-7.6L19 8l-9 9z"}
1),"CheckCircle"),Vs=Me(e.jsx("path",{d:"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z"}),"Warning");function $s(n){return ln("MuiStepIcon",n)}const zn=cn("MuiStepIcon",["root","active","completed","error","text"]);var at;const zs=n=>{const{classes:t,active:r,completed:i,error:_}=n;return un({root:["root",r&&"active",i&&"completed",_&&"error"],text:["text"]},$s,t)},Bn=Oe(ys,{name:"MuiStepIcon",slot:"Root",overridesResolver:(n,t)=>t.root})(wn(({theme:n})=>({display:"block",transition:n.transitions.create("color",{duration:n.transitions.duration.shortest}),color:(n.vars||n).palette.text.disabled,[`&.${zn.completed}`]:{color:(n.vars||n).palette.primary.main},[`&.${zn.active}`]:{color:(n.vars||n).palette.primary.main},[`&.${zn.error}`]:{color:(n.vars||n).palette.error.main}}))),Bs=Oe("text",{name:"MuiStepIcon",slot:"Text",overridesResolver:(n,t)=>t.text})(wn(({theme:n})=>({fill:(n.vars||n).palette.primary.contrastText,fontSize:n.typography.caption.fontSize,fontFamily:n.typography.fontFamily}))),Os=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStepIcon"}),{active:_=!1,className:s,completed:o=!1,error:a=!1,icon:d,...w}=i,v={...i,active:_,completed:o,error:a},f=zs(v);if(typeof d=="number"||typeof d=="string"){const p=sn(s,f.root);return a?e.jsx(Bn,{as:Vs,className:p,ref:r,ownerState:v,...w}):o?e.jsx(Bn,{as:As,className:p,ref:r,ownerState:v,...w}):e.jsxs(Bn,{className:p,ref:r,ownerState:v,...w,children:[at||(at=e.jsx("circle",{cx:"12",cy:"12",r:"12"})),e.jsx(Bs,{className:f.text,x:"12",y:"12",textAnchor:"middle",dominantBaseline:"central",ownerState:v,children:d})]})}return d});function Ds(n){return ln("MuiStepLabel",n)}const Ze=cn("MuiStepLabel",["root","horizontal","vertical","label","active","completed","error","disabled","iconContainer","alternativeLabel","labelContainer"]),Ns=n=>{const{classes:t,orientation:r,active:i,completed:_,error:s,disabled:o,alternativeLabel:a}=n;return un({root:["root",r,s&&"error",o&&"disabled",a&&"alternativeLabel"],label:["label",i&&"active",_&&"completed",s&&"error",o&&"disabled",a&&"alternativeLabel"],iconContainer:["iconContainer",i&&"active",_&&"completed",s&&"error",o&&"disabled",a&&"alternativeLabel"],labelContainer:["labelContainer",a&&"alternativeLabel"]},Ds,t)},Fs=Oe("span",{name:"MuiStepLabel",slot:"Root",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[t.root,t[r.orientation]]}})({display:"flex",alignItems:"center",[`&.${Ze.alternativeLabel}`]:{flexDirection:"column"},[`&.${Ze.disabled}`]:{cursor:"default"},variants:[{props:{orientation:"vertical"},style:{textAlign:"left",padding:"8px 0"}}]}),Gs=Oe("span",{name:"MuiStepLabel",slot:"Label",overridesResolver:(n,t)=>t.label})(wn(({theme:n})=>({...n.typography.body2,display:"block",transition:n.transitions.create("color",{duration:n.transitions.duration.shortest}),[`&.${Ze.active}`]:{color:(n.vars||n).palette.text.primary,fontWeight:500},[`&.${Ze.completed}`]:{color:(n.vars||n).palette.text.primary,fontWeight:500},[`&.${Ze.alternativeLabel}`]:{marginTop:16},[`&.${Ze.error}`]:{color:(n.vars||n).palette.error.main}}))),Hs=Oe("span",{name:"MuiStepLabel",slot:"IconContainer",overridesResolver:(n,t)=>t.iconContainer})({flexShrink:0,display:"flex",paddingRight:8,[`&.${Ze.alternativeLabel}`]:{paddingRight:0}}),Us=Oe("span",{name:"MuiStepLabel",slot:"LabelContainer",overridesResolver:(n,t)=>t.labelContainer})(wn(({theme:n})=>({width:"100%",color:(n.vars||n).palette.text.secondary,[`&.${Ze.alternativeLabel}`]:{textAlign:"center"}}))),St=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStepLabel"}),{children:_,className:s,componentsProps:o={},error:a=!1,icon:d,optional:w,slots:v={},slotProps:f={},StepIconComponent:p,StepIconProps:z,...C}=i,{alternativeLabel:N,orientation:G}=u.useContext(Cn),{active:J,disabled:L,completed:I,icon:V}=u.useContext(Mn),X=d||V;let Y=p;X&&!Y&&(Y=Os);const ne={...i,active:J,alternativeLabel:N,completed:I,disabled:L,error:a,orientation:G},W=Ns(ne),Z={slots:v,slotProps:{stepIcon:z,...o,...f}},[ie,ue]=Wn("root",{elementType:Fs,externalForwardedProps:{...Z,...C},ownerState:ne,ref:r,className:sn(W.root,s)}),[ae,x]=Wn("label",{elementType:Gs,externalForwardedProps:Z,ownerState:ne}),[te,m]=Wn("stepIcon",{elementType:Y,externalForwardedProps:Z,ownerState:ne});return e.jsxs(ie,{...ue,children:[X||te?e.jsx(Hs,{className:W.iconContainer,ownerState:ne,children:e.jsx(te,{completed:I,active:J,error:a,icon:X,...m})}):null,e.jsxs(Us,{className:W.labelContainer,ownerState:ne,children:[_?e.jsx(ae,{...x,className:sn(W.label,x==null?void 0:x.className),children:_}):null,w]})]})});St.muiName="StepLabel";function Qs(n){return ln("MuiStepButton",n)}const it=cn("MuiStepButton",["root","horizontal","vertical","touchRipple"]),Ks=n=>{const{classes:t,orientation:r}=n;return un({root:["root",r],touchRipple:["touchRipple"]},Qs,t)},Js=Oe(Xt,{name:"MuiStepButton",slot:"Root",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[{[`& .${it.touchRipple}`]:t.touchRipple},t.root,t[r.orientation]]}})({width:"100%",padding:"24px 16px",margin:"-24px -16px",boxSizing:"content-box",[`& .${it.touchRipple}`]:{color:"rgba(0, 0, 0, 0.3)"},variants:[{props:{orientation:"vertical"},style:{justifyContent:"flex-start",padding:"8px",margin:"-8px"}}]}),Xs=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStepButton"}),{children:_,className:s,icon:o,optional:a,...d}=i,{disabled:w,active:v}=u.useContext(Mn),{orientation:f}=u.useContext(Cn),p={...i,orientation:f},z=Ks(p),C={icon:o,optional:a},N=fs(_,["StepLabel"])?u.cloneElement(_,C):e.jsx(St,{...C,children:_});return e.jsx(Js,{focusRipple:!0,disabled:w,TouchRippleProps:{className:z.touchRipple},className:sn(z.root,s),ref:r,ownerState:p,"aria-current":v?"step":void 0,...d,children:N})});function Ys(n){return ln("MuiStepConnector",n)}cn("MuiStepConnector",["root","horizontal","vertical","alternativeLabel","active","completed","disabled","line","lineHorizontal","lineVertical"]);const Zs=n=>{const{classes:t,orientation:r,alternativeLabel:i,active:_,completed:s,disabled:o}=n,a={root:["root",r,i&&"alternativeLabel",_&&"active",s&&"completed",o&&"disabled"],line:["line",`line${vt(r)}`]};return un(a,Ys,t)},er=Oe("div",{name:"MuiStepConnector",slot:"Root",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[t.root,t[r.orientation],r.alternativeLabel&&t.alternativeLabel,r.completed&&t.completed]}})({flex:"1 1 auto",variants:[{props:{orientation:"vertical"},style:{marginLeft:12}},{props:{alternativeLabel:!0},style:{position:"absolute",top:12,left:"calc(-50% + 20px)",right:"calc(50% + 20px)"}}]}),nr=Oe("span",{name:"MuiStepConnector",slot:"Line",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[t.line,t[`line${vt(r.orientation)}`]]}})(wn(({theme:n})=>{const t=n.palette.mode==="light"?n.palette.grey[400]:n.palette.grey[600];return{display:"block",borderColor:n.vars?n.vars.palette.StepConnector.border:t,variants:[{props:{orientation:"horizontal"},style:{borderTopStyle:"solid",borderTopWidth:1}},{props:{orientation:"vertical"},style:{borderLeftStyle:"solid",borderLeftWidth:1,minHeight:24}}]}})),tr=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStepConnector"}),{className:_,...s}=i,{alternativeLabel:o,orientation:a="horizontal"}=u.useContext(Cn),{active:d,disabled:w,completed:v}=u.useContext(Mn),f={...i,alternativeLabel:o,orientation:a,active:d,completed:v,disabled:w},p=Zs(f);return e.jsx(er,{className:sn(p.root,_),ref:r,ownerState:f,...s,children:e.jsx(nr,{className:p.line,ownerState:f})})});function sr(n){return ln("MuiStepper",n)}cn("MuiStepper",["root","horizontal","vertical","nonLinear","alternativeLabel"]);const rr=n=>{const{orientation:t,nonLinear:r,alternativeLabel:i,classes:_}=n;return un({root:["root",t,r&&"nonLinear",i&&"alternativeLabel"]},sr,_)},ar=Oe("div",{name:"MuiStepper",slot:"Root",overridesResolver:(n,t)=>{const{ownerState:r}=n;return[t.root,t[r.orientation],r.alternativeLabel&&t.alternativeLabel,r.nonLinear&&t.nonLinear]}})({display:"flex",variants:[{props:{orientation:"horizontal"},style:{flexDirection:"row",alignItems:"center"}},{props:{orientation:"vertical"},style:{flexDirection:"column"}},{props:{alternativeLabel:!0},style:{alignItems:"flex-start"}}]}),ir=e.jsx(tr,{}),or=u.forwardRef(function(t,r){const i=dn({props:t,name:"MuiStepper"}),{activeStep:_=0,alternativeLabel:s=!1,children:o,className:a,component:d="div",connector:w=ir,nonLinear:v=!1,orientation:f="horizontal",...p}=i,z={...i,nonLinear:v,alternativeLabel:s,orientation:f,component:d}
1,C=rr(z),N=u.Children.toArray(o).filter(Boolean),G=N.map((L,I)=>u.cloneElement(L,{index:I,last:I+1===N.length,...L.props})),J=u.useMemo(()=>({activeStep:_,alternativeLabel:s,connector:w,nonLinear:v,orientation:f}),[_,s,w,v,f]);return e.jsx(Cn.Provider,{value:J,children:e.jsx(ar,{as:d,ownerState:z,className:sn(C.root,a),ref:r,...p,children:G})})}),lr=Me(e.jsx("path",{d:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4m-7 7H3v4c0 1.1.9 2 2 2h4v-2H5zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2m0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2z"}),"CenterFocusStrong"),ot=Me(e.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"}),"CheckCircle"),cr=Me(e.jsx("path",{d:"M16.59 7.58 10 14.17l-3.59-3.58L5 12l5 5 8-8zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"}),"CheckCircleOutline"),dr=Me(e.jsx("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96M19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95C8.08 7.14 9.94 6 12 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11c1.56.1 2.78 1.41 2.78 2.96 0 1.65-1.35 3-3 3m-9-3.82-2.09-2.09L6.5 13.5 10 17l6.01-6.01-1.41-1.41z"}),"CloudDoneOutlined"),ur=Me(e.jsx("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96M19 18H6c-2.21 0-4-1.79-4-4 0-2.05 1.53-3.76 3.56-3.97l1.07-.11.5-.95C8.08 7.14 9.94 6 12 6c2.62 0 4.88 1.86 5.39 4.43l.3 1.5 1.53.11c1.56.1 2.78 1.41 2.78 2.96 0 1.65-1.35 3-3 3M8 13h2.55v3h2.9v-3H16l-4-4z"}),"CloudUploadOutlined"),lt=Me(e.jsx("path",{d:"M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"}),"ErrorOutline"),hr=Me(e.jsx("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5m0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5m0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5M7 19h14v-2H7zm0-6h14v-2H7zm0-8v2h14V5z"}),"FormatListBulleted"),vr=Me(e.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2m6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56M12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96M4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56m2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8M12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96M14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2m.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56M16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2z"}),"LanguageOutlined"),kt=Me(e.jsx("path",{d:"M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2M9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9zm9 14H6V10h12zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2"}),"LockOutlined"),It=Me(e.jsx("path",{d:"M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.89-2-2-2m0 16H5V7h14zm-7-8.5c1.84 0 3.48.96 4.34 2.5-.86 1.54-2.5 2.5-4.34 2.5s-3.48-.96-4.34-2.5c.86-1.54 2.5-2.5 4.34-2.5M12 9c-2.73 0-5.06 1.66-6 4 .94 2.34 3.27 4 6 4s5.06-1.66 6-4c-.94-2.34-3.27-4-6-4m0 5.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5"}),"PreviewOutlined"),_r=Me(e.jsx("path",{d:"M3 17v2h6v-2zM3 5v2h10V5zm10 16v-2h8v-2h-8v-2h-2v6zM7 9v2H3v2h4v2h2V9zm14 4v-2H11v2zm-6-4h2V7h4V5h-4V3h-2z"}),"Tune"),pr=Me([e.jsx("path",{d:"M23 11.99 20.56 9.2l.34-3.69-3.61-.82L15.4 1.5 12 2.96 8.6 1.5 6.71 4.69 3.1 5.5l.34 3.7L1 11.99l2.44 2.79-.34 3.7 3.61.82 1.89 3.2 3.4-1.47 3.4 1.46 1.89-3.19 3.61-.82-.34-3.69zm-3.95 1.48-.56.65.08.85.18 1.95-1.9.43-.84.19-.44.74-.99 1.68-1.78-.77-.8-.34-.79.34-1.78.77-.99-1.67-.44-.74-.84-.19-1.9-.43.18-1.96.08-.85-.56-.65L3.67 12l1.29-1.48.56-.65-.09-.86-.18-1.94 1.9-.43.84-.19.44-.74.99-1.68 1.78.77.8.34.79-.34 1.78-.77.99 1.68.44.74.84.19 1.9.43-.18 1.95-.08.85.56.65 1.29 1.47z"},"0"),e.jsx("path",{d:"m10.09 13.75-2.32-2.33-1.48 1.49 3.8 3.81 7.34-7.36-1.48-1.49z"},"1")],"VerifiedOutlined"),gr=Me(e.jsx("path",{d:"M12 6c3.79 0 7.17 2.13 8.82 5.5C19.17 14.87 15.79 17 12 17s-7.17-2.13-8.82-5.5C4.83 8.13 8.21 6 12 6m0-2C7 4 2.73 7.11 1 11.5 2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4m0 5c1.38 0 2.5 1.12 2.5 2.5S13.38 14 12 14s-2.5-1.12-2.5-2.5S10.62 9 12 9m0-2c-2.48 0-4.5 2.02-4.5 4.5S9.52 16 12 16s4.5-2.02 4.5-4.5S14.48 7 12 7"}),"VisibilityOutlined"),ct=n=>n==="use_simpler_wording"||n==="use_standard_wording",Pt=(n,t,r)=>{const i=r==="use_simpler_wording"?"simpler":"standard",_=n.presentationVariants.find(s=>s.kind===i&&(s.appliesToAllPathways||s.pathwayIds.includes(t.pathwayId)));if(!(!_||_.id===t.presentationVariantId))return{...t,presentationVariantId:_.id}};class xr{constructor(t){this.tail=Promise.resolve(),this.pending=0,this.onPendingChange=t}enqueue(t){var i;this.pending+=1,(i=this.onPendingChange)==null||i.call(this,this.pending);const r=this.tail.then(t,t);return this.tail=r.then(()=>this.finish(),()=>this.finish()),r}flush(){return this.tail}get hasPendingOperations(){return this.pending>0}finish(){var t;this.pending=Math.max(0,this.pending-1),(t=this.onPendingChange)==null||t.call(this,this.pending)}}const Rt=u.createContext(void 0),mr=n=>
1n.status===409||n.status===412||n.status===428||n.status===700,yr=({roomId:n,surveyId:t,versionLabel:r,initialVersion:i,children:_})=>{const{t:s}=Te(),o=s("enhanced_survey_error_parent_not_loaded"),[a,d]=u.useState([]),[w,v]=u.useState(),[f,p]=u.useState(),[z,C]=u.useState(),[N,G]=u.useState(),[J,L]=u.useState(!0),[I,V]=u.useState(!1),[X,Y]=u.useState(!1),[ne,W]=u.useState(!1),[Z,ie]=u.useState(0),[ue,ae]=u.useState(),[x,te]=u.useState(),m=u.useRef(void 0),T=u.useRef(void 0),ce=u.useRef(void 0),M=u.useRef(0),ee=u.useRef(0),q=u.useRef(0),B=u.useRef(0),P=u.useRef(void 0),le=u.useRef(void 0);le.current||(le.current=new xr(ie));const oe=le.current,j=u.useCallback((E,O)=>{if(m.current=E,v(E),O){const re=Ke(E.definition);T.current=re,p(re),ee.current=M.current,V(!1)}},[]),ke=u.useCallback(async()=>{L(!0),ae(void 0),P.current=void 0;try{const E=(i==null?void 0:i.roomId)===n&&i.surveyId===t&&i.version===r,[O,re,_e,De]=await Promise.all([In(n,t),E?Promise.resolve(i):Jn(n,t,r),Vt(n),$t(n)]),$e=De.find(He=>He.surveyId===t);if(!$e)throw new Ne(404,"",o);d(O),M.current=0,ee.current=0,q.current=0,B.current=0,j(re,!0),ce.current=$e.title,C($e.title),Y(!1),G(_e),te(void 0),W(!1)}catch(E){ae(pn(E))}finally{L(!1)}},[j,i,o,n,t,r]);u.useEffect(()=>{ke()},[ke]);const Ie=u.useCallback((E,O)=>{var _e;if(!T.current||((_e=m.current)==null?void 0:_e.status)!=="draft")return;const re=Ke(T.current);E(re),M.current+=1,T.current=re,p(re),V(!0),O!=null&&O.manualSave&&W(!0),ae(void 0)},[]),Ae=u.useCallback(E=>{var O;((O=m.current)==null?void 0:O.status)==="draft"&&(q.current+=1,ce.current=E,C(E),Y(!0),W(!0),ae(void 0))},[]),ye=u.useCallback(E=>{const O=pn(E);return ae(O),mr(O)&&(P.current=O,te({error:O}),O.status===412&&W(!0)),O},[]),Ce=u.useCallback(async()=>{const E=m.current,O=T.current,re=ce.current;if(!E||!O||re===void 0)return;if(E.status!=="draft")return E;const _e=Ke(O),De=re.trim(),$e=Rn(_e),He=$e||M.current!==ee.current,g=q.current!==B.current;if(!He&&!g)return await oe.flush(),m.current;if(P.current)throw P.current;$e&&(M.current+=1,T.current=_e,p(_e),V(!0));const b=M.current,D=q.current;return oe.enqueue(async()=>{if(P.current)throw P.current;const R=m.current;if(!(R!=null&&R.concurrencyToken)){const H=new Ne(428,"",s("enhanced_survey_error_missing_concurrency_token"));throw ye(H),H}try{let H=R;if(He){H=await zt(n,t,r,{roomId:n,surveyId:t,version:r,definition:_e,concurrencyToken:R.concurrencyToken}),ee.current=b;const h=M.current===b;j(H,h),V(!h)}if(g){const h=await Bt(n,t,{title:De});B.current=D;const $=q.current===D;$&&(ce.current=h.title,C(h.title)),Y(!$)}return M.current===ee.current&&q.current===B.current&&W(!1),ae(void 0),await Nn(n),H}catch(H){throw ye(H)}})},[j,oe,ye,n,t,s,r]),Le=u.useCallback(async()=>{await Ce(),await oe.flush()},[oe,Ce]),Pe=u.useCallback(async()=>{d(await In(n,t))},[n,t]),qe=u.useCallback(async E=>{if(await Le(),P.current)throw P.current;return oe.enqueue(async()=>{const O=m.current;if(!O)throw new Ne(404,"",s("enhanced_survey_error_version_not_loaded"));let re;try{re=await E(O)}catch(_e){throw ye(_e)}M.current+=1,ee.current=M.current,j(re,!0),re.status==="draft"||re.status==="in_review"||re.status==="approved"?ns(n,t,re.version,re.status):ts(t),ae(void 0);try{await Pe()}catch(_e){ae(pn(_e))}return await Nn(n),re})},[j,oe,Le,ye,Pe,n,t,s]),Ue=u.useCallback(async E=>{const O=T.current?Ke(T.current):void 0;L(!0);try{const re=await Jn(n,t,r);if(P.current=void 0,te(void 0),ae(void 0),m.current=re,v(re),E||!O){M.current+=1,ee.current=M.current;const _e=Ke(re.definition);T.current=_e,p(_e),V(!1),W(!1)}else T.current=O,p(O),M.current+=1,ee.current=M.current-1,V(!0),W(!0);d(await In(n,t))}catch(re){ae(pn(re))}finally{L(!1)}},[n,t,r]);u.useEffect(()=>{if(!I||ne||(w==null?void 0:w.status)!=="draft"||P.current)return;const E=window.setTimeout(()=>{Ce().catch(()=>{})},1500);return()=>window.clearTimeout(E)},[f,I,ne,Ce,w==null?void 0:w.status]);const Ve=I||X;u.useEffect(()=>{const E=O=>{var re;(Ve||(re=le.current)!=null&&re.hasPendingOperations)&&(O.preventDefault(),O.returnValue="")};return window.addEventListener("beforeunload",E),()=>window.removeEventListener("beforeunload",E)},[Ve]);const Ge=u.useMemo(()=>({roomId:n,surveyId:t,versionLabel:r,versions:a,version:w,definition:f,surveyTitle:z,capabilities:N,loading:J,dirty:Ve,requiresManualSave:ne,pendingMutations:Z,error:ue,conflict:x,editable:(w==null?void 0:w.status)==="draft"&&!x,updateDefinition:Ie,updateSurveyTitle:Ae,saveDraft:Ce,flush:Le,runMutation:qe,reloadLatest:Ue,refreshVersions:Pe,clearError:()=>ae(void 0)}
1),[N,x,f,Ve,ue,Le,J,Z,ne,Pe,Ue,n,qe,Ce,t,z,Ie,Ae,w,r,a]);return e.jsx(Rt.Provider,{value:Ge,children:_})},Ln=()=>{const n=u.useContext(Rt);if(!n)throw new Error("useEnhancedSurvey must be used within EnhancedSurveyProvider");return n},qt=({open:n,result:t,error:r,wordingControlPending:i=!1,onWordingControl:_,onClose:s})=>{const{t:o}=Te(),a=t==null?void 0:t.configuration;return e.jsxs(en,{open:n,onClose:s,fullScreen:!0,children:[e.jsxs(nn,{sx:{borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(k,{variant:"h5",component:"span",fontWeight:700,children:o("enhanced_survey_member_preview")}),e.jsx(Xe,{"aria-label":o("enhanced_survey_close"),onClick:s,sx:{position:"absolute",right:16,top:12},children:e.jsx(Fn,{})})]}),e.jsx(tn,{sx:{bgcolor:"#f5f7fb",py:4},children:e.jsxs(xe,{sx:{maxWidth:760,mx:"auto"},children:[r&&e.jsx(de,{severity:"error",sx:{mb:3},children:r}),!!(t!=null&&t.errors.length)&&e.jsx(y,{spacing:1,sx:{mb:3},children:t.errors.map(d=>e.jsx(de,{severity:"error",children:d.message},`${d.path}-${d.code}`))}),a&&!(t!=null&&t.errors.length)?e.jsxs(Se,{elevation:0,sx:{p:{xs:2,md:4},borderRadius:3},children:[e.jsx(y,{spacing:3,divider:e.jsx(Tn,{flexItem:!0}),children:[...a.blocks].sort((d,w)=>d.order-w.order).map(d=>{var v;const w=d.question?a.blocks.filter(f=>!!f.question).sort((f,p)=>f.order-p.order).findIndex(f=>f.id===d.id)+1:0;return e.jsxs(xe,{children:[e.jsx(k,{variant:d.type==="information"||d.type==="completion"?"h5":"h6",fontWeight:600,gutterBottom:!0,children:d.question?o("enhanced_survey_preview_question",{number:w,title:d.content}):d.content}),!!d.helpContent&&e.jsx(k,{color:"text.secondary",sx:{mb:2},children:d.helpContent}),((v=d.question)==null?void 0:v.responseType)==="free_text"&&e.jsx(K,{fullWidth:!0,multiline:!0,minRows:3,label:o("enhanced_survey_preview_response")}),d.question&&d.question.responseType!=="free_text"&&e.jsx(me,{children:d.question.responseType==="multiple_choice"?e.jsx(y,{children:d.question.choices.map((f,p)=>e.jsx(fe,{control:e.jsx(hn,{}),label:`${p+1}. ${f.content}`},f.id))}):e.jsx(bn,{children:d.question.choices.map((f,p)=>e.jsx(fe,{value:f.id,control:e.jsx(vn,{}),label:`${p+1}. ${f.content}`},f.id))})}),d.consent&&e.jsxs(y,{spacing:1,children:[e.jsx(k,{color:"text.secondary",children:d.consent.explanation}),e.jsxs(y,{direction:"row",spacing:1,children:[e.jsx(U,{variant:"contained",children:o("enhanced_survey_preview_consent_yes")}),e.jsx(U,{variant:"outlined",children:o("enhanced_survey_preview_consent_no")})]})]})]},d.id)})}),!!a.controls.length&&e.jsx(y,{direction:"row",flexWrap:"wrap",gap:1,sx:{mt:3},children:a.controls.map(d=>ct(d.action)&&_?e.jsx(U,{variant:"outlined",disabled:i,onClick:()=>{ct(d.action)&&_(d.action)},children:d.label},d.id):e.jsx(Fe,{label:d.label,variant:"outlined"},d.id))})]}):t!=null&&t.errors.length?null:e.jsx(de,{severity:"info",children:o("enhanced_survey_preview_not_loaded")})]})})]})},an=["setup","build","review"],fr=n=>{const t=n.pathways[0],r=t?n.presentationVariants.filter(s=>s.appliesToAllPathways||s.pathwayIds.includes(t.id)):[],i=r.find(s=>s.kind==="standard")??r[0],_=n.languages.find(s=>s.isSourceLanguage)??n.languages.find(s=>s.language===n.sourceLanguage)??n.languages[0];if(!(!t||!i||!_))return{pathwayId:t.id,presentationVariantId:i.id,language:_.language,deliveryMode:n.aiConfiguration.deliveryMode}},jr=({stage:n,children:t})=>{const{t:r,i18n:i}=Te(),_=Un(),{roomId:s,surveyId:o,versions:a,version:d,definition:w,loading:v,dirty:f,requiresManualSave:p,pendingMutations:z,error:C,conflict:N,saveDraft:G,flush:J,reloadLatest:L,clearError:I}=Ln(),V=Yt(Ot(s)),X=a.some(M=>M.status==="published"),[Y,ne]=u.useState(),[W,Z]=u.useState(!1),[ie,ue]=u.useState(!1),[ae,x]=u.useState(),te=async M=>{try{await J(),_(Dn(s,o,(d==null?void 0:d.version)??"",M))}catch{}},m=async M=>{try{await J(),_(M)}catch{}},T=async()=>{if(!w||ie)return;const M=fr(w);if(!M){ne(void 0),Z(!0);return}ue(!0),x(void 0);try{await J();const ee=await xn(s,o,d.version,M);ne(ee),Z(!0)}catch(ee){x(ee instanceof Error?ee.message:r("enhanced_survey_operation_failed"))}finally{ue(!1)}},ce=async M=>{var B;if(!w||ie)return;const ee=(B=Y==null?void 0:Y.configuration)==null?void 0:B.selection;if(!ee)return;const q=Pt(w,ee,M);if(q){ue(!0),x(void 0);try{ne(await xn(s,o,d.version,q))}catch(P){x(P instanceof Error?P.message:r("enhanced_survey_operation_failed"))}finally{ue(!1)}}};return v?e.jsx(xe,{display:"flex",minHeight:"65vh",alignItems:"center",justifyContent:"center",children:e.jsx(Je,{"aria-label":r("enhanced_survey_loading_builder")})}):d?e.jsxs(xe,{sx:{bgcolor:"#f5f7fb",minHeight:"100vh",pb:12},children:[e.jsx(Se,{square:!0,elevation:0,sx:{borderBottom:"1px solid",borderColor:"divider",position:"sticky",top:0,zIndex:10},children:e.jsx(gn,{maxWidth:"xl",sx:{py:2},children:e.jsxs(y,{spacing:2,children:[e.jsxs(y,{direction:{xs:"column",md:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",md:"center"},spacing:2,children:[e.jsxs(y,{direction:"row",spacing:1.5,alignItems:"center",children:[e.jsx(U,{startIcon:e.jsx(tt,{}),onClick:()=>void m(`/community/room/${encodeURIComponent(s)}`),children:r("enhanced_survey_back_to_surveys")}),e.jsxs(xe,{children:[e.jsx(k,{variant:"h5",component:"h1",fontWeight:700,children:r("enhanced_survey_enhanced_title")}),e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(Fe,{size:"small",color:d.status==="draft"?"primary":"default",label:r(`enhanced_survey_status_${d.status}`)}),e.jsx(k,{variant:"caption",color:"text.secondary",children:z>0?r("enhanced_survey_saving"):f?r("enhanced_survey_unsaved_changes"):r("enhanced_survey_saved_at",{time:new Intl.DateTimeFormat(i.language,{hour:"2-digit",minute:"2-digit"}).format(new Date(d.updatedAt))})})]})]})]}),e.jsxs(y,{spacing:1,alignItems:"flex-end",children:[e.jsxs(y,{direction:"row",spacing:1.5,alignItems:"center",children:[e.jsxs(me,{size:"small",sx:{minWidth:180},children:[e.jsx(je,{children:r("enhanced_survey_version_selector")}),e.jsx(be,{label:r("enhanced_survey_version_selector"),value:d.version,onChange:M=>void m(Dn(s,o,M.target.value,n)),children:a.map(M=>e.jsxs(ge,{value:M.version,children:[M.version," ·"," ",r(`enhanced_survey_status_${M.status}`),M.publishedAt?` · ${new Intl.DateTimeFormat(i.language,{dateStyle:"medium"}).format(new Date(M.publishedAt))}`:""]},M.id))})]}),d.status!=="draft"&&e.jsx(U,{startIcon:e.jsx(Kn,{}),onClick:()=>_(ss(s,o)),children:r("enhanced_survey_create_version")}),e.jsx(U,{startIcon:ie?e.jsx(Je,{size:16}):e.jsx(It,{}),disabled:ie||z>0||!!N,onClick:()=>void T(),children:r(ie?"enhanced_survey_loading_preview":"enhanced_survey_preview")})]}),V&&X&&e.jsx(js,{roomId:s,surveyId:o,surveyTitle:r("enhanced_survey_enhanced_title"),triggerLabelKey:"enhanced_survey_delete_published",warningLabelKey:"enhanced_survey_delete_published_warning",onDeleted:async()=>{await Nn(s),_(`/community/room/${encodeURIComponent(s)}`)}})]})]}),e.jsx(or,{activeStep:an.indexOf(n),alternativeLabel:!0,children:an.map((M,ee)=>e.jsx(Ws,{completed:d.status==="published"||an.indexOf(n)>
1ee,children:e.jsx(Xs,{"aria-current":M===n?"step":void 0,onClick:()=>void te(M),sx:{'&[aria-current="step"] .MuiStepIcon-root':{borderRadius:"50%",outline:"2px solid",outlineColor:"info.light",outlineOffset:"3px"}},children:r(`enhanced_survey_step_${M}`)})},M))})]})})}),e.jsxs(gn,{maxWidth:"xl",sx:{pt:3},children:[N&&e.jsxs(de,{severity:"warning",sx:{mb:3},children:[e.jsx(k,{variant:"h6",children:r("enhanced_survey_concurrency_title")}),e.jsx(k,{sx:{mb:2},children:r("enhanced_survey_concurrency_description")}),e.jsxs(y,{direction:{xs:"column",sm:"row"},spacing:1,children:[e.jsx(U,{variant:"contained",onClick:()=>void L(!0),children:r("enhanced_survey_reload_latest")}),e.jsx(U,{variant:"outlined",onClick:()=>void L(!1),children:r("enhanced_survey_review_unsaved_changes")})]})]}),p&&!N&&e.jsx(de,{severity:"info",sx:{mb:3},children:r("enhanced_survey_manual_save_required")}),C&&!N&&e.jsx(de,{severity:C.status===403?"warning":"error",onClose:I,sx:{mb:3},children:C.message}),ae&&e.jsx(de,{severity:"error",onClose:()=>x(void 0),sx:{mb:3},children:ae}),d.status!=="draft"&&e.jsx(de,{icon:e.jsx(cr,{}),severity:"info",sx:{mb:3},children:r("enhanced_survey_read_only_status",{status:r(`enhanced_survey_status_${d.status}`)})}),t]}),e.jsx(Se,{elevation:8,sx:{position:"fixed",bottom:0,left:0,right:0,zIndex:9,borderTop:"1px solid",borderColor:"divider"},children:e.jsx(gn,{maxWidth:"xl",sx:{py:1.5},children:e.jsxs(y,{direction:"row",alignItems:"center",justifyContent:"space-between",children:[e.jsx(U,{disabled:n==="setup",onClick:()=>void te(an[an.indexOf(n)-1]),children:r("enhanced_survey_back")}),e.jsxs(y,{direction:"row",spacing:1.5,children:[d.status==="draft"&&e.jsx(U,{variant:"outlined",startIcon:z>0?e.jsx(ur,{}):e.jsx(dr,{}),disabled:z>0||!!N,onClick:()=>void G(),children:z>0?r("enhanced_survey_saving"):r("enhanced_survey_save_draft")}),n!=="review"&&e.jsx(U,{variant:"contained",onClick:()=>void te(an[an.indexOf(n)+1]),children:r(n==="build"?"enhanced_survey_review_survey":"enhanced_survey_continue")})]})]})})}),e.jsx(qt,{open:W,result:Y,error:ae,wordingControlPending:ie,onWordingControl:M=>void ce(M),onClose:()=>Z(!1)})]}):e.jsx(gn,{maxWidth:"md",sx:{py:8},children:e.jsxs(de,{severity:(C==null?void 0:C.status)===403?"warning":"error",children:[e.jsx(k,{variant:"h6",gutterBottom:!0,children:(C==null?void 0:C.status)===403?r("enhanced_survey_moderator_required"):r("enhanced_survey_load_failed")}),e.jsx(k,{children:C==null?void 0:C.message}),e.jsx(U,{startIcon:e.jsx(tt,{}),onClick:()=>_(`/community/room/${encodeURIComponent(s)}`),sx:{mt:2},children:r("enhanced_survey_back_to_surveys")})]})})},we=({label:n,children:t})=>e.jsx(xe,{role:"group","aria-label":n,sx:{bgcolor:"rgba(34, 116, 86, 0.07)",border:"1px solid rgba(34, 116, 86, 0.22)",borderRadius:2,p:2},children:e.jsxs(y,{spacing:1.5,children:[e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(gr,{color:"success",fontSize:"small"}),e.jsx(k,{variant:"subtitle2",color:"success.dark",sx:{letterSpacing:0},children:n})]}),t]})}),br="generative_ai_help",Et=10,wr=n=>{var i;const t=n.blocks??[],[r]=t;return t.length===1&&r.type==="information"&&n.aiConfiguration.standardToSimplerEnabled===!1&&((i=n.completion)==null?void 0:i.blockId)===r.id},Cr=(n,t)=>{var z,C,N,G,J,L,I,V,X,Y,ne;n.messageBundle.controls.forEach(W=>{W.deliveryModes.includes(t)||W.deliveryModes.push(t)});const r=n.aiConfiguration;r.deliveryMode=t;const i=t===br;if(r.generativeClarificationEnabled=i,r.answerQualityCheckEnabled=i,r.answeringSupportAssessmentEnabled=!1,r.defaults.generatedClarificationEnabled=i,r.defaults.answerQualityCheckEnabled=i,r.defaults.shortAnswerCheckEnabled=i,(z=r.defaults).minimumWordCount??(z.minimumWordCount=Et),r.defaults.unclearAnswerCheckEnabled=i,r.defaults.clarificationTurnLimit=i?2:0,Object.values(r.overrides).forEach(W=>{delete W.generatedClarificationEnabled,delete W.answerQualityCheckEnabled,delete W.shortAnswerCheckEnabled,delete W.minimumWordCount,delete W.unclearAnswerCheckEnabled,delete W.clarificationTurnLimit}),!i){r.liveAIProfile=void 0,r.liveCapabilities=[];return}const _=wr(n),s=n.aiArtifacts,o=(C=s==null?void 0:s.profiles)==null?void 0:C[0],a=(G=(N=o==null?void 0:o.definition)==null?void 0:N.capabilities)==null?void 0:G.find(W=>W.capability==="generate_question_clarification"),d=(L=(J=o==null?void 0:o.definition)==null?void 0:J.capabilities)==null?void 0:L.find(W=>W.capability==="assess_free_text_short"),w=(V=(I=o==null?void 0:o.definition)==null?void 0:I.capabilities)==null?void 0:V.find(W=>W.capability==="assess_free_text_unclear"),v=(X=n.messageBundle.messages.find(W=>W.kind==="generated_help_unavailable"))==null?void 0:X.contentId,f=(Y=n.messageBundle.messages.find(W=>W.kind==="short_answer_check"))==null?void 0:Y.contentId,p=(ne=n.messageBundle.messages.find(W=>W.kind==="unclear_answer_check"))==null?void 0:ne.contentId;
1if(!(o!=null&&o.reference)||!(a!=null&&a.outputSchema)||!v||!_&&(!(d!=null&&d.outputSchema)||!(w!=null&&w.outputSchema)||!f||!p))throw new Error("enhanced_survey_delivery_mode_artifacts_missing");r.liveAIProfile=o.reference,r.liveCapabilities=[{capability:"generate_question_clarification",outputSchema:a.outputSchema,fixedFallbackContentId:v},..._?[]:[{capability:"assess_free_text_short",outputSchema:d.outputSchema,fixedFallbackContentId:f},{capability:"assess_free_text_unclear",outputSchema:w.outputSchema,fixedFallbackContentId:p}]]},dt=["answerQualityCheckEnabled","shortAnswerCheckEnabled","minimumWordCount","unclearAnswerCheckEnabled"],Sr=[{kind:"short_answer_check",value:"Please add a little more detail about how this answer relates to the question."},{kind:"unclear_answer_check",value:"Please clarify how this answer relates to the question."}],ut=n=>{Sr.forEach(({kind:t,value:r})=>{n.messageBundle.messages.some(i=>i.kind===t)||n.messageBundle.messages.push({kind:t,contentId:gt(n,r)})})},Tt=({block:n,definition:t,language:r,capabilities:i,editable:_,updateDefinition:s})=>{var ae;const{t:o}=Te(),[a,d]=u.useState(!1),w=t.aiConfiguration.overrides[n.id]??{},v={...t.aiConfiguration.defaults,...w},f=Object.keys(w).length>0,p=t.aiConfiguration.deliveryMode==="generative_ai_help"&&t.aiConfiguration.generativeClarificationEnabled,z=p,C=t.aiConfiguration.standardToSimplerEnabled&&t.presentationVariants.some(x=>x.kind==="simpler"),N=(i==null?void 0:i.limits.minimumClarificationTurns)??1,G=(i==null?void 0:i.limits.maximumClarificationTurns)??5,J=(i==null?void 0:i.limits.defaultMinimumAnswerWords)??Et,L=(i==null?void 0:i.limits.minimumAnswerWords)??1,I=(i==null?void 0:i.limits.maximumAnswerWords)??100,V=v.minimumWordCount??J,Y=dt.some(x=>Object.prototype.hasOwnProperty.call(w,x))?v.answerQualityCheckEnabled&&v.shortAnswerCheckEnabled&&v.unclearAnswerCheckEnabled&&V===J?"descriptive":!v.answerQualityCheckEnabled&&!v.shortAnswerCheckEnabled&&!v.unclearAnswerCheckEnabled?"concise":"custom":"survey_default",ne=a?"custom":Y,W=`answer-validation-${n.id}`,Z=(x,te)=>s(m=>{const T={...m.aiConfiguration.overrides[n.id]??{},[x]:te};if(te===!0&&(x==="answerQualityCheckEnabled"||x==="shortAnswerCheckEnabled"||x==="unclearAnswerCheckEnabled")&&(m.aiConfiguration.answerQualityCheckEnabled=!0,ut(m)),te===!0&&(x==="shortAnswerCheckEnabled"||x==="unclearAnswerCheckEnabled")&&(T.answerQualityCheckEnabled=!0),te===!1&&(x==="shortAnswerCheckEnabled"||x==="unclearAnswerCheckEnabled")){const M=x==="shortAnswerCheckEnabled"?!1:T.shortAnswerCheckEnabled??m.aiConfiguration.defaults.shortAnswerCheckEnabled,ee=x==="unclearAnswerCheckEnabled"?!1:T.unclearAnswerCheckEnabled??m.aiConfiguration.defaults.unclearAnswerCheckEnabled;T.answerQualityCheckEnabled=M||ee}x==="answerQualityCheckEnabled"&&te===!1&&(T.shortAnswerCheckEnabled=!1,T.unclearAnswerCheckEnabled=!1),m.aiConfiguration.overrides[n.id]=T}),ie=x=>{d(x==="custom"),x!=="custom"&&s(te=>{const m={...te.aiConfiguration.overrides[n.id]??{}};if(x==="survey_default")dt.forEach(T=>delete m[T]);else{const T=x==="descriptive";m.answerQualityCheckEnabled=T,m.shortAnswerCheckEnabled=T,m.unclearAnswerCheckEnabled=T,T?(m.minimumWordCount=J,te.aiConfiguration.answerQualityCheckEnabled=!0,ut(te)):delete m.minimumWordCount}Object.keys(m).length===0?delete te.aiConfiguration.overrides[n.id]:te.aiConfiguration.overrides[n.id]=m})},ue=(x,te)=>s(m=>{const T={...m.aiConfiguration.overrides[n.id]??{}};let ce=T[x];if(!ce){const M=m.aiConfiguration.defaults[x];ce=gt(m,ve(m,m.sourceLanguage,M)),T[x]=ce}m.aiConfiguration.overrides[n.id]=T,mn(m,r,ce,te)});return e.jsxs(y,{spacing:2,children:[e.jsxs(y,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(k,{variant:"subtitle2",children:o(f?"enhanced_survey_question_overrides_active":"enhanced_survey_uses_survey_defaults")}),f&&_&&e.jsx(U,{size:"small",onClick:()=>s(x=>{delete x.aiConfiguration.overrides[n.id]}),children:o("enhanced_survey_reset_to_defaults")})]}),e.jsx(we,{label:o("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,minRows:2,label:o("enhanced_survey_approved_help_content"),value:ve(t,r,v.approvedHelpContentId),disabled:!_,onChange:x=>ue("approvedHelpContentId",x.target.value)})}),e.jsxs(me,{fullWidth:!0,disabled:!_,children:[e.jsx(je,{children:o("enhanced_survey_repeat_behavior")}),e.jsx(be,{label:o("enhanced_survey_repeat_behavior"),value:v.repeatBehavior,onChange:x=>Z("repeatBehavior",x.target.value),children:((i==null?void 0:i.repeatBehaviors)??[v.repeatBehavior]).map(x=>e.jsx(ge,{value:x,children:o(`enhanced_survey_repeat_${x}`)},x))})]}),!p&&e.jsx(de,{severity:"info",children:o("enhanced_survey_generative_controls_disabled")}),e.jsx(fe,{control:e.jsx(Ye,{checked:v.generatedClarificationEnabled,disabled:!_||!p,onChange:x=>Z("generatedClarificationEnabled",x.target.checked)}),label:o("enhanced_survey_generated_clarification")}),((ae=n.question)==null?void 0:ae.responseType)==="free_text"&&e.jsxs(e.Fragment,{children:[e.jsxs(me,{fullWidth:!0,disabled:!_||!z,children:[e.jsx(je,{id:W,children:o("enhanced_survey_answer_validation")}),e.jsxs(be,{labelId:W,label:o("enhanced_survey_answer_validation"),value:ne,onChange:x=>ie(x.target.value),children:[e.jsx(ge,{value:"survey_default",children:o("enhanced_survey_answer_validation_default")}),e.jsx(ge,{value:"descriptive",children:o("enhanced_survey_answer_validation_descriptive")}
1),e.jsx(ge,{value:"concise",children:o("enhanced_survey_answer_validation_concise")}),e.jsx(ge,{value:"custom",children:o("enhanced_survey_answer_validation_custom")})]})]}),ne==="custom"&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{control:e.jsx(Ye,{checked:v.shortAnswerCheckEnabled,disabled:!_||!z,onChange:x=>Z("shortAnswerCheckEnabled",x.target.checked)}),label:o("enhanced_survey_minimum_word_check")}),v.shortAnswerCheckEnabled&&e.jsx(K,{fullWidth:!0,type:"number",label:o("enhanced_survey_minimum_words"),value:V,disabled:!_||!z,inputProps:{min:L,max:I},onChange:x=>Z("minimumWordCount",Math.max(L,Math.min(I,Number(x.target.value))))}),e.jsx(fe,{control:e.jsx(Ye,{checked:v.unclearAnswerCheckEnabled,disabled:!_||!z,onChange:x=>Z("unclearAnswerCheckEnabled",x.target.checked)}),label:o("enhanced_survey_clarity_relevance_check")})]})]}),e.jsx(fe,{control:e.jsx(Ye,{checked:v.standardToSimplerEnabled,disabled:!_||!C,onChange:x=>Z("standardToSimplerEnabled",x.target.checked)}),label:o("enhanced_survey_standard_to_simpler")}),e.jsx(K,{fullWidth:!0,type:"number",label:o("enhanced_survey_clarification_turn_limit"),value:v.clarificationTurnLimit,disabled:!_||!p,inputProps:{min:N,max:G},onChange:x=>Z("clarificationTurnLimit",Math.max(N,Math.min(G,Number(x.target.value))))})]})},kr=[{kind:"short_answer_check",label:"enhanced_survey_short_answer_message"},{kind:"unclear_answer_check",label:"enhanced_survey_unclear_answer_message"}],Ir=({definition:n,language:t,editable:r,translating:i,onTranslateMissing:_,updateDefinition:s})=>{const{t:o}=Te(),a=kr.flatMap(v=>{const f=n.messageBundle.messages.find(p=>p.kind===v.kind);return f?[{...v,contentId:f.contentId}]:[]});if(!a.length)return null;const d=n.languages.find(v=>v.language===t),w=!!d&&!d.isSourceLanguage&&a.some(v=>{var f;return!((f=d.content[v.contentId])!=null&&f.value.trim())});return e.jsx(we,{label:o("enhanced_survey_quality_messages"),children:e.jsxs(y,{spacing:2,children:[w&&e.jsx(de,{severity:"warning",action:e.jsx(U,{color:"inherit",disabled:!r||i,onClick:_,children:o("enhanced_survey_translate_missing_quality_messages")}),children:o("enhanced_survey_missing_quality_messages")}),a.map(v=>e.jsx(K,{id:`enhanced-survey-content-${v.contentId}`,fullWidth:!0,required:!0,multiline:!0,minRows:2,label:o(v.label),value:ve(n,t,v.contentId),disabled:!r,onChange:f=>s(p=>mn(p,t,v.contentId,f.target.value))},v.kind))]})})},Mt=({definition:n,language:t,pathwayId:r,variantId:i,selectedBlockId:_,onLanguageChange:s,onPathwayChange:o,onVariantChange:a,onBlockChange:d,content:w,properties:v,languageActions:f,contextReview:p,showSourceReviewStatus:z=!1,editable:C=!1,maxBlocks:N=Number.MAX_SAFE_INTEGER,onAddBlock:G,onMoveBlock:J})=>{const{t:L}=Te(),I=Dt(),V=Zt(I.breakpoints.down("lg")),[X,Y]=u.useState(!1),[ne,W]=u.useState(!1),Z=u.useMemo(()=>qn(n.blocks),[n.blocks]),ie=n.blocks.find(m=>m.id===_),ue=xt(ie),ae=m=>{const T=En(m,r,i);return ve(n,t,T==null?void 0:T.contentId).trim()||L(`enhanced_survey_block_${m.type}`)},x=(m=!1)=>e.jsxs(Se,{elevation:0,square:m,sx:{borderRadius:m?0:3,height:"100%",overflow:"auto"},children:[e.jsx(xe,{sx:{p:2,borderBottom:"1px solid",borderColor:"divider"},children:e.jsxs(y,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(k,{variant:"h6",fontWeight:700,children:L("enhanced_survey_structure")}),e.jsxs(y,{direction:"row",spacing:.5,alignItems:"center",children:[C&&G&&e.jsx(U,{size:"small",startIcon:e.jsx(Kn,{}),disabled:n.blocks.length>=N,onClick:G,children:L("enhanced_survey_add_question")}),m&&e.jsx(Xe,{"aria-label":L("enhanced_survey_close"),onClick:()=>Y(!1),children:e.jsx(Fn,{})})]})]})}),e.jsx(Pn,{disablePadding:!0,children:Z.map((T,ce)=>{const M=An(n,T),ee=En(T,r,i),q=!ve(n,t,ee==null?void 0:ee.contentId).trim();return e.jsxs(bt,{selected:T.id===_,onClick:()=>{d(T.id),Y(!1)},sx:{borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(Gn,{primary:`${ce+1}. ${ae(T)}`,secondary:q?L("enhanced_survey_incomplete"):z&&(ee==null?void 0:ee.sourceReview.status)==="pending"?L("enhanced_survey_source_pending"):void 0,primaryTypographyProps:{noWrap:!0},secondaryTypographyProps:{color:q?"error":"warning.main"}}),M?e.jsx(ms,{title:L("enhanced_survey_required_block_locked"),children:e.jsx(kt,{"aria-label":L("enhanced_survey_required_block_locked"),color:"action",fontSize:"small"})}):C&&J?e.jsxs(y,{children:[e.jsx(Xe,{size:"small",disabled:ce===0||An(n,Z[ce-1]),"aria-label":L("enhanced_survey_move_up"),onClick:B=>{B.stopPropagation(),J(T.id,-1)},children:e.jsx(wt,{fontSize:"small"})}),e.jsx(Xe,{size:"small",disabled:ce===Z.length-1||An(n,Z[ce+1]),"aria-label":L("enhanced_survey_move_down"),onClick:B=>{B.stopPropagation(),J(T.id,1)},children:e.jsx(Ct,{fontSize:"small"})})]}):null]},T.id)})})]}),te=(m=!1)=>e.jsxs(Se,{elevation:0,square:m,sx:{p:2.5,borderRadius:m?0:3,height:"100%",overflow:"auto"},children:[m&&e.jsx(xe,{sx:{display:"flex",justifyContent:"flex-end",mb:1},children:e.jsx(Xe,{"aria-label":L("enhanced_survey_close"),onClick:()=>W(!1),children:e.jsx(Fn,{})})}),v]});return e.jsxs(y,{spacing:2,children:[e.jsx(Se,{elevation:0,sx:{p:2,borderRadius:3},children:e.jsxs(y,{spacing:2,children:[e.jsxs(y,{direction:{xs:"column",lg:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",lg:"center"},spacing:2,children:[e.jsx(xe,{sx:{minWidth:0,flex:1},children:e.jsx(gs,{value:t,onChange:(m,T)=>s(T),variant:"scrollable",scrollButtons:"auto","aria-label":L("enhanced_survey_language_tabs"),children:n.languages.map(m=>e.jsx(xs,{value:m.language,label:`${m.language} · ${L(`enhanced_survey_language_status_${m.approval.status}`)}`},m.language))})}),f]}),n.pathways.length>1&&!ue&&e.jsxs(me,{size:"small",sx:{maxWidth:360},children:[e.jsx(je,{children:L("enhanced_survey_pathway")}),e.jsx(be,{label:L("enhanced_survey_pathway"),value:r,onChange:m=>o(m.target.value),children:n.pathways.map(m=>e.jsx(ge,{value:m.id,children:m.name},m.id))})]}),e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",flexWrap:"wrap",children:[e.jsx(k,{variant:"subtitle2",children:L("enhanced_survey_wording_options")}),ue?e.jsx(Fe,{label:L("enhanced_survey_global")}):n.presentationVariants.filter(m=>m.appliesToAllPathways||m.pathwayIds.includes(r)).map(m=>e.jsx(Fe,{clickable:!0,color:m.id===i?"primary":"default",variant:m.id===i?"filled":"outlined",label:L(`enhanced_survey_variant_${m.kind}`),onClick:()=>a(m.id)},m.id))]}),p]})}),V?e.jsxs(y,{spacing:2,children:[e.jsxs(y,{direction:"row",spacing:1,children:[e.jsx(U,{variant:"outlined",startIcon:e.jsx(hr,{}),onClick:()=>Y(!0),children:L("enhanced_survey_structure")}),e.jsx(U,{variant:"outlined",startIcon:e.jsx(_r,{}),onClick:()=>W(!0),children:L("enhanced_survey_properties")})]}),e.jsx(Se,{elevation:0,sx:{p:{xs:2,md:3},borderRadius:3,minHeight:520},children:w}),e.jsx(nt,{anchor:"left",open:X,onClose:()=>Y(!1),children:e.jsx(xe,{sx:{width:{xs:"88vw",sm:380},height:"100%"},children:x(!0)})}),e.jsx(nt,{anchor:"right",open:ne,onClose:()=>W(!1),children:e.jsx(xe,{sx:{width:{xs:"88vw",sm:420},height:"100%"},children:te(!0)})})]}):e.jsxs(se,{container:!0,spacing:2,alignItems:"stretch",children:[e.jsx(se,{item:!0,xs:3,children:x()}),e.jsx(se,{item:!0,xs:6,children:e.jsx(Se,{elevation:0,sx:{p:3,borderRadius:3,minHeight:520},children:w})}),e.jsx(se,{item:!0,xs:3,children:te()})]})]})},_n=()=>({open:!1,content:"",helpText:"",sourceReference:"",questionResponseType:"",questionRequired:"",questionNonAnswerMode:"",questionAllowedNonAnswers:[]}),Pr=()=>{const{i18n:n,t}=Te(),r=Qn(),i=_t(),{roomId:_,definition:s,version:o,capabilities:a,editable:d,pendingMutations:w,updateDefinition:v,runMutation:f}=Ln(),[p,z]=u.useState(""),[C,N]=u.useState(""),[G,J]=u.useState(""),[L,I]=u.useState(""),[V,X]=u.useState(_n),[Y,ne]=u.useState(!1),[W,Z]=u.useState(""),[ie,ue]=u.useState(!1),[ae,x]=u.useState(),[te,m]=u.useState(!1),[T,ce]=u.useState(""),[M,ee]=u.useState(""),[q,B]=u.useState(""),P=u.useRef(""),le=u.useRef(void 0),oe=u.useMemo(()=>qn((s==null?void 0:s.blocks)??[]),[s==null?void 0:s.blocks]);if(u.useEffect(()=>{var g,b,D;if(s){if(le.current!==s){le.current=s;const R=JSON.parse(JSON.stringify(s));if(Rn(R)){v(Rn);return}}if(s.languages.some(R=>R.language===p)||z(s.sourceLanguage),s.pathways.some(R=>R.id===C)||N(((g=s.pathways[0])==null?void 0:g.id)??""),!s.presentationVariants.some(R=>R.id===G)){const R=s.presentationVariants.find(H=>H.kind==="standard");J((R==null?void 0:R.id)??((b=s.presentationVariants[0])==null?void 0:b.id)??"")}s.blocks.some(R=>R.id===L)||I(((D=oe[0])==null?void 0:D.id)??"")}},[s,p,C,L,oe,v,G]),u.useEffect(()=>{var Q,he;const g=(Q=r.state)==null?void 0:Q.validationPath;if(!s||!g||P.current===g)return;P.current=g;const b=s.blocks.find(We=>g.includes(We.id)),D=(he=g.match(/content\.([^.]+)\.value/i))==null?void 0:he[1],R=D?is(s,D):void 0,H=g.match(/blocks\[(\d+)\]/i),c=H?oe[Number(H[1])]:void 0,h=b??(R==null?void 0:R.block)??c;h&&(I(h.id),R!=null&&R.pathwayId&&N(R.pathwayId),R!=null&&R.presentationVariantId&&J(R.presentationVariantId));const $=s.languages.find(We=>g.includes(We.language));$&&z($.language),D&&B(D)},[s,r.state,oe]),u.useEffect(()=>{q&&window.requestAnimationFrame(()=>{const g=document.getElementById(`enhanced-survey-content-${q}`);
1g==null||g.focus(),g&&B("")})},[p,q]),!s||!o)return null;const j=s.blocks.find(g=>g.id===L),ke=j?En(j,C,G):void 0,Ie=s.languages.find(g=>g.language===p),Ae=g=>Object.fromEntries(s.languages.map(b=>[b.language,String(n.getFixedT(b.language)(`enhanced_survey_non_answer_${g}`))])),ye=g=>{j&&v(b=>{const D=b.blocks.find(R=>R.id===j.id);D&&g(D,b),Rn(b)})},Ce=(g,b)=>{g&&v(D=>mn(D,p,g,b))},Le=()=>!!j&&ds(s,j.id,(a==null?void 0:a.structure.minimumBlocks)??1),Pe=!!V.questionResponseType&&!!V.questionRequired&&!!V.questionNonAnswerMode&&(V.questionNonAnswerMode==="none"||V.questionAllowedNonAnswers.length>0),qe=!!V.content.trim()&&!!V.sourceReference.trim()&&Pe,Ue=async()=>{var g,b;if(!(!j||!Le())&&await i({title:t("enhanced_survey_remove_block_title"),description:t("enhanced_survey_remove_block_description"),isDestructive:!0,okLabel:t("enhanced_survey_remove")})){const D=oe.findIndex(H=>H.id===j.id),R=((g=oe[D+1])==null?void 0:g.id)??((b=oe[D-1])==null?void 0:b.id)??"";v(H=>cs(H,j.id)),I(R)}},Ve=()=>{if(!qe)return;let g="";v(b=>{g=ls(b,"question",C,V.sourceReference.trim(),V.content.trim(),{helpText:V.helpText.trim(),question:{responseType:V.questionResponseType,required:V.questionRequired==="yes",allowedNonAnswers:V.questionNonAnswerMode==="selected"?V.questionAllowedNonAnswers.map(D=>({outcome:D,labels:Ae(D)})):[]}})}),z(s.sourceLanguage),I(g),X(_n())},Ge=()=>{if(!T.trim()||!M.trim())return;let g="";v(b=>{g=ft(b,T,M.trim())??""}),g&&J(g),m(!1),ce(""),ee("")},E=async g=>{j!=null&&j.question&&(g==="free_text"&&j.question.choices.length>0&&!await i({title:t("enhanced_survey_change_to_free_text_title"),description:t("enhanced_survey_change_to_free_text_description"),isDestructive:!0,okLabel:t("enhanced_survey_continue")})||ye((b,D)=>{if(b.question)if(b.question.responseType=g,g==="free_text")b.question.choices=[];else{if(g==="multiple_choice"&&b.question.choices.forEach(H=>{H.requiresFreeText=void 0}),b.question.choices.length>0)return;const R=b.question.sourceReview.sourceReference;Vn(D,b,R),Vn(D,b,R)}}))},O=(g,b)=>ye((D,R)=>{var c;const H=(c=D.question)==null?void 0:c.choices.find(h=>h.id===g);H&&b(H,R)}),re=(g,b)=>ye(D=>{var $;const R=($=D.question)==null?void 0:$.choices;if(!R)return;const H=R.findIndex(Q=>Q.id===g),c=H+b;if(H<0||c<0||c>=R.length)return;const[h]=R.splice(H,1);R.splice(c,0,h)}),_e=async(g=!1)=>{var D,R;const b=g?p:W;if(!(!b||!o.concurrencyToken)&&!(g&&!await i({title:t("enhanced_survey_regenerate_language_title"),description:t("enhanced_survey_regenerate_language_description"),isDestructive:!1,okLabel:t("enhanced_survey_regenerate")}))){x(void 0),ne(!1),ue(!0);try{const H=await f(c=>{if(!c.concurrencyToken)throw new Ne(428,"",t("enhanced_survey_error_missing_concurrency_token"));return Nt(_,c.surveyId,c.version,{concurrencyToken:c.concurrencyToken,targetLanguage:b})});z(b),J(((D=H.definition.presentationVariants.find(c=>c.kind==="standard"))==null?void 0:D.id)??((R=H.definition.presentationVariants[0])==null?void 0:R.id)??""),Z("")}catch(H){x(H instanceof Error?H.message:t("enhanced_survey_operation_failed"))}finally{ue(!1)}}},De=((a==null?void 0:a.supportedLanguages)??[]).filter(g=>!s.languages.some(b=>b.language===g)),$e=()=>{const g=j?mt(j,s.blocks):void 0;if(g)return e.jsx(de,{severity:"error",children:t(g)});if(!j||!ke)return e.jsx(de,{severity:"warning",children:t("enhanced_survey_presentation_missing")});const b=ve(s,p,ke.contentId),D=ve(s,p,ke.helpContentId),R=rn(j),c=xt(j)||j.type==="consent"?t("enhanced_survey_prompt"):j.type==="completion"?t("enhanced_survey_completion_message"):j.type==="question"?t("enhanced_survey_question_text"):t("enhanced_survey_block_content");return e.jsxs(y,{spacing:2.5,children:[e.jsx(xe,{children:e.jsx(k,{variant:"h5",fontWeight:700,children:t(`enhanced_survey_block_${j.type}`)})}),e.jsxs(we,{label:t("enhanced_survey_member_visible_content"),children:[e.jsx(K,{id:`enhanced-survey-content-${ke.contentId}`,inputProps:{"data-primary-content":"true"},fullWidth:!0,required:!0,multiline:!0,minRows:3,label:c,value:b,disabled:!d,onChange:h=>Ce(ke.contentId,h.target.value)}),ke.helpContentId&&e.jsx(K,{fullWidth:!0,multiline:!0,minRows:2,label:t("enhanced_survey_help_text"),value:D,disabled:!d,onChange:h=>Ce(ke.helpContentId,h.target.value)})]}),j.type==="consent"&&j.consent&&e.jsx(Rr,{block:j,definition:s,language:p,editable:d,onContentChange:Ce}),(j.type==="question"||j.type==="wording_selection")&&j.question&&e.jsxs(e.Fragment,{children:[e.jsxs(me,{disabled:!d||rn(j),children:[e.jsx(k,{variant:"subtitle2",children:t("enhanced_survey_response_type")}
1),e.jsx(bn,{row:!0,value:j.question.responseType,onChange:h=>void E(h.target.value),children:["single_choice","multiple_choice","free_text"].filter(h=>a==null?void 0:a.responseTypes.includes(h)).map(h=>e.jsx(fe,{value:h,control:e.jsx(vn,{}),label:t(`enhanced_survey_response_${h}`)},h))})]}),j.question.responseType!=="free_text"&&e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",children:t("enhanced_survey_answers")}),j.question.choices.map((h,$)=>{var We,ze;const Q=yt(h,C,G,j),he=ve(s,p,Q==null?void 0:Q.contentId);return e.jsx(Se,{variant:"outlined",sx:{p:2,borderRadius:2},children:e.jsxs(y,{spacing:1.5,children:[e.jsxs(y,{direction:"row",alignItems:"center",justifyContent:"space-between",children:[e.jsx(k,{variant:"subtitle2",children:t("enhanced_survey_answer_number",{number:$+1})}),d&&!rn(j)&&e.jsxs(y,{direction:"row",spacing:.5,children:[e.jsx(Xe,{size:"small",disabled:$===0,"aria-label":t("enhanced_survey_move_up"),onClick:()=>re(h.id,-1),children:e.jsx(wt,{fontSize:"small"})}),e.jsx(Xe,{size:"small",disabled:$===(((We=j.question)==null?void 0:We.choices.length)??0)-1,"aria-label":t("enhanced_survey_move_down"),onClick:()=>re(h.id,1),children:e.jsx(Ct,{fontSize:"small"})}),e.jsx(Xe,{size:"small","aria-label":t("enhanced_survey_remove_answer"),onClick:()=>ye((l,A)=>{us(A,l,h.id)}),children:e.jsx(st,{fontSize:"small"})})]})]}),e.jsx(we,{label:t("enhanced_survey_member_visible_content"),children:e.jsx(K,{id:Q?`enhanced-survey-content-${Q.contentId}`:void 0,fullWidth:!0,required:!0,label:R?h.id===((ze=j.wordingSelection)==null?void 0:ze.simplerChoiceId)?t("enhanced_survey_simpler_choice_label"):t("enhanced_survey_standard_choice_label"):t("enhanced_survey_display_text"),value:he,disabled:!d||!Q,onChange:l=>Q&&O(h.id,(A,S)=>mn(S,p,Q.contentId,l.target.value))})}),e.jsx(K,{fullWidth:!0,required:!0,label:t("enhanced_survey_reporting_value"),value:h.canonicalValue,disabled:!d||rn(j),onChange:l=>O(h.id,A=>{A.canonicalValue=l.target.value}),helperText:t("enhanced_survey_reporting_value_help")}),j.question.responseType==="single_choice"&&e.jsx(fe,{control:e.jsx(hn,{checked:h.requiresFreeText===!0,disabled:!d,onChange:l=>ye(A=>{var S;(S=A.question)==null||S.choices.forEach(F=>{F.requiresFreeText=F.id===h.id&&l.target.checked||void 0})})}),label:t("enhanced_survey_answer_requires_free_text")})]})},h.id)}),d&&!rn(j)&&e.jsx(U,{startIcon:e.jsx(Kn,{}),sx:{alignSelf:"flex-start"},disabled:j.question.choices.length>=((a==null?void 0:a.limits.maxChoicesPerQuestion)??200),onClick:()=>ye((h,$)=>{var Q;return Vn($,h,((Q=h.question)==null?void 0:Q.sourceReview.sourceReference)??ke.sourceReview.sourceReference)}),children:t("enhanced_survey_add_answer")})]})]}),j.type==="completion"&&e.jsxs(we,{label:t("enhanced_survey_member_visible_content"),children:[e.jsx(K,{fullWidth:!0,multiline:!0,label:t("enhanced_survey_next_steps_message"),value:ve(s,p,s.completion.nextStepsContentId),disabled:!d,onChange:h=>Ce(s.completion.nextStepsContentId,h.target.value)}),e.jsx(K,{fullWidth:!0,multiline:!0,label:t("enhanced_survey_recoverable_error_content"),value:ve(s,p,s.completion.recoverableErrorContentId),disabled:!d,onChange:h=>Ce(s.completion.recoverableErrorContentId,h.target.value)})]}),e.jsx(Ir,{definition:s,language:p,editable:d,translating:ie,onTranslateMissing:()=>void _e(!0),updateDefinition:v})]})},He=()=>{var g;return j?e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",fontWeight:700,children:t("enhanced_survey_properties")}),j.question&&!rn(j)&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{control:e.jsx(Ye,{checked:j.question.required,disabled:!d,onChange:b=>ye(D=>{D.question&&(D.question.required=b.target.checked)})}),label:t("enhanced_survey_required_response")}),e.jsx(k,{variant:"subtitle2",children:t("enhanced_survey_non_answers")}),((a==null?void 0:a.nonAnswerOutcomes)??[]).map(b=>{var H;const D=(H=j.question)==null?void 0:H.allowedNonAnswers.find(c=>c.outcome===b),R=t(`enhanced_survey_non_answer_${b}`);return e.jsxs(xe,{children:[e.jsx(fe,{control:e.jsx(hn,{checked:!!D,disabled:!d,onChange:c=>ye((h,$)=>{h.question&&(c.target.checked?hs($,h.question,b,Ae(b)):vs($,h.question,b))})}),label:D&&ve(s,p,D.labelContentId)||R}),D&&e.jsx(K,{fullWidth:!0,size:"small",sx:{ml:4,width:"calc(100% - 32px)"},label:t("enhanced_survey_non_answer_label"),value:ve(s,p,D.labelContentId),disabled:!d,onChange:c=>ye((h,$)=>{var he;const Q=(he=h.question)==null?void 0:he.allowedNonAnswers.find(We=>We.outcome===b);Q&&mn($,p,Q.labelContentId,c.target.value)})})]},b)})]}),e.jsx(Tn,{}
1),e.jsxs(yn,{disableGutters:!0,elevation:0,children:[e.jsx(fn,{children:e.jsx(k,{variant:"subtitle2",children:t("enhanced_survey_advanced_settings")})}),e.jsx(jn,{children:e.jsxs(y,{spacing:1,children:[e.jsx(k,{variant:"body2",children:t("enhanced_survey_pathway_value",{pathway:((g=s.pathways.find(b=>b.id===C))==null?void 0:g.name)??""})}),e.jsx(k,{variant:"body2",children:t("enhanced_survey_delivery_mode_value",{mode:t(`enhanced_survey_delivery_${s.aiConfiguration.deliveryMode}`)})}),e.jsx(k,{variant:"body2",children:t("enhanced_survey_message_count",{count:s.messageBundle.messages.length})}),e.jsx(k,{variant:"body2",children:t("enhanced_survey_control_count",{count:s.messageBundle.controls.length})}),e.jsx(de,{severity:"info",children:t("enhanced_survey_template_settings_read_only")}),!s.presentationVariants.some(b=>b.kind==="simpler")&&d&&e.jsx(U,{variant:"outlined",onClick:()=>{ce(t("enhanced_survey_variant_simpler")),m(!0)},children:t("enhanced_survey_add_simpler_wording")})]})})]}),j.question&&!rn(j)&&e.jsxs(yn,{disableGutters:!0,elevation:0,children:[e.jsx(fn,{children:e.jsx(k,{variant:"subtitle2",children:t("enhanced_survey_question_advanced")})}),e.jsx(jn,{children:e.jsx(Tt,{block:j,definition:s,language:p,capabilities:a,editable:d,updateDefinition:v})})]}),d&&j&&e.jsx(U,{color:"error",startIcon:e.jsx(st,{}),disabled:!Le(),onClick:()=>void Ue(),children:t("enhanced_survey_remove_block")})]}):null};return e.jsxs(y,{spacing:3,"aria-busy":ie,children:[e.jsx(pt,{open:ie,role:"status","aria-live":"polite","aria-hidden":!ie,sx:{color:"common.white",zIndex:g=>g.zIndex.modal+1},children:e.jsxs(y,{spacing:2,alignItems:"center",children:[e.jsx(Je,{color:"inherit"}),e.jsx(k,{color:"inherit",fontWeight:600,children:t("enhanced_survey_operation_in_progress")})]})}),e.jsxs(xe,{children:[e.jsx(k,{variant:"h4",component:"h2",fontWeight:700,gutterBottom:!0,children:t("enhanced_survey_build_title")}),e.jsx(k,{color:"text.secondary",children:t("enhanced_survey_build_description")})]}),ae&&e.jsx(de,{severity:"error",onClose:()=>x(void 0),children:ae}),e.jsx(Mt,{definition:s,language:p,pathwayId:C,variantId:G,selectedBlockId:L,onLanguageChange:z,onPathwayChange:N,onVariantChange:J,onBlockChange:I,editable:d,maxBlocks:(a==null?void 0:a.limits.maxBlocks)??500,onAddBlock:()=>X({..._n(),open:!0}),onMoveBlock:(g,b)=>v(D=>os(D,g,b)),languageActions:d?e.jsxs(y,{direction:"row",spacing:1,children:[Ie&&!Ie.isSourceLanguage&&e.jsx(U,{startIcon:e.jsx(bs,{}),disabled:w>0,onClick:()=>void _e(!0),children:t("enhanced_survey_regenerate_language")}),e.jsx(U,{startIcon:e.jsx(vr,{}),variant:"outlined",disabled:w>0||De.length===0||s.languages.length>=((a==null?void 0:a.limits.maxLanguages)??Number.MAX_SAFE_INTEGER),onClick:()=>ne(!0),children:t("enhanced_survey_add_language")})]}):void 0,content:$e(),properties:He()}),e.jsxs(en,{open:V.open,onClose:()=>X(_n()),fullWidth:!0,maxWidth:"lg",children:[e.jsx(nn,{children:t("enhanced_survey_add_question")}),e.jsx(tn,{children:e.jsxs(y,{spacing:2.5,sx:{pt:1},children:[e.jsxs(we,{label:t("enhanced_survey_member_visible_content"),children:[e.jsx(K,{fullWidth:!0,required:!0,multiline:!0,label:t("enhanced_survey_block_content"),value:V.content,onChange:g=>X(b=>({...b,content:g.target.value})),helperText:t("enhanced_survey_default_content_language",{language:t(s.sourceLanguage.replace("-","_"))})}),e.jsx(K,{fullWidth:!0,multiline:!0,minRows:2,label:t("enhanced_survey_help_text"),value:V.helpText,onChange:g=>X(b=>({...b,helpText:g.target.value}))})]}),e.jsx(K,{fullWidth:!0,required:!0,label:t("enhanced_survey_source_reference"),value:V.sourceReference,onChange:g=>X(b=>({...b,sourceReference:g.target.value})),helperText:t("enhanced_survey_source_reference_help")}),e.jsxs(y,{spacing:2,children:[e.jsxs(me,{fullWidth:!0,required:!0,children:[e.jsx(je,{children:t("enhanced_survey_response_type")}),e.jsx(be,{label:t("enhanced_survey_response_type"),value:V.questionResponseType,onChange:g=>X(b=>({...b,questionResponseType:g.target.value})),children:((a==null?void 0:a.responseTypes)??[]).map(g=>e.jsx(ge,{value:g,children:t(`enhanced_survey_response_${g}`)},g))})]}),e.jsxs(me,{fullWidth:!0,required:!0,children:[e.jsx(je,{children:t("enhanced_survey_required_response")}),e.jsxs(be,{label:t("enhanced_survey_required_response"),value:V.questionRequired,onChange:g=>X(b=>({...b,questionRequired:g.target.value})),children:[e.jsx(ge,{value:"yes",children:t("enhanced_survey_yes")}),e.jsx(ge,{value:"no",children:t("enhanced_survey_no")})]})]}),e.jsxs(me,{fullWidth:!0,required:!0,children:[e.jsx(je,{children:t("enhanced_survey_non_answers")}),e.jsxs(be,{label:t("enhanced_survey_non_answers"),value:V.questionNonAnswerMode,onChange:g=>X(b=>({...b,questionNonAnswerMode:g.target.value,questionAllowedNonAnswers:g.target.value==="none"?[]:b.questionAllowedNonAnswers})),children:[e.jsx(ge,{value:"none",children:t("enhanced_survey_non_answers_none")}),e.jsx(ge,{value:"selected",disabled:!(a!=null&&a.nonAnswerOutcomes.length),children:t("enhanced_survey_non_answers_selected")})]})]}),V.questionNonAnswerMode==="selected"&&e.jsx(y,{spacing:0,children:((a==null?void 0:a.nonAnswerOutcomes)??[]).map(g=>e.jsx(fe,{control:e.jsx(hn,{checked:V.questionAllowedNonAnswers.includes(g),onChange:b=>X(D=>({...D,questionAllowedNonAnswers:b.target.checked?[...D.questionAllowedNonAnswers,g]:D.questionAllowedNonAnswers.filter(R=>R!==g)}))}),label:t(`enhanced_survey_non_answer_${g}`)},g))})]})]})}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>X(_n()),children:t("enhanced_survey_cancel")}),e.jsx(U,{variant:"contained",disabled:!qe,onClick:Ve,children:t("enhanced_survey_add_question")})]})]}),e.jsxs(en,{open:te,onClose:()=>m(!1),fullWidth:!0,maxWidth:"sm",children:[e.jsx(nn,{children:t("enhanced_survey_add_simpler_wording")}),e.jsx(tn,{children:e.jsxs(y,{spacing:2,sx:{pt:1},children:[e.jsx(de,{severity:"info",children:t("enhanced_survey_add_simpler_description")}),e.jsx(K,{fullWidth:!0,required:!0,label:t("enhanced_survey_variant_name"),value:T,onChange:g=>ce(g.target.value)}),e.jsx(K,{fullWidth:!0,required:!0,label:t("enhanced_survey_source_reference"),value:M,onChange:g=>ee(g.target.value),helperText:t("enhanced_survey_source_reference_help")})]})}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>m(!1),children:t("enhanced_survey_cancel")}),e.jsx(U,{variant:"contained",disabled:!T.trim()||!M.trim(),onClick:Ge,children:t("enhanced_survey_add_simpler_wording")})]})]}),e.jsxs(en,{open:Y,onClose:()=>ne(!1),fullWidth:!0,maxWidth:"sm",children:[e.jsx(nn,{children:t("enhanced_survey_add_language")}),e.jsx(tn,{children:e.jsxs(y,{spacing:2,sx:{pt:1},children:[e.jsx(de,{severity:"info",children:t("enhanced_survey_translation_review_warning")}),e.jsxs(me,{fullWidth:!0,required:!0,children:[e.jsx(je,{children:t("enhanced_survey_target_language")}),e.jsx(be,{label:t("enhanced_survey_target_language"),value:W,onChange:g=>Z(g.target.value),children:De.map(g=>e.jsx(ge,{value:g,children:g},g))})]})]})}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>ne(!1),children:t("enhanced_survey_cancel")}),e.jsx(U,{variant:"contained",disabled:!W||w>0,onClick:()=>void _e(),children:t("enhanced_survey_generate_translation")})]})]})]})},Rr=({block:n,definition:t,language:r,editable:i,onContentChange:_})=>{const{t:s}=Te();if(!n.consent)return null;const o=n.consent;return e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",children:s("enhanced_survey_consent_settings")}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_consent_explanation"),value:ve(t,r,o.explanationContentId),disabled:!i,onChange:a=>_(o.explanationContentId,a.target.value)})}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,label:s("enhanced_survey_consent_accepted_label"),value:ve(t,r,o.acceptedLabelContentId),disabled:!i,onChange:a=>_(o.acceptedLabelContentId,a.target.value)})}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,label:s("enhanced_survey_consent_declined_label"),value:ve(t,r,o.declinedLabelContentId),disabled:!i,onChange:a=>_(o.declinedLabelContentId,a.target.value)})}),o.noConsequence.contentId&&e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_no_consequence_content"),value:ve(t,r,o.noConsequence.contentId),disabled:!i,onChange:a=>_(o.noConsequence.contentId,a.target.value)})}),o.unansweredConsequence.contentId&&e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_unanswered_consequence_content"),value:ve(t,r,o.unansweredConsequence.contentId),disabled:!i,onChange:a=>_(o.unansweredConsequence.contentId,a.target.value)})})]})},qr=({item:n,issueCount:t,editable:r,disabled:i,onDecision:_})=>{var w;const{t:s}=Te(),o=(w=Object.values(n.content).find(v=>!!v.generation))==null?void 0:w.generation,a=n.approval.status==="approved"?"success":n.approval.status==="rejected"?"error":"warning",d=[t?s("enhanced_survey_issue_count",{count:t}):void 0,o?s("enhanced_survey_generated_by",{tool:o.tool}):void 0].filter(v=>!!v);return e.jsx(jt,{disableGutters:!0,divider:!0,sx:{py:2},children:e.jsxs(y,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",sm:"flex-start"},spacing:2,sx:{width:"100%",minWidth:0},children:[e.jsxs(xe,{sx:{flex:1,minWidth:0},children:[e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",flexWrap:"wrap",children:[e.jsx(k,{children:n.language}),n.isSourceLanguage&&e.jsx(Fe,{size:"small",label:s("enhanced_survey_source_language_badge")})]}),e.jsx(k,{"data-testid":"language-review-metadata","aria-hidden":!d.length,variant:"body2",color:"text.secondary",sx:{mt:.5,minHeight:20,overflowWrap:"anywhere",visibility:d.length?"visible":"hidden"},children:d.length?d.join(" · "):" "})]}),e.jsxs(y,{spacing:1,alignItems:{xs:"flex-start",sm:"flex-end"},sx:{flexShrink:0,maxWidth:"100%"},children:[e.jsx(Fe,{size:"small",color:a,label:s(`enhanced_survey_language_status_${n.approval.status}`),sx:{width:96}}),r&&e.jsxs(y,{direction:"row",spacing:1,sx:{flexWrap:"wrap",rowGap:1},children:[e.jsx(U,{size:"small",variant:n.approval.status==="rejected"?"contained":"outlined",color:"error",disabled:i||n.approval.status==="rejected",onClick:()=>void _(n.language,"rejected"),sx:{width:76},children:s("enhanced_survey_reject")}),e.jsx(U,{size:"small",variant:n.approval.status==="approved"?"contained":"outlined",color:"success",disabled:i||n.approval.status==="approved",onClick:()=>void _(n.language,"approved"),sx:{width:76},children:s("enhanced_survey_approve")})]})]})]})})},Ee={pathway:n=>`pathway:${n}`,presentationVariant:n=>`presentation-variant:${n}`,route:n=>`route:${n}`,blockPresentation:(n,t)=>`block-presentation:${n}:${t}`,question:n=>`question:${n}`,choice:(n,t)=>`choice:${n}:${t}`,choicePresentation:(n,t,r)=>`choice-presentation:${n}:${t}:${r}`},On=(n,t)=>`${n}\0${t}`,Er=(n,t)=>n===t?0:n<t?-1:1,Tr=(n,t)=>{const r=Math.max(n.order.length,t.order.length);for(let i=0;i<r;i+=1){const _=Er(n.order[i]??"",t.order[i]??"");if(_!==0)return _}return 0},Mr=n=>[...n.pathways.map(t=>
1({key:Ee.pathway(t.id),targetType:"pathway",sourceReference:t.sourceReview.sourceReference,validationPath:`definition.pathways.${t.id}.sourceReview`,order:[t.id],pathwayId:t.id})),...n.presentationVariants.map(t=>({key:Ee.presentationVariant(t.id),targetType:"presentation_variant",sourceReference:t.sourceReview.sourceReference,validationPath:`definition.presentationVariants.${t.id}.sourceReview`,order:[t.id],pathwayId:t.appliesToAllPathways?void 0:t.pathwayIds[0],variantId:t.id})),...n.routes.map(t=>({key:Ee.route(t.id),targetType:"route",sourceReference:t.sourceReview.sourceReference,validationPath:`definition.routes.${t.id}.sourceReview`,order:[t.id],blockId:t.routeBlockId})),...n.blocks.flatMap(t=>[...t.presentations.map((r,i)=>({key:Ee.blockPresentation(t.id,i),targetType:"block_presentation",sourceReference:r.sourceReview.sourceReference,validationPath:`definition.blocks.${t.id}.presentations.sourceReview`,order:[t.id,String(i)],blockId:t.id,pathwayId:r.pathwayId,variantId:r.presentationVariantId})),...t.question?[{key:Ee.question(t.id),targetType:"question",sourceReference:t.question.sourceReview.sourceReference,validationPath:`definition.blocks.${t.id}.question.sourceReview`,order:[t.id],blockId:t.id},...t.question.choices.flatMap(r=>[{key:Ee.choice(t.id,r.id),targetType:"choice",sourceReference:r.sourceReview.sourceReference,validationPath:`definition.blocks.${t.id}.question.choices.${r.id}.sourceReview`,order:[t.id,r.id],blockId:t.id},...r.presentations.map((i,_)=>
1({key:Ee.choicePresentation(t.id,r.id,_),targetType:"choice_presentation",sourceReference:i.sourceReview.sourceReference,validationPath:`definition.blocks.${t.id}.question.choices.${r.id}.presentations.sourceReview`,order:[t.id,r.id,String(_)],blockId:t.id,pathwayId:i.pathwayId,variantId:i.presentationVariantId}))])]:[]])],Lt=(n,t)=>{const r=new Map;Mr(n).forEach(v=>{const f=On(v.targetType,v.sourceReference);r.set(f,[...r.get(f)??[],v])});const i=new Map;t.forEach(v=>{const f=On(v.targetType,v.sourceReference);i.set(f,[...i.get(f)??[],v])});const _=new Map,s=new Map,o=new Map,a=new Map,d=[],w=new Set;return i.forEach((v,f)=>{const p=[...r.get(f)??[]].sort(Tr);p.length===0||p.length!==v.length||v.forEach((z,C)=>{const N=p[C],G={key:N.key,targetType:N.targetType,validationPath:N.validationPath,item:z,blockId:N.blockId,pathwayId:N.pathwayId,variantId:N.variantId};_.set(N.key,z),o.set(z.path,G),a.set(N.validationPath,[...a.get(N.validationPath)??[],G]),w.add(z),N.blockId&&s.set(N.blockId,[...s.get(N.blockId)??[],z])})}),t.forEach(v=>{if(w.has(v))return;const f=On(v.targetType,v.sourceReference),p=r.get(f)??[],z=new Set(p.map(C=>C.blockId).filter(C=>!!C));if(z.size===1&&p.length>0&&p.every(C=>C.blockId===[...z][0])){const C=[...z][0];s.set(C,[...s.get(C)??[],v])}d.push(v)}),{byContext:_,byBlock:s,byItemPath:o,byValidationPath:a,unmapped:d}},Lr=({item:n,label:t,children:r,disabled:i=!1,highlighted:_=!1,focusRequestId:s,onDecision:o})=>{const{t:a}=Te(),d=u.useRef(null);if(u.useEffect(()=>{if(!_)return;const v=()=>{const p=d.current;p&&(p.focus({preventScroll:!0}),typeof p.scrollIntoView=="function"&&p.scrollIntoView({behavior:"smooth",block:"center"}))};if(typeof requestAnimationFrame!="function"){v();return}const f=requestAnimationFrame(v);return()=>cancelAnimationFrame(f)},[s,_]),!n)return null;const w=n.status==="approved"?"success":n.status==="rejected"?"error":"warning";return e.jsx(Se,{ref:d,role:"region","aria-label":t??a("enhanced_survey_contextual_review"),tabIndex:-1,"data-highlighted":_?"true":"false",variant:"outlined",sx:{p:1.25,borderRadius:2,width:"100%",minWidth:0,borderColor:`${w}.main`,outline:_?"3px solid":"none",outlineColor:"warning.main",outlineOffset:3},children:e.jsxs(y,{direction:{xs:"column",sm:"row"},spacing:1.25,justifyContent:"space-between",alignItems:{xs:"stretch",sm:"flex-start"},children:[e.jsxs(xe,{sx:{flex:1,minWidth:0},children:[e.jsx(k,{variant:"caption",fontWeight:700,children:t??a("enhanced_survey_contextual_review")}),r]}),e.jsxs(y,{spacing:1,alignItems:"flex-end",sx:{flexShrink:0,alignSelf:"flex-end"},children:[e.jsx(Fe,{size:"small",color:w,label:a(`enhanced_survey_source_${n.status}`)}),e.jsxs(y,{direction:"row",spacing:1,children:[e.jsx(U,{size:"small",variant:n.status==="rejected"?"contained":"outlined",color:"error",disabled:i||n.status==="rejected",onClick:()=>void o(n.path,"rejected"),children:a("enhanced_survey_reject")}),e.jsx(U,{size:"small",variant:n.status==="approved"?"contained":"outlined",color:"success",disabled:i||n.status==="approved",onClick:()=>void o(n.path,"approved"),children:a("enhanced_survey_approve")})]})]})]})})},Wr=({definition:n,capabilities:t,sourceReviewItems:r,decisionsDisabled:i=!1,focusRequest:_,onDecision:s,onBlockDecision:o})=>{var T,ce,M,ee;const{t:a}=Te(),[d,w]=u.useState(n.sourceLanguage),[v,f]=u.useState(((T=n.pathways[0])==null?void 0:T.id)??""),[p,z]=u.useState(((ce=n.presentationVariants.find(q=>q.kind==="standard"))==null?void 0:ce.id)??((M=n.presentationVariants[0])==null?void 0:M.id)??""),[C,N]=u.useState(((ee=qn(n.blocks)[0])==null?void 0:ee.id)??""),[G,J]=u.useState(!1),L=u.useMemo(()=>Lt(n,r),[n,r]);u.useEffect(()=>{if(!_)return;const q=L.byItemPath.get(_.path);if(!q)return;q.blockId&&N(q.blockId),q.targetType==="route"&&J(!0);let B=q.pathwayId;if(q.variantId){const P=n.presentationVariants.find(le=>le.id===q.variantId);P&&!P.appliesToAllPathways&&!P.pathwayIds.includes(B??v)&&(B=P.pathwayIds[0]),z(q.variantId)}B&&f(B)},[n.presentationVariants,_,L,v]),u.useEffect(()=>{var B,P,le,oe;n.languages.some(j=>j.language===d)||w(n.sourceLanguage),n.pathways.some(j=>j.id===v)||f(((B=n.pathways[0])==null?void 0:B.id)??"");const q=n.presentationVariants.filter(j=>j.appliesToAllPathways||j.pathwayIds.includes(v));q.some(j=>j.id===p)||z(((P=q.find(j=>j.kind==="standard"))==null?void 0:P.id)??((le=q[0])==null?void 0:le.id)??""),n.blocks.some(j=>j.id===C)||N(((oe=qn(n.blocks)[0])==null?void 0:oe.id)??"")},[n,d,v,C,p]);const I=n.blocks.find(q=>q.id===C),V=I?I.presentations.findIndex(q=>q===En(I,v,p)):-1,X=I&&V>=0?I.presentations[V]:void 0,Y=I?L.byBlock.get(I.id)??[]:[],ne=Y.filter(q=>q.status==="pending").length,W=Y.every(q=>q.status==="approved")?"approved":Y.every(q=>q.status==="rejected")?"rejected":ne?"pending":"mixed",Z=I?n.routes.filter(q=>q.routeBlockId===I.id&&L.byContext.has(Ee.route(q.id))):[],ie=(q,B,P)=>{const le=L.byContext.get(q),oe=!!le&&(_==null?void 0:_.path)===le.path;return e.jsx(Lr,{item:le,label:B,disabled:i,highlighted:oe,focusRequestId:oe?_==null?void 0:_.requestId:void 0,onDecision:s,children:P})},ue=n.pathways.find(q=>q.id===v),ae=n.presentationVariants.find(q=>q.id===p),x=e.jsxs(y,{spacing:1,children:[ie(Ee.pathway(v),a("enhanced_survey_review_pathway_source"),ue?e.jsx(k,{variant:"body2",children:a("enhanced_survey_review_pathway_context",{name:ue.name,audience:ue.audie
1nce})}):void 0),ie(Ee.presentationVariant(p),a("enhanced_survey_review_variant_source"),ae?e.jsx(k,{variant:"body2",children:a("enhanced_survey_review_variant_context",{name:ae.name,kind:a(`enhanced_survey_variant_${ae.kind}`)})}):void 0)]}),te=()=>{const q=I?mt(I,n.blocks):void 0;if(q)return e.jsx(de,{severity:"error",children:a(q)});if(!I||!X)return e.jsx(de,{severity:"warning",children:a("enhanced_survey_presentation_missing")});const B=I.question;return e.jsxs(y,{spacing:2.5,children:[e.jsxs(y,{direction:{xs:"column",md:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",md:"flex-start"},spacing:2,children:[e.jsx(k,{variant:"h5",fontWeight:700,children:a(`enhanced_survey_block_${I.type}`)}),!!Y.length&&e.jsxs(y,{spacing:1,alignItems:{xs:"stretch",md:"flex-end"},children:[e.jsx(Fe,{size:"small",color:W==="approved"?"success":W==="rejected"?"error":"warning",label:a(`enhanced_survey_block_review_${W}`,{count:ne})}),e.jsxs(y,{direction:"row",spacing:1,children:[e.jsx(U,{size:"small",color:"error",variant:"outlined",disabled:i||Y.every(P=>P.status==="rejected"),onClick:()=>void o(Y.filter(P=>P.status!=="rejected").map(P=>P.path),"rejected"),children:a("enhanced_survey_reject_block")}),e.jsx(U,{size:"small",variant:"contained",disabled:i||Y.every(P=>P.status==="approved"),onClick:()=>void o(Y.filter(P=>P.status!=="approved").map(P=>P.path),"approved"),children:a("enhanced_survey_approve_block")})]})]})]}),e.jsxs(y,{spacing:1.5,children:[e.jsx(we,{label:a("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,minRows:3,label:I.type==="question"?a("enhanced_survey_question_text"):a("enhanced_survey_block_content"),value:ve(n,d,X.contentId),InputProps:{readOnly:!0}})}),ie(Ee.blockPresentation(I.id,V),a("enhanced_survey_review_block_wording_source"))]}),X.helpContentId&&e.jsx(we,{label:a("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,minRows:2,label:a("enhanced_survey_help_text"),value:ve(n,d,X.helpContentId),InputProps:{readOnly:!0}})}),I.consent&&e.jsx(Ar,{block:I,definition:n,language:d,allowedActions:(t==null?void 0:t.consentConsequenceActions)??[],allowedClassifications:(t==null?void 0:t.consentClassifications)??[]}),B&&e.jsxs(e.Fragment,{children:[e.jsxs(y,{spacing:1.5,children:[e.jsx(y,{spacing:2,sx:{width:"100%"},children:e.jsxs(me,{children:[e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_response_type")}),e.jsx(bn,{row:!0,value:B.responseType,children:["single_choice","multiple_choice","free_text"].filter(P=>((t==null?void 0:t.responseTypes)??[B.responseType]).includes(P)).map(P=>e.jsx(fe,{value:P,disabled:!0,control:e.jsx(vn,{}),label:a(`enhanced_survey_response_${P}`)},P))})]})}),ie(Ee.question(I.id),a("enhanced_survey_review_question_source"))]}),B.responseType!=="free_text"&&e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",children:a("enhanced_survey_answers")}),B.choices.map((P,le)=>{const oe=P.presentations.findIndex(ke=>ke===yt(P,v,p,I)),j=oe>=0?P.presentations[oe]:void 0;return e.jsx(Se,{variant:"outlined",sx:{p:2,borderRadius:2},children:e.jsxs(y,{spacing:1.5,children:[e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_answer_number",{number:le+1})}),e.jsxs(y,{spacing:1.5,children:[e.jsx(we,{label:a("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,label:a("enhanced_survey_display_text"),value:ve(n,d,j==null?void 0:j.contentId),InputProps:{readOnly:!0}})}),j&&ie(Ee.choicePresentation(I.id,P.id,oe),a("enhanced_survey_review_answer_wording_source",{number:le+1}))]}),e.jsxs(y,{spacing:1.5,children:[e.jsx(K,{fullWidth:!0,label:a("enhanced_survey_reporting_value"),value:P.canonicalValue,InputProps:{readOnly:!0},helperText:a("enhanced_survey_reporting_value_help")}),B.responseType==="single_choice"&&e.jsx(fe,{control:e.jsx(hn,{checked:P.requiresFreeText===!0,disabled:!0}),label:a("enhanced_survey_answer_requires_free_text")}),ie(Ee.choice(I.id,P.id),a("enhanced_survey_review_answer_source",{number:le+1}))]})]})},P.id)})]})]}),I.type==="completion"&&e.jsxs(we,{label:a("enhanced_survey_member_visible_content"),children:[e.jsx(K,{fullWidth:!0,multiline:!0,label:a("enhanced_survey_next_steps_content"),value:ve(n,d,n.completion.nextStepsContentId),InputProps:{readOnly:!0}}),e.jsx(K,{fullWidth:!0,multiline:!0,label:a("enhanced_survey_recoverable_error_content"),value:ve(n,d,n.completion.recoverableErrorContentId),InputProps:{readOnly:!0}})]})]})},m=()=>{var q;return I?e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",fontWeight:700,children:a("enhanced_survey_properties")}),I.question&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{disabled:!0,control:e.jsx(Ye,{checked:I.question.required,disabled:!0}),label:a("enhanced_survey_required_response")}),e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_non_answers")}),((t==null?void 0:t.nonAnswerOutcomes)??[]).map(B=>{var le;const P=(le=I.question)==null?void 0:le.allowedNonAnswers.find(oe=>oe.outcome===B);return e.jsx(fe,{disabled:!0,control:e.jsx(hn,{checked:!!P,disabled:!0}),label:P?ve(n,d,P.labelContentId)||a(`enhanced_survey_non_answer_${B}`):a(`enhanced_survey_non_answer_${B}`)},B)})]}),e.jsx(Tn,{}
1),e.jsxs(yn,{disableGutters:!0,elevation:0,children:[e.jsx(fn,{children:e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_advanced_settings")})}),e.jsx(jn,{children:e.jsxs(y,{spacing:1,children:[e.jsx(k,{variant:"body2",children:a("enhanced_survey_pathway_value",{pathway:((q=n.pathways.find(B=>B.id===v))==null?void 0:q.name)??""})}),e.jsx(k,{variant:"body2",children:a("enhanced_survey_delivery_mode_value",{mode:a(`enhanced_survey_delivery_${n.aiConfiguration.deliveryMode}`)})}),e.jsx(k,{variant:"body2",children:a("enhanced_survey_message_count",{count:n.messageBundle.messages.length})}),e.jsx(k,{variant:"body2",children:a("enhanced_survey_control_count",{count:n.messageBundle.controls.length})}),e.jsx(de,{severity:"info",children:a("enhanced_survey_template_settings_read_only")})]})})]}),!!Z.length&&e.jsxs(yn,{disableGutters:!0,elevation:0,expanded:G,onChange:(B,P)=>J(P),children:[e.jsx(fn,{children:e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_route_reviews")})}),e.jsx(jn,{children:e.jsx(y,{spacing:1,children:Z.map(B=>{var P;return e.jsx(xe,{children:ie(Ee.route(B.id),a("enhanced_survey_review_route_source"),e.jsx(k,{variant:"body2",children:a("enhanced_survey_review_route_context",{block:B.routeBlockId,option:B.optionId,pathway:((P=n.pathways.find(le=>le.id===B.destinationPathwayId))==null?void 0:P.name)??B.destinationPathwayId,profile:B.destinationProfileVersion})}))},B.id)})})})]}),I.question&&e.jsxs(yn,{disableGutters:!0,elevation:0,children:[e.jsx(fn,{children:e.jsx(k,{variant:"subtitle2",children:a("enhanced_survey_question_advanced")})}),e.jsx(jn,{children:e.jsx(Tt,{block:I,definition:n,language:d,capabilities:t,editable:!1,updateDefinition:()=>{}})})]})]}):null};return e.jsx(Mt,{definition:n,language:d,pathwayId:v,variantId:p,selectedBlockId:C,onLanguageChange:w,onPathwayChange:f,onVariantChange:z,onBlockChange:N,contextReview:x,showSourceReviewStatus:!0,content:te(),properties:m()})},Ar=({block:n,definition:t,language:r,allowedActions:i,allowedClassifications:_})=>{const{t:s}=Te();if(!n.consent)return null;const o=n.consent;return e.jsxs(y,{spacing:2,children:[e.jsx(k,{variant:"h6",children:s("enhanced_survey_consent_settings")}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_consent_explanation"),value:ve(t,r,o.explanationContentId),InputProps:{readOnly:!0}})}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,label:s("enhanced_survey_consent_accepted_label"),value:ve(t,r,o.acceptedLabelContentId),InputProps:{readOnly:!0}})}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,label:s("enhanced_survey_consent_declined_label"),value:ve(t,r,o.declinedLabelContentId),InputProps:{readOnly:!0}})}),e.jsxs(me,{fullWidth:!0,disabled:!0,children:[e.jsx(je,{children:s("enhanced_survey_consent_classification")}),e.jsx(be,{label:s("enhanced_survey_consent_classification"),value:o.classification,children:(_.length?_:[o.classification]).map(a=>e.jsx(ge,{value:a,children:s(`enhanced_survey_consent_${a}`)},a))})]}),e.jsx(fe,{disabled:!0,control:e.jsx(Ye,{checked:o.required,disabled:!0}),label:s("enhanced_survey_required_consent")}),e.jsxs(me,{fullWidth:!0,disabled:!0,children:[e.jsx(je,{children:s("enhanced_survey_no_consequence_action")}),e.jsx(be,{label:s("enhanced_survey_no_consequence_action"),value:o.noConsequence.action,children:(i.length?i:[o.noConsequence.action]).map(a=>e.jsx(ge,{value:a,children:s(`enhanced_survey_consequence_${a}`)},a))})]}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_no_consequence_content"),value:ve(t,r,o.noConsequence.contentId),InputProps:{readOnly:!0}})}),e.jsxs(me,{fullWidth:!0,disabled:!0,children:[e.jsx(je,{children:s("enhanced_survey_unanswered_consequence_action")}),e.jsx(be,{label:s("enhanced_survey_unanswered_consequence_action"),value:o.unansweredConsequence.action,children:(i.length?i:[o.unansweredConsequence.action]).map(a=>e.jsx(ge,{value:a,children:s(`enhanced_survey_consequence_${a}`)},a))})]}),e.jsx(we,{label:s("enhanced_survey_member_visible_content"),children:e.jsx(K,{fullWidth:!0,multiline:!0,label:s("enhanced_survey_unanswered_consequence_content"),value:ve(t,r,o.unansweredConsequence.contentId),InputProps:{readOnly:!0}})}),e.jsx(fe,{disabled:!0,control:e.jsx(Ye,{checked:o.amendmentsAllowed,disabled:!0}),label:s("enhanced_survey_amendments_allowed")})]})},Vr={"messageBundle.messages.ShortAnswerCheck":"short_answer_check","messageBundle.messages.UnclearAnswerCheck":"unclear_answer_check"},$r=(n,t)=>{var s;const r=Vr[n.path];if(n.code!=="survey.content.not_resolved"||!r)return n.path;const i=(s=t.messageBundle.messages.find(o=>o.kind===r))==null?void 0:s.contentId,_=i?t.languages.find(o=>{var a;return!o.isSourceLanguage&&!((a=o.content[i])!=null&&a.value.trim())}):void 0;return _&&i?`definition.languages.${_.language}.content.${i}.value`:n.path},zr="enhanced-survey-language-review",Hn=n=>{const t=n.path.toLowerCase(),r=n.code.toLowerCase();return t.includes("governanceteammemberids")||t.includes("responsere
1cipientmemberids")||t.includes("safeguardrecipientmemberids")?"setup":t.includes("livethemeanalysis")||t.includes("aiartifacts")?"delivery":t.includes("source")||r.includes("source")?"sources":t.includes("language")||r.includes("language")?"languages":t.includes("route")||t.includes("pathway")?"pathways":t.includes("consent")?"consent":t.includes("block")||t.includes("question")||t.includes("choice")?"blocks":t.includes("aiconfiguration")||t.includes("safety")?"delivery":t.includes("message")||t.includes("control")?"messages":t.includes("completion")||t.includes("recipient")?"completion":t.includes("governance")||t.includes("purpose")||t.includes("sourcelanguage")||r.includes("setup")?"setup":"other"},ht=n=>{if(n.code.toLowerCase()==="survey.language.not_approved")return"review";const t=Hn(n);if(t==="sources")return"review";if(t==="messages"&&n.path.toLowerCase().includes("control")&&n.path.toLowerCase().includes("deliverymode")||t==="setup"||t==="delivery")return"setup";if(t!=="other")return"build"},Br=n=>n.code.toLowerCase()==="survey.language.not_approved"?zr:void 0,Or=n=>{const t=n.toLowerCase();if(t.includes("governanceteammemberids"))return"enhanced-survey-governance-team";if(t.includes("responserecipientmemberids"))return"enhanced-survey-response-recipients";if(t.includes("safeguardrecipientmemberids"))return"enhanced-survey-safeguard-recipients";if(t.includes("livethemeanalysis")||t.includes("aiartifacts"))return"enhanced-survey-live-theme-analysis";if(t.includes("safety.profile"))return"enhanced-survey-safety-profile";if(t.includes("aiconfiguration")||t.includes("control")&&t.includes("deliverymode"))return"enhanced-survey-delivery-mode"},Dr=()=>{const{t:n}=Te(),t=Un(),r=_t(),{roomId:i,surveyId:_,version:s,definition:o,capabilities:a,editable:d,pendingMutations:w,flush:v,runMutation:f}=Ln(),[p,z]=u.useState(),[C,N]=u.useState(),[G,J]=u.useState(),[L,I]=u.useState(),[V,X]=u.useState(!1),[Y,ne]=u.useState(!1),[W,Z]=u.useState(!1),[ie,ue]=u.useState(!1),[ae,x]=u.useState(),[te,m]=u.useState(!1),[T,ce]=u.useState(""),[M,ee]=u.useState([]),[q,B]=u.useState(!1),[P,le]=u.useState(!1),[oe,j]=u.useState(!1),[ke,Ie]=u.useState(!1),[Ae,ye]=u.useState(),[Ce,Le]=u.useState(),Pe=u.useMemo(()=>o?Lt(o,(C==null?void 0:C.items)??[]):void 0,[o,C]);u.useEffect(()=>{if(!Ce)return;const l=()=>{const S=document.getElementById(Ce.targetId);S&&(S.focus({preventScroll:!0}),typeof S.scrollIntoView=="function"&&S.scrollIntoView({behavior:"smooth",block:"center"}))};if(typeof requestAnimationFrame!="function"){l();return}const A=requestAnimationFrame(l);return()=>cancelAnimationFrame(A)},[Ce]),u.useEffect(()=>{o&&J(l=>{const A=l==null?void 0:l.pathwayId,S=o.pathways.some(Be=>Be.id===A)?A??"":"",F=l==null?void 0:l.presentationVariantId,pe=o.presentationVariants.some(Be=>Be.id===F&&(Be.appliesToAllPathways||Be.pathwayIds.includes(S)))?F??"":"",Qe=l==null?void 0:l.language,Sn=o.languages.some(Be=>Be.language===Qe)?Qe??"":"";return{pathwayId:S,presentationVariantId:pe,language:Sn,deliveryMode:o.aiConfiguration.deliveryMode}})},[o]);const qe=u.useCallback(async()=>{if(s){Z(!0);try{N(await Ft(i,_,s.version))}catch(l){x(l instanceof Error?l.message:n("enhanced_survey_operation_failed"))}finally{Z(!1)}}},[i,_,n,s]),Ue=u.useCallback(async()=>{if(s){ne(!0),x(void 0);try{await v();const l=await Gt(i,_,s.version);return z(l),l}catch(l){x(l instanceof Error?l.message:n("enhanced_survey_operation_failed"));return}finally{ne(!1)}}},[v,i,_,n,s]);if(u.useEffect(()=>{s&&(Ue(),qe())},[s==null?void 0:s.updatedAt]),!s||!o||!G)return null;const Ve=o.presentationVariants.filter(l=>l.appliesToAllPathways||l.pathwayIds.includes(G.pathwayId)),Ge=p==null?void 0:p.errors.reduce((l,A)=>{const S=Hn(A);return l[S]=[...l[S]??[],A],l},{}),E=l=>{const A=Hn(l);if(A==="other")return;if(A==="sources"){const F=(Pe==null?void 0:Pe.byValidationPath.get(l.path))??[],pe=F.find(Qe=>Qe.item.status==="pending")??F[0];pe&&ye(Qe=>({path:pe.item.path,requestId:((Qe==null?void 0:Qe.requestId)??0)+1}));return}const S=ht(l);if(S==="review"){const F=Br(l);F&&Le(pe=>({targetId:F,requestId:((pe==null?void 0:pe.requestId)??0)+1}));return}if(S){const F=$r(l,o);t(Dn(i,_,s.version,S),{state:{validationPath:F}})}}
1,O=async()=>{ue(!0),x(void 0);try{await v();const l=await xn(i,_,s.version,G);I(l),X(!0)}catch(l){x(l instanceof Error?l.message:n("enhanced_survey_operation_failed"))}finally{ue(!1)}},re=async l=>{var F;if(ie)return;const A=(F=L==null?void 0:L.configuration)==null?void 0:F.selection;if(!A)return;const S=Pt(o,A,l);if(S){ue(!0),x(void 0);try{const pe=await xn(i,_,s.version,S);I(pe),J(S)}catch(pe){x(pe instanceof Error?pe.message:n("enhanced_survey_operation_failed"))}finally{ue(!1)}}},_e=async()=>{B(!0),x(void 0);try{await v();const l=o.pathways.flatMap(S=>o.presentationVariants.filter(F=>F.appliesToAllPathways||F.pathwayIds.includes(S.id)).flatMap(F=>o.languages.map(pe=>({key:`${S.id}:${F.id}:${pe.language}`,pathwayName:S.name,variantName:F.name,language:pe.language,selection:{pathwayId:S.id,presentationVariantId:F.id,language:pe.language,deliveryMode:o.aiConfiguration.deliveryMode}})))),A=await Promise.all(l.map(async S=>({key:S.key,pathwayName:S.pathwayName,variantName:S.variantName,language:S.language,result:await xn(i,_,s.version,S.selection)})));return ee(A),A.every(S=>!!S.result.configuration&&S.result.errors.length===0)}catch(l){return x(l instanceof Error?l.message:n("enhanced_survey_operation_failed")),!1}finally{B(!1)}},De=async(l,A)=>{const S=[...new Set(l)];if(S.length){x(void 0),le(!0);try{for(const F of S)await f(pe=>{if(!pe.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));return Xn(i,_,pe.version,{concurrencyToken:pe.concurrencyToken,path:F,status:A})});await qe()}catch(F){x(F instanceof Error?F.message:n("enhanced_survey_operation_failed")),await qe()}finally{le(!1)}}},$e=(l,A)=>De([l],A),He=async(l,A)=>{x(void 0);try{await f(S=>{if(!S.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));return Yn(i,_,S.version,{concurrencyToken:S.concurrencyToken,language:l,status:A})})}catch(S){x(S instanceof Error?S.message:n("enhanced_survey_operation_failed"))}},g=async()=>{const l=((C==null?void 0:C.items)??[]).filter(S=>S.status==="pending").map(S=>S.path),A=o.languages.filter(S=>S.approval.status!=="approved").map(S=>S.language);if(!(!l.length&&!A.length)){x(void 0),le(!0);try{for(const S of[...new Set(l)])await f(F=>{if(!F.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));return Xn(i,_,F.version,{concurrencyToken:F.concurrencyToken,path:S,status:"approved"})});for(const S of A)await f(F=>{if(!F.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));return Yn(i,_,F.version,{concurrencyToken:F.concurrencyToken,language:S,status:"approved"})});await qe()}catch(S){x(S instanceof Error?S.message:n("enhanced_survey_operation_failed")),await qe()}finally{le(!1)}}},b=async(l,A)=>{var S;if(!oe){j(!0),x(void 0);try{if(l==="submit"||l==="approve"||l==="publish"){const F=await Ue();if(!F)return;if(F.errors.length>0){Ie(!0);return}}if((l==="approve"||l==="publish")&&!await _e())return;await f(async F=>{if(!F.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));const pe={concurrencyToken:F.concurrencyToken,approvalVersion:A};if(l==="publish"){const Sn=(await In(i,_)).filter(Wt=>Wt.status==="published");if(Sn.length>1)throw new Ne(409,"",n("enhanced_survey_publish_conflicting_live_versions"));const Be=Sn[0];if(Be){if(!Be.concurrencyToken)throw new Ne(428,"",n("enhanced_survey_error_missing_concurrency_token"));return Zn(i,_,F.version,l,{...pe,currentPublishedVersion:Be.version,currentPublishedConcurrencyToken:Be.concurrencyToken})}}return Zn(i,_,F.version,l,pe)}),l==="publish"&&await ws(i),m(!1),ce("")}catch(F){const pe=F;(S=pe.validationErrors)!=null&&S.length&&(z({errors:pe.validationErrors}),Ie(!0)),x(F instanceof Error?F.message:n("enhanced_survey_operation_failed"))}finally{j(!1)}}},D=async l=>{if(l==="approve"){m(!0);return}const A=l==="retire"||l==="supersede";(l==="submit"||await r({title:n(`enhanced_survey_${l}_title`),description:n(`enhanced_survey_${l}_description`,{version:s.version}),isDestructive:A,okLabel:n(`enhanced_survey_action_${l}`)}))&&await b(l)},R=a==null?void 0:a.lifecycle.find(l=>l.status===s.status),H=l=>(R==null?void 0:R.allowedTransitions.includes(l))??!1,c=o.pathways.some(l=>l.id===G.pathwayId)&&Ve.some(l=>l.id===G.presentationVariantId)&&o.languages.some(l=>l.language===G.language)&&G.deliveryMode===o.aiConfiguration.deliveryMode,h=(C==null?void 0:C.items.filter(l=>l.status==="pending").length)??0,$=o.languages.filter(l=>l.approval.status!=="approved").length,Q=()=>{const l=C==null?void 0:C.items.find(A=>A.status==="pending"&&(Pe==null?void 0:Pe.byItemPath.has(A.path)));l&&ye(A=>({path:l.path,requestId:((A==null?void 0:A.requestId)??0)+1}))},he=!d||!C||w>0||W||P,We=s.status==="draft"&&H("in_review")?["submit"]:s.status==="in_review"?[...H("draft")?["reopen"]:[],...H("approved")?["approve"]:[]]:s.status==="approved"&&H("published")?["publish"]:s.status==="published"?[...H("superseded")?["supersede"]:[],...H("retired")?["retire"]:[]]:s.status==="superseded"&&H("retired")?["retire"]:[],ze=oe||w>0||Y||W||ie||q||P;return e.jsxs(y,{spacing:3,"aria-busy":ze,children:[e.jsx(pt,{open:ze,role:"status","aria-live":"polite","aria-hidden":!ze,sx:{color:"common.white",zIndex:l=>l.zIndex.modal+1},children:e.jsxs(y,{spacing:2,alignItems:"center",children:[e.jsx(Je,{color:"inherit"}),e.jsx(k,{color:"inherit",fontWeight:600,children:n("enhanced_survey_operation_in_progress")})]})}),e.jsxs(y,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",sm:"flex-start"},spacing:2,children:[e.jsxs(xe,{children:[e.jsx(k,{variant:"h4",component:"h2",fontWeight:700,gutterBottom:!0,children:n("enhanced_survey_review_title")}),e.jsx(k,{color:"text.secondary",children:n("enhanced_survey_review_description")})]}),e.jsxs(y,{spacing:1,alignItems:"stretch",sx:{width:{xs:"100%",sm:208},flexShrink:0},children:[p&&e.jsx(Fe,{color:p.errors.length?"warning":"success",label:p.errors.length?n("enhanced_survey_issue_count",{count:p.errors.length}):n("enhanced_survey_validation_valid"),onClick:()=>
1Ie(!0),sx:{width:"100%",height:32}}),e.jsx(U,{variant:"outlined",disabled:Y||w>0,startIcon:Y?e.jsx(Je,{size:16}):void 0,onClick:()=>void Ue().then(l=>{l&&Ie(!0)}),sx:{width:"100%",minHeight:36,height:"auto",whiteSpace:"normal"},children:n("enhanced_survey_run_validation")}),e.jsx(U,{variant:"outlined",disabled:he||h+$===0,startIcon:P?e.jsx(Je,{size:16}):void 0,onClick:()=>void g(),sx:{width:"100%",minHeight:36,height:"auto",whiteSpace:"normal"},children:n("enhanced_survey_approve_all")})]})]}),ae&&e.jsx(de,{severity:"error",onClose:()=>x(void 0),children:ae}),e.jsxs(xe,{children:[e.jsxs(y,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},spacing:1,sx:{mb:1.5},children:[e.jsxs(xe,{children:[e.jsx(k,{variant:"h5",fontWeight:700,gutterBottom:!0,children:n("enhanced_survey_review_workspace_title")}),e.jsx(k,{color:"text.secondary",children:n("enhanced_survey_review_workspace_description")})]}),e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",children:[W&&e.jsx(Je,{size:20}),e.jsx(Fe,{color:h?"warning":"success",label:n("enhanced_survey_pending_count",{count:h}),onClick:h?Q:void 0,sx:{minWidth:144}})]})]}),e.jsx(Wr,{definition:o,capabilities:a,sourceReviewItems:(C==null?void 0:C.items)??[],decisionsDisabled:he,focusRequest:Ae,onDecision:$e,onBlockDecision:De})]}),e.jsxs(se,{container:!0,spacing:3,children:[e.jsx(se,{item:!0,xs:12,lg:7,children:e.jsx(y,{spacing:3,children:e.jsxs(Se,{elevation:0,sx:{p:3,borderRadius:3},children:[e.jsx(k,{variant:"h6",fontWeight:700,gutterBottom:!0,children:n("enhanced_survey_preview_combinations")}),e.jsxs(se,{container:!0,spacing:2,sx:{mt:.5},children:[e.jsx(se,{item:!0,xs:12,sm:6,children:e.jsxs(me,{fullWidth:!0,children:[e.jsx(je,{children:n("enhanced_survey_pathway")}),e.jsx(be,{label:n("enhanced_survey_pathway"),value:G.pathwayId,onChange:l=>{const A=l.target.value,S=o.presentationVariants.filter(F=>F.appliesToAllPathways||F.pathwayIds.includes(A));J({...G,pathwayId:A,presentationVariantId:S.some(F=>F.id===G.presentationVariantId)?G.presentationVariantId:""})},children:o.pathways.map(l=>e.jsx(ge,{value:l.id,children:l.name},l.id))})]})}),e.jsx(se,{item:!0,xs:12,sm:6,children:e.jsxs(me,{fullWidth:!0,children:[e.jsx(je,{children:n("enhanced_survey_wording")}),e.jsx(be,{label:n("enhanced_survey_wording"),value:G.presentationVariantId,onChange:l=>J({...G,presentationVariantId:l.target.value}),children:Ve.map(l=>e.jsx(ge,{value:l.id,children:l.name},l.id))})]})}),e.jsx(se,{item:!0,xs:12,sm:6,children:e.jsxs(me,{fullWidth:!0,children:[e.jsx(je,{children:n("enhanced_survey_language")}),e.jsx(be,{label:n("enhanced_survey_language"),value:G.language,onChange:l=>J({...G,language:l.target.value}),children:o.languages.map(l=>e.jsx(ge,{value:l.language,children:l.language},l.language))})]})}),e.jsx(se,{item:!0,xs:12,sm:6,children:e.jsxs(me,{fullWidth:!0,children:[e.jsx(je,{children:n("enhanced_survey_delivery_mode")}),e.jsx(be,{label:n("enhanced_survey_delivery_mode"),value:G.deliveryMode,onChange:l=>J({...G,deliveryMode:l.target.value}),children:((a==null?void 0:a.deliveryModes)??[o.aiConfiguration.deliveryMode]).filter(l=>l===o.aiConfiguration.deliveryMode).map(l=>e.jsx(ge,{value:l,children:n(`enhanced_survey_delivery_${l}`)},l))})]})})]}),e.jsx(U,{variant:"contained",startIcon:e.jsx(It,{}),disabled:!c||ie||w>0,onClick:()=>void O(),sx:{mt:2},children:n(ie?"enhanced_survey_loading_preview":"enhanced_survey_open_preview")}),e.jsx(Tn,{sx:{my:2}}),e.jsxs(y,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",sm:"center"},spacing:1,children:[e.jsx(k,{variant:"subtitle2",children:n("enhanced_survey_all_combinations")}),e.jsx(U,{size:"small",variant:"outlined",disabled:q||w>0,onClick:()=>void _e(),children:n(q?"enhanced_survey_checking_combinations":"enhanced_survey_check_all_combinations")})]}),!!M.length&&e.jsx(Pn,{dense:!0,disablePadding:!0,sx:{mt:1},children:M.map(l=>{const A=!!l.result.configuration&&l.result.errors.length===0;return e.jsxs(jt,{disableGutters:!0,divider:!0,children:[e.jsx(et,{sx:{minWidth:34},children:A?e.jsx(ot,{color:"success",fontSize:"small"}):e.jsx(lt,{color:"error",fontSize:"small"})}),e.jsx(Gn,{primary:`${l.pathwayName} · ${l.variantName} · ${l.language}`,secondary:A?n("enhanced_survey_preview_resolves"):l.result.errors.map(S=>S.message).join(" · ")})]},l.key)})})]})})}),e.jsx(se,{item:!0,xs:12,lg:5,children:e.jsxs(y,{spacing:3,children:[e.jsxs(Se,{id:"enhanced-survey-language-review",role:"region","aria-label":n("enhanced_survey_languages"),tabIndex:-1,elevation:0,sx:{p:3,borderRadius:3},children:[e.jsx(k,{variant:"h6",fontWeight:700,sx:{mb:1},children:n("enhanced_survey_languages")}
1),e.jsx(Pn,{disablePadding:!0,children:o.languages.map(l=>{const A=((p==null?void 0:p.errors)??[]).filter(S=>S.path.includes(l.language)).length;return e.jsx(qr,{item:l,issueCount:A,editable:d,disabled:w>0,onDecision:He},l.language)})})]}),e.jsxs(Se,{elevation:0,sx:{p:3,borderRadius:3},children:[e.jsx(k,{variant:"h6",fontWeight:700,gutterBottom:!0,children:n("enhanced_survey_version_lifecycle")}),e.jsx(y,{direction:"row",spacing:1,alignItems:"center",sx:{mb:2},children:["draft","in_review","approved","published"].map((l,A)=>e.jsxs(y,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(Fe,{size:"small",color:s.status===l?"primary":"default",label:n(`enhanced_survey_status_${l}`)}),A<3&&e.jsx(k,{color:"text.secondary",children:"â"})]},l))}),e.jsxs(y,{spacing:1,children:[We.map(l=>e.jsx(U,{variant:l==="retire"?"outlined":"contained",color:l==="retire"?"error":"primary",startIcon:e.jsx(pr,{}),disabled:oe||w>0||Y||q,onClick:()=>void D(l),children:n(`enhanced_survey_action_${l}`)},l)),!We.length&&e.jsx(k,{color:"text.secondary",children:n("enhanced_survey_no_lifecycle_actions")})]})]})]})})]}),e.jsx(qt,{open:V,result:L,error:ae,wordingControlPending:ie,onWordingControl:l=>void re(l),onClose:()=>X(!1)}),e.jsxs(en,{open:ke,onClose:()=>Ie(!1),disableRestoreFocus:!0,fullWidth:!0,maxWidth:"md",children:[e.jsx(nn,{children:n("enhanced_survey_validation_results")}),e.jsx(tn,{children:(p==null?void 0:p.errors.length)===0?e.jsx(de,{severity:"success",icon:e.jsx(ot,{}),sx:{mt:1},children:n("enhanced_survey_validation_passed")}):e.jsx(y,{spacing:1,sx:{pt:1},children:Object.entries(Ge??{}).map(([l,A])=>e.jsxs(xe,{children:[e.jsx(k,{variant:"subtitle2",children:n(`enhanced_survey_validation_group_${l}`,{count:A.length})}),e.jsx(Pn,{dense:!0,disablePadding:!0,children:A.map(S=>e.jsxs(bt,{onClick:()=>{Ie(!1),E(S)},children:[e.jsx(et,{sx:{minWidth:34},children:e.jsx(lt,{color:"error",fontSize:"small"})}),e.jsx(Gn,{primary:S.message}),ht(S)==="review"?e.jsx(lr,{fontSize:"small"}):e.jsx(Cs,{fontSize:"small"})]},`${S.code}-${S.path}`))})]},l))})}),e.jsx(on,{children:e.jsx(U,{onClick:()=>Ie(!1),children:n("enhanced_survey_close")})})]}),e.jsxs(en,{open:te,onClose:()=>m(!1),fullWidth:!0,maxWidth:"sm",children:[e.jsx(nn,{children:n("enhanced_survey_approve_version_title")}),e.jsx(tn,{children:e.jsxs(y,{spacing:2,sx:{pt:1},children:[e.jsx(k,{children:n("enhanced_survey_approval_survey_version",{version:s.version})}),e.jsx(K,{autoFocus:!0,fullWidth:!0,required:!0,label:n("enhanced_survey_approval_reference"),value:T,inputProps:{maxLength:100},onChange:l=>ce(l.target.value)}),e.jsx(de,{severity:"info",children:n("enhanced_survey_approval_hash_notice")})]})}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>m(!1),children:n("enhanced_survey_cancel")}),e.jsx(U,{variant:"contained",disabled:!T.trim()||oe,onClick:()=>void b("approve",T.trim()),children:n("enhanced_survey_action_approve")})]})]})]})},Nr=[Re.organizations,Re.responsibleTeams,Re.safetyProfiles,Re.responsePolicies,Re.immediateDangerPolicies,Re.reportRecipientProfiles],kn=n=>`${n.id}::${n.version}`,Fr=()=>{const{t:n}=Te(),t=Qn(),r=Un(),{roomId:i,version:_,definition:s,surveyTitle:o,capabilities:a,editable:d,dirty:w,updateDefinition:v,updateSurveyTitle:f,flush:p}=Ln(),[z,C]=u.useState({}),[N,G]=u.useState([]),[J,L]=u.useState([]),[I,V]=u.useState(!1),[X,Y]=u.useState(),[ne,W]=u.useState([]),[Z,ie]=u.useState([]),[ue,ae]=u.useState(!1),[x,te]=u.useState(),[m,T]=u.useState(),[ce,M]=u.useState(),[ee,q]=u.useState(),[B,P]=u.useState(""),[le,oe]=u.useState(""),[j,ke]=u.useState(),Ie=u.useRef({}),Ae=u.useRef({});w||(Ie.current={},Ae.current={});const ye=u.useRef(""),Ce=u.useRef(""),Le=!!s,Pe=a==null?void 0:a.catalogTypes;u.useEffect(()=>{w||(Ie.current={})},[w]),u.useEffect(()=>{if(!Le)return;V(!0),Y(void 0);const c=Nr.filter(h=>Pe==null?void 0:Pe.includes(h));Promise.all([Promise.all(c.map(h=>Ht(i,h))),_s(i),Ut(i)]).then(([h,$,Q])=>{C(Object.fromEntries(h.map(he=>[he.catalogType,he]))),G($),L(Q)}).catch(h=>Y(h instanceof Error?h.message:n("enhanced_survey_authoring_sources_failed"))).finally(()=>V(!1))},[Pe,Le,i,n]),u.useEffect(()=>{if(!Le)return;let c=!0;return ae(!0),te(void 0),Qt(i).then(async h=>{const $=await Promise.allSettled(h.filter(Q=>!!Q.currentPublishedVersion).map(async Q=>{const he=await Kt(i,Q.id,Q.currentPublishedVersion);return Ss(i,Q,he)?void 0:he}));c&&(W(h),ie($.flatMap(Q=>Q.status==="fulfilled"&&Q.value?[Q.value]:[])),$.some(Q=>Q.status==="rejected")&&te(n("enhanced_survey_codebook_load_partial")))}).catch(h=>{c&&te(pn(h).message)}).finally(()=>{c&&ae(!1)}),()=>{c=!1}},[Le,i,n]);const qe=s==null?void 0:s.languages.find(c=>c.isSourceLanguage),Ve=u.useMemo(()=>Array.from(new Set(s==null?void 0:s.presentationVariants.map(c=>c.kind))),[s==null?void 0:s.presentationVariants]).includes("simpler")?"standard_and_simpler":"standard_only",Ge=u.useMemo(()=>{var c,h;return((h=(c=a==null?void 0:a.configurationOptions)==null?void 0:c.find($=>$.key==="delivery-mode"))==null?void 0:h.options)??[]},[a==null?void 0:a.configurationOptions]),E=s==null?void 0:s.liveThemeAnalysis,O=Z.find(c=>
1c.codebookId===(E==null?void 0:E.codebook.codebookId)&&c.version===E.codebook.codebookVersion&&c.contentHash===E.codebook.contentHash),re=E?ks(O,E):!1,_e=u.useCallback(c=>{const h=ne.find(he=>he.id===c),$=Z.find(he=>he.codebookId===c&&he.version===(h==null?void 0:h.currentPublishedVersion));if(!h||!$||!E)return;const Q=Is(i,h,$);if(!Q){te(n("enhanced_survey_codebook_consistency_error"));return}v(he=>{he.liveThemeAnalysis&&(he.liveThemeAnalysis=Ps(he.liveThemeAnalysis,Q,$))}),te(void 0)},[ne,E,Z,i,n,v]);u.useEffect(()=>{var h;const c=(h=t.state)==null?void 0:h.publishedCodebookId;!c||!E||Ce.current===c||!Z.some($=>$.codebookId===c)||(Ce.current=c,_e(c),r(t.pathname,{replace:!0}))},[E,t.pathname,t.state,r,Z,_e]);const De=async()=>{try{await p(),r(rs(i),{state:{returnTo:t.pathname}})}catch{}},$e=c=>{v(h=>{h.purpose.responseRecipientMemberIds=c}),p().catch(()=>{})};if(u.useEffect(()=>{var Q;const c=(Q=t.state)==null?void 0:Q.validationPath,h=c?Or(c):void 0;if(!s||!h||ye.current===c)return;const $=document.getElementById(h);$&&(ye.current=c??"",typeof $.scrollIntoView=="function"&&$.scrollIntoView({behavior:"smooth",block:"center"}),$.focus())},[s,Ge.length,t.state]),!s||!_)return null;const He=Jt(s.aiConfiguration.safety.immediateDangerPolicy.id),g=()=>{if(!ee)return;const c=Ae.current[ee];if(ee==="standard_and_simpler"&&!c&&(!B.trim()||!le.trim())){ke(n("enhanced_survey_wording_metadata_required"));return}Ae.current[Ve]=Ke(s),v(h=>{if(c){Object.assign(h,Ke(c));return}if(ee==="standard_only"){Object.assign(h,ps(h));return}if(!ft(h,B.trim(),le.trim()))throw new Error("enhanced_survey_wording_change_failed")},{manualSave:!0}),q(void 0),P(""),oe(""),ke(void 0)},b=()=>{if(!m)return;const c=s.aiConfiguration.deliveryMode,h=Ie.current[m];Ie.current[c]=Ke(s);try{v($=>{if(h){Object.assign($,Ke(h));return}Cr($,m)},{manualSave:!0}),M(void 0),T(void 0)}catch($){M($ instanceof Error?n($.message):n("enhanced_survey_operation_failed")),T(void 0)}},D=(c,h)=>v($=>{$.purpose[c]=h}),R=(c,h)=>{var Q;const $=(Q=z[c])==null?void 0:Q.items.find(h);return $?kn($):""},H=(c,h,$,Q,he)=>{var We;return e.jsxs(me,{id:he,tabIndex:he?-1:void 0,fullWidth:!0,disabled:!d||I,children:[e.jsx(je,{children:n(c)}),e.jsx(be,{label:n(c),value:$,onChange:ze=>{var A;const l=(A=z[h])==null?void 0:A.items.find(S=>kn(S)===ze.target.value);l&&Q(l)},children:(((We=z[h])==null?void 0:We.items)??[]).map(ze=>e.jsx(ge,{value:kn(ze),children:ze.displayName},kn(ze)))})]})};return e.jsxs(y,{spacing:3,children:[e.jsxs(xe,{children:[e.jsx(k,{variant:"h4",component:"h2",fontWeight:700,gutterBottom:!0,children:n("enhanced_survey_setup_title")}),e.jsx(k,{color:"text.secondary",children:n("enhanced_survey_existing_setup_description")})]}),X&&e.jsx(de,{severity:"error",children:X}),e.jsxs(Se,{elevation:0,sx:{p:{xs:2,md:3},borderRadius:3},children:[e.jsxs(y,{direction:"row",spacing:1,alignItems:"center",sx:{mb:2},children:[e.jsx(kt,{color:"action"}),e.jsx(k,{variant:"h6",fontWeight:700,children:n("enhanced_survey_listing_details")})]}),e.jsx(de,{severity:"info",sx:{mb:2},children:n("enhanced_survey_listing_edit_help")}),e.jsxs(se,{container:!0,spacing:2,children:[e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx(K,{fullWidth:!0,label:n("enhanced_survey_title_label"),value:o??"",disabled:!d,required:!0,inputProps:{minLength:3,maxLength:500},onChange:c=>f(c.target.value)})}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx(K,{fullWidth:!0,label:n("enhanced_survey_version_label"),value:_.version,disabled:!0})}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx(K,{fullWidth:!0,label:n("enhanced_survey_source_language"),value:(qe==null?void 0:qe.language)??s.sourceLanguage,disabled:!0})}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsxs(me,{fullWidth:!0,disabled:!d,children:[e.jsx(k,{variant:"body2",color:"text.secondary",children:n("enhanced_survey_wording_options")}),e.jsxs(bn,{row:!0,value:Ve,onChange:c=>q(c.target.value),children:[e.jsx(fe,{value:"standard_only",control:e.jsx(vn,{}),label:n("enhanced_survey_standard_only")}),e.jsx(fe,{value:"standard_and_simpler",control:e.jsx(vn,{}),label:n("enhanced_survey_standard_and_simpler")})]})]})})]})]}),!!Ge.length&&e.jsxs(Se,{id:"enhanced-survey-delivery-mode",tabIndex:-1,elevation:0,sx:{p:{xs:2,md:3},borderRadius:3},children:[e.jsx(k,{variant:"h6",fontWeight:700,sx:{mb:2},children:n("enhanced_survey_delivery_mode")}),ce&&e.jsx(de,{severity:"error",sx:{mb:2},children:ce}),e.jsx(bn,{value:s.aiConfiguration.deliveryMode,onChange:c=>{const h=Ge.find($=>$.value===c.target.value);h&&T(h.value)},children:e.jsx(y,{spacing:1.5,children:Ge.map(c=>e.jsx(xe,{children:e.jsx(fe,{value:c.value,disabled:!d,control:e.jsx(vn,{}
1),sx:{width:"100%",alignItems:"flex-start","& .MuiFormControlLabel-label":{flex:1}},label:e.jsxs(xe,{sx:{pt:.75},children:[e.jsx(k,{fontWeight:600,children:c.displayName}),e.jsx(k,{variant:"body2",color:"text.secondary",children:c.description})]})})},c.value))})})]}),e.jsxs(en,{open:!!m,onClose:()=>T(void 0),children:[e.jsx(nn,{children:n("enhanced_survey_delivery_mode_change_title")}),e.jsx(tn,{children:e.jsx(rt,{children:n("enhanced_survey_delivery_mode_change_warning")})}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>T(void 0),children:n("cancel")}),e.jsx(U,{variant:"contained",onClick:b,children:n("enhanced_survey_delivery_mode_change_confirm")})]})]}),e.jsxs(en,{open:!!ee,onClose:()=>q(void 0),children:[e.jsx(nn,{children:n("enhanced_survey_wording_change_title")}),e.jsxs(tn,{children:[e.jsx(rt,{sx:{mb:2},children:n("enhanced_survey_wording_change_warning")}),ee==="standard_and_simpler"&&!Ae.current.standard_and_simpler&&e.jsxs(y,{spacing:2,children:[e.jsx(K,{label:n("enhanced_survey_variant_name"),value:B,required:!0,onChange:c=>P(c.target.value)}),e.jsx(K,{label:n("enhanced_survey_source_reference"),value:le,required:!0,onChange:c=>oe(c.target.value)})]}),j&&e.jsx(de,{severity:"error",sx:{mt:2},children:j})]}),e.jsxs(on,{children:[e.jsx(U,{onClick:()=>q(void 0),children:n("cancel")}),e.jsx(U,{variant:"contained",onClick:g,children:n("enhanced_survey_wording_change_confirm")})]})]}),e.jsxs(Se,{elevation:0,sx:{p:{xs:2,md:3},borderRadius:3},children:[e.jsxs(y,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"stretch",sm:"center"},spacing:1,sx:{mb:2},children:[e.jsxs(xe,{children:[e.jsx(k,{variant:"h6",fontWeight:700,children:n("enhanced_survey_live_theme_analysis")}),e.jsx(k,{variant:"body2",color:"text.secondary",children:n("enhanced_survey_live_theme_analysis_help")})]}),e.jsx(U,{variant:"outlined",onClick:()=>void De(),children:n("enhanced_survey_manage_codebooks")})]}),x&&e.jsx(de,{severity:"warning",sx:{mb:2},children:x}),!E&&e.jsx(de,{severity:"error",sx:{mb:2},children:n("enhanced_survey_live_theme_missing")}),!!E&&!O&&e.jsx(de,{severity:"warning",sx:{mb:2},children:n("enhanced_survey_codebook_reference_outdated")}),e.jsxs(se,{container:!0,spacing:2,children:[e.jsx(se,{item:!0,xs:12,md:6,children:e.jsxs(me,{fullWidth:!0,required:!0,disabled:!d||ue||!E,error:!!E&&!O,children:[e.jsx(je,{id:"enhanced-survey-codebook-label",children:n("enhanced_survey_codebook")}),e.jsx(be,{id:"enhanced-survey-codebook",labelId:"enhanced-survey-codebook-label",label:n("enhanced_survey_codebook"),value:(O==null?void 0:O.codebookId)??"",onChange:c=>_e(c.target.value),children:Z.map(c=>{const h=ne.find($=>$.id===c.codebookId);return e.jsxs(ge,{value:c.codebookId,children:[(h==null?void 0:h.title)??c.definition.title," ·"," ",n("enhanced_survey_codebook_version",{version:c.version})]},`${c.codebookId}::${c.version}`)})})]})}),e.jsx(se,{item:!0,xs:12,md:2,children:e.jsx(K,{fullWidth:!0,required:!0,type:"number",disabled:!d||!O,label:n("enhanced_survey_theme_confidence_threshold"),value:(E==null?void 0:E.confidenceThreshold)??"",inputProps:{min:(O==null?void 0:O.definition.defaultConfidenceThreshold)??0,max:1,step:.01},error:!!E&&!re,onChange:c=>v(h=>{h.liveThemeAnalysis&&(h.liveThemeAnalysis.confidenceThreshold=Number(c.target.value))})})}),e.jsx(se,{item:!0,xs:12,md:2,children:e.jsx(K,{fullWidth:!0,required:!0,type:"number",disabled:!d||!O,label:n("enhanced_survey_theme_max_themes"),value:(E==null?void 0:E.maxThemesPerAnswer)??"",inputProps:{min:1,max:O==null?void 0:O.definition.maxThemesPerAnswer},error:!!E&&!re,helperText:n("enhanced_survey_theme_count_help"),onChange:c=>v(h=>{h.liveThemeAnalysis&&(h.liveThemeAnalysis.maxThemesPerAnswer=Number(c.target.value))})})}),e.jsx(se,{item:!0,xs:12,md:2,children:e.jsx(K,{fullWidth:!0,required:!0,type:"number",disabled:!d||!O,label:n("enhanced_survey_theme_max_interpretation"),value:(E==null?void 0:E.maxInterpretationLength)??"",inputProps:{min:1,max:O==null?void 0:O.definition.maxInterpretationLength},error:!!E&&!re,onChange:c=>v(h=>{h.liveThemeAnalysis&&(h.liveThemeAnalysis.maxInterpretationLength=Number(c.target.value))})})}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsxs(me,{fullWidth:!0,required:!0,disabled:!d,children:[e.jsx(je,{children:n("enhanced_survey_theme_failure_behavior")}),e.jsxs(be,{label:n("enhanced_survey_theme_failure_behavior"),value:(E==null?void 0:E.failureBehavior)??"",onChange:c=>v(h=>{h.liveThemeAnalysis&&(h.liveThemeAnalysis.failureBehavior=c.target.value)}),children:[e.jsx(ge,{value:"allow_completion",children:n("enhanced_survey_theme_allow_completion")}),e.jsx(ge,{value:"block_completion",children:n("enhanced_survey_theme_block_completion")})]})]})}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsxs(me,{fullWidth:!0,required:!0,disabled:!d,children:[e.jsx(je,{children:n("enhanced_survey_theme_review_policy")}),e.jsxs(be,{label:n("enhanced_survey_theme_review_policy"),value:(E==null?void 0:E.reviewPolicy)??"",onChange:c=>v(h=>{h.liveThemeAnalysis&&(h.liveThemeAnalysis.reviewPolicy=c.target.value)}),children:[e.jsx(ge,{value:"not_required",children:n("enhanced_survey_theme_review_not_required")}),e.jsx(ge,{value:"required",children:n("enhanced_survey_theme_review_required")})]})]})})]})]}),e.jsxs(Se,{elevation:0,sx:{p:{xs:2,md:3},borderRadius:3},children:[e.jsx(k,{variant:"h6",fontWeight:700,sx:{mb:2},children:n("enhanced_survey_purpose")}),e.jsxs(se,{container:!0,spacing:2,children:[e.jsx(se,{item:!0,xs:12,children:e.jsx(K,{fullWidth:!0,multiline:!0,label:n("enhanced_survey_goal"),value:s.purpose.goal,disabled:!d,onChange:c=>D("goal",c.target.value)})}),e.jsx(se,{item:!0,xs:12,md:4,children:e.jsx(K,{fullWidth:!0,type:"number",label:n("enhanced_survey_estimated_minutes"),value:s.purpose.estimatedMinutes,disabled:!d,inputProps:{min:1},onChange:c=>D("estimatedMinutes",Number(c.target.value))})}),e.jsx(se,{item:!0,xs:12,children:e.jsx(K,{fullWidth:!0,multiline:!0,label:n("enhanced_survey_next_steps"),value:s.purpose.nextSteps,disabled:!d,onChange:c=>D("nextSteps",c.target.value)})})]})]}),e.jsxs(Se,{elevation:0,sx:{p:{xs:2,md:3},borderRadius:3},children:[e.jsxs(y,{direction:"row",alignItems:"center",spacing:1,sx:{mb:2},children:[e.jsx(k,{variant:"h6",fontWeight:700,children:n("enhanced_survey_governance")}),I&&e.jsx(Je,{size:18})]}),e.jsxs(se,{container:!0,spacing:2,children:[e.jsx(se,{item:!0,xs:12,md:6,children:e.jsxs(me,{fullWidth:!0,disabled:!d||I,children:[e.jsx(je,{children:n("enhanced_survey_owner")}),e.jsx(be,{label:n("enhanced_survey_owner"),value:s.governance.ownerMemberId,onChange:c=>v(h=>{h.governance.ownerMemberId=c.target.value}),children:N.map(c=>{const h=c.id??c.memberId;return e.jsx(ge,{value:h,children:c.memberDisplayName},h)})})]})}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_organization",Re.organizations,R(Re.organizations,c=>c.id===s.governance.organizationId),c=>v(h=>{h.governance.organizationId=c.id}))}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx($n,{id:"enhanced-survey-governance-team",label:n("enhanced_survey_governance_team"),candidates:J,selectedMemberIds:s.governance.governanceTeamMemberIds??[],onChange:c=>v(h=>{h.governance.governanceTeamMemberIds=c}),disabled:!d||I||!!X,loading:I})}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_responsible_team",Re.responsibleTeams,R(Re.responsibleTeams,c=>c.value===s.governance.responsibleTeam),c=>v(h=>{h.governance.responsibleTeam=c.value}))}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx($n,{id:"enhanced-survey-response-recipients",label:n("enhanced_survey_response_recipients"),candidates:J,selectedMemberIds:s.purpose.responseRecipientMemberIds??[],onChange:$e,disabled:!d||I||!!X,loading:I})}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_safety_profile",Re.safetyProfiles,R(Re.safetyProfiles,c=>c.id===s.aiConfiguration.safety.profile.id&&c.version===s.aiConfiguration.safety.profile.version),c=>v(h=>{h.aiConfiguration.safety.profile={id:c.id,version:c.version}}),"enhanced-survey-safety-profile")}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_response_policy",Re.responsePolicies,R(Re.responsePolicies,c=>c.id===s.aiConfiguration.safety.responsePolicy.id&&c.version===s.aiConfiguration.safety.responsePolicy.version),c=>v(h=>{h.aiConfiguration.safety.responsePolicy={id:c.id,version:c.version}}
1))}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_danger_policy",Re.immediateDangerPolicies,R(Re.immediateDangerPolicies,c=>c.id===s.aiConfiguration.safety.immediateDangerPolicy.id&&c.version===s.aiConfiguration.safety.immediateDangerPolicy.version),c=>v(h=>{h.aiConfiguration.safety.immediateDangerPolicy={id:c.id,version:c.version}}))}),e.jsx(se,{item:!0,xs:12,md:6,children:e.jsx($n,{id:"enhanced-survey-safeguard-recipients",label:n("enhanced_survey_room_safeguard_recipients"),candidates:J,selectedMemberIds:s.aiConfiguration.safety.safeguardRecipientMemberIds??[],onChange:c=>v(h=>{h.aiConfiguration.safety.safeguardRecipientMemberIds=c}),disabled:!d||I||!!X,loading:I,required:He})}),e.jsx(se,{item:!0,xs:12,md:6,children:H("enhanced_survey_report_recipient",Re.reportRecipientProfiles,R(Re.reportRecipientProfiles,c=>c.id===s.aiConfiguration.safety.reportRecipientProfile.id&&c.version===s.aiConfiguration.safety.reportRecipientProfile.version),c=>v(h=>{h.aiConfiguration.safety.reportRecipientProfile={id:c.id,version:c.version}}
1))})]})]})]})},ua=({stage:n})=>{const{t}=Te(),r=Qn(),{roomId:i="",surveyId:_="",version:s=""}=es();if(!i||!_||!s)return e.jsx(gn,{maxWidth:"md",sx:{py:8},children:e.jsx(de,{severity:"error",children:t("enhanced_survey_invalid_route")})});const o=as(r.state,i,_,s);return e.jsx(yr,{roomId:i,surveyId:_,versionLabel:s,initialVersion:o,children:e.jsx(jr,{stage:n,children:n==="setup"?e.jsx(Fr,{}):n==="build"?e.jsx(Pr,{}):e.jsx(Dr,{})})},`${i}-${_}-${s}`)};export{ua as default}; 2//# sourceMappingURL=EnhancedSurveyVersionPage-C5rMUIwK.js.map
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.