import{aw as T,ej as j,j as a,a8 as y,k as A,l as b,o as I,g as d,h as m,i as u}from"./app-BgLa5dit.js";import{R as g}from"./BOJRju0G.chunk.js";import{E as w}from"./DTaYxhew.chunk.js";import{O as P}from"./DNClpFKN.chunk.js";import{T as E}from"./lZO4aq5x.chunk.js";import{O as _}from"./BrvXpjxr.chunk.js";import{a as q,R as D}from"./KotJtg73.chunk.js";import"./DkDkjje4.chunk.js";import"./DV8zX5C-.chunk.js";import"./CIRO_mWB.chunk.js";import"./CVqrJ8QP.chunk.js";import"./C8_78Eqq.chunk.js";import"./DJ0pq8J_.chunk.js";import"./BUT90D7O.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";const G={table:"w-100 h-auto",header:"bg-light border-bottom",headerCell:"fw-semibold text-nowrap p-3",row:"py-3",cell:"p-3 flex-grow-1"},x=j();function M(e){const o=T().values.mappings.sort((s,i)=>{const r=e.externalSchools.find(l=>l.id===s.externalId),t=e.externalSchools.find(l=>l.id===i.externalId);return(r==null?void 0:r.name.localeCompare((t==null?void 0:t.name)||""))||0}),h={externalSchool:x.accessor(s=>s,{id:"externalSchool",header:()=>`${y.toTitleCase(e.providerId)} school`,cell:s=>{const i=s.getValue(),r=e.externalSchools.find(t=>t.id===i.externalId);return a.jsx("div",{children:r==null?void 0:r.name})},size:400}),school:x.accessor(s=>s,{id:"school",header:"ClickView customer",cell:s=>{const i=s.getValue(),r=e.schools.find(t=>t.id.toString()===i.masterId.toString());return a.jsx("div",{children:r==null?void 0:r.name})},size:400}),id:x.accessor(s=>s,{id:"cvcId",header:"CVC ID",cell:s=>{const i=s.getValue(),r=e.schools.find(t=>t.id.toString()===i.masterId.toString());return a.jsx(a.Fragment,{children:r==null?void 0:r.crmId})}})};return a.jsx("div",{className:"border rounded-3 overflow-hidden",children:a.jsx(E,{data:o,columns:Object.values(h),theme:G})})}function ee(e){var R;const{providerId:n,externalId:o,mappings:h}=e.queryParams,s=A(),i=b(),r=I(n&&o&&g.getExternalOrganisation(n,o)),t=I(P.getAllCustomersFromOrganisation(e.id)),l=I(n&&o&&g.getExternalSchools(n,o));o||d.trigger({application:u.CRM_STUDIO,action:m.CrmStudio.ORGANISATION_ROSTERING_WIZARD_SELECT_EXTERNAL,args:[e.id],params:e.queryParams}),n||d.trigger({application:u.CRM_STUDIO,action:m.CrmStudio.ORGANISATION_ROSTERING_WIZARD,args:[e.id],params:e.queryParams}),h||d.trigger({application:u.CRM_STUDIO,action:m.CrmStudio.ORGANISATION_ROSTERING_WIZARD_MAPPING,args:[e.id],params:e.queryParams});const f=!t.hasCompleted||!l.hasCompleted||!r.hasCompleted,p=!!e.queryParams.integrationId;async function C(c){await s(g.createSchoolMapping(D.buildRosteringRequest(e.id,c)))}async function N(c){await s(g.updateRosteringSchoolMappings(e.queryParams.integrationId,c.mappings))}async function O(c){var S;try{p?await N(c):await C(c),i.success("Successfully saved rostering setup"),d.trigger({application:u.CRM_STUDIO,action:m.CrmStudio.ORGANISATION_ROSTERING,args:[e.id]})}catch(v){i.error(((S=v.responseJSON)==null?void 0:S.message)||"Failed to save rostering setup, please try again")}}return a.jsxs(_,{id:e.id,currentStepId:q.CONFIRMATION,queryParams:e.queryParams,onSubmit:O,isLoading:f,isEdit:p,children:[a.jsx("h2",{className:"h3",children:"Review and confirm"}),a.jsx("p",{className:"my-4",children:"You are about to sync rostering schools to ClickView. Please check and confirm all details:"}),a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"row mt-2 align-items-center",children:[a.jsx("label",{className:"col-4 mb-0",children:"Provider"}),a.jsx("div",{className:"col-6",children:a.jsx(w,{id:e.queryParams.providerId})}),a.jsxs("div",{className:"row mt-2",children:[a.jsx("label",{className:"col-4",children:"District school"}),a.jsx("span",{className:"col-6",children:(R=r.data)==null?void 0:R.name})]})]}),a.jsx("h3",{className:"h6 mt-4 mb-3",children:"School mappings"}),a.jsx(M,{providerId:e.queryParams.providerId,externalSchools:l.data,schools:t.data})]})]})}export{ee as RosteringWizardConfirmationView};
//# sourceMappingURL=CQ3HVRwx.chunk.js.map
