import{k as Y,l as k,o as S,R as q,j as a,E as F,a8 as T,a9 as m}from"./app-BgLa5dit.js";import{S as u,a as B}from"./B11DWb8Z.chunk.js";import{a as E,u as H}from"./BoupYpv9.chunk.js";import{C as d}from"./q-IBKcuF.chunk.js";import"./CIRO_mWB.chunk.js";import"./DUpYPoLs.chunk.js";import"./EZim8aq-.chunk.js";import"./BD9MrUJP.chunk.js";import"./s6cGcwlA.chunk.js";import"./Zwjmkasg.chunk.js";import"./4qGb1BIY.chunk.js";import"./DnXDEnAR.chunk.js";import"./DpUpv6rY.chunk.js";import"./CG7zbly5.chunk.js";import"./m4aqaK_l.chunk.js";import"./MEkA24R1.chunk.js";import"./C53kfXmd.chunk.js";function te(e){var l,g;const c=Y(),i=k(),n=S(d.customer(e.id)),{customerIdpMappings:p,isLoading:y}=E(e.id),{isLoading:h}=H(e.id),f=S(n.data&&u.getSsoYearGroupsMappings(e.id)),v=p==null?void 0:p.find(s=>s.idpId===e.idpId),[w,x]=q.useState(!1),{isLegacy:M,isShared:C}=B.getSsoManagementContext(e.idpId);async function j(){var t;const s=((t=f.data)==null?void 0:t.map(o=>{var r;return{yearGroupId:((r=o.yearGroup.id)==null?void 0:r.toString())||null,ssoMapping:""}}))||[];try{return await c(u.saveSsoYearGroupsMappings(e.id,s))}catch(o){if(o.status===200)return;throw o}}async function R(){var s,t,o;try{return await c(u.clearSamlSsoMapping((t=(s=n.data)==null?void 0:s.country)==null?void 0:t.code,(o=n.data)==null?void 0:o.customerGuid))}catch(r){if(r.status===200)return;throw r}}async function I(){return await c(d.removeCustomerIdpMappings(e.id,e.idpId))}async function L(){try{await I(),i.success("Successfully removed the customer's sso mapping")}catch{i.error("Cannot remove sso mapping, please try again")}}async function G(){try{await j(),await R(),i.success("Successfully removed the customer's sso mapping")}catch{i.error("Cannot remove sso mapping, please try again")}}async function P(){var s;try{const t=d.removeCustomerIdpMappings(e.id,e.idpId);await c(t),i.success("Successfully removed the customer's sso mapping")}catch(t){i.error(((s=t.responseJSON)==null?void 0:s.message)||"Failed to remove SSO mapping, please try again")}}async function O(){x(!0);try{C?await L():M?await G():v&&await P()}finally{e.closePopup()}}const A=n.hasCompleted&&!y&&!h;return a.jsxs(F,{title:"Remove SSO mapping",closePopup:e.closePopup,showLoadingSpinner:!A,children:[a.jsx("p",{children:"Are you sure you want to remove this mapping?"}),a.jsxs("ul",{className:"mt-1 ps-3 ms-1",children:[a.jsxs("li",{children:["SSO: ",a.jsx("strong",{children:T.toTitleCase(e.idpId)})]}),a.jsxs("li",{children:["Customer: ",a.jsx("strong",{children:`${(l=n.data)==null?void 0:l.name} (${(g=n.data)==null?void 0:g.crmId})`})]})]}),a.jsxs(m,{children:[a.jsx(m.Cancel,{onClick:e.closePopup}),a.jsx(m.Submit,{text:"Remove SSO mapping",variant:"danger",onClick:O,showSpinner:w})]})]})}export{te as RemoveCustomerSsoMappingView};
//# sourceMappingURL=BfWlEr8u.chunk.js.map
