import{R as l,l as v,k as w,j as s,E as j,a9 as y,G as D,eC as F,am as O}from"./app-BgLa5dit.js";import{S as u,a as T}from"./B11DWb8Z.chunk.js";import{C as k,a as G,A as R}from"./BX_Z1075.chunk.js";import{S as B}from"./C-49bs9g.chunk.js";import"./CIRO_mWB.chunk.js";import"./DTaYxhew.chunk.js";import"./DV8zX5C-.chunk.js";import"./CVqrJ8QP.chunk.js";function H(n){const[p,b]=l.useState(),[I,m]=l.useState(!1),[A,g]=l.useState(!1),[h,d]=l.useState(!1),a=v(),o=w(),f=!!p;async function S(e){var t;try{return await o(u.createIdp({loginUrl:e.loginUrl,logoUrl:e.idpLogo,logoutUrl:e.logoutUrl,name:e.idpName,entityId:e.entityId,enabled:!1,ownerId:parseInt(n.entityId)}))}catch(r){console.error(`error creating idp: ${r}`),a.error(((t=r.responseJSON)==null?void 0:t.message)||"Failed to create IDP, please try again")}}async function C(e,t){var r;try{return await o(u.updateIdp(e.id,{loginUrl:e.loginUrl,logoutUrl:e.logoutUrl,logoUrl:e.logoUrl,name:e.name,entityId:e.entityId,ownerId:e.ownerId,enabled:t}))}catch(i){console.error(`error updating idp: ${i}`),a.error(((r=i.responseJSON)==null?void 0:r.message)||"Failed to update IDP, please try again")}}async function x(e,t){var r;if(!(!t.certificates||t.certificates.length===0))try{o(u.createIdpCertificate(e,t.certificates))}catch(i){console.error(`error saving idp certificate: ${i}`),a.error(((r=i.responseJSON)==null?void 0:r.message)||"Failed to save IDP certificate, please try again")}}async function N(e,t){var r;try{const i=T.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 o(u.setIdpAttributeMappings(n.entityId,e,i))}catch(i){console.error(`error saving idp attribute mappings: ${i}`),a.error(((r=i.responseJSON)==null?void 0:r.message)||"Failed to create IDP attribute mappings, please try again")}}async function P(e){try{m(!0);const t=await S(e);await x(t.id,e),await N(t.id,e),e.enabled&&await C(t,e.enabled),a.success("Custom IDP has been created"),b(t)}finally{m(!1)}}function U(e){return o(F.uploadBase64Image(O.Logos,e))}function c(){A||(d(!1),n.closePopup())}return s.jsxs(j,{size:"lg",title:"Create custom IDP",closePopup:c,children:[f&&s.jsxs(s.Fragment,{children:[s.jsx(B,{idp:p,showAlertBanner:!0,leadingText:"Here are your service provider details:"}),s.jsx(y,{children:s.jsx(y.Submit,{variant:"dark",text:"Close",onClick:c})})]}),!f&&s.jsx(D,{initialValues:{certificates:[],enabled:!1,entityId:"",idpLogo:"",idpName:"",loginUrl:"",logoutUrl:"",displayNameAttribute:"",emailAddressAttribute:"",firstNameAttribute:"",lastNameAttribute:"",roleAttribute:"",userTypeAttribute:"",yearGroupAttribute:"",customerAttribute:""},validationSchema:k.concat(R),onSubmit:null,children:s.jsx(G,{isCreate:!0,uploadImage:U,isOrg:n.isOrg,working:I,submitButtonText:"Create",onCancel:c,onSubmit:P,showImageCropper:h,setShowImageCropper:d,onCropStart:()=>g(!0),onCropEnd:()=>g(!1)})})]})}export{H as CreateIdpPopupView};
//# sourceMappingURL=hDwjeiT9.chunk.js.map
