import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{c as r,l as i}from"./vendor-react-Cts2Wj-s.js";import{Q as a,X as o,at as s,d as c,f as l,ht as u,j as ee,l as te,lt as d,nt as f,p,pt as m,rt as h,s as g}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{G as _,W as v,gt as y}from"./vendor-mui-icons-606Bohdn.js";import{_ as b,g as x,h as ne,l as S,m as C,n as w,p as T,r as E,v as D,x as O}from"./ui-BLXHSX1T.js";import{V as k,a as A,n as j,o as M}from"./index-JB73_g7R.js";import{a as N,n as P,r as F}from"./api-C88VCaJt.js";var I=e(n(),1),L=t(),R={open:`#1976d2`,in_progress:`#f57c00`,done:`#388e3c`,cancelled:`#d32f2f`},z={open:`primary`,in_progress:`warning`,done:`success`,cancelled:`error`};function re(e){return{open:`Open`,in_progress:`In Progress`,done:`Done`,cancelled:`Cancelled`}[e]??e}function B(){let{projectId:e,epicId:t}=i(),n=r(),{palette:B}=m(),V=k(`tasks`),[H,U]=(0,I.useState)(null),[W,G]=(0,I.useState)([]),[K,q]=(0,I.useState)(!0),[J,Y]=(0,I.useState)(null),[X,Z]=(0,I.useState)(!1),[ie,Q]=(0,I.useState)(!1),$=(0,I.useCallback)(async()=>{if(!(!e||!t))try{let[n,r]=await Promise.all([F(e,t),N(e,t)]);U(n),G(r)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{q(!1)}},[e,t]);(0,I.useEffect)(()=>{$()},[$]),O(e??null,(0,I.useCallback)(e=>{(e.type.startsWith(`epic:`)||e.type.startsWith(`task:`))&&$()},[$]));let ae=async()=>{if(!(!e||!t)){Q(!0);try{await P(e,t),n(`/${e}/epics`)}finally{Q(!1)}}};if(K)return(0,L.jsx)(a,{sx:{display:`flex`,justifyContent:`center`,py:4},children:(0,L.jsx)(s,{})});if(J||!H)return(0,L.jsx)(h,{severity:`error`,children:J||`Epic not found`});let oe=H.progress.total>0?H.progress.done/H.progress.total*100:0;return(0,L.jsxs)(a,{children:[(0,L.jsx)(T,{breadcrumbs:[{label:`Epics`,to:`/${e}/epics`},{label:H.title}],actions:V?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(o,{startIcon:(0,L.jsx)(_,{}),onClick:()=>n(`/${e}/epics/${t}/edit`),children:`Edit`}),(0,L.jsx)(o,{startIcon:(0,L.jsx)(v,{}),color:`error`,onClick:()=>Z(!0),children:`Delete`})]}):void 0}),(0,L.jsxs)(d,{variant:`outlined`,sx:{p:2,mb:3},children:[(0,L.jsxs)(a,{sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,mb:1},children:[(0,L.jsx)(f,{variant:`subtitle2`,children:`Progress`}),(0,L.jsxs)(f,{variant:`body2`,fontWeight:600,sx:{color:B.custom.textMuted},children:[H.progress.done,` / `,H.progress.total,` tasks done`]})]}),(0,L.jsx)(ee,{variant:`determinate`,value:oe,sx:{height:8,borderRadius:4,bgcolor:u(R[H.status]??`#616161`,.15),"& .MuiLinearProgress-bar":{bgcolor:R[H.status]??`#616161`,borderRadius:4}}})]}),(0,L.jsxs)(D,{title:`Properties`,sx:{mb:3},children:[(0,L.jsx)(S,{label:`ID`,children:(0,L.jsxs)(a,{sx:{display:`flex`,alignItems:`center`,gap:.5},children:[(0,L.jsx)(f,{variant:`body2`,sx:{fontFamily:`monospace`},children:H.id}),(0,L.jsx)(ne,{value:H.id})]})}),(0,L.jsx)(S,{label:`Status`,children:(0,L.jsx)(b,{label:re(H.status),color:z[H.status]??`neutral`})}),(0,L.jsx)(S,{label:`Priority`,children:(0,L.jsx)(b,{label:A(H.priority),color:j[H.priority]})}),(0,L.jsx)(S,{label:`Tags`,children:(0,L.jsx)(x,{tags:H.tags})}),(0,L.jsx)(S,{label:`Created`,children:(0,L.jsx)(C,{value:H.createdAt,showTime:!0})}),(0,L.jsx)(S,{label:`Updated`,children:(0,L.jsx)(C,{value:H.updatedAt,showTime:!0,showRelative:!0})})]}),H.description&&(0,L.jsx)(D,{title:`Description`,sx:{mb:3},children:(0,L.jsx)(w,{children:H.description})}),(0,L.jsx)(D,{title:`Tasks (${W.length})`,action:W.length>0?(0,L.jsx)(o,{size:`small`,startIcon:(0,L.jsx)(y,{}),onClick:()=>n(`/${e}/tasks/list?epic=${t}`),children:`View in list`}):void 0,children:W.length===0?(0,L.jsx)(f,{variant:`body2`,sx:{color:B.custom.textMuted,py:2},children:`No tasks linked to this epic yet.`}):(0,L.jsxs)(p,{size:`small`,children:[(0,L.jsx)(te,{children:(0,L.jsxs)(g,{children:[(0,L.jsx)(c,{children:`Title`}),(0,L.jsx)(c,{width:120,children:`Status`}),(0,L.jsx)(c,{width:100,children:`Priority`}),(0,L.jsx)(c,{children:`Tags`})]})}),(0,L.jsx)(l,{children:W.map(t=>(0,L.jsxs)(g,{hover:!0,sx:{cursor:`pointer`},onClick:()=>n(`/${e}/tasks/${t.id}`),children:[(0,L.jsx)(c,{children:(0,L.jsx)(f,{variant:`body2`,fontWeight:500,children:t.title})}),(0,L.jsx)(c,{children:(0,L.jsx)(b,{label:M(t.status),color:{backlog:`neutral`,todo:`primary`,in_progress:`warning`,review:`primary`,done:`success`,cancelled:`error`}[t.status],size:`small`})}),(0,L.jsx)(c,{children:(0,L.jsx)(b,{label:A(t.priority),color:j[t.priority],size:`small`})}),(0,L.jsx)(c,{children:t.tags?.length>0&&(0,L.jsx)(x,{tags:t.tags})})]},t.id))})]})}),(0,L.jsx)(E,{open:X,title:`Delete Epic`,message:`Delete "${H.title}"? Tasks linked to it will NOT be deleted.`,confirmLabel:`Delete`,confirmColor:`error`,onConfirm:ae,onCancel:()=>Z(!1),loading:ie})]})}export{B as default};