import{j as o}from"./vendor-mui-69397583.js";import{f as w,r as F}from"./vendor-react-ece1c85f.js";import{F as b,Y as A,l as C,E as I,c9 as m,O as f,Q as g}from"./index-c62ac197.js";import{D as k}from"./DoubleSidedImage-ae98733b.js";import{b as L,c as M,a as T}from"./vendor-redux-a1f00e6b.js";import{c as $,d as v,e as B}from"./RoleService-7008da2c.js";import{R as G}from"./RoleForm-cc251eba.js";const R="RoleEditState",c=L(R+"/getTRole",async t=>(await $(t.id)).data),O=async t=>(await v(t)).data,Q=async t=>(await B(t)).success,U={loading:!0,roleData:{id:"",role:"",description:""}},W=M({name:`${R}/state`,initialState:U,reducers:{},extraReducers:t=>{t.addCase(c.fulfilled,(s,i)=>{s.roleData=i.payload,s.loading=!1}).addCase(c.pending,s=>{s.loading=!0})}}),Y=W.reducer,_=T({data:Y}),h=b;A("RoleEditState",_);const q=t=>{const{roleId:s,onDrawerClose:i,footerWidth:x}=t,D=C(),d=w(),r=h(e=>{var n,a;return(a=(n=e.RoleEditState)==null?void 0:n.data)==null?void 0:a.roleData}),l=h(e=>{var n,a;return(a=(n=e.RoleEditState)==null?void 0:n.data)==null?void 0:a.loading}),S=e=>{D(c({id:e}))},y=async(e,n)=>{var u;n(!0);const a=await O({id:e.id??"",name:e.name??"",description:e.description});n(!1),a!=null&&a.success?p("updated"):N(((u=a==null?void 0:a.data)==null?void 0:u.message)||"Something went wrong"),t==null||t.fetchData(),i(null)},E=()=>{i()},j=async e=>{e(!1),await Q(s??"")&&(p("deleted"),i(null))},N=e=>{f.push(o.jsx(g,{title:"Failed",type:"danger",duration:2500,children:e}),{placement:"top-center"}),d("/app/settings/role")},p=e=>{f.push(o.jsxs(g,{title:"Success",type:"success",duration:2500,children:["Role Successfully ",e]}),{placement:"top-center"}),d("/app/settings/role")};return F.useEffect(()=>{S(s)},[s]),o.jsxs(o.Fragment,{children:[o.jsx(I,{loading:l,children:!m(r)&&o.jsx(o.Fragment,{children:o.jsx(G,{type:"edit",footerWidth:x,initialData:r,onFormSubmit:y,onDiscard:E,onDelete:j})})}),!l&&m(r)&&o.jsxs("div",{className:"h-full flex flex-col items-center justify-center",children:[o.jsx(k,{src:"/img/others/img-2.png",darkModeSrc:"/img/others/img-2-dark.png",alt:"No product found!"}),o.jsx("h3",{className:"mt-8",children:"No role found!"})]})]})},Z=q;export{Z as R,Q as d};
