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{H as D,o as k,b as w,t as S,v as M,p as b,j as e,S as f,L as $,k as P,q as O}from"./index-DoU2MHKd.js";import{M as Z}from"./index-BrNVkngO.js";import{b as U,s as B}from"./schema-DPsh5xTJ.js";import{u as F,B as W}from"./BlurComponent-By-zEEWf.js";import{F as T}from"./index-BjvZ8PnY.js";import{F as V}from"./index-m30_MRwT.js";import{a as y}from"./index-CVW_SfJD.js";import{T as _}from"./index-Dx3xM2U7.js";import{G as l}from"./Grid-Dszo2Bkt.js";import{E as q}from"./types-DawfCQSy.js";import{M as ee}from"./index-BBvCh1_S.js";import{F as ne}from"./index-B682V-Nx.js";import{C as se}from"./index-CqjYKmlu.js";import{P as H}from"./index-B2Phbgk6.js";import{S as te}from"./index-CVuyG2eD.js";import{T as R}from"./Typography-CcGLjhMP.js";import{d as N}from"./index-BlY_8HrJ.js";import{D as Q,a as z}from"./index-DiVRNiCO.js";import{u as G}from"./useMutation-BvY1LEQe.js";import{T as K,a as j}from"./index-CiRO-Vqk.js";import{T as J,a as X,b as Y}from"./TableActionsComponent-BvKqtDOP.js";import{B as re}from"./Box-COt46hbf.js";import{T as ae,a as E}from"./Tabs-qW8erDQu.js";import"./observer-B278D4P8.js";import"./Paper-KHBRuWUR.js";import"./ownerWindow-PUvYI-j5.js";import"./isHostComponent-BHK9_qiJ.js";import"./useTheme-DOOi9IXa.js";import"./ListItemText-DZ1IUloL.js";import"./MenuItem-CjvEvgdY.js";import"./Menu-DB1Y7QV-.js";import"./Modal-B-eFE2gS.js";import"./Portal-DQ_SGxKm.js";import"./TextField-CalTE7pK.js";import"./useId-CrSPMxLa.js";import"./Select-PBynr6jS.js";import"./createSvgIcon-DsB0b7BB.js";import"./InputAdornment-dDMHAIE_.js";import"./IconButton-58mvjT_A.js";import"./Slide-BJUyXsdq.js";import"./Dialog-DHruG21S.js";import"./DialogContent-BMAaEywl.js";import"./SwitchBase-DGPEKm6a.js";import"./index-iKvzeMDi.js";import"./index-BNpHSX81.js";import"./index-BI46YYdk.js";const oe={bank_account:"",bank_holder_name:"",bank_number:"",iban:"",swift_code:""},ie=()=>{const{id:n}=D(),a=k(),r=w.useRef(),{handleError:t,fireToast:c}=F(),{loading:s,requestHandlers:i}=S(),x=d=>{const p=new FormData;return Object.keys(d).forEach(o=>{p.append(o,d[o])}),p},m=async d=>{const p=x(d),{res:o,error:u}=await i({type:"POST",endpoint:`/admin/users/${n}?_method=PUT`,body:p});if(u)return t(u);c({title:o.message,type:"success"}),a(b.vendors)},g=async()=>{var u,v;const{res:d,error:p}=await i({endpoint:`/admin/users/${n}`});if(p)return t(p);const o={...((u=d.data)==null?void 0:u.bank_info)&&d.data.bank_info};(v=r.current)==null||v.setValues(o)};return M({queryKey:[`/admin/users/${n}`],queryFn:g,options:{enabled:!!n}}),{defaultValues:oe,onSubmit:m,loading:s,formRef:r}},le=()=>{const{defaultValues:n,onSubmit:a,loading:r,formRef:t}=ie();return e.jsx(V,{ref:t,defaultValues:n,onSubmit:a,schema:U,children:e.jsx(f,{gap:4,children:e.jsxs(T,{children:[e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"bank_holder_name",label:"bank_holder_name"})}),e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"bank_account",label:"bank_account"})}),e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"bank_number",label:"bank_number"})}),e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"swift_code",label:"swift_code"})}),e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"iban",label:"iban"})}),e.jsx(l,{item:!0,xs:12,mt:1,children:e.jsxs(f,{direction:"row",justifyContent:"flex-end",flexWrap:"wrap",gap:2,children:[e.jsx($,{to:b.vendors,children:e.jsx(y,{variant:"contained",color:"secondary",children:"cancel"})}),e.jsx(y,{loading:r,variant:"contained",color:"primary",type:"submit",children:"submit"})]})})]})})})},ce={owner_name:"",email:"",password:"",password_confirmation:"",mobile:"",image:null,status:"Active",type:"vendor"},de=()=>{const{id:n}=D(),{t:a}=P(),r=k(),t=w.useRef(),c=w.useRef(),{handleError:s,fireToast:i}=F(),{loading:x,requestHandlers:m}=S(),g=o=>{const u=new FormData,{password:v,password_confirmation:C,...I}=o;return Object.keys(n?I:o).forEach(h=>{if(h==="image"&&o[h])typeof o[h]=="object"&&u.append(h,o[h][0]);else if(h==="mobile"){const A=o[h].split(" ");u.append(h,A.slice(1).join("")),u.append("country_code",A[0])}else h==="status"?n&&u.append("status",o[h]?`${q.Blocked}`:`${q.Active}`):u.append(h,o[h])}),u},d=async o=>{const u=g(o),{res:v,error:C}=await m({type:"POST",endpoint:n?`/admin/users/${n}?_method=PUT`:"/admin/users",body:u});if(C)return s(C);i({title:v.message,type:"success"}),r(b.vendors)},p=async()=>{var C,I;const{res:o,error:u}=await m({endpoint:`/admin/users/${n}`});if(u)return s(u);const v={owner_name:o.data.owner_name,email:o.data.email,mobile:`${o.data.country.code} ${o.data.mobile}`,image:(C=o.data.image)==null?void 0:C.path,status:o.data.status===q.Active?0:1};(I=t.current)==null||I.setValues(v)};return M({queryKey:[`/admin/users/${n}`],queryFn:p,options:{enabled:!!n}}),{defaultValues:ce,onSubmit:d,loading:x,formRef:t,t:a,id:n,passwordRef:c}},L=()=>{var m;const{t:n,defaultValues:a,onSubmit:r,loading:t,formRef:c,id:s,passwordRef:i}=de(),x=s?B.omit(["password","password_confirmation"]):B;return e.jsxs(e.Fragment,{children:[s&&e.jsx(se,{id:s,ref:i}),e.jsx(V,{ref:c,defaultValues:a,onSubmit:r,schema:x,children:e.jsx(f,{gap:4,children:e.jsxs(T,{children:[e.jsx(l,{item:!0,xl:2,xs:12,children:e.jsx(ne,{name:"image"})}),e.jsxs(l,{item:!0,container:!0,xs:12,xl:10,gap:2,children:[e.jsx(l,{item:!0,xs:12,children:e.jsx(_,{name:"owner_name",label:"owner_name"})}),e.jsx(l,{item:!0,xs:12,children:e.jsx(_,{name:"email",label:"email"})}),e.jsx(l,{item:!0,xs:12,children:e.jsx(ee,{name:"mobile",label:"mobile"})}),!s&&e.jsxs(e.Fragment,{children:[e.jsx(l,{item:!0,xs:12,children:e.jsx(H,{name:"password",label:"password"})}),e.jsx(l,{item:!0,xs:12,children:e.jsx(H,{name:"password_confirmation",label:"confirm_password"})})]}),s&&e.jsxs(f,{gap:2,children:[e.jsxs(f,{direction:"row",alignItems:"center",gap:2,children:[e.jsx(R,{color:"error",children:n("label.is_blocked")}),e.jsx(te,{name:"status"})]}),e.jsx(y,{onClick:(m=i.current)==null?void 0:m.openDialog,children:"change_password"})]})]}),e.jsx(l,{item:!0,xs:12,mt:1,children:e.jsxs(f,{direction:"row",justifyContent:"flex-end",flexWrap:"wrap",gap:2,children:[e.jsx($,{to:b.vendors,children:e.jsx(y,{variant:"contained",color:"secondary",children:"cancel"})}),e.jsx(y,{loading:t,variant:"contained",color:"primary",type:"submit",children:"submit"})]})})]})})})]})},me=["branch_name","mobile","location","city","governorate","actions"],ue=()=>{const{id:n}=D(),{t:a}=P(),r=O(),t=w.useRef(null),{requestHandlers:c}=S(),{handleError:s,fireToast:i}=F(),x=G({mutationFn:async m=>{var p;const{res:g,error:d}=await c({type:"DELETE",endpoint:`admin/branches/${m}`});if(d)return s(d);i({type:"success",title:g.message}),(p=t.current)==null||p.closeDialog()},onSuccess:()=>{r.invalidateQueries(["admin/branches"])}});return{t:a,headers:me,dialogRef:t,mutation:x,id:n}},pe=()=>{const{dialogRef:n,mutation:a,headers:r,id:t,t:c}=ue();return e.jsxs(T,{children:[e.jsx(Q,{ref:n,submit:a.mutate,loading:a.isPending,children:e.jsxs(f,{alignItems:"center",gap:2,children:[e.jsx("img",{src:z,width:48,alt:"delete"}),e.jsx(R,{variant:"subtitle2",children:c("label.delete_branch_title")}),e.jsx(R,{variant:"body1",color:"#666666",children:c("label.delete_branch_description")})]})}),e.jsx(T.PaperTitle,{title:"branches_list_title",children:e.jsx($,{to:b.vendorBranchesCreate.replace(":id",`${t}`),children:e.jsx(y,{variant:"contained",endIcon:e.jsx(N,{size:20}),children:"add"})})}),e.jsx(K,{reqName:`admin/branches?user_id=${t}`,headers:r,render:({item:s})=>e.jsxs(e.Fragment,{children:[e.jsx(j,{children:s.name}),e.jsx(j,{sx:{direction:"ltr"},children:`${s.country_code} ${s.mobile}`}),e.jsx(j,{children:s.location}),e.jsx(j,{children:s.city.name}),e.jsx(j,{children:s.governorate.name}),e.jsxs(J,{children:[e.jsx($,{to:`${b.vendorBranchesEdit.replace(":id",`${t}`).replace(":branchId",`${s.id}`)}`,children:e.jsx(X,{})}),e.jsx(Y,{onClick:()=>{var i;return(i=n.current)==null?void 0:i.openDialog(s.id)}})]})]})})]})},xe=["name","email","vendor_name","branch","role_name","actions"],he=()=>{const{id:n}=D(),{t:a}=P(),r=O(),t=w.useRef(null),{requestHandlers:c}=S(),{handleError:s,fireToast:i}=F(),x=G({mutationFn:async m=>{var p;const{res:g,error:d}=await c({type:"DELETE",endpoint:`admin/employees/${m}`});if(d)return s(d);i({type:"success",title:g.message}),(p=t.current)==null||p.closeDialog()},onSuccess:()=>{r.invalidateQueries([`admin/employees?user_id=${n}`])}});return{t:a,headers:xe,dialogRef:t,mutation:x,id:n}},je=()=>{const{dialogRef:n,mutation:a,headers:r,id:t,t:c}=he();return e.jsxs(T,{children:[e.jsx(Q,{ref:n,submit:a.mutate,loading:a.isPending,children:e.jsxs(f,{alignItems:"center",gap:2,children:[e.jsx("img",{src:z,width:48,alt:"delete"}),e.jsx(R,{variant:"subtitle2",children:c("label.delete_employee_title")}),e.jsx(R,{variant:"body1",color:"#666666",children:c("label.delete_employee_description")})]})}),e.jsx(T.PaperTitle,{title:"employees_list_title",children:e.jsx($,{to:b.vendorEmployeesCreate.replace(":id",`${t}`),children:e.jsx(y,{variant:"contained",endIcon:e.jsx(N,{size:20}),children:"add"})})}),e.jsx(K,{reqName:`admin/employees?user_id=${t}`,headers:r,render:({item:s})=>{var i,x;return e.jsxs(e.Fragment,{children:[e.jsx(j,{children:s.owner_name}),e.jsx(j,{children:s.email}),e.jsx(j,{children:(i=s.vendor)==null?void 0:i.owner_name}),e.jsx(j,{children:(x=s.branch)==null?void 0:x.name}),e.jsx(j,{children:s.role_name}),e.jsxs(J,{children:[e.jsx($,{to:`${b.vendorEmployeesEdit.replace(":id",`${t}`).replace(":employeeId",`${s.id}`)}`,children:e.jsx(X,{})}),e.jsx(Y,{onClick:()=>{var m;return(m=n.current)==null?void 0:m.openDialog(s.id)}})]})]})}})]})},fe={target_type:"user",notification_type:"",body:"",user_id:""},be=()=>{const{id:n}=D(),a=k(),r=w.useRef(),{handleError:t,fireToast:c}=F(),{loading:s,requestHandlers:i}=S();return{defaultValues:fe,onSubmit:async m=>{m.user_id=`${n}`;const{res:g,error:d}=await i({type:"POST",endpoint:"/admin/send-notifications",body:m});if(d)return t(d);c({title:g.message,type:"success"}),a(b.vendors)},loading:s,formRef:r}},ge=()=>{const{defaultValues:n,onSubmit:a,loading:r,formRef:t}=be();return e.jsx(V,{ref:t,defaultValues:n,onSubmit:a,schema:U,children:e.jsx(f,{gap:4,children:e.jsxs(T,{children:[e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"notification_type",label:"title"})}),e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(_,{name:"body",label:"body"})}),e.jsx(l,{item:!0,xs:12,mt:1,children:e.jsxs(f,{direction:"row",justifyContent:"flex-end",flexWrap:"wrap",gap:2,children:[e.jsx($,{to:b.vendors,children:e.jsx(y,{variant:"contained",color:"secondary",children:"cancel"})}),e.jsx(y,{loading:r,variant:"contained",color:"primary",type:"submit",children:"send"})]})})]})})})},_e=()=>{const{id:n}=D(),{t:a}=P(),[r,t]=w.useState(1),c=(s,i)=>{t(i)};return e.jsx(re,{sx:{width:"100%",typography:"body1"},children:n?e.jsxs(l,{container:!0,gap:2,children:[e.jsx(l,{item:!0,xs:12,children:e.jsxs(ae,{textColor:"primary",value:r,onChange:c,variant:"scrollable",children:[e.jsx(E,{label:a("label.personal_info"),value:1}),e.jsx(E,{label:a("label.bank_info"),value:2}),e.jsx(E,{label:a("label.branches"),value:3}),e.jsx(E,{label:a("label.employees"),value:4}),e.jsx(E,{label:a("label.send_notification"),value:5})]})}),e.jsx(l,{item:!0,xs:12,children:e.jsxs(W,{children:[r===1&&e.jsx(L,{}),r===2&&e.jsx(le,{}),r===3&&e.jsx(pe,{}),r===4&&e.jsx(je,{}),r===5&&e.jsx(ge,{})]},r)})]}):e.jsx(L,{})})},xn=()=>e.jsxs(W,{children:[e.jsx(Z,{title:"vendors"}),e.jsx(_e,{})]});export{xn as default};