import{R as S,l as J,k as W,j as h,E as $,G as z,eC as B,am as H}from"./app-BgLa5dit.js";import{a as l,S as p}from"./B11DWb8Z.chunk.js";import{C as V,a as K,A as Q}from"./BX_Z1075.chunk.js";import{u as X}from"./jfOju8wm.chunk.js";import"./CIRO_mWB.chunk.js";import"./DTaYxhew.chunk.js";import"./DV8zX5C-.chunk.js";import"./CVqrJ8QP.chunk.js";import"./C-49bs9g.chunk.js";function ae(i){const[F,A]=S.useState(!1),[D,w]=S.useState(!1),[j,O]=S.useState(!1),{idp:e,certificates:s,attributeMappings:E,isLoading:L}=X({idpId:i.idpId}),c=J(),n=W(),{firstNameAttribute:g,surnameAttribute:m,displayNameAttribute:d,emailAddressAttribute:I,userRoleAttribute:f,userTypeAttribute:y,yearGroupValueAttribute:b,customerAttribute:C}=l.generateAttributesHashObject(E);async function M(t){var o;try{return await n(p.updateIdp(e==null?void 0:e.id,{loginUrl:t.loginUrl,logoutUrl:t.logoutUrl,logoUrl:t.idpLogo,name:t.idpName,entityId:t.entityId,enabled:t.enabled,ownerId:parseInt(i.entityId)}))}catch(r){console.error(`error updating idp: ${r}`),c.error(((o=r.responseJSON)==null?void 0:o.message)||"Failed to update IDP, please try again")}}async function T(t){var o;try{const r=t.certificates||[],k=(s==null?void 0:s.map(a=>a.id))||[],N=r.filter(a=>!(s!=null&&s.some(u=>l.getFriendlyCertificateString(u)===a))),P=k.filter(a=>!r.some(u=>{const U=s==null?void 0:s.find(q=>q.id===a);return U&&l.getFriendlyCertificateString(U)===u}));if(P.length>0){const a=P.map(u=>n(p.deleteIdpCertificate(e==null?void 0:e.id,u)));await Promise.all(a)}N.length>0&&await n(p.createIdpCertificate(e==null?void 0:e.id,N))}catch(r){console.error(`error saving idp certificate: ${r}`),c.error(((o=r.responseJSON)==null?void 0:o.message)||"Failed to update IDP certificate, please try again")}}async function v(t){var o;try{const r=l.generateIdpAttributeMappings({displayName:t.displayNameAttribute,emailAddress:t.emailAddressAttribute,firstName:t.firstNameAttribute,lastName:t.lastNameAttribute,role:t.roleAttribute,userType:t.userTypeAttribute,yearGroup:t.yearGroupAttribute,customer:t.customerAttribute});return await n(p.setIdpAttributeMappings(i.entityId,e==null?void 0:e.id,r))}catch(r){console.error(`error saving idp attribute mappings: ${r}`),c.error(((o=r.responseJSON)==null?void 0:o.message)||"Failed to update IDP attribute mappings, please try again")}}async function G(t){try{A(!0),await v(t),await T(t),await M(t),c.success("Custom IDP has been updated"),i.closePopup()}finally{A(!1),i.closePopup()}}function R(t){return n(B.uploadBase64Image(H.Logos,t))}function x(){D||i.closePopup()}return h.jsx($,{size:"lg",title:"Edit custom IDP",closePopup:x,showLoadingSpinner:L,children:h.jsx(z,{initialValues:{certificates:(s==null?void 0:s.map(t=>l.getFriendlyCertificateString(t)))||[],enabled:e==null?void 0:e.enabled,entityId:e==null?void 0:e.entityId,idpName:e==null?void 0:e.name,loginUrl:e==null?void 0:e.loginUrl,logoutUrl:e==null?void 0:e.logoutUrl,idpLogo:e==null?void 0:e.logoUrl,displayNameAttribute:d==null?void 0:d.source,emailAddressAttribute:I==null?void 0:I.source,firstNameAttribute:g==null?void 0:g.source,lastNameAttribute:m==null?void 0:m.source,roleAttribute:f==null?void 0:f.source,userTypeAttribute:y==null?void 0:y.source,yearGroupAttribute:b==null?void 0:b.source,customerAttribute:C==null?void 0:C.source},validationSchema:V.concat(Q),onSubmit:null,children:h.jsx(K,{idp:e,uploadImage:R,isOrg:i.isOrg,working:F,submitButtonText:"Save",onCancel:x,onSubmit:G,showImageCropper:j,setShowImageCropper:O,onCropStart:()=>w(!0),onCropEnd:()=>w(!1)})})})}export{ae as EditIdpPopupView};
//# sourceMappingURL=Dm3cICzS.chunk.js.map
