import{b as J,a as R,h as W,vR as Y,ez as Z,j as o,I as $,ec as V,Q as n,ae as L,af as ee,fe as re,jp as ae,aU as oe,aV as se,K as p,uT as ie,vS as le,vT as d,vU as ne}from"./index-def636a4.js";import{c as u,b as t}from"./index.esm-eec4f448.js";import{o as te}from"./yup-c8535458.js";import{u as me}from"./index.esm-7d9d1491.js";import{S as G}from"./SelectComponent-cea9b89b.js";import{D as ce,a as pe}from"./DialogContent-0cb684b3.js";import{D as de}from"./DialogTitle-e2e75924.js";import{D as ue}from"./DialogContentText-b2259947.js";import{T as he}from"./Tooltip-762a58b6.js";import{D as ge}from"./DialogActions-c4045764.js";const ze=()=>{var x,v,j,b,f,P,_,y,S,C,M,z,q,A,w,F,T,k;const K="VendorItem",i=J(),{vendorItem:{selectedData:r,model:N,pageParams:h},system:{userAccessList:xe}}=R(e=>({system:W(e),vendorItem:Y(e)})),{miniItemsList:s,miniVendors:a}=R(e=>Z(e)),l=()=>{i(ie(!1))},O=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:g,handleSubmit:Q,reset:m}=me({resolver:te(O),values:{item:r!=null&&r.item?{label:(x=r==null?void 0:r.item)==null?void 0:x.name,value:(v=r==null?void 0:r.item)==null?void 0:v.id}:null,vendor:r!=null&&r.vendor?{label:(j=r.vendor)==null?void 0:j.name,value:(b=r.vendor)==null?void 0:b.id}:null}}),X=e=>{var I,U,B,E;if(r!=null&&r.id){const c={obj:{id:r==null?void 0:r.id,item_id:(B=e==null?void 0:e.item)==null?void 0:B.value,vendor_id:(E=e==null?void 0:e.vendor)==null?void 0:E.value},pageParams:h,clearDataFn:()=>{l(),m(),i(d({}))},navigate:H=>{}};i(ne(c))}else{const c={obj:{item_id:(I=e==null?void 0:e.item)==null?void 0:I.value,vendor_id:(U=e==null?void 0:e.vendor)==null?void 0:U.value},pageParams:h,clearDataFn:()=>{l(),m(),i(d({}))},navigate:H=>{}};i(le(c)),l(),i(d({})),m()}};return o.jsx(o.Fragment,{children:o.jsxs(ce,{open:N,onClose:l,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[o.jsxs(de,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[r!=null&&r.id?"Update ":"Add ",K,o.jsx($,{onClick:l,children:o.jsx(V,{color:"white"})})]}),o.jsx(pe,{sx:{px:"24px",pt:"12px !important",pb:0},children:o.jsx(ue,{id:"alert-dialog-description",sx:{width:500},children:o.jsxs("form",{style:{width:"100%"},onSubmit:Q(X),children:[o.jsx(n,{size:{xs:12,md:4},mt:0,children:o.jsxs(n,{container:!0,alignItems:"center",children:[o.jsx(n,{size:{xs:11},children:o.jsx(G,{name:"item",label:"Item",control:g,options:(f=s.list)==null?void 0:f.map(e=>({id:e.id,name:e.name})),required:!0,loading:s.loading,selectParams:{page:(P=s==null?void 0:s.miniParams)==null?void 0:P.page,page_size:(_=s==null?void 0:s.miniParams)==null?void 0:_.page_size,search:(y=s==null?void 0:s.miniParams)==null?void 0:y.search,no_of_pages:(S=s==null?void 0:s.miniParams)==null?void 0:S.no_of_pages},hasMore:((C=s==null?void 0:s.miniParams)==null?void 0:C.page)<((M=s==null?void 0:s.miniParams)==null?void 0:M.no_of_pages),fetchapi:L,clearData:ee})}),o.jsx(n,{size:{xs:1},mt:3,children:o.jsx(he,{title:"Add Customer",children:o.jsx($,{onClick:()=>{window.open("/pages/masters/item/add/","_blank")},children:o.jsx(re,{})})})})]})}),o.jsx(n,{size:{xs:12,md:4},mt:2,children:o.jsx(G,{name:"vendor",label:"Vendor/OEM",control:g,required:!0,options:(z=a==null?void 0:a.list)==null?void 0:z.map(e=>({id:e.id,name:e.name})),loading:a==null?void 0:a.loading,onChange:e=>{i(ae(e==null?void 0:e.value))},selectParams:{page:(q=a==null?void 0:a.miniParams)==null?void 0:q.page,page_size:(A=a==null?void 0:a.miniParams)==null?void 0:A.page_size,search:(w=a==null?void 0:a.miniParams)==null?void 0:w.search,no_of_pages:(F=a==null?void 0:a.miniParams)==null?void 0:F.no_of_pages},hasMore:((T=a==null?void 0:a.miniParams)==null?void 0:T.page)<((k=a==null?void 0:a.miniParams)==null?void 0:k.no_of_pages),fetchapi:oe,clearData:se})}),o.jsxs(ge,{sx:{p:2},children:[o.jsx(p,{onClick:l,variant:"outlined",color:"secondary",children:"Cancel"}),r!=null&&r.id?o.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"}):o.jsx(p,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"})]})]})})})]})})};export{ze as A};
