import{b as Q,a as R,g as W,vR as Y,eu as Z,j as o,I as $,ef as V,P as n,ae as L,af as ee,f7 as re,ji as ae,aU as oe,aV as se,J as p,uT as ie,vS as le,vT as d,vU as ne}from"./index-d2b25495.js";import{c as u,b as t}from"./index.esm-3043d6d4.js";import{o as te}from"./yup-267e586f.js";import{u as me}from"./index.esm-ce3c2c20.js";import{S as G}from"./SelectComponent-d286bfef.js";import{D as ce,a as pe}from"./DialogContent-cded694d.js";import{D as de}from"./DialogTitle-a145b392.js";import{D as ue}from"./DialogContentText-43575e44.js";import{T as ge}from"./Tooltip-82372cdb.js";import{D as he}from"./DialogActions-7c802cc8.js";const qe=()=>{var x,v,j,b,f,P,_,y,S,C,M,q,z,A,w,F,T,k;const J="VendorItem",i=Q(),{vendorItem:{selectedData:r,model:N,pageParams:g},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:h,handleSubmit:X,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}}),D=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:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:K=>{}};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:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:K=>{}};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 ",J,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:X(D),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:h,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(ge,{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:h,required:!0,options:(q=a==null?void 0:a.list)==null?void 0:q.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:(z=a==null?void 0:a.miniParams)==null?void 0:z.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(he,{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{qe as A};
