import{r as d,f as g,j as s,S as n,h as i,H as p}from"./vendor-ClLR6ncd.js";import{d as c}from"./Warning-DsmyDRzF.js";import{D as f}from"./index-DY-IkI-n.js";import{q as u,d as x,i as h,T as j}from"./index-OtVJl4GC.js";import"./lodash-ZyeDnt0e.js";import"./DialogContent-DR8Wx7Lo.js";import"./DialogTitle-i0lt2jWQ.js";function S(){return u().username}function v(){const{username:r,expireUser:e}=u();return x(async()=>{const t=new URL(`/users/${r}`,window.origin);await h({url:t.toString(),method:"DELETE"})},{onSuccess:()=>{e()}})}const y=()=>{};function I(){const r=S(),e=v(),[t,l]=d.useState(""),o=g(),a=()=>{o(-1)},m=e.isIdle?y:()=>{o("/")};return s.jsx(f,{isOpen:!0,isDisabledSubmit:t!==r||e.isLoading||e.isError||e.isSuccess,cancel:a,close:m,dialogTitle:`Delete ${r}`,dialogBodyMessage:e.isIdle?s.jsxs(n,{spacing:1,children:[s.jsxs(n,{direction:"row",spacing:1,justifyContent:"center",alignItems:"center",children:[s.jsx(c,{color:"error",fontSize:"large"}),s.jsx(i,{color:"error.main",variant:"h5",children:"Danger zone"}),s.jsx(c,{color:"error",fontSize:"large"})]}),s.jsx(i,{children:"This action is irreversable. Please type your username to confirm the removal"}),s.jsx(j,{autoComplete:"off",value:t,setter:l,label:"Username"})]}):e.isLoading?"Removing user...":e.isError?s.jsxs(n,{spacing:2,children:[s.jsxs(i,{children:["Error on removing user: ",e.error.message]}),s.jsx(p,{variant:"contained",onClick:e.reset,children:"Try again"})]}):e.isSuccess?s.jsx(n,{spacing:2,children:s.jsx(i,{children:"User removed successfully!"})}):"",submitTitle:"Delete",onSubmit:()=>{e.mutate(),a()}})}export{I as default};
