import{c as C,b5 as P,a as h,aW as A,hi as D,r as I,j as e,I as k,J as E,B as F,bB as M,T as w,K as r,am as z,an as T,E as c,hn as B,ho as $,ql as L,qm as Q}from"./index-7d3dbb9c.js";import{c as f,a as R,b as d}from"./index.esm-9d396c5f.js";import{o as V}from"./yup-55e79238.js";import{u as U}from"./index.esm-12cc9f7b.js";import"./CustomDatepicker-6d5ad1ab.js";import{F as g}from"./FormInput-602ae51d.js";import"./index-b5c17d61.js";import"./ScrollableList-ffeab0b0.js";import"./SectionDivider-be0a23cf.js";import{S as W}from"./SelectComponent-b1bc4bdd.js";import{T as G}from"./TextArea-4d76f175.js";import{D as J}from"./Dialog-d125aee1.js";import{D as K}from"./DialogTitle-a3176c12.js";import{D as X}from"./DialogContent-d34f4ba4.js";import{D as H}from"./DialogContentText-9128b573.js";import{D as N}from"./DialogActions-99629c3a.js";const he=({selectedAssetId:b})=>{const n=C();P();const{miniItemsList:t,miniAsset:O}=h(A),{selectedData:a,loading:y,isModelVisible:j,pageParams:_}=h(i=>D(i)),o=()=>{n(B({})),n($(!1)),m({part_name:null,description:"",life_span:"",quantity:""})},l=a==null?void 0:a.id,S=f().shape({quantity:R().typeError("Quantity must be a number").positive("Quantity must be greater than 0"),life_span:d().notRequired(),part_name:f().shape({label:d().required("Please select an item"),value:d().required("Please select an item")})}),{control:p,handleSubmit:q,setValue:s,reset:m,formState:{errors:Y}}=U({resolver:V(S)});I.useEffect(()=>{a&&a.id?(s("life_span",a==null?void 0:a.life_span),s("quantity",a==null?void 0:a.quantity),s("part_name",a!=null&&a.item?{label:a.item.value,value:a.item.label}:null),s("description",(a==null?void 0:a.description)??"")):m({part_name:null,description:"",life_span:"",quantity:""})},[a,m,s]);const v=i=>{console.log("onsubmmit is being triggered");const x={formData:{description:i.description,quantity:i.quantity,life_span:i.life_span,item_id:i.part_name.value,asset_id:b||""},id:l??void 0,pageParams:_,clearDataFn:()=>{o()}};n(l?Q(x):L(x))};return e.jsx(e.Fragment,{children:e.jsxs(J,{open:j,onClose:(i,u)=>{u!=="backdropClick"&&o()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(K,{sx:{bgcolor:"",color:"black",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[l?"Update ":"Add ","Spare",e.jsx(k,{onClick:o,children:e.jsx(E,{color:"black"})})]}),e.jsx(X,{sx:{px:"24px",pt:"12px !important",pb:0,backgroundColor:"transparent",boxShadow:"none"},children:y?e.jsxs(F,{children:[e.jsx(M,{}),e.jsx(w,{textAlign:"center",children:"Loading..."})]}):e.jsx(H,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:q(v),children:[e.jsxs(r,{container:!0,spacing:2,children:[e.jsx(r,{size:{xs:12},children:e.jsx(W,{required:!0,name:"part_name",label:"Spare",control:p,rules:{required:!0},options:t==null?void 0:t.list.map(i=>({id:i.id,name:`${i.name}(${i.code})`})),loading:t.loading,selectParams:{page:t.miniParams.page,page_size:t.miniParams.page_size,search:t.miniParams.search,no_of_pages:t.miniParams.no_of_pages},hasMore:t.miniParams.page<t.miniParams.no_of_pages,fetchapi:z,clearData:T})}),e.jsx(r,{size:{xs:12},children:e.jsx(g,{required:!0,name:"quantity",label:"Quantity",type:"text",placeholder:"Enter Quantity here...",control:p})}),e.jsx(r,{size:{xs:12},children:e.jsx(g,{name:"life_span",label:"Life Span(months)",type:"text",placeholder:"Enter LifeSpan here...",control:p})}),e.jsx(r,{size:{xs:12},children:e.jsx(G,{name:"description",label:"Description",type:"text",placeholder:"Write Description here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:p})})]}),e.jsxs(N,{sx:{p:3,display:"flex",justifyContent:"flex-end",pr:0},children:[e.jsx(c,{onClick:o,variant:"outlined",color:"secondary",children:"Cancel"}),l?e.jsx(c,{variant:"contained",type:"submit",color:"success",autoFocus:!0,children:"Update"}):e.jsx(c,{variant:"contained",type:"submit",color:"success",autoFocus:!0,children:"Submit"})]})]})})})]})})};export{he as A};
