import{aw as g,R,aq as x,j as e,Y as h,h as i,i as s,dj as E,g as j,b8 as b,o as L,at as k,G as D,e9 as G}from"./app-BgLa5dit.js";import{W}from"./DJ0pq8J_.chunk.js";import{E as w}from"./BUT90D7O.chunk.js";import{C as y}from"./CCcwLDvu.chunk.js";import{O as P}from"./DNClpFKN.chunk.js";import{b as p,R as I,a as C}from"./KotJtg73.chunk.js";function F(t){const n=g(),[l,o]=R.useState(!1);R.useEffect(()=>{n.validateForm()},[n.values]);const d=!n.isValid,a=p[t.currentStep],u=x.isFunction(a.previousStep)?a.previousStep(n.values):a.previousStep,r=!!u,S=r?{...p[u].appLink,args:[t.id],params:I.convertDataToQueryParams(n.values)}:null,c=t.currentStep===C.SELECT_PROVIDER,N={application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_OVERVIEW,args:[t.id]},O=x.isFunction(a.nextStep)?a.nextStep(n.values):a.nextStep,_=!!a.nextStep?{...p[O].appLink,args:[t.id],params:I.convertDataToQueryParams(n.values)}:null;function f(){j.trigger(_)}async function A(){o(!0),await t.onComplete(n.values),o(!1)}return e.jsxs("div",{className:"d-flex justify-content-end border-top p-4",children:[(r||c)&&e.jsx(h,{className:"me-2 btn btn-dark-outline",appLink:c?N:S,children:`${c?"Cancel":"Back"}`}),e.jsx(E,{showSpinner:l,disabled:d,onClick:_?f:A,variant:"dark",className:d?"btn btn-dark":"",children:_?"Next":"Save"})]})}const M="_container_1q4ji_1",U="_subHeader_1q4ji_4",H="_main_1q4ji_7",q="_leftNav_1q4ji_10",m={container:M,subHeader:U,main:H,leftNav:q},T="rostering-wizard",v=[{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD},{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD_SELECT_PROVIDER},{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD_SET_UP_ROSTERING},{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD_SELECT_EXTERNAL},{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD_MAPPING},{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING_WIZARD_CONFIRMATION}];function X(t){var S,c;const n=b(),l=()=>n.unlock(T),o=L(P.getOrganisation(t.id)),d=(S=o.data)==null?void 0:S.name,a=p[t.currentStepId],u=I.getRosteringWizardSteps(t.id,t.queryParams,t.isEdit),r=I.convertQueryParamsToData(t.queryParams);return R.useEffect(()=>{const N=t.currentStepId!==C.CONFIRMATION?v:[...v,{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING,args:[t.id]}];if(Object.values(r).some(O=>!!O)){n.lock({id:T,title:"Are you sure you want to leave?",text:"The changes you have made will not be saved.",appLinkWhitelist:N});return}l()},[r]),R.useEffect(()=>()=>{l()},[]),o.hasCompleted?e.jsxs(e.Fragment,{children:[e.jsx(y,{}),e.jsxs("div",{className:`row g-0 border-bottom ${m.container}`,children:[e.jsxs("div",{className:`border-end ${m.leftNav} px-3 pt-5 pb-3 d-flex flex-column justify-content-between`,children:[e.jsxs("div",{children:[e.jsx("p",{className:`${m.subHeader} mb-2`,children:"ROSTERING SETUP WIZARD"}),e.jsx(W,{steps:u,currentStep:t.currentStepId,theme:{itemsContainer:"mt-4",itemContent:"px-3 w-100",item:"mb-1",isSelectedOverride:"bg-light-blue fw-normal"}})]}),e.jsx(k,{svg:w,className:"w-fit text-decoration-none",appLink:{application:s.CRM_STUDIO,action:i.CrmStudio.ORGANISATION_ROSTERING,args:[t.id]},children:e.jsx("span",{className:"ms-2",children:"Cancel and Exit"})})]}),e.jsx(D,{initialValues:r,validationSchema:a.schema,onSubmit:null,children:e.jsxs("div",{className:`${m.main} d-flex flex-column justify-content-between`,children:[e.jsxs("div",{className:"p-5",children:[e.jsxs("p",{children:[d," - ",(c=o.data)==null?void 0:c.id]}),t.isLoading?e.jsx(G,{}):t.children]}),e.jsx(F,{id:t.id,currentStep:t.currentStepId,onComplete:t.onSubmit})]})})]})]}):e.jsx(e.Fragment,{})}export{X as O};
//# sourceMappingURL=BrvXpjxr.chunk.js.map
