import{k as v,r as d,h as g,F as y,j as i,K as x,Y as C,B as N}from"./vendor.e6eaca24.js";import{s as t}from"./UserEditPage.66f2d9f8.js";import{a as f,R as p,m as S,u as U,b as l,h as E,t as u}from"./index.c6944236.js";import{u as R}from"./useAsyncCallbackPending.bf7bbf90.js";import"./validators.ad4c624c.js";import"./v4.90f1a8cc.js";async function z(e){const{requestError:s,response:a}=await f.user.getUserMeta({username:e,getPrivileges:!0});if(s)throw new p(s,{showRefresh:!0,showBack:!0});if(a.error)throw new p(S(`user_edit.errors.${a.error}`));return a}var h=(e=>(e.EditHomepage="EditHomepage",e.ManageUser="ManageUser",e.ManageUserGroup="ManageUserGroup",e.ManageProblem="ManageProblem",e.ManageContest="ManageContest",e.ManageDiscussion="ManageDiscussion",e.SkipRecaptcha="SkipRecaptcha",e))(h||{});const $=e=>{const s=U("user_edit.privilege");d.exports.useEffect(()=>{l.enterNewPage(`${s(".title")} - ${e.meta.username}`,null,!1)},[l.locale,e.meta]);const[,a]=E(),[w,b]=R(async()=>{const{requestError:r,response:n}=await f.user.setUserPrivileges({userId:e.meta.id,privileges:[...c]});r?u.error(r(s)):n.error?u.error(s(`user_edit.errors.${n.error}`)):(a(!1),u.success(s(".success")))}),[c,M]=d.exports.useState(new Set(e.privileges));function k(r,n){const o=new Set(c);n?o.add(r):o.delete(r),M(o),a(!0)}const m=l.currentUser.isAdmin;return g(y,{children:[i(x,{className:t.sectionHeader,size:"large",content:s(".header")}),Object.values(h).map(r=>g("div",{className:t.privilegeRow,children:[i(C,{toggle:!0,readOnly:!m,label:s(`.privileges.${r}.name`),checked:c.has(r),onChange:(n,{checked:o})=>k(r,o)}),i("div",{className:t.notes,children:s(`.privileges.${r}.notes`)})]},r)),i("div",{className:t.notes+" "+t.notesAdminOnly,children:s(".admin_only")}),i(N,{className:t.submit,loading:w,disabled:!m,primary:!0,content:s(".submit"),onClick:b})]})},D=v($);export{D as View,z as fetchData};
