import{aw as I,R as S,j as e,cn as j,aO as v,a8 as R,az as C,ax as y,dH as F,o as u,g as E,h as N,i as _}from"./app-BgLa5dit.js";import{R as h}from"./BOJRju0G.chunk.js";import{E as b}from"./DTaYxhew.chunk.js";import{O}from"./DNClpFKN.chunk.js";import{T as P}from"./CRMfsAcH.chunk.js";import{O as k}from"./BrvXpjxr.chunk.js";import{a as w}from"./KotJtg73.chunk.js";import"./DkDkjje4.chunk.js";import"./DV8zX5C-.chunk.js";import"./CIRO_mWB.chunk.js";import"./CVqrJ8QP.chunk.js";import"./DJ0pq8J_.chunk.js";import"./BUT90D7O.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";const M="_item_177fu_1",A="_lastItem_177fu_5",x={item:M,lastItem:A};function L(a,s){if(!a)return s;const n=[];return s.forEach(r=>{r.name.toLowerCase().includes(a.toLowerCase())&&n.push(r)}),n}function T(a){var p;const s=I(),n=S.useRef(null),r=(p=s.values.mappings)==null?void 0:p.find(t=>t.externalId===a.external.id),o=a.schools.find(t=>t.id.toString()===(r==null?void 0:r.masterId.toString())),c=a.schools.filter(t=>{var i;return!((i=s.values.mappings)!=null&&i.some(l=>l.masterId.toString()===t.id.toString()))});return e.jsxs("div",{className:`row align-items-center p-3 border-bottom ${a.isLast?`${x.lastItem} mb-n3`:""} ${x.item}`,children:[e.jsx("div",{className:"mb-0 col-5 col-lg-4",children:e.jsx("span",{className:"text-break",children:a.external.name})}),e.jsx("div",{className:"col-7 col-lg-8",children:e.jsx(j,{initialQuery:o==null?void 0:o.name,initialLocalSuggestions:c,renderSuggestionsOnInputFocus:!0,activationLength:0,controlsRef:n,onSuggestionSelected:t=>{var d;const i={externalId:a.external.id,masterId:t.id};((d=s.values.mappings)==null?void 0:d.find(m=>m.externalId===a.external.id))?s.setFieldValue("mappings",[...s.values.mappings.filter(m=>m.externalId!==a.external.id),i]):s.setFieldValue("mappings",[...s.values.mappings||[],i])},local:c,getLocalSuggestions:L,placeholder:"Enter customer name to search",searchIconPlacement:!1,highlightInputOnFocus:!0,renderAsForm:!1,showClearInputIcon:!0,onClickClearInput:()=>{var i;((i=s.values.mappings)==null?void 0:i.find(l=>l.externalId===a.external.id))&&s.setFieldValue("mappings",[...(s.values.mappings||[]).filter(l=>l.externalId!==a.external.id)])},onBlur:()=>{var t,i;(t=s.values.mappings)!=null&&t.find(l=>l.externalId===a.external.id)||(i=n.current)==null||i.resetQuery()},onSuggestionDependencies:[s.values.mappings],getSuggestionComponent:t=>e.jsx("div",{children:`${t.name} - ${t.crmId}`}),getEmptyStateComponent:t=>e.jsxs(e.Fragment,{children:[e.jsx(P,{query:t,imageUrl:v.EmptyStates.TYPEAHEAD_RESULTS}),e.jsx("p",{className:"px-3 d-flex align-items-center text-center",children:"Please make sure this ClickView customer is set up in Curation Studio and try again."})]})})})]})}const V="_container_nb3ys_1",$="_header_nb3ys_9",f={container:V,header:$};function q(a){const s=I(),n=s.errors.mappings,r=a.externalSchools.sort((o,c)=>o.name.localeCompare(c.name));return e.jsxs("div",{className:`mb-3 ${f.container}`,children:[e.jsxs("div",{className:`${f.header} bg-light border row fw-semibold p-3`,children:[e.jsxs("div",{className:"col-5 col-lg-4",children:[R.toTitleCase(s.values.providerId)," School"]}),e.jsx("div",{className:"col-7 col-lg-8",children:"ClickView School"})]}),e.jsx(C,{children:e.jsx(y,{name:"mappings",id:"mappings",children:()=>r.map((o,c)=>e.jsx(T,{isLast:c===r.length-1,external:o,schools:a.schools},o.id))})}),!!n&&e.jsx(F,{name:"school-mapping",children:n})]})}function se(a){var t,i,l,d,m;const{providerId:s,externalId:n}=a.queryParams,r=u(s&&n&&h.getExternalOrganisation(s,n)),o=u(O.getAllCustomersFromOrganisation(a.id)),c=u(s&&n&&h.getExternalSchools(s,n));n||E.trigger({application:_.CRM_STUDIO,action:N.CrmStudio.ORGANISATION_ROSTERING_WIZARD,args:[a.id],params:a.queryParams});const p=!o.data||!c.data||!r.data;return e.jsxs(k,{id:a.id,currentStepId:w.MAPPING,queryParams:a.queryParams,isLoading:p,isEdit:!!a.queryParams.integrationId,children:[e.jsx("h2",{className:"h3",children:"Map schools into ClickView"}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"d-flex my-4",children:[e.jsx(b,{id:s}),e.jsxs("p",{className:"ms-2 my-auto",children:["• ",(t=r.data)==null?void 0:t.name]})]}),e.jsxs("p",{children:["There are ",(i=c.data)==null?void 0:i.length," schools under ",(l=r.data)==null?void 0:l.name,"."]}),e.jsx("p",{children:"Map the school names to the appropriate ClickView customer:"}),e.jsx(q,{externalSchools:(d=c.data)==null?void 0:d.map(g=>({...g,value:g.id})),schools:(m=o.data)==null?void 0:m.map(g=>({...g,value:g.id}))})]})]})}export{se as RosteringWizardMappingView};
//# sourceMappingURL=i00mYeBR.chunk.js.map
