import{b as J,a as E,h as W,vM as Y,er as Z,j as o,I as N,ec as V,Q as n,ae as L,af as ee,f3 as re,jd as ae,aU as oe,aV as se,K as p,uO as ie,vN as le,vO as d,vP as ne}from"./index-76d4793e.js";import{c as u,b as t}from"./index.esm-ad8a7c9f.js";import{o as te}from"./yup-688ec4f6.js";import{u as me}from"./index.esm-3adfd9f7.js";import{S as $}from"./SelectComponent-3c1140e6.js";import{D as ce,a as pe}from"./DialogContent-7bd8dd8f.js";import{D as de}from"./DialogTitle-71dd5b3a.js";import{D as ue}from"./DialogContentText-7642f81f.js";import{T as he}from"./Tooltip-0a59b9eb.js";import{D as ge}from"./DialogActions-5a5e1db9.js";const qe=()=>{var x,v,j,b,f,P,_,y,S,C,M,q,z,A,w,F,k,I;const G="VendorItem",i=J(),{vendorItem:{selectedData:r,model:K,pageParams:h},system:{userAccessList:xe}}=E(e=>({system:W(e),vendorItem:Y(e)})),{miniItemsList:s,miniVendors:a}=E(e=>Z(e)),l=()=>{i(ie(!1))},Q=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:R,reset:m}=me({resolver:te(Q),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 T,O,U,B;if(r!=null&&r.id){const c={obj:{id:r==null?void 0:r.id,item_id:(U=e==null?void 0:e.item)==null?void 0:U.value,vendor_id:(B=e==null?void 0:e.vendor)==null?void 0:B.value},pageParams:h,clearDataFn:()=>{l(),m(),i(d({}))},navigate:H=>{}};i(ne(c))}else{const c={obj:{item_id:(T=e==null?void 0:e.item)==null?void 0:T.value,vendor_id:(O=e==null?void 0:e.vendor)==null?void 0:O.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:K,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 ",G,o.jsx(N,{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:R(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($,{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(N,{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($,{name:"vendor",label:"Vendor/OEM",control:g,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:((k=a==null?void 0:a.miniParams)==null?void 0:k.page)<((I=a==null?void 0:a.miniParams)==null?void 0:I.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{qe as A};
