import{n as w,u as b,j as e,k as o,B as h,l as m}from"./index-O0BQoyzo.js";import{r as N}from"./react-Cb2sDjhD.js";import{T as v,a as T,b as u,c as l,d as k,e as c}from"./table-CPn1MRcy.js";import{u as y,a as A}from"./use-background-tasks-BQrEeUwY.js";import{H}from"./heart-pulse-DmGhKR2W.js";import{L as R}from"./loader-circle-9VUMGitw.js";import{R as S}from"./refresh-ccw-D2CWiyU_.js";import{P as C}from"./play-CfSn5Vdl.js";import"./useQuery-PdiC7-sY.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const P=w("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]]);function Q(){const{t}=b(["tasks","common"]),s=y(),r=A(),[j,f]=N.useState(null);async function p(a,n){try{await r.mutateAsync({row:a,op:n}),m.success(t(n==="enable"?"heartbeat.enabledToast":"heartbeat.disabledToast"))}catch(i){m.error(i?.message??String(i))}}const d=s.data?.bindings??[];return e.jsxs("div",{className:"mx-auto flex max-w-6xl flex-col gap-4 p-4",children:[e.jsxs("header",{className:"flex items-center gap-3",children:[e.jsx(H,{className:"h-5 w-5 text-text-dim"}),e.jsx("h1",{className:"text-xl font-semibold",children:t("heartbeat.title")}),e.jsx(o,{variant:"info",children:d.length}),e.jsxs(h,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>void s.refetch(),disabled:s.isFetching,"aria-label":t("actions.refresh",{ns:"common"}),children:[s.isFetching?e.jsx(R,{className:"h-4 w-4 animate-spin"}):e.jsx(S,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:t("heartbeat.refresh")})]})]}),e.jsx("p",{className:"text-sm text-text-dim",children:t("heartbeat.subtitle")}),s.isLoading?e.jsx("div",{className:"h-48 rounded-md bg-surface-2 animate-pulse"}):d.length===0?e.jsx(z,{}):e.jsx("section",{className:"rounded-md border border-border bg-surface",children:e.jsxs(v,{children:[e.jsx(T,{children:e.jsxs(u,{children:[e.jsx(l,{children:t("heartbeat.col.thread")}),e.jsx(l,{children:t("heartbeat.col.owner")}),e.jsx(l,{children:t("heartbeat.col.interval")}),e.jsx(l,{children:t("heartbeat.col.lastTick")}),e.jsx(l,{children:t("heartbeat.col.enabled")}),e.jsx(l,{children:t("heartbeat.col.body")})]})}),e.jsx(k,{children:d.map(a=>{const n=`${a.platform}:${a.channelId}:${a.threadId}`,i=j===n,g=a.lastTickAt?a.lastStatus==="delivered"?e.jsx(o,{variant:"success",children:x(a.lastTickAt,t)}):a.lastStatus==="error"?e.jsxs(o,{variant:"danger",title:a.lastReason,children:[a.lastStatus," · ",x(a.lastTickAt,t)]}):e.jsxs(o,{variant:"outline",title:a.lastReason,children:[a.lastStatus," · ",x(a.lastTickAt,t)]}):e.jsx(o,{variant:"outline",children:t("heartbeat.never")});return e.jsxs(u,{children:[e.jsxs(c,{className:"font-mono text-[11px]",children:[a.platform,":",a.threadId]}),e.jsx(c,{className:"font-mono text-[11px]",children:a.userId||"—"}),e.jsx(c,{className:"text-xs",children:t("heartbeat.intervalMin",{count:a.intervalMinutes})}),e.jsx(c,{children:g}),e.jsx(c,{children:e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>void p(a,a.enabled?"disable":"enable"),disabled:r.isPending,children:a.enabled?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-4 w-4"}),e.jsx("span",{children:t("heartbeat.pause")})]}):e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"h-4 w-4"}),e.jsx("span",{children:t("heartbeat.enable")})]})})}),e.jsxs(c,{className:"max-w-md",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>f(i?null:n),className:"-ml-2",children:t(i?"heartbeat.hide":"heartbeat.show")}),i&&e.jsx("pre",{className:"mt-2 whitespace-pre-wrap break-words rounded bg-surface-2 p-2 text-[11px] text-text-dim",children:a.body})]})]},n)})})]})})]})}function z(){const{t}=b("tasks");return e.jsx("section",{className:"rounded-md border border-border bg-surface p-6 text-center text-sm text-text-dim",children:t("heartbeat.empty")})}function x(t,s){if(!t)return s("heartbeat.never");const r=Date.now()-new Date(t).getTime();return!Number.isFinite(r)||r<0||r<6e4?s("heartbeat.justNow"):r<36e5?s("heartbeat.minutesAgo",{count:Math.floor(r/6e4)}):r<864e5?s("heartbeat.hoursAgo",{count:Math.floor(r/36e5)}):s("heartbeat.daysAgo",{count:Math.floor(r/864e5)})}export{Q as default};
//# sourceMappingURL=heartbeat-kLoGBNCo.js.map
