import{j as s}from"./vendor-mui-69397583.js";import{r as Q,f as Z}from"./vendor-react-ece1c85f.js";import{F as v,Y as ee,l as te,E as ae,c9 as W,O as g,Q as h}from"./index-c62ac197.js";import{D as se}from"./DoubleSidedImage-ae98733b.js";import{b as re,c as ne,a as de}from"./vendor-redux-a1f00e6b.js";import{d as ie,e as ce,b as oe}from"./UserService-047aef51.js";import{U as le}from"./UserForm-31fdd3b3.js";const _="UserEditState",p=re(_+"/getUser",async t=>{const a=await ie(t.id);return a.data.role={value:a.data.role,label:a.data.role},a.data}),ue=async(t,a)=>await ce(t,a),me={loading:!0,userData:{id:"",tenantName:"",firstName:"",lastName:"",email:"",role:"",phone:"",brLocationId:""}},fe=ne({name:`${_}/state`,initialState:me,reducers:{},extraReducers:t=>{t.addCase(p.fulfilled,(a,i)=>{a.userData=i.payload,a.loading=!1}).addCase(p.pending,a=>{a.loading=!0})}}),ge=fe.reducer,he=de({data:ge}),Y=v;ee("UserEditState",he);const pe=t=>{const{userId:a,onDrawerClose:i,footerWidth:q,isAccountList:z=!1}=t;Q.useState([]);const H=te();t==null||t.selectedId;const J=Z(),m=Y(e=>{var n,d,f,c,o,l,u,r,S,U,E,N,x,I,j,b,w,F,L,T,A,C,R,k,M,$,B,G,O;return{...(d=(n=e.UserEditState)==null?void 0:n.data)==null?void 0:d.userData,phone:(o=(c=(f=e.UserEditState)==null?void 0:f.data)==null?void 0:c.userData)==null?void 0:o.phoneNumber,loginType:{value:(r=(u=(l=e.UserEditState)==null?void 0:l.data)==null?void 0:u.userData)==null?void 0:r.loginType,label:(E=(U=(S=e.UserEditState)==null?void 0:S.data)==null?void 0:U.userData)==null?void 0:E.loginType},accountId:(I=(x=(N=e.UserEditState)==null?void 0:N.data)==null?void 0:x.userData)!=null&&I.accountId?{value:(w=(b=(j=e.UserEditState)==null?void 0:j.data)==null?void 0:b.userData)==null?void 0:w.accountId,label:(T=(L=(F=e.UserEditState)==null?void 0:F.data)==null?void 0:L.userData)==null?void 0:T.accountName}:null,countyId:(R=(C=(A=e.UserEditState)==null?void 0:A.data)==null?void 0:C.userData)!=null&&R.countyId?{value:($=(M=(k=e.UserEditState)==null?void 0:k.data)==null?void 0:M.userData)==null?void 0:$.countyId,label:(O=(G=(B=e.UserEditState)==null?void 0:B.data)==null?void 0:G.userData)==null?void 0:O.countyName}:null}}),y=Y(e=>{var n,d;return(d=(n=e.UserEditState)==null?void 0:n.data)==null?void 0:d.loading}),K=e=>{H(p({id:e}))},P=async(e,n)=>{var c,o,l,u;n(!0);const d={email:e.email,role:e.role.value,firstName:e.firstName,lastName:e.lastName,brLocationId:e.brLocationId,phone:(e==null?void 0:e.phone)??null,loginType:(c=e==null?void 0:e.loginType)==null?void 0:c.value,entityId:((o=e==null?void 0:e.entityId)==null?void 0:o.value)??null},f=e.id??"";try{const r=await ue(f,d);n(!1),r!=null&&r.success?(i(),t==null||t.fetchData(),D("updated")):g.push(s.jsx(h,{title:"Error",type:"danger",duration:2500,children:r.message}),{placement:"top-center"})}catch(r){g.push(s.jsx(h,{title:"Error",type:"danger",duration:2500,children:((u=(l=r==null?void 0:r.response)==null?void 0:l.data)==null?void 0:u.message)||"Something went wrong. please try again!"}),{placement:"top-center"})}},V=()=>{i()},X=async e=>{e(!1),await oe(m.id)&&(D("deleted"),t==null||t.fetchData(),i())},D=e=>{g.push(s.jsxs(h,{title:"Success",type:"success",duration:2500,children:["User Successfully ",e]}),{placement:"top-center"}),z||J("/app/settings/user")};return Q.useEffect(()=>{K(a)},[a]),s.jsxs(s.Fragment,{children:[s.jsx(ae,{loading:y,children:!W(m)&&s.jsx(s.Fragment,{children:s.jsx(le,{type:"edit",footerWidth:q,initialData:m,onFormSubmit:P,onDiscard:V,onDelete:X})})}),!y&&W(m)&&s.jsxs("div",{className:"h-full flex flex-col items-center justify-center",children:[s.jsx(se,{src:"/img/others/img-2.png",darkModeSrc:"/img/others/img-2-dark.png",alt:"No product found!"}),s.jsx("h3",{className:"mt-8",children:"No user found!"})]})]})},Ie=pe;export{Ie as U};
