import{r as e}from"./rolldown-runtime-hePW80VL.js";import{o as t}from"./vendor-forms-yQg41KHz.js";import{l as n,t as r}from"./vendor-react-CAGJwf-T.js";import{c as i}from"./api-sqDSbqTC.js";import{t as a}from"./DataTable-BFSm8gty.js";import{t as o}from"./clock-Dhn93nlC.js";import{t as s}from"./KpiStatCard-BBISpQ8S.js";import{t as c}from"./shield-alert-tG113PR4.js";import{t as l}from"./triangle-alert-CQ-4Schb.js";import{t as u}from"./format-BVO_kFTb.js";import{C as d,D as f,Dt as p,O as m,Q as h,S as g,x as _}from"./index-Z_bdWDpJ.js";import{r as v}from"./vendor-table-DrED5BwI.js";import{t as y}from"./PageHeader-UI75nV23.js";import{N as b,k as x,x as S}from"./workflowRtkApi-CinPa_NH.js";var C=e(t(),1),w=r(),T={pending:`warning`,escalated:`error`,resolved:`success`,expired:`outline`},E=v();function D(e){if(!e)return`—`;let t=new Date(e);return isNaN(t.getTime())?`—`:u(t,`dd MMM yyyy`)}function O(){let e=n(),[t,r]=(0,C.useState)(1),[u]=(0,C.useState)(20),[v,O]=(0,C.useState)(``),[k,A]=(0,C.useState)(!1),[j,M]=(0,C.useState)(null),[N,P]=(0,C.useState)(``),F=(0,C.useMemo)(()=>{let e={page:String(t),page_size:String(u)};return v&&(e.search=v),e},[t,u,v]),I=S(F,{skip:k}),L=x(F,{skip:!k}),R=k?L:I,{data:z}=S({page:`1`,page_size:`1`}),[B,{isLoading:V}]=b(),H=R.data?.results??[],U=R.data?.count??0,W=Math.ceil(U/u),G=z?.count??0,K=e=>{M(e),P(``)},q=async()=>{if(j)try{await B({id:j.id,resolution_notes:N||void 0}).unwrap(),i.success(`Escalation resolved`),M(null)}catch(e){i.error(_(e,`Failed to resolve escalation`))}},J=(0,C.useMemo)(()=>[E.accessor(`created_at`,{header:`Escalated`,cell:e=>{let t=e.getValue(),n=t?new Date(t):null;return(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-[13px] text-[var(--color-text-primary)]`,children:D(t)}),n&&!isNaN(n.getTime())&&(0,w.jsx)(`div`,{className:`text-[11px] text-[var(--color-text-muted)]`,children:h(n,{addSuffix:!0})})]})}}),E.accessor(`reason`,{header:`Reason`,cell:e=>(0,w.jsx)(`div`,{className:`max-w-xs truncate text-[13px] text-[var(--color-text-primary)]`,title:e.getValue(),children:e.getValue()||`—`})}),E.accessor(e=>e.instance_data?.workflow_name,{id:`workflow`,header:`Workflow`,cell:e=>(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-[13px] text-[var(--color-text-secondary)]`,children:e.getValue()||`—`}),e.row.original.step_name&&(0,w.jsx)(`div`,{className:`text-[11px] text-[var(--color-text-muted)]`,children:e.row.original.step_name})]})}),E.accessor(`escalated_to_name`,{header:`Assigned To`,cell:e=>(0,w.jsx)(`span`,{className:`text-[13px] text-[var(--color-text-secondary)]`,children:e.getValue()||`—`})}),E.accessor(`status`,{header:`Status`,cell:e=>(0,w.jsx)(g,{variant:T[e.getValue()]??`default`,size:`sm`,children:e.getValue()})}),E.display({id:`actions`,header:`Actions`,cell:t=>{let n=t.row.original;return(0,w.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,w.jsx)(f,{size:`sm`,variant:`ghost`,onClick:()=>e(`/admin/workflow/instances/${n.instance}`),children:`View`}),n.status!==`resolved`&&(0,w.jsx)(f,{size:`sm`,variant:`ghost`,onClick:()=>K(n),children:`Resolve`})]})}})],[e]);return(0,w.jsxs)(`div`,{children:[(0,w.jsx)(y,{title:`Escalations`,description:`SLA-breached workflow steps that require management attention.`}),(0,w.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-3 sm:grid-cols-3`,children:[(0,w.jsx)(s,{compact:!0,icon:(0,w.jsx)(l,{className:`h-5 w-5`}),value:G,label:`Pending`,color:`rose`}),(0,w.jsx)(s,{compact:!0,icon:(0,w.jsx)(c,{className:`h-5 w-5`}),value:U,label:k?`Total`:`Showing Pending`,color:`amber`}),(0,w.jsx)(s,{compact:!0,icon:(0,w.jsx)(p,{className:`h-5 w-5`}),value:k?(R.data?.count??0)-G:`—`,label:`Resolved`,color:`emerald`})]}),(0,w.jsx)(`div`,{className:`mb-3 flex items-center justify-end`,children:(0,w.jsxs)(f,{size:`sm`,variant:k?`outline`:`ghost`,onClick:()=>{A(e=>!e),r(1)},children:[(0,w.jsx)(o,{className:`h-4 w-4`}),k?`Show Pending Only`:`Show All`]})}),(0,w.jsx)(a,{columns:J,data:H,isLoading:R.isLoading,isFetching:R.isFetching,searchable:!0,searchPlaceholder:`Search escalations…`,onSearch:e=>{O(e),r(1)},totalItems:U,currentPage:t,pageSize:u,totalPages:W,onPageChange:r,emptyTitle:k?`No escalations`:`No pending escalations`,emptyDescription:k?`No workflow escalations found.`:`All escalations have been resolved or none have been triggered yet.`}),(0,w.jsx)(m,{isOpen:!!j,onClose:()=>M(null),title:`Resolve Escalation`,description:j?.reason,size:`md`,footer:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(f,{variant:`outline`,onClick:()=>M(null),children:`Cancel`}),(0,w.jsxs)(f,{onClick:q,isLoading:V,children:[(0,w.jsx)(p,{className:`h-4 w-4`}),` Mark Resolved`]})]}),children:(0,w.jsx)(d,{label:`Resolution Notes (optional)`,value:N,onChange:e=>P(e.target.value),placeholder:`Describe how this was resolved…`,rows:4})})]})}export{O as default};