import{l as S,R as L,bT as i,j as s,bA as V,eS as G,b7 as c,F as b,aT as y,J as C,aP as q,k as O,o as d,E as B,aO as _,aR as H,bV as Y,aQ as $,bv as J}from"./app-BgLa5dit.js";import{E as K}from"./DULJTEyC.chunk.js";import{U as Q}from"./ZKp_vc-v.chunk.js";import{a as X}from"./m4aqaK_l.chunk.js";import{C as u,U as h}from"./q-IBKcuF.chunk.js";import"./De9um1Ze.chunk.js";import"./COKAB0_A.chunk.js";import"./BYVfdcaw.chunk.js";import"./BfMtaC_g.chunk.js";import"./R6rHoxuD.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"./MEkA24R1.chunk.js";import"./C53kfXmd.chunk.js";var o=(e=>(e.ShowDetails="show-details",e.EmailedUsers="emailed-students",e.EmailedAdmin="emailed-admin",e))(o||{});const U="userManager.userCreatedSuccess";function z(e){return s.jsx("div",{className:"d-flex justify-content-center w-50 mx-auto pb-3",children:s.jsx("img",{src:e.emailSentImageUrl,alt:"",role:"presentation",className:"w-100"})})}function W(e){return s.jsxs(s.Fragment,{children:[s.jsx("p",{children:s.jsx(c,{phrase:"userDetailsInfo"})}),s.jsx("p",{className:"mb-0 fw-semibold",children:s.jsx(c,{phrase:"username"})}),s.jsx("p",{children:e.creationResponse.username}),s.jsx("p",{className:"mb-0 fw-semibold",children:s.jsx(c,{phrase:"password"})}),s.jsx("p",{children:e.creationResponse.password})]})}function Z(e){return s.jsxs(s.Fragment,{children:[s.jsx(z,{...e}),s.jsx("p",{children:s.jsx(c,{phrase:"emailedUsersInfo",options:{smartCount:e.creationResponse.isBulk?2:1}})})]})}function ee(e){const a=S();function x(){a.success(b.getPhrase(U,"copied")),e.onClose()}const r=L.useMemo(()=>e.userType===i.Staff||e.creationResponse.isBulk||e.creationResponse.hasEmail?o.EmailedUsers:o.ShowDetails,[e.creationResponse]);if(!r)return s.jsx(s.Fragment,{});const m=(()=>{switch(r){case o.ShowDetails:return s.jsx(W,{...e});case o.EmailedUsers:return s.jsx(Z,{...e})}})();return s.jsxs(V.Provider,{value:U,children:[m,s.jsx("div",{className:"d-flex justify-content-end border-top pt-3 px-3 mx-n3",children:r===o.ShowDetails?s.jsx(G.CopyToClipboard,{onCopy:x,text:`${e.creationResponse.username} - ${e.creationResponse.password}`,children:s.jsx("button",{className:"btn btn-dark",children:s.jsx(c,{phrase:"copy"})})}):s.jsx("button",{onClick:e.onClose,className:"btn btn-dark",children:s.jsx(c,{phrase:"okay"})})})]})}const w="_cv:create:next:user";function se(e,a){return{firstName:"",email:"",surname:"",username:"",userType:e,customerId:a.customerId,masterYearGroup:null,masterRole:Y.User,requirePasswordChange:!1,generatePassword:e===i.Learner,password:"",displayName:null}}function be(e){const[a,x]=y.useState(!!C.get(w)),[r,m]=y.useState(null),T=S(),E=q(),R=O(),p=d(H.currentUser()),I=d(u.yearGroups(e.customerId)),f=d(u.passwordPolicy(e.customerId)),N=d(u.customer(e.customerId)),P=e.userType===i.Staff?"userManager.createStaff":"userManager.createStudent",l=b.encloseNamespace(P);function A(t){const n=h.formatCreateOrValidateUserRequest([t],e.userType,e.customerId);return R(u.bulkValidate(n,!1,e.customerId))}async function v(t,n){const F=await A(t);if(!h.handleAsyncErrors(F,t,null,n))return;const M=h.formatCreateOrValidateUserRequest([t],e.userType,e.customerId);$(E,u.createUsers({users:M,customerId:e.customerId,success:j=>{J.logUserAction(t,e.analyticsOptions),a&&n({reset:!0}),m({...j,hasEmail:!!t.email,password:t.password||j.password,isBulk:!1})},error:()=>{T.error(l("error")),e.closePopup()}}))}function k(){m(null),a||e.closePopup()}const D=l(r?"titleSuccess":"titleCreating"),g=!!p.data&&!!f.data;return s.jsx(Q.Provider,{value:X.Curator,children:s.jsx(B,{closePopup:e.closePopup,title:D,showLoadingSpinner:!g,children:(()=>{var t;return g?r?s.jsx(ee,{onClose:k,creationResponse:r,emailSentImageUrl:_.UserManager.EMAIL_SENT,userType:e.userType}):s.jsx(K,{onSubmit:v,userType:e.userType,onClickCancel:e.closePopup,yearGroups:I.data,initialValues:se(e.userType,p.data),onToggleNextCheckbox:()=>x(n=>(C.set(w,!n),!n)),shouldGoToNext:a,goToNextText:l("createNext"),currentUser:p.data,submitText:l("submit"),showPasswordField:e.userType===i.Learner,emailRequired:e.userType===i.Staff,showDisplayNameField:e.userType===i.Staff,passwordPolicy:f.data,hasOrg:!!((t=N.data)!=null&&t.organisation),canEditSuperAdmin:!0}):s.jsx(s.Fragment,{})})()})})}export{be as CreateUserView};
//# sourceMappingURL=CHmycxvZ.chunk.js.map
