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{$ as a,Q as o,X as s,at as c,nt as l,rt as u}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";import{G as d,W as f}from"./vendor-mui-icons-606Bohdn.js";import{_ as p,a as m,g as h,h as g,l as _,n as v,p as y,r as b,v as x,x as S}from"./ui-BLXHSX1T.js";import{V as C}from"./index-JB73_g7R.js";import{_ as w,c as T,d as E,f as D,h as O,i as k,n as A,r as j,s as M,u as N}from"./skill-ZS39xCGU.js";import{t as P}from"./relation-manager-DQ9I91YW.js";import{n as F}from"./attachments-BKCJWgDD.js";var I=e(n(),1),L=t();function R(){let{projectId:e,skillId:t}=i(),n=r(),R=C(`skills`),[z,B]=(0,I.useState)(null),[V,H]=(0,I.useState)([]),[U,W]=(0,I.useState)([]),[G,K]=(0,I.useState)(!0),[q,J]=(0,I.useState)(null),[Y,X]=(0,I.useState)(!1),Z=(0,I.useCallback)(async()=>{if(!(!e||!t))try{let[n,r,i]=await Promise.all([N(e,t),D(e,t),E(e,t)]);B(n),H(r),W(i),J(null)}catch(e){J(e instanceof Error?e.message:String(e))}finally{K(!1)}},[e,t]);return(0,I.useEffect)(()=>{Z()},[Z]),S(e??null,(0,I.useCallback)(e=>{e.type.startsWith(`skill:`)&&Z()},[Z])),G?(0,L.jsx)(o,{sx:{display:`flex`,justifyContent:`center`,py:4},children:(0,L.jsx)(c,{})}):q||!z?(0,L.jsx)(u,{severity:`error`,children:q||`Skill not found`}):(0,L.jsxs)(o,{children:[(0,L.jsx)(y,{breadcrumbs:[{label:`Skills`,to:`/${e}/skills`},{label:z.title}],actions:R?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(s,{variant:`contained`,color:`success`,startIcon:(0,L.jsx)(d,{}),onClick:()=>n(`/${e}/skills/${t}/edit`),children:`Edit`}),(0,L.jsx)(s,{color:`error`,startIcon:(0,L.jsx)(f,{}),onClick:()=>X(!0),children:`Delete`})]}):void 0}),(0,L.jsx)(m,{main:(0,L.jsxs)(L.Fragment,{children:[z.description&&(0,L.jsx)(x,{title:`Description`,sx:{mb:3},children:(0,L.jsx)(v,{children:z.description})}),z.steps.length>0&&(0,L.jsx)(x,{title:`Steps`,sx:{mb:3},children:(0,L.jsx)(o,{component:`ol`,sx:{m:0,pl:2.5},children:z.steps.map((e,t)=>(0,L.jsx)(l,{component:`li`,variant:`body2`,sx:{mb:.5},children:e},t))})}),z.triggers.length>0&&(0,L.jsx)(x,{title:`Triggers`,sx:{mb:3},children:(0,L.jsx)(o,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:z.triggers.map((e,t)=>(0,L.jsx)(a,{label:e,size:`small`,variant:`outlined`},t))})}),z.inputHints.length>0&&(0,L.jsx)(x,{title:`Input Hints`,sx:{mb:3},children:(0,L.jsx)(o,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:z.inputHints.map((e,t)=>(0,L.jsx)(a,{label:e,size:`small`,variant:`outlined`},t))})}),z.filePatterns.length>0&&(0,L.jsx)(x,{title:`File Patterns`,sx:{mb:3},children:(0,L.jsx)(o,{sx:{display:`flex`,flexWrap:`wrap`,gap:.5},children:z.filePatterns.map((e,t)=>(0,L.jsx)(a,{label:e,size:`small`,variant:`outlined`,sx:{fontFamily:`monospace`}},t))})})]}),sidebar:(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(x,{title:`Details`,sx:{mb:3},children:[(0,L.jsx)(_,{label:`ID`,children:(0,L.jsxs)(o,{sx:{display:`flex`,alignItems:`center`,gap:.5},children:[(0,L.jsx)(l,{variant:`body2`,sx:{fontFamily:`monospace`},children:z.id}),(0,L.jsx)(g,{value:z.id})]})}),(0,L.jsx)(_,{label:`Version`,children:(0,L.jsxs)(l,{variant:`body2`,sx:{fontFamily:`monospace`},children:[`v`,z.version]})}),(0,L.jsx)(_,{label:`Source`,children:(0,L.jsx)(p,{label:k(z.source),color:A[z.source]??`primary`})}),(0,L.jsx)(_,{label:`Confidence`,children:(0,L.jsx)(l,{variant:`body2`,children:j(z.confidence)})}),(0,L.jsx)(_,{label:`Usage Count`,children:(0,L.jsx)(l,{variant:`body2`,children:z.usageCount})}),z.lastUsedAt&&(0,L.jsx)(_,{label:`Last Used`,children:(0,L.jsx)(l,{variant:`body2`,children:new Date(z.lastUsedAt).toLocaleString()})}),z.createdBy&&(0,L.jsx)(_,{label:`Created by`,children:(0,L.jsx)(l,{variant:`body2`,children:z.createdBy})}),z.updatedBy&&z.updatedBy!==z.createdBy&&(0,L.jsx)(_,{label:`Updated by`,children:(0,L.jsx)(l,{variant:`body2`,children:z.updatedBy})}),(0,L.jsx)(_,{label:`Created`,children:(0,L.jsx)(l,{variant:`body2`,children:new Date(z.createdAt).toLocaleString()})}),(0,L.jsx)(_,{label:`Updated`,children:(0,L.jsx)(l,{variant:`body2`,children:new Date(z.updatedAt).toLocaleString()})}),(0,L.jsx)(_,{label:`Tags`,children:z.tags.length>0?(0,L.jsx)(h,{tags:z.tags}):(0,L.jsx)(l,{variant:`body2`,color:`text.secondary`,children:`—`})})]}),(0,L.jsx)(x,{title:`Attachments`,sx:{mb:3},children:(0,L.jsx)(F,{attachments:U,getUrl:n=>O(e,t,n),onUpload:async n=>{await w(e,t,n),W(await E(e,t))},onDelete:async n=>{await T(e,t,n),W(await E(e,t))},readOnly:!R})}),(0,L.jsx)(x,{title:`Relations`,children:(0,L.jsx)(P,{projectId:e,entityId:t,entityType:`skills`,relations:V,onRefresh:Z})})]})}),(0,L.jsx)(b,{open:Y,title:`Delete Skill`,message:`Are you sure you want to delete "${z.title}"? This cannot be undone.`,confirmLabel:`Delete`,confirmColor:`error`,onConfirm:async()=>{!e||!t||(await M(e,t),n(`/${e}/skills`))},onCancel:()=>X(!1)})]})}export{R as default};