mkA~(@^_^@)~PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT p0 import{o as R,H as D,b as w,t as P,v as S,p as C,j as e,S as $,L as E}from"./index-DoU2MHKd.js";import{M as T}from"./index-BrNVkngO.js";import{u as q,B as H}from"./BlurComponent-By-zEEWf.js";import{e as y}from"./schema-DPsh5xTJ.js";import{F as b}from"./index-BjvZ8PnY.js";import{F as k}from"./index-m30_MRwT.js";import{S as A}from"./index-jGzTCmkU.js";import{a as h}from"./index-CVW_SfJD.js";import{T as j}from"./index-Dx3xM2U7.js";import{C as B}from"./index-CqjYKmlu.js";import{P as g}from"./index-B2Phbgk6.js";import{G as o}from"./Grid-Dszo2Bkt.js";import"./Box-COt46hbf.js";import"./observer-B278D4P8.js";import"./Typography-CcGLjhMP.js";import"./Paper-KHBRuWUR.js";import"./ownerWindow-PUvYI-j5.js";import"./isHostComponent-BHK9_qiJ.js";import"./Select-PBynr6jS.js";import"./Menu-DB1Y7QV-.js";import"./Modal-B-eFE2gS.js";import"./useTheme-DOOi9IXa.js";import"./Portal-DQ_SGxKm.js";import"./createSvgIcon-DsB0b7BB.js";import"./useId-CrSPMxLa.js";import"./MenuItem-CjvEvgdY.js";import"./Slide-BJUyXsdq.js";import"./Dialog-DHruG21S.js";import"./DialogContent-BMAaEywl.js";import"./InputAdornment-dDMHAIE_.js";import"./IconButton-58mvjT_A.js";const I={owner_name:"",email:"",password:"",password_confirmation:"",role_name:"",branch_id:""},V=()=>{const x=R(),{id:n,employeeId:t}=D(),p=w.useRef(),l=w.useRef(),{handleError:i,fireToast:s}=q(),{loading:f,requestHandlers:m}=P(),F=r=>{const a=new FormData,{password:c,password_confirmation:d,...u}=r;return Object.keys(t?u:r).forEach(_=>{a.append(_,r[_])}),a.append("vendor_id",`${n}`),a},v=async r=>{const a=F(r),c=t?`/admin/employees/${t}?_method=PUT`:"/admin/employees",{res:d,error:u}=await m({type:"POST",endpoint:c,body:a});if(u)return i(u);s({title:d.message,type:"success"}),x(`${C.vendorEdit}/${n}`)};return S({queryKey:[],queryFn:async()=>{var d;const{res:r,error:a}=await m({endpoint:`/admin/employees/${t}`});if(a)return i(a);const c={owner_name:r.data.owner_name,email:r.data.email,role_name:r.data.role_name,branch_id:r.data.branch.id};(d=p.current)==null||d.setValues(c)},options:{enabled:!!t}}),{defaultValues:I,onSubmit:v,loading:f,formRef:p,passwordRef:l,id:n,employeeId:t}},G=()=>{var m;const{defaultValues:x,onSubmit:n,loading:t,formRef:p,passwordRef:l,id:i,employeeId:s}=V(),f=s?y.omit(["password","password_confirmation"]):y;return e.jsxs(e.Fragment,{children:[s&&e.jsx(B,{id:s,ref:l}),e.jsx(k,{ref:p,defaultValues:x,onSubmit:n,schema:f,children:e.jsxs(b,{children:[e.jsx(b.PaperTitle,{title:s?"edit_employee":"add_new_employee"}),e.jsxs(o,{item:!0,container:!0,xs:12,spacing:2,children:[e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(j,{name:"owner_name",label:"name"})}),e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(j,{name:"email",label:"email"})}),!s&&e.jsxs(e.Fragment,{children:[e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(g,{name:"password",label:"password"})}),e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(g,{name:"password_confirmation",label:"confirm_password"})})]}),e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(j,{name:"role_name",label:"role_name"})}),e.jsx(o,{item:!0,xs:12,md:6,children:e.jsx(A,{label:"branch",name:"branch_id",item_value:"id",item_label:"name",reqName:`/admin/branches?user_id=${i}`})}),s&&e.jsx(o,{item:!0,xs:12,children:e.jsx(h,{onClick:(m=l.current)==null?void 0:m.openDialog,children:"change_password"})})]}),e.jsx(o,{item:!0,xs:12,mt:1,children:e.jsxs($,{direction:"row",justifyContent:"flex-end",flexWrap:"wrap",gap:2,children:[e.jsx(E,{to:`${C.vendorEdit}/${i}`,children:e.jsx(h,{variant:"contained",color:"secondary",children:"cancel"})}),e.jsx(h,{loading:t,variant:"contained",color:"primary",type:"submit",children:"submit"})]})})]})})]})},we=()=>e.jsxs(H,{children:[e.jsx(T,{title:"employees"}),e.jsx(G,{})]});export{we as default};