import{d as H,a as G,b as K,oB as O,aM as Q,j as s,I as W,ax as V,Y as L,Z as ee,nJ as ae,_ as oe,$ as re,z as p,n1 as se,oC as ie,oD as d,oE as le}from"./index-4dfc510b.js";import{c as u,b as t,u as ne}from"./index.esm-0a454763.js";import{o as te}from"./yup-80def618.js";import{S as T}from"./SelectComponent-bfde3322.js";import{D as me,a as ce}from"./DialogContent-3bf4ff27.js";import{D as pe}from"./DialogTitle-248b1818.js";import{D as de}from"./DialogContentText-a6ab23a2.js";import{G as U}from"./Grid2-713975b3.js";import{D as ue}from"./DialogActions-49286e71.js";const Se=()=>{var x,v,b,f,j,P,_,y,S,C,M,q,z,A,F,w,k,B;const D="VendorItem",i=H(),{vendorItem:{selectedData:a,model:J,pageParams:g},system:{userAccessList:ge}}=G(e=>({system:K(e),vendorItem:O(e)})),{miniItemsList:r,miniVendors:o}=G(e=>Q(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:R,reset:m}=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}}),X=e=>{var n,I,$,E;if(a!=null&&a.id){const c={obj:{id:a==null?void 0:a.id,item_id:($=e==null?void 0:e.item)==null?void 0:$.value,vendor_id:(E=e==null?void 0:e.vendor)==null?void 0:E.value},pageParams:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:Z=>{}};i(le(c))}else{const c={obj:{item_id:(n=e==null?void 0:e.item)==null?void 0:n.value,vendor_id:(I=e==null?void 0:e.vendor)==null?void 0:I.value},pageParams:g,clearDataFn:()=>{l(),m(),i(d({}))},navigate:Z=>{}};i(ie(c)),l(),i(d({})),m()}};return s.jsx(s.Fragment,{children:s.jsxs(me,{open:J,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 ",D,s.jsx(W,{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:R(X),children:[s.jsx(U,{size:{xs:12,md:4},mt:0,children:s.jsx(T,{name:"item",label:"Item",control:h,options:(j=r.list)==null?void 0:j.map(e=>({id:e.id,name:e.name})),required:!0,loading:r.loading,selectParams:{page:(P=r==null?void 0:r.miniParams)==null?void 0:P.page,page_size:(_=r==null?void 0:r.miniParams)==null?void 0:_.page_size,search:(y=r==null?void 0:r.miniParams)==null?void 0:y.search,no_of_pages:(S=r==null?void 0:r.miniParams)==null?void 0:S.no_of_pages},hasMore:((C=r==null?void 0:r.miniParams)==null?void 0:C.page)<((M=r==null?void 0:r.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=o==null?void 0:o.list)==null?void 0:q.map(e=>({id:e.id,name:e.name})),loading:o==null?void 0:o.loading,onChange:e=>{i(ae(e==null?void 0:e.value))},selectParams:{page:(z=o==null?void 0:o.miniParams)==null?void 0:z.page,page_size:(A=o==null?void 0:o.miniParams)==null?void 0:A.page_size,search:(F=o==null?void 0:o.miniParams)==null?void 0:F.search,no_of_pages:(w=o==null?void 0:o.miniParams)==null?void 0:w.no_of_pages},hasMore:((k=o==null?void 0:o.miniParams)==null?void 0:k.page)<((B=o==null?void 0:o.miniParams)==null?void 0:B.no_of_pages),fetchapi:oe,clearData:re})}),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{Se as A};
