import{bv as u,eL as T,bw as U,bp as F,bs as z,bT as q,F as H,j as n,bA as J,E as M,b7 as K,a9 as I,R as f,J as O}from"./app-BgLa5dit.js";import{B as w}from"./DpWmZ9cE.chunk.js";import{u as D}from"./DL8ott7R.chunk.js";import{E as W}from"./DULJTEyC.chunk.js";import{U as S,a as X}from"./q-IBKcuF.chunk.js";function te(e){const{hasValidatedUsers:s,setInvalidUsers:l,userType:o,setHideValidListings:t,setExistingUsers:x}=e;return(m,c)=>{const{failed:d,succeed:y}=w.getCategorizedUsers(m),r=w.getInvalidUsers(d,c),i=w.getExistingUsers(y,c);x(i);const C=d.reduce((g,E)=>(E.errorCodes.forEach(h=>{g[h]||(g[h]=0),g[h]++}),g),{});s||u.logUserAction({totalUploaded:c.length,totalInvalid:Object.keys(r).length,errorCodeCount:C},{...w.getAnalyticsOptions(o),workflowPhase:U.Start,descriptor:T.Bulk}),window.setTimeout(()=>{Object.keys(r).length||t(!1),l(r)},1e3)}}function ie(e){const{setHideValidListings:s,hideValidListings:l,userType:o}=e;s(!l),u.logUserAction({hideValidListings:!l},{...w.getAnalyticsOptions(o),actionType:z.Click,descriptor:F.ToggleHideValidListings,workflowPhase:U.Complete})}function ae(e,s){e(null),s()}function ne(e,s){e([]),s()}function oe(e){const{deleteUsers:s}=D(),l=e.userType===q.Learner?"userManager.deleteUploadedStudentPopup":"userManager.deleteUploadedStaffPopup",o=H.encloseNamespace(l);function t(){s(e.users),u.logUserAction({},u.mergeOptions(e.analyticsOptions,{workflowPhase:U.Discard,descriptor:e.users.length>1?T.Bulk:T.Single})),e.closePopup()}return n.jsx(J.Provider,{value:l,children:n.jsxs(M,{title:o("title",{smartCount:e.users.length}),closePopup:e.closePopup,children:[n.jsx("p",{className:"m-0 pb-3",children:n.jsx(K,{phrase:"confirmation",options:{smartCount:e.users.length}})}),n.jsxs(I,{children:[n.jsx(I.Cancel,{onClick:e.closePopup}),n.jsx(I.Submit,{variant:"danger",onClick:t,text:o("delete",{smartCount:e.users.length})})]})]})})}const Y="userManager.editUploadedUserPopup",V=H.encloseNamespace(Y),B="_cv:edit:next:user";function le(e){var L,b;const{invalidUsers:s,updateUser:l,existingUsersHash:o}=D(),[t,x]=f.useState(!!s[e.user.lookupId]),[m,c]=f.useState(!1),[d,y]=f.useState(!!O.get(B)),r=f.useMemo(()=>Object.keys(s),[s]);f.useEffect(()=>{x(!!s[e.user.lookupId]),u.logUserAction({isInvalid:!!s[e.user.lookupId],data:e.user},u.mergeOptions(e.analyticsOptions,{workflowPhase:U.Start}))},[e.user]),f.useEffect(()=>{m&&window.setTimeout(()=>c(!1),300)},[m,c]);const i=s[e.user.lookupId];async function C(a,v){var j,A,N;if(t){const P=await e.validateUser(a);if(!S.handleAsyncErrors(P,a,null,v))return;const p=r.indexOf(e.user.lookupId),G=d?r[p+1]||r[0]:"";c(!0),e.setUser((j=s[G])==null?void 0:j.user)}const k=t?(A=i==null?void 0:i.user)==null?void 0:A.lookupId:(N=e==null?void 0:e.user)==null?void 0:N.lookupId;if(k){if(typeof e.validateEmail=="function"&&a.email){const P=await e.validateEmail(a.email);P[0].validationCode!==X.UserCanBeCreated?o[k]={user:{...P[0].user,...a},errorCodes:[P[0].validationCode]}:o[k]&&delete o[k]}a&&(l({...a,lookupId:k}),u.logUserAction({isInvalid:!1,data:a},u.mergeOptions(e.analyticsOptions,{workflowPhase:U.Complete}))),!t||!r.length||!d?window.setTimeout(e.closePopup,300):v&&v({reset:!0})}}function g(){y(a=>(O.set(B,!a),!a))}const E=t&&r.length>1,h=V(E&&d?"saveAndNext":"save"),R=S.getMinimumPasswordLength(e.passwordPolicy,e.userType,t?(L=i==null?void 0:i.user)==null?void 0:L.masterRole:(b=e==null?void 0:e.user)==null?void 0:b.masterRole);return t&&!i?n.jsx(n.Fragment,{}):n.jsx(M,{closePopup:e.closePopup,title:e.title,showLoadingSpinner:m,children:n.jsx(W,{initialValues:t?i.user:e.user,initialErrors:t?S.getErrorMessages(i.errorCodes,R,!1,e.localErrorMessage):{},userType:e.userType,onSubmit:C,yearGroups:e.yearGroups,onClickCancel:e.closePopup,submitText:h,onToggleNextCheckbox:g,shouldGoToNext:d,formSize:e.formSize,currentUser:e.currentUser,emailRequired:e.emailRequired,showPasswordField:e.showPasswordField,passwordPolicy:e.passwordPolicy,validateEmail:e.validateEmail,appLinks:e.appLinks,isInBulkEditing:!0},e.user.lookupId)})}export{oe as D,le as E,ae as a,ne as b,te as g,ie as o};
//# sourceMappingURL=Bl0-tJo1.chunk.js.map
