import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{l as r}from"./vendor-react-Cts2Wj-s.js";import{Q as i,X as a,at as o,b as s,x as c}from"./vendor-mui-Ckcy4Lfd.js";import{a as l,g as u,o as d,s as f,t as p,v as m}from"./ui-BLXHSX1T.js";import{G as h,r as g,t as _}from"./index-JB73_g7R.js";var v=e(n(),1),y=t(),b=Object.fromEntries(_.map(e=>[e.status,e.color])),x=[{value:`critical`,label:`Critical`},{value:`high`,label:`High`},{value:`medium`,label:`Medium`},{value:`low`,label:`Low`}];function S({task:e,defaults:t,onSubmit:n,onCancel:S,submitLabel:C=`Save`}){let{projectId:w}=r(),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(`todo`),[j,M]=(0,v.useState)(`medium`),[N,P]=(0,v.useState)([]),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(``),[z,B]=(0,v.useState)(``),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)(!1),[G,K]=(0,v.useState)(!1);(0,v.useEffect)(()=>{e?(E(e.title),O(e.description),A(e.status),M(e.priority),P(e.tags??[]),I(e.dueDate?new Date(e.dueDate).toISOString().split(`T`)[0]:``),R(e.estimate==null?``:String(e.estimate)),B(e.assignee??``)):t&&(t.title&&E(t.title),t.status&&A(t.status),t.priority&&M(t.priority),t.assignee&&B(t.assignee),t.tags&&P(t.tags))},[e]),(0,v.useEffect)(()=>{w&&h(w).then(H).catch(()=>{})},[w]);let q=async()=>{if(!T.trim()){K(!0);return}W(!0);try{await n({title:T.trim(),description:D.trim(),status:k,priority:j,tags:N,dueDate:F?new Date(F).getTime():null,estimate:L?Number(L):null,assignee:z||null})}finally{W(!1)}};return(0,y.jsxs)(i,{component:`form`,id:`task-form`,onSubmit:e=>{e.preventDefault(),q()},sx:{display:`flex`,flexDirection:`column`,gap:3},children:[(0,y.jsx)(l,{main:(0,y.jsx)(m,{title:`Details`,children:(0,y.jsxs)(i,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,y.jsx)(d,{fieldLabel:`Title`,required:!0,autoFocus:!0,fullWidth:!0,value:T,onChange:e=>{E(e.target.value),K(!1)},error:G,helperText:G?`Title is required`:void 0}),(0,y.jsxs)(i,{children:[(0,y.jsx)(f,{children:`Description`}),(0,y.jsx)(p,{value:D,onChange:O,height:250})]})]})}),sidebar:(0,y.jsx)(m,{title:`Properties`,children:(0,y.jsxs)(i,{sx:{display:`flex`,flexDirection:`column`,gap:2},children:[(0,y.jsxs)(i,{children:[(0,y.jsx)(f,{children:`Status`}),(0,y.jsx)(s,{fullWidth:!0,value:k,onChange:e=>A(e.target.value),renderValue:e=>{let t=b[e],n=_.find(t=>t.status===e)?.label??e;return(0,y.jsxs)(i,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,y.jsx)(i,{sx:{width:10,height:10,borderRadius:`50%`,bgcolor:t}}),n]})},sx:{"& .MuiSelect-select":{display:`flex`,alignItems:`center`}},children:_.map(e=>(0,y.jsx)(c,{value:e.status,children:(0,y.jsxs)(i,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,y.jsx)(i,{sx:{width:10,height:10,borderRadius:`50%`,bgcolor:e.color}}),e.label]})},e.status))})]}),(0,y.jsxs)(i,{children:[(0,y.jsx)(f,{children:`Priority`}),(0,y.jsx)(s,{fullWidth:!0,value:j,onChange:e=>M(e.target.value),renderValue:e=>{let t=g[e],n=x.find(t=>t.value===e)?.label??e;return(0,y.jsxs)(i,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,y.jsx)(i,{sx:{width:10,height:10,borderRadius:`50%`,bgcolor:t}}),n]})},sx:{"& .MuiSelect-select":{display:`flex`,alignItems:`center`}},children:x.map(e=>(0,y.jsx)(c,{value:e.value,children:(0,y.jsxs)(i,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,y.jsx)(i,{sx:{width:10,height:10,borderRadius:`50%`,bgcolor:g[e.value]}}),e.label]})},e.value))})]}),(0,y.jsx)(d,{fieldLabel:`Due Date`,fullWidth:!0,type:`date`,value:F,onChange:e=>I(e.target.value)}),(0,y.jsx)(d,{fieldLabel:`Estimate (hours)`,fullWidth:!0,type:`number`,value:L,onChange:e=>R(e.target.value),slotProps:{input:{inputProps:{min:0,step:.5}}}}),(0,y.jsxs)(i,{children:[(0,y.jsx)(f,{children:`Assignee`}),(0,y.jsxs)(s,{fullWidth:!0,value:z,onChange:e=>B(e.target.value),displayEmpty:!0,renderValue:e=>e?V.find(t=>t.id===e)?.name||e:`Unassigned`,children:[(0,y.jsx)(c,{value:``,children:`Unassigned`}),V.map(e=>(0,y.jsx)(c,{value:e.id,children:e.name||e.id},e.id))]})]}),(0,y.jsx)(u,{tags:N,editable:!0,onAdd:e=>P(t=>t.includes(e)?t:[...t,e]),onRemove:e=>P(t=>t.filter(t=>t!==e))})]})})}),(0,y.jsxs)(i,{sx:{display:`flex`,gap:1,justifyContent:`flex-end`},children:[(0,y.jsx)(a,{onClick:S,children:`Cancel`}),(0,y.jsx)(a,{variant:`contained`,onClick:q,disabled:U||!T.trim(),children:U?(0,y.jsx)(o,{size:20}):C})]})]})}export{S as t};