import{c as C,b4 as P,a as h,aW as A,hh 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,hm as $,hn as B,qi as L,qj as Q}from"./index-55b8aeb0.js";import{c as f,a as R,b as d}from"./index.esm-8f37a121.js";import{o as V}from"./yup-21078b88.js";import{u as U}from"./index.esm-31587b9b.js";import"./CustomDatepicker-9892b2ee.js";import{F as g}from"./FormInput-6413815f.js";import"./index-7c560a47.js";import"./ScrollableList-a069ff95.js";import"./SectionDivider-0fcc86df.js";import{S as W}from"./SelectComponent-2bce8639.js";import{T as G}from"./TextArea-c15d3047.js";import{D as J}from"./Dialog-5977b5ec.js";import{D as K}from"./DialogTitle-37cbd0b5.js";import{D as X}from"./DialogContent-c61b109b.js";import{D as H}from"./DialogContentText-766272a6.js";import{D as N}from"./DialogActions-57cb8efb.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};
