import{d as H,a as T,b as J,qW as K,a_ as O,j as s,I as Q,aL as V,ab as L,ac as ee,q0 as ae,ad as re,ae as oe,R as p,ps as se,qX as ie,qY as d,qZ as le}from"./index-e79f7aad.js";import{c as u,b as t,u as ne}from"./index.esm-1ca67d65.js";import{o as te}from"./yup-96f14780.js";import{S as U}from"./SelectComponent-1ba596ac.js";import{D as me,a as ce}from"./DialogContent-6a297cef.js";import{D as pe}from"./DialogTitle-62595023.js";import{D as de}from"./DialogContentText-0c5306f9.js";import{G as X}from"./Grid2-7786e458.js";import{D as ue}from"./DialogActions-edd1d02f.js";const qe=()=>{var v,x,b,f,j,P,_,y,q,S,C,M,A,z,F,w,k,I;const $="VendorItem",i=H(),{vendorItem:{selectedData:a,model:E,pageParams:g},system:{userAccessList:ge}}=T(e=>({system:J(e),vendorItem:K(e)})),{miniItemsList:o,miniVendors:r}=T(e=>O(e)),l=()=>{i(se(!1))},N=u().shape({item:u().shape({label:t().required("Please select item"),value:t().required("Please select item")}).required("Please select item"),vendor:u().shape({label:t().required("Please select vendor"),value:t().required("Please select vendor")}).required("Please select vendor")}),{control:h,handleSubmit:W,reset:m}=ne({resolver:te(N),values:{item:a!=null&&a.item?{label:(v=a==null?void 0:a.item)==null?void 0:v.name,value:(x=a==null?void 0:a.item)==null?void 0:x.id}:null,vendor:a!=null&&a.vendor?{label:(b=a.vendor)==null?void 0:b.name,value:(f=a.vendor)==null?void 0:f.id}:null}}),Y=e=>{var n,B,G,R;if(a!=null&&a.id){const c={obj:{id:a==null?void 0:a.id,item_id:(G=e==null?void 0:e.item)==null?void 0:G.value,vendor_id:(R=e==null?void 0:e.vendor)==null?void 0:R.value},pageParams:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:D=>{}};i(le(c))}else{const c={obj:{item_id:(n=e==null?void 0:e.item)==null?void 0:n.value,vendor_id:(B=e==null?void 0:e.vendor)==null?void 0:B.value},pageParams:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:D=>{}};i(ie(c)),l(),i(d({})),m()}};return s.jsx(s.Fragment,{children:s.jsxs(me,{open:E,onClose:(e,n)=>{n!=="backdropClick"&&l()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[s.jsxs(pe,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[a!=null&&a.id?"Update ":"Add ",$,s.jsx(Q,{onClick:l,children:s.jsx(V,{color:"white"})})]}),s.jsx(ce,{sx:{px:"24px",pt:"12px !important",pb:0},children:s.jsx(de,{id:"alert-dialog-description",sx:{width:500},children:s.jsxs("form",{style:{width:"100%"},onSubmit:W(Y),children:[s.jsx(X,{size:{xs:12,md:4},mt:0,children:s.jsx(U,{name:"item",label:"Item",control:h,options:(j=o.list)==null?void 0:j.map(e=>({id:e.id,name:e.name})),required:!0,loading:o.loading,selectParams:{page:(P=o==null?void 0:o.miniParams)==null?void 0:P.page,page_size:(_=o==null?void 0:o.miniParams)==null?void 0:_.page_size,search:(y=o==null?void 0:o.miniParams)==null?void 0:y.search,no_of_pages:(q=o==null?void 0:o.miniParams)==null?void 0:q.no_of_pages},hasMore:((S=o==null?void 0:o.miniParams)==null?void 0:S.page)<((C=o==null?void 0:o.miniParams)==null?void 0:C.no_of_pages),fetchapi:L,clearData:ee})}),s.jsx(X,{size:{xs:12,md:4},mt:2,children:s.jsx(U,{name:"vendor",label:"Vendor",control:h,required:!0,options:(M=r==null?void 0:r.list)==null?void 0:M.map(e=>({id:e.id,name:e.name})),loading:r==null?void 0:r.loading,onChange:e=>{i(ae(e==null?void 0:e.value))},selectParams:{page:(A=r==null?void 0:r.miniParams)==null?void 0:A.page,page_size:(z=r==null?void 0:r.miniParams)==null?void 0:z.page_size,search:(F=r==null?void 0:r.miniParams)==null?void 0:F.search,no_of_pages:(w=r==null?void 0:r.miniParams)==null?void 0:w.no_of_pages},hasMore:((k=r==null?void 0:r.miniParams)==null?void 0:k.page)<((I=r==null?void 0:r.miniParams)==null?void 0:I.no_of_pages),fetchapi:re,clearData:oe})}),s.jsxs(ue,{sx:{p:2},children:[s.jsx(p,{onClick:l,variant:"outlined",color:"secondary",children:"Cancel"}),a!=null&&a.id?s.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"}):s.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"})]})]})})})]})})};export{qe as A};
