import{c as G,l as v,b5 as C,r as i,a as j,nv as M,h as I,nt as w,j as e,I as z,J as F,B as q,bB as B,T as L,K as o,ao as V,ap as Y,y as $,E as b,nx as R,nA as U,nD as J,nE as K}from"./index-d9e0bbb9.js";import{u as N}from"./index.esm-97139da9.js";import{o as W}from"./yup-267c2267.js";import{c as D,b as S}from"./index.esm-65c50bc3.js";import{S as A}from"./SelectComponent-0a507d7b.js";import{F as X}from"./FormInput-44ad439a.js";import{T as H}from"./TextArea-18d8079e.js";import{D as O}from"./Dialog-ef39ad8f.js";import{D as Q}from"./DialogTitle-60c6eefe.js";import{D as Z}from"./DialogContent-4a855a79.js";import{D as ee}from"./DialogContentText-b49b6920.js";import{D as se}from"./DialogActions-2abea93f.js";import"./objectSpread2-7f959c25.js";import"./toPropertyKey-720374c3.js";import"./floating-ui.dom-cd6c919d.js";import"./InputLabel-8c8abfdd.js";import"./useFormControl-8bb67ca0.js";import"./Checkbox-74feb846.js";import"./SwitchBase-8b88dd2c.js";import"./useControlled-ba6710bb.js";import"./createSvgIcon-c99d086f.js";import"./FormControlLabel-685586a9.js";import"./OutlinedInput-8f17518b.js";import"./isHostComponent-73d6e646.js";import"./TextField-14942967.js";import"./FormControl-664346ce.js";import"./Select-661ba76b.js";import"./Menu-c23c1491.js";import"./Grow-ca477235.js";import"./List-c3ed6b04.js";import"./useSlotProps-a7d9b3b8.js";const Fe=()=>{const r=G();v();const{id:u}=C(),[x,ae]=i.useState([]);i.useState([]),j(M),j(I);const{GeneralTask:{selectedData:s,pageParams:T,isModelVisible:k,loading:_},mini:{miniAssetEssentials:te,miniAsset:t},system:{userAccessList:ie}}=w(),n=()=>{r(R({})),g(),r(U(!1))},y=D().shape({asset:D().shape({label:S().required("Please select a Asset"),value:S().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:g,setValue:c,formState:{errors:h}}=N({resolver:W(y)});i.useEffect(()=>{console.log("selectedData:",s)},[]),i.useEffect(()=>{s&&s.id&&(c("asset",s!=null&&s.asset?{label:s.asset.name,value:s.asset.id}:null),c("description",s.description),c("due_date",s.due_date))},[s,g,c]),i.useEffect(()=>{console.log(" Validation Errors:",h)},[h]);const E=a=>{var f;console.log("Submitted Data:",a),console.log("on submit triggered:");const m={asset_id:a.asset.value,description:a.description,due_date:a.due_date};a.status&&(m.status=(f=a.status)==null?void 0:f.id),console.log("attached image:",x);const p={obj:m,image:x,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,m)=>{m!=="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(z,{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(E),children:[e.jsxs(o,{container:!0,spacing:2,children:[e.jsx(o,{size:{xs:12,md:6},children:e.jsx(A,{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(A,{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{Fe as default};
