import{c as C,l as E,b4 as v,r as i,a as j,nr as M,h as w,np as z,j as e,I,J as F,B as q,bA as B,T as L,K as o,ao as V,ap as Y,y as $,E as b,nt as R,nw as U,nz as J,nA as K}from"./index-aa586041.js";import{u as N}from"./index.esm-c1bef48d.js";import{o as W}from"./yup-75085264.js";import{c as A,b as D}from"./index.esm-5d8102a7.js";import{S}from"./SelectComponent-aad66251.js";import{F as X}from"./FormInput-7412b024.js";import{T as H}from"./TextArea-1d2de9d0.js";import{D as O}from"./Dialog-26aea2b0.js";import{D as Q}from"./DialogTitle-35e72887.js";import{D as Z}from"./DialogContent-5a256860.js";import{D as ee}from"./DialogContentText-ab749083.js";import{D as se}from"./DialogActions-90af69f6.js";import"./objectSpread2-e05f2ee3.js";import"./defineProperty-83f36300.js";import"./toPropertyKey-d8419463.js";import"./typeof-7fd5df1e.js";import"./slicedToArray-f5e6f6d2.js";import"./floating-ui.dom-cd6c919d.js";import"./InputLabel-fa135afd.js";import"./useFormControl-1a7e7d92.js";import"./FormControlLabel-ab2ab32c.js";import"./Checkbox-da19fcfe.js";import"./SwitchBase-8c9d77fa.js";import"./useControlled-e0c526ba.js";import"./createSvgIcon-26e7576d.js";import"./OutlinedInput-8f0d0162.js";import"./isHostComponent-73d6e646.js";import"./TextField-5fe8ef1a.js";import"./FormControl-fed32f2b.js";import"./Select-03e2ed06.js";import"./Menu-3823c2ca.js";import"./Grow-6aaee206.js";import"./List-d99f3a17.js";import"./useSlotProps-01ed14c0.js";const Le=()=>{const r=C();E();const{id:u}=v(),[g,ae]=i.useState([]);i.useState([]),j(M),j(w);const{GeneralTask:{selectedData:s,pageParams:T,isModelVisible:k,loading:_},mini:{miniAssetEssentials:te,miniAsset:t},system:{userAccessList:ie}}=z(),n=()=>{r(R({})),x(),r(U(!1))},y=A().shape({asset:A().shape({label:D().required("Please select a Asset"),value:D().required("Please select a Asset")})}),d=s==null?void 0:s.id;i.useEffect(()=>{console.log("seelctedData output:",s)},[s]);const{control:l,handleSubmit:P,reset:x,setValue:m,formState:{errors:h}}=N({resolver:W(y)});i.useEffect(()=>{console.log("selectedData:",s)},[]),i.useEffect(()=>{s&&s.id&&(m("asset",s!=null&&s.asset?{label:s.asset.name,value:s.asset.id}:null),m("description",s.description),m("due_date",s.due_date))},[s,x,m]),i.useEffect(()=>{console.log(" Validation Errors:",h)},[h]);const G=a=>{var f;console.log("Submitted Data:",a),console.log("on submit triggered:");const c={asset_id:a.asset.value,description:a.description,due_date:a.due_date};a.status&&(c.status=(f=a.status)==null?void 0:f.id),console.log("attached image:",g);const p={obj:c,image:g,id:d,pageParams:T,clearDataFn:()=>{n()}};console.log("images has been attached:",p.image),r(u&&u!=="0"?J(p):K(p))};return e.jsx(e.Fragment,{children:e.jsxs(O,{open:k,onClose:(a,c)=>{c!=="backdropClick"&&n()},"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(Q,{sx:{bgcolor:"success.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[d?"Update ":"Add ","General Task",e.jsx(I,{onClick:n,children:e.jsx(F,{color:"white"})})]}),e.jsx(Z,{sx:{px:"24px",pt:"12px !important",pb:0},children:_?e.jsxs(q,{children:[e.jsx(B,{}),e.jsx(L,{textAlign:"center",children:"Loading..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{id:"alert-dialog-description",sx:{width:500}}),e.jsxs("form",{onSubmit:P(G),children:[e.jsxs(o,{container:!0,spacing:2,children:[e.jsx(o,{size:{xs:12,md:6},children:e.jsx(S,{name:"asset",label:"Asset ",placeholder:"Select Asset",control:l,options:t==null?void 0:t.list.map(a=>({id:a.id,name:`${a.name}(${a.code})`})),required:!0,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:V,clearData:Y})}),e.jsx(o,{size:{xs:12,md:6},children:e.jsx(X,{required:!0,name:"due_date",label:"Due Date",type:"date",placeholder:"Enter date here...",control:l,inputProps:{min:$().format("YYYY-MM-DD")}})}),e.jsx(o,{size:{xs:12,md:6},children:(s==null?void 0:s.id)&&e.jsx(S,{name:"status",label:"Status",control:l,rules:{required:!0},options:[{id:1,name:"Pending"},{id:2,name:"Completed"}]})}),e.jsx(o,{size:{xs:12},children:e.jsx(H,{name:"description",label:"Description",type:"text",placeholder:"Write Description here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:l})})]}),e.jsxs(se,{sx:{p:3,pr:0},children:[e.jsx(b,{variant:"outlined",color:"success",onClick:n,children:"Cancel"}),e.jsx(b,{variant:"contained",color:"success",type:"submit",sx:{ml:2},children:d?"Update GeneralTask":"Add GeneralTask"})]})]})]})})]})})};export{Le as default};
