import{c as C,b4 as P,a as h,aW as A,hg as D,r as I,j as e,I as k,J as E,B as F,bA as M,T as w,K as r,am as z,an as T,E as c,hl as $,hm as B,qh as L,qi as Q}from"./index-c910e189.js";import{c as f,a as R,b as d}from"./index.esm-4b824583.js";import{o as V}from"./yup-e6171339.js";import{u as U}from"./index.esm-cb7a914e.js";import"./CustomDatepicker-fa2ab383.js";import{F as g}from"./FormInput-a4f22564.js";import"./index-f58a077c.js";import"./ScrollableList-4f192da2.js";import"./SectionDivider-782acfa4.js";import{S as W}from"./SelectComponent-34494e1c.js";import{T as G}from"./TextArea-173e49c2.js";import{D as J}from"./Dialog-a2882bbb.js";import{D as K}from"./DialogTitle-9a53d260.js";import{D as X}from"./DialogContent-589114d5.js";import{D as H}from"./DialogContentText-1b4ebcf7.js";import{D as N}from"./DialogActions-d05865c7.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($({})),n(B(!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};
