import{aI as U,az as c,aj as C,bu as L,c4 as k,bc as N,aX as b,ao as a,aF as y,L as v,aP as T,Y as w,aZ as B,aq as P,ba as D,f as H,e as M,bU as m,ci as x,cb as _,m as q,o as O}from"./app-k0jcl5PQ.js";import{T as G,a as Y}from"./m0YrH4Ug.chunk.js";import{C as A}from"./_XP6hjk3.chunk.js";import"./BUELddOb.chunk.js";import"./CnoMMtVD.chunk.js";import"./BzIt8QkE.chunk.js";import"./BEDdXV-K.chunk.js";import"./D1M9dqnr.chunk.js";import"./CnSDR2E3.chunk.js";import"./CovT_itD.chunk.js";const p="classrooms.addStudentsToClassroom",i=v.encloseNamespace(p),z={application:M.USER_MANAGER,action:H.UserManager.STUDENTS};function F(s,l,o,e){return{userId:e,customerId:o,query:s,searchType:"user",filters:{excludeClassroom:l,userType:[_.Learner],userProfile:{status:[`${x.Active.toLowerCase()}`,`${x.Inactive.toLowerCase()}`],customerId:o}},indices:["user"],limit:Y}}function ae(s){const[l,o]=U.useState(!1),[e,g]=U.useState([]),n=c(C.currentUser()),d=c(L.config()),h=c(C.token()),u=c(n.data&&A.getClassroom(s.classroomId,n.data.id)),E=k(),S=N(),{hasPermissions:j}=b();function R(){e!=null&&e.length&&(o(!0),q(E,A.addStudents(e.map(t=>t.id),s.classroomId,()=>{o(!1),O.logUserAction({id:s.classroomId,userCount:e.length},s.analyticsOptions),S.success(i("success",{smartCount:e.length,classroomName:u.data.name,escapeText:!0})),s.closePopup()},()=>{o(!1),S.error(i("error",{smartCount:e.length,classroomName:u.data.name})),s.closePopup()})))}const f=!!h.data&&!!u.data&&!!d.data&&!!n.data;return a.jsx(y,{title:i("title"),closePopup:s.closePopup,showLoadingSpinner:!f,children:f&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"pb-3",children:a.jsx(G,{placeholder:i("placeholder"),getRemoteUrl:()=>w.safeUrlConcat(d.data.gatewayApiUrl,"/v3/search"),getRemotePostBody:t=>{var r;return F(t,s.classroomId,n.data.customerId,(r=n.data)==null?void 0:r.id)},requestHeaders:{authorization:`Bearer ${h.data.value}`},selections:e,formatRemoteSuggestions:t=>t.results.filter(r=>!e.find(I=>I.id===r.id)),onSuggestionSelected:t=>g([...e,t]),removeSelection:t=>g(e.filter(r=>r.id!==t.id)),imageCdnUrl:d.data.imageCdnUrl,activationLength:2,debounceTime:200,errorStateImageUrl:T.TYPEAHEAD_ERROR,emptyStateImageUrl:T.EmptyStates.TYPEAHEAD_RESULTS})}),j(B.ManageUsers)&&a.jsxs("p",{children:[a.jsx(P,{namespace:p,phrase:"createNewStudent"}),a.jsx(D,{className:"info-link",onClick:s.closePopup,appLink:z,children:a.jsx(P,{namespace:p,phrase:"studentManager"})})]}),a.jsxs(m,{children:[a.jsx(m.Cancel,{onClick:s.closePopup}),a.jsx(m.Submit,{onClick:R,variant:"dark",text:i("add"),showSpinner:l,disabled:!(e!=null&&e.length)})]})]})})}export{ae as AddStudentsToClassroomView};
//# sourceMappingURL=CtMuePtk.chunk.js.map
