@ukhomeoffice/cop-react-form-renderer 8.0.3 → 8.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -5
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
`);return i===-1?"":r.stack.slice(i+1)})();try{if(!s.stack)s.stack=o;else if(o){const i=o.indexOf(`
|
|
7
7
|
`),l=i===-1?-1:o.indexOf(`
|
|
8
8
|
`,i+1),a=l===-1?"":o.slice(l+1);String(s.stack).endsWith(a)||(s.stack+=`
|
|
9
|
-
`+o)}}catch{}}throw s}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=De(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:o}=n;s!==void 0&&At.assertOptions(s,{silentJSONParsing:he.transitional(he.boolean),forcedJSONParsing:he.transitional(he.boolean),clarifyTimeoutError:he.transitional(he.boolean),legacyInterceptorReqResOrdering:he.transitional(he.boolean),advertiseZstdAcceptEncoding:he.transitional(he.boolean)},!1),r!=null&&(m.isFunction(r)?n.paramsSerializer={serialize:r}:At.assertOptions(r,{encode:he.function,serialize:he.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),At.assertOptions(n,{baseUrl:he.spelling("baseURL"),withXsrfToken:he.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&m.merge(o.common,o[n.method]);o&&m.forEach(["delete","get","head","post","put","patch","query","common"],y=>{delete o[y]}),n.headers=ue.concat(i,o);const l=[];let a=!0;this.interceptors.request.forEach(function(p){if(typeof p.runWhen=="function"&&p.runWhen(n)===!1)return;a=a&&p.synchronous;const A=n.transitional||An;A&&A.legacyInterceptorReqResOrdering?l.unshift(p.fulfilled,p.rejected):l.push(p.fulfilled,p.rejected)});const c=[];this.interceptors.response.forEach(function(p){c.push(p.fulfilled,p.rejected)});let u,h=0,f;if(!a){const y=[Qn.bind(this),void 0];for(y.unshift(...l),y.push(...c),f=y.length,u=Promise.resolve(n);h<f;)u=u.then(y[h++],y[h++]);return u}f=l.length;let E=n;for(;h<f;){const y=l[h++],p=l[h++];try{E=y(E)}catch(A){p.call(this,A);break}}try{u=Qn.call(this,E)}catch(y){return Promise.reject(y)}for(h=0,f=c.length;h<f;)u=u.then(c[h++],c[h++]);return u}getUri(t){t=De(this.defaults,t);const n=Js(t.baseURL,t.url,t.allowAbsoluteUrls);return Gs(n,t.params,t.paramsSerializer)}};m.forEach(["delete","get","head","options"],function(t){Re.prototype[t]=function(n,s){return this.request(De(s||{},{method:t,url:n,data:(s||{}).data}))}});m.forEach(["post","put","patch","query"],function(t){function n(s){return function(o,i,l){return this.request(De(l||{},{method:t,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}Re.prototype[t]=n(),t!=="query"&&(Re.prototype[t+"Form"]=n(!0))});let ha=class er{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(r=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](r);s._listeners=null}),this.promise.then=r=>{let o;const i=new Promise(l=>{s.subscribe(l),o=l}).then(r);return i.cancel=function(){s.unsubscribe(o)},i},t(function(o,i,l){s.reason||(s.reason=new rt(o,i,l),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=s=>{t.abort(s)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new er(function(r){t=r}),cancel:t}}};function ma(e){return function(n){return e.apply(null,n)}}function pa(e){return m.isObject(e)&&e.isAxiosError===!0}const sn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(sn).forEach(([e,t])=>{sn[t]=e});function tr(e){const t=new Re(e),n=vs(Re.prototype.request,t);return m.extend(n,Re.prototype,t,{allOwnKeys:!0}),m.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return tr(De(e,r))},n}const Z=tr(st);Z.Axios=Re;Z.CanceledError=rt;Z.CancelToken=ha;Z.isCancel=Ws;Z.VERSION=Tn;Z.toFormData=Rt;Z.AxiosError=D;Z.Cancel=Z.CanceledError;Z.all=function(t){return Promise.all(t)};Z.spread=ma;Z.isAxiosError=pa;Z.mergeConfig=De;Z.AxiosHeaders=ue;Z.formToJSON=e=>Ks(m.isHTMLForm(e)?new FormData(e):e);Z.getAdapter=Zs.getAdapter;Z.HttpStatusCode=sn;Z.default=Z;const{Axios:af,AxiosError:cf,CanceledError:uf,isCancel:df,CancelToken:ff,VERSION:hf,all:mf,Cancel:pf,isAxiosError:Ef,spread:Af,toFormData:yf,AxiosHeaders:Tf,HttpStatusCode:Sf,formToJSON:Cf,getAdapter:gf,mergeConfig:bf,create:wf}=Z,ce={onAction:(e,t)=>({formData:e,patch:t}),onChange:e=>{},onFormComplete:()=>{},onFormLoad:e=>{},onGetComponent:(e,t)=>null,onGetCYA:e=>null,onGetCYARows:(e,t,n)=>null,onGoingBack:()=>{},onPageChange:(e,t)=>e,onRequest:e=>e,onSubmit:(e,t,n,s)=>{typeof n=="function"&&n()},onValidate:(e,t)=>t,onCancel:e=>{}},es=Object.keys(ce),nr=R.createContext(),sr=({overrides:e={onAction:void 0,onCancel:void 0,onChange:void 0,onFormComplete:void 0,onFormLoad:void 0,onGetComponent:void 0,onGetCYA:void 0,onGetCYARows:void 0,onGoingBack:void 0,onPageChange:void 0,onRequest:void 0,onSubmit:void 0,onValidate:void 0},children:t=null})=>{const[n,s]=R.useState({onAction:e?.onAction||ce.onAction,onChange:e?.onChange||ce.onChange,onFormComplete:e?.onFormComplete||ce.onFormComplete,onFormLoad:e?.onFormLoad||ce.onFormLoad,onGetComponent:e?.onGetComponent||ce.onGetComponent,onGetCYA:e?.onGetCYA||ce.onGetCYA,onGetCYARows:e?.onGetCYARows||ce.onGetCYARows,onGoingBack:e?.onGoingBack||ce.onGoingBack,onPageChange:e?.onPageChange||ce.onPageChange,onRequest:e?.onRequest||ce.onRequest,onSubmit:e?.onSubmit||ce.onSubmit,onValidate:e?.onValidate||ce.onValidate,onCancel:e?.onCancel||ce.onCancel}),r=(i,l)=>{es.includes(i)&&s(a=>({...a,[i]:l||ce[i]}))},o=i=>{es.includes(i)&&s(l=>({...l,[i]:ce[i]}))};return d.jsx(nr.Provider,{value:{hooks:n,addHook:r,removeHook:o},children:t})},Pe=()=>R.useContext(nr),Ea=()=>{const{hooks:e}=Pe(),[t,n]=R.useState({});return R.useEffect(()=>{const s=Z.create({baseURL:"/"});return s.interceptors.request.use(e.onRequest),s.interceptors.response.use(r=>r,async r=>Promise.reject(r)),n({instance:s}),()=>{n({})}},[e]),t.instance},Cn=R.createContext(),rr=({children:e=null})=>{const{hooks:t}=Pe(),[n,s]=R.useState([]),[r,o]=R.useState([]),i=f=>{f!==void 0&&o(E=>[...E,...f].filter(y=>!!y))},l=f=>{typeof f=="function"&&o(E=>E.filter(y=>!f(y)))},a=()=>{r.length&&o([])},c=f=>{f!==void 0&&s(E=>[...E,...f].filter(y=>!!y))},u=()=>{o([]),s([])},h={page:f=>{const E=w.Validate.page(f,r),y=t.onValidate(f,E);return s(y),y},pages:f=>{const E=f.map(p=>w.Validate.page(p,r)),y=f.flatMap((p,A)=>t.onValidate(p,E[A]));return s(y),y}};return d.jsx(Cn.Provider,{value:{errors:n,addErrors:c,clearErrors:u,queuedErrors:r,enqueueErrors:i,dequeueErrors:l,clearQueuedErrors:a,validate:h},children:e})},He=()=>R.useContext(Cn),Yt={},Ht={},Aa="idle",ya="fetching",or="fetched",ir="error",Ta=(e,t=!0)=>{const n=Ea(),s=R.useRef(Z.CancelToken.source()),[r,o]=R.useState(Aa),[i,l]=R.useState(null),[a,c]=R.useState(null),u=()=>{s.current&&s.current.cancel()};return R.useEffect(()=>{if(!e||!n)return;(async()=>{try{l(null),o(ya);let f;if(t&&Yt[e])f=Yt[e];else{if(t&&Ht[e])throw Ht[e];f=(await n.get(e,{cancelToken:s.current.token}).catch(y=>{throw l(y),y})).data,t&&(Yt[e]=f)}c(f),o(or)}catch(f){t&&(Ht[e]=f),l(f),c(null),o(ir)}})()},[n,e,t]),{status:r,error:i,data:a,cancelRequests:u}},Sa="loading",yt="complete",Ca=e=>{const t=e.data;if(t&&!t.options||t?.url)return S.Utils.interpolateString(t.url,e.formData)},ga=(e,t)=>{const n=Ca({...e,formData:t}),{status:s,data:r}=Ta(n,e?.data?.useCache),[o,i]=R.useState([]),[l,a]=R.useState(Sa);return R.useEffect(()=>{n?s===or?(r&&i(de.refData.toOptions(r.data||r,e.item)),a(yt)):s===ir&&(i([]),a(yt)):(e.data&&e.data.options&&i(de.refData.toOptions(e.data.options,e.item)),a(yt))},[e.id,s,r,n]),{data:o,status:l}},Xe=(e,t)=>{const n=te(e,["fieldId","displayMenu","showCharacterCount","readonly"]);return d.jsx(S.FormGroup,{...n,onChange:null,children:t})},gn=(e,t,n,s,r={})=>{if(!t)return[];const o=w.CollectionPage.getData(t.collection.name,t.formData)||[];let i=[];return o.forEach(l=>{r={...r,[`${t.collection.name.split(".").pop()}ActiveId`]:l.id};const a=t.childPages?.flatMap(c=>{const u={...c,formData:{...n,...r}};if(c.childPages)return gn(e,u,n,s,r);const h=w.Validate.page(u);return s.onValidate(u,h)});i=i.concat(a.map(c=>({...c,entryId:l.id,showFor:e.id,raisedBy:e.id})))}),i},bn=({value:e,component:t,formData:n,placeholder:s})=>e?t?d.jsx(Ve,{component:{...t,readonly:!0},wrap:!1,value:e,formData:n}):Object.prototype.hasOwnProperty.call(e,"label")?e.label:e:(Object.prototype.hasOwnProperty.call(t||{},"cyaPlaceholder")?t?.cyaPlaceholder:s)||d.jsx(S.VisuallyHidden,{children:"No answer"}),ba="Continue",rn=({action:e,onAction:t,...n})=>{const s=typeof e=="string"?W.DEFAULTS[e]:e,r=W.DEFAULTS[e.type];return s?d.jsx(S.Button,{...n,className:s.className,classModifiers:s.classModifiers,start:s.start||!1,name:s.label,onClick:s.disabled?()=>{}:()=>t(s),children:s.label||r?.label||ba}):null},wa="hods-form-confirmation",_a="Are you sure?",Ia="Confirm",Pa=({id:e,message:t,confirmLabel:n,children:s,onConfirm:r,onCancel:o,classModifiers:i=[]})=>{const l=S.Utils.classBuilder(wa,i,"");return d.jsxs("div",{id:e,className:l(),role:"alert",children:[d.jsx("h2",{children:t||_a}),s,d.jsx(S.Button,{classModifiers:"warning",onClick:r,autoFocus:!0,children:n||Ia}),d.jsx(S.Button,{classModifiers:"secondary",onClick:o,children:"Cancel"})]})},wn=e=>e&&Array.isArray(e.components)?e.components.flatMap(t=>t.type===_.CONTAINER?wn(t):ot.editable(t)?t:null).filter(t=>!!t):[],xa=e=>{const t=e.full_path||e.fieldId;return e.components.map(n=>{const s=t?`${t}.${n.fieldId}`:n.fieldId,r={...n,full_path:s};return n.type===_.CONTAINER?on(r):(n.type===_.RADIOS&&r.data?.options?.forEach((o,i)=>{o.nested?.forEach((l,a)=>{l.type===_.CONTAINER&&(r.data.options[i].nested[a]=on(l))})}),r)})},on=e=>{if(e){const t=xa(e);return{...e,components:t}}return e},Oa=(e,t)=>e.some(n=>ot.show(n,t)),Ra=(e,t)=>{if(!e)return!1;if(e.show_when)return e.show_when.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t);const n=wn(e);return n.length>0?Oa(n,t):!0},Lt={editableComponents:wn,setup:on,show:Ra},Na=(e,t)=>e.some(n=>Ie(n,t)),Dt=(e,t)=>{if(!e)return!1;if(e.show_when)return e.show_when.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t);const n=Lt.editableComponents(e);return n.length>0?Na(n,t):!0},La=(e,t,n)=>{if(!e)return null;const s=[];e.childPages.forEach(l=>{!l.summaryQuickEdit||!Dt(l,{...t,...n})||l.summaryQuickEdit.forEach(a=>{if(typeof a=="string"){s.push({...l.components.find(h=>h.id===a)});return}const c=l.components.find(h=>h.id===a.use);if(!c)return;const u={...c,...a};if(a.show_when){Ue(a.show_when,{...t,...n})&&s.push({...u,show_when:c.show_when||[]});return}s.push(u)})});const r={...e.childPages[0],formData:t};r.components=s,r.actions=[{type:"save",label:"Save",validate:!0,classModifiers:"primary"},{type:"cancel",label:"Cancel",classModifiers:"secondary"}];const{id:o,...i}=n;return r.formData={...r.formData,...i,[`${e.collection?.name?.split(".").pop()}ActiveId`]:n.id},delete r.title,delete r.collection,r},_n=({actions:e,onAction:t})=>!e||e.length===0?null:d.jsx(S.ButtonGroup,{children:e.map((n,s)=>d.jsx(rn,{action:n,onAction:t},s))}),Da=e=>{if(!e?.customValidation)return!1;const t=e?.customValidation.find(n=>n.runWhen?.onLoad===!0);return t&&t.runWhen?.constraint?ae.meetsOne(t.runWhen?.constraint,e.formData):!1},lr="hods-form__page",In=({page:e,pages:t=[],onAction:n,onWrapperChange:s=void 0,onTopLevelChange:r=void 0,onChange:o=void 0,hashLink:i=!1,classBlock:l=lr,classModifiers:a=[],className:c="",submitting:u=!1,pageId:h})=>{const[f,E]=R.useState({}),{errors:y,validate:p}=He(),[A,T]=R.useState({}),[N,C]=R.useState(!1),b=R.useMemo(()=>Da(e),[e]);R.useEffect(()=>{C(!0)},[]),R.useEffect(()=>{N&&b&&p.page(e)},[h,N]);const P=({target:I})=>{const k=e,{value:O}=I;O?(k.formData[I.name]=O,E(x=>({...x,[I.name]:O})),T(x=>({...x,[I.component]:I.label}))):(delete k.formData[I.name],E(x=>{const{[I.name]:j,...$}=x;return $}),T(x=>{const{[I.component]:j,...$}=x;return $})),typeof o=="function"&&o(e.formData)};R.useEffect(()=>{const I=document.title.replace("Error: ","");document.title=y.length>0?"Error: "+I:I},[y]);const U=w.classBuilder(l,a,c),g=e;g.actions=g.actions?.map(I=>I.label?{...I,label:w.interpolateString(I.label,g.formData)}:I),g.formData=w.Operate.runPageOperations(g,{...g.formData,...f},s||P);const L=e.title?d.jsx(S.Heading,{size:e.titleSize,children:w.FormPage.getTitle(e.title,e.formData)}):d.jsx(S.Label,{id:e.id,required:e.required,hideOptionalSuffix:e.hideOptionalSuffix,children:e.label}),v=e.components.filter(I=>w.Component.show(I,e.formData)).map((I,k)=>d.jsx(Ve,{component:I,onAction:O=>n(O,f,A),onChange:s||P,onTopLevelChange:r||P,value:e.formData[I.fieldId]||f[I.fieldId],formData:e.formData,pages:t,submitting:u},k));let F=null;return b&&y?.length>0?F=[{error:e?.customValidation?.[0]?.message}]:y?.length>0&&!b&&(F=y),d.jsxs("div",{className:U(),children:[F&&d.jsx(S.ErrorSummary,{errors:F,hashLink:i}),e.fieldset&&d.jsxs("fieldset",{className:"govuk-fieldset",children:[d.jsx("legend",{className:"govuk-fieldset__legend",children:L}),v]}),!e.fieldset&&d.jsxs(d.Fragment,{children:[L,v]}),d.jsx(_n,{actions:e.actions?.filter(I=>w.Component.show(I,e.formData)),onAction:I=>n(I,f,A)})]},e.id)},ts="hods-form-banner-strip",ar=({id:e,banners:t=[],formData:n,classModifiers:s})=>{const r=w.classBuilder(ts,s,""),o=t.filter(i=>w.Component.show(i,n));return d.jsx("div",{id:e,className:r(),children:o.map((i,l)=>{const a=`${e}-banner-${l}`;if(typeof i=="string"||i.type==="plain"){const c=typeof i=="string"?i:i.text;return d.jsx("div",{id:a,className:r("banner"),children:d.jsx(S.Markup,{content:w.interpolateString(c,n)})},a)}return d.jsx(S.Tag,{classBlock:`${ts}__tag`,classModifiers:i.classModifiers,text:w.interpolateString(i.text,n)},a)})})},va=e=>{if(e&&e.action){if(typeof e.action.onAction=="function")return{onClick:()=>e.action.onAction(e),onKeyPress:t=>{t.key==="Enter"&&e.action.onAction(e)},tabIndex:"0"};if(e.action.page)return{href:`/${e.action.page}`}}return{}},Pn=({row:e})=>{const[t,n]=R.useState({});return R.useEffect(()=>{n(va(e))},[e,n]),e.action?d.jsxs(S.Link,{...t,children:[e.action.label,e.action.aria_suffix&&d.jsxs(S.VisuallyHidden,{children:[" ",e.action.aria_suffix]})]}):null},cr=({row:e,classes:t,showAction:n=!1})=>d.jsxs("dl",{className:t("row"),role:"listitem",children:[d.jsxs("dt",{className:t("key"),children:[e.key,!e.required&&" (optional)"]}),d.jsx("dd",{className:t("value"),children:e.value}),n&&d.jsx("dd",{className:t("actions"),children:e.action&&d.jsx(Pn,{row:e})})]}),ur=({title:e,classes:t})=>d.jsx("div",{className:`${t("row")} ${t("title")}`,role:"listitem",children:d.jsx(S.SmallHeading,{children:e})}),Tt=(e,t,n,s,r)=>{const o={...e,formData:{...e.formData,...s}},i=jt(o,t);return t.type==="title"?d.jsx(ur,{title:t.key,classes:n}):d.jsx(cr,{row:{key:i.key,value:d.jsx(bn,{value:i.value||t.value,component:i.component,formData:o.formData,placeholder:r}),required:i.required},classes:n},`${i.fieldId}`)},Fa="govuk-summary-card",ja="govuk-summary-list",ft="Item",ht="Change",ns="Delete",Ua="warning",Ma=({id:e,entryData:t,config:n,onFullEdit:s,onDelete:r,masterPage:o,classModifiers:i=null,optionalFieldPlaceholder:l=null})=>{const a=S.Utils.classBuilder(Fa,i,n.className),c=S.Utils.classBuilder(ja,[]);return d.jsxs("div",{className:a(),id:e,children:[d.jsxs("div",{className:a("title-wrapper",[],"dark"),children:[d.jsxs("div",{className:a("title-content"),children:[d.jsx("h2",{className:a("title"),children:S.Utils.interpolateString(n.title||ft,{...t,index:t.index+1})}),n.banners&&d.jsx(ar,{id:`BannerStrip${t.id}`,banners:n.banners,formData:t})]}),d.jsxs("ul",{className:a("actions"),children:[d.jsx("li",{className:a("action"),children:n.changeAction&&typeof s=="function"&&n.changeAction.classModifiers?d.jsx(S.Button,{id:`${e}.changeButton`,onClick:()=>s(n.changeAction.page,t.id),classModifiers:n.changeAction.classModifiers,"aria-label":S.Utils.interpolateString(`${n.changeAction?.label||ht} ${n.title||ft}`,{...t,index:t.index+1}),children:n.changeAction?.label||ht}):d.jsx("button",{type:"button",className:"govuk-link govuk-link-button",onClick:()=>s(n.changeAction.page,t.id),"aria-label":S.Utils.interpolateString(`${n.changeAction?.label||ht} ${n.title||ft}`,{...t,index:t.index+1}),children:n.changeAction?.label||ht})}),d.jsx("li",{className:a("action"),children:n.deleteAction&&typeof r=="function"&&d.jsx(S.Button,{id:`${e}.deleteButton`,onClick:()=>r(t),classModifiers:n.deleteAction.classModifiers||Ua,"aria-label":S.Utils.interpolateString(`${n.deleteAction?.label||ns} ${n.title||ft}`,{...t,index:t.index+1}),children:n.deleteAction.label||ns})})]})]}),d.jsx("div",{className:a("content"),children:d.jsx("dl",{className:c(),role:"list",children:o?.childPages?.flatMap(u=>{const h=u.components.map(f=>w.Component.elevateNested([f],t)).flat().filter(Boolean);return u.summaryLayout?.sections?.flatMap(f=>{const y=f.columns.filter(p=>ae.meetsAll(p,{...u.formData,...t})).flatMap(p=>p.fields||[]);return y.length?y.flatMap(p=>{const A=h.find(T=>T.fieldId===p);return A?Tt(u,A,c,t,l):null}):null})})})})]})},ka=({id:e,"data-testid":t,actions:n,onFullEdit:s=null,entryData:r,formData:o,name:i,autoFocus:l})=>Array.isArray(n)?d.jsx(d.Fragment,{children:n.filter(a=>w.Component.show(a,o)).map(a=>d.jsx(S.Button,{id:e,"data-testid":t,onClick:()=>s(a?.page,r.id),classModifiers:a?.classModifiers||rs,"aria-label":w.FormPage.getConditionalText(a?.aria_label,r),name:i,autoFocus:l,children:a?.label||ss},e))}):d.jsx(S.Button,{id:e,"data-testid":t,onClick:()=>s(n?.page,r.id),classModifiers:n?.classModifiers||rs,"aria-label":w.FormPage.getConditionalText(n?.aria_label,r),name:i,autoFocus:l,children:n?.label||ss}),Ba=e=>{if(e.page)return e.page;const t=e.href||e.url;if(t)return t.split("/").pop()},vt=(e,t,n)=>{const s=t?.cya_link;return e!==!0&&s?{page:Ba(s)||t.id||"#",label:s.label||"Change",aria_suffix:s.aria_suffix,onAction:n}:null},dr=[_.ALERT,_.COLLECTION_SUMMARY,_.DETAILS,_.HEADING,_.HTML,_.INSET_TEXT],Ct=(e,t)=>{if(!e||dr.includes(e.type)||Object.prototype.hasOwnProperty.call(e,"show_on_cya")&&!e.show_on_cya)return!1;if(e.hideOnCyaWhenEmpty)if(e.type===_.COLLECTION){if(!se(t,e.full_path||e.fieldId)?.length)return!1}else{const n=se(t,e.fieldId);if(!n&&n!==!1&&n!==0)return!1}return e.type===_.CONTAINER?Lt.show(e,t):ot.show(e,t)},fr=e=>({...e,components:e.components.map(t=>Array.isArray(t.components)?{...t,components:t.components.map(n=>dr.includes(n.type)?null:{...n,...!n.full_path&&{full_path:`${t.full_path||`${e.full_path}.${t.fieldId}`}.${n.fieldId}`}}).filter(n=>!!n)}:{...t,...!t.full_path&&{full_path:`${e.full_path||e.fieldId}.${t.fieldId}`}})}),$a=(e,t)=>[{pageId:e.id,key:e.components[0].labels?.empty||"Nothing entered",required:e.required,action:vt(!1,e,t)}],Ya=(e,t,n,s)=>({id:t.id,fieldId:t.id,type:_.CONTAINER,required:e.required,full_path:s,components:e.item.map(r=>({...r,label:S.Utils.interpolateString(r.label,{...t,index:n}),full_path:`${s}.${r.fieldId}`}))}),Ha=(e,t,n,s,r)=>{const o={...$e,...e.labels};return o.item?{pageId:n,fieldId:e.fieldId,full_path:r,key:S.Utils.interpolateString(o.item,{...t,index:s}),type:"title",action:null}:null},xn=(e,t,n,s,r)=>Array.isArray(n)&&n.length&&Ct(t,e.formData)?n.flatMap((o,i)=>{const l=(t.countOffset||0)+i+1,a=`${t.full_path||t.fieldId}[${i}]`;let c=Ya(t,o,l,a);return c=fr(c),[Ha(t,o,e.id,l,a),...qe(e,c,o,s,r)]}).filter(o=>!!o):$a(e,s),Va="hods-form-summary-card-details",hr=({masterPage:e,childCollections:t=[],formData:n,entryData:s,classModifiers:r,hideChildSectionTitles:o=!1,optionalFieldPlaceholder:i})=>{const l=w.classBuilder(Va,r),a=R.useMemo(()=>t.map(u=>e.childPages.find(h=>h.collection?.name===u)).filter(u=>!!u),[e,t]),c=(u,h,f)=>{let E=0;return u.flatMap((y,p)=>{let A=0;const T=y.fields?.flatMap(C=>h.filter(P=>P.fieldId===C).map(P=>{if(!P||!Ie(P,{...f.formData,...s}))return null;if(P.type===_.CONTAINER){const U=qe(f,P,s);return A+=1,d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:U.map(g=>{const L={...s,[g.fieldId]:s[P.fieldId]?.[g.fieldId]};return Tt(f,{...g,label:g.key},l,L,i)})},C)}if(P.type===_.COLLECTION){const U=xn({...f,formData:{...f.formData,...s}},P,s[P.id]);A+=1;let g=0;return d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:U.map(L=>{const v={...s,[L.fieldId]:s[P.fieldId]?.[L.fieldId]},F=Tt(f,{...L,label:L.key},l,v,i);return L.type==="title"&&(g+=1,g>1)?d.jsx("div",{style:{marginTop:"40px"},children:F}):F})},C)}return A+=1,d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:Tt(f,P,l,s,i)},C)})).filter(C=>!!C);return!(p===u.length-1)&&T.length!==0?(E+=2,[...T,d.jsx("div",{className:l("divider"),style:{"--column":E}},`divider${E}`)]):T}).filter(y=>!!y)};return e?.childPages?.filter(u=>w.FormPage.show(u,{...n,...s})).map(u=>{const h=w.Component.elevateNested(u?.components,s);return u.summaryLayout?.sections.map(f=>{if(f.show_when&&!w.Condition.meetsAll(f.show_when,{...n,...s}))return null;if(f.type==="childCollection"){const y=a.find(A=>A.collection.name===f.collectionName),p=s[f.collectionName.split(".").pop()]||[];return y&&p.length>0?d.jsxs(d.Fragment,{children:[d.jsx("h3",{className:l("section-title"),children:f.title}),p.map(A=>d.jsx(hr,{masterPage:y,childMasterPages:[],formData:{...n,...s,...A},entryData:A,hideChildSectionTitles:!0,optionalFieldPlaceholder:i}))]}):null}const E=f.columns.filter(y=>ae.meetsAll(y,{...u.formData,...s}));return d.jsxs("div",{className:l("section"),children:[!o&&d.jsx("h3",{className:l("section-title"),children:w.FormPage.getConditionalText(f.title,{...u.formData,...s})}),d.jsx("dl",{className:l("section-content"),style:{"--dividers":E.length-1},children:c(E,h,u)})]},f.title)})}).filter(u=>!!u)||null},qa="hods-form-summary-card",ss="Change",Ga="Delete",Ka="Quick Edit",Wa="Duplicate",za="Full details",rs="secondary",os=({id:e,entryData:t,config:n,classModifiers:s,onFullEdit:r,onDelete:o,onDuplicate:i,onQuickEdit:l,parentCollectionName:a,childCollections:c=[],formData:u,masterPage:h,hideDetails:f=!1})=>{const[E,y]=R.useState(!1),p=S.Utils.classBuilder(qa,s,n.className),A=R.useMemo(()=>n.quickEdit?La(h,u,t):null,[h,n,u,t,E]),{addErrors:T,resetQuickEditErrors:N,clearTopLevelErrorsForCard:C,validate:b}=He(),{hooks:P}=Pe(),U=async(g,L)=>{if(g.type==="cancel"&&(y(v=>!v),N?.()),g.type==="save"&&typeof l=="function"){const v={...A.formData,...L,[`${a}ActiveId`]:t.id},F=b.page({...A,formData:v});if(F.length)return;let I;await P.onSubmit("quickEdit",v,()=>{},O=>{I=O}),I&&T(I);const k=F.concat(I);if(k.length===0||k.length===1&&k[0]===void 0){C();const O=w.CollectionPage.getData(a,u),{isDuplicate:x,...j}=O[t.index];O[t.index]={...j,...L},l({target:{name:a,value:O}}),y($=>!$)}}};return n.listView?d.jsx(Ma,{id:e,entryData:t,config:n,onFullEdit:r,onDelete:o,masterPage:h,classModifiers:s,optionalFieldPlaceholder:n.fullDetails?.optionalFieldPlaceholder}):d.jsxs("div",{className:p(),id:e,children:[d.jsxs("div",{className:p("header"),children:[d.jsxs("div",{className:p("header-content"),children:[n.banners&&d.jsx(ar,{id:`BannerStrip${t.id}`,banners:n.banners,formData:t}),d.jsx("h2",{id:`${e}.titleText`,className:p("header-content-title"),children:w.FormPage.getTitle(n.title,t)}),n.details&&d.jsx("div",{id:`${e}.titleDetail`,className:p("header-content-detail"),children:w.FormPage.getConditionalText(n.details,t)})]}),d.jsxs("div",{className:p("header-actions"),children:[n.quickEdit&&d.jsx(S.Button,{"data-testid":"quickedit-button",id:`${e}.quickEditButton`,onClick:()=>y(g=>!g),classModifiers:"primary",disabled:E,name:"QuickEdit",autoFocus:n.focusOn,children:Ka}),n.changeAction&&typeof r=="function"&&d.jsx(ka,{id:`${e}.changeButton`,"data-testid":"change-button",actions:n.changeAction,onFullEdit:r,entryData:t,formData:u,name:"Change",autoFocus:n.focusOn}),n.deleteAction&&typeof o=="function"&&d.jsx(S.Button,{id:`${e}.deleteButton`,onClick:()=>o(t),classModifiers:"secondary","aria-label":w.FormPage.getConditionalText(n.deleteAction?.aria_label,t),name:"Delete",children:n.deleteAction?.label||Ga}),n.duplicateAction&&typeof i=="function"&&d.jsx(S.Button,{"data-testid":"duplicate-button",id:`${e}.duplicateButton`,onClick:()=>{i(t)},classModifiers:"secondary","aria-label":w.FormPage.getConditionalText(n.duplicateAction?.aria_label,t),name:"Duplicate",autoFocus:n.focusOn,children:n.duplicateAction?.label||Wa})]})]}),E&&A&&d.jsx(In,{page:A,onAction:(g,L)=>U(g,L),className:p("editpage")}),d.jsx("div",{className:p("body"),children:!f&&d.jsx(S.Details,{summary:n.detailsTitle||za,className:"details",children:d.jsx(hr,{masterPage:h,childCollections:c,formData:u,entryData:t,optionalFieldPlaceholder:n.fullDetails?.optionalFieldPlaceholder})})})]})},Ja=({entryId:e,topLevelErrors:t=[],clearTopLevelErrorsForCard:n,children:s})=>{const{hooks:r}=Pe(),o=t.filter(h=>h.entryId===e)||[],[i,l]=R.useState(null),a=()=>{l(null)},c=h=>{l(f=>(f??[]).concat(h))},u={page:h=>{const f=w.Validate.page(h),E=r.onValidate(h,f);return l(E),E}};return d.jsx(Cn.Provider,{value:{addErrors:c,errors:i===null?[...o]:i,resetQuickEditErrors:a,clearTopLevelErrorsForCard:n,validate:u},children:s})},is="Add",Xa=({config:e,formData:t,onAction:n,onChange:s,onTopLevelChange:r,pages:o=[]})=>{const{hooks:i}=Pe(),{errors:l,addErrors:a,clearErrors:c,queuedErrors:u,enqueueErrors:h,dequeueErrors:f}=He(),[E,y]=R.useState(null),p=R.useMemo(()=>w.CollectionPage.getData(e.collectionName,t)||[],[t]),A=Array.isArray(p)&&p.length>0?p.reduce((L,v)=>v.isDuplicate&&(!L||v.id>L.id)?v:L,null):null,T=R.useMemo(()=>{const L=e.collectionName.split(".");let v=w.CollectionPage.mergePages(o||[])||[];return L.reduce((F,I,k)=>{const O=k===0?`${F}${I}`:`${F}.${I}`;return k===L.length-1?v?.find(x=>x.collection?.name===O)||null:(v=v.find(x=>x.collection?.name===O)?.childPages||null,O)},"")},[o]),N=R.useMemo(()=>e.card.listView?T.childPages?.reduce((v,F)=>{const I=et(F.components,{...t,...E});return v.concat(I)},[])||[]:[],[T,t,E,e.card.listView]),C=()=>{u.length>0&&f(v=>v.raisedBy===e.id);const L=gn(e,T,t,i);L.length>0&&h(L)};R.useEffect(()=>{Array.isArray(p)&&p.length>0&&C()},[p]);const b=(L,v)=>{if(typeof n=="function"){const F=[...p],I=p.findIndex(x=>x.id===v),{isDuplicate:k,...O}=p[I];F[I]={...O},n({type:mt.SAVE_AND_NAVIGATE,page:L,addToFormData:[{field:`${e.collectionName.split(".").pop()}ActiveId`,value:v},{field:e.collectionName,value:F,isCollection:!0}]})}},P=L=>{w.CollectionPage.duplicateEntry(e.collectionName,t,L.id,e.card?.duplicateAction?.fieldsToIgnore||[],{isDuplicate:!0});const v=e.collectionName.split(".").shift();typeof r=="function"&&(r({target:{name:v,value:w.CollectionPage.getData(v,t)}}),C())},U=()=>{if(!E)return;w.CollectionPage.removeEntry(e.collectionName,t,E.id);const L=e.collectionName.split(".").shift();typeof r=="function"&&r({target:{name:L,value:w.CollectionPage.getData(L,t)}}),y(null),C()},g=L=>{const v=N.find(I=>I.fieldId===L);if(!v)return null;const F=jt({...T,formData:{...t,...E}},v);return d.jsx("div",{className:"confirmation-field-value",children:d.jsx(bn,{value:F.value,component:F.component,formData:F.formData})},L)};return d.jsxs("div",{id:e.fieldId,children:[E&&d.jsx(Pa,{id:`${e.fieldId}.confirmation`,message:w.interpolateString(e.confirmation?.message,{...E,index:E.index+1})||null,confirmLabel:w.interpolateString(e.confirmation?.label,E)||null,onConfirm:U,onCancel:()=>y(null),children:e.card.listView?d.jsx("div",{className:"confirmation-content",children:e.confirmation?.displayFields.map(g)}):d.jsx(os,{id:`${e.fieldId}.confirmationChild`,entryData:E,config:e.card?{...e.card,quickEdit:null}:{},masterPage:T,classModifiers:"nested",hideDetails:!0})}),!e.card.listView&&e.addButton&&d.jsx(rn,{id:`${e.fieldId}.addButton`,action:{collection:e.collectionName,label:w.interpolateString(e.addButton.label||is,{documents:p}),page:e.addButton.page,type:mt.COLLECTION_ADD,classModifiers:["secondary"]},onAction:n}),d.jsx("ul",{className:"collection-summary-card-list",children:p.map((L,v)=>{const F=l.filter(O=>O.entryId===L.id).length>0,I={...e.card,...L.isDuplicate&&e.duplicatedCard?e.duplicatedCard:{},...F&&e.errorCard?e.errorCard:{},focusOn:A?.id===L.id},k=`${e.fieldId}.summaryCard${L.id}`;return d.jsx("li",{children:d.jsx(Ja,{entryId:L.id,topLevelErrors:l,clearTopLevelErrorsForCard:()=>{const O=l.filter(x=>x.entryId!==L.id);c(),a(O)},children:d.jsx(os,{id:k,entryData:{...L,index:v},masterPage:T,config:I||{},onFullEdit:b,onDuplicate:P,onDelete:()=>y({...L,index:v}),onQuickEdit:O=>(C(),s(O)),parentCollectionName:e.collectionName.split(".").shift(),childCollections:e.childCollections||[],formData:t,classModifiers:L.id===E?.id?["deleting-summary-card"]:[""],inError:l.filter(O=>O.entryId===L.id).length>0},k)})})})}),e.card.listView&&e.addButton&&d.jsx(rn,{id:`${e.fieldId}.addButton`,action:{collection:e.collectionName,label:w.interpolateString(e.addButton.label||is,{documents:p}),page:e.addButton.page,type:mt.COLLECTION_ADD,classModifiers:["secondary"],customAction:{type:e.addButton.customAction}},onAction:n})]})},Qa="hods-form-collection",Za=({config:e,value:t,formData:n,onChange:s=void 0,onTopLevelChange:r=void 0,wrap:o=!1})=>{const[i,l]=R.useState(t),a=p=>{l(p),typeof s=="function"&&s({target:{name:e.fieldId,value:p}})},c=({target:p})=>{if(typeof s=="function")if(p.name===w.Meta.name)s({target:p});else{const A=i.findIndex(T=>T.id===p.name);a([...i.slice(0,A),p.value,...i.slice(A+1)])}},u=async()=>{a([...i,{id:_t.v4()}])},h=async p=>{a(i.filter(A=>A.id!==p.id))},f=p=>p.initial&&!i.length?p.initial:p.add;R.useEffect(()=>{if(e.focusOnAdd&&Array.isArray(i)&&i.length&&(i.length>e.minimumEntries||!e.minimumEntries)){const p=i[i.length-1]?.id,T=document.getElementById(p)?.childNodes[0]?.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');T&&T.length>0&&T[0].focus()}},[i.length,e.focusOnAdd,e.minimumEntries]),R.useEffect(()=>{e.minimumEntries&&!i.length&&u()},[e.minimumEntries,i.length]);const E={...$e,...e.labels},y=w.classBuilder(Qa,[],e.className);return d.jsxs("div",{className:y(),id:e.id,children:[e.label&&d.jsx(S.Label,{id:e.id,required:e.required,className:y("title"),children:e.label}),Array.isArray(i)&&i.map((p,A)=>{const T=`${e.full_path||e.fieldId}[${A}]`,N=(e.countOffset||0)+A+1,C=w.interpolateString(E.item,{...p,index:N}),b=w.interpolateString(E.remove,{...p,index:N}),P=e.disableAddAndRemove||A===0&&e.minimumEntries?"":e.removeLocation??"start",U=A!==0&&e.subsequentItemStyle?e.subsequentItemStyle:{};return d.jsxs("div",{className:`${y("item")}`,style:U,children:[d.jsxs(S.Label,{id:p.id,required:!0,className:y("item-title"),children:[C,P==="start"&&d.jsx(S.Button,{onClick:()=>h(p),classModifiers:"secondary",children:b})]}),d.jsx(Ln,{container:{id:p.id,fieldId:p.id,type:"container",required:e.required,full_path:T,components:e.item.map(g=>{const{firstOnlyLabel:L,...v}=g;let{hint:F}=g;e.restrictHint&&A>0&&(F=void 0);let{label:I}=g;return A===0&&(I=g.firstOnlyLabel??g.label),{...v,hint:F,readonly:!!(e?.readonly||g.readonly),label:w.interpolateString(I,{...p,index:N}),full_path:`${T}.${g.fieldId}`}})},value:p,formData:n,onChange:c,onTopLevelChange:r,wrap:o}),P==="end"&&d.jsx(S.ButtonGroup,{className:"govuk-!-margin-top-2",children:d.jsx(S.Button,{onClick:()=>h(p),classModifiers:"secondary",children:b})})]},p.id)}),!e.disableAddAndRemove&&d.jsx(S.ButtonGroup,{children:d.jsx(S.Button,{onClick:u,classModifiers:"secondary",children:f(E)})})]})},ec=(e,t,n)=>{const s=e,r=typeof s.value=="object"?s.value?.value:s.value,o=n.find(i=>String(i.id)===r);return s.label=o===void 0?s.value||"":o.label,s.component=t.cya_label,s},tc=(e,t)=>typeof e=="string"?!!S.Utils.interpolateString(e,t):!!e,Vt=(e,t)=>{if(Array.isArray(t)){const n=t.find(s=>s.id===(e.full_path||e.id));if(n){const s={error:n.error};return n.properties&&(s.propsInError=n.properties),s}}},nc=[_.RADIOS,_.CHECKBOXES,_.DATE,_.TIME],sc=e=>e.fieldset||nc.includes(e.type),Ve=({component:e,value:t=null,formData:n=null,wrap:s=!0,onAction:r,onChange:o,onTopLevelChange:i,pages:l=[],submitting:a=!1,...c})=>{const{hooks:u}=Pe(),h=He(),{data:f,status:E}=ga(e,n),[y,p]=R.useState([]);R.useEffect(()=>{E===yt&&p(f)},[e,f,E]);const A=({target:C})=>typeof o=="function"?(e.type===_.EMAIL&&(C.value=C.value.trim()),e.type===_.CHECKBOXES&&Array.isArray(C.value)&&C.value.forEach(b=>{b.children&&b.nested&&(delete b.children,delete b.nested)}),C=ec(C,e,f),e.type===_.SELECT&&C.value===""&&(C.value=null,C.label=null),o({target:C}),!0):!1;if(R.useEffect(()=>{const C=w.Component.defaultValue(e,n);!t&&!n?.[e.fieldId]&&C&&typeof A=="function"&&A({target:{name:e.fieldId,value:C}})},[]),e.type===_.CONTAINER){let C=d.jsx(Ln,{...c,container:e,wrap:s,onChange:A,onTopLevelChange:i,value:t||w.Component.defaultValue(e,n),formData:n});return e.fieldset&&(C=Xe(e,C)),e.additionalValidation&&(C=Xe({...e,...Vt(e,h?.errors)},C)),C}if(e.type===_.COLLECTION)return d.jsx(Za,{...c,config:e,wrap:s,onChange:A,onTopLevelChange:i,value:t||w.Component.defaultValue(e,n),formData:n});if(e.type===_.COLLECTION_SUMMARY)return Xe({...e,...Vt(e,h?.errors)},d.jsx(Xa,{...c,config:e,formData:n,onAction:r,onChange:o,onTopLevelChange:i,pages:l}));const T=C=>{let b=e.full_path||e.fieldId;if(e.pageCollection){const P=w.CollectionPage.getActiveIndex(e.pageCollection.name,n);b=`${`${e.pageCollection.name}[${P}]`}.${b}`}i({target:{name:w.Meta.name,value:w.Meta.documents.setForField(C,n,b,e.allowMultiple)}})},N=({target:C})=>{if(A({target:C})){if(e.type===_.FILE)T([C.value]);else if(e.type===_.MULTI_FILE){const b=C.value.map((P,U)=>({...P,indexInField:U}));T(b)}}};return w.Component.get({...c,...e,id:e.full_path||e.id,...Vt(e,h?.errors),fieldset:sc(e),disabled:tc(e.disabled,n),label:w.interpolateString(e.label,n),content:w.interpolateString(e.content,n),hint:w.interpolateString(e.hint,n),cya_label:w.interpolateString(e.cya_label,n),suffix:w.interpolateString(e.suffix,n),options:y,value:t,onChange:N,onTopLevelChange:i,formData:n,onAction:r,submitting:a},s,u.onGetComponent)},rc=[_.AUTOCOMPLETE,_.CALCULATION,_.CHECKBOXES,_.COLLECTION_SUMMARY,_.DATE,_.EMAIL,_.FILE,_.MULTI_FILE,_.PHONE_NUMBER,_.RADIOS,_.SELECT,_.TEXT,_.TEXT_AREA,_.TIME],mr=e=>rc.includes(e?.type)||e?.isEditable||!1,oc="govuk-list",ic="govuk-body",lc=e=>{const t=te(e),n=S.Utils.interpolateString(e.heading,e.formData),s=S.Utils.interpolateString(e.text,e.formData);return d.jsx(S.Alert,{...t,heading:n,children:s})},ac=e=>{const t=te(e),n=de.getAutocompleteSource(e);return d.jsx(S.Autocomplete,{...t,source:n})},cc=e=>{let t=[];de.getOptions(e,s=>{t=s}),t=t.map(s=>Array.isArray(s.nested)?{...s,children:pr(e,s.nested)}:s);const n=te(e);return d.jsx(S.Checkboxes,{...n,options:t})},uc=e=>{const t=de.applyFormula(e);typeof e.onChange=="function"&&t!==e.value&&e.onChange({target:{name:e.fieldId,value:t}});const n=te(e,["formula"]);return d.jsx(S.TextInput,{...n,readonly:!0})},dc=e=>{const t=te(e);return d.jsx(S.DateInput,{...t})},fc=e=>{const t=te(e,["tagName"]),n=Ft(e);return d.jsx(S.Details,{...t,children:n})},hc=e=>{const t=te(e);return d.jsx(S.FileUpload,{...t})},mc=e=>{const t=te(e);return d.jsx(S.MultiFileUpload,{...t})},pc=e=>{const t=te(e);return d.jsx(S.Heading,{...t,children:e.content})},Ft=e=>{const t=te(e);return d.jsx(S.Markup,{...t})},Ec=e=>{const t=te(e);return d.jsx(S.InsetText,{...t,children:e.content})},Ac=e=>{const t=te(e,["ordered"]),n=e.ordered?"ol":"ul",s=e.ordered?"number":"bullet",r=S.Utils.classBuilder(oc,s),o=t.items?.map(i=>`<li>${i}</li>`).join("");return Ft({...t,className:r(),tagName:n,content:o,type:_.HTML})},yc=e=>{const t=te(e);return Ft({className:ic,...t,tagName:"p",type:_.HTML})},Tc=e=>{let t=[];de.getOptions(e,s=>{t=s}),t=t.map(s=>Array.isArray(s.nested)?{...s,children:pr(e,s.nested)}:s);const n=te(e);return d.jsx(S.Radios,{...n,options:t})},Sc=e=>{const t=te(e);return d.jsx(S.TextArea,{...t})},Cc=e=>{const t=te(e);return d.jsx(S.TextInput,{...t})},gc=e=>{const t=te(e);return d.jsx(S.TimeInput,{...t})},bc=e=>{let t=[];de.getOptions(e,s=>{t=s});const n=te(e);return d.jsx(S.Select,{...n,options:t})},wc=e=>{const t=te(e);return d.jsx(S.WarningText,{...t,children:e.content})},_c=e=>{switch(e.type){case _.HTML:return Ft(e);case _.HEADING:return pc(e);case _.INSET_TEXT:return Ec(e);case _.TEXT:case _.EMAIL:case _.PHONE_NUMBER:return Cc(e);case _.TEXT_AREA:return Sc(e);case _.AUTOCOMPLETE:return ac(e);case _.RADIOS:return Tc(e);case _.CHECKBOXES:return cc(e);case _.DATE:return dc(e);case _.TIME:return gc(e);case _.FILE:return hc(e);case _.MULTI_FILE:return mc(e);case _.WARNING:return wc(e);case _.SELECT:return bc(e);case _.DETAILS:return fc(e);case _.CALCULATION:return uc(e);case _.ALERT:return lc(e);case _.PARAGRAPH:return yc(e);case _.LIST:return Ac(e);default:return null}},Ic=(e,t)=>{const n={...t};if(e.full_path){const s=e.full_path.split(".");s.pop(),s.push(n.fieldId),n.full_path=s.join(".")}return e.formData&&(n.value=e.formData[n.fieldId]||de.getSource(e.formData,n.full_path)||""),"readonly"in n&&delete n.readonly,e.readonly?(n.readonly=e.readonly,d.jsx("div",{children:Er(n,!1)})):d.jsx(Ve,{component:n,value:n.value,onChange:e.onChange,onTopLevelChange:e.onChange,formData:e.formData},n.key)},pr=(e,t)=>{const n=t.filter(s=>!(s.show_when&&!ae.meetsAll(s.show_when,e.formData))).map(s=>d.jsx(d.Fragment,{children:Ic(e,s)},s.id));return n.length>0?n:null},Er=(e,t=!0,n=void 0)=>{if(typeof n=="function"){const r=n(e,t);if(r)return r}const s=_c(e);return s&&t&&mr(e)?Xe(e,s):s},Pc=e=>e.defaultValue||e.defaultObjectValue,xc=e=>{const n=/^(\d{1,2})-\d{1,2}-(\d{4})$/.test(e.defaultValue)?e.defaultValue:null;return e.defaultValue==="today"?K().format("DD-MM-YYYY"):n},Oc=(e,t)=>{const n={...e};let s=null;return!n.literal&&!n.sourced&&(n.sourced={...n}),n.literal&&(s={...n.literal}),n.sourced&&(s=s??{},Object.keys(n.sourced).every(r=>{const o=typeof n.sourced[r]=="string"&&se(t,n.sourced[r]);return o===void 0&&n.skipIfSourceInvalid?(s=null,!1):(s[r]=o||n.sourced[r],!0)})),s},Ar=(e,t)=>Pc(e)?e.type===_.DATE?xc(e):(e.defaultObjectValue?Oc(e.defaultObjectValue,t):null)||e.defaultValue||null:null,Rc={[_.COLLECTION]:[],[_.CONTAINER]:{}},Nc=(e,t)=>e&&(Ar(e,t)||Rc[e.type])||"",ot={clean:te,defaultValue:Nc,defaultValueFromConfig:Ar,editable:mr,elevateNested:et,get:Er,setupContainerPaths:fr,show:Ie,wrap:Xe},Lc=(e,t)=>{e.data?.options?.forEach(n=>{Array.isArray(n.nested)&&Ze(t.formData[e.id],n)&&n.nested.forEach(s=>{const r=s;r.value=t.formData[r.id]})})},jt=(e,t,n)=>{let s="";return e.formData&&t.fieldId&&(s=e.formData[t.fieldId],Lc(t,e)),{pageId:e.id,id:t.id,fieldId:t.fieldId,full_path:t.full_path,key:S.Utils.interpolateString(t.cya_label||t.label,e.formData),required:t.required,component:ot.editable(t)?t:void 0,value:s||"",action:e.cya_link?.singleChangeLink?null:vt(t.readonly,e,n)}},qe=(e,t,n,s,r)=>Ct(t,{...e.formData,...n})?et(t.components.filter(i=>i.show_on_cya===void 0||i.show_on_cya),n).filter(i=>Ct(i,{...e.formData,...n})).flatMap(i=>{const l=n?n[i.fieldId]:void 0;if(typeof r=="function"){const a=r({...e,formData:n},i,s);if(a)return a}return i.type===_.CONTAINER?qe(e,i,{...l,...n},s,r):i.type===_.COLLECTION?xn(e,i,l,s,r):jt({...e,formData:n},i,s)}):null,Dc=e=>{if(!e.conditionalProperties)return e;let t={...e};return e.conditionalProperties.forEach(n=>{w.Condition.met(n.condition,e.formData[n.condition.field])&&(t=Object.assign(t,n.properties))}),t},ls=(e,t,n="text")=>{if(typeof e=="string")return S.Utils.interpolateString(e,t);if(!Array.isArray(e)||Object.keys(t).length===0)return null;const s=e.find(r=>typeof r=="string"?!0:Ue(r.show_when,t));return typeof s=="string"?S.Utils.interpolateString(s,t):S.Utils.interpolateString(s[n],t)},vc=e=>{const t={...e};return t.page||(t.href?t.page=t.href.split("/").pop():t.url&&(t.page=t.url.split("/").pop())),t},Fc=e=>{if(e&&Array.isArray(e.actions))return e.actions.map(t=>{if(typeof t=="string")return W.DEFAULTS[t];if(t&&typeof t=="object"){const n=t;return W.DEFAULTS[n.type]?.validate&&!n.hasOwnProperty("validate")&&(n.validate=!0),vc(n)}}).filter(t=>!!t)},jc=e=>({type:_.HTML,tagName:"p",content:e}),Uc=(e,t)=>{const n=e.use.split("."),s=n.shift();let r=JSON.parse(JSON.stringify({...t.find(l=>l.id===s)})),o=r,i=r;for(;o&&n.length>0;){const l=n.shift();Array.isArray(o.components)?(i=o,i.components=i.components.filter(a=>a.id===l),i.components.length>0?o=i.components[0]:o=void 0):o=void 0}if(o)return o={cya_label:o.label,...o,...e},i&&i.id!==o.id?i.components=[o]:r=o,o.item&&Array.isArray(o.item)&&(o.item=o.item.map(l=>l.use?ln(l,t):l)),r},ln=(e,t)=>{if(e){const n=Uc(e,t);if(n)return n}return{...e}},yr=(e,t,n)=>{if(!e)return null;const s=e.components.map(o=>{if(typeof o=="string")return jc(o);let i;return o.type===_.CONTAINER&&(o.components=o.components.map(l=>l.use?ln(l,t):l)),o.use?i=ln(o,t):i={...o},n?de.refData.setupUrl(i,n):i}),r=Fc(e);return Lt.setup({...e,formData:n,components:s,actions:r})},Mc=(e,t,n)=>Array.isArray(e)?e.map((s,r)=>({...yr(s,t,n),index:r})):[],Tr=(e,t)=>e?.hasOwnProperty("show_on_cya")&&!e.show_on_cya?!1:Dt(e,t),it={applyConditionalProperties:Dc,getConditionalText:ls,get:yr,getAll:Mc,getTitle:(e,t)=>ls(e,t,"title"),show:Dt,showCYA:Tr},kc=(e,t)=>{if(!e)return null;if(!t)return e;const n={...e};return n.show_when?Array.isArray(t)?n.show_when=Array.isArray(n.show_when)?[...t,...n.show_when]:[...t,n.show_when]:n.show_when=Array.isArray(n.show_when)?[...n.show_when,t]:[n.show_when,t]:n.show_when=t,n},Bc=(e,t)=>{const n=e.split(".").pop();t[`${n}ActiveId`]=null},Ut=(e,t)=>{const n=e.split(".").pop();return t[`${n}ActiveId`]||null},$c=e=>typeof e=="number"&&e>=0,Sr=(e,t,n)=>{const s=e[0];if(e.length===1)return t[s]||null;const r=n?.[`${s}ActiveId`]||null;if(!r)return null;const o=t[s]?.findIndex(i=>i.id===r);return $c(o)?(e.shift(),Sr(e,t[s][o],n)):null},Ge=(e,t)=>{const n=e.split(".");return Sr(n,t,t)},Cr=(e,t,n,s=[],r={})=>{const o=Ge(e,t),i=o?.find(u=>u.id===n);if(!i)return null;const l=_t.v4(),a={...i,...r,id:l};s.forEach(u=>delete a[u]);const c=o.findIndex(u=>u.id===n)+1;return c===-1?o.push(a):o.splice(c,0,a),t[`${e.split(".").pop()}ActiveId`]=a.id,l},Yc=(e,t)=>{const n=Ut(e,t);return Cr(e,t,n)},Hc=e=>typeof e=="number"&&e>=0,gr=(e,t,n)=>{const s=e[0],r=n?.[`${s}ActiveId`]||null;if(!r)return null;const o=t[s]?.findIndex(i=>i.id===r);return Hc(o)?e.length===1?o:(e.shift(),gr(e,t[s][o],n)):null},br=(e,t)=>{const n=e.split(".");return gr(n,t,t)},Vc=e=>({id:e.id,name:e.name,...e.collection.show_when&&{show_when:e.collection.show_when},orderInForm:e.orderInForm,deleteCollectionWhenHidden:e.deleteCollectionWhenHidden,collection:{masterPage:!0,...e.collection},formData:{...e.formData},childPages:[e]}),qc=(e,t)=>{t.collection={...t.collection,...e.collection},t.formData={...t.formData,...e.formData},t.childPages=[...t.childPages,e]},Gc=(e,t)=>{const n=e.collection.name.split(".");if(n.length===1)return!1;n.pop();const s=n.join("."),r=t[s]||null;return r?(r.childPages.push(e),r.childPages.sort((o,i)=>o.orderInForm-i.orderInForm),!0):!1},wr=e=>{const t={};return e.map((s,r)=>{if(s.orderInForm=r,s?.collection?.name){if(!t[s.collection.name]){const o=Vc(s);return t[s.collection.name]=o,o}return qc(s,t[s.collection.name]),null}return s}).filter(s=>!!s).map(s=>s.collection?.masterPage&&Gc(s,t)?null:s).filter(s=>!!s)},Kc=(e,t,n)=>{const s=Ge(e,t);if(!s)return null;const r=s.findIndex(l=>l.id===n);if(r===-1)return null;const o=s[r];s.splice(r,1);const i=t;return i[`${e}ActiveId`]=s.length>0?s[0].id:null,o},Wc=e=>typeof e=="number"&&e>=0,On=(e,t,n)=>{const s=e.split("."),r=s[s.length-1];let o=n;s.some(i=>{if(o[i]||(o[i]=[]),!o[i].find(c=>c.id===n[`${i}ActiveId`])){const c=_t.v4();n[`${i}ActiveId`]=n[`${i}ActiveId`]||c,o[i].push({id:n[`${i}ActiveId`]})}if(i===r)return o[r]=t,!0;const l=n[`${i}ActiveId`],a=o[i]?.findIndex(c=>c.id===l);return Wc(a)?(o=o[i][a],!1):!0})},gt={addEntry:Bc,duplicateActiveEntry:Yc,duplicateEntry:Cr,getActiveId:Ut,getActiveIndex:br,getData:Ge,getErrorsForCollection:gn,mergePages:wr,removeEntry:Kc,setData:On},zc=e=>typeof e=="number"&&e>=0,Jc=(e,t,n,s,r,o)=>{const i=r?.label||$e.remove;return{pageId:e.id,fieldId:`delete${s}`,key:`delete${s}`,type:"action",action:{onAction:()=>{n(null,a=>{const c=a;if(!o)return c;Object.entries(o).forEach(f=>{const[E,y]=f;c[E]=y});const u=gt.getData(e.collection.name,c),h=u?.findIndex(f=>f.id===t.id);return zc(h)&&u.splice(h,1),c})},label:S.Utils.interpolateString(i,{...t,index:s})}}},Xc=(e,t,n,s,r,o={})=>{const i=r?.label||$e.change;return{pageId:e.id,fieldId:`change${s}${r.page}`,key:`change${s}${r.page}`,type:"action",action:{onAction:l=>{const a=c=>{const u=c;return Object.entries(o).forEach(h=>{const[f,E]=h;u[f]=E}),u};n(r.page?{pageId:r.page}:l,a)},label:S.Utils.interpolateString(i,{...t,index:s})}}},Qc=(e,t)=>t.show_when?Ue(t.show_when,e):!0,Zc=(e,t,n,s)=>({id:t.id,fieldId:t.id,type:_.CONTAINER,required:!0,full_path:s,components:e.components.map(r=>({...r,label:S.Utils.interpolateString(r.label,{...t,index:n}),full_path:`${s}.${r.fieldId}`}))}),eu=(e,t,n,s,r)=>{const o={...$e,...e.collection.labels};return{pageId:n,fieldId:"Title",full_path:`${r}.Title`,key:S.Utils.interpolateString(o.item,{...t,index:s}),type:"heading",size:e.collection.titleSize||"s"}},tu=(e,t,n,s,r)=>e.text===""?null:{pageId:t,fieldId:`heading${n}`,full_path:`heading${n}`,key:S.Utils.interpolateString(e.text,r),type:s===null?"heading":"headingWithAction",size:e.size||"s",action:s===null?null:{onAction:s,label:"Change"}},nu=(e,t,n,s)=>({pageId:e.id,fieldId:`${e.collection.name}Title`,full_path:`${e.collection.name}Title`,key:n?.text||t.charAt(0).toUpperCase()+t.slice(1),type:s==null?"heading":"headingWithAction",size:n?.size||"m",action:s===null?null:{onAction:s,label:"Change"}}),su=(e,t,n,s,r,o={})=>e.collection?.actions?.filter(i=>Qc(r,i)).map(i=>i.type==="remove"?Jc(e,t,n,s,i,o):i.type==="change"?Xc(e,t,n,s,i,o):null).filter(i=>!!i),_r=(e,t,n={})=>()=>{const s=r=>{const o=r;return Object.entries(n).forEach(i=>{const[l,a]=i;o[l]=a}),o};t({pageId:e.id},s)},ru=(e,t,n,s,r,o,i)=>{let l=[];return e.forEach(a=>{let c=a;if(c.collection.masterPage)l=l.concat(Ir(c,n,s,t,i));else if(c.collection.route&&(c=kc(c,c.collection.route)||c),Tr(c,{...c.formData,...t})){const u=_r(c,n,i);if(c.collection.heading){const E=c.collection.heading.changeLink?u:null,y=tu(c.collection.heading,c.id,r,E,t);l=l.concat(y)}const h=Zc(c,t,r,o),f=qe({...c,formData:{...c.formData,...t}},h,{...c.formData,...t},u,s);l=l.concat(f)}}),l},Ir=(e,t,n,s,r={})=>{const o=e.collection.name.split(".").pop();let i=s[o]||null;const l=s[`${o}ActiveId`];if(!i||i.length===0)return[];let a=[];if(!e.collection.hideNameFromCYA){const f=e.collection.collectionHeading?.changeLinkPage?_r({id:e.collection.collectionHeading.changeLinkPage},t,r):null;a.push(nu(e,o,e.collection.collectionHeading,f))}let c=0;const u=Array.isArray(e.collection.hideItemTitles)?Ue(e.collection.hideItemTitles,s):e.collection.hideItemTitles;return(Array.isArray(e.collection.onlyShowActiveEntryOnCYA)?Ue(e.collection.onlyShowActiveEntryOnCYA,s):e.collection.onlyShowActiveEntryOnCYA)&&(i=[i.find((E,y)=>(c=y,E.id===l))]),i.forEach(f=>{if(!f)return;r={...r,[`${o}ActiveId`]:f.id};const E=c+1,y=e.collection?.actionPosition||"top",p=`${e.collection.name}[${c}]`,A=su(e,f,t,E,s,r);if(!u){const T=eu(e,f,e.id,E,p);a=a.concat(T)}y==="top"&&(a=a.concat(A)),a=a.concat(ru(e.childPages,f,t,n,E,p,r)),y==="bottom"&&(a=a.concat(A)),c+=1}),a.filter(f=>!!f)},ou=e=>e.value?e.component?d.jsx("div",{children:d.jsx(Ve,{component:{...e.component,readonly:!0},wrap:!1,value:e.value})},e.id):e.value:null,iu=(e,t)=>{let n=-1;return{value:d.jsx(d.Fragment,{children:e.components.map(r=>{const o=t.findIndex(i=>i.id===r);return n<0&&(n=o),o>-1?ou(t[o]):null})}),firstComponentIndex:n}},lu=(e,t,n,s)=>{const{value:r,firstComponentIndex:o}=iu(t,n);return{row:{pageId:e.id,fieldId:t.id,key:t.label,required:t.required,value:r,action:vt(!1,e,s)},insertAt:o}},au=(e,t,n=null)=>{if(it.showCYA(e,e.formData)){if(e.collection)return Ir(e,t,n,e.formData);const r=et(e.components,e.formData).filter(o=>Ct(o,e.formData)).flatMap(o=>{if(typeof n=="function"){const i=n(e,o,t);if(i)return i}switch(o.type){case _.CONTAINER:return qe(e,o,e.formData[o.fieldId],t,n);case _.COLLECTION:return xn(e,o,e.formData[o.fieldId],t,n);default:return jt(e,o,t)}});if(e.groups?.length>0){e.groups.forEach(i=>{const{row:l,insertAt:a}=lu(e,i,r,t);a>-1?r.splice(a,0,l):r.push(l)});const o=e.groups.flatMap(i=>i.components);return r.filter(i=>!o.includes(i.id))}return r}return[]},cu={getRows:au,getCYARowsForContainer:qe},Pr=(e,t)=>{if(e&&t)switch(e.type){case"lowercase":return t.toLowerCase();case"uppercase":return t.toUpperCase();default:return t}return t},xr=(e,t,n)=>{const s=t;e.format&&e.format.on===n&&(s[e.fieldId]=Pr(e.format,s[e.fieldId]))},Or=(e,t,n)=>{e.forEach(s=>xr(s,t,n))},Rr=(e,t,n)=>{Or(e.components,t,n)},uu=(e,t,n)=>{e.forEach(s=>Rr(s,t,n))},du=(e,t,n)=>{const s={...t};return Or(e.components,s,n),uu(e.pages,s,n),s},fu={component:xr,data:Pr,form:du,page:Rr},hu=(e,t,n,s)=>{if(e===ne.HUB&&t){if(t.format===ye.CYA)return ye.CYA;if(t.components)return it.get(t,n,s)}if(e===ne.TASK||e===ne.FORM_WITH_TASK)return ye.TASK},mu={get:hu},Rn="meta",Nn="documents",an=e=>e?.[Rn]?.[Nn]||[],pu=(e,t,n,s)=>{const r=s?an(t):an(t).filter(i=>i.field!==n);return Array.isArray(e)&&e.forEach(i=>{r.push({...i,field:n})}),{...t?t[Rn]:void 0,[Nn]:r}},Eu={setForField:pu,get:an,name:Nn},Au={documents:Eu,name:Rn},yu=(e,t)=>{if(e?.field){const n=S.Utils.interpolateString(e.field,t);return!!se(t,n)}return!1},qt=(e,t)=>{if(e?.value)return e.value;const n=S.Utils.interpolateString(e?.field,t);return se(t,n)},Tu=(e,t)=>{if(!e||!t)return null;const n=S.Utils.interpolateString(e.target,t),s=se(t,n),r=qt(e,t),o=qt(e.cutoff,t),i=qt(e.ignore,t);let l=null;return s&&r&&Array.isArray(s)&&s.every((a,c)=>c===o?!1:c===i?!0:a===r||e.key&&se(a,e.key)===r?(l=c,!1):!0),typeof l=="number"?l.toString():l},Su=(e,t,n)=>{let s;if(e?.field){const r=S.Utils.interpolateString(e.field,t);s=se(t,r)}else s=e?.value;s!=null&&e.name&&t[e.name]!==s&&n({target:{name:e.name,value:s}})},Cu=(e,t)=>{if(e?.field){const n=S.Utils.interpolateString(e.field,t);return se(t,n)||null}return e?.value||null},gu=(e,t,n)=>{const s=t;e?.field&&e?.component&&(delete s[e.field],n({target:{name:e.field,value:null,component:e.component}}))},bu=(e,t)=>{if(e?.condition){const n=e,s=S.Utils.interpolateString(n.field,t),r=se(t,s);switch(n.condition){case"changes":{const o=`${s}LastValue`,i=n[o]||null;return i===null?(n[o]=r,!1):r!==i?(n[o]=r,!0):!1}case"isTruthy":return!!r;case"isFalsy":return!r;default:return!1}}return!0},wu=(e,t)=>{if(e?.fields){let n;return e.fields.find(s=>{const r=S.Utils.interpolateString(s,t),o=se(t,r);return o?(n=o,!0):!1}),n||(e.fallback?S.Utils.interpolateString(e.fallback,t):"")}return e?.value||null},_u=(e,t)=>{if(!e||!t)return null;const n=e.target.split(".");let s="";n.forEach(i=>{if(s!==""&&(s+="."),i.slice(-2)==="[]"){const l=i.slice(0,-2),a=br(l,t);s+=`${l}[${a}]`}else s+=i});const r=S.Utils.interpolateString(s,t);return se(t,r)?.length||0},Iu=(e,t)=>{const n=S.Utils.interpolateString(e.target,t),s=se(t,n);return s&&Array.isArray(s)?s.some(r=>e.key?se(r,e.key)===e.value:r===e.value):s&&typeof s=="object"?se(s,e.key)===e.value:!1},Pu={checkValueIsTruthy:yu,getIndexOfMatchingValueIn:Tu,doesContainValue:Iu,persistValueInFormData:Su,setValueInFormData:Cu,deleteValueInFormData:gu,getLength:_u,getFirstOf:wu},xu=(e,t,n)=>{const s=Pu[e.function];if(typeof s=="function")return s(e,t,n)},Ou=(e,t,n)=>(e?.operations&&t&&e.operations.forEach(s=>{if(bu(s.run_when,t)){const r=xu(s,t,n);if(s.output){const o=S.Utils.interpolateString(s.output,t).replace("[",".").replace("]","");Rs(t,o,r)}}}),t),Ru={runPageOperations:Ou},Nu=(e,t,n,s)=>!(e!==t.base&&s[t.check]),Lu=(e,t,n)=>{const s=e[n.id]?.[t.base],r=e[n.id]?.[t.check],o=r&&r?.length>0;return!!(s||o)},Du=e=>/^-?\d+$/.test(e),bt=e=>Du(e)?e.padStart(2,"0"):"",ge=e=>{const[t,n,s]=e.split("-");return`${bt(t)}-${bt(n)}-${s}`},Nr=e=>{const[t,n]=e.split(":");return`${bt(t)}:${bt(n)}`},Se="DD-MM-YYYY";K.extend(Be);const vu=(e,t)=>{const n=t.date?K(ge(t.date),Se):K().add(t.value,t.unit);return K(ge(e),Se).isAfter(n)};K.extend(Be);const Fu=(e,t)=>{const n=t.date?K(ge(t.date),Se):K().add(t.value,t.unit);return K(ge(e),Se).isBefore(n)};K.extend(Be);const ju=(e,t,n)=>{const s=n.components?.find(c=>c.fieldId===t.date),r=n.components?.find(c=>c.fieldId===t.time);if(!s||!r||!e)return!1;const o=e[n.fieldId]?.[t.date],i=e[n.fieldId]?.[t.time];if(!o||!i||Qe(s,e[n.fieldId],e[n.fieldId])||Qe(r,e[n.fieldId],e[n.fieldId]))return!0;const l=ge(e[n.fieldId]?.[t.date]),a=Nr(e[n.fieldId]?.[t.time]);return K(`${l} ${a}`,`${Se} HH:mm`).isBefore(K())};K.extend(Be);K.extend(fn);const Uu=(e,t)=>{const n=K(ge(e),Se).isBefore(K()),s=K(ge(e),Se).isToday();return n&&!s?!0:s&&!!t?.todayAllowed};K.extend(Be);K.extend(fn);const Mu=(e,t)=>K(ge(e),Se).isAfter(K())?!0:!!t?.todayAllowed&&K(ge(e),Se).isToday(),ku=(e,t)=>e?e.length>t.value:!0,Bu=(e,t)=>e?e.length<t.value:!0,$u=(e,t)=>{if(!e)return!0;const n=typeof e=="string"?e.replace(/,/g,""):e;return parseFloat(n)>t.value},Yu=(e,t)=>{if(!e)return!0;const n=typeof e=="string"?e.replace(/,/g,""):e;return parseFloat(n)<t.value},Hu=(e,t)=>e?(t?.allowCommas?/^[0-9,]*\.?[0-9]*$/:/^[0-9]*\.?[0-9]*$/).test(e):!0,Vu=(e,t)=>e?t.array.includes(e):!0,qu=(e,t,n,s)=>{if(!e||!s)return!0;const r=Ut(t.collectionPath,s);return!Ge(t.collectionPath,s)?.some(l=>l.id===r?!1:t.caseInsensitive&&typeof e=="string"&&typeof l[n.id]=="string"?l[n.id].toUpperCase()===e.toUpperCase():l[n.id]===e)},Gu=(e,t,n)=>n.components?.some(s=>!!e[n.id]?.[s.id]),Ku=(e,t)=>!e||!e.includes(".")?!0:e.split(".")[1].length<t.maxDecimals,Wu=/(%27)|(')|(--)|(%23)|(#)|((%3D)|(=))[^\n]*((%27)|(')|(--)|(%3B)|(;))|w*((%27)|('))((%6F)|o|(%4F))((%72)|r|(%52))|((%27)|('))union/i,zu=e=>{if(e){const t=typeof e=="object"?JSON.stringify(e):String(e);return!Wu.test(t)}return!1},Ju=(e,t,n)=>n.components?.reduce((r,o)=>e[n.id]?.[o.id]?Array.isArray(e[n.id][o.id])&&e[n.id][o.id].length===0?r:r+1:r,0)<2,Xu={conditionallyPermittedChange:Nu,conditionallyRequired:Lu,mustBeAfter:vu,mustBeBefore:Fu,mustBeEarlierDateTime:ju,mustBeGreaterThan:$u,mustBeInTheFuture:Mu,mustBeInThePast:Uu,mustBeLessThan:Yu,mustBeLongerThan:ku,mustBeNumbersOnly:Hu,mustBeOneOf:Vu,mustBeShorterThan:Bu,mustBeUniqueInCollection:qu,mustEnterAtLeastOne:Gu,mustHaveLessThanDecimalPlaces:Ku,mustNotContainSql:zu,mustSelectOnlyOne:Ju},Qu=(e,t,n,s)=>{const r=Xu[t.function],o=t.objectValueToUse?e[t.objectValueToUse]:e;if(typeof r=="function")return r(o,t,n,s)?void 0:t.message},Lr=(e,t,n)=>{if(t&&Array.isArray(e.additionalValidation)){let s;return e.additionalValidation.forEach(r=>{s||(s=Qu(t,r,e,n))}),s}},wt=(e,t,n)=>{if(!e)return[];const s=n||t,r=Lr(e,s);if(r)return{id:e.id,error:r};const o=[];if(Array.isArray(e.components)){const i=t&&e.fieldId?t[e.fieldId]:t;et(e.components,i).forEach(a=>{const c=e.full_path||e.fieldId?`${e.full_path||e.fieldId}.${a.fieldId}`:a.fieldId;o.push(Qe({...a,full_path:c},i,s))})}return o.flat(1).filter(i=>!!i)},Zu=(e,t,n)=>{const s=[];return e&&Array.isArray(e.item)&&Array.isArray(t)&&t.forEach((r,o)=>{const i=(e.countOffset||0)+o+1,l=`${e.full_path||e.fieldId}[${o}]`,a={full_path:l,components:e.item.map(c=>{const u={...c,full_path:`${l}.${c.fieldId}`};return c.custom_errors&&Array.isArray(c.custom_errors)&&(u.custom_errors=c.custom_errors.map(h=>({...h,message:S.Utils.interpolateString(o===0&&h.firstOnlyMessage?h.firstOnlyMessage:h.message,{index:i})}))),u})};s.push(wt(a,r,n))}),s.filter(r=>!!r).flat()};K.extend(Be);K.extend(fn);K.extend(Xr);const ed=(e,t)=>e==="02"?K().year(t).isLeapYear()?29:28:["04","06","09","11"].includes(e)?30:31,Dr=e=>{if(!e)return{message:void 0,propsInError:void 0};const t=ge(e),[n,s,r]=t.split("-"),o=parseInt(n,10),i=parseInt(s,10),l=[],a=[];if(r.length===0?(l.push("year"),a.push("Date must include a year")):r.length!==4&&(l.push("year"),a.push("Year must be 4 numbers")),s.length===0?(l.push("month"),a.push("Date must include a month")):(i>12||i<1)&&(l.push("month"),a.push("Month must be between 1 and 12")),n.length===0)l.push("day"),a.push("Date must include a day");else{const c=ed(s,r);(o>c||o<1)&&(l.push("day"),a.push(`Day must be between 1 and ${c}`))}if(l.length>0){const c={};return l.includes("day")&&(c.day=!0),l.includes("month")&&(c.month=!0),l.includes("year")&&(c.year=!0),{message:l.length===1?a[0]:"Enter a valid date",propsInError:c}}return K(t,Se).format(Se)!==t?{message:"Enter a valid date",propsInError:{day:!0,month:!0,year:!0}}:{message:void 0,propsInError:void 0}},td=/^[a-z0-9._\-']+@(digital\.)?homeoffice.gov.uk$/i,nd=/^[a-z0-9._\-']+@jmsc.gov.uk$/i,vr=(e,t="",n=[])=>{if(e){const s=t?t.toLowerCase():"email address";if(typeof e=="string"&&(td.test(e)||nd.test(e)))return;if(Array.isArray(n)){const r=n.filter(o=>o.type==="format");if(r&&r.length>0&&r[0].message)return r[0].message}return`Enter ${s} in the correct format, like jane.doe@homeoffice.gov.uk`}},sd="Invalid files must be deleted",Fr=(e,t)=>{if(!e)return;let n=!1;if(e.every(s=>(n=s.error,!n)),n){if(Array.isArray(t)){const s=t.filter(r=>r.type==="invalidFile");if(s&&s.length>0&&s[0].message)return s[0].message}return sd}},jr=(e,t,n,s)=>{if(e){if(typeof e=="string"){if(new RegExp(n).test(e))return;if(Array.isArray(s)){const o=s.filter(i=>i.type==="pattern");if(o?.[0]?.message)return o[0].message}}return t?`${t} failed regex validation`:"Component failed regex validation"}},Ur=(e,t,n)=>{let s=!1;if((e||e===!1||e===0)&&(s=!0,typeof e=="string"?s=e.trim().length>0:Array.isArray(e)&&(s=e.length>0)),!s){if(Array.isArray(n)){const o=n.filter(i=>i.type==="required");if(o&&o.length>0&&o[0].message)return o[0].message}return`${t||"Field"} is required`}},Mr=(e,t,n,s,r,o=1e3)=>{if(!n||!r&&!t)return;if(r&&!t||t.length>o){if(Array.isArray(s)){const l=s.filter(a=>a.type==="length");if(l&&l.length>0&&l[0].message)return l[0].message}return`${e} must be ${o} characters or less`}},kr=e=>{if(!e)return{message:void 0,propsInError:void 0};const t=Nr(e),[n,s]=t.split(":"),r=parseInt(n,10),o=parseInt(s,10),i=[],l=[];if(/^\d{0,2}:\d{0,2}$/.test(e)||(i.push("invalid"),l.push("Enter a valid time")),n.length===0?(i.push("hour"),l.push("Time must include a hour")):(r>23||r<0)&&(i.push("hour"),l.push("Hour must be between 0 and 23")),s.length===0?(i.push("minute"),l.push("Time must include a minute")):(o>59||o<0)&&(i.push("minute"),l.push("Minute must be between 0 and 59")),i.length>0){const c={};return i.includes("hour")&&(c.hour=!0),i.includes("minute")&&(c.minute=!0),i.includes("invalid")&&(c.invalid=!0),{message:i.length>1?"Enter a valid time":l[0],propsInError:c}}return{message:void 0,propsInError:void 0}},rd=(e,t)=>e?.type==="or"?ae.meetsOne(e.conditions,t):ae.meetsAll(e.conditions,t),Qe=(e,t,n)=>{const s=n||t;if(!Ie(e,{...s,...t}))return;if(e.type===_.CONTAINER)return wt(e,t,s);let r,o,l=(t&&typeof t=="object"?t:{})[e.fieldId];if(e.type===_.COLLECTION_SUMMARY&&(l=Ge(e.collectionName,s)),e.required&&(!e.requiredOverrideConditions||!rd(e.requiredOverrideConditions,s))&&(r=Ur(l,e.label,e.custom_errors)),!r){switch(e.type){case _.COLLECTION:return Zu(e,l,s);case _.EMAIL:r=vr(l,e.label,e.custom_errors);break;case _.DATE:case _.TIME:{const a=e.type===_.DATE?Dr:kr,{message:c,propsInError:u}=a(l);o=u,r=c;break}case _.CHECKBOXES:case _.RADIOS:{let a=[];if(e.data.options?.forEach(c=>{c.nested&&Ze(n[e.id],c)&&(a=a.concat(wt({components:c.nested},n)))}),a.length>0)return a;break}case _.MULTI_FILE:r=Fr(l,e.custom_errors);break;case _.TEXT_AREA:r=Mr(e.label,l,e.showCharacterCount,e.custom_errors,e.required,e.maxLength);break}!r&&e.pattern&&(r=jr(l,e.label,e.pattern,e.custom_errors)),!r&&e.additionalValidation&&(r=Lr(e,l,n),e.type===_.DATE&&r&&(o={day:!0,month:!0,year:!0}))}if(r)return{id:e.full_path||e.id,error:r,properties:o}},od=(e,t=[])=>{let n=e.formData;if(e.collection){const s=gt.getActiveIndex(e.collection.name,e.formData);s!==null&&(n={...e.formData,...gt.getData(e.collection.name,e.formData)?.[s]})}return Dt(e,n)&&Array.isArray(e.components)?e.components.reduce((r,o)=>{if(!Ie(o,n))return r;const l=(t.length>0?t.filter(a=>a.showFor?a.showFor===o.id:a.id===o.id):[]).concat(Qe(o,n,n));return r.concat(l).flat().map(a=>a&&{...a,error:S.Utils.interpolateString(a.error,n)})},[]).filter(r=>!!r).flat():[]},id={component:Qe,container:wt,email:vr,date:Dr,multifile:Fr,page:od,regex:jr,required:Ur,textarea:Mr,time:kr},w={CheckYourAnswers:cu,CollectionPage:gt,Component:ot,Condition:ae,Container:Lt,Data:de,Format:fu,FormPage:it,Hub:mu,Meta:Au,Operate:Ru,Validate:id,...S.Utils},ld="hods-form-container",Ln=({container:e,value:t=void 0,formData:n,onChange:s=void 0,wrap:r=!0,onTopLevelChange:o=void 0,...i})=>{const l=({target:h})=>{if(typeof s=="function")if(h.name===w.Meta.name)s({target:h});else{const f={...t,[h.name]:h.value};s({target:{name:e.fieldId,value:f}})}},a=h=>{const f=`${e.full_path||e.fieldId}.${h.fieldId}`;return h.type===_.CONTAINER?w.Container.show({...h,full_path:f},n):w.Component.show({...h,full_path:f},{...n,...se(n,e.full_path)})},c=w.classBuilder(ld,[],e.className),u=S.Utils.cleanHtmlAttributes(i);return d.jsxs("div",{...u,className:c(),id:e.id,children:[e.title&&d.jsx(S.MediumHeading,{children:e.title}),e.components&&e.components.filter(a).map((h,f)=>{const E=h.type===_.FILE?{}:"",y=t?t[h.fieldId]:E,p=`${e.full_path||e.fieldId}.${h.fieldId}`;return d.jsx(Ve,{...i,component:{...h,full_path:p,readonly:!!(e.readonly||h.readonly)},formData:n,value:y||E,wrap:r,onChange:l,onTopLevelChange:o},f)})]})},ad=e=>{if(e&&Object.prototype.hasOwnProperty.call(e,"action")){if(typeof e.action.onAction=="function")return{onClick:()=>e.action.onAction(e),onKeyPress:t=>{t.key==="Enter"&&e.action.onAction(e)},tabIndex:"0"};if(e.action.page)return{href:`/${e.action.page}`}}return{}},as=({group:e})=>{const[t,n]=R.useState({});return R.useEffect(()=>{n(ad(e))},[e,n]),e?.action?d.jsxs(S.Link,{...t,"aria-label":`${e.action.label} ${e.action.aria_suffix}`,children:[e.action.label,e.action.aria_suffix&&d.jsxs("span",{className:"mobile-text govuk-link",children:[" ",`${e.action.aria_suffix}`]})]}):null},cd=({title:e,size:t="m",classes:n})=>d.jsxs("div",{className:`${n("heading")}`,role:"listitem",children:[t==="s"&&d.jsx(S.SmallHeading,{children:e}),t==="m"&&d.jsx(S.MediumHeading,{children:e})]}),ud=({row:e,classes:t,noChangeAction:n=!1})=>d.jsxs("div",{className:t("headingWithAction"),role:"listitem",children:[d.jsxs("td",{className:"heading-text",colSpan:"2",children:[e.size==="s"&&d.jsx(S.SmallHeading,{children:e.key}),e.size==="m"&&d.jsx(S.MediumHeading,{children:e.key})]}),d.jsx("td",{className:"heading-action",children:!n&&d.jsx(Pn,{row:{action:e.action}})})]}),dd="govuk-summary-list",cn=({rows:e,noChangeAction:t=!1,noGroupAction:n=!1,isGroup:s=!1,classBlock:r=dd,classModifiers:o=[],className:i="",showGroupAction:l=!0,...a})=>{const c=S.Utils.classBuilder(r,o,i),u=S.Utils.cleanHtmlAttributes(a);let h=null;if(s){const f=e.filter(E=>!!E.action);h=f?.length?f[0]:null}return d.jsx("div",{className:"group-of-rows",children:d.jsxs("div",{...u,className:c(),role:"list",children:[e.map(f=>{const E=`${f.pageId}_${f.full_path||f.fieldId}`;return f.type==="title"?d.jsx(ur,{title:f.key,classes:c},E):f.type==="heading"?d.jsx(cd,{title:f.key,size:f.size||"s",classes:c},E):f.type==="headingWithAction"?d.jsx(ud,{row:f,classes:c,noChangeAction:t},E):f.type==="action"?t?null:d.jsx("div",{children:d.jsx(as,{group:f})},`${E}-actions`):d.jsx(cr,{row:f,classes:c,showAction:!t},E)}).filter(f=>!!f),l&&s&&!n&&d.jsx("div",{className:"change-group-button",children:d.jsx(as,{group:h})})]})})},fd="hods-check-your-answers",hd="Check your answers",cs=9,md=({title:e=hd,titleSize:t="l",pages:n,actions:s=[],onAction:r,onRowAction:o,hide_page_titles:i=!1,hide_actions:l=!1,hide_title:a=!1,summaryListClassModifiers:c,noChangeAction:u,noGroupAction:h,groups:f,sections:E=[],type:y,hideBlankRows:p=!1,optionalFieldPlaceholder:A})=>{const[T,N]=R.useState([]),[C,b]=R.useState([]),{errors:P}=He(),{hooks:U}=Pe();R.useEffect(()=>{const x=(q,X)=>w.CheckYourAnswers.getRows(q,o,U.onGetCYARows).map((V,z)=>({...V,value:d.jsx(bn,{value:V.value,component:V.component,formData:q.formData,placeholder:A},`${X}_${z}`)})),$=w.CollectionPage.mergePages(n).map((q,X)=>{const G=x(q,X);return G?.length?{...q,rows:G}:null}).filter(q=>!!q);N($)},[n,o,N]);const g=i?0:cs,L=x=>x===T.length-1;R.useEffect(()=>{(()=>{const j=Array.isArray(f)?f.map($=>$.pageId):[];b(j)})()},[b,f]);const v=U.onGetCYA({title:e,pages:n,actions:s,onAction:r,onRowAction:o,hidePageTitles:i,hideActions:l,hideTitle:a,summaryListClassModifiers:c,noChangeAction:u,noGroupAction:h,groups:f,errors:P,sections:E,type:y});if(v)return v;const F=x=>C.includes(x),I=x=>f?.find(j=>j.pageId===x),k=(x,j)=>{if(!x.cya_link?.singleChangeLink||u)return d.jsxs(d.Fragment,{children:[j==="s"&&d.jsx(S.SmallHeading,{children:w.FormPage.getTitle(x.title,x.formData)}),j==="m"&&d.jsx(S.MediumHeading,{children:w.FormPage.getTitle(x.title,x.formData)})]});const $=vt(!1,x,o);return d.jsxs("div",{className:"heading-with-action",children:[d.jsxs("div",{className:"heading-text",children:[j==="s"&&d.jsx(S.SmallHeading,{children:w.FormPage.getTitle(x.title,x.formData)}),j==="m"&&d.jsx(S.MediumHeading,{children:w.FormPage.getTitle(x.title,x.formData)})]}),d.jsx("div",{className:"heading-action",children:d.jsx(Pn,{row:{action:$}})})]})},O=()=>Array.from(new Set(P.map(j=>j.id))).map(j=>P.find($=>$.id===j));return d.jsxs("div",{className:fd,children:[e&&!a&&d.jsx(S.Heading,{size:t,children:e},"heading"),P&&P.length>0&&d.jsx(S.ErrorSummary,{errors:O()}),y===ne.TASK_CYA&&T.length>0&&E&&E.map(x=>x.tasks.filter(j=>j.state!==H.TYPES.SKIPPED).map((j,$)=>{const q=T.filter(X=>j.pages.some(G=>G===X.name));return d.jsxs(R.Fragment,{children:[d.jsx(S.MediumHeading,{children:q.length>0&&(j.displayName||j.name)}),q.map((X,G)=>{const V=F(X.id)||u,z=!i&&X.title&&!F(X.id);return d.jsxs(R.Fragment,{children:[z&&k(X,"s"),d.jsx(cn,{rows:X.rows,classModifiers:c,noChangeAction:V,noGroupAction:h,isGroup:F(X.id)})]},G)})]},$)})),y!==ne.TASK_CYA&&T&&T.map((x,j,$)=>{const q=!p||x.collection?x.rows:x.rows.filter(pe=>pe?.value?.props?.value);if(q.length===0)return null;const X=!i&&x.title&&!F(x.id),G=L(j)||F($[j].id)||$.length>j+1&&F($[j+1].id)?cs:g,V=F(x.id)?I(x.id):void 0,z=`govuk-!-margin-bottom-${G}`,fe=F(x.id)||u;return d.jsxs(R.Fragment,{children:[X&&k(x,"m"),V&&d.jsx("div",{className:"group-title",children:d.jsx(S.MediumHeading,{children:V.title||w.FormPage.getTitle(x.title,x.formData)})}),d.jsx(cn,{className:z,rows:q,classModifiers:c,noChangeAction:fe,noGroupAction:h,isGroup:F(x.id)})]},j)}),!l&&d.jsx(_n,{actions:s?.filter(x=>w.Component.show(x,n[n.length-1].formData)),onAction:x=>r(x)})]})},pd=lr,Ed=({page:e,pages:t,onCollectionChange:n=void 0,onAction:s,hashLink:r=!1,classBlock:o=pd,classModifiers:i=[],className:l="",submitting:a=!1})=>{const[c,u]=R.useState({});let h=w.CollectionPage.getData(e.collection.name,e.formData)||[];const f=e.collection.name.split(".").pop();let E=w.CollectionPage.getActiveIndex(e.collection.name,e.formData);const y=e,p=({target:P})=>{w.CollectionPage.setData(y.collection.name,P.value,e.formData),h=P.value;const U=e.collection.name.split(".").shift();u(g=>({...g,[U]:w.CollectionPage.getData(U,e.formData)}))},A=({target:P})=>{y.formData[P.name]=P.value,u(U=>({...U,[P.name]:P.value}))},T=P=>{p({target:{value:P}}),typeof n=="function"&&n(e.formData)},N=P=>{E=h.length,A({target:{name:`${f}ActiveId`,value:P}})},C=P=>{s(P,c,{})},b=({target:P})=>{if(E===null){const U=_t.v4();N(U),T([...h,{id:U,[P.name]:P.value}])}else T([...h.slice(0,E),{...h[E],[P.name]:P.value},...h.slice(E+1)])};return e.collection?.waitForFormData&&e.formData&&Object.keys(e.formData).length===0?null:d.jsx(In,{page:{...e,formData:{...e.formData,...h[E],[`${f}ActiveIndex`]:E,[`${f}NumberedIndex`]:typeof E=="number"?E+1:null},components:e.components.map(P=>({...P,pageCollection:{...e.collection}}))},pages:t,onAction:C,onWrapperChange:b,onTopLevelChange:A,hashLink:r,classBlock:o,classModifiers:i,className:l,submitting:a})},Ad="hods-task-list",yd=({state:e=H.TYPES.CANNOT_START_YET})=>{const t=S.Utils.classBuilder(Ad,void 0,void 0),n=H.DETAILS[e]||H.DETAILS.cannotStartYet;return d.jsx(S.Tag,{classModifiers:n.colour,className:t("tag"),children:n.label})},Td="hods-task-list",Sd=({task:e,onClick:t})=>{const n=S.Utils.classBuilder(Td,void 0,void 0),[s,r]=R.useState(e.state!==H.TYPES.CANNOT_START_YET),[o,i]=R.useState(e.state);R.useEffect(()=>{r(e.state!==H.TYPES.CANNOT_START_YET),i(e.state)},[e.state,r,i]);const l=e.displayName||e.name;return d.jsxs("li",{className:n("item"),children:[d.jsx("span",{className:n("task-name"),children:s?d.jsx(S.Link,{onClick:()=>t(e),onKeyPress:a=>{a.key==="Enter"&&t(e)},tabIndex:0,children:l}):l}),d.jsx(yd,{state:o})]})},Cd="hods-task-list",gd="Incomplete form",bd=({id:e="",refTitle:t,refNumber:n,notes:s={},incompleteTitle:r=gd,showCompletionOverview:o=!0,sections:i,fieldId:l="",onTaskAction:a,classBlock:c=Cd,classModifiers:u=[],className:h="",formData:f={},annotations:E=[],...y})=>{const p=S.Utils.classBuilder(c,u,h),A=S.Utils.cleanHtmlAttributes(y),[T,N]=i.filter(g=>!g.skipped).reduce((g,L)=>[g[0]+(L.tasks?.filter(v=>v.state===H.TYPES.COMPLETE).length??0),g[1]+(L.tasks?.filter(v=>v.state!==H.TYPES.SKIPPED).length??0)],[0,0]),C=`${e}Notes`,{title:b,text:P}=s&&s||{},U=g=>{typeof a=="function"&&a(g)};return d.jsxs("div",{...A,id:e,className:p(),children:[n&&t&&d.jsxs(d.Fragment,{children:[d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:`${t}`})}),d.jsx("p",{className:"govuk-body govuk-!-font-weight-regular",children:`${n}`})]}),E.length>0&&E.map(g=>d.jsxs("div",{className:p("annotation"),children:[d.jsx("p",{className:`${p("annotation-key")} govuk-body`,children:S.Utils.interpolateString(g.key,f)}),d.jsx("p",{className:`${p("annotation-value")} govuk-body`,children:S.Utils.interpolateString(g.value,f)})]},g.key)),o&&N!==T&&d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:r})}),o&&d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-7",children:`You have completed ${T} of ${N} sections`}),b&&P&&Ie(s,f)&&d.jsxs(d.Fragment,{children:[d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:S.Utils.interpolateString(b,f)})}),d.jsx(S.TextArea,{id:C,fieldId:C,readOnly:!0,value:S.Utils.interpolateString(P,f)})]}),i.filter(g=>!g.skipped).map((g,L)=>d.jsxs(R.Fragment,{children:[d.jsxs("h2",{className:p("section"),children:[i.length>1?`${L+1}. `:" ",g.name]}),g.label&&d.jsx(S.Hint,{children:g.label}),d.jsx("ol",{className:p("items"),children:g.tasks.filter(v=>v.state!==H.TYPES.SKIPPED).map(v=>d.jsx(Sd,{task:v,onClick:U},`${g.name}-${v.name}`))})]},`${g.name}`))]})},Br=(e,t)=>e?.page||t,wd=(e,t,n)=>{const s=Br(e.action,e.pageId);s!==t&&n(s)},_d=(e,t,n,s=void 0)=>{const r=Br(e,t);r!==t&&n(r,s)},Id=(e,t)=>{t(e)},Te={cyaAction:wd,navigate:_d,submissionError:Id},Pd=(e,t,n,s)=>e.validate?e.checkPreexistingErrors&&s.length!==0?!1:n(t).length===0:!0,xd=(e,t)=>t(e).length===0,Od=["radios","checkboxes"],Rd=(e,t)=>{const n=e.split("."),s={};return n.forEach(r=>{s[`${r}ActiveId`]=t[`${r}ActiveId`]}),s};function Nd(e,t){const n=[];return e?.data?.options?.forEach(s=>{!Ze(t,s)&&s.nested&&s.nested.forEach(r=>{n.push(r.id)})}),n}const $r=(e,t)=>{let n=e;if(t.components.forEach(s=>{if(!Od.includes(s.type))return;Nd(s,n[s.id]).forEach(o=>{delete n[o]})}),t.collection){n={...Rd(t.collection.name,t.formData),...n};const s=Ge(t.collection.name,n);if(s){const r=Ut(t.collection.name,n),o=s.map(i=>i.id===r?$r(i,{...t,collection:void 0}):i);On(t.collection.name,o,n)}}return n},Ld=(e,t,n)=>{if(e===re.HUB&&n===ye.CYA)return{title:""};if(e===re.CYA)return{};const s=t?.find(r=>r.id===e);if(s?.type===re.PARTIAL_CYA){const r=w.FormPage.applyConditionalProperties(s);return{title:r.title,hideChangeActions:r.hideChangeActions,hideGroupActions:r.hideGroupActions}}},Yr=(e,t,n)=>{if(e)return e===re.HUB?n===ye.CYA||n===ye.TASK?void 0:n:t.find(s=>s.id===e)},Dd=(e,t,n)=>({pageId:e,cya:Ld(e,t,n),page:Yr(e,t,n)}),us=(e,t)=>e.slice(0,e.findIndex(n=>n?.id===t)),vd=(e,t,n)=>e.page?.type===re.PARTIAL_CYA?us(n||t,e.pageId):n||t,ds=(e,t,n,s,r)=>{if(!t&&r===ne.FORM_WITH_TASK){if(s?.formStatus?.taskPage){const i=n.find(l=>l.id===s.formStatus.taskPage);return i?.type==="pre-task-list"?i.id:re.HUB}return n.length>0?n[0].id:void 0}let o;return e?.pages?.forEach(i=>{it.show({show_when:i.show_when},s)&&(o=i.pageId)}),o||e?.page||re.HUB},Hr=(e,t,n)=>{let s=e.findIndex(o=>o.id===t)+1,r=e[s];for(;r&&!it.show(r,n);)s+=1,r=e[s];return r?.id||void 0},Fd=(e,t,n)=>Hr(e,t,n)||re.CYA,jd=e=>e.length>0?e[0].id:void 0,un=(e,t,n,s,r)=>{if(s){if(s.type===W.TYPES.NAVIGATE)return t.find(o=>o.id===s.page)?s.page:void 0;if(s.type===W.TYPES.SAVE_AND_RETURN)return e===ne.HUB?re.HUB:void 0}switch(e){case ne.HUB:return ds(s);case ne.CYA:return Fd(t,n,r);case ne.FORM_WITH_TASK:case ne.TASK:return ds(s,n,t,r,e);case ne.WIZARD:return Hr(t,n,r);default:return jd(t)}},Ud=(e,t,n,s,r,o,i,l)=>{if(e===ne.TASK||e===ne.FORM_WITH_TASK){const a=r.formStatus||{};return a.tasks=a.tasks||{},a.tasks[o.name]=a.tasks[o.name]||{},n===(re.CYA||"submitForm")&&i?a.tasks[o.name].complete=!0:o.name?s?.type===W.TYPES.SAVE_AND_NAVIGATE?a.tasks[o.name]={complete:!1,currentPage:un(e,t,n,s,r)}:o.pages?.includes(n)&&(a.tasks[o.name]={complete:!!s?.complete,currentPage:n}):l&&l.forEach(c=>{c.tasks.forEach(u=>{const h=u.pages[u.pages.length-1];(h===n||h.id===n)&&i&&u?.type==="pre-task-list"?a.tasks[u.name]={complete:i,currentPage:n}:u.pages.includes(n)&&u?.type==="pre-task-list"&&(a.tasks[u.name]={complete:!1,currentPage:n})})}),a.taskPage=a.tasks[o.name].currentPage,a}return s?.type===W.TYPES.SAVE_AND_RETURN?{page:n}:{page:un(e,t,n,s,r)}},Md=({complete:e,currentPage:t},n=H.TYPES.NOT_STARTED)=>e?H.TYPES.COMPLETE:t||e!==void 0&&!e&&t===void 0?H.TYPES.IN_PROGRESS:n,kd=(e,t,n=!1)=>t.reduce((s,r)=>{const o=e[r];return n&&o?.state===H.TYPES.SKIPPED?s:s&&o?.complete},!0),Vr=(e,t)=>{const n=e[t-1].state;return n===H.TYPES.COMPLETE?!0:n===H.TYPES.SKIPPED?t-1===0?!0:Vr(e,t-1):!1},Bd=(e,t,n,s,r=!1,o=!0)=>{if(s[e.name])return Md(s[e.name],e.state);if(r)return e.depends_on&&!kd(s,e.depends_on,e.ignoreSkipped)?H.TYPES.CANNOT_START_YET:H.TYPES.NOT_STARTED;let i=o;return t&&(i=Vr(n,t)),i?H.TYPES.NOT_STARTED:H.TYPES.CANNOT_START_YET},$d=(e,t,n,s)=>{const r=e.tasks.map(o=>({...o}));return r.filter(o=>o.state!==H.TYPES.SKIPPED).forEach((o,i)=>{const l=o;l.state=Bd(l,i,r,t,n,s)}),r},qr=(e,t)=>{const n=e[t-1]?.tasks.slice(-1)[0]?.state;return n===H.TYPES.COMPLETE?!0:n===H.TYPES.SKIPPED?t-1===0?!0:qr(e,t-1):!1},Yd=(e,t,n=!1,s=null)=>{const r=e.map(i=>{const l=i.show_when?[i.show_when].flat():[];return s&&!w.Condition.meetsAll(l,s)?{...i,skipped:!0,tasks:i.tasks.map(a=>({...a,state:H.TYPES.SKIPPED}))}:{...i}});r.forEach(i=>{const l=i;l.tasks=l.tasks.map(a=>{const c=a.show_when?[a.show_when].flat():[];return s&&!w.Condition.meetsAll(c,s)?{...a,state:H.TYPES.SKIPPED}:{...a}})});const o={...t};return r.forEach(i=>{i.tasks.filter(l=>l.state===H.TYPES.SKIPPED).forEach(l=>{o[l.name]={...o[l.name],state:H.TYPES.SKIPPED}})}),r.forEach((i,l)=>{const a=i,c=l===0||qr(r,l);a.tasks=$d(a,o,n,c)}),r},Hd=(e,t,n)=>{n.has(e)||n.set(e,[]),n.get(e).push(t)},ke=(e,t)=>{if(Array.isArray(e))for(let r=0;r<e.length;r+=1)ke(e[r],t);const n=t.split(".");let s=e;for(let r=0;r<n.length-1;r+=1)if(s=s[n[r]],s===void 0)return;s[n[n.length-1]]&&delete s[n[n.length-1]]},Gr=e=>{if(typeof e!="string"||!e.includes("."))return null;const t=e.split(".");return t.pop(),t.join(".")},Dn=(e,t)=>{const n=Gr(e);return n?`${n}.${t}`:t},Vd=e=>{for(let t=e.length-1;t>=0;t-=1){const n=e[t];Object.keys(n).length===1&&Object.keys(n)[0]==="id"&&e.splice(t,1)}},qd=e=>{const t=(n,s)=>(typeof n=="object"&&n!==null&&(Array.isArray(n)?n.forEach(r=>{t(r,s)}):Object.keys(n).forEach(r=>{r==="field"&&s.push(n[r]),t(n[r],s)})),s);return e.show_when?new Set(t(e.show_when,[])||[]):null},Gd=(e,t)=>{const n=e.split(".");for(let s=n.length;s>0;s-=1){const r=n.slice(0,s).join("."),o=t.get(r);if(o)return o}return null},Je=(e,t)=>e.show_when?e.show_when?.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t):!0,Kr=(e,t,n)=>{const s=t.get(e.use)??n.get(e.use)??e,r=JSON.parse(JSON.stringify(s));return e.use&&e.show_when&&(r.show_when=e.show_when),r},Kd=(e,t,n)=>{const{meta:{documents:s}}=n,r=t[e.fieldId];if(!s||!r)return;const o=Array.isArray(r)?r:[r];for(let i=o.length-1;i>=0;i-=1){const l=s.findIndex(a=>a.url===o[i].url);l!==-1&&s.splice(l,1)}},dn=e=>{if(Array.isArray(e))for(let t=e.length-1;t>=0;t-=1)Array.isArray(e[t])&&e[t].length===0?e.splice(t,1):dn(e[t]),typeof e[t]=="object"&&Object.keys(e[t]).length===0&&e.splice(t,1);else e!==null&&typeof e=="object"&&Object.keys(e).forEach(t=>{Array.isArray(e[t])&&e[t].length===0?(e[`${t}ActiveId`]&&delete e[`${t}ActiveId`],delete e[`${t}ActiveId`],e[t]&&delete e[t]):dn(e[t])})},Wr=(e,t)=>{e?.data?.options&&e?.data?.options?.forEach(n=>{n.nested?.forEach(t)})},Wd=(e,t,n,s)=>{if(s[t]>1)s[t]-=1;else{if(n.preserveInPayload)return;ke(e,t),Wr(n,r=>{const o=Dn(t,r.fieldId);s[o]>1?s[o]-=1:ke(e,o)})}},zd=(e,t,n,s)=>{t.forEach(r=>{if(!e.has(r.fieldId)){if(r.type==="multifile"&&Kd(r,n,s),r.preserveInPayload)return;ke(n,r.fieldId),Wr(r,o=>{const i=Dn(r.fieldId,o.fieldId);e.has(i)||ke(n,i)})}})},fs=e=>Array.isArray(e)?e:[e],Jd=(e,t,n,s)=>{const r=new Map,o={},i=[],l=new Map,a=(c,u,h)=>{u.fieldId&&(h=h?`${h}.${u.fieldId}`:u.fieldId,o[h]=(o[h]||0)+1,u.path=h,c.show_when&&(u.show_when=u.show_when?[...fs(c.show_when),...fs(u.show_when)]:c.show_when),Hd(h,u,r),u.components?u.components.forEach(f=>{a(c,f,h)}):u?.data?.options&&u?.data?.options?.forEach(f=>{if(f.nested){const E=!Ze(se(s,h),f),y=f.show_when;f.nested.forEach(p=>{E&&i.push(Dn(h,p.fieldId)),y&&(p.show_when=y),a(c,p,Gr(h))})}}))};return e?.forEach(c=>{c.childPages?l.set(c.collection.name,c):c.components?.forEach(u=>{const h=Kr(u,t,n);a(c,h,null)})}),i.forEach(c=>{o[c]>1?o[c]-=1:ke(s,c)}),{allComponents:r,componentsToKeep:o,allCollections:l}},Xd=e=>{const t=new Map;return e?.forEach(n=>{n?.forEach(s=>{if(!s.fieldId)return;const r=qd(s);if(r)if(t.has(s.path)){const o=t.get(s.path);r.forEach(i=>o.add(i))}else t.set(s.path,new Set(r))})}),t},Qd=(e,t,n,s,r,o)=>{const i=(a,c,u)=>{if(a.has(c))return;a.add(c),u.get(c.path)?.forEach(f=>{const E=Gd(f,t);if(E)E.forEach(y=>{a.has(y)||i(a,y,u)});else{const y=/([a-zA-Z_$][\w$]*)\[\d+\]/,p=f.match(y);if(p){const A=p[1],T=s.get(A);T&&T.childPages?.forEach(N=>{if(N.show_when){const C=JSON.stringify(N.show_when),b=`It is not possible to reliably clean hidden data when a component is dependent on a
|
|
9
|
+
`+o)}}catch{}}throw s}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=De(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:o}=n;s!==void 0&&At.assertOptions(s,{silentJSONParsing:he.transitional(he.boolean),forcedJSONParsing:he.transitional(he.boolean),clarifyTimeoutError:he.transitional(he.boolean),legacyInterceptorReqResOrdering:he.transitional(he.boolean),advertiseZstdAcceptEncoding:he.transitional(he.boolean)},!1),r!=null&&(m.isFunction(r)?n.paramsSerializer={serialize:r}:At.assertOptions(r,{encode:he.function,serialize:he.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),At.assertOptions(n,{baseUrl:he.spelling("baseURL"),withXsrfToken:he.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&m.merge(o.common,o[n.method]);o&&m.forEach(["delete","get","head","post","put","patch","query","common"],y=>{delete o[y]}),n.headers=ue.concat(i,o);const l=[];let a=!0;this.interceptors.request.forEach(function(p){if(typeof p.runWhen=="function"&&p.runWhen(n)===!1)return;a=a&&p.synchronous;const A=n.transitional||An;A&&A.legacyInterceptorReqResOrdering?l.unshift(p.fulfilled,p.rejected):l.push(p.fulfilled,p.rejected)});const c=[];this.interceptors.response.forEach(function(p){c.push(p.fulfilled,p.rejected)});let u,h=0,f;if(!a){const y=[Qn.bind(this),void 0];for(y.unshift(...l),y.push(...c),f=y.length,u=Promise.resolve(n);h<f;)u=u.then(y[h++],y[h++]);return u}f=l.length;let E=n;for(;h<f;){const y=l[h++],p=l[h++];try{E=y(E)}catch(A){p.call(this,A);break}}try{u=Qn.call(this,E)}catch(y){return Promise.reject(y)}for(h=0,f=c.length;h<f;)u=u.then(c[h++],c[h++]);return u}getUri(t){t=De(this.defaults,t);const n=Js(t.baseURL,t.url,t.allowAbsoluteUrls);return Gs(n,t.params,t.paramsSerializer)}};m.forEach(["delete","get","head","options"],function(t){Re.prototype[t]=function(n,s){return this.request(De(s||{},{method:t,url:n,data:(s||{}).data}))}});m.forEach(["post","put","patch","query"],function(t){function n(s){return function(o,i,l){return this.request(De(l||{},{method:t,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}Re.prototype[t]=n(),t!=="query"&&(Re.prototype[t+"Form"]=n(!0))});let ha=class er{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(r=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](r);s._listeners=null}),this.promise.then=r=>{let o;const i=new Promise(l=>{s.subscribe(l),o=l}).then(r);return i.cancel=function(){s.unsubscribe(o)},i},t(function(o,i,l){s.reason||(s.reason=new rt(o,i,l),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=s=>{t.abort(s)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new er(function(r){t=r}),cancel:t}}};function ma(e){return function(n){return e.apply(null,n)}}function pa(e){return m.isObject(e)&&e.isAxiosError===!0}const sn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(sn).forEach(([e,t])=>{sn[t]=e});function tr(e){const t=new Re(e),n=vs(Re.prototype.request,t);return m.extend(n,Re.prototype,t,{allOwnKeys:!0}),m.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return tr(De(e,r))},n}const Z=tr(st);Z.Axios=Re;Z.CanceledError=rt;Z.CancelToken=ha;Z.isCancel=Ws;Z.VERSION=Tn;Z.toFormData=Rt;Z.AxiosError=D;Z.Cancel=Z.CanceledError;Z.all=function(t){return Promise.all(t)};Z.spread=ma;Z.isAxiosError=pa;Z.mergeConfig=De;Z.AxiosHeaders=ue;Z.formToJSON=e=>Ks(m.isHTMLForm(e)?new FormData(e):e);Z.getAdapter=Zs.getAdapter;Z.HttpStatusCode=sn;Z.default=Z;const{Axios:af,AxiosError:cf,CanceledError:uf,isCancel:df,CancelToken:ff,VERSION:hf,all:mf,Cancel:pf,isAxiosError:Ef,spread:Af,toFormData:yf,AxiosHeaders:Tf,HttpStatusCode:Sf,formToJSON:Cf,getAdapter:gf,mergeConfig:bf,create:wf}=Z,ce={onAction:(e,t)=>({formData:e,patch:t}),onChange:e=>{},onFormComplete:()=>{},onFormLoad:e=>{},onGetComponent:(e,t)=>null,onGetCYA:e=>null,onGetCYARows:(e,t,n)=>null,onGoingBack:()=>{},onPageChange:(e,t)=>e,onRequest:e=>e,onSubmit:(e,t,n,s)=>{typeof n=="function"&&n()},onValidate:(e,t)=>t,onCancel:e=>{}},es=Object.keys(ce),nr=R.createContext(),sr=({overrides:e={onAction:void 0,onCancel:void 0,onChange:void 0,onFormComplete:void 0,onFormLoad:void 0,onGetComponent:void 0,onGetCYA:void 0,onGetCYARows:void 0,onGoingBack:void 0,onPageChange:void 0,onRequest:void 0,onSubmit:void 0,onValidate:void 0},children:t=null})=>{const[n,s]=R.useState({onAction:e?.onAction||ce.onAction,onChange:e?.onChange||ce.onChange,onFormComplete:e?.onFormComplete||ce.onFormComplete,onFormLoad:e?.onFormLoad||ce.onFormLoad,onGetComponent:e?.onGetComponent||ce.onGetComponent,onGetCYA:e?.onGetCYA||ce.onGetCYA,onGetCYARows:e?.onGetCYARows||ce.onGetCYARows,onGoingBack:e?.onGoingBack||ce.onGoingBack,onPageChange:e?.onPageChange||ce.onPageChange,onRequest:e?.onRequest||ce.onRequest,onSubmit:e?.onSubmit||ce.onSubmit,onValidate:e?.onValidate||ce.onValidate,onCancel:e?.onCancel||ce.onCancel}),r=(i,l)=>{es.includes(i)&&s(a=>({...a,[i]:l||ce[i]}))},o=i=>{es.includes(i)&&s(l=>({...l,[i]:ce[i]}))};return d.jsx(nr.Provider,{value:{hooks:n,addHook:r,removeHook:o},children:t})},Pe=()=>R.useContext(nr),Ea=()=>{const{hooks:e}=Pe(),[t,n]=R.useState({});return R.useEffect(()=>{const s=Z.create({baseURL:"/"});return s.interceptors.request.use(e.onRequest),s.interceptors.response.use(r=>r,async r=>Promise.reject(r)),n({instance:s}),()=>{n({})}},[e]),t.instance},Cn=R.createContext(),rr=({children:e=null})=>{const{hooks:t}=Pe(),[n,s]=R.useState([]),[r,o]=R.useState([]),i=f=>{f!==void 0&&o(E=>[...E,...f].filter(y=>!!y))},l=f=>{typeof f=="function"&&o(E=>E.filter(y=>!f(y)))},a=()=>{r.length&&o([])},c=f=>{f!==void 0&&s(E=>[...E,...f].filter(y=>!!y))},u=()=>{o([]),s([])},h={page:f=>{const E=w.Validate.page(f,r),y=t.onValidate(f,E);return s(y),y},pages:f=>{const E=f.map(p=>w.Validate.page(p,r)),y=f.flatMap((p,A)=>t.onValidate(p,E[A]));return s(y),y}};return d.jsx(Cn.Provider,{value:{errors:n,addErrors:c,clearErrors:u,queuedErrors:r,enqueueErrors:i,dequeueErrors:l,clearQueuedErrors:a,validate:h},children:e})},He=()=>R.useContext(Cn),Yt={},Ht={},Aa="idle",ya="fetching",or="fetched",ir="error",Ta=(e,t=!0)=>{const n=Ea(),s=R.useRef(Z.CancelToken.source()),[r,o]=R.useState(Aa),[i,l]=R.useState(null),[a,c]=R.useState(null),u=()=>{s.current&&s.current.cancel()};return R.useEffect(()=>{if(!e||!n)return;(async()=>{try{l(null),o(ya);let f;if(t&&Yt[e])f=Yt[e];else{if(t&&Ht[e])throw Ht[e];f=(await n.get(e,{cancelToken:s.current.token}).catch(y=>{throw l(y),y})).data,t&&(Yt[e]=f)}c(f),o(or)}catch(f){t&&(Ht[e]=f),l(f),c(null),o(ir)}})()},[n,e,t]),{status:r,error:i,data:a,cancelRequests:u}},Sa="loading",yt="complete",Ca=e=>{const t=e.data;if(t&&!t.options||t?.url)return S.Utils.interpolateString(t.url,e.formData)},ga=(e,t)=>{const n=Ca({...e,formData:t}),{status:s,data:r}=Ta(n,e?.data?.useCache),[o,i]=R.useState([]),[l,a]=R.useState(Sa);return R.useEffect(()=>{n?s===or?(r&&i(de.refData.toOptions(r.data||r,e.item)),a(yt)):s===ir&&(i([]),a(yt)):(e.data&&e.data.options&&i(de.refData.toOptions(e.data.options,e.item)),a(yt))},[e.id,s,r,n]),{data:o,status:l}},Xe=(e,t)=>{const n=te(e,["fieldId","displayMenu","showCharacterCount","readonly"]);return d.jsx(S.FormGroup,{...n,onChange:null,children:t})},gn=(e,t,n,s,r={})=>{if(!t)return[];const o=w.CollectionPage.getData(t.collection.name,t.formData)||[];let i=[];return o.forEach(l=>{r={...r,[`${t.collection.name.split(".").pop()}ActiveId`]:l.id};const a=t.childPages?.flatMap(c=>{const u={...c,formData:{...n,...r}};if(c.childPages)return gn(e,u,n,s,r);const h=w.Validate.page(u);return s.onValidate(u,h)});i=i.concat(a.map(c=>({...c,entryId:l.id,showFor:e.id,raisedBy:e.id})))}),i},bn=({value:e,component:t,formData:n,placeholder:s})=>e?t?d.jsx(Ve,{component:{...t,readonly:!0},wrap:!1,value:e,formData:n}):Object.prototype.hasOwnProperty.call(e,"label")?e.label:e:(Object.prototype.hasOwnProperty.call(t||{},"cyaPlaceholder")?t?.cyaPlaceholder:s)||d.jsx(S.VisuallyHidden,{children:"No answer"}),ba="Continue",rn=({action:e,onAction:t,...n})=>{const s=typeof e=="string"?W.DEFAULTS[e]:e,r=W.DEFAULTS[e.type];return s?d.jsx(S.Button,{...n,className:s.className,classModifiers:s.classModifiers,start:s.start||!1,name:s.label,onClick:s.disabled?()=>{}:()=>t(s),children:s.label||r?.label||ba}):null},wa="hods-form-confirmation",_a="Are you sure?",Ia="Confirm",Pa=({id:e,message:t,confirmLabel:n,children:s,onConfirm:r,onCancel:o,classModifiers:i=[]})=>{const l=S.Utils.classBuilder(wa,i,"");return d.jsxs("div",{id:e,className:l(),role:"alert",children:[d.jsx("h2",{children:t||_a}),s,d.jsx(S.Button,{classModifiers:"warning",onClick:r,autoFocus:!0,children:n||Ia}),d.jsx(S.Button,{classModifiers:"secondary",onClick:o,children:"Cancel"})]})},wn=e=>e&&Array.isArray(e.components)?e.components.flatMap(t=>t.type===_.CONTAINER?wn(t):ot.editable(t)?t:null).filter(t=>!!t):[],xa=e=>{const t=e.full_path||e.fieldId;return e.components.map(n=>{const s=t?`${t}.${n.fieldId}`:n.fieldId,r={...n,full_path:s};return n.type===_.CONTAINER?on(r):(n.type===_.RADIOS&&r.data?.options?.forEach((o,i)=>{o.nested?.forEach((l,a)=>{l.type===_.CONTAINER&&(r.data.options[i].nested[a]=on(l))})}),r)})},on=e=>{if(e){const t=xa(e);return{...e,components:t}}return e},Oa=(e,t)=>e.some(n=>ot.show(n,t)),Ra=(e,t)=>{if(!e)return!1;if(e.show_when)return e.show_when.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t);const n=wn(e);return n.length>0?Oa(n,t):!0},Lt={editableComponents:wn,setup:on,show:Ra},Na=(e,t)=>e.some(n=>Ie(n,t)),Dt=(e,t)=>{if(!e)return!1;if(e.show_when)return e.show_when.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t);const n=Lt.editableComponents(e);return n.length>0?Na(n,t):!0},La=(e,t,n)=>{if(!e)return null;const s=[];e.childPages.forEach(l=>{!l.summaryQuickEdit||!Dt(l,{...t,...n})||l.summaryQuickEdit.forEach(a=>{if(typeof a=="string"){s.push({...l.components.find(h=>h.id===a)});return}const c=l.components.find(h=>h.id===a.use);if(!c)return;const u={...c,...a};if(a.show_when){Ue(a.show_when,{...t,...n})&&s.push({...u,show_when:c.show_when||[]});return}s.push(u)})});const r={...e.childPages[0],formData:t};r.components=s,r.actions=[{type:"save",label:"Save",validate:!0,classModifiers:"primary"},{type:"cancel",label:"Cancel",classModifiers:"secondary"}];const{id:o,...i}=n;return r.formData={...r.formData,...i,[`${e.collection?.name?.split(".").pop()}ActiveId`]:n.id},delete r.title,delete r.collection,r},_n=({actions:e,onAction:t})=>!e||e.length===0?null:d.jsx(S.ButtonGroup,{children:e.map((n,s)=>d.jsx(rn,{action:n,onAction:t},s))}),Da=e=>{if(!e?.customValidation)return!1;const t=e?.customValidation.find(n=>n.runWhen?.onLoad===!0);return t&&t.runWhen?.constraint?ae.meetsOne(t.runWhen?.constraint,e.formData):!1},lr="hods-form__page",In=({page:e,pages:t=[],onAction:n,onWrapperChange:s=void 0,onTopLevelChange:r=void 0,onChange:o=void 0,hashLink:i=!1,classBlock:l=lr,classModifiers:a=[],className:c="",submitting:u=!1,pageId:h})=>{const[f,E]=R.useState({}),{errors:y,validate:p}=He(),[A,T]=R.useState({}),[N,C]=R.useState(!1),b=R.useMemo(()=>Da(e),[e]);R.useEffect(()=>{C(!0)},[]),R.useEffect(()=>{N&&b&&p.page(e)},[h,N]);const P=({target:I})=>{const k=e,{value:O}=I;O?(k.formData[I.name]=O,E(x=>({...x,[I.name]:O})),T(x=>({...x,[I.component]:I.label}))):(delete k.formData[I.name],E(x=>{const{[I.name]:j,...$}=x;return $}),T(x=>{const{[I.component]:j,...$}=x;return $})),typeof o=="function"&&o(e.formData)};R.useEffect(()=>{const I=document.title.replace("Error: ","");document.title=y.length>0?"Error: "+I:I},[y]);const U=w.classBuilder(l,a,c),g=e;g.actions=g.actions?.map(I=>I.label?{...I,label:w.interpolateString(I.label,g.formData)}:I),g.formData=w.Operate.runPageOperations(g,{...g.formData,...f},s||P);const L=e.title?d.jsx(S.Heading,{size:e.titleSize,children:w.FormPage.getTitle(e.title,e.formData)}):d.jsx(S.Label,{id:e.id,required:e.required,hideOptionalSuffix:e.hideOptionalSuffix,children:e.label}),v=e.components.filter(I=>w.Component.show(I,e.formData)).map((I,k)=>d.jsx(Ve,{component:I,onAction:O=>n(O,f,A),onChange:s||P,onTopLevelChange:r||P,value:e.formData[I.fieldId]||f[I.fieldId],formData:e.formData,pages:t,submitting:u},k));let F=null;return b&&y?.length>0?F=[{error:e?.customValidation?.[0]?.message}]:y?.length>0&&!b&&(F=y),d.jsxs("div",{className:U(),children:[F&&d.jsx(S.ErrorSummary,{errors:F,hashLink:i}),e.fieldset&&d.jsxs("fieldset",{className:"govuk-fieldset",children:[d.jsx("legend",{className:"govuk-fieldset__legend",children:L}),v]}),!e.fieldset&&d.jsxs(d.Fragment,{children:[L,v]}),d.jsx(_n,{actions:e.actions?.filter(I=>w.Component.show(I,e.formData)),onAction:I=>n(I,f,A)})]},e.id)},ts="hods-form-banner-strip",ar=({id:e,banners:t=[],formData:n,classModifiers:s})=>{const r=w.classBuilder(ts,s,""),o=t.filter(i=>w.Component.show(i,n));return d.jsx("div",{id:e,className:r(),children:o.map((i,l)=>{const a=`${e}-banner-${l}`;if(typeof i=="string"||i.type==="plain"){const c=typeof i=="string"?i:i.text;return d.jsx("div",{id:a,className:r("banner"),children:d.jsx(S.Markup,{content:w.interpolateString(c,n)})},a)}return d.jsx(S.Tag,{classBlock:`${ts}__tag`,classModifiers:i.classModifiers,text:w.interpolateString(i.text,n)},a)})})},va=e=>{if(e&&e.action){if(typeof e.action.onAction=="function")return{onClick:()=>e.action.onAction(e),onKeyPress:t=>{t.key==="Enter"&&e.action.onAction(e)},tabIndex:"0"};if(e.action.page)return{href:`/${e.action.page}`}}return{}},Pn=({row:e})=>{const[t,n]=R.useState({});return R.useEffect(()=>{n(va(e))},[e,n]),e.action?d.jsxs(S.Link,{...t,children:[e.action.label,e.action.aria_suffix&&d.jsxs(S.VisuallyHidden,{children:[" ",e.action.aria_suffix]})]}):null},cr=({row:e,classes:t,showAction:n=!1})=>d.jsxs("dl",{className:t("row"),role:"listitem",children:[d.jsxs("dt",{className:t("key"),children:[e.key,!e.required&&" (optional)"]}),d.jsx("dd",{className:t("value"),children:e.value}),n&&d.jsx("dd",{className:t("actions"),children:e.action&&d.jsx(Pn,{row:e})})]}),ur=({title:e,classes:t})=>d.jsx("div",{className:`${t("row")} ${t("title")}`,role:"listitem",children:d.jsx(S.SmallHeading,{children:e})}),Tt=(e,t,n,s,r)=>{const o={...e,formData:{...e.formData,...s}},i=jt(o,t);return t.type==="title"?d.jsx(ur,{title:t.key,classes:n}):d.jsx(cr,{row:{key:i.key,value:d.jsx(bn,{value:i.value||t.value,component:i.component,formData:o.formData,placeholder:r}),required:i.required},classes:n},`${i.fieldId}`)},Fa="govuk-summary-card",ja="govuk-summary-list",ft="Item",ht="Change",ns="Delete",Ua="warning",Ma=({id:e,entryData:t,config:n,onFullEdit:s,onDelete:r,masterPage:o,classModifiers:i=null,optionalFieldPlaceholder:l=null})=>{const a=S.Utils.classBuilder(Fa,i,n.className),c=S.Utils.classBuilder(ja,[]);return d.jsxs("div",{className:a(),id:e,children:[d.jsxs("div",{className:a("title-wrapper",[],"dark"),children:[d.jsxs("div",{className:a("title-content"),children:[d.jsx("h2",{className:a("title"),children:S.Utils.interpolateString(n.title||ft,{...t,index:t.index+1})}),n.banners&&d.jsx(ar,{id:`BannerStrip${t.id}`,banners:n.banners,formData:t})]}),d.jsxs("ul",{className:a("actions"),children:[d.jsx("li",{className:a("action"),children:n.changeAction&&typeof s=="function"&&n.changeAction.classModifiers?d.jsx(S.Button,{id:`${e}.changeButton`,onClick:()=>s(n.changeAction.page,t.id),classModifiers:n.changeAction.classModifiers,"aria-label":S.Utils.interpolateString(`${n.changeAction?.label||ht} ${n.title||ft}`,{...t,index:t.index+1}),children:n.changeAction?.label||ht}):d.jsx("button",{type:"button",className:"govuk-link govuk-link-button",onClick:()=>s(n.changeAction.page,t.id),"aria-label":S.Utils.interpolateString(`${n.changeAction?.label||ht} ${n.title||ft}`,{...t,index:t.index+1}),children:n.changeAction?.label||ht})}),d.jsx("li",{className:a("action"),children:n.deleteAction&&typeof r=="function"&&d.jsx(S.Button,{id:`${e}.deleteButton`,onClick:()=>r(t),classModifiers:n.deleteAction.classModifiers||Ua,"aria-label":S.Utils.interpolateString(`${n.deleteAction?.label||ns} ${n.title||ft}`,{...t,index:t.index+1}),children:n.deleteAction.label||ns})})]})]}),d.jsx("div",{className:a("content"),children:d.jsx("dl",{className:c(),role:"list",children:o?.childPages?.flatMap(u=>{const h=u.components.map(f=>w.Component.elevateNested([f],t)).flat().filter(Boolean);return u.summaryLayout?.sections?.flatMap(f=>{const y=f.columns.filter(p=>ae.meetsAll(p,{...u.formData,...t})).flatMap(p=>p.fields||[]);return y.length?y.flatMap(p=>{const A=h.find(T=>T.fieldId===p);return A?Tt(u,A,c,t,l):null}):null})})})})]})},ka=({id:e,"data-testid":t,actions:n,onFullEdit:s=null,entryData:r,formData:o,name:i,autoFocus:l})=>Array.isArray(n)?d.jsx(d.Fragment,{children:n.filter(a=>w.Component.show(a,o)).map(a=>d.jsx(S.Button,{id:e,"data-testid":t,onClick:()=>s(a?.page,r.id),classModifiers:a?.classModifiers||rs,"aria-label":w.FormPage.getConditionalText(a?.aria_label,r),name:i,autoFocus:l,children:a?.label||ss},e))}):d.jsx(S.Button,{id:e,"data-testid":t,onClick:()=>s(n?.page,r.id),classModifiers:n?.classModifiers||rs,"aria-label":w.FormPage.getConditionalText(n?.aria_label,r),name:i,autoFocus:l,children:n?.label||ss}),Ba=e=>{if(e.page)return e.page;const t=e.href||e.url;if(t)return t.split("/").pop()},vt=(e,t,n)=>{const s=t?.cya_link;return e!==!0&&s?{page:Ba(s)||t.id||"#",label:s.label||"Change",aria_suffix:s.aria_suffix,onAction:n}:null},dr=[_.ALERT,_.COLLECTION_SUMMARY,_.DETAILS,_.HEADING,_.HTML,_.INSET_TEXT],Ct=(e,t)=>{if(!e||dr.includes(e.type)||Object.prototype.hasOwnProperty.call(e,"show_on_cya")&&!e.show_on_cya)return!1;if(e.hideOnCyaWhenEmpty)if(e.type===_.COLLECTION){if(!se(t,e.full_path||e.fieldId)?.length)return!1}else{const n=se(t,e.fieldId);if(!n&&n!==!1&&n!==0)return!1}return e.type===_.CONTAINER?Lt.show(e,t):ot.show(e,t)},fr=e=>({...e,components:e.components.map(t=>Array.isArray(t.components)?{...t,components:t.components.map(n=>dr.includes(n.type)?null:{...n,...!n.full_path&&{full_path:`${t.full_path||`${e.full_path}.${t.fieldId}`}.${n.fieldId}`}}).filter(n=>!!n)}:{...t,...!t.full_path&&{full_path:`${e.full_path||e.fieldId}.${t.fieldId}`}})}),$a=(e,t)=>[{pageId:e.id,key:e.components[0].labels?.empty||"Nothing entered",required:e.required,action:vt(!1,e,t)}],Ya=(e,t,n,s)=>({id:t.id,fieldId:t.id,type:_.CONTAINER,required:e.required,full_path:s,components:e.item.map(r=>({...r,label:S.Utils.interpolateString(r.label,{...t,index:n}),full_path:`${s}.${r.fieldId}`}))}),Ha=(e,t,n,s,r)=>{const o={...$e,...e.labels};return o.item?{pageId:n,fieldId:e.fieldId,full_path:r,key:S.Utils.interpolateString(o.item,{...t,index:s}),type:"title",action:null}:null},xn=(e,t,n,s,r)=>Array.isArray(n)&&n.length&&Ct(t,e.formData)?n.flatMap((o,i)=>{const l=(t.countOffset||0)+i+1,a=`${t.full_path||t.fieldId}[${i}]`;let c=Ya(t,o,l,a);return c=fr(c),[Ha(t,o,e.id,l,a),...qe(e,c,o,s,r)??[]]}).filter(o=>!!o):$a(e,s),Va="hods-form-summary-card-details",hr=({masterPage:e,childCollections:t=[],formData:n,entryData:s,classModifiers:r,hideChildSectionTitles:o=!1,optionalFieldPlaceholder:i})=>{const l=w.classBuilder(Va,r),a=R.useMemo(()=>t.map(u=>e.childPages.find(h=>h.collection?.name===u)).filter(u=>!!u),[e,t]),c=(u,h,f)=>{let E=0;return u.flatMap((y,p)=>{let A=0;const T=y.fields?.flatMap(C=>h.filter(P=>P.fieldId===C).map(P=>{if(!P||!Ie(P,{...f.formData,...s}))return null;if(P.type===_.CONTAINER){const U=qe(f,P,s);return A+=1,d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:U.map(g=>{const L={...s,[g.fieldId]:s[P.fieldId]?.[g.fieldId]};return Tt(f,{...g,label:g.key},l,L,i)})},C)}if(P.type===_.COLLECTION){const U=xn({...f,formData:{...f.formData,...s}},P,s[P.id]);A+=1;let g=0;return d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:U.map(L=>{const v={...s,[L.fieldId]:s[P.fieldId]?.[L.fieldId]},F=Tt(f,{...L,label:L.key},l,v,i);return L.type==="title"&&(g+=1,g>1)?d.jsx("div",{style:{marginTop:"40px"},children:F}):F})},C)}return A+=1,d.jsx("div",{className:l("field"),style:{"--column":E+1,"--row":A},role:"list",children:Tt(f,P,l,s,i)},C)})).filter(C=>!!C);return!(p===u.length-1)&&T.length!==0?(E+=2,[...T,d.jsx("div",{className:l("divider"),style:{"--column":E}},`divider${E}`)]):T}).filter(y=>!!y)};return e?.childPages?.filter(u=>w.FormPage.show(u,{...n,...s})).map(u=>{const h=w.Component.elevateNested(u?.components,s);return u.summaryLayout?.sections.map(f=>{if(f.show_when&&!w.Condition.meetsAll(f.show_when,{...n,...s}))return null;if(f.type==="childCollection"){const y=a.find(A=>A.collection.name===f.collectionName),p=s[f.collectionName.split(".").pop()]||[];return y&&p.length>0?d.jsxs(d.Fragment,{children:[d.jsx("h3",{className:l("section-title"),children:f.title}),p.map(A=>d.jsx(hr,{masterPage:y,childMasterPages:[],formData:{...n,...s,...A},entryData:A,hideChildSectionTitles:!0,optionalFieldPlaceholder:i}))]}):null}const E=f.columns.filter(y=>ae.meetsAll(y,{...u.formData,...s}));return d.jsxs("div",{className:l("section"),children:[!o&&d.jsx("h3",{className:l("section-title"),children:w.FormPage.getConditionalText(f.title,{...u.formData,...s})}),d.jsx("dl",{className:l("section-content"),style:{"--dividers":E.length-1},children:c(E,h,u)})]},f.title)})}).filter(u=>!!u)||null},qa="hods-form-summary-card",ss="Change",Ga="Delete",Ka="Quick Edit",Wa="Duplicate",za="Full details",rs="secondary",os=({id:e,entryData:t,config:n,classModifiers:s,onFullEdit:r,onDelete:o,onDuplicate:i,onQuickEdit:l,parentCollectionName:a,childCollections:c=[],formData:u,masterPage:h,hideDetails:f=!1})=>{const[E,y]=R.useState(!1),p=S.Utils.classBuilder(qa,s,n.className),A=R.useMemo(()=>n.quickEdit?La(h,u,t):null,[h,n,u,t,E]),{addErrors:T,resetQuickEditErrors:N,clearTopLevelErrorsForCard:C,validate:b}=He(),{hooks:P}=Pe(),U=async(g,L)=>{if(g.type==="cancel"&&(y(v=>!v),N?.()),g.type==="save"&&typeof l=="function"){const v={...A.formData,...L,[`${a}ActiveId`]:t.id},F=b.page({...A,formData:v});if(F.length)return;let I;await P.onSubmit("quickEdit",v,()=>{},O=>{I=O}),I&&T(I);const k=F.concat(I);if(k.length===0||k.length===1&&k[0]===void 0){C();const O=w.CollectionPage.getData(a,u),{isDuplicate:x,...j}=O[t.index];O[t.index]={...j,...L},l({target:{name:a,value:O}}),y($=>!$)}}};return n.listView?d.jsx(Ma,{id:e,entryData:t,config:n,onFullEdit:r,onDelete:o,masterPage:h,classModifiers:s,optionalFieldPlaceholder:n.fullDetails?.optionalFieldPlaceholder}):d.jsxs("div",{className:p(),id:e,children:[d.jsxs("div",{className:p("header"),children:[d.jsxs("div",{className:p("header-content"),children:[n.banners&&d.jsx(ar,{id:`BannerStrip${t.id}`,banners:n.banners,formData:t}),d.jsx("h2",{id:`${e}.titleText`,className:p("header-content-title"),children:w.FormPage.getTitle(n.title,t)}),n.details&&d.jsx("div",{id:`${e}.titleDetail`,className:p("header-content-detail"),children:w.FormPage.getConditionalText(n.details,t)})]}),d.jsxs("div",{className:p("header-actions"),children:[n.quickEdit&&d.jsx(S.Button,{"data-testid":"quickedit-button",id:`${e}.quickEditButton`,onClick:()=>y(g=>!g),classModifiers:"primary",disabled:E,name:"QuickEdit",autoFocus:n.focusOn,children:Ka}),n.changeAction&&typeof r=="function"&&d.jsx(ka,{id:`${e}.changeButton`,"data-testid":"change-button",actions:n.changeAction,onFullEdit:r,entryData:t,formData:u,name:"Change",autoFocus:n.focusOn}),n.deleteAction&&typeof o=="function"&&d.jsx(S.Button,{id:`${e}.deleteButton`,onClick:()=>o(t),classModifiers:"secondary","aria-label":w.FormPage.getConditionalText(n.deleteAction?.aria_label,t),name:"Delete",children:n.deleteAction?.label||Ga}),n.duplicateAction&&typeof i=="function"&&d.jsx(S.Button,{"data-testid":"duplicate-button",id:`${e}.duplicateButton`,onClick:()=>{i(t)},classModifiers:"secondary","aria-label":w.FormPage.getConditionalText(n.duplicateAction?.aria_label,t),name:"Duplicate",autoFocus:n.focusOn,children:n.duplicateAction?.label||Wa})]})]}),E&&A&&d.jsx(In,{page:A,onAction:(g,L)=>U(g,L),className:p("editpage")}),d.jsx("div",{className:p("body"),children:!f&&d.jsx(S.Details,{summary:n.detailsTitle||za,className:"details",children:d.jsx(hr,{masterPage:h,childCollections:c,formData:u,entryData:t,optionalFieldPlaceholder:n.fullDetails?.optionalFieldPlaceholder})})})]})},Ja=({entryId:e,topLevelErrors:t=[],clearTopLevelErrorsForCard:n,children:s})=>{const{hooks:r}=Pe(),o=t.filter(h=>h.entryId===e)||[],[i,l]=R.useState(null),a=()=>{l(null)},c=h=>{l(f=>(f??[]).concat(h))},u={page:h=>{const f=w.Validate.page(h),E=r.onValidate(h,f);return l(E),E}};return d.jsx(Cn.Provider,{value:{addErrors:c,errors:i===null?[...o]:i,resetQuickEditErrors:a,clearTopLevelErrorsForCard:n,validate:u},children:s})},is="Add",Xa=({config:e,formData:t,onAction:n,onChange:s,onTopLevelChange:r,pages:o=[]})=>{const{hooks:i}=Pe(),{errors:l,addErrors:a,clearErrors:c,queuedErrors:u,enqueueErrors:h,dequeueErrors:f}=He(),[E,y]=R.useState(null),p=R.useMemo(()=>w.CollectionPage.getData(e.collectionName,t)||[],[t]),A=Array.isArray(p)&&p.length>0?p.reduce((L,v)=>v.isDuplicate&&(!L||v.id>L.id)?v:L,null):null,T=R.useMemo(()=>{const L=e.collectionName.split(".");let v=w.CollectionPage.mergePages(o||[])||[];return L.reduce((F,I,k)=>{const O=k===0?`${F}${I}`:`${F}.${I}`;return k===L.length-1?v?.find(x=>x.collection?.name===O)||null:(v=v.find(x=>x.collection?.name===O)?.childPages||null,O)},"")},[o]),N=R.useMemo(()=>e.card.listView?T.childPages?.reduce((v,F)=>{const I=et(F.components,{...t,...E});return v.concat(I)},[])||[]:[],[T,t,E,e.card.listView]),C=()=>{u.length>0&&f(v=>v.raisedBy===e.id);const L=gn(e,T,t,i);L.length>0&&h(L)};R.useEffect(()=>{Array.isArray(p)&&p.length>0&&C()},[p]);const b=(L,v)=>{if(typeof n=="function"){const F=[...p],I=p.findIndex(x=>x.id===v),{isDuplicate:k,...O}=p[I];F[I]={...O},n({type:mt.SAVE_AND_NAVIGATE,page:L,addToFormData:[{field:`${e.collectionName.split(".").pop()}ActiveId`,value:v},{field:e.collectionName,value:F,isCollection:!0}]})}},P=L=>{w.CollectionPage.duplicateEntry(e.collectionName,t,L.id,e.card?.duplicateAction?.fieldsToIgnore||[],{isDuplicate:!0});const v=e.collectionName.split(".").shift();typeof r=="function"&&(r({target:{name:v,value:w.CollectionPage.getData(v,t)}}),C())},U=()=>{if(!E)return;w.CollectionPage.removeEntry(e.collectionName,t,E.id);const L=e.collectionName.split(".").shift();typeof r=="function"&&r({target:{name:L,value:w.CollectionPage.getData(L,t)}}),y(null),C()},g=L=>{const v=N.find(I=>I.fieldId===L);if(!v)return null;const F=jt({...T,formData:{...t,...E}},v);return d.jsx("div",{className:"confirmation-field-value",children:d.jsx(bn,{value:F.value,component:F.component,formData:F.formData})},L)};return d.jsxs("div",{id:e.fieldId,children:[E&&d.jsx(Pa,{id:`${e.fieldId}.confirmation`,message:w.interpolateString(e.confirmation?.message,{...E,index:E.index+1})||null,confirmLabel:w.interpolateString(e.confirmation?.label,E)||null,onConfirm:U,onCancel:()=>y(null),children:e.card.listView?d.jsx("div",{className:"confirmation-content",children:e.confirmation?.displayFields.map(g)}):d.jsx(os,{id:`${e.fieldId}.confirmationChild`,entryData:E,config:e.card?{...e.card,quickEdit:null}:{},masterPage:T,classModifiers:"nested",hideDetails:!0})}),!e.card.listView&&e.addButton&&d.jsx(rn,{id:`${e.fieldId}.addButton`,action:{collection:e.collectionName,label:w.interpolateString(e.addButton.label||is,{documents:p}),page:e.addButton.page,type:mt.COLLECTION_ADD,classModifiers:["secondary"]},onAction:n}),d.jsx("ul",{className:"collection-summary-card-list",children:p.map((L,v)=>{const F=l.filter(O=>O.entryId===L.id).length>0,I={...e.card,...L.isDuplicate&&e.duplicatedCard?e.duplicatedCard:{},...F&&e.errorCard?e.errorCard:{},focusOn:A?.id===L.id},k=`${e.fieldId}.summaryCard${L.id}`;return d.jsx("li",{children:d.jsx(Ja,{entryId:L.id,topLevelErrors:l,clearTopLevelErrorsForCard:()=>{const O=l.filter(x=>x.entryId!==L.id);c(),a(O)},children:d.jsx(os,{id:k,entryData:{...L,index:v},masterPage:T,config:I||{},onFullEdit:b,onDuplicate:P,onDelete:()=>y({...L,index:v}),onQuickEdit:O=>(C(),s(O)),parentCollectionName:e.collectionName.split(".").shift(),childCollections:e.childCollections||[],formData:t,classModifiers:L.id===E?.id?["deleting-summary-card"]:[""],inError:l.filter(O=>O.entryId===L.id).length>0},k)})})})}),e.card.listView&&e.addButton&&d.jsx(rn,{id:`${e.fieldId}.addButton`,action:{collection:e.collectionName,label:w.interpolateString(e.addButton.label||is,{documents:p}),page:e.addButton.page,type:mt.COLLECTION_ADD,classModifiers:["secondary"],customAction:{type:e.addButton.customAction}},onAction:n})]})},Qa="hods-form-collection",Za=({config:e,value:t,formData:n,onChange:s=void 0,onTopLevelChange:r=void 0,wrap:o=!1})=>{const[i,l]=R.useState(t),a=p=>{l(p),typeof s=="function"&&s({target:{name:e.fieldId,value:p}})},c=({target:p})=>{if(typeof s=="function")if(p.name===w.Meta.name)s({target:p});else{const A=i.findIndex(T=>T.id===p.name);a([...i.slice(0,A),p.value,...i.slice(A+1)])}},u=async()=>{a([...i,{id:_t.v4()}])},h=async p=>{a(i.filter(A=>A.id!==p.id))},f=p=>p.initial&&!i.length?p.initial:p.add;R.useEffect(()=>{if(e.focusOnAdd&&Array.isArray(i)&&i.length&&(i.length>e.minimumEntries||!e.minimumEntries)){const p=i[i.length-1]?.id,T=document.getElementById(p)?.childNodes[0]?.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');T&&T.length>0&&T[0].focus()}},[i.length,e.focusOnAdd,e.minimumEntries]),R.useEffect(()=>{e.minimumEntries&&!i.length&&u()},[e.minimumEntries,i.length]);const E={...$e,...e.labels},y=w.classBuilder(Qa,[],e.className);return d.jsxs("div",{className:y(),id:e.id,children:[e.label&&d.jsx(S.Label,{id:e.id,required:e.required,className:y("title"),children:e.label}),Array.isArray(i)&&i.map((p,A)=>{const T=`${e.full_path||e.fieldId}[${A}]`,N=(e.countOffset||0)+A+1,C=w.interpolateString(E.item,{...p,index:N}),b=w.interpolateString(E.remove,{...p,index:N}),P=e.disableAddAndRemove||A===0&&e.minimumEntries?"":e.removeLocation??"start",U=A!==0&&e.subsequentItemStyle?e.subsequentItemStyle:{};return d.jsxs("div",{className:`${y("item")}`,style:U,children:[d.jsxs(S.Label,{id:p.id,required:!0,className:y("item-title"),children:[C,P==="start"&&d.jsx(S.Button,{onClick:()=>h(p),classModifiers:"secondary",children:b})]}),d.jsx(Ln,{container:{id:p.id,fieldId:p.id,type:"container",required:e.required,full_path:T,components:e.item.map(g=>{const{firstOnlyLabel:L,...v}=g;let{hint:F}=g;e.restrictHint&&A>0&&(F=void 0);let{label:I}=g;return A===0&&(I=g.firstOnlyLabel??g.label),{...v,hint:F,readonly:!!(e?.readonly||g.readonly),label:w.interpolateString(I,{...p,index:N}),full_path:`${T}.${g.fieldId}`}})},value:p,formData:n,onChange:c,onTopLevelChange:r,wrap:o}),P==="end"&&d.jsx(S.ButtonGroup,{className:"govuk-!-margin-top-2",children:d.jsx(S.Button,{onClick:()=>h(p),classModifiers:"secondary",children:b})})]},p.id)}),!e.disableAddAndRemove&&d.jsx(S.ButtonGroup,{children:d.jsx(S.Button,{onClick:u,classModifiers:"secondary",children:f(E)})})]})},ec=(e,t,n)=>{const s=e,r=typeof s.value=="object"?s.value?.value:s.value,o=n.find(i=>String(i.id)===r);return s.label=o===void 0?s.value||"":o.label,s.component=t.cya_label,s},tc=(e,t)=>typeof e=="string"?!!S.Utils.interpolateString(e,t):!!e,Vt=(e,t)=>{if(Array.isArray(t)){const n=t.find(s=>s.id===(e.full_path||e.id));if(n){const s={error:n.error};return n.properties&&(s.propsInError=n.properties),s}}},nc=[_.RADIOS,_.CHECKBOXES,_.DATE,_.TIME],sc=e=>e.fieldset||nc.includes(e.type),Ve=({component:e,value:t=null,formData:n=null,wrap:s=!0,onAction:r,onChange:o,onTopLevelChange:i,pages:l=[],submitting:a=!1,...c})=>{const{hooks:u}=Pe(),h=He(),{data:f,status:E}=ga(e,n),[y,p]=R.useState([]);R.useEffect(()=>{E===yt&&p(f)},[e,f,E]);const A=({target:C})=>typeof o=="function"?(e.type===_.EMAIL&&(C.value=C.value.trim()),e.type===_.CHECKBOXES&&Array.isArray(C.value)&&C.value.forEach(b=>{b.children&&b.nested&&(delete b.children,delete b.nested)}),C=ec(C,e,f),e.type===_.SELECT&&C.value===""&&(C.value=null,C.label=null),o({target:C}),!0):!1;if(R.useEffect(()=>{const C=w.Component.defaultValue(e,n);!t&&!n?.[e.fieldId]&&C&&typeof A=="function"&&A({target:{name:e.fieldId,value:C}})},[]),e.type===_.CONTAINER){let C=d.jsx(Ln,{...c,container:e,wrap:s,onChange:A,onTopLevelChange:i,value:t||w.Component.defaultValue(e,n),formData:n});return e.fieldset&&(C=Xe(e,C)),e.additionalValidation&&(C=Xe({...e,...Vt(e,h?.errors)},C)),C}if(e.type===_.COLLECTION)return d.jsx(Za,{...c,config:e,wrap:s,onChange:A,onTopLevelChange:i,value:t||w.Component.defaultValue(e,n),formData:n});if(e.type===_.COLLECTION_SUMMARY)return Xe({...e,...Vt(e,h?.errors)},d.jsx(Xa,{...c,config:e,formData:n,onAction:r,onChange:o,onTopLevelChange:i,pages:l}));const T=C=>{let b=e.full_path||e.fieldId;if(e.pageCollection){const P=w.CollectionPage.getActiveIndex(e.pageCollection.name,n);b=`${`${e.pageCollection.name}[${P}]`}.${b}`}i({target:{name:w.Meta.name,value:w.Meta.documents.setForField(C,n,b,e.allowMultiple)}})},N=({target:C})=>{if(A({target:C})){if(e.type===_.FILE)T([C.value]);else if(e.type===_.MULTI_FILE){const b=C.value.map((P,U)=>({...P,indexInField:U}));T(b)}}};return w.Component.get({...c,...e,id:e.full_path||e.id,...Vt(e,h?.errors),fieldset:sc(e),disabled:tc(e.disabled,n),label:w.interpolateString(e.label,n),content:w.interpolateString(e.content,n),hint:w.interpolateString(e.hint,n),cya_label:w.interpolateString(e.cya_label,n),suffix:w.interpolateString(e.suffix,n),options:y,value:t,onChange:N,onTopLevelChange:i,formData:n,onAction:r,submitting:a},s,u.onGetComponent)},rc=[_.AUTOCOMPLETE,_.CALCULATION,_.CHECKBOXES,_.COLLECTION_SUMMARY,_.DATE,_.EMAIL,_.FILE,_.MULTI_FILE,_.PHONE_NUMBER,_.RADIOS,_.SELECT,_.TEXT,_.TEXT_AREA,_.TIME],mr=e=>rc.includes(e?.type)||e?.isEditable||!1,oc="govuk-list",ic="govuk-body",lc=e=>{const t=te(e),n=S.Utils.interpolateString(e.heading,e.formData),s=S.Utils.interpolateString(e.text,e.formData);return d.jsx(S.Alert,{...t,heading:n,children:s})},ac=e=>{const t=te(e),n=de.getAutocompleteSource(e);return d.jsx(S.Autocomplete,{...t,source:n})},cc=e=>{let t=[];de.getOptions(e,s=>{t=s}),t=t.map(s=>Array.isArray(s.nested)?{...s,children:pr(e,s.nested)}:s);const n=te(e);return d.jsx(S.Checkboxes,{...n,options:t})},uc=e=>{const t=de.applyFormula(e);typeof e.onChange=="function"&&t!==e.value&&e.onChange({target:{name:e.fieldId,value:t}});const n=te(e,["formula"]);return d.jsx(S.TextInput,{...n,readonly:!0})},dc=e=>{const t=te(e);return d.jsx(S.DateInput,{...t})},fc=e=>{const t=te(e,["tagName"]),n=Ft(e);return d.jsx(S.Details,{...t,children:n})},hc=e=>{const t=te(e);return d.jsx(S.FileUpload,{...t})},mc=e=>{const t=te(e);return d.jsx(S.MultiFileUpload,{...t})},pc=e=>{const t=te(e);return d.jsx(S.Heading,{...t,children:e.content})},Ft=e=>{const t=te(e);return d.jsx(S.Markup,{...t})},Ec=e=>{const t=te(e);return d.jsx(S.InsetText,{...t,children:e.content})},Ac=e=>{const t=te(e,["ordered"]),n=e.ordered?"ol":"ul",s=e.ordered?"number":"bullet",r=S.Utils.classBuilder(oc,s),o=t.items?.map(i=>`<li>${i}</li>`).join("");return Ft({...t,className:r(),tagName:n,content:o,type:_.HTML})},yc=e=>{const t=te(e);return Ft({className:ic,...t,tagName:"p",type:_.HTML})},Tc=e=>{let t=[];de.getOptions(e,s=>{t=s}),t=t.map(s=>Array.isArray(s.nested)?{...s,children:pr(e,s.nested)}:s);const n=te(e);return d.jsx(S.Radios,{...n,options:t})},Sc=e=>{const t=te(e);return d.jsx(S.TextArea,{...t})},Cc=e=>{const t=te(e);return d.jsx(S.TextInput,{...t})},gc=e=>{const t=te(e);return d.jsx(S.TimeInput,{...t})},bc=e=>{let t=[];de.getOptions(e,s=>{t=s});const n=te(e);return d.jsx(S.Select,{...n,options:t})},wc=e=>{const t=te(e);return d.jsx(S.WarningText,{...t,children:e.content})},_c=e=>{switch(e.type){case _.HTML:return Ft(e);case _.HEADING:return pc(e);case _.INSET_TEXT:return Ec(e);case _.TEXT:case _.EMAIL:case _.PHONE_NUMBER:return Cc(e);case _.TEXT_AREA:return Sc(e);case _.AUTOCOMPLETE:return ac(e);case _.RADIOS:return Tc(e);case _.CHECKBOXES:return cc(e);case _.DATE:return dc(e);case _.TIME:return gc(e);case _.FILE:return hc(e);case _.MULTI_FILE:return mc(e);case _.WARNING:return wc(e);case _.SELECT:return bc(e);case _.DETAILS:return fc(e);case _.CALCULATION:return uc(e);case _.ALERT:return lc(e);case _.PARAGRAPH:return yc(e);case _.LIST:return Ac(e);default:return null}},Ic=(e,t)=>{const n={...t};if(e.full_path){const s=e.full_path.split(".");s.pop(),s.push(n.fieldId),n.full_path=s.join(".")}return e.formData&&(n.value=e.formData[n.fieldId]||de.getSource(e.formData,n.full_path)||""),"readonly"in n&&delete n.readonly,e.readonly?(n.readonly=e.readonly,d.jsx("div",{children:Er(n,!1)})):d.jsx(Ve,{component:n,value:n.value,onChange:e.onChange,onTopLevelChange:e.onChange,formData:e.formData},n.key)},pr=(e,t)=>{const n=t.filter(s=>!(s.show_when&&!ae.meetsAll(s.show_when,e.formData))).map(s=>d.jsx(d.Fragment,{children:Ic(e,s)},s.id));return n.length>0?n:null},Er=(e,t=!0,n=void 0)=>{if(typeof n=="function"){const r=n(e,t);if(r)return r}const s=_c(e);return s&&t&&mr(e)?Xe(e,s):s},Pc=e=>e.defaultValue||e.defaultObjectValue,xc=e=>{const n=/^(\d{1,2})-\d{1,2}-(\d{4})$/.test(e.defaultValue)?e.defaultValue:null;return e.defaultValue==="today"?K().format("DD-MM-YYYY"):n},Oc=(e,t)=>{const n={...e};let s=null;return!n.literal&&!n.sourced&&(n.sourced={...n}),n.literal&&(s={...n.literal}),n.sourced&&(s=s??{},Object.keys(n.sourced).every(r=>{const o=typeof n.sourced[r]=="string"&&se(t,n.sourced[r]);return o===void 0&&n.skipIfSourceInvalid?(s=null,!1):(s[r]=o||n.sourced[r],!0)})),s},Ar=(e,t)=>Pc(e)?e.type===_.DATE?xc(e):(e.defaultObjectValue?Oc(e.defaultObjectValue,t):null)||e.defaultValue||null:null,Rc={[_.COLLECTION]:[],[_.CONTAINER]:{}},Nc=(e,t)=>e&&(Ar(e,t)||Rc[e.type])||"",ot={clean:te,defaultValue:Nc,defaultValueFromConfig:Ar,editable:mr,elevateNested:et,get:Er,setupContainerPaths:fr,show:Ie,wrap:Xe},Lc=(e,t)=>{e.data?.options?.forEach(n=>{Array.isArray(n.nested)&&Ze(t.formData[e.id],n)&&n.nested.forEach(s=>{const r=s;r.value=t.formData[r.id]})})},jt=(e,t,n)=>{let s="";return e.formData&&t.fieldId&&(s=e.formData[t.fieldId],Lc(t,e)),{pageId:e.id,id:t.id,fieldId:t.fieldId,full_path:t.full_path,key:S.Utils.interpolateString(t.cya_label||t.label,e.formData),required:t.required,component:ot.editable(t)?t:void 0,value:s||"",action:e.cya_link?.singleChangeLink?null:vt(t.readonly,e,n)}},qe=(e,t,n,s,r)=>Ct(t,{...e.formData,...n})?et(t.components.filter(i=>i.show_on_cya===void 0||i.show_on_cya),n).filter(i=>Ct(i,{...e.formData,...n})).flatMap(i=>{const l=n?n[i.fieldId]:void 0;if(typeof r=="function"){const a=r({...e,formData:n},i,s);if(a)return a}return i.type===_.CONTAINER?qe(e,i,{...l,...n},s,r):i.type===_.COLLECTION?xn(e,i,l,s,r):jt({...e,formData:n},i,s)}):null,Dc=e=>{if(!e.conditionalProperties)return e;let t={...e};return e.conditionalProperties.forEach(n=>{w.Condition.met(n.condition,e.formData[n.condition.field])&&(t=Object.assign(t,n.properties))}),t},ls=(e,t,n="text")=>{if(typeof e=="string")return S.Utils.interpolateString(e,t);if(!Array.isArray(e)||Object.keys(t).length===0)return null;const s=e.find(r=>typeof r=="string"?!0:Ue(r.show_when,t));return typeof s=="string"?S.Utils.interpolateString(s,t):S.Utils.interpolateString(s[n],t)},vc=e=>{const t={...e};return t.page||(t.href?t.page=t.href.split("/").pop():t.url&&(t.page=t.url.split("/").pop())),t},Fc=e=>{if(e&&Array.isArray(e.actions))return e.actions.map(t=>{if(typeof t=="string")return W.DEFAULTS[t];if(t&&typeof t=="object"){const n=t;return W.DEFAULTS[n.type]?.validate&&!n.hasOwnProperty("validate")&&(n.validate=!0),vc(n)}}).filter(t=>!!t)},jc=e=>({type:_.HTML,tagName:"p",content:e}),Uc=(e,t)=>{const n=e.use.split("."),s=n.shift();let r=JSON.parse(JSON.stringify({...t.find(l=>l.id===s)})),o=r,i=r;for(;o&&n.length>0;){const l=n.shift();Array.isArray(o.components)?(i=o,i.components=i.components.filter(a=>a.id===l),i.components.length>0?o=i.components[0]:o=void 0):o=void 0}if(o)return o={cya_label:o.label,...o,...e},i&&i.id!==o.id?i.components=[o]:r=o,o.item&&Array.isArray(o.item)&&(o.item=o.item.map(l=>l.use?ln(l,t):l)),r},ln=(e,t)=>{if(e){const n=Uc(e,t);if(n)return n}return{...e}},yr=(e,t,n)=>{if(!e)return null;const s=e.components.map(o=>{if(typeof o=="string")return jc(o);let i;return o.type===_.CONTAINER&&(o.components=o.components.map(l=>l.use?ln(l,t):l)),o.use?i=ln(o,t):i={...o},n?de.refData.setupUrl(i,n):i}),r=Fc(e);return Lt.setup({...e,formData:n,components:s,actions:r})},Mc=(e,t,n)=>Array.isArray(e)?e.map((s,r)=>({...yr(s,t,n),index:r})):[],Tr=(e,t)=>e?.hasOwnProperty("show_on_cya")&&!e.show_on_cya?!1:Dt(e,t),it={applyConditionalProperties:Dc,getConditionalText:ls,get:yr,getAll:Mc,getTitle:(e,t)=>ls(e,t,"title"),show:Dt,showCYA:Tr},kc=(e,t)=>{if(!e)return null;if(!t)return e;const n={...e};return n.show_when?Array.isArray(t)?n.show_when=Array.isArray(n.show_when)?[...t,...n.show_when]:[...t,n.show_when]:n.show_when=Array.isArray(n.show_when)?[...n.show_when,t]:[n.show_when,t]:n.show_when=t,n},Bc=(e,t)=>{const n=e.split(".").pop();t[`${n}ActiveId`]=null},Ut=(e,t)=>{const n=e.split(".").pop();return t[`${n}ActiveId`]||null},$c=e=>typeof e=="number"&&e>=0,Sr=(e,t,n)=>{const s=e[0];if(e.length===1)return t[s]||null;const r=n?.[`${s}ActiveId`]||null;if(!r)return null;const o=t[s]?.findIndex(i=>i.id===r);return $c(o)?(e.shift(),Sr(e,t[s][o],n)):null},Ge=(e,t)=>{const n=e.split(".");return Sr(n,t,t)},Cr=(e,t,n,s=[],r={})=>{const o=Ge(e,t),i=o?.find(u=>u.id===n);if(!i)return null;const l=_t.v4(),a={...i,...r,id:l};s.forEach(u=>delete a[u]);const c=o.findIndex(u=>u.id===n)+1;return c===-1?o.push(a):o.splice(c,0,a),t[`${e.split(".").pop()}ActiveId`]=a.id,l},Yc=(e,t)=>{const n=Ut(e,t);return Cr(e,t,n)},Hc=e=>typeof e=="number"&&e>=0,gr=(e,t,n)=>{const s=e[0],r=n?.[`${s}ActiveId`]||null;if(!r)return null;const o=t[s]?.findIndex(i=>i.id===r);return Hc(o)?e.length===1?o:(e.shift(),gr(e,t[s][o],n)):null},br=(e,t)=>{const n=e.split(".");return gr(n,t,t)},Vc=e=>({id:e.id,name:e.name,...e.collection.show_when&&{show_when:e.collection.show_when},orderInForm:e.orderInForm,deleteCollectionWhenHidden:e.deleteCollectionWhenHidden,collection:{masterPage:!0,...e.collection},formData:{...e.formData},childPages:[e]}),qc=(e,t)=>{t.collection={...t.collection,...e.collection},t.formData={...t.formData,...e.formData},t.childPages=[...t.childPages,e]},Gc=(e,t)=>{const n=e.collection.name.split(".");if(n.length===1)return!1;n.pop();const s=n.join("."),r=t[s]||null;return r?(r.childPages.push(e),r.childPages.sort((o,i)=>o.orderInForm-i.orderInForm),!0):!1},wr=e=>{const t={};return e.map((s,r)=>{if(s.orderInForm=r,s?.collection?.name){if(!t[s.collection.name]){const o=Vc(s);return t[s.collection.name]=o,o}return qc(s,t[s.collection.name]),null}return s}).filter(s=>!!s).map(s=>s.collection?.masterPage&&Gc(s,t)?null:s).filter(s=>!!s)},Kc=(e,t,n)=>{const s=Ge(e,t);if(!s)return null;const r=s.findIndex(l=>l.id===n);if(r===-1)return null;const o=s[r];s.splice(r,1);const i=t;return i[`${e}ActiveId`]=s.length>0?s[0].id:null,o},Wc=e=>typeof e=="number"&&e>=0,On=(e,t,n)=>{const s=e.split("."),r=s[s.length-1];let o=n;s.some(i=>{if(o[i]||(o[i]=[]),!o[i].find(c=>c.id===n[`${i}ActiveId`])){const c=_t.v4();n[`${i}ActiveId`]=n[`${i}ActiveId`]||c,o[i].push({id:n[`${i}ActiveId`]})}if(i===r)return o[r]=t,!0;const l=n[`${i}ActiveId`],a=o[i]?.findIndex(c=>c.id===l);return Wc(a)?(o=o[i][a],!1):!0})},gt={addEntry:Bc,duplicateActiveEntry:Yc,duplicateEntry:Cr,getActiveId:Ut,getActiveIndex:br,getData:Ge,getErrorsForCollection:gn,mergePages:wr,removeEntry:Kc,setData:On},zc=e=>typeof e=="number"&&e>=0,Jc=(e,t,n,s,r,o)=>{const i=r?.label||$e.remove;return{pageId:e.id,fieldId:`delete${s}`,key:`delete${s}`,type:"action",action:{onAction:()=>{n(null,a=>{const c=a;if(!o)return c;Object.entries(o).forEach(f=>{const[E,y]=f;c[E]=y});const u=gt.getData(e.collection.name,c),h=u?.findIndex(f=>f.id===t.id);return zc(h)&&u.splice(h,1),c})},label:S.Utils.interpolateString(i,{...t,index:s})}}},Xc=(e,t,n,s,r,o={})=>{const i=r?.label||$e.change;return{pageId:e.id,fieldId:`change${s}${r.page}`,key:`change${s}${r.page}`,type:"action",action:{onAction:l=>{const a=c=>{const u=c;return Object.entries(o).forEach(h=>{const[f,E]=h;u[f]=E}),u};n(r.page?{pageId:r.page}:l,a)},label:S.Utils.interpolateString(i,{...t,index:s})}}},Qc=(e,t)=>t.show_when?Ue(t.show_when,e):!0,Zc=(e,t,n,s)=>({id:t.id,fieldId:t.id,type:_.CONTAINER,required:!0,full_path:s,components:e.components.map(r=>({...r,label:S.Utils.interpolateString(r.label,{...t,index:n}),full_path:`${s}.${r.fieldId}`}))}),eu=(e,t,n,s,r)=>{const o={...$e,...e.collection.labels};return{pageId:n,fieldId:"Title",full_path:`${r}.Title`,key:S.Utils.interpolateString(o.item,{...t,index:s}),type:"heading",size:e.collection.titleSize||"s"}},tu=(e,t,n,s,r)=>e.text===""?null:{pageId:t,fieldId:`heading${n}`,full_path:`heading${n}`,key:S.Utils.interpolateString(e.text,r),type:s===null?"heading":"headingWithAction",size:e.size||"s",action:s===null?null:{onAction:s,label:"Change"}},nu=(e,t,n,s)=>({pageId:e.id,fieldId:`${e.collection.name}Title`,full_path:`${e.collection.name}Title`,key:n?.text||t.charAt(0).toUpperCase()+t.slice(1),type:s==null?"heading":"headingWithAction",size:n?.size||"m",action:s===null?null:{onAction:s,label:"Change"}}),su=(e,t,n,s,r,o={})=>e.collection?.actions?.filter(i=>Qc(r,i)).map(i=>i.type==="remove"?Jc(e,t,n,s,i,o):i.type==="change"?Xc(e,t,n,s,i,o):null).filter(i=>!!i),_r=(e,t,n={})=>()=>{const s=r=>{const o=r;return Object.entries(n).forEach(i=>{const[l,a]=i;o[l]=a}),o};t({pageId:e.id},s)},ru=(e,t,n,s,r,o,i)=>{let l=[];return e.forEach(a=>{let c=a;if(c.collection.masterPage)l=l.concat(Ir(c,n,s,t,i));else if(c.collection.route&&(c=kc(c,c.collection.route)||c),Tr(c,{...c.formData,...t})){const u=_r(c,n,i);if(c.collection.heading){const E=c.collection.heading.changeLink?u:null,y=tu(c.collection.heading,c.id,r,E,t);l=l.concat(y)}const h=Zc(c,t,r,o),f=qe({...c,formData:{...c.formData,...t}},h,{...c.formData,...t},u,s);l=l.concat(f)}}),l},Ir=(e,t,n,s,r={})=>{const o=e.collection.name.split(".").pop();let i=s[o]||null;const l=s[`${o}ActiveId`];if(!i||i.length===0)return[];let a=[];if(!e.collection.hideNameFromCYA){const f=e.collection.collectionHeading?.changeLinkPage?_r({id:e.collection.collectionHeading.changeLinkPage},t,r):null;a.push(nu(e,o,e.collection.collectionHeading,f))}let c=0;const u=Array.isArray(e.collection.hideItemTitles)?Ue(e.collection.hideItemTitles,s):e.collection.hideItemTitles;return(Array.isArray(e.collection.onlyShowActiveEntryOnCYA)?Ue(e.collection.onlyShowActiveEntryOnCYA,s):e.collection.onlyShowActiveEntryOnCYA)&&(i=[i.find((E,y)=>(c=y,E.id===l))]),i.forEach(f=>{if(!f)return;r={...r,[`${o}ActiveId`]:f.id};const E=c+1,y=e.collection?.actionPosition||"top",p=`${e.collection.name}[${c}]`,A=su(e,f,t,E,s,r);if(!u){const T=eu(e,f,e.id,E,p);a=a.concat(T)}y==="top"&&(a=a.concat(A)),a=a.concat(ru(e.childPages,f,t,n,E,p,r)),y==="bottom"&&(a=a.concat(A)),c+=1}),a.filter(f=>!!f)},ou=e=>e.value?e.component?d.jsx("div",{children:d.jsx(Ve,{component:{...e.component,readonly:!0},wrap:!1,value:e.value})},e.id):e.value:null,iu=(e,t)=>{let n=-1;return{value:d.jsx(d.Fragment,{children:e.components.map(r=>{const o=t.findIndex(i=>i.id===r);return n<0&&(n=o),o>-1?ou(t[o]):null})}),firstComponentIndex:n}},lu=(e,t,n,s)=>{const{value:r,firstComponentIndex:o}=iu(t,n);return{row:{pageId:e.id,fieldId:t.id,key:t.label,required:t.required,value:r,action:vt(!1,e,s)},insertAt:o}},au=(e,t,n=null)=>{if(it.showCYA(e,e.formData)){if(e.collection)return Ir(e,t,n,e.formData);const r=et(e.components,e.formData).filter(o=>Ct(o,e.formData)).flatMap(o=>{if(typeof n=="function"){const i=n(e,o,t);if(i)return i}switch(o.type){case _.CONTAINER:return qe(e,o,e.formData[o.fieldId],t,n);case _.COLLECTION:return xn(e,o,e.formData[o.fieldId],t,n);default:return jt(e,o,t)}});if(e.groups?.length>0){e.groups.forEach(i=>{const{row:l,insertAt:a}=lu(e,i,r,t);a>-1?r.splice(a,0,l):r.push(l)});const o=e.groups.flatMap(i=>i.components);return r.filter(i=>!o.includes(i.id))}return r}return[]},cu={getRows:au,getCYARowsForContainer:qe},Pr=(e,t)=>{if(e&&t)switch(e.type){case"lowercase":return t.toLowerCase();case"uppercase":return t.toUpperCase();default:return t}return t},xr=(e,t,n)=>{const s=t;e.format&&e.format.on===n&&(s[e.fieldId]=Pr(e.format,s[e.fieldId]))},Or=(e,t,n)=>{e.forEach(s=>xr(s,t,n))},Rr=(e,t,n)=>{Or(e.components,t,n)},uu=(e,t,n)=>{e.forEach(s=>Rr(s,t,n))},du=(e,t,n)=>{const s={...t};return Or(e.components,s,n),uu(e.pages,s,n),s},fu={component:xr,data:Pr,form:du,page:Rr},hu=(e,t,n,s)=>{if(e===ne.HUB&&t){if(t.format===ye.CYA)return ye.CYA;if(t.components)return it.get(t,n,s)}if(e===ne.TASK||e===ne.FORM_WITH_TASK)return ye.TASK},mu={get:hu},Rn="meta",Nn="documents",an=e=>e?.[Rn]?.[Nn]||[],pu=(e,t,n,s)=>{const r=s?an(t):an(t).filter(i=>i.field!==n);return Array.isArray(e)&&e.forEach(i=>{r.push({...i,field:n})}),{...t?t[Rn]:void 0,[Nn]:r}},Eu={setForField:pu,get:an,name:Nn},Au={documents:Eu,name:Rn},yu=(e,t)=>{if(e?.field){const n=S.Utils.interpolateString(e.field,t);return!!se(t,n)}return!1},qt=(e,t)=>{if(e?.value)return e.value;const n=S.Utils.interpolateString(e?.field,t);return se(t,n)},Tu=(e,t)=>{if(!e||!t)return null;const n=S.Utils.interpolateString(e.target,t),s=se(t,n),r=qt(e,t),o=qt(e.cutoff,t),i=qt(e.ignore,t);let l=null;return s&&r&&Array.isArray(s)&&s.every((a,c)=>c===o?!1:c===i?!0:a===r||e.key&&se(a,e.key)===r?(l=c,!1):!0),typeof l=="number"?l.toString():l},Su=(e,t,n)=>{let s;if(e?.field){const r=S.Utils.interpolateString(e.field,t);s=se(t,r)}else s=e?.value;s!=null&&e.name&&t[e.name]!==s&&n({target:{name:e.name,value:s}})},Cu=(e,t)=>{if(e?.field){const n=S.Utils.interpolateString(e.field,t);return se(t,n)||null}return e?.value||null},gu=(e,t,n)=>{const s=t;e?.field&&e?.component&&(delete s[e.field],n({target:{name:e.field,value:null,component:e.component}}))},bu=(e,t)=>{if(e?.condition){const n=e,s=S.Utils.interpolateString(n.field,t),r=se(t,s);switch(n.condition){case"changes":{const o=`${s}LastValue`,i=n[o]||null;return i===null?(n[o]=r,!1):r!==i?(n[o]=r,!0):!1}case"isTruthy":return!!r;case"isFalsy":return!r;default:return!1}}return!0},wu=(e,t)=>{if(e?.fields){let n;return e.fields.find(s=>{const r=S.Utils.interpolateString(s,t),o=se(t,r);return o?(n=o,!0):!1}),n||(e.fallback?S.Utils.interpolateString(e.fallback,t):"")}return e?.value||null},_u=(e,t)=>{if(!e||!t)return null;const n=e.target.split(".");let s="";n.forEach(i=>{if(s!==""&&(s+="."),i.slice(-2)==="[]"){const l=i.slice(0,-2),a=br(l,t);s+=`${l}[${a}]`}else s+=i});const r=S.Utils.interpolateString(s,t);return se(t,r)?.length||0},Iu=(e,t)=>{const n=S.Utils.interpolateString(e.target,t),s=se(t,n);return s&&Array.isArray(s)?s.some(r=>e.key?se(r,e.key)===e.value:r===e.value):s&&typeof s=="object"?se(s,e.key)===e.value:!1},Pu={checkValueIsTruthy:yu,getIndexOfMatchingValueIn:Tu,doesContainValue:Iu,persistValueInFormData:Su,setValueInFormData:Cu,deleteValueInFormData:gu,getLength:_u,getFirstOf:wu},xu=(e,t,n)=>{const s=Pu[e.function];if(typeof s=="function")return s(e,t,n)},Ou=(e,t,n)=>(e?.operations&&t&&e.operations.forEach(s=>{if(bu(s.run_when,t)){const r=xu(s,t,n);if(s.output){const o=S.Utils.interpolateString(s.output,t).replace("[",".").replace("]","");Rs(t,o,r)}}}),t),Ru={runPageOperations:Ou},Nu=(e,t,n,s)=>!(e!==t.base&&s[t.check]),Lu=(e,t,n)=>{const s=e[n.id]?.[t.base],r=e[n.id]?.[t.check],o=r&&r?.length>0;return!!(s||o)},Du=e=>/^-?\d+$/.test(e),bt=e=>Du(e)?e.padStart(2,"0"):"",ge=e=>{const[t,n,s]=e.split("-");return`${bt(t)}-${bt(n)}-${s}`},Nr=e=>{const[t,n]=e.split(":");return`${bt(t)}:${bt(n)}`},Se="DD-MM-YYYY";K.extend(Be);const vu=(e,t)=>{const n=t.date?K(ge(t.date),Se):K().add(t.value,t.unit);return K(ge(e),Se).isAfter(n)};K.extend(Be);const Fu=(e,t)=>{const n=t.date?K(ge(t.date),Se):K().add(t.value,t.unit);return K(ge(e),Se).isBefore(n)};K.extend(Be);const ju=(e,t,n)=>{const s=n.components?.find(c=>c.fieldId===t.date),r=n.components?.find(c=>c.fieldId===t.time);if(!s||!r||!e)return!1;const o=e[n.fieldId]?.[t.date],i=e[n.fieldId]?.[t.time];if(!o||!i||Qe(s,e[n.fieldId],e[n.fieldId])||Qe(r,e[n.fieldId],e[n.fieldId]))return!0;const l=ge(e[n.fieldId]?.[t.date]),a=Nr(e[n.fieldId]?.[t.time]);return K(`${l} ${a}`,`${Se} HH:mm`).isBefore(K())};K.extend(Be);K.extend(fn);const Uu=(e,t)=>{const n=K(ge(e),Se).isBefore(K()),s=K(ge(e),Se).isToday();return n&&!s?!0:s&&!!t?.todayAllowed};K.extend(Be);K.extend(fn);const Mu=(e,t)=>K(ge(e),Se).isAfter(K())?!0:!!t?.todayAllowed&&K(ge(e),Se).isToday(),ku=(e,t)=>e?e.length>t.value:!0,Bu=(e,t)=>e?e.length<t.value:!0,$u=(e,t)=>{if(!e)return!0;const n=typeof e=="string"?e.replace(/,/g,""):e;return parseFloat(n)>t.value},Yu=(e,t)=>{if(!e)return!0;const n=typeof e=="string"?e.replace(/,/g,""):e;return parseFloat(n)<t.value},Hu=(e,t)=>e?(t?.allowCommas?/^[0-9,]*\.?[0-9]*$/:/^[0-9]*\.?[0-9]*$/).test(e):!0,Vu=(e,t)=>e?t.array.includes(e):!0,qu=(e,t,n,s)=>{if(!e||!s)return!0;const r=Ut(t.collectionPath,s);return!Ge(t.collectionPath,s)?.some(l=>l.id===r?!1:t.caseInsensitive&&typeof e=="string"&&typeof l[n.id]=="string"?l[n.id].toUpperCase()===e.toUpperCase():l[n.id]===e)},Gu=(e,t,n)=>n.components?.some(s=>!!e[n.id]?.[s.id]),Ku=(e,t)=>!e||!e.includes(".")?!0:e.split(".")[1].length<t.maxDecimals,Wu=/(%27)|(')|(--)|(%23)|(#)|((%3D)|(=))[^\n]*((%27)|(')|(--)|(%3B)|(;))|w*((%27)|('))((%6F)|o|(%4F))((%72)|r|(%52))|((%27)|('))union/i,zu=e=>{if(e){const t=typeof e=="object"?JSON.stringify(e):String(e);return!Wu.test(t)}return!1},Ju=(e,t,n)=>n.components?.reduce((r,o)=>e[n.id]?.[o.id]?Array.isArray(e[n.id][o.id])&&e[n.id][o.id].length===0?r:r+1:r,0)<2,Xu={conditionallyPermittedChange:Nu,conditionallyRequired:Lu,mustBeAfter:vu,mustBeBefore:Fu,mustBeEarlierDateTime:ju,mustBeGreaterThan:$u,mustBeInTheFuture:Mu,mustBeInThePast:Uu,mustBeLessThan:Yu,mustBeLongerThan:ku,mustBeNumbersOnly:Hu,mustBeOneOf:Vu,mustBeShorterThan:Bu,mustBeUniqueInCollection:qu,mustEnterAtLeastOne:Gu,mustHaveLessThanDecimalPlaces:Ku,mustNotContainSql:zu,mustSelectOnlyOne:Ju},Qu=(e,t,n,s)=>{const r=Xu[t.function],o=t.objectValueToUse?e[t.objectValueToUse]:e;if(typeof r=="function")return r(o,t,n,s)?void 0:t.message},Lr=(e,t,n)=>{if(t&&Array.isArray(e.additionalValidation)){let s;return e.additionalValidation.forEach(r=>{s||(s=Qu(t,r,e,n))}),s}},wt=(e,t,n)=>{if(!e)return[];const s=n||t,r=Lr(e,s);if(r)return{id:e.id,error:r};const o=[];if(Array.isArray(e.components)){const i=t&&e.fieldId?t[e.fieldId]:t;et(e.components,i).forEach(a=>{const c=e.full_path||e.fieldId?`${e.full_path||e.fieldId}.${a.fieldId}`:a.fieldId;o.push(Qe({...a,full_path:c},i,s))})}return o.flat(1).filter(i=>!!i)},Zu=(e,t,n)=>{const s=[];return e&&Array.isArray(e.item)&&Array.isArray(t)&&t.forEach((r,o)=>{const i=(e.countOffset||0)+o+1,l=`${e.full_path||e.fieldId}[${o}]`,a={full_path:l,components:e.item.map(c=>{const u={...c,full_path:`${l}.${c.fieldId}`};return c.custom_errors&&Array.isArray(c.custom_errors)&&(u.custom_errors=c.custom_errors.map(h=>({...h,message:S.Utils.interpolateString(o===0&&h.firstOnlyMessage?h.firstOnlyMessage:h.message,{index:i})}))),u})};s.push(wt(a,r,n))}),s.filter(r=>!!r).flat()};K.extend(Be);K.extend(fn);K.extend(Xr);const ed=(e,t)=>e==="02"?K().year(t).isLeapYear()?29:28:["04","06","09","11"].includes(e)?30:31,Dr=e=>{if(!e)return{message:void 0,propsInError:void 0};const t=ge(e),[n,s,r]=t.split("-"),o=parseInt(n,10),i=parseInt(s,10),l=[],a=[];if(r.length===0?(l.push("year"),a.push("Date must include a year")):r.length!==4&&(l.push("year"),a.push("Year must be 4 numbers")),s.length===0?(l.push("month"),a.push("Date must include a month")):(i>12||i<1)&&(l.push("month"),a.push("Month must be between 1 and 12")),n.length===0)l.push("day"),a.push("Date must include a day");else{const c=ed(s,r);(o>c||o<1)&&(l.push("day"),a.push(`Day must be between 1 and ${c}`))}if(l.length>0){const c={};return l.includes("day")&&(c.day=!0),l.includes("month")&&(c.month=!0),l.includes("year")&&(c.year=!0),{message:l.length===1?a[0]:"Enter a valid date",propsInError:c}}return K(t,Se).format(Se)!==t?{message:"Enter a valid date",propsInError:{day:!0,month:!0,year:!0}}:{message:void 0,propsInError:void 0}},td=/^[a-z0-9._\-']+@(digital\.)?homeoffice.gov.uk$/i,nd=/^[a-z0-9._\-']+@jmsc.gov.uk$/i,vr=(e,t="",n=[])=>{if(e){const s=t?t.toLowerCase():"email address";if(typeof e=="string"&&(td.test(e)||nd.test(e)))return;if(Array.isArray(n)){const r=n.filter(o=>o.type==="format");if(r&&r.length>0&&r[0].message)return r[0].message}return`Enter ${s} in the correct format, like jane.doe@homeoffice.gov.uk`}},sd="Invalid files must be deleted",Fr=(e,t)=>{if(!e)return;let n=!1;if(e.every(s=>(n=s.error,!n)),n){if(Array.isArray(t)){const s=t.filter(r=>r.type==="invalidFile");if(s&&s.length>0&&s[0].message)return s[0].message}return sd}},jr=(e,t,n,s)=>{if(e){if(typeof e=="string"){if(new RegExp(n).test(e))return;if(Array.isArray(s)){const o=s.filter(i=>i.type==="pattern");if(o?.[0]?.message)return o[0].message}}return t?`${t} failed regex validation`:"Component failed regex validation"}},Ur=(e,t,n)=>{let s=!1;if((e||e===!1||e===0)&&(s=!0,typeof e=="string"?s=e.trim().length>0:Array.isArray(e)&&(s=e.length>0)),!s){if(Array.isArray(n)){const o=n.filter(i=>i.type==="required");if(o&&o.length>0&&o[0].message)return o[0].message}return`${t||"Field"} is required`}},Mr=(e,t,n,s,r,o=1e3)=>{if(!n||!r&&!t)return;if(r&&!t||t.length>o){if(Array.isArray(s)){const l=s.filter(a=>a.type==="length");if(l&&l.length>0&&l[0].message)return l[0].message}return`${e} must be ${o} characters or less`}},kr=e=>{if(!e)return{message:void 0,propsInError:void 0};const t=Nr(e),[n,s]=t.split(":"),r=parseInt(n,10),o=parseInt(s,10),i=[],l=[];if(/^\d{0,2}:\d{0,2}$/.test(e)||(i.push("invalid"),l.push("Enter a valid time")),n.length===0?(i.push("hour"),l.push("Time must include a hour")):(r>23||r<0)&&(i.push("hour"),l.push("Hour must be between 0 and 23")),s.length===0?(i.push("minute"),l.push("Time must include a minute")):(o>59||o<0)&&(i.push("minute"),l.push("Minute must be between 0 and 59")),i.length>0){const c={};return i.includes("hour")&&(c.hour=!0),i.includes("minute")&&(c.minute=!0),i.includes("invalid")&&(c.invalid=!0),{message:i.length>1?"Enter a valid time":l[0],propsInError:c}}return{message:void 0,propsInError:void 0}},rd=(e,t)=>e?.type==="or"?ae.meetsOne(e.conditions,t):ae.meetsAll(e.conditions,t),Qe=(e,t,n)=>{const s=n||t;if(!Ie(e,{...s,...t}))return;if(e.type===_.CONTAINER)return wt(e,t,s);let r,o,l=(t&&typeof t=="object"?t:{})[e.fieldId];if(e.type===_.COLLECTION_SUMMARY&&(l=Ge(e.collectionName,s)),e.required&&(!e.requiredOverrideConditions||!rd(e.requiredOverrideConditions,s))&&(r=Ur(l,e.label,e.custom_errors)),!r){switch(e.type){case _.COLLECTION:return Zu(e,l,s);case _.EMAIL:r=vr(l,e.label,e.custom_errors);break;case _.DATE:case _.TIME:{const a=e.type===_.DATE?Dr:kr,{message:c,propsInError:u}=a(l);o=u,r=c;break}case _.CHECKBOXES:case _.RADIOS:{let a=[];if(e.data.options?.forEach(c=>{c.nested&&Ze(n[e.id],c)&&(a=a.concat(wt({components:c.nested},n)))}),a.length>0)return a;break}case _.MULTI_FILE:r=Fr(l,e.custom_errors);break;case _.TEXT_AREA:r=Mr(e.label,l,e.showCharacterCount,e.custom_errors,e.required,e.maxLength);break}!r&&e.pattern&&(r=jr(l,e.label,e.pattern,e.custom_errors)),!r&&e.additionalValidation&&(r=Lr(e,l,n),e.type===_.DATE&&r&&(o={day:!0,month:!0,year:!0}))}if(r)return{id:e.full_path||e.id,error:r,properties:o}},od=(e,t=[])=>{let n=e.formData;if(e.collection){const s=gt.getActiveIndex(e.collection.name,e.formData);s!==null&&(n={...e.formData,...gt.getData(e.collection.name,e.formData)?.[s]})}return Dt(e,n)&&Array.isArray(e.components)?e.components.reduce((r,o)=>{if(!Ie(o,n))return r;const l=(t.length>0?t.filter(a=>a.showFor?a.showFor===o.id:a.id===o.id):[]).concat(Qe(o,n,n));return r.concat(l).flat().map(a=>a&&{...a,error:S.Utils.interpolateString(a.error,n)})},[]).filter(r=>!!r).flat():[]},id={component:Qe,container:wt,email:vr,date:Dr,multifile:Fr,page:od,regex:jr,required:Ur,textarea:Mr,time:kr},w={CheckYourAnswers:cu,CollectionPage:gt,Component:ot,Condition:ae,Container:Lt,Data:de,Format:fu,FormPage:it,Hub:mu,Meta:Au,Operate:Ru,Validate:id,...S.Utils},ld="hods-form-container",Ln=({container:e,value:t=void 0,formData:n,onChange:s=void 0,wrap:r=!0,onTopLevelChange:o=void 0,...i})=>{const l=({target:h})=>{if(typeof s=="function")if(h.name===w.Meta.name)s({target:h});else{const f={...t,[h.name]:h.value};s({target:{name:e.fieldId,value:f}})}},a=h=>{const f=`${e.full_path||e.fieldId}.${h.fieldId}`;return h.type===_.CONTAINER?w.Container.show({...h,full_path:f},n):w.Component.show({...h,full_path:f},{...n,...se(n,e.full_path)})},c=w.classBuilder(ld,[],e.className),u=S.Utils.cleanHtmlAttributes(i);return d.jsxs("div",{...u,className:c(),id:e.id,children:[e.title&&d.jsx(S.MediumHeading,{children:e.title}),e.components&&e.components.filter(a).map((h,f)=>{const E=h.type===_.FILE?{}:"",y=t?t[h.fieldId]:E,p=`${e.full_path||e.fieldId}.${h.fieldId}`;return d.jsx(Ve,{...i,component:{...h,full_path:p,readonly:!!(e.readonly||h.readonly)},formData:n,value:y||E,wrap:r,onChange:l,onTopLevelChange:o},f)})]})},ad=e=>{if(e&&Object.prototype.hasOwnProperty.call(e,"action")){if(typeof e.action.onAction=="function")return{onClick:()=>e.action.onAction(e),onKeyPress:t=>{t.key==="Enter"&&e.action.onAction(e)},tabIndex:"0"};if(e.action.page)return{href:`/${e.action.page}`}}return{}},as=({group:e})=>{const[t,n]=R.useState({});return R.useEffect(()=>{n(ad(e))},[e,n]),e?.action?d.jsxs(S.Link,{...t,"aria-label":`${e.action.label} ${e.action.aria_suffix}`,children:[e.action.label,e.action.aria_suffix&&d.jsxs("span",{className:"mobile-text govuk-link",children:[" ",`${e.action.aria_suffix}`]})]}):null},cd=({title:e,size:t="m",classes:n})=>d.jsxs("div",{className:`${n("heading")}`,role:"listitem",children:[t==="s"&&d.jsx(S.SmallHeading,{children:e}),t==="m"&&d.jsx(S.MediumHeading,{children:e})]}),ud=({row:e,classes:t,noChangeAction:n=!1})=>d.jsxs("div",{className:t("headingWithAction"),role:"listitem",children:[d.jsxs("td",{className:"heading-text",colSpan:"2",children:[e.size==="s"&&d.jsx(S.SmallHeading,{children:e.key}),e.size==="m"&&d.jsx(S.MediumHeading,{children:e.key})]}),d.jsx("td",{className:"heading-action",children:!n&&d.jsx(Pn,{row:{action:e.action}})})]}),dd="govuk-summary-list",cn=({rows:e,noChangeAction:t=!1,noGroupAction:n=!1,isGroup:s=!1,classBlock:r=dd,classModifiers:o=[],className:i="",showGroupAction:l=!0,...a})=>{const c=S.Utils.classBuilder(r,o,i),u=S.Utils.cleanHtmlAttributes(a);let h=null;if(s){const f=e.filter(E=>!!E.action);h=f?.length?f[0]:null}return d.jsx("div",{className:"group-of-rows",children:d.jsxs("div",{...u,className:c(),role:"list",children:[e.map(f=>{const E=`${f.pageId}_${f.full_path||f.fieldId}`;return f.type==="title"?d.jsx(ur,{title:f.key,classes:c},E):f.type==="heading"?d.jsx(cd,{title:f.key,size:f.size||"s",classes:c},E):f.type==="headingWithAction"?d.jsx(ud,{row:f,classes:c,noChangeAction:t},E):f.type==="action"?t?null:d.jsx("div",{children:d.jsx(as,{group:f})},`${E}-actions`):d.jsx(cr,{row:f,classes:c,showAction:!t},E)}).filter(f=>!!f),l&&s&&!n&&d.jsx("div",{className:"change-group-button",children:d.jsx(as,{group:h})})]})})},fd="hods-check-your-answers",hd="Check your answers",cs=9,md=({title:e=hd,titleSize:t="l",pages:n,actions:s=[],onAction:r,onRowAction:o,hide_page_titles:i=!1,hide_actions:l=!1,hide_title:a=!1,summaryListClassModifiers:c,noChangeAction:u,noGroupAction:h,groups:f,sections:E=[],type:y,hideBlankRows:p=!1,optionalFieldPlaceholder:A})=>{const[T,N]=R.useState([]),[C,b]=R.useState([]),{errors:P}=He(),{hooks:U}=Pe();R.useEffect(()=>{const x=(q,X)=>w.CheckYourAnswers.getRows(q,o,U.onGetCYARows).map((V,z)=>({...V,value:d.jsx(bn,{value:V.value,component:V.component,formData:q.formData,placeholder:A},`${X}_${z}`)})),$=w.CollectionPage.mergePages(n).map((q,X)=>{const G=x(q,X);return G?.length?{...q,rows:G}:null}).filter(q=>!!q);N($)},[n,o,N]);const g=i?0:cs,L=x=>x===T.length-1;R.useEffect(()=>{(()=>{const j=Array.isArray(f)?f.map($=>$.pageId):[];b(j)})()},[b,f]);const v=U.onGetCYA({title:e,pages:n,actions:s,onAction:r,onRowAction:o,hidePageTitles:i,hideActions:l,hideTitle:a,summaryListClassModifiers:c,noChangeAction:u,noGroupAction:h,groups:f,errors:P,sections:E,type:y});if(v)return v;const F=x=>C.includes(x),I=x=>f?.find(j=>j.pageId===x),k=(x,j)=>{if(!x.cya_link?.singleChangeLink||u)return d.jsxs(d.Fragment,{children:[j==="s"&&d.jsx(S.SmallHeading,{children:w.FormPage.getTitle(x.title,x.formData)}),j==="m"&&d.jsx(S.MediumHeading,{children:w.FormPage.getTitle(x.title,x.formData)})]});const $=vt(!1,x,o);return d.jsxs("div",{className:"heading-with-action",children:[d.jsxs("div",{className:"heading-text",children:[j==="s"&&d.jsx(S.SmallHeading,{children:w.FormPage.getTitle(x.title,x.formData)}),j==="m"&&d.jsx(S.MediumHeading,{children:w.FormPage.getTitle(x.title,x.formData)})]}),d.jsx("div",{className:"heading-action",children:d.jsx(Pn,{row:{action:$}})})]})},O=()=>Array.from(new Set(P.map(j=>j.id))).map(j=>P.find($=>$.id===j));return d.jsxs("div",{className:fd,children:[e&&!a&&d.jsx(S.Heading,{size:t,children:e},"heading"),P&&P.length>0&&d.jsx(S.ErrorSummary,{errors:O()}),y===ne.TASK_CYA&&T.length>0&&E&&E.map(x=>x.tasks.filter(j=>j.state!==H.TYPES.SKIPPED).map((j,$)=>{const q=T.filter(X=>j.pages.some(G=>G===X.name));return d.jsxs(R.Fragment,{children:[d.jsx(S.MediumHeading,{children:q.length>0&&(j.displayName||j.name)}),q.map((X,G)=>{const V=F(X.id)||u,z=!i&&X.title&&!F(X.id);return d.jsxs(R.Fragment,{children:[z&&k(X,"s"),d.jsx(cn,{rows:X.rows,classModifiers:c,noChangeAction:V,noGroupAction:h,isGroup:F(X.id)})]},G)})]},$)})),y!==ne.TASK_CYA&&T&&T.map((x,j,$)=>{const q=!p||x.collection?x.rows:x.rows.filter(pe=>pe?.value?.props?.value);if(q.length===0)return null;const X=!i&&x.title&&!F(x.id),G=L(j)||F($[j].id)||$.length>j+1&&F($[j+1].id)?cs:g,V=F(x.id)?I(x.id):void 0,z=`govuk-!-margin-bottom-${G}`,fe=F(x.id)||u;return d.jsxs(R.Fragment,{children:[X&&k(x,"m"),V&&d.jsx("div",{className:"group-title",children:d.jsx(S.MediumHeading,{children:V.title||w.FormPage.getTitle(x.title,x.formData)})}),d.jsx(cn,{className:z,rows:q,classModifiers:c,noChangeAction:fe,noGroupAction:h,isGroup:F(x.id)})]},j)}),!l&&d.jsx(_n,{actions:s?.filter(x=>w.Component.show(x,n[n.length-1].formData)),onAction:x=>r(x)})]})},pd=lr,Ed=({page:e,pages:t,onCollectionChange:n=void 0,onAction:s,hashLink:r=!1,classBlock:o=pd,classModifiers:i=[],className:l="",submitting:a=!1})=>{const[c,u]=R.useState({});let h=w.CollectionPage.getData(e.collection.name,e.formData)||[];const f=e.collection.name.split(".").pop();let E=w.CollectionPage.getActiveIndex(e.collection.name,e.formData);const y=e,p=({target:P})=>{w.CollectionPage.setData(y.collection.name,P.value,e.formData),h=P.value;const U=e.collection.name.split(".").shift();u(g=>({...g,[U]:w.CollectionPage.getData(U,e.formData)}))},A=({target:P})=>{y.formData[P.name]=P.value,u(U=>({...U,[P.name]:P.value}))},T=P=>{p({target:{value:P}}),typeof n=="function"&&n(e.formData)},N=P=>{E=h.length,A({target:{name:`${f}ActiveId`,value:P}})},C=P=>{s(P,c,{})},b=({target:P})=>{if(E===null){const U=_t.v4();N(U),T([...h,{id:U,[P.name]:P.value}])}else T([...h.slice(0,E),{...h[E],[P.name]:P.value},...h.slice(E+1)])};return e.collection?.waitForFormData&&e.formData&&Object.keys(e.formData).length===0?null:d.jsx(In,{page:{...e,formData:{...e.formData,...h[E],[`${f}ActiveIndex`]:E,[`${f}NumberedIndex`]:typeof E=="number"?E+1:null},components:e.components.map(P=>({...P,pageCollection:{...e.collection}}))},pages:t,onAction:C,onWrapperChange:b,onTopLevelChange:A,hashLink:r,classBlock:o,classModifiers:i,className:l,submitting:a})},Ad="hods-task-list",yd=({state:e=H.TYPES.CANNOT_START_YET})=>{const t=S.Utils.classBuilder(Ad,void 0,void 0),n=H.DETAILS[e]||H.DETAILS.cannotStartYet;return d.jsx(S.Tag,{classModifiers:n.colour,className:t("tag"),children:n.label})},Td="hods-task-list",Sd=({task:e,onClick:t})=>{const n=S.Utils.classBuilder(Td,void 0,void 0),[s,r]=R.useState(e.state!==H.TYPES.CANNOT_START_YET),[o,i]=R.useState(e.state);R.useEffect(()=>{r(e.state!==H.TYPES.CANNOT_START_YET),i(e.state)},[e.state,r,i]);const l=e.displayName||e.name;return d.jsxs("li",{className:n("item"),children:[d.jsx("span",{className:n("task-name"),children:s?d.jsx(S.Link,{onClick:()=>t(e),onKeyPress:a=>{a.key==="Enter"&&t(e)},tabIndex:0,children:l}):l}),d.jsx(yd,{state:o})]})},Cd="hods-task-list",gd="Incomplete form",bd=({id:e="",refTitle:t,refNumber:n,notes:s={},incompleteTitle:r=gd,showCompletionOverview:o=!0,sections:i,fieldId:l="",onTaskAction:a,classBlock:c=Cd,classModifiers:u=[],className:h="",formData:f={},annotations:E=[],...y})=>{const p=S.Utils.classBuilder(c,u,h),A=S.Utils.cleanHtmlAttributes(y),[T,N]=i.filter(g=>!g.skipped).reduce((g,L)=>[g[0]+(L.tasks?.filter(v=>v.state===H.TYPES.COMPLETE).length??0),g[1]+(L.tasks?.filter(v=>v.state!==H.TYPES.SKIPPED).length??0)],[0,0]),C=`${e}Notes`,{title:b,text:P}=s&&s||{},U=g=>{typeof a=="function"&&a(g)};return d.jsxs("div",{...A,id:e,className:p(),children:[n&&t&&d.jsxs(d.Fragment,{children:[d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:`${t}`})}),d.jsx("p",{className:"govuk-body govuk-!-font-weight-regular",children:`${n}`})]}),E.length>0&&E.map(g=>d.jsxs("div",{className:p("annotation"),children:[d.jsx("p",{className:`${p("annotation-key")} govuk-body`,children:S.Utils.interpolateString(g.key,f)}),d.jsx("p",{className:`${p("annotation-value")} govuk-body`,children:S.Utils.interpolateString(g.value,f)})]},g.key)),o&&N!==T&&d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:r})}),o&&d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-7",children:`You have completed ${T} of ${N} sections`}),b&&P&&Ie(s,f)&&d.jsxs(d.Fragment,{children:[d.jsx("p",{className:"govuk-body govuk-!-margin-bottom-0",children:d.jsx("strong",{className:"tasklist-summary",children:S.Utils.interpolateString(b,f)})}),d.jsx(S.TextArea,{id:C,fieldId:C,readOnly:!0,value:S.Utils.interpolateString(P,f)})]}),i.filter(g=>!g.skipped).map((g,L)=>d.jsxs(R.Fragment,{children:[d.jsxs("h2",{className:p("section"),children:[i.length>1?`${L+1}. `:" ",g.name]}),g.label&&d.jsx(S.Hint,{children:g.label}),d.jsx("ol",{className:p("items"),children:g.tasks.filter(v=>v.state!==H.TYPES.SKIPPED).map(v=>d.jsx(Sd,{task:v,onClick:U},`${g.name}-${v.name}`))})]},`${g.name}`))]})},Br=(e,t)=>e?.page||t,wd=(e,t,n)=>{const s=Br(e.action,e.pageId);s!==t&&n(s)},_d=(e,t,n,s=void 0)=>{const r=Br(e,t);r!==t&&n(r,s)},Id=(e,t)=>{t(e)},Te={cyaAction:wd,navigate:_d,submissionError:Id},Pd=(e,t,n,s)=>e.validate?e.checkPreexistingErrors&&s.length!==0?!1:n(t).length===0:!0,xd=(e,t)=>t(e).length===0,Od=["radios","checkboxes"],Rd=(e,t)=>{const n=e.split("."),s={};return n.forEach(r=>{s[`${r}ActiveId`]=t[`${r}ActiveId`]}),s};function Nd(e,t){const n=[];return e?.data?.options?.forEach(s=>{!Ze(t,s)&&s.nested&&s.nested.forEach(r=>{n.push(r.id)})}),n}const $r=(e,t)=>{let n=e;if(t.components.forEach(s=>{if(!Od.includes(s.type))return;Nd(s,n[s.id]).forEach(o=>{delete n[o]})}),t.collection){n={...Rd(t.collection.name,t.formData),...n};const s=Ge(t.collection.name,n);if(s){const r=Ut(t.collection.name,n),o=s.map(i=>i.id===r?$r(i,{...t,collection:void 0}):i);On(t.collection.name,o,n)}}return n},Ld=(e,t,n)=>{if(e===re.HUB&&n===ye.CYA)return{title:""};if(e===re.CYA)return{};const s=t?.find(r=>r.id===e);if(s?.type===re.PARTIAL_CYA){const r=w.FormPage.applyConditionalProperties(s);return{title:r.title,hideChangeActions:r.hideChangeActions,hideGroupActions:r.hideGroupActions}}},Yr=(e,t,n)=>{if(e)return e===re.HUB?n===ye.CYA||n===ye.TASK?void 0:n:t.find(s=>s.id===e)},Dd=(e,t,n)=>({pageId:e,cya:Ld(e,t,n),page:Yr(e,t,n)}),us=(e,t)=>e.slice(0,e.findIndex(n=>n?.id===t)),vd=(e,t,n)=>e.page?.type===re.PARTIAL_CYA?us(n||t,e.pageId):n||t,ds=(e,t,n,s,r)=>{if(!t&&r===ne.FORM_WITH_TASK){if(s?.formStatus?.taskPage){const i=n.find(l=>l.id===s.formStatus.taskPage);return i?.type==="pre-task-list"?i.id:re.HUB}return n.length>0?n[0].id:void 0}let o;return e?.pages?.forEach(i=>{it.show({show_when:i.show_when},s)&&(o=i.pageId)}),o||e?.page||re.HUB},Hr=(e,t,n)=>{let s=e.findIndex(o=>o.id===t)+1,r=e[s];for(;r&&!it.show(r,n);)s+=1,r=e[s];return r?.id||void 0},Fd=(e,t,n)=>Hr(e,t,n)||re.CYA,jd=e=>e.length>0?e[0].id:void 0,un=(e,t,n,s,r)=>{if(s){if(s.type===W.TYPES.NAVIGATE)return t.find(o=>o.id===s.page)?s.page:void 0;if(s.type===W.TYPES.SAVE_AND_RETURN)return e===ne.HUB?re.HUB:void 0}switch(e){case ne.HUB:return ds(s);case ne.CYA:return Fd(t,n,r);case ne.FORM_WITH_TASK:case ne.TASK:return ds(s,n,t,r,e);case ne.WIZARD:return Hr(t,n,r);default:return jd(t)}},Ud=(e,t,n,s,r,o,i,l)=>{if(e===ne.TASK||e===ne.FORM_WITH_TASK){const a=r.formStatus||{};return a.tasks=a.tasks||{},a.tasks[o.name]=a.tasks[o.name]||{},n===(re.CYA||"submitForm")&&i?a.tasks[o.name].complete=!0:o.name?s?.type===W.TYPES.SAVE_AND_NAVIGATE?a.tasks[o.name]={complete:!1,currentPage:un(e,t,n,s,r)}:o.pages?.includes(n)&&(a.tasks[o.name]={complete:!!s?.complete,currentPage:n}):l&&l.forEach(c=>{c.tasks.forEach(u=>{const h=u.pages[u.pages.length-1];(h===n||h.id===n)&&i&&u?.type==="pre-task-list"?a.tasks[u.name]={complete:i,currentPage:n}:u.pages.includes(n)&&u?.type==="pre-task-list"&&(a.tasks[u.name]={complete:!1,currentPage:n})})}),a.taskPage=a.tasks[o.name].currentPage,a}return s?.type===W.TYPES.SAVE_AND_RETURN?{page:n}:{page:un(e,t,n,s,r)}},Md=({complete:e,currentPage:t},n=H.TYPES.NOT_STARTED)=>e?H.TYPES.COMPLETE:t||e!==void 0&&!e&&t===void 0?H.TYPES.IN_PROGRESS:n,kd=(e,t,n=!1)=>t.reduce((s,r)=>{const o=e[r];return n&&o?.state===H.TYPES.SKIPPED?s:s&&o?.complete},!0),Vr=(e,t)=>{const n=e[t-1].state;return n===H.TYPES.COMPLETE?!0:n===H.TYPES.SKIPPED?t-1===0?!0:Vr(e,t-1):!1},Bd=(e,t,n,s,r=!1,o=!0)=>{if(s[e.name])return Md(s[e.name],e.state);if(r)return e.depends_on&&!kd(s,e.depends_on,e.ignoreSkipped)?H.TYPES.CANNOT_START_YET:H.TYPES.NOT_STARTED;let i=o;return t&&(i=Vr(n,t)),i?H.TYPES.NOT_STARTED:H.TYPES.CANNOT_START_YET},$d=(e,t,n,s)=>{const r=e.tasks.map(o=>({...o}));return r.filter(o=>o.state!==H.TYPES.SKIPPED).forEach((o,i)=>{const l=o;l.state=Bd(l,i,r,t,n,s)}),r},qr=(e,t)=>{const n=e[t-1]?.tasks.slice(-1)[0]?.state;return n===H.TYPES.COMPLETE?!0:n===H.TYPES.SKIPPED?t-1===0?!0:qr(e,t-1):!1},Yd=(e,t,n=!1,s=null)=>{const r=e.map(i=>{const l=i.show_when?[i.show_when].flat():[];return s&&!w.Condition.meetsAll(l,s)?{...i,skipped:!0,tasks:i.tasks.map(a=>({...a,state:H.TYPES.SKIPPED}))}:{...i}});r.forEach(i=>{const l=i;l.tasks=l.tasks.map(a=>{const c=a.show_when?[a.show_when].flat():[];return s&&!w.Condition.meetsAll(c,s)?{...a,state:H.TYPES.SKIPPED}:{...a}})});const o={...t};return r.forEach(i=>{i.tasks.filter(l=>l.state===H.TYPES.SKIPPED).forEach(l=>{o[l.name]={...o[l.name],state:H.TYPES.SKIPPED}})}),r.forEach((i,l)=>{const a=i,c=l===0||qr(r,l);a.tasks=$d(a,o,n,c)}),r},Hd=(e,t,n)=>{n.has(e)||n.set(e,[]),n.get(e).push(t)},ke=(e,t)=>{if(Array.isArray(e))for(let r=0;r<e.length;r+=1)ke(e[r],t);const n=t.split(".");let s=e;for(let r=0;r<n.length-1;r+=1)if(s=s[n[r]],s===void 0)return;s[n[n.length-1]]&&delete s[n[n.length-1]]},Gr=e=>{if(typeof e!="string"||!e.includes("."))return null;const t=e.split(".");return t.pop(),t.join(".")},Dn=(e,t)=>{const n=Gr(e);return n?`${n}.${t}`:t},Vd=e=>{for(let t=e.length-1;t>=0;t-=1){const n=e[t];Object.keys(n).length===1&&Object.keys(n)[0]==="id"&&e.splice(t,1)}},qd=e=>{const t=(n,s)=>(typeof n=="object"&&n!==null&&(Array.isArray(n)?n.forEach(r=>{t(r,s)}):Object.keys(n).forEach(r=>{r==="field"&&s.push(n[r]),t(n[r],s)})),s);return e.show_when?new Set(t(e.show_when,[])||[]):null},Gd=(e,t)=>{const n=e.split(".");for(let s=n.length;s>0;s-=1){const r=n.slice(0,s).join("."),o=t.get(r);if(o)return o}return null},Je=(e,t)=>e.show_when?e.show_when?.type==="or"?ae.meetsOne(e,t):ae.meetsAll(e,t):!0,Kr=(e,t,n)=>{const s=t.get(e.use)??n.get(e.use)??e,r=JSON.parse(JSON.stringify(s));return e.use&&e.show_when&&(r.show_when=e.show_when),r},Kd=(e,t,n)=>{const{meta:{documents:s}}=n,r=t[e.fieldId];if(!s||!r)return;const o=Array.isArray(r)?r:[r];for(let i=o.length-1;i>=0;i-=1){const l=s.findIndex(a=>a.url===o[i].url);l!==-1&&s.splice(l,1)}},dn=e=>{if(Array.isArray(e))for(let t=e.length-1;t>=0;t-=1)Array.isArray(e[t])&&e[t].length===0?e.splice(t,1):dn(e[t]),typeof e[t]=="object"&&Object.keys(e[t]).length===0&&e.splice(t,1);else e!==null&&typeof e=="object"&&Object.keys(e).forEach(t=>{Array.isArray(e[t])&&e[t].length===0?(e[`${t}ActiveId`]&&delete e[`${t}ActiveId`],delete e[`${t}ActiveId`],e[t]&&delete e[t]):dn(e[t])})},Wr=(e,t)=>{e?.data?.options&&e?.data?.options?.forEach(n=>{n.nested?.forEach(t)})},Wd=(e,t,n,s)=>{if(s[t]>1)s[t]-=1;else{if(n.preserveInPayload)return;ke(e,t),Wr(n,r=>{const o=Dn(t,r.fieldId);s[o]>1?s[o]-=1:ke(e,o)})}},zd=(e,t,n,s)=>{t.forEach(r=>{if(!e.has(r.fieldId)){if(r.type==="multifile"&&Kd(r,n,s),r.preserveInPayload)return;ke(n,r.fieldId),Wr(r,o=>{const i=Dn(r.fieldId,o.fieldId);e.has(i)||ke(n,i)})}})},fs=e=>Array.isArray(e)?e:[e],Jd=(e,t,n,s)=>{const r=new Map,o={},i=[],l=new Map,a=(c,u,h)=>{u.fieldId&&(h=h?`${h}.${u.fieldId}`:u.fieldId,o[h]=(o[h]||0)+1,u.path=h,c.show_when&&(u.show_when=u.show_when?[...fs(c.show_when),...fs(u.show_when)]:c.show_when),Hd(h,u,r),u.components?u.components.forEach(f=>{a(c,f,h)}):u?.data?.options&&u?.data?.options?.forEach(f=>{if(f.nested){const E=!Ze(se(s,h),f),y=f.show_when;f.nested.forEach(p=>{E&&i.push(Dn(h,p.fieldId)),y&&(p.show_when=y),a(c,p,Gr(h))})}}))};return e?.forEach(c=>{c.childPages?l.set(c.collection.name,c):c.components?.forEach(u=>{const h=Kr(u,t,n);a(c,h,null)})}),i.forEach(c=>{o[c]>1?o[c]-=1:ke(s,c)}),{allComponents:r,componentsToKeep:o,allCollections:l}},Xd=e=>{const t=new Map;return e?.forEach(n=>{n?.forEach(s=>{if(!s.fieldId)return;const r=qd(s);if(r)if(t.has(s.path)){const o=t.get(s.path);r.forEach(i=>o.add(i))}else t.set(s.path,new Set(r))})}),t},Qd=(e,t,n,s,r,o)=>{const i=(a,c,u)=>{if(a.has(c))return;a.add(c),u.get(c.path)?.forEach(f=>{const E=Gd(f,t);if(E)E.forEach(y=>{a.has(y)||i(a,y,u)});else{const y=/([a-zA-Z_$][\w$]*)\[\d+\]/,p=f.match(y);if(p){const A=p[1],T=s.get(A);T&&T.childPages?.forEach(N=>{if(N.show_when){const C=JSON.stringify(N.show_when),b=`It is not possible to reliably clean hidden data when a component is dependent on a
|
|
10
10
|
collection's data, and that collection is itself dependent on data elsewhere in the form.
|
|
11
11
|
The dependency path is ${f}, and the chained show_when is ${C}.
|
|
12
12
|
The form will need to be changed to break this chained dependency`;throw new Error(b)}})}}}),Je(c,o)||Wd(o,c.path,c,n)},l=new Set;e?.forEach((a,c)=>{t.get(c)?.forEach(h=>{l.has(h)||i(l,h,e)})})},Zd=(e,t,n,s)=>{e?.forEach((r,o)=>{Je(r,t)||(delete t[o],delete t[`${o}ActiveId`]);const i=t[o];i?.forEach(l=>{const a={...t,...l},c=new Set,u=new Map;r.childPages?.forEach(h=>{const f=Je(h,a);h.components?.forEach(E=>{const y=Kr(E,n,s);if(!y.fieldId)return;const p=Je(E,a);f&&p&&Je(y,a)?c.add(y.fieldId):u.set(y.id,y)})}),zd(c,u,l,t)}),i&&Vd(i)})},ef=(e,t,n)=>{if(!e)return n;const s=new Map(t.components.map(u=>[u.id,u])),r=new Map(t.components.map(u=>[u.fieldId,u])),o=wr(t.pages),{allComponents:i,componentsToKeep:l,allCollections:a}=Jd(o,s,r,n),c=Xd(i);return Qd(c,i,l,a,t,n),Zd(a,n,s,r),dn(n),n},Q={canActionProceed:Pd,canCYASubmit:xd,cleanHiddenNestedData:$r,getFormState:Dd,getRelevantPages:vd,getNextPageId:un,getPage:Yr,getSubmissionStatus:Ud,getUpdatedSectionStates:Yd,clearOutUncompletedRoutes:ef},tf=(e,t,n,s,r,o,i,l,a,c,u,h,f,E,y,p,A,T)=>{if(t.type===W.TYPES.SUBMIT&&E!==ye.TASK){if(e("submit"),Q.canCYASubmit(n,s.pages)&&!A){T(!0);const N=w.Format.form({pages:n,components:o},{...i},we.SUBMIT),C={pages:n,components:o};Q.clearOutUncompletedRoutes(r,C,N),N.formStatus=Q.getSubmissionStatus(a,n,c,t,N,u,!0),l(N),h.onSubmit(t.type,N,()=>{h.onFormComplete(),T(!1)},b=>{T(!1),Te.submissionError(b,f)})}}else{const C=!(Object.prototype.hasOwnProperty.call(t,"validate")&&!t.validate)?Q.canCYASubmit(u.fullPages,s.pages):!0;if(t.type===W.TYPES.SAVE_AND_CONTINUE&&E===ye.TASK&&C){const b=w.Format.form({pages:n,components:o},{...i},we.SUBMIT);b.formStatus=Q.getSubmissionStatus(a,n,c,t,b,u,!0),l(b),h.onSubmit(t.type,b,()=>{T(!1),y(re.HUB)},P=>{T(!1),Te.submissionError(P,f)})}if(t.type===W.TYPES.SUBMIT&&E===ye.TASK&&(e("submit"),C)){const b=w.Format.form({pages:n,components:o},{...i},we.SUBMIT),P={pages:n,components:o};Q.clearOutUncompletedRoutes(r,P,b),b.formStatus=Q.getSubmissionStatus(a,n,c,t,b,u,!0),l(b),h.onSubmit(t.type,b,()=>{h.onFormComplete(),T(!1)},U=>{T(!1),Te.submissionError(U,f)})}if(t.type===W.TYPES.SAVE_AND_NAVIGATE&&C){const b=w.Format.form({pages:n,components:o},{...i},we.SUBMIT);b.formStatus=Q.getSubmissionStatus(a,n,c,t,b,u,!0),l(b),h.onSubmit(t.type,b,()=>{T(!1),y(t.page)},P=>{T(!1),Te.submissionError(P,f)})}if(t.type===W.TYPES.SAVE_AND_RETURN&&C){const b=w.Format.form({pages:n,components:o},{...i},we.SUBMIT);b.formStatus=Q.getSubmissionStatus(a,n,c,t,b,u,!1),l(b),h.onSubmit(t.type,b,()=>{a===ne.TASK?y(void 0):y(re.HUB),T(!1)},P=>{T(!1),Te.submissionError(P,f)})}if(t.type===W.TYPES.NAVIGATE&&(y(Q.getNextPageId(a,n,c,t,p.page?.formData)),T(!1)),t.type===W.TYPES.CANCEL){const b=w.Format.form({pages:n,components:o},{...i},we.CANCEL);h.onCancel(b),T(!1)}}},hs=(e,t,n,s,r,o,i,l,a,c,u,h,f,E,y,p,A,T,N,C,b,P)=>{const U={...r},g=o,L=s.onAction(g.page.formData,t,r,e.customAction);g.page.formData=L.formData;let v=L.patch;if(g.page.formData={...g.page.formData,...v},e.type===W.TYPES.CANCEL){s.onCancel(g.page.formData),b(!1);return}if(Q.canActionProceed(e,g.page,i.page,P)&&(!C||e.ignoreSubmittingFlag))if(v=Q.cleanHiddenNestedData(v,g.page),b(!0),e.addToFormData&&((Array.isArray(e.addToFormData)?e.addToFormData:[e.addToFormData]).forEach(I=>{I.isCollection?On(I.field,I.value,o.page.formData):w.Data.setDataItem(o.page.formData,I.field,I.value)}),g.page.formData[e.addToFormData.field]=e.addToFormData.value),e.type===W.TYPES.NAVIGATE)Te.navigate(e,f,l),b(!1);else{let F=G=>l(Q.getNextPageId(a,u,f,e,G)),I,k;e.collection&&(I=e.collection,k=`addAnother${I.charAt(0).toUpperCase()+I.slice(1)}`.slice(0,-1));let O,x;switch(I&&(O=g.page.formData[I],O&&O.length>0&&g.page.formData[`${I}ActiveId`]&&(x=O.findIndex(G=>G.id===g.page.formData[`${I}ActiveId`]))),e.type){case W.TYPES.SUBMIT:E("submit");break;case W.TYPES.SAVE_AND_NAVIGATE:const G={...y};O&&O.length>0&&e.resetActiveId&&(g.page.formData[`${I}ActiveId`]=O[0].id),O&&O.length>0&&!e.resetActiveId&&(x!==void 0&&x+1<g.page.formData[I].length&&(g.page.formData[k]="Yes"),x!==void 0&&x+1===g.page.formData[I].length&&g.page.formData[k]&&(g.page.formData[k]="No")),F=()=>Te.navigate(e,f,l,G);break;case W.TYPES.COLLECTION_ADD:if(x===void 0||O.length===0||x+1===g.page.formData[I].length?w.CollectionPage.addEntry(e.collection,g.page.formData):g.page.formData[`${e.collection}ActiveId`]=O[x+1].id,g.page.formData[`${e.collection}`]&&g.page.formData[`${e.collection}`].length>0){const pe=g.page.formData[`${e.collection}`].length-1;Object.keys(g.page.formData[`${e.collection}`][pe]).filter(J=>J in g.page.formData&&J!=="id").forEach(J=>delete g.page.formData[J])}F=()=>Te.navigate(e,f,l);break;case W.TYPES.COLLECTION_DUPLICATE:w.CollectionPage.duplicateActiveEntry(e.collection,o.page.formData)&&(F=()=>Te.navigate(e,f,l));break;case W.TYPES.COLLECTION_REMOVE:const V=e.targetId||g.page.formData[`${e.collection.split(".").pop()}ActiveId`],z=w.CollectionPage.removeEntry(e.collection,o.page.formData,V);e.recordRemoval&&(g.page.formData[`${e.collection.split(".").pop()}LastRemoved`]={...z});const fe=g.page.formData.id;z!==null&&Object.keys(z).filter(Y=>Y in g.page.formData).forEach(Y=>delete g.page.formData[Y]),Object.assign(g.page.formData,O[O.length-1]),g.page.formData.id=fe,O.length>0?g.page.formData[`${e.collection}ActiveId`]=O[O.length-1].id:(delete g.page.formData[`${e.collection}ActiveId`],delete g.page.formData[e.collection]),F=()=>Te.navigate(e,f,l);break}w.Data.deleteValues(r,o.page.formData);const j=w.Format.form({pages:u,components:h},{...r,...t,...o.page.formData},we.SUBMIT);j.formStatus=Q.getSubmissionStatus(a,u,f,e,j,y,!0,A?.sections),v&&p(j);const $={pages:u,components:h};e.type===W.TYPES.SUBMIT&&Q.clearOutUncompletedRoutes(c,$,j);let q,X;a===ne.HUB&&Object.keys(n).length>0&&(q=Object.keys(n)[0],X=Object.values(n)[0]),s.onSubmit(e.type,j,G=>{const V={...j,...G};T({data:V}),F(V),b(!1)},(G,V=!0)=>{Te.submissionError(G,N),V&&p({...U}),b(!1)},q,X,f)}},ms=(e,t,n,s,r,o)=>{if(e){const i=e;i.fullPages=[],i.pages.forEach(a=>{i.fullPages.push(Q.getPage(a,t))}),n(e);const l={...i};if(i.state===H.TYPES.COMPLETE&&!i.alwaysShowFirstPage)if(s?.noTaskCYAs){const a=r.formStatus.tasks[e.name].currentPage;o(i.pages[0]||a)}else i.customCYA?o(i.customCYA):o(re.CYA,l);else if(i.state===H.TYPES.IN_PROGRESS&&!i.alwaysShowFirstPage){const a=r.formStatus.tasks[e.name].currentPage;o(a||e.pages[0],l)}else i.firstPage?o(i.firstPage,l):o(i.pages[0],l)}},zr=({title:e,titleSize:t,type:n,cleanseHiddenData:s=!1,components:r,pages:o,hub:i={nonSequential:!1,sections:[]},cya:l={actions:[],disableTaskSwitch:!1},data:a,hashLink:c=!1,hooks:u,classBlock:h=nf,classModifiers:f=[],className:E="",hide_title:y,summaryListClassModifiers:p=[],noChangeAction:A=!1,newPageId:T="",viewOnly:N=!0,hideBlankRows:C=!1})=>d.jsx(sr,{overrides:u,children:d.jsx(rr,{children:d.jsx(sf,{title:e,titleSize:t,type:n,cleanseHiddenData:s,components:r,pages:o,hub:i,cya:l,data:a,classBlock:h,classModifiers:f,className:E,hashLink:c,hide_title:y,summaryListClassModifiers:p,noChangeAction:A,newPageId:T,viewOnly:N,hideBlankRows:C})})}),nf="hods-form",sf=({title:e,titleSize:t,type:n,cleanseHiddenData:s,components:r,pages:o,hub:i,cya:l,data:a,classBlock:c,classModifiers:u,className:h,hashLink:f,hide_title:E,summaryListClassModifiers:y,noChangeAction:p,newPageId:A,viewOnly:T,hideBlankRows:N})=>{const[C,b]=R.useState({}),[P,U]=R.useState(),[g,L]=R.useState([]),[v,F]=R.useState(void 0),[I,k]=R.useState(Q.getNextPageId(n,o,null,null,a)),[O,x]=R.useState(Q.getFormState(I,g,v)),[j,$]=R.useState({}),[q,X]=R.useState({}),[G,V]=R.useState("load"),[z,fe]=R.useState(!1),[pe,Y]=R.useState(!1),{hooks:J}=Pe(),{addErrors:Ke,clearErrors:We,errors:Ee,validate:xe}=He();window.onpopstate=B=>{if(!document.location.hash&&(B.state&&B.state.fullPages!==void 0&&$(ee=>({...ee,fullPages:B.state?.fullPages})),We(),fe(!0),J.onGoingBack(B.state?B.state:null,O.page?.formData),r&&g&&C&&O.page?.formData&&G===void 0)){const ee=w.Format.form({pages:g,components:r},{...C,...O.page.formData},we.SUBMIT);if(ee?.formStatus?.taskPage){const ie=ee.formStatus.tasks;Object.keys(ie).forEach(_e=>{const Fn=ie[_e];Fn.currentPage&&!Fn.complete&&delete ie[_e].currentPage}),delete ee.formStatus.taskPage}b(ee)}},R.useEffect(()=>{r&&o&&a&&(G==="load"||T)&&(b(w.Data.setupForm(o,r,a)),a.formStatus?.page&&k(a.formStatus.page))},[r,o,a,b,G,T]),R.useEffect(()=>{L(w.FormPage.getAll(o,r,{...C}))},[r,o,C,L]),R.useEffect(()=>{k(B=>B||Q.getNextPageId(n,g))},[n,g,k]),R.useEffect(()=>{F(w.Hub.get(n,i,r,{...C}))},[n,i,C,r,F]),R.useEffect(()=>{n===ne.HUB&&z&&C&&O.page?.formData&&(O.page.formData={...C}),fe(!1),x(Q.getFormState(I,g,v))},[g,v,I,x,n,z,C,O.page]),R.useEffect(()=>{V(void 0),J.onFormLoad(B=>{$(B)})},[J]),R.useEffect(()=>{X(i)},[i]),R.useEffect(()=>{P?.data&&(b(P.data),U(void 0))},[P,b,U]);const Ae=i?.sections,M=i?.nonSequential;R.useEffect(()=>{const B=j.fullPages;if(B&&(B.forEach(ee=>{const ie=ee;ie&&(ie.formData=C)}),$(ee=>({...ee,fullPages:B}))),Ae){const ee=C?.formStatus?.tasks||{},ie=Q.getUpdatedSectionStates(Ae,ee,M,C);X(_e=>({..._e,sections:[...ie]}))}},[j.fullPages,C,Ae,M]);const oe=(B,ee={})=>{We(),k(B),J.onPageChange(B,ee)};R.useEffect(()=>{A!==void 0&&k(A)},[A]);const be=B=>{J.onChange(B)},ve=(B,ee)=>{if(typeof ee=="function"){const ie=ee({...C});ie&&b(ie)}O.page?.type===re.PARTIAL_CYA&&!l.disableTaskSwitch&&q.sections.every(ie=>ie.tasks.every(_e=>_e.pages.includes(B.pageId)&&_e.name!==j.name?(ms(_e,g,$,q,C,oe),!1):!0)),B&&Te.cyaAction(B,I,oe)},lt=w.classBuilder(c,u,h);if(v===ye.TASK){const B=l;B.actions=[W.TYPES.SAVE_AND_CONTINUE,W.TYPES.SAVE_AND_RETURN]}const{noTaskCYAs:vn,nonSequential:Fe,...Jr}=q;return d.jsxs("div",{className:lt(),children:[e&&!E&&I===re.HUB&&d.jsx(S.Heading,{size:t,children:e}),O.cya&&d.jsx(md,{pages:Q.getRelevantPages(O,g,j.fullPages),...l,...O.page?.type===re.PARTIAL_CYA&&{actions:O.page.actions?.filter(B=>w.Component.show(B,C))},...O.cya,onAction:B=>{tf(V,B,g,xe,s,r,C,b,n,I,j,J,Ke,v,oe,O,pe,Y)},onRowAction:ve,summaryListClassModifiers:y,hide_title:E,noChangeAction:O.cya.hideChangeActions??p,noGroupAction:O.cya.hideGroupActions??!1,sections:typeof q<"u"?q.sections:[],type:n,hideBlankRows:N}),v===ye.TASK&&O.pageId===re.HUB&&d.jsx(bd,{...Jr,refNumber:C.businessKey,onTaskAction:B=>{ms(B,g,$,q,C,oe)},annotations:q?.taskListAnnotations||[],formData:C}),O.page&&!O.cya&&!O.page.collection&&d.jsx(In,{page:O.page,pages:[...g],onAction:(B,ee,ie)=>{hs(B,ee,ie,J,C,O,xe,oe,n,s,g,r,I,V,j,b,q,U,Ke,pe,Y,Ee)},onChange:be,hashLink:f,classModifiers:O.page.classModifiers,className:O.page.className,submitting:pe,pageId:I}),O.page&&!O.cya&&O.page.collection&&d.jsx(Ed,{page:O.page,pages:g,onCollectionChange:be,onAction:(B,ee,ie)=>{hs(B,ee,ie,J,C,O,xe,oe,n,s,g,r,I,V,j,b,q,U,Ke,pe,Y,Ee)},hashLink:f,classModifiers:O.page.classModifiers,className:O.page.className,submitting:pe})]})};exports.Container=Ln;exports.FormComponent=Ve;exports.FormRenderer=zr;exports.FormTypes=ne;exports.HooksContextProvider=sr;exports.HubFormats=ye;exports.Models=$o;exports.PageActions=_n;exports.SummaryList=cn;exports.Utils=w;exports.ValidationContextProvider=rr;exports.default=zr;
|
package/dist/index.js
CHANGED
|
@@ -3365,7 +3365,7 @@ const {
|
|
|
3365
3365
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- FIXME
|
|
3366
3366
|
gc(t, o, e.id, l, a),
|
|
3367
3367
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- FIXME
|
|
3368
|
-
...Je(e, c, o, r, s)
|
|
3368
|
+
...Je(e, c, o, r, s) ?? []
|
|
3369
3369
|
];
|
|
3370
3370
|
}).filter((o) => !!o) : Cc(e, r), bc = "hods-form-summary-card-details", Ds = ({
|
|
3371
3371
|
masterPage: e,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite",
|
|
6
6
|
"build": "tsc -b && vite build",
|
|
@@ -20,12 +20,9 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@ukhomeoffice/cop-react-components": "6.0.2",
|
|
22
22
|
"dayjs": "1.11.0",
|
|
23
|
-
"dompurify": "3.4.8",
|
|
24
23
|
"govuk-frontend": "5.9.0",
|
|
25
|
-
"marked": "14.0.0",
|
|
26
24
|
"monaco-editor": "0.53.0",
|
|
27
|
-
"uuid": "14.0.0"
|
|
28
|
-
"yaml": "2.9.0"
|
|
25
|
+
"uuid": "14.0.0"
|
|
29
26
|
},
|
|
30
27
|
"peerDependencies": {
|
|
31
28
|
"react": ">=16.14.0 <20",
|