import{aA as j,h as I,i as O,aw as _,R as g,j as t,Y as y,dj as L,g as R,o as D,G as E,e9 as T}from"./app-BgLa5dit.js";import{W as k}from"./DJ0pq8J_.chunk.js";import{C as w}from"./CCcwLDvu.chunk.js";import{W as P}from"./Bs6fQ2wT.chunk.js";import{O as W}from"./u6fIQ8Ti.chunk.js";var o=(e=>(e.DETAILS="details",e.CONFIRM="confirm",e))(o||{});const F=j.object().shape({name:j.string().trim().required("Organisation name is required").min(2,"Organisation name must be at least 2 characters").max(100,"Organisation name must be less than 100 characters"),type:j.number().required("Organisation type is required")}),m={[o.DETAILS]:{id:o.DETAILS,label:"Organisation details",nextStep:o.CONFIRM,appLink:{application:O.CRM_STUDIO,action:I.CrmStudio.NEW_ORGANISATION_WIZARD_DETAILS},previousStep:null,schema:F},[o.CONFIRM]:{id:o.CONFIRM,label:"Review and confirm",nextStep:null,appLink:{application:O.CRM_STUDIO,action:I.CrmStudio.NEW_ORGANISATION_WIZARD_CONFIRM},previousStep:o.DETAILS,schema:null}},v=["accountId","name","type"],f={filterValidQueryParams:e=>{const a={};return Object.keys(e).forEach(n=>{v.includes(n)&&(a[n]=e[n])}),a},convertQueryParamsToData(e){const a={};return e.name&&(a.name=e.name),e.type&&(a.type=+e.type),e.accountId&&(a.salesforceAccountId=e.accountId),a},convertDataToQueryParams:e=>{const a={};return Object.entries(e).forEach(([n,i])=>{n==="salesforceAccountId"&&(a.accountId=i),v.includes(n)&&i!==""&&i!==null&&i!==void 0&&(a[n]=i.toString())}),a}};function M(e){const a=_(),[n,i]=g.useState(!1);g.useEffect(()=>{a.validateForm()},[a.values]);const l=!a.isValid,r=m[e.currentStep],c=!!r.previousStep,x=c?{...m[r.previousStep].appLink,params:f.convertDataToQueryParams(a.values)}:null,u=!!r.nextStep?{...m[r.nextStep].appLink,params:f.convertDataToQueryParams(a.values)}:null;function h(){R.trigger(u)}function p(){i(!0),e.onComplete(a.values)}return t.jsxs("div",{className:"d-flex justify-content-end border-top p-4",children:[c&&t.jsx(y,{className:"me-2 btn btn-dark-outline",appLink:x,children:"Back"}),t.jsx(L,{showSpinner:n,disabled:l||e.hasSalesforceOrganisation,onClick:u?h:p,variant:"dark",className:l?"btn btn-dark":"",children:u?"Next":"Create organisation"})]})}const C={application:O.CRM_STUDIO,action:I.CrmStudio.ORGANISATIONS},Q="_container_1jj8j_1",H="_subHeader_1jj8j_4",V="_main_1jj8j_7",z="_leftNav_1jj8j_10",S={container:Q,subHeader:H,main:V,leftNav:z};function Y(e){var p,N,b;const a=m[e.currentStepId],n=f.filterValidQueryParams(e.queryParams),i=!!e.queryParams.accountId,[l,r]=g.useState(),c=D(!!e.queryParams.accountId&&W.salesforceOrganisation(e.queryParams.accountId,s=>{var A;return s.status===404?r("Salesforce organisation could not be found"):r(((A=s==null?void 0:s.responseJSON)==null?void 0:A.message)??"An error occurred when trying to find this organisation in Salesforce")})),x=i&&!!l,d=f.convertQueryParamsToData(n),u=i?{salesforceAccountId:e.queryParams.accountId,name:((p=c.data)==null?void 0:p.name)||d.name||"",type:(N=c.data)==null?void 0:N.orgType}:{name:d.name||"",type:d.type&&+d.type},h=Object.values(m).map(s=>({id:s.id,text:s.label,appLink:s.appLink}));return t.jsxs(t.Fragment,{children:[t.jsx(w,{closeAppLink:C}),t.jsxs("div",{className:`d-flex border-bottom ${S.container}`,children:[t.jsxs("div",{className:`border-end ${S.leftNav} px-3 pt-5 pb-3 d-flex flex-column justify-content-between`,children:[t.jsxs("div",{children:[t.jsx("p",{className:`${S.subHeader} mb-2`,children:"ORGANISATION SETUP WIZARD"}),t.jsx(k,{steps:h,currentStep:e.currentStepId,theme:{itemsContainer:"mt-4",itemContent:"px-3 w-100",item:"mb-1",isSelectedOverride:"bg-light-blue fw-normal"}})]}),t.jsx(P,{appLink:C})]}),t.jsx(E,{initialValues:u,validationSchema:a.schema,onSubmit:null,children:t.jsxs("div",{className:`${S.main} d-flex flex-column justify-content-between`,children:[t.jsx("div",{className:"p-5",children:x?t.jsx("p",{className:"alert alert-danger",children:l}):e.loaded?e.children:t.jsx(T,{})}),t.jsx(M,{currentStep:e.currentStepId,onComplete:e.onSubmit,hasSalesforceOrganisation:!!((b=c.data)!=null&&b.masterId)})]})})]})]})}export{Y as N,o as a};
//# sourceMappingURL=BY5LkID7.chunk.js.map
