import{j as e,b7 as d,F as l,O as U,Q as k,au as I,b4 as M,ap as A,bT as N,R as o,at as L,ee as O,aS as F}from"./app-BgLa5dit.js";import{E as R,a as B,D as $,b as q}from"./Bl0-tJo1.chunk.js";import{u as b}from"./DL8ott7R.chunk.js";import{B as y}from"./DpWmZ9cE.chunk.js";import{W as z}from"./MEkA24R1.chunk.js";import{E as m}from"./0GREfvNX.chunk.js";import{a as g}from"./q-IBKcuF.chunk.js";const S="userManager.userDuplicatesEmptyState";function G(s){const{existingUsersHash:n}=b(),a=!!Object.keys(n).length;return e.jsxs(m,{children:[e.jsx(m.Image,{src:s.imageUrl}),e.jsx(m.Heading,{children:e.jsx(d,{namespace:S,phrase:"heading"})}),e.jsx(m.Cta,{text:l.getPhrase(S,a?"next":"create"),onClick:s.onClickConfirm,className:"btn btn-dark"})]})}const c="userManager.userDuplicateSet",W=(s,n)=>[{Header:l.getPhrase(c,"firstName"),id:"firstName",accessor:"firstName",Cell:({value:a})=>e.jsx("div",{className:"w-100",children:a}),width:12.5},{Header:l.getPhrase(c,"lastName"),id:"surname",accessor:"surname",Cell:({value:a})=>e.jsx("div",{className:"w-100",children:a}),width:12.5},{Header:l.getPhrase(c,"email"),id:"email",Cell:a=>{const r=a.row.original,t=r.errorCodes.find(i=>i===g.EmailAlreadyExisted);return e.jsx("div",{className:`w-100 ${t?"text-danger":""}`,children:r.email})},width:39},{Header:l.getPhrase(c,"username"),id:"username",Cell:a=>{const r=a.row.original,t=r.errorCodes.find(i=>i===g.UsernameAlreadyExisted);return e.jsx("div",{className:`w-100 ${t?"text-danger":""}`,children:r.username})},width:29},{Header:"",id:"actions",accessor:"lookupId",Cell:({value:a})=>e.jsxs("div",{className:"w-100 d-flex align-items-center",children:[e.jsx(U,{className:"me-2 cursor-pointer",onClick:()=>s(a),children:e.jsx(k,{svg:I,title:l.getPhrase(c,"editTooltip"),tooltipPlacement:"top",tooltipSpanHack:!0})}),e.jsx(U,{className:"cursor-pointer",onClick:()=>n(a),children:e.jsx(k,{svg:M,title:l.getPhrase(c,"deleteTooltip"),tooltipPlacement:"top",tooltipSpanHack:!0})})]}),width:7}],u="userManager.userDuplicateSet",Q={header:"fw-semibold pb-1",headerCell:"px-2 py-1",cell:"px-2 py-1"};function V(s,n){const a=n===N.Learner;return s.length===2?l.getPhrase(u,a?"duplicateUsernameAndEmailStudents":"duplicateUsernameAndEmailStaff"):s.find(r=>r===g.UsernameAlreadyExisted)?l.getPhrase(u,a?"duplicateUsernamesStudents":"duplicateUsernamesStaff"):s.find(r=>r===g.EmailAlreadyExisted)?l.getPhrase(u,a?"duplicateEmailsStudents":"duplicateEmailsStaff"):""}function _(s){const n=V(s.set.errorCodes,s.userType),a=t=>s.onClickEdit(s.set.users.find(i=>i.lookupId===t)),r=t=>s.onClickDelete([t]);return n?e.jsxs("div",{className:"pb-4",children:[e.jsx("h3",{className:"h5",children:e.jsx(d,{namespace:u,phrase:"heading",options:{counter:s.index+1}})}),e.jsx("p",{className:"text-danger mb-1",children:n}),e.jsx("div",{className:"p-2 border rounded-3",children:e.jsx(A,{columns:W(a,r),data:s.set.users.map(t=>({lookupId:t.lookupId,firstName:t.firstName,surname:t.surname,email:t.email,username:t.username,errorCodes:s.set.errorCodes})),theme:Q})})]}):e.jsx(e.Fragment,{})}function te(s){const{users:n,duplicateSets:a}=b(),{setDisableNext:r,setOnClickConfirm:t}=o.useContext(z),i=s.userType===N.Learner?"userManager.studentDuplicates":"userManager.staffDuplicates",v=l.encloseNamespace(i),[j,C]=o.useState([]),[p,h]=o.useState(),[P]=o.useState(a);return o.useEffect(()=>{r(!!(a!=null&&a.length))},[a==null?void 0:a.length]),o.useEffect(()=>{t(()=>s.onClickConfirm)},[s.onClickConfirm]),n!=null&&n.length?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"h4",children:e.jsx(d,{namespace:i,phrase:"heading"})}),e.jsx("main",{className:"pb-3",children:a!=null&&a.length?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mb-3 fw-semibold",children:e.jsx(d,{namespace:i,phrase:"subheading"})}),e.jsx("div",{className:"pb-3",children:e.jsx(L,{svg:O,appLink:s.appLinks.userUploadPopup,className:"btn btn-outline-dark me-2",children:e.jsx(d,{namespace:i,phrase:"reupload"})})}),P.map((D,x)=>{const T=D.users.map(f=>f.lookupId),E=a.find(f=>{const w=f.users.map(H=>H.lookupId);return F.isEqual(T,w)});return E.errorCodes.length?e.jsx(_,{index:x,set:E,userType:s.userType,onClickEdit:h,onClickDelete:C},x):e.jsx(o.Fragment,{},x)})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mb-3",children:e.jsx(d,{namespace:i,phrase:"emptyStateSubheading"})}),e.jsx(G,{imageUrl:s.emptyStateImageUrl,onClickConfirm:s.onClickConfirm})]})}),!!p&&e.jsx(R,{user:p,setUser:h,closePopup:()=>B(h,s.closePopup),title:v("editUser"),userType:s.userType,analyticsOptions:y.getAnalyticsOptions(s.userType),currentUser:s.currentUser,yearGroups:s.yearGroups,validateUser:s.validateUser,formSize:s.formSize,emailRequired:s.emailRequired,passwordPolicy:s.passwordPolicy,appLinks:s.appLinks,localErrorMessage:s.localErrorMessage,validateEmail:s.validateEmail},p.lookupId),!!j.length&&e.jsx($,{users:j,userType:s.userType,closePopup:()=>q(C,s.closePopup),analyticsOptions:y.getAnalyticsOptions(s.userType)})]}):e.jsx(e.Fragment,{})}export{te as U};
//# sourceMappingURL=D3UuIyr4.chunk.js.map
