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-7d3dbb9c.js";import{u as N}from"./index.esm-12cc9f7b.js";import{o as W}from"./yup-55e79238.js";import{c as D,b as S}from"./index.esm-9d396c5f.js";import{S as A}from"./SelectComponent-b1bc4bdd.js";import{F as X}from"./FormInput-602ae51d.js";import{T as H}from"./TextArea-4d76f175.js";import{D as O}from"./Dialog-d125aee1.js";import{D as Q}from"./DialogTitle-a3176c12.js";import{D as Z}from"./DialogContent-d34f4ba4.js";import{D as ee}from"./DialogContentText-9128b573.js";import{D as se}from"./DialogActions-99629c3a.js";import"./objectSpread2-947328ce.js";import"./toPropertyKey-720374c3.js";import"./floating-ui.dom-cd6c919d.js";import"./InputLabel-ade41a0b.js";import"./useFormControl-7314cc67.js";import"./Checkbox-4b8e4bb1.js";import"./SwitchBase-d834be30.js";import"./useControlled-338e346b.js";import"./createSvgIcon-25cfe1a8.js";import"./FormControlLabel-4a3a4313.js";import"./OutlinedInput-e6d419ce.js";import"./isHostComponent-73d6e646.js";import"./TextField-a362d747.js";import"./FormControl-f3d9cdb4.js";import"./Select-762ec619.js";import"./Menu-5245abf0.js";import"./Grow-1b15246b.js";import"./List-d7c020ab.js";import"./useSlotProps-f2e72ab1.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};
