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-5768b108.js";import{c as f,a as R,b as d}from"./index.esm-85e2fec5.js";import{o as V}from"./yup-7ddf262a.js";import{u as U}from"./index.esm-4803c918.js";import"./CustomDatepicker-c97efda4.js";import{F as g}from"./FormInput-be88fa2a.js";import"./index-42cce9d5.js";import"./ScrollableList-c8e84a4e.js";import"./SectionDivider-bc494fef.js";import{S as W}from"./SelectComponent-f4c81d57.js";import{T as G}from"./TextArea-286cc2d2.js";import{D as J}from"./Dialog-82ae8e2c.js";import{D as K}from"./DialogTitle-399fe93b.js";import{D as X}from"./DialogContent-281dc416.js";import{D as H}from"./DialogContentText-28299755.js";import{D as N}from"./DialogActions-96d02ef8.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};
