import{aI as H,bc as O,c4 as V,b0 as Y,az as o,aj as k,bu as D,b4 as B,ah as I,ao as r,iP as z,aF as W,L as X,aP as Z,f as J,e as K,aG as P,aH as R,dZ as p,cf as Q,cb as f,m as G,o as v,ci as _,iX as $,r as ee}from"./app-k0jcl5PQ.js";import{E as ae}from"./BTTfV1w9.chunk.js";import{U as te,L as se}from"./Ci9wan9m.chunk.js";import{U as re}from"./B4GO8DD1.chunk.js";import{S as ie}from"./BpDDe8SM.chunk.js";import{U as n}from"./9ls1F1Ve.chunk.js";import"./kLXBNYk1.chunk.js";import"./C3DvQ1wU.chunk.js";import"./-8JHv8fd.chunk.js";import"./Dqgyavxf.chunk.js";import"./CBiwFpxE.chunk.js";import"./BDviDDog.chunk.js";import"./wCY37Ze3.chunk.js";import"./U4M4wGTR.chunk.js";import"./DV1GpLCe.chunk.js";import"./Di9d6zcy.chunk.js";import"./CKctgafI.chunk.js";import"./DLmnDxSd.chunk.js";import"./CW7x8M-z.chunk.js";import"./BhAq_-86.chunk.js";import"./fstW5ZQE.chunk.js";function oe(e,y){var u;return{userId:e.id,firstName:e.name,surname:e.surname,userType:e.userType,customerId:y.customerId,email:e.email||"",masterYearGroup:e.masterYearGroup??null,username:e.username,masterRole:e.userProfile.role,status:e.status,displayName:((u=e.metadata)==null?void 0:u.displayName)??""}}const c=X.encloseNamespace("userManager.editUser");function Le(e){const[y,u]=H.useState(!1),l=O(),S=V(),g=Y(),s=o(n.getUser(e.id)),t=o(k.currentUser()),U=o(t.data&&n.yearGroups(t.data.customerId)),h=o(t.data&&ie.getCustomerSecuritySettings(t.data.customerId)),x=o(D.config()),L=o(B.customer(t.data.customerId,null,null,!0)),M=o(n.getAuthenticationMethodsByUserIds([e.id]));function b(a){const i=p.formatCreateOrValidateUserRequest([a],e.userType,t.data.customerId);return g(n.bulkValidate(i))}function j(a){const i={userEmails:[{email:a,userType:e.userType}]};return g(n.bulkCheckEmail(i,t.data.customerId))}async function w(a,i){var C,T;const d=await b(a);if(!p.handleAsyncErrors(d,a,s.data,i))return;const F=p.formatEditUserRequest(a);G(S,n.updateUser(F,t.data.id,m=>{if(v.logUserAction(m,e.analyticsOptions),s.data.email!==m.email&&m.status===_.Inactive){N(m);return}l.success(c("success")),e.closePopup()},()=>{l.error(c("error")),e.closePopup()},()=>{},((C=s.data.masterYearGroup)==null?void 0:C.value)===0&&((T=a.masterYearGroup)==null?void 0:T.value)!==0))}function N(a){G(S,n.resendActivationEmail(a.id,()=>{v.logUserAction(a,{...e.analyticsOptions,actionType:ee.SendEmail,descriptor:$.ActivateUser}),l.success(c("success")),u(!0)},()=>{l.error(c("error")),e.closePopup()}))}const A=!!s.data&&!!t.data&&!!U.data&&!!h.data&&M.hasCompleted&&!!x.data,E=I.hasSso(s.data),q=I.hasRmUnifySso(s.data);return r.jsx(re.Provider,{value:z.Primary,children:r.jsx(W,{closePopup:e.closePopup,title:c("popupTitle"),showLoadingSpinner:!A,children:(()=>{var a,i,d;return A?y?r.jsx(te,{creationResponse:{isBulk:!1},userType:e.userType,onClose:e.closePopup,emailSentImageUrl:Z.EMAIL_SENT}):r.jsxs(r.Fragment,{children:[E&&r.jsx(se,{userType:e.userType,isNew:!1,helpArticle:P.getLiteArticle(R.EditSsoAccounts),ssoMappingsApplink:{application:K.SETTINGS,action:J.Settings.SSO_YEAR_GROUP_MAPPINGS}}),r.jsx(ae,{user:s.data,userType:e.userType,yearGroups:e.userType===f.Learner?U.data:null,initialValues:oe(s.data,t.data),initialErrors:p.getInitialErrorsForInvalidYearGroups(s.data.masterYearGroup),onSubmit:w,onClickCancel:e.closePopup,currentUser:t.data,emailRequired:e.userType===f.Staff,showDisplayNameField:e.userType===f.Staff,passwordPolicy:h.data,editSsoUserHelpArticle:P.getLiteArticle(R.EditSsoAccounts),validateEmail:j,hasOrg:!!((a=L.data)!=null&&a.organisation),countryCode:(i=t.data)==null?void 0:i.countryCode,canEditSuperAdmin:((d=t.data)==null?void 0:d.role)===Q.SuperAdmin,hideSsoToggle:!E,canEditSsoFields:q})]}):r.jsx(r.Fragment,{})})()})})}export{Le as EditUserView};
//# sourceMappingURL=Cj4d3YFx.chunk.js.map
