import{d as J,a as R,b as O,pw as Q,aZ as W,j as s,I as Y,aK as V,ab as L,ac as ee,oE as ae,ad as re,ae as oe,R as c,o4 as se,px as ie,py as d,pz as le}from"./index-6c48ebe4.js";import{c as u,b as t,u as ne}from"./index.esm-fd3369ba.js";import{o as te}from"./yup-75ac0470.js";import{S as T}from"./SelectComponent-a742bcde.js";import{D as pe,a as me}from"./DialogContent-2975c76a.js";import{D as ce}from"./DialogTitle-6235c46a.js";import{D as de}from"./DialogContentText-928ca488.js";import{G as U}from"./Grid2-70d79e93.js";import{D as ue}from"./DialogActions-aa83bc6c.js";const Se=()=>{var x,v,b,f,j,P,_,y,S,C,M,q,z,A,w,F,k,I;const $="VendorItem",i=J(),{vendorItem:{selectedData:a,model:K,pageParams:g},system:{userAccessList:ge}}=R(e=>({system:O(e),vendorItem:Q(e)})),{miniItemsList:o,miniVendors:r}=R(e=>W(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:X,reset:p}=ne({resolver:te(N),values:{item:a!=null&&a.item?{label:(x=a==null?void 0:a.item)==null?void 0:x.name,value:(v=a==null?void 0:a.item)==null?void 0:v.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}}),Z=e=>{var n,B,E,G;if(a!=null&&a.id){const m={obj:{id:a==null?void 0:a.id,item_id:(E=e==null?void 0:e.item)==null?void 0:E.value,vendor_id:(G=e==null?void 0:e.vendor)==null?void 0:G.value},pageParams:g,clearDataFn:()=>{l(),p(),i(d({}))},navigate:H=>{}};i(le(m))}else{const m={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(),p(),i(d({}))},navigate:H=>{}};i(ie(m)),l(),i(d({})),p()}};return s.jsx(s.Fragment,{children:s.jsxs(pe,{open:K,onClose:(e,n)=>{n!=="backdropClick"&&l()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[s.jsxs(ce,{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(Y,{onClick:l,children:s.jsx(V,{color:"white"})})]}),s.jsx(me,{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:X(Z),children:[s.jsx(U,{size:{xs:12,md:4},mt:0,children:s.jsx(T,{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:(S=o==null?void 0:o.miniParams)==null?void 0:S.no_of_pages},hasMore:((C=o==null?void 0:o.miniParams)==null?void 0:C.page)<((M=o==null?void 0:o.miniParams)==null?void 0:M.no_of_pages),fetchapi:L,clearData:ee})}),s.jsx(U,{size:{xs:12,md:4},mt:2,children:s.jsx(T,{name:"vendor",label:"Vendor",control:h,required:!0,options:(q=r==null?void 0:r.list)==null?void 0:q.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:(z=r==null?void 0:r.miniParams)==null?void 0:z.page,page_size:(A=r==null?void 0:r.miniParams)==null?void 0:A.page_size,search:(w=r==null?void 0:r.miniParams)==null?void 0:w.search,no_of_pages:(F=r==null?void 0:r.miniParams)==null?void 0:F.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(c,{onClick:l,variant:"outlined",color:"secondary",children:"Cancel"}),a!=null&&a.id?s.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"}):s.jsx(c,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"})]})]})})})]})})};export{Se as A};
