@sentry/junior-dashboard 0.290.0 → 0.292.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +3 -3
- package/dist/client-manifest.json +1 -1
- package/dist/index.js +3 -3
- package/dist/public/chunks/{AdminPage-htjffg0n.js → AdminPage-fdz3hucf.js} +1 -1
- package/dist/public/chunks/{Area-hr2tz6ad.js → Area-f1nin66q.js} +1 -1
- package/dist/public/chunks/{AutomationPage-eihr9acm.js → AutomationPage-d5mdkrn9.js} +3 -3
- package/dist/public/chunks/{AutomationRunDetails-op6rfaji.js → AutomationRunDetails-hyjcewq8.js} +1 -1
- package/dist/public/chunks/AutomationRunsPage-fcez9yb2.js +1 -0
- package/dist/public/chunks/AutomationsPage-in07jyvb.js +15 -0
- package/dist/public/chunks/{BarChart-cg02osy4.js → BarChart-hdlbq093.js} +1 -1
- package/dist/public/chunks/{BoardPage-mbypholh.js → BoardPage-jmv26j4s.js} +1 -1
- package/dist/public/chunks/{CodeChangeRow-oyge0uo2.js → CodeChangeRow-enn40527.js} +2 -2
- package/dist/public/chunks/CodePage-ous0utk0.js +1 -0
- package/dist/public/chunks/{CodeSummaryCards-gikkczl6.js → CodeSummaryCards-d2oxdoq1.js} +1 -1
- package/dist/public/chunks/{ConnectionsPage-l2d6sesm.js → ConnectionsPage-lilwyiau.js} +2 -2
- package/dist/public/chunks/{DrawerContent-jt25bpic.js → DrawerContent-jg0soa2u.js} +1 -1
- package/dist/public/chunks/{FilterBar-h4ab22b1.js → FilterBar-lsllb7tj.js} +1 -1
- package/dist/public/chunks/{FormNotice-oukmcfaj.js → FormNotice-mmzuj60h.js} +1 -1
- package/dist/public/chunks/{LocationDetailPage-gldsmom2.js → LocationDetailPage-cf82jjul.js} +1 -1
- package/dist/public/chunks/{LocationsPage-glec25wm.js → LocationsPage-g9b4zhrs.js} +1 -1
- package/dist/public/chunks/{McpSettingsPage-nfv7qia1.js → McpSettingsPage-gibci7qd.js} +1 -1
- package/dist/public/chunks/{PeoplePage-kd1ad63d.js → PeoplePage-cphdlfgf.js} +1 -1
- package/dist/public/chunks/{PersonProfilePage-diqz6hmw.js → PersonProfilePage-mf6i9tif.js} +1 -1
- package/dist/public/chunks/{PersonalTokensPage-mwkwnlc7.js → PersonalTokensPage-iodbv05e.js} +1 -1
- package/dist/public/chunks/PluginReportRecordSet-fossppyd.js +1 -0
- package/dist/public/chunks/{PluginUserPage-l7q0ylyz.js → PluginUserPage-ismd883z.js} +2 -2
- package/dist/public/chunks/RepositoryPage-dwvax7uv.js +1 -0
- package/dist/public/chunks/SettingsPage-f9kssan6.js +1 -0
- package/dist/public/chunks/{SystemPage-mpp6dtwm.js → SystemPage-a5t28k3w.js} +1 -1
- package/dist/public/chunks/{WorkspaceFormPage-o74u0sno.js → WorkspaceFormPage-h21lnuo4.js} +2 -2
- package/dist/public/chunks/WorkspacesPage-h0lwq044.js +1 -0
- package/dist/public/chunks/{automationFormat-bhjz2hx6.js → automationFormat-nmiq4qj2.js} +1 -1
- package/dist/public/chunks/{chart-mxqu3c8e.js → chart-dbzd0ka8.js} +1 -1
- package/dist/public/chunks/{code-highlighter-dd09ntlw.js → code-highlighter-lmx9nqyd.js} +1 -1
- package/dist/public/chunks/{format-eev8is9c.js → format-c4b0iyrx.js} +2 -2
- package/dist/public/chunks/{junior-btnqqkq5.js → junior-gfsokzu9.js} +2 -2
- package/dist/public/chunks/{workspaceQueries-i5xdl0za.js → workspaceQueries-l3p6sri7.js} +1 -1
- package/dist/public/client-mgf2bxi7.js +165 -0
- package/dist/public/styles-6XAAC7O5.css +2 -0
- package/dist/tailwind.css +1 -1
- package/package.json +4 -4
- package/src/client/conversations/ConversationMeta.tsx +127 -34
- package/src/client/conversations/ConversationWorkspace.tsx +45 -30
- package/src/client/conversations/conversationSections.ts +3 -2
- package/src/client/format.ts +1 -0
- package/src/client/types.ts +2 -0
- package/dist/public/chunks/AutomationRunsPage-sx9tdkxv.js +0 -1
- package/dist/public/chunks/AutomationsPage-mnstyn9j.js +0 -15
- package/dist/public/chunks/CodePage-ojiokuht.js +0 -1
- package/dist/public/chunks/PluginReportRecordSet-ea6phh3k.js +0 -1
- package/dist/public/chunks/RepositoryPage-f61pzf0s.js +0 -1
- package/dist/public/chunks/SettingsPage-oqgh66n1.js +0 -1
- package/dist/public/chunks/WorkspacesPage-kfphmgpt.js +0 -1
- package/dist/public/client-ll3qwj84.js +0 -165
- package/dist/public/styles-GFFU7LPU.css +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ot as e,pt as t,ut as n}from"./vendor-lthmb2su.js";import{S as r,r as i}from"./vendor-react-ggbyvons.js";import{t as a}from"./button-loz3etho.js";import{$ as o,Bt as s,Pt as c}from"./vendor-icons-mxz7yi04.js";import{C as l,F as u,L as d}from"./junior-
|
|
1
|
+
import{ot as e,pt as t,ut as n}from"./vendor-lthmb2su.js";import{S as r,r as i}from"./vendor-react-ggbyvons.js";import{t as a}from"./button-loz3etho.js";import{$ as o,Bt as s,Pt as c}from"./vendor-icons-mxz7yi04.js";import{C as l,F as u,L as d}from"./junior-gfsokzu9.js";import{i as f,n as p,o as m}from"./http-cdq677qt.js";import{r as h}from"./styles-j0007fov.js";import{t as g}from"./Card-hy4bfgq7.js";import{m as _,t as v}from"./PageHeader-kvp1fo95.js";import{y}from"./format-c4b0iyrx.js";import{t as b}from"./AnchorHeading-cp3vx8qa.js";import{ht as x,q as S,t as C}from"../client-mgf2bxi7.js";var w=r();const T=[`dashboard`,`service-accounts`];function E(e){return`/api/service-accounts/${encodeURIComponent(e)}`}function D(){return n({queryKey:T,queryFn:({signal:e})=>f(u,`/api/service-accounts`,e),refetchOnWindowFocus:!0,retry:!1})}function O(e){let t=e.userOAuth?`People who have not connected their own ${e.displayName} account use this account.`:`Everyone uses this account. People cannot connect their own ${e.displayName} account.`;return e.connected?`Connected by ${e.connectedBy??`the CLI`} ${y(e.connectedAt)}. ${t}`:`Not connected.${e.userOAuth?``:` ${e.displayName} is not available until you connect it.`} ${t} Sign in as the shared account, not as yourself.`}function k(n){let{accountsQuery:r}=n,i=t(),s=e({mutationFn:e=>m(d,E(e.provider),{}),onSuccess:({authorizationUrl:e},{popup:t})=>{t?t.closed||(t.opener=null,t.location.href=e):window.location.assign(e)},onError:(e,{popup:t})=>{t?.close()}}),c=e({mutationFn:e=>p(l,E(e.provider)),onSuccess:()=>i.invalidateQueries({queryKey:T})}),u=r.data?.serviceAccounts??[];if(r.isSuccess&&u.length===0)return null;let f=s.isPending||c.isPending,h=s.isPending?s.variables?.provider:c.isPending?c.variables?.provider:void 0,v=!r.data&&r.isError,y=s.isError?`Could not start the sign-in. Try again.`:c.isError?`Could not disconnect the account. Try again.`:v?`Could not load service accounts. Try again.`:void 0;return/* @__PURE__ */ (0,w.jsxs)(g,{as:`section`,padding:`md`,children:[/* @__PURE__ */ (0,w.jsx)(b,{anchor:`service-accounts`,className:`m-0 font-display text-base font-medium text-dashboard-text`,title:`Service accounts`}),/* @__PURE__ */ (0,w.jsxs)(`p`,{className:`mt-1 mb-4 text-sm text-dashboard-text-muted`,children:[`A shared account that Junior uses for a plugin. It can do only what its plugin allows, usually read. Everyone who can talk to`,` `,_(),` can use it, so give it only access that all of them may have.`]}),y?/* @__PURE__ */ (0,w.jsx)(S,{className:v?void 0:`mb-4`,children:y}):null,v?null:r.isPending?/* @__PURE__ */ (0,w.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`Loading service accounts…`}):/* @__PURE__ */ (0,w.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex items-center gap-3 rounded-md border border-dashboard-border-strong p-3`,children:[/* @__PURE__ */ (0,w.jsx)(o,{"aria-hidden":`true`,className:`shrink-0 text-dashboard-accent`,size:16}),/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[/* @__PURE__ */ (0,w.jsx)(`p`,{className:`m-0 truncate text-sm font-semibold`,children:e.displayName}),/* @__PURE__ */ (0,w.jsx)(x,{size:`compact`,tone:e.connected?`success`:e.userOAuth?`neutral`:`warning`,children:e.connected?`connected`:`not connected`}),e.userOAuth?null:/* @__PURE__ */ (0,w.jsx)(x,{size:`compact`,tone:`neutral`,children:`shared only`})]}),/* @__PURE__ */ (0,w.jsx)(`p`,{className:`mt-1 mb-0 break-words text-xs text-dashboard-text-muted`,children:O(e)}),/* @__PURE__ */ (0,w.jsx)(`p`,{className:`mt-1 mb-0 break-words font-mono text-xs text-dashboard-text-faint`,children:e.tools.join(`, `)})]}),e.connected?/* @__PURE__ */ (0,w.jsx)(a,{"aria-busy":c.isPending&&h===e.provider,"aria-label":`Disconnect the ${e.displayName} service account`,disabled:f,onClick:()=>{s.reset(),c.mutate(e)},variant:`danger`,children:`Disconnect`}):null,/* @__PURE__ */ (0,w.jsx)(a,{"aria-busy":s.isPending&&h===e.provider,"aria-label":`${e.connected?`Reconnect`:`Connect`} the ${e.displayName} service account`,disabled:f,onClick:()=>{c.reset();let t=window.open(`about:blank`,`_blank`);s.mutate({provider:e.provider,popup:t})},children:s.isPending&&h===e.provider?`Connecting…`:e.connected?`Reconnect`:`Connect`})]},e.provider))})]})}function A(e){let t=e.pages.filter(e=>e.navigation===`admin`),n=D(),r=t.length===0&&n.data?.serviceAccounts.length===0;return/* @__PURE__ */ (0,w.jsx)(`div`,{className:`${h} px-4 py-8 md:px-8`,children:/* @__PURE__ */ (0,w.jsxs)(`section`,{className:`mx-auto grid w-full max-w-3xl gap-6`,children:[/* @__PURE__ */ (0,w.jsx)(v,{description:/* @__PURE__ */ (0,w.jsxs)(w.Fragment,{children:[`Setup that only Junior admins can see. Change who is an admin with`,` `,/* @__PURE__ */ (0,w.jsx)(`code`,{children:`junior admin grant <email>`}),` and`,` `,/* @__PURE__ */ (0,w.jsx)(`code`,{children:`junior admin revoke <email>`}),`.`]}),title:`Admin`}),/* @__PURE__ */ (0,w.jsx)(k,{accountsQuery:n}),r?/* @__PURE__ */ (0,w.jsx)(g,{padding:`md`,children:/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex items-center gap-4`,children:[/* @__PURE__ */ (0,w.jsx)(`div`,{className:`grid size-10 shrink-0 place-items-center rounded-md border border-dashboard-border bg-dashboard-fill-soft text-dashboard-text-muted`,children:/* @__PURE__ */ (0,w.jsx)(s,{"aria-hidden":`true`,size:17})}),/* @__PURE__ */ (0,w.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`No plugin has admin setup.`})]})}):t.length===0?null:/* @__PURE__ */ (0,w.jsx)(`div`,{className:`grid gap-3`,children:t.map(e=>/* @__PURE__ */ (0,w.jsx)(i,{className:`no-underline`,to:C(e.pluginName,e.id),children:/* @__PURE__ */ (0,w.jsx)(g,{padding:`md`,children:/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex items-center gap-3`,children:[/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[/* @__PURE__ */ (0,w.jsx)(`div`,{className:`font-sans font-medium text-xs text-dashboard-text-muted`,children:e.pluginDisplayName}),/* @__PURE__ */ (0,w.jsx)(`h2`,{className:`mt-1 mb-0 font-display text-base font-medium text-dashboard-text`,children:e.label}),/* @__PURE__ */ (0,w.jsx)(`p`,{className:`mt-1 mb-0 text-sm text-dashboard-text-muted`,children:e.description})]}),/* @__PURE__ */ (0,w.jsx)(c,{"aria-hidden":`true`,className:`shrink-0 text-dashboard-text-muted`,size:16})]})})},`${e.pluginName}:${e.id}`))})]})})}export{A as AdminPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{nt as t}from"./vendor-lthmb2su.js";import{C as n}from"./vendor-react-ggbyvons.js";import{$t as r,At as i,Bt as a,Ct as o,D as s,Dt as c,E as l,Et as u,F as d,G as f,Ht as p,I as m,K as h,M as g,Mt as _,N as v,Nt as y,O as b,Pt as x,Qt as S,R as C,S as ee,T as w,Tt as T,U as E,Vt as D,Wt as O,X as k,Xt as A,Yt as j,Z as M,Zt as te,b as N,bt as P,ct as ne,dt as re,et as ie,ft as F,gt as I,j as ae,k as oe,kt as L,mt as se,pt as ce,q as le,rt as ue,st as de,ut as R,w as fe,wt as pe,x as me,y as z,zt as B}from"./chart-mxqu3c8e.js";var V=/* @__PURE__ */ e(n());function H(){return H=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},H.apply(null,arguments)}var U=e=>{var{cx:n,cy:r,r:i,className:a}=e,o=t(`recharts-dot`,a);return p(n)&&p(r)&&p(i)?/*#__PURE__*/ V.createElement(`circle`,H({},S(e),x(e),{className:o,cx:n,cy:r,r:i})):null},he=[`points`];function W(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function G(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?W(Object(n),!0).forEach(function(t){ge(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ge(e,t,n){return(t=_e(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _e(e){var t=ve(e,`string`);return typeof t==`symbol`?t:t+``}function ve(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function K(){return K=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},K.apply(null,arguments)}function ye(e,t){if(e==null)return{};var n,r,i=be(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function be(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function xe(e){var{option:n,dotProps:r,className:i}=e;if(/*#__PURE__*/ (0,V.isValidElement)(n))return/*#__PURE__*/ (0,V.cloneElement)(n,r);if(typeof n==`function`)return n(r);var a=t(i,typeof n==`boolean`?``:n.className),o=r??{},{points:s}=o,c=ye(o,he);return/*#__PURE__*/ V.createElement(U,K({},c,{className:a}))}function Se(e,t){return e==null?!1:t?!0:e.length===1}function Ce(e){var{points:t,dot:n,className:r,dotClassName:i,dataKey:a,baseProps:o,needClip:s,clipPathId:c,zIndex:l=M.scatter}=e;if(!Se(t,n))return null;var u=ae(n),f=te(n),p=t.map((e,r)=>{var s=G(G(G({r:3},o),f),{},{index:r,cx:e.x??void 0,cy:e.y??void 0,dataKey:a,value:e.value,payload:e.payload,points:t});return/*#__PURE__*/ V.createElement(xe,{key:`dot-${r}`,option:n,dotProps:s,className:i})}),m={};return s&&c!=null&&(m.clipPath=`url(#clipPath-${u?``:`dots-`}${c})`),/*#__PURE__*/ V.createElement(d,{zIndex:l},/*#__PURE__*/ V.createElement(j,K({className:r},m),p))}function q(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function J(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?q(Object(n),!0).forEach(function(t){we(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):q(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function we(e,t,n){return(t=Te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Te(e){var t=Ee(e,`string`);return typeof t==`symbol`?t:t+``}function Ee(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var De=e=>{var{point:t,childIndex:n,mainColor:i,activeDot:a,dataKey:o,clipPath:s}=e;if(a===!1||t.x==null||t.y==null)return null;var c=J(J(J({},{index:n,dataKey:o,cx:t.x,cy:t.y,r:4,fill:i??`none`,strokeWidth:2,stroke:`#fff`,payload:t.payload,value:t.value}),r(a)),x(a)),l=/*#__PURE__*/ (0,V.isValidElement)(a)?/*#__PURE__*/ (0,V.cloneElement)(a,c):typeof a==`function`?a(c):/*#__PURE__*/ V.createElement(U,c);return/*#__PURE__*/ V.createElement(j,{className:`recharts-active-dot`,clipPath:s},l)};function Y(e){var{points:t,mainColor:n,activeDot:r,itemDataKey:i,clipPath:a,zIndex:o=M.activeDot}=e,s=_(C),c=fe();if(t==null||c==null)return null;var l=t.find(e=>c.includes(e.payload));return D(l)?null:/*#__PURE__*/ V.createElement(d,{zIndex:o},/*#__PURE__*/ V.createElement(De,{point:l,childIndex:Number(s),mainColor:n,dataKey:i,activeDot:r,clipPath:a}))}function Oe(e){var t=r(e),n=3,i=2;if(t!=null){var{r:a,strokeWidth:o}=t,s=Number(a),c=Number(o);return(Number.isNaN(s)||s<0)&&(s=n),(Number.isNaN(c)||c<0)&&(c=i),{r:s,strokeWidth:c}}return{r:n,strokeWidth:i}}var ke=(e,t,n)=>E(e,`xAxis`,z(e,t),n),Ae=(e,t,n)=>h(e,`xAxis`,z(e,t),n),je=(e,t,n)=>E(e,`yAxis`,N(e,t),n),Me=(e,t,n)=>h(e,`yAxis`,N(e,t),n),Ne=i([F,ke,je,Ae,Me],(e,t,n,r,i)=>c(e,`xAxis`)?P(t,r,!1):P(n,i,!1)),Pe=i([le,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`area`).find(e=>e.id===t)),Fe=e=>{var t=F(e);return c(t,`xAxis`)?`yAxis`:`xAxis`},Ie=(e,t)=>Fe(e)===`yAxis`?N(e,t):z(e,t),Le=i([Pe,(e,t,n)=>f(e,Fe(e),Ie(e,t),n)],(e,t)=>{if(e!=null&&t!=null){var{stackId:n}=e,r=k(e);if(n!=null&&r!=null){var i=(t[n]?.stackedData)?.find(e=>e.key===r);if(i!=null)return i.map(e=>[e[0],e[1]])}}}),Re=i([F,ke,je,Ae,Me,Le,ue,Ne,Pe,ie],(e,t,n,r,i,a,o,s,c,l)=>{var{chartData:u,dataStartIndex:d,dataEndIndex:f}=o;if(!(c==null||e!==`horizontal`&&e!==`vertical`||t==null||n==null||r==null||i==null||r.length===0||i.length===0||s==null)){var{data:p}=c,m=p&&p.length>0?p:u?.slice(d,f+1);if(m!=null)return st({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:d,areaSettings:c,stackedData:a,displayedData:m,chartBaseValue:l,bandSize:s})}}),ze=[`id`],Be=[`activeDot`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`fill`,`fillOpacity`,`hide`,`isAnimationActive`,`legendType`,`stroke`,`xAxisId`,`yAxisId`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function Ve(e,t){if(e==null)return{};var n,r,i=He(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function He(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Ue(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ue(Object(n),!0).forEach(function(t){We(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ue(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function We(e,t,n){return(t=Ge(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ge(e){var t=Ke(e,`string`);return typeof t==`symbol`?t:t+``}function Ke(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Q(e,t){return e&&e!==`none`?e:t}var qe=e=>{var{dataKey:t,name:n,stroke:r,fill:i,legendType:a,hide:o}=e;return[{inactive:o,dataKey:t,type:a,color:Q(r,i),value:T(n,t),payload:e}]},Je=/*#__PURE__*/ V.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:O,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:T(o,t),hide:s,type:l,color:Q(r,a),unit:c,graphicalItemId:u}};return/*#__PURE__*/ V.createElement(oe,{tooltipEntrySettings:d})});function Ye(e){var{clipPathId:t,points:n,props:r}=e,{needClip:i,dot:a,dataKey:o}=r,s=S(r);return/*#__PURE__*/ V.createElement(Ce,{points:n,dot:a,className:`recharts-area-dots`,dotClassName:`recharts-area-dot`,dataKey:o,baseProps:s,needClip:i,clipPathId:t})}function Xe(e){var{showLabels:t,children:n,points:r}=e,i=r.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,parentViewBox:void 0,viewBox:t,fill:void 0})});return/*#__PURE__*/ V.createElement(g,{value:t?i:void 0},n)}function Ze(e){var{points:t,baseLine:n,needClip:r,clipPathId:i,props:a}=e,{layout:o,type:s,stroke:c,connectNulls:l,isRange:u}=a,{id:d}=a,f=Ve(a,ze),p=S(f),m=A(f);return/*#__PURE__*/ V.createElement(V.Fragment,null,t?.length>1&&/*#__PURE__*/ V.createElement(j,{clipPath:r?`url(#clipPath-${i})`:void 0},/*#__PURE__*/ V.createElement(R,X({},m,{id:d,points:t,connectNulls:l,type:s,baseLine:n,layout:o,stroke:`none`,className:`recharts-area-area`})),c!==`none`&&/*#__PURE__*/ V.createElement(R,X({},p,{className:`recharts-area-curve`,layout:o,type:s,connectNulls:l,fill:`none`,points:t})),c!==`none`&&u&&Array.isArray(n)&&/*#__PURE__*/ V.createElement(R,X({},p,{className:`recharts-area-curve`,layout:o,type:s,connectNulls:l,fill:`none`,points:n}))),/*#__PURE__*/ V.createElement(Ye,{points:t,props:f,clipPathId:i}))}function Qe(e){var{alpha:t,baseLine:n,points:r,strokeWidth:i}=e,a=r[0]?.y,o=r[r.length-1]?.y;if(!L(a)||!L(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.x||0));return p(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.x||0),c)),p(c)?/*#__PURE__*/ V.createElement(`rect`,{x:0,y:a<o?a:a-s,width:c+(i?parseInt(`${i}`,10):1),height:Math.floor(s)}):null}function $e(e){var{alpha:t,baseLine:n,points:r,strokeWidth:i}=e,a=r[0]?.x,o=r[r.length-1]?.x;if(!L(a)||!L(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.y||0));return p(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.y||0),c)),p(c)?/*#__PURE__*/ V.createElement(`rect`,{x:a<o?a:a-s,y:0,width:s,height:Math.floor(c+(i?parseInt(`${i}`,10):1))}):null}function et(e){var{alpha:t,layout:n,points:r,baseLine:i,strokeWidth:a}=e;return n===`vertical`?/*#__PURE__*/ V.createElement(Qe,{alpha:t,points:r,baseLine:i,strokeWidth:a}):/*#__PURE__*/ V.createElement($e,{alpha:t,points:r,baseLine:i,strokeWidth:a})}function tt(e){var{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:o}=e,{points:s,baseLine:c,isAnimationActive:l,animationBegin:u,animationDuration:d,animationEasing:f,onAnimationStart:m,onAnimationEnd:h}=r,g=(0,V.useMemo)(()=>({points:s,baseLine:c}),[s,c]),_=de(g,`recharts-area-`),y=ce(),[b,x]=(0,V.useState)(!1),S=!b,C=(0,V.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),ee=(0,V.useCallback)(()=>{typeof m==`function`&&m(),x(!0)},[m]);if(y==null)return null;var w=i.current,T=o.current;return/*#__PURE__*/ V.createElement(Xe,{showLabels:S,points:s},r.children,/*#__PURE__*/ V.createElement(ne,{animationId:_,begin:u,duration:d,isActive:l,easing:f,onAnimationEnd:C,onAnimationStart:ee,key:_},e=>{if(w){var u=w.length/s.length,d=e===1?s:s.map((t,n)=>{var r=Math.floor(n*u);if(w[r]){var i=w[r];return Z(Z({},t),{},{x:B(i.x,t.x,e),y:B(i.y,t.y,e)})}return t}),f=p(c)?B(T,c,e):D(c)||a(c)?B(T,0,e):c.map((t,n)=>{var r=Math.floor(n*u);if(Array.isArray(T)&&T[r]){var i=T[r];return Z(Z({},t),{},{x:B(i.x,t.x,e),y:B(i.y,t.y,e)})}return t});return e>0&&(i.current=d,o.current=f),/*#__PURE__*/ V.createElement(Ze,{points:d,baseLine:f,needClip:t,clipPathId:n,props:r})}return e>0&&(i.current=s,o.current=c),/*#__PURE__*/ V.createElement(j,null,l&&/*#__PURE__*/ V.createElement(`defs`,null,/*#__PURE__*/ V.createElement(`clipPath`,{id:`animationClipPath-${n}`},/*#__PURE__*/ V.createElement(et,{alpha:e,points:s,baseLine:c,layout:y,strokeWidth:r.strokeWidth}))),/*#__PURE__*/ V.createElement(j,{clipPath:`url(#animationClipPath-${n})`},/*#__PURE__*/ V.createElement(Ze,{points:s,baseLine:c,needClip:t,clipPathId:n,props:r})))}),/*#__PURE__*/ V.createElement(v,{label:r.label}))}function nt(e){var{needClip:t,clipPathId:n,props:r}=e,i=(0,V.useRef)(null),a=(0,V.useRef)();return/*#__PURE__*/ V.createElement(tt,{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:a})}var rt=class extends V.PureComponent{render(){var{hide:e,dot:n,points:r,className:i,top:a,left:o,needClip:s,xAxisId:c,yAxisId:l,width:u,height:f,id:p,baseLine:m,zIndex:h}=this.props;if(e)return null;var g=t(`recharts-area`,i),_=p,{r:v,strokeWidth:y}=Oe(n),b=ae(n),x=v*2+y,S=s?`url(#clipPath-${b?``:`dots-`}${_})`:void 0;return/*#__PURE__*/ V.createElement(d,{zIndex:h},/*#__PURE__*/ V.createElement(j,{className:g},s&&/*#__PURE__*/ V.createElement(`defs`,null,/*#__PURE__*/ V.createElement(me,{clipPathId:_,xAxisId:c,yAxisId:l}),!b&&/*#__PURE__*/ V.createElement(`clipPath`,{id:`clipPath-dots-${_}`},/*#__PURE__*/ V.createElement(`rect`,{x:o-x/2,y:a-x/2,width:u+x,height:f+x}))),/*#__PURE__*/ V.createElement(nt,{needClip:s,clipPathId:_,props:this.props})),/*#__PURE__*/ V.createElement(Y,{points:r,mainColor:Q(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:S}),this.props.isRange&&Array.isArray(m)&&/*#__PURE__*/ V.createElement(Y,{points:m,mainColor:Q(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:S}))}},it={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!1,fill:`#3182bd`,fillOpacity:.6,hide:!1,isAnimationActive:`auto`,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,type:`linear`,label:!1,xAxisId:0,yAxisId:0,zIndex:M.area};function at(e){var{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,connectNulls:a,dot:o,fill:s,fillOpacity:c,hide:l,isAnimationActive:u,legendType:d,stroke:f,xAxisId:p,yAxisId:h}=e,g=Ve(e,Be),v=se(),y=m(),{needClip:b}=ee(p,h),x=I(),{points:S,isRange:C,baseLine:T}=_(t=>Re(t,e.id,x))??{},E=w();if(v!==`horizontal`&&v!==`vertical`||E==null||y!==`AreaChart`&&y!==`ComposedChart`)return null;var{height:D,width:O,x:k,y:A}=E;return!S||!S.length?null:/*#__PURE__*/ V.createElement(rt,X({},g,{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,baseLine:T,connectNulls:a,dot:o,fill:s,fillOpacity:c,height:D,hide:l,layout:v,isAnimationActive:u,isRange:C,legendType:d,needClip:b,points:S,stroke:f,width:O,left:k,top:A,xAxisId:p,yAxisId:h}))}var ot=(e,t,n,r,i)=>{var a=n??t;if(p(a))return a;var o=e===`horizontal`?i:r,s=o.scale.domain();if(o.type===`number`){var c=Math.max(s[0],s[1]),l=Math.min(s[0],s[1]);return a===`dataMin`?l:a===`dataMax`||c<0?c:Math.max(Math.min(s[0],s[1]),0)}return a===`dataMin`?s[0]:a===`dataMax`?s[1]:s[0]};function st(e){var{areaSettings:{connectNulls:t,baseValue:n,dataKey:r},stackedData:i,layout:a,chartBaseValue:s,xAxis:c,yAxis:l,displayedData:d,dataStartIndex:f,xAxisTicks:p,yAxisTicks:m,bandSize:h}=e,g=i&&i.length,_=ot(a,s,n,c,l),v=a===`horizontal`,y=!1,b=d.map((e,n)=>{var a;if(g)a=i[f+n];else{var s=u(e,r);Array.isArray(s)?(a=s,y=!0):a=[_,s]}var d=a?.[1]??null,b=d==null||g&&!t&&u(e,r)==null;return v?{x:o({axis:c,ticks:p,bandSize:h,entry:e,index:n}),y:b?null:l.scale.map(d)??null,value:a,payload:e}:{x:b?null:c.scale.map(d)??null,y:o({axis:l,ticks:m,bandSize:h,entry:e,index:n}),value:a,payload:e}});return{points:b,baseLine:(g||y?b.map(e=>{var t=Array.isArray(e.value)?e.value[0]:null;return v?{x:e.x,y:t!=null&&e.y!=null?l.scale.map(t)??null:null,payload:e.payload}:{x:t==null?null:c.scale.map(t)??null,y:e.y,payload:e.payload}}):v?l.scale.map(_):c.scale.map(_))??0,isRange:y}}function ct(e){var t=y(e,it),n=I();return/*#__PURE__*/ V.createElement(s,{id:t.id,type:`area`},e=>/*#__PURE__*/ V.createElement(V.Fragment,null,/*#__PURE__*/ V.createElement(b,{legendPayload:qe(t)}),/*#__PURE__*/ V.createElement(Je,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),/*#__PURE__*/ V.createElement(l,{type:`area`,id:e,data:t.data,dataKey:t.dataKey,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,stackId:pe(t.stackId),hide:t.hide,barSize:void 0,baseValue:t.baseValue,isPanorama:n,connectNulls:t.connectNulls}),/*#__PURE__*/ V.createElement(at,X({},t,{id:e}))))}var $=/*#__PURE__*/ V.memo(ct,re);$.displayName=`Area`;export{$ as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{nt as t}from"./vendor-lthmb2su.js";import{C as n}from"./vendor-react-ggbyvons.js";import{$t as r,At as i,Bt as a,Ct as o,D as s,Dt as c,E as l,Et as u,F as d,G as f,Ht as p,I as m,K as h,M as g,Mt as _,N as v,Nt as y,O as b,Pt as x,Qt as S,R as C,S as ee,T as w,Tt as T,U as E,Vt as D,Wt as O,X as k,Xt as A,Yt as j,Z as M,Zt as te,b as N,bt as P,ct as ne,dt as re,et as ie,ft as F,gt as I,j as ae,k as oe,kt as L,mt as se,pt as ce,q as le,rt as ue,st as de,ut as R,w as fe,wt as pe,x as me,y as z,zt as B}from"./chart-dbzd0ka8.js";var V=/* @__PURE__ */ e(n());function H(){return H=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},H.apply(null,arguments)}var U=e=>{var{cx:n,cy:r,r:i,className:a}=e,o=t(`recharts-dot`,a);return p(n)&&p(r)&&p(i)?/*#__PURE__*/ V.createElement(`circle`,H({},S(e),x(e),{className:o,cx:n,cy:r,r:i})):null},he=[`points`];function W(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function G(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?W(Object(n),!0).forEach(function(t){ge(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ge(e,t,n){return(t=_e(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _e(e){var t=ve(e,`string`);return typeof t==`symbol`?t:t+``}function ve(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function K(){return K=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},K.apply(null,arguments)}function ye(e,t){if(e==null)return{};var n,r,i=be(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function be(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function xe(e){var{option:n,dotProps:r,className:i}=e;if(/*#__PURE__*/ (0,V.isValidElement)(n))return/*#__PURE__*/ (0,V.cloneElement)(n,r);if(typeof n==`function`)return n(r);var a=t(i,typeof n==`boolean`?``:n.className),o=r??{},{points:s}=o,c=ye(o,he);return/*#__PURE__*/ V.createElement(U,K({},c,{className:a}))}function Se(e,t){return e==null?!1:t?!0:e.length===1}function Ce(e){var{points:t,dot:n,className:r,dotClassName:i,dataKey:a,baseProps:o,needClip:s,clipPathId:c,zIndex:l=M.scatter}=e;if(!Se(t,n))return null;var u=ae(n),f=te(n),p=t.map((e,r)=>{var s=G(G(G({r:3},o),f),{},{index:r,cx:e.x??void 0,cy:e.y??void 0,dataKey:a,value:e.value,payload:e.payload,points:t});return/*#__PURE__*/ V.createElement(xe,{key:`dot-${r}`,option:n,dotProps:s,className:i})}),m={};return s&&c!=null&&(m.clipPath=`url(#clipPath-${u?``:`dots-`}${c})`),/*#__PURE__*/ V.createElement(d,{zIndex:l},/*#__PURE__*/ V.createElement(j,K({className:r},m),p))}function q(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function J(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?q(Object(n),!0).forEach(function(t){we(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):q(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function we(e,t,n){return(t=Te(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Te(e){var t=Ee(e,`string`);return typeof t==`symbol`?t:t+``}function Ee(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var De=e=>{var{point:t,childIndex:n,mainColor:i,activeDot:a,dataKey:o,clipPath:s}=e;if(a===!1||t.x==null||t.y==null)return null;var c=J(J(J({},{index:n,dataKey:o,cx:t.x,cy:t.y,r:4,fill:i??`none`,strokeWidth:2,stroke:`#fff`,payload:t.payload,value:t.value}),r(a)),x(a)),l=/*#__PURE__*/ (0,V.isValidElement)(a)?/*#__PURE__*/ (0,V.cloneElement)(a,c):typeof a==`function`?a(c):/*#__PURE__*/ V.createElement(U,c);return/*#__PURE__*/ V.createElement(j,{className:`recharts-active-dot`,clipPath:s},l)};function Y(e){var{points:t,mainColor:n,activeDot:r,itemDataKey:i,clipPath:a,zIndex:o=M.activeDot}=e,s=_(C),c=fe();if(t==null||c==null)return null;var l=t.find(e=>c.includes(e.payload));return D(l)?null:/*#__PURE__*/ V.createElement(d,{zIndex:o},/*#__PURE__*/ V.createElement(De,{point:l,childIndex:Number(s),mainColor:n,dataKey:i,activeDot:r,clipPath:a}))}function Oe(e){var t=r(e),n=3,i=2;if(t!=null){var{r:a,strokeWidth:o}=t,s=Number(a),c=Number(o);return(Number.isNaN(s)||s<0)&&(s=n),(Number.isNaN(c)||c<0)&&(c=i),{r:s,strokeWidth:c}}return{r:n,strokeWidth:i}}var ke=(e,t,n)=>E(e,`xAxis`,z(e,t),n),Ae=(e,t,n)=>h(e,`xAxis`,z(e,t),n),je=(e,t,n)=>E(e,`yAxis`,N(e,t),n),Me=(e,t,n)=>h(e,`yAxis`,N(e,t),n),Ne=i([F,ke,je,Ae,Me],(e,t,n,r,i)=>c(e,`xAxis`)?P(t,r,!1):P(n,i,!1)),Pe=i([le,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`area`).find(e=>e.id===t)),Fe=e=>{var t=F(e);return c(t,`xAxis`)?`yAxis`:`xAxis`},Ie=(e,t)=>Fe(e)===`yAxis`?N(e,t):z(e,t),Le=i([Pe,(e,t,n)=>f(e,Fe(e),Ie(e,t),n)],(e,t)=>{if(e!=null&&t!=null){var{stackId:n}=e,r=k(e);if(n!=null&&r!=null){var i=(t[n]?.stackedData)?.find(e=>e.key===r);if(i!=null)return i.map(e=>[e[0],e[1]])}}}),Re=i([F,ke,je,Ae,Me,Le,ue,Ne,Pe,ie],(e,t,n,r,i,a,o,s,c,l)=>{var{chartData:u,dataStartIndex:d,dataEndIndex:f}=o;if(!(c==null||e!==`horizontal`&&e!==`vertical`||t==null||n==null||r==null||i==null||r.length===0||i.length===0||s==null)){var{data:p}=c,m=p&&p.length>0?p:u?.slice(d,f+1);if(m!=null)return st({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:d,areaSettings:c,stackedData:a,displayedData:m,chartBaseValue:l,bandSize:s})}}),ze=[`id`],Be=[`activeDot`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`fill`,`fillOpacity`,`hide`,`isAnimationActive`,`legendType`,`stroke`,`xAxisId`,`yAxisId`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(null,arguments)}function Ve(e,t){if(e==null)return{};var n,r,i=He(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function He(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Ue(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Z(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ue(Object(n),!0).forEach(function(t){We(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ue(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function We(e,t,n){return(t=Ge(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ge(e){var t=Ke(e,`string`);return typeof t==`symbol`?t:t+``}function Ke(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Q(e,t){return e&&e!==`none`?e:t}var qe=e=>{var{dataKey:t,name:n,stroke:r,fill:i,legendType:a,hide:o}=e;return[{inactive:o,dataKey:t,type:a,color:Q(r,i),value:T(n,t),payload:e}]},Je=/*#__PURE__*/ V.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:O,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:T(o,t),hide:s,type:l,color:Q(r,a),unit:c,graphicalItemId:u}};return/*#__PURE__*/ V.createElement(oe,{tooltipEntrySettings:d})});function Ye(e){var{clipPathId:t,points:n,props:r}=e,{needClip:i,dot:a,dataKey:o}=r,s=S(r);return/*#__PURE__*/ V.createElement(Ce,{points:n,dot:a,className:`recharts-area-dots`,dotClassName:`recharts-area-dot`,dataKey:o,baseProps:s,needClip:i,clipPathId:t})}function Xe(e){var{showLabels:t,children:n,points:r}=e,i=r.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,parentViewBox:void 0,viewBox:t,fill:void 0})});return/*#__PURE__*/ V.createElement(g,{value:t?i:void 0},n)}function Ze(e){var{points:t,baseLine:n,needClip:r,clipPathId:i,props:a}=e,{layout:o,type:s,stroke:c,connectNulls:l,isRange:u}=a,{id:d}=a,f=Ve(a,ze),p=S(f),m=A(f);return/*#__PURE__*/ V.createElement(V.Fragment,null,t?.length>1&&/*#__PURE__*/ V.createElement(j,{clipPath:r?`url(#clipPath-${i})`:void 0},/*#__PURE__*/ V.createElement(R,X({},m,{id:d,points:t,connectNulls:l,type:s,baseLine:n,layout:o,stroke:`none`,className:`recharts-area-area`})),c!==`none`&&/*#__PURE__*/ V.createElement(R,X({},p,{className:`recharts-area-curve`,layout:o,type:s,connectNulls:l,fill:`none`,points:t})),c!==`none`&&u&&Array.isArray(n)&&/*#__PURE__*/ V.createElement(R,X({},p,{className:`recharts-area-curve`,layout:o,type:s,connectNulls:l,fill:`none`,points:n}))),/*#__PURE__*/ V.createElement(Ye,{points:t,props:f,clipPathId:i}))}function Qe(e){var{alpha:t,baseLine:n,points:r,strokeWidth:i}=e,a=r[0]?.y,o=r[r.length-1]?.y;if(!L(a)||!L(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.x||0));return p(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.x||0),c)),p(c)?/*#__PURE__*/ V.createElement(`rect`,{x:0,y:a<o?a:a-s,width:c+(i?parseInt(`${i}`,10):1),height:Math.floor(s)}):null}function $e(e){var{alpha:t,baseLine:n,points:r,strokeWidth:i}=e,a=r[0]?.x,o=r[r.length-1]?.x;if(!L(a)||!L(o))return null;var s=t*Math.abs(a-o),c=Math.max(...r.map(e=>e.y||0));return p(n)?c=Math.max(n,c):n&&Array.isArray(n)&&n.length&&(c=Math.max(...n.map(e=>e.y||0),c)),p(c)?/*#__PURE__*/ V.createElement(`rect`,{x:a<o?a:a-s,y:0,width:s,height:Math.floor(c+(i?parseInt(`${i}`,10):1))}):null}function et(e){var{alpha:t,layout:n,points:r,baseLine:i,strokeWidth:a}=e;return n===`vertical`?/*#__PURE__*/ V.createElement(Qe,{alpha:t,points:r,baseLine:i,strokeWidth:a}):/*#__PURE__*/ V.createElement($e,{alpha:t,points:r,baseLine:i,strokeWidth:a})}function tt(e){var{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:o}=e,{points:s,baseLine:c,isAnimationActive:l,animationBegin:u,animationDuration:d,animationEasing:f,onAnimationStart:m,onAnimationEnd:h}=r,g=(0,V.useMemo)(()=>({points:s,baseLine:c}),[s,c]),_=de(g,`recharts-area-`),y=ce(),[b,x]=(0,V.useState)(!1),S=!b,C=(0,V.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),ee=(0,V.useCallback)(()=>{typeof m==`function`&&m(),x(!0)},[m]);if(y==null)return null;var w=i.current,T=o.current;return/*#__PURE__*/ V.createElement(Xe,{showLabels:S,points:s},r.children,/*#__PURE__*/ V.createElement(ne,{animationId:_,begin:u,duration:d,isActive:l,easing:f,onAnimationEnd:C,onAnimationStart:ee,key:_},e=>{if(w){var u=w.length/s.length,d=e===1?s:s.map((t,n)=>{var r=Math.floor(n*u);if(w[r]){var i=w[r];return Z(Z({},t),{},{x:B(i.x,t.x,e),y:B(i.y,t.y,e)})}return t}),f=p(c)?B(T,c,e):D(c)||a(c)?B(T,0,e):c.map((t,n)=>{var r=Math.floor(n*u);if(Array.isArray(T)&&T[r]){var i=T[r];return Z(Z({},t),{},{x:B(i.x,t.x,e),y:B(i.y,t.y,e)})}return t});return e>0&&(i.current=d,o.current=f),/*#__PURE__*/ V.createElement(Ze,{points:d,baseLine:f,needClip:t,clipPathId:n,props:r})}return e>0&&(i.current=s,o.current=c),/*#__PURE__*/ V.createElement(j,null,l&&/*#__PURE__*/ V.createElement(`defs`,null,/*#__PURE__*/ V.createElement(`clipPath`,{id:`animationClipPath-${n}`},/*#__PURE__*/ V.createElement(et,{alpha:e,points:s,baseLine:c,layout:y,strokeWidth:r.strokeWidth}))),/*#__PURE__*/ V.createElement(j,{clipPath:`url(#animationClipPath-${n})`},/*#__PURE__*/ V.createElement(Ze,{points:s,baseLine:c,needClip:t,clipPathId:n,props:r})))}),/*#__PURE__*/ V.createElement(v,{label:r.label}))}function nt(e){var{needClip:t,clipPathId:n,props:r}=e,i=(0,V.useRef)(null),a=(0,V.useRef)();return/*#__PURE__*/ V.createElement(tt,{needClip:t,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:a})}var rt=class extends V.PureComponent{render(){var{hide:e,dot:n,points:r,className:i,top:a,left:o,needClip:s,xAxisId:c,yAxisId:l,width:u,height:f,id:p,baseLine:m,zIndex:h}=this.props;if(e)return null;var g=t(`recharts-area`,i),_=p,{r:v,strokeWidth:y}=Oe(n),b=ae(n),x=v*2+y,S=s?`url(#clipPath-${b?``:`dots-`}${_})`:void 0;return/*#__PURE__*/ V.createElement(d,{zIndex:h},/*#__PURE__*/ V.createElement(j,{className:g},s&&/*#__PURE__*/ V.createElement(`defs`,null,/*#__PURE__*/ V.createElement(me,{clipPathId:_,xAxisId:c,yAxisId:l}),!b&&/*#__PURE__*/ V.createElement(`clipPath`,{id:`clipPath-dots-${_}`},/*#__PURE__*/ V.createElement(`rect`,{x:o-x/2,y:a-x/2,width:u+x,height:f+x}))),/*#__PURE__*/ V.createElement(nt,{needClip:s,clipPathId:_,props:this.props})),/*#__PURE__*/ V.createElement(Y,{points:r,mainColor:Q(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:S}),this.props.isRange&&Array.isArray(m)&&/*#__PURE__*/ V.createElement(Y,{points:m,mainColor:Q(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:S}))}},it={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!1,fill:`#3182bd`,fillOpacity:.6,hide:!1,isAnimationActive:`auto`,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,type:`linear`,label:!1,xAxisId:0,yAxisId:0,zIndex:M.area};function at(e){var{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,connectNulls:a,dot:o,fill:s,fillOpacity:c,hide:l,isAnimationActive:u,legendType:d,stroke:f,xAxisId:p,yAxisId:h}=e,g=Ve(e,Be),v=se(),y=m(),{needClip:b}=ee(p,h),x=I(),{points:S,isRange:C,baseLine:T}=_(t=>Re(t,e.id,x))??{},E=w();if(v!==`horizontal`&&v!==`vertical`||E==null||y!==`AreaChart`&&y!==`ComposedChart`)return null;var{height:D,width:O,x:k,y:A}=E;return!S||!S.length?null:/*#__PURE__*/ V.createElement(rt,X({},g,{activeDot:t,animationBegin:n,animationDuration:r,animationEasing:i,baseLine:T,connectNulls:a,dot:o,fill:s,fillOpacity:c,height:D,hide:l,layout:v,isAnimationActive:u,isRange:C,legendType:d,needClip:b,points:S,stroke:f,width:O,left:k,top:A,xAxisId:p,yAxisId:h}))}var ot=(e,t,n,r,i)=>{var a=n??t;if(p(a))return a;var o=e===`horizontal`?i:r,s=o.scale.domain();if(o.type===`number`){var c=Math.max(s[0],s[1]),l=Math.min(s[0],s[1]);return a===`dataMin`?l:a===`dataMax`||c<0?c:Math.max(Math.min(s[0],s[1]),0)}return a===`dataMin`?s[0]:a===`dataMax`?s[1]:s[0]};function st(e){var{areaSettings:{connectNulls:t,baseValue:n,dataKey:r},stackedData:i,layout:a,chartBaseValue:s,xAxis:c,yAxis:l,displayedData:d,dataStartIndex:f,xAxisTicks:p,yAxisTicks:m,bandSize:h}=e,g=i&&i.length,_=ot(a,s,n,c,l),v=a===`horizontal`,y=!1,b=d.map((e,n)=>{var a;if(g)a=i[f+n];else{var s=u(e,r);Array.isArray(s)?(a=s,y=!0):a=[_,s]}var d=a?.[1]??null,b=d==null||g&&!t&&u(e,r)==null;return v?{x:o({axis:c,ticks:p,bandSize:h,entry:e,index:n}),y:b?null:l.scale.map(d)??null,value:a,payload:e}:{x:b?null:c.scale.map(d)??null,y:o({axis:l,ticks:m,bandSize:h,entry:e,index:n}),value:a,payload:e}});return{points:b,baseLine:(g||y?b.map(e=>{var t=Array.isArray(e.value)?e.value[0]:null;return v?{x:e.x,y:t!=null&&e.y!=null?l.scale.map(t)??null:null,payload:e.payload}:{x:t==null?null:c.scale.map(t)??null,y:e.y,payload:e.payload}}):v?l.scale.map(_):c.scale.map(_))??0,isRange:y}}function ct(e){var t=y(e,it),n=I();return/*#__PURE__*/ V.createElement(s,{id:t.id,type:`area`},e=>/*#__PURE__*/ V.createElement(V.Fragment,null,/*#__PURE__*/ V.createElement(b,{legendPayload:qe(t)}),/*#__PURE__*/ V.createElement(Je,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),/*#__PURE__*/ V.createElement(l,{type:`area`,id:e,data:t.data,dataKey:t.dataKey,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,stackId:pe(t.stackId),hide:t.hide,barSize:void 0,baseValue:t.baseValue,isPanorama:n,connectNulls:t.connectNulls}),/*#__PURE__*/ V.createElement(at,X({},t,{id:e}))))}var $=/*#__PURE__*/ V.memo(ct,re);$.displayName=`Area`;export{$ as t};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{ot as t,pt as n,rt as r,ut as i}from"./vendor-lthmb2su.js";import{C as a,S as o,_ as s,a as c,d as l,h as u,l as d,p as f,r as p,y as m}from"./vendor-react-ggbyvons.js";import{Et as h,Ut as g,Vt as _,Xt as v,c as y,cn as b,d as x,dn as S,et as ee,f as C,fn as w,h as T,it as E,m as D,p as te,rt as O,un as k,ut as A}from"./vendor-ui-kvc1qhaw.js";import{n as j,t as M}from"./button-loz3etho.js";import{It as N,Nt as P,O as F,Qt as I,l as L,qt as ne,wt as re}from"./vendor-icons-mxz7yi04.js";import{a as ie,i as R,n as ae,r as oe,t as se}from"./automationFormat-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{ot as t,pt as n,rt as r,ut as i}from"./vendor-lthmb2su.js";import{C as a,S as o,_ as s,a as c,d as l,h as u,l as d,p as f,r as p,y as m}from"./vendor-react-ggbyvons.js";import{Et as h,Ut as g,Vt as _,Xt as v,c as y,cn as b,d as x,dn as S,et as ee,f as C,fn as w,h as T,it as E,m as D,p as te,rt as O,un as k,ut as A}from"./vendor-ui-kvc1qhaw.js";import{n as j,t as M}from"./button-loz3etho.js";import{It as N,Nt as P,O as F,Qt as I,l as L,qt as ne,wt as re}from"./vendor-icons-mxz7yi04.js";import{a as ie,i as R,n as ae,r as oe,t as se}from"./automationFormat-nmiq4qj2.js";import{t as ce}from"./plus-gndielka.js";import{a as le,n as ue,t as de}from"./tooltip-c9bbl0em.js";import{$ as fe,Ft as pe,It as me,Lt as he,Mt as ge,Nt as _e,Pt as ve,Q as z,Rt as ye,at as be,it as xe,jt as Se,st as Ce}from"./junior-gfsokzu9.js";import{a as we,i as B,o as Te,r as Ee,t as V}from"./http-cdq677qt.js";import{a as De,t as H}from"./styles-j0007fov.js";import{t as U}from"./Card-hy4bfgq7.js";import{t as Oe}from"./skeleton-h6p83ux1.js";import{t as ke}from"./PageContentSkeleton-b7dkba0l.js";import{d as Ae,n as je,r as Me,s as Ne,t as Pe,u as Fe}from"./PageHeader-kvp1fo95.js";import{b as Ie,k as Le,l as Re,n as W,p as ze,y as Be}from"./format-c4b0iyrx.js";import{t as Ve}from"./SecondaryNavigation-m358iuko.js";import{t as He}from"./PageLayout-l6dhbimv.js";import{t as Ue}from"./AnchorHeading-cp3vx8qa.js";import{r as We,t as G}from"./searchParams-moqjgi65.js";import{A as Ge,At as Ke,F as qe,Gt as Je,Ht as Ye,I as Xe,K as Ze,L as Qe,M as $e,Mt as et,N as tt,Ot as nt,P as rt,R as it,Tt as at,Ut as ot,X as st,_t as ct,bt as K,en as lt,gt as q,ht as ut,j as dt,k as ft,kt as pt,q as mt,vt as ht,yt as J,z as gt}from"../client-mgf2bxi7.js";import{t as Y}from"./FormNotice-mmzuj60h.js";import{t as X}from"./native-select-jfknh8t4.js";import{i as _t,n as vt,r as yt,t as bt}from"./AutomationRunDetails-hyjcewq8.js";import{r as xt}from"./FilterBar-lsllb7tj.js";import{t as St}from"./SelectableRow-j8fwjsjz.js";import{C as Ct,a as wt,d as Tt,n as Et,o as Dt,s as Ot,t as kt}from"./chart-dbzd0ka8.js";import{n as At,t as jt}from"./BarChart-hdlbq093.js";import{t as Mt}from"./ChartLegend-c3e9l1vl.js"
|
|
2
2
|
/**
|
|
3
3
|
* @license lucide-react v1.17.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
6
6
|
* See the LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
;const Nt=I(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]);var Z=/* @__PURE__ */ e(a(),1),Q=o();function Pt({automation:e,editPath:r,editVariant:i,onDelete:a}){let o=dt(),s=n(),c=e.status===`completed`,l=e.status===`paused`,u=e.status===`blocked`,d=!c,f=l||u?`resume`:`pause`,m=t({mutationFn:async()=>{let t=`/api/automations/${encodeURIComponent(e.id)}`,n=await B(z,`${t}/edit`);if(n.status!==e.status)throw Error(`The Automation changed. Reload the page before trying again.`);return Te(z,`${t}/lifecycle`,{action:f,revision:n.revision})},onSuccess:async e=>{await s.invalidateQueries({queryKey:[`dashboard`,`automations`]}),o.add({title:e.status===`blocked`?`Automation is still blocked`:f===`pause`?`Automation paused`:`Automation resumed`,description:e.status===`blocked`?`Fix the reported requirement before resuming again.`:f===`pause`?`Work already queued or running may finish.`:`Future triggers are enabled.`,type:e.status===`blocked`?`warning`:`success`})}});return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 justify-items-stretch gap-3 md:justify-items-end`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-label":`Automation actions`,className:`flex flex-wrap items-center gap-2`,role:`group`,children:[c?null:/* @__PURE__ */ (0,Q.jsxs)(p,{className:j({variant:i}),to:r,children:[/* @__PURE__ */ (0,Q.jsx)(F,{"aria-hidden":`true`,size:14}),`Edit automation`]}),d?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(M,{disabled:m.isPending,onClick:()=>m.mutate(),children:m.isPending?`Updating…`:f===`pause`?`Pause`:`Resume`}),/* @__PURE__ */ (0,Q.jsxs)(it,{children:[/* @__PURE__ */ (0,Q.jsx)(tt,{render:/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`About pausing`,size:`icon`}),children:/* @__PURE__ */ (0,Q.jsx)(re,{"aria-hidden":`true`,size:16})}),/* @__PURE__ */ (0,Q.jsx)(ht,{side:`bottom`,align:`end`,"aria-label":`About pausing`,children:/* @__PURE__ */ (0,Q.jsxs)(Ke,{children:[`Pausing stops new runs. Work already queued or running may finish. Resuming skips missed runs and waits for the next scheduled time or new event.`,l&&e.statusReason?` Removing the pause keeps the block until you fix it and resume again.`:``]})})]})]}):null,/* @__PURE__ */ (0,Q.jsxs)(de,{children:[/* @__PURE__ */ (0,Q.jsx)(le,{render:/* @__PURE__ */ (0,Q.jsx)(M,{focusableWhenDisabled:!0,"aria-label":`Delete automation`,size:`icon`,variant:`danger`,onClick:e=>a(e.currentTarget),disabled:m.isPending,children:/* @__PURE__ */ (0,Q.jsx)(L,{"aria-hidden":`true`,size:16})})}),/* @__PURE__ */ (0,Q.jsx)(ue,{size:`compact`,children:`Delete automation`})]})]}),m.error?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-w-sm`,children:/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`Could not update this automation.`,children:m.error instanceof V?m.error.apiError??`Try again.`:m.error.message})}):null]})}function Ft(e){let[r,i]=(0,Z.useState)(!0),a=n(),o=dt(),s=t({mutationFn:()=>Ee(`/api/automations/${encodeURIComponent(e.automation.id)}`),onSuccess:async()=>{await a.invalidateQueries({queryKey:[`dashboard`,`automations`]}),e.onDeleted(),o.add({title:`Automation deleted`,description:e.automation.title,type:`success`}),i(!1)}});return/* @__PURE__ */ (0,Q.jsx)(ot,{open:r,onOpenChange:(e,t)=>{s.isPending?t.cancel():i(e)},onOpenChangeComplete:t=>{t||e.onClose()},children:/* @__PURE__ */ (0,Q.jsxs)(rt,{finalFocus:e.returnFocus,children:[/* @__PURE__ */ (0,Q.jsx)(pt,{children:`Delete automation?`}),/* @__PURE__ */ (0,Q.jsxs)(mt,{children:[`Delete`,` `,/* @__PURE__ */ (0,Q.jsx)(`strong`,{className:`font-medium text-dashboard-text`,children:e.automation.title}),`? This removes the Automation and stops future triggers. Work already queued or running may finish.`]}),s.error?/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`The automation could not be deleted. Try again.`}):null,/* @__PURE__ */ (0,Q.jsxs)(Ge,{children:[/* @__PURE__ */ (0,Q.jsx)(qe,{disabled:s.isPending,children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Je,{variant:`danger`,disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Deleting…`:`Delete automation`})]})]})})}function It(e,t){return typeof e.destination==`string`?e.destination===`task_creator`?`Creator · Direct message`:`${t.label} · ${t.visibility}`:e.destination.channelId===t.channelId&&e.destination.teamId===t.teamId?`${t.label} · ${t.visibility}`:`Saved destination · ${e.destination.channelId}`}const Lt=[`sunday`,`monday`,`tuesday`,`wednesday`,`thursday`,`friday`,`saturday`];function Rt(e){return{title:e.title??``,instruction:e.instruction,credentialMode:e.credentialMode,outcomes:e.outcomes,trigger:e.kind===`event`?e.trigger:void 0}}function zt(e){let t=e.schedule.recurrence;if(e.schedule.kind===`recurring`&&t){let{time:n,weekdays:r,...i}=t;return{kind:`recurring`,...i,timezone:e.schedule.timezone,time:`${String(n.hour).padStart(2,`0`)}:${String(n.minute).padStart(2,`0`)}`,weekdays:r?.flatMap(e=>Lt[e]??[])}}if(e.nextRunAtMs){let t=new Intl.DateTimeFormat(`en-CA`,{timeZone:e.schedule.timezone,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).formatToParts(e.nextRunAtMs),n=e=>t.find(t=>t.type===e)?.value??``;return{kind:`one_off`,timezone:e.schedule.timezone,timing:{type:`at`,date:`${n(`year`)}-${n(`month`)}-${n(`day`)}`,time:`${n(`hour`)}:${n(`minute`)}`}}}return{kind:`recurring`,frequency:`daily`,time:`09:00`,timezone:e.schedule.timezone}}function Bt(e,t){let n={};return t.title!==(e.title??``)&&(n.title=t.title),t.instruction!==e.instruction&&(n.instruction=t.instruction),t.credentialMode!==e.credentialMode&&(n.credentialMode=t.credentialMode),JSON.stringify(t.outcomes)!==JSON.stringify(e.outcomes)&&(n.outcomes=t.outcomes),e.kind===`scheduled`&&t.schedule&&(n.schedule=t.schedule),e.kind===`event`&&JSON.stringify(t.trigger)!==JSON.stringify(e.trigger)&&(n.trigger=t.trigger),n}const Vt={title:`Title`,instruction:`Instruction`,schedule:`Schedule`,trigger:`Trigger`,outcomes:`Where results go`,credentialMode:`Credentials`};function Ht(e){let t=Object.keys(Vt).filter(t=>e.changes[t]!==void 0),n=Ut(e.original),r=(t,n)=>Wt(t,n,e.summary);return/* @__PURE__ */ (0,Q.jsx)(`aside`,{"aria-label":`Your changes`,className:H(`min-w-0 lg:sticky lg:top-4 lg:self-start`,t.length===0&&`max-lg:hidden`),children:/* @__PURE__ */ (0,Q.jsxs)(U,{padding:`sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted`,children:`Your changes`}),t.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`No changes yet. Edit a section to see it here.`}):/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`m-0 grid list-none gap-3 p-0`,children:t.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`li`,{className:`grid min-w-0 gap-1 text-sm`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`font-medium`,children:Vt[t]}),/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`Undo ${Vt[t].toLowerCase()} change`,disabled:e.disabled,onClick:()=>e.onUndo(t),children:`Undo`})]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs text-dashboard-text-muted line-through decoration-dashboard-text-muted/50`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Saved: `}),r(n,t)]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`New: `}),r(e.changes,t)]})]},t))}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted`,children:`Saving creates a new version. It does not run this automation.`})]})})}function Ut(e){let t=Rt(e);return e.kind===`scheduled`?{...t,schedule:zt(e)}:t}function Wt(e,t,n){switch(t){case`title`:return e.title||`First line of the instruction`;case`instruction`:return e.instruction||`Empty`;case`credentialMode`:return e.credentialMode===`creator`?n.ownedByViewer?`Your connected accounts`:`${n.createdBy}'s connected accounts`:`System credentials only`;case`outcomes`:return e.outcomes?.length?e.outcomes.map(e=>It(e,n.destination)).join(`, `):`No success message`;case`schedule`:return e.schedule?Kt(e.schedule):`Not set`;case`trigger`:{let t=e.trigger;if(!t)return`Not set`;let n=t.identifier?`${t.label} · ${t.identifier}`:`Any ${t.label}`,r=Object.keys(t.match??{}).length;return[n,t.events.join(`, `),r?`${r} ${r===1?`filter`:`filters`}`:``].filter(Boolean).join(` · `)}}}const Gt={daily:`day`,weekly:`week`,monthly:`month`,yearly:`year`};function Kt(e){if(e.kind===`one_off`)return`Once on ${e.timing.date} at ${e.timing.time} (${e.timezone})`;let t=e.interval??1,n=Gt[e.frequency];return`Every ${t===1?n:`${t} ${n}s`}${e.frequency===`weekly`&&e.weekdays?.length?` on ${e.weekdays.map(e=>e.slice(0,1).toUpperCase()+e.slice(1,3)).join(`, `)}`:e.frequency===`monthly`&&e.dayOfMonth?` on day ${e.dayOfMonth}`:e.frequency===`yearly`&&e.month&&e.dayOfMonth?` on ${String(e.month).padStart(2,`0`)}-${String(e.dayOfMonth).padStart(2,`0`)}`:``} at ${e.time} (${e.timezone})`}function qt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function $(e){return/* @__PURE__ */ (0,Q.jsxs)(`section`,{className:H(`grid min-w-0 gap-5 border-t border-dashboard-border-emphasis py-8 md:grid-cols-[12rem_minmax(0,1fr)] md:gap-10`,e.changed&&`-ml-4 pl-4 shadow-[inset_2px_0_0_var(--color-dashboard-accent)] sm:-ml-5 sm:pl-5`),children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(Ue,{anchor:qt(e.title),className:`m-0 font-display text-lg font-medium`,title:e.title}),e.changed?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 text-xs text-dashboard-accent-text`,children:`Unsaved changes`}):null,e.detail?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-2 mb-0 text-sm leading-relaxed text-dashboard-text-muted`,children:e.detail}):null]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`grid min-w-0 content-start gap-5`,children:e.children})]})}function Jt(e){let t=e.value??zt(e.automation),[n,r]=(0,Z.useState)(e.value);(0,Z.useEffect)(()=>{let t=setTimeout(()=>r(e.value),300);return()=>clearTimeout(t)},[e.value]);let a=xe.safeParse(n),o=i({queryKey:[`dashboard`,`automation-schedule-preview`,e.automation.id,n],enabled:!!n&&a.success,retry:!1,queryFn:()=>Te(be,`/api/automations/${encodeURIComponent(e.automation.id)}/preview`,n)}),s=t.kind===`recurring`?t.frequency:`once`,c=t.kind===`recurring`?t.time:t.timing.time,l=e.value?o.data?.nextRunAtMs:e.automation.nextRunAtMs,u=e.value!==n||o.isFetching,d=o.error instanceof V?o.error.apiError:o.error?`Schedule preview could not be loaded. Try again.`:e.value&&!a.success&&!u?a.error.issues[0]?.message:void 0;return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-frequency`,children:`Repeat`}),/* @__PURE__ */ (0,Q.jsxs)(X,{id:`schedule-frequency`,value:s,onChange:n=>{let r=n.target.value;(r===`once`||r===`daily`||r===`weekly`||r===`monthly`||r===`yearly`)&&e.onChange(r===`once`?{kind:`one_off`,timezone:t.timezone??e.automation.schedule.timezone,timing:{type:`at`,date:``,time:c}}:{kind:`recurring`,timezone:t.timezone,time:c,frequency:r,interval:1,weekdays:r===`weekly`?[`monday`]:void 0,dayOfMonth:[`monthly`,`yearly`].includes(r)?1:void 0,month:r===`yearly`?1:void 0})},children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`once`,children:`Once`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`daily`,children:`Every day`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`weekly`,children:`Every week`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`monthly`,children:`Every month`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`yearly`,children:`Every year`})]})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-time`,children:`Time`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-time`,type:`time`,value:c,onChange:n=>e.onChange(t.kind===`recurring`?{...t,time:n.target.value}:{...t,timing:{type:`at`,date:t.timing.date,time:n.target.value}})})]})]}),t.kind===`recurring`?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t.frequency===`weekly`?/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-2 text-sm font-semibold`,children:`On`}),/* @__PURE__ */ (0,Q.jsx)(Fe,{className:`grid grid-cols-7 gap-1.5`,multiple:!0,onValueChange:n=>e.onChange({...t,weekdays:n}),value:t.weekdays??[],children:[...Lt.slice(1),Lt[0]].map(e=>/* @__PURE__ */ (0,Q.jsx)(Ae,{"aria-label":e,className:`h-auto min-h-11 min-w-0 border-dashboard-border-emphasis px-1 capitalize data-pressed:border-dashboard-focus/50 data-pressed:bg-dashboard-focus/10 data-pressed:text-dashboard-focus sm:min-h-10 sm:text-sm`,value:e,children:e.slice(0,3)},e))})]}):null,/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-interval`,children:`Interval`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-interval`,type:`number`,min:1,max:365,value:t.interval??1,onChange:n=>e.onChange({...t,interval:n.target.valueAsNumber})}),/* @__PURE__ */ (0,Q.jsx)(ut,{id:`schedule-interval-help`,children:`Number of calendar periods between runs.`})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-start`,children:`Start date`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-start`,type:`date`,value:t.startDate??``,onChange:n=>e.onChange({...t,startDate:n.target.value||void 0})})]})]}),t.frequency===`monthly`||t.frequency===`yearly`?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-day`,children:`Day of month`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-day`,type:`number`,min:1,max:31,value:t.dayOfMonth??1,onChange:n=>e.onChange({...t,dayOfMonth:n.target.valueAsNumber})})]}),t.frequency===`yearly`?/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-month`,children:`Month`}),/* @__PURE__ */ (0,Q.jsx)(X,{id:`schedule-month`,value:t.month??1,onChange:n=>e.onChange({...t,month:Number(n.target.value)}),children:Array.from({length:12},(e,t)=>/* @__PURE__ */ (0,Q.jsx)(`option`,{value:t+1,children:new Intl.DateTimeFormat(`en`,{month:`long`,timeZone:`UTC`}).format(new Date(Date.UTC(2026,t,1)))},t))})]}):null]}):null]}):/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-date`,children:`Date`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-date`,type:`date`,value:t.timing.date,onChange:n=>e.onChange({...t,timing:{type:`at`,time:c,date:n.target.value}})})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-timezone`,children:`Timezone`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-timezone`,list:`automation-timezones`,value:t.timezone??``,onChange:n=>e.onChange({...t,timezone:n.target.value})}),/* @__PURE__ */ (0,Q.jsx)(`datalist`,{id:`automation-timezones`,children:[`UTC`,...Intl.supportedValuesOf(`timeZone`)].map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{children:e},e))}),/* @__PURE__ */ (0,Q.jsx)(ut,{id:`schedule-timezone-help`,children:`Use an IANA timezone. The schedule follows local time, including daylight saving time.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{role:`status`,className:`flex gap-3 rounded-md bg-dashboard-fill-soft p-3 text-sm leading-relaxed`,children:[/* @__PURE__ */ (0,Q.jsx)(ie,{"aria-hidden":!0,size:17,className:`mt-0.5 shrink-0 text-dashboard-text-muted`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:u?`Checking schedule…`:d?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`text-rose-300`,children:d}),o.error?/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void o.refetch(),children:`Try again`}):null]}):l?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[`Next run`,` `,new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`,timeZone:e.value?o.data?.schedule.timezone??`UTC`:e.automation.schedule.timezone}).format(l)]}):`No next run.`})]}),e.value?/* @__PURE__ */ (0,Q.jsx)(M,{className:`w-fit`,onClick:()=>e.onChange(void 0),children:`Keep saved schedule`}):null]})}function Yt(e){return e.filters.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-1 text-xs text-dashboard-text-muted`,children:`No filters. Runs on every selected event.`}):/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`mt-1 text-xs text-dashboard-text-muted`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:`Every filter must match:`}),/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5`,children:e.filters.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{className:`break-words`,children:e},e))})]})}const Xt={resourceTypes:[],events:{},anyResourceFields:{}};function Zt(e,t){let n=e.events[t]?.reach;if(typeof n!=`object`)return;let r=n.anyOf.map(t=>e.anyResourceFields[t]?.description??t);return r.length===1?`needs a filter: ${r[0]}`:`needs one of these filters: ${r.join(`; or `)}`}function Qt(e){let[t,n]=(0,Z.useState)(),r=i({queryKey:[`dashboard`,`automation-event-catalog`],queryFn:({signal:e})=>B(fe,`/api/automations/event-catalog`,e),retry:!1}),a=r.data?.find(t=>t.namespace===e.value.namespace),o=a??Xt,s=a?.displayName??e.value.namespace,c=e.value.resourceType===void 0,l=ve(o,e.value),u=r.data?pe(o,e.value):[],d=!l||u.some(e=>e.reason!==`field_not_set`&&e.reason!==`filter_required`),f=r.data?.filter(e=>Se(e).length>0)??[],p=Object.entries(l?.fields??{}),m=p.filter(([t,n])=>e.value.match?.[t]!==void 0||ye(n,e.value.events).length===0),h=(t,n)=>{let r={...e.value.match};n===void 0?delete r[t]:r[t]=n,e.onChange({...e.value,match:r})};return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[r.error?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Event choices could not be loaded.`,children:[`Saved values are kept.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void r.refetch(),children:`Try again`})]}):r.isPending?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`status`,children:`Loading event choices…`}):null,d&&r.data?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Saved trigger · Kept unchanged`,children:[`Some saved values are not in the current catalog. You can edit other fields, or select a new resource type to replace the trigger.`,/* @__PURE__ */ (0,Q.jsx)($t,{displayName:s,source:o,trigger:e.value})]}):null,/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-resource`,children:d?`Replace trigger`:`Resource type`}),/* @__PURE__ */ (0,Q.jsxs)(X,{id:`trigger-resource`,value:d?``:`${e.value.namespace}:${e.value.resourceType??`*`}`,onChange:e=>{let[t,i]=e.target.value.split(`:`);if(i===`*`&&t){n({namespace:t,label:``,events:[]});return}let a=r.data?.find(e=>e.namespace===t)?.resourceTypes.find(e=>e.type===i);t&&a&&n({namespace:t,resourceType:a.type,identifier:``,label:``,events:[]})},children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:``,disabled:!0,children:`Keep saved trigger`}),f.map(e=>/* @__PURE__ */ (0,Q.jsxs)(`option`,{value:`${e.namespace}:*`,children:[e.displayName,` · any resource`]},`${e.namespace}:*`)),r.data?.flatMap(e=>e.resourceTypes.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`option`,{value:`${e.namespace}:${t.type}`,children:[e.displayName,` · `,t.type.replaceAll(`_`,` `)]},`${e.namespace}:${t.type}`)))]})]}),/* @__PURE__ */ (0,Q.jsx)(ot,{onOpenChange:e=>{e||n(void 0)},open:t!==void 0,children:/* @__PURE__ */ (0,Q.jsxs)(rt,{children:[/* @__PURE__ */ (0,Q.jsx)(pt,{children:`Replace the saved trigger?`}),/* @__PURE__ */ (0,Q.jsx)(mt,{children:`Its resource, events, and filters will be cleared.`}),/* @__PURE__ */ (0,Q.jsxs)(Ge,{children:[/* @__PURE__ */ (0,Q.jsx)(qe,{children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Je,{onClick:()=>{t&&e.onChange(t),n(void 0)},variant:`primary`,children:`Replace trigger`})]})]})}),!d&&l?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-label`,children:c?`Trigger name`:`Resource name`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`trigger-label`,value:e.value.label,onChange:t=>e.onChange({...e.value,label:t.target.value})})]}),c?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:`Runs for every resource that the filters match.`}):/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-identifier`,children:`Resource identifier`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`trigger-identifier`,value:e.value.identifier??``,onChange:t=>e.onChange({...e.value,identifier:t.target.value})}),/* @__PURE__ */ (0,Q.jsx)(ut,{id:`trigger-identifier-help`,children:`Use the exact provider resource identifier, not its display name.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-2 text-sm font-semibold`,children:`Run on these events`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis`,children:l.events.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-start gap-3 px-3 py-3 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(at,{className:`mt-0.5`,checked:e.value.events.includes(t),disabled:e.disabled,onCheckedChange:()=>e.onChange({...e.value,events:e.value.events.includes(t)?e.value.events.filter(e=>e!==t):[...e.value.events,t]})}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`min-w-0 break-words`,children:[he(t),c&&Zt(o,t)?/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`text-dashboard-text-muted`,children:[` `,`· `,Zt(o,t)]}):null]})]},t))})]}),p.length?/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{className:`grid gap-4`,children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-3 text-sm font-semibold`,children:`Filters`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[`Every filter must match. Leave a filter blank to match any value.`,m.length<p.length?` Filters that a selected event does not set are hidden.`:null]}),m.map(([t,n])=>{let r=e.value.match?.[t],i=u.find(e=>e.field===t);return/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`match-${t}`,children:t}),Array.isArray(r)?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`break-all`,children:_e(t,n,r)}),` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>h(t,void 0),children:`Remove filter`})]}):n.kind===`boolean`||n.enum?/* @__PURE__ */ (0,Q.jsxs)(X,{id:`match-${t}`,value:r===void 0?``:String(r),onChange:e=>h(t,e.target.value===``?void 0:n.kind===`boolean`?e.target.value===`true`:e.target.value),children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:``,children:`Any value`}),(n.enum??[`true`,`false`]).map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{children:e},e))]}):/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`match-${t}`,type:n.kind===`number`?`number`:`text`,step:`any`,value:r===void 0?``:String(r),onChange:e=>h(t,e.target.value===``?void 0:n.kind===`number`?e.target.valueAsNumber:e.target.value)}),n.description?/* @__PURE__ */ (0,Q.jsx)(ut,{id:`match-${t}-help`,children:n.description}):null,i?/* @__PURE__ */ (0,Q.jsx)(gt,{children:i.message}):null]},t)})]}):null]}):null,JSON.stringify(e.value)===JSON.stringify(e.original)?null:/* @__PURE__ */ (0,Q.jsx)(M,{className:`w-fit`,onClick:()=>e.onChange(e.original),children:`Keep saved trigger`})]})}function $t(e){let t=ge(e.source,e.trigger);return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`my-2 list-disc pl-5`,children:t.problems.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:e},e))}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-xs`,children:[/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 break-words`,children:[e.displayName,` ·`,` `,e.trigger.resourceType?.replaceAll(`_`,` `)??`any resource`,e.trigger.identifier?` · ${e.trigger.identifier}`:null]}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-1 break-words text-dashboard-text-muted`,children:t.events.join(`, `)}),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:t.filters})]})]})}function en(e){return e.outcomes.length?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-decimal gap-2 pl-5 text-sm`,children:e.outcomes.map((t,n)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:It(t,e.destination)},n))}):/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:`No success message`})}function tn(e){let t=e.original.length?e.original:[{action:`send_message`,destination:`current_conversation`}],n=[...e.original.flatMap((t,n)=>typeof t.destination==`string`?[]:[{value:`saved:${n}`,label:It(t,e.destination),outcome:t}]),{value:`current_conversation`,label:`${e.destination.label} · ${e.destination.visibility}`,outcome:{action:`send_message`,destination:`current_conversation`}},{value:`task_creator`,label:`Creator · Direct message`,outcome:{action:`send_message`,destination:`task_creator`}}];return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(et,{"aria-label":`Success messages`,disabled:e.disabled,className:`flex flex-wrap gap-x-6 gap-y-3`,onValueChange:n=>e.onChange(n?t:[]),value:e.value.length>0,children:[!0,!1].map(e=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`inline-flex min-h-8 cursor-pointer items-center gap-2 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(nt,{value:e}),e?`Send a message`:`No success message`]},String(e)))}),e.value.length?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-4 sm:gap-2`,children:[e.value.map((t,r)=>{let i=e.original.findIndex(e=>JSON.stringify(e)===JSON.stringify(t));return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`w-4 text-xs text-dashboard-text-muted`,children:[r+1,`.`]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:H(`min-w-0 flex-1`,e.value.length>1&&`order-last basis-full sm:order-none sm:basis-auto`),children:/* @__PURE__ */ (0,Q.jsx)(X,{"aria-label":`Message ${r+1} destination`,value:typeof t.destination==`string`?t.destination:`saved:${i}`,onChange:t=>{let i=n.find(e=>e.value===t.target.value);i&&e.onChange(e.value.map((e,t)=>t===r?i.outcome:e))},children:n.map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),e.value.length>1?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(M,{size:`icon`,className:`ml-auto sm:ml-0`,"aria-label":`Move message ${r+1} up`,disabled:r===0,onClick:()=>{let n=[...e.value],i=n[r-1];i&&(n[r-1]=t,n[r]=i,e.onChange(n))},children:/* @__PURE__ */ (0,Q.jsx)(Nt,{size:16})}),/* @__PURE__ */ (0,Q.jsx)(M,{size:`icon`,"aria-label":`Remove message ${r+1}`,onClick:()=>e.onChange(e.value.filter((e,t)=>t!==r)),children:/* @__PURE__ */ (0,Q.jsx)(L,{size:16})})]}):null]},r)}),e.value.length<5?/* @__PURE__ */ (0,Q.jsxs)(M,{className:`w-fit`,onClick:()=>e.onChange([...e.value,{action:`send_message`,destination:`task_creator`}]),children:[/* @__PURE__ */ (0,Q.jsx)(ce,{size:15}),`Add message`]}):null]}):/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm leading-relaxed text-dashboard-text-muted`,children:`Junior still does the work. No message is sent after success.`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[e.value.length?`Messages are sent in this order. `:``,`This does not limit actions in the instruction.`]})]})}function nn(e){let r=dt(),[i,a]=(0,Z.useState)(e.automation),[o,s]=(0,Z.useState)(()=>Rt(e.automation)),[c,d]=(0,Z.useState)({}),[f,m]=(0,Z.useState)(),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1),y=u(),b=n(),x=Bt(i,o),S=Object.keys(x).length>0,ee={kind:i.kind,revision:i.revision,...x},C=l(()=>S&&!v.current),w=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{C.state===`blocked`&&w.current?.focus()},[C.state]);let T=`/api/automations/${encodeURIComponent(i.id)}`;(0,Z.useEffect)(()=>{let e=e=>{S&&!v.current&&(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[S]);let E=()=>requestAnimationFrame(()=>(_.current?.querySelector(`[aria-invalid="true"]`)??_.current?.querySelector(`[data-save-error]`))?.focus()),D=t({mutationFn:()=>we(z,T,ee),onSuccess:async()=>{v.current=!0,await b.invalidateQueries({queryKey:[`dashboard`,`automations`]}),r.add({title:`Automation saved`,description:`Changes apply to future work.`,type:`success`}),y(e.returnPath)},onError:e=>{d(e instanceof V?e.fields??{}:{}),E()}});function te(e){f&&(s(e?{...Rt(f),...x}:Rt(f)),a(f),m(void 0),D.reset(),d({}))}let O=t({mutationFn:()=>B(z,`${T}/edit`),onSuccess:m}),k=D.error instanceof V&&D.error.code===`conflict`,A=e=>s(t=>({...t,...e})),j=e=>{A({[e]:Rt(i)[e]}),g(e=>e+1)},N=e=>Object.entries(c).filter(([t])=>t===e||t.startsWith(`${e}.`)).flatMap(([,e])=>e).join(` `)||void 0,P=i.kind===`scheduled`?`schedule`:`trigger`,F=i.ownedByViewer,I=e.summary.createdBy,L=!F&&i.credentialMode===`creator`&&(x.instruction!==void 0||x[P]!==void 0||x.outcomes!==void 0),ne=N(P),re=e=>({"aria-invalid":!!N(e)||void 0,"aria-describedby":N(e)?`${e}-error`:void 0});return/* @__PURE__ */ (0,Q.jsxs)(`form`,{ref:_,noValidate:!0,onSubmit:e=>{if(e.preventDefault(),D.isPending||k||!S)return;let t=Ce.safeParse(ee);if(t.success)d({}),D.mutate();else{let e={};for(let n of t.error.issues)(e[n.path.join(`.`)]??=[]).push(n.message);d(e),E()}},children:[C.state===`blocked`?/* @__PURE__ */ (0,Q.jsx)(`div`,{tabIndex:-1,ref:w,className:`mb-6 outline-none`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Discard unsaved changes?`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Your changes have not been saved.`}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>C.reset(),children:`Keep editing`}),/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>C.proceed(),children:`Discard changes`})]})]})}):null,D.error||Object.keys(c).length?/* @__PURE__ */ (0,Q.jsx)(`div`,{tabIndex:-1,"data-save-error":!0,className:`mb-6 outline-none`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{tone:k?`warning`:`error`,title:k?`This automation changed while you were editing.`:`Changes could not be saved.`,children:[/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-1`,children:[`Your edits are still here.`,` `,k?`Review the latest version before saving again.`:D.error instanceof V?D.error.apiError:`Check the fields below, or try again.`]}),k?/* @__PURE__ */ (0,Q.jsx)(M,{disabled:O.isPending,onClick:()=>O.mutate(),children:O.isPending?`Loading…`:`Review latest version`}):null,O.error?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,children:`The latest version could not be loaded. Try again.`}):null]})}):null,f?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`mb-6`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Compare your edits with the latest saved version`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Only the fields you changed are shown. Keeping your edits will replace these fields. Other saved fields stay unchanged.`}),Object.entries(x).map(([e,t])=>/* @__PURE__ */ (0,Q.jsxs)(`section`,{className:`my-4`,children:[/* @__PURE__ */ (0,Q.jsx)(`h3`,{className:`text-sm font-semibold capitalize`,children:e===`credentialMode`?`Credentials`:e}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Latest saved`}),/* @__PURE__ */ (0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-sm`,children:rn(e===`schedule`&&f.kind===`scheduled`?zt(f):f[e])})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Your edit`}),/* @__PURE__ */ (0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-sm`,children:rn(t)})]})]})]},e)),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>te(!0),children:`Keep my changed fields`}),/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>te(!1),children:`Use latest saved version`})]})]})}):null,F?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-0 mb-6 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted`,children:[I,` created this automation. You can edit it because it is in a public channel. Only `,I,` can turn on their connected accounts. Version history keeps every saved change.`]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10`,children:[/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{disabled:D.isPending,className:`min-w-0 [&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0`,children:[/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.title!==void 0||x.instruction!==void 0,title:`What to do`,detail:`Give Junior a clear instruction and a name you can find later.`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`title`,children:`Title`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`title`,value:o.title,placeholder:e.summary.title,onChange:e=>A({title:e.target.value}),...re(`title`)}),/* @__PURE__ */ (0,Q.jsx)(gt,{id:`title-error`,children:N(`title`)})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`instruction`,children:`Instruction`}),/* @__PURE__ */ (0,Q.jsx)(Ze,{id:`instruction`,rows:8,value:o.instruction,onChange:e=>A({instruction:e.target.value}),...re(`instruction`),className:`resize-y text-base leading-relaxed sm:text-sm`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-right text-xs text-dashboard-text-muted`,children:[o.instruction.length.toLocaleString(),` / 4,000`]}),/* @__PURE__ */ (0,Q.jsx)(gt,{id:`instruction-error`,children:N(`instruction`)})]})]}),/* @__PURE__ */ (0,Q.jsx)($,{changed:x[P]!==void 0,title:`When to run`,detail:i.kind===`scheduled`?`Choose a schedule in a specific timezone.`:`Run when a matching event occurs.`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{id:`${P}-error`,tabIndex:-1,"aria-invalid":!!ne||void 0,className:`grid min-w-0 gap-5 outline-none`,children:[ne?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-rose-300`,children:ne}):null,i.kind===`scheduled`?/* @__PURE__ */ (0,Q.jsx)(Jt,{automation:i,value:o.schedule,onChange:e=>A({schedule:e})}):/* @__PURE__ */ (0,Q.jsx)(Qt,{value:o.trigger??i.trigger,original:i.trigger,disabled:D.isPending,onChange:e=>A({trigger:e})})]})}),/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.outcomes!==void 0,title:`Where results go`,detail:`Choose who gets a message after successful work.`,children:[N(`outcomes`)?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-rose-300`,children:N(`outcomes`)}):null,/* @__PURE__ */ (0,Q.jsx)(tn,{value:o.outcomes,original:i.outcomes,destination:e.summary.destination,disabled:D.isPending,onChange:e=>A({outcomes:e})})]}),/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.credentialMode!==void 0,title:`Credentials`,detail:`Choose which connected accounts Junior can use.`,children:[/* @__PURE__ */ (0,Q.jsx)(et,{"aria-label":`Credential mode`,disabled:D.isPending,className:`divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis`,onValueChange:e=>A({credentialMode:e}),value:L?`system`:o.credentialMode,children:[[`creator`,F?`Your connected accounts`:`${I}’s connected accounts`,F?`Uses accounts connected by you, the creator.`:`Uses accounts connected by ${I}. Only ${I} can turn this on.`],[`system`,`System credentials only`,F?`Does not use your connected accounts. Some work may not be possible.`:`Does not use anyone’s connected accounts. Some work may not be possible.`]].map(([e,t,n])=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 px-4 py-4 has-data-checked:bg-dashboard-fill-soft has-data-disabled:cursor-not-allowed has-data-disabled:opacity-60`,children:[/* @__PURE__ */ (0,Q.jsx)(nt,{className:`mt-0.5`,value:e,disabled:e===`creator`&&!F&&(i.credentialMode!==`creator`||L)}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-dashboard-text-muted`,children:n})]})]},e))}),L?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Saving switches this automation to system credentials.`,children:[`Only `,I,` can let a changed instruction,`,i.kind===`event`?` trigger,`:` schedule,`,` or result destination use their connected accounts.`]}):null,N(`credentialMode`)?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,children:N(`credentialMode`)}):null]})]},h),/* @__PURE__ */ (0,Q.jsx)(Ht,{changes:x,disabled:D.isPending,onUndo:j,original:i,summary:e.summary})]}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mb-5 text-xs leading-relaxed text-dashboard-text-muted sm:hidden`,children:`Changes apply to future work. Saving does not run this automation.`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`sticky bottom-0 z-20 -mx-4 border-t border-dashboard-border-emphasis bg-dashboard-bg px-4 py-4 sm:-mx-8 sm:px-8`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,role:`status`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs font-medium sm:text-sm`,children:D.isPending?`Saving…`:S?`Unsaved changes`:`Unchanged`}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 hidden text-xs text-dashboard-text-muted sm:block`,children:`Changes apply to future work. Saving does not run it.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(p,{to:e.returnPath,className:`inline-flex min-h-11 items-center rounded-md border border-dashboard-border-emphasis px-3 text-sm text-dashboard-text no-underline sm:min-h-9`,children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(M,{type:`submit`,variant:`primary`,className:`min-h-11 sm:min-h-9`,disabled:!S||D.isPending||k,children:`Save changes`})]})]})})]})}function rn(e){return e==null?`Not set`:typeof e==`string`?e:JSON.stringify(e,null,2)}function an(){return/* @__PURE__ */ (0,Q.jsx)(`div`,{role:`status`,"aria-label":`Loading automation editor`,children:[`What to do`,`When to run`,`Where results go`,`Credentials`].map((e,t)=>/* @__PURE__ */ (0,Q.jsxs)($,{title:e,children:[/* @__PURE__ */ (0,Q.jsx)(Oe,{className:`h-4 w-24`}),/* @__PURE__ */ (0,Q.jsx)(Oe,{className:t===0?`h-48 w-full`:`h-20 w-full`})]},e))})}function on({automation:e}){let t=lt(!0,e.id),n=t.data?.executions.slice(0,3)??[];return/* @__PURE__ */ (0,Q.jsxs)(`section`,{"aria-label":`Recent runs`,className:`grid min-w-0 gap-2.5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsx)(`h3`,{className:`m-0 text-xs font-medium text-dashboard-text-muted`,children:`Recent runs`}),e.totalRuns>0||n.length>0?/* @__PURE__ */ (0,Q.jsx)(p,{className:`${De} text-xs`,to:W(e.id,`runs`),children:`View all runs`}):null]}),t.isPending?/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-busy":`true`,role:`status`,className:`grid gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Loading recent runs`}),Array.from({length:3},(e,t)=>/* @__PURE__ */ (0,Q.jsx)(Oe,{className:`h-14 rounded-md`},t))]}):null,t.error?/* @__PURE__ */ (0,Q.jsxs)(ct,{children:[`Recent runs could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void t.refetch(),children:`Try again`})]}):null,t.data&&n.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:e.totalRuns===0?`No runs yet. Results will appear here after the first run.`:`No recent runs are available. Older run details may have expired.`}):null,n.length>0?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 list-none divide-y divide-dashboard-border-subtle p-0`,children:n.map(t=>{let n=[t.durationMs===void 0?void 0:Ie(t.durationMs),t.costUsd===void 0?void 0:ze({total:t.costUsd})].filter(Boolean).join(` · `),r=t.title===e.title?void 0:t.title,i=/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-1`,children:[/* @__PURE__ */ (0,Q.jsx)(ft,{size:`compact`,tone:t.status===`completed`?`success`:t.status===`failed`?`danger`:`warning`,children:t.status}),/* @__PURE__ */ (0,Q.jsx)(`time`,{className:`text-xs text-dashboard-text-muted`,dateTime:t.executedAt,title:R(t.executedAt),children:Be(t.executedAt)})]}),r||n?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-3 text-xs text-dashboard-text-muted`,children:[r?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 min-w-0 truncate text-dashboard-text`,title:r,children:r}):null,n?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 shrink-0 tabular-nums`,children:n}):null]}):null,t.conversationId?null:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:`No Conversation recorded`})]}),a=`grid min-w-0 gap-1 rounded-md px-2 py-2.5`;return/* @__PURE__ */ (0,Q.jsx)(`li`,{children:t.conversationId?/* @__PURE__ */ (0,Q.jsx)(p,{"aria-label":`Open ${t.status} run from ${R(t.executedAt)}`,className:`${a} text-inherit no-underline transition-colors hover:bg-dashboard-fill-hover focus-visible:outline-2 focus-visible:outline-dashboard-focus`,to:st(t.conversationId),children:i}):/* @__PURE__ */ (0,Q.jsx)(`div`,{className:a,children:i})},t.executionId)})}):null]})}const sn=/*#__PURE__*/ Z.createContext(void 0);function cn(){let e=Z.useContext(sn);if(e===void 0)throw Error(k(10));return e}const ln={value:()=>null},un=/*#__PURE__*/ Z.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,hiddenUntilFound:a,keepMounted:o,loopFocus:s,onValueChange:c,multiple:l=!1,orientation:u=`vertical`,value:d,defaultValue:f,style:p,...m}=e,h=f??w,g=Z.useRef([]),[v,y]=E({controlled:d,default:h,name:`Accordion`,state:`value`}),x=b((e,t,n)=>{let r;r=l?t?[...v,e]:v.filter(t=>t!==e):v[0]===e?[]:[e],c?.(r,n),!n.isCanceled&&y(r)}),S=Z.useMemo(()=>({value:v,disabled:i,orientation:u}),[v,i,u]),C=Z.useMemo(()=>({disabled:i,handleValueChange:x,hiddenUntilFound:a??!1,keepMounted:o??!1,state:S,value:v}),[i,x,a,o,S,v]),T=_(`div`,e,{state:S,ref:t,props:m,stateAttributesMapping:ln});return/*#__PURE__*/ (0,Q.jsx)(sn.Provider,{value:C,children:/*#__PURE__*/ (0,Q.jsx)(ee,{elementsRef:g,children:T})})}),dn=/*#__PURE__*/ Z.createContext(void 0);function fn(){let e=Z.useContext(dn);if(e===void 0)throw Error(k(9));return e}const pn={...x,index:e=>({"data-index":String(e)}),...v,value:()=>null},mn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{className:n,disabled:r=!1,onOpenChange:i,render:a,value:o,style:s,...c}=e,{ref:l,index:u}=O(),{disabled:d,handleValueChange:f,state:p,value:m}=cn(),h=A(),g=o??h,v=r||d,y=m.includes(g),x=b((e,t)=>{i?.(e,t),!t.isCanceled&&f(g,e,t)}),S=T({open:y,onOpenChange:x,disabled:v}),ee=Z.useMemo(()=>({...S,onOpenChange:x,state:{open:S.open,disabled:S.disabled,transitionStatus:S.transitionStatus}}),[S,x]),C=Z.useMemo(()=>({...p,hidden:!y&&!S.mounted,index:u,disabled:v,open:y}),[S.mounted,v,u,y,p]),w=A(),[E,D]=Z.useState(),k=E===null?void 0:E??w,j=Z.useMemo(()=>({defaultTriggerId:w,open:y,state:C,setTriggerId:D,triggerId:k}),[w,y,C,D,k]),M=_(`div`,e,{state:C,ref:[t,l],props:c,stateAttributesMapping:pn});return/*#__PURE__*/ (0,Q.jsx)(te.Provider,{value:ee,children:/*#__PURE__*/ (0,Q.jsx)(dn.Provider,{value:j,children:M})})}),hn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{state:o}=fn();return _(`h3`,e,{state:o,ref:t,props:a,stateAttributesMapping:pn})}),gn={...pn,...C},_n=/*#__PURE__*/ Z.forwardRef(function(e,t){let{disabled:n,className:r,id:i,render:a,nativeButton:o=!0,style:s,...c}=e,{panelId:l,open:u,handleTrigger:d,disabled:f}=D(),{getButtonProps:p,buttonRef:m}=h({disabled:n||f,native:o}),{defaultTriggerId:g,state:v,setTriggerId:y}=fn(),b=i||void 0,x=b??g;return S(()=>(y(e=>b??(e===null?void 0:e)),()=>{y(e=>e===b?null:e)}),[b,y]),_(`button`,e,{state:v,ref:[t,m],props:[{"aria-controls":u?l:void 0,"aria-expanded":u,id:x,onClick:d},c,p],stateAttributesMapping:gn})}),vn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,id:a,render:o,style:s,...c}=e,{hiddenUntilFound:l,keepMounted:u}=cn(),{defaultPanelId:d,mounted:f,onOpenChange:p,open:m,setMounted:h,setOpen:v,setPanelIdState:b,transitionStatus:x}=D(),ee=r??l,C=i??u,w=a||void 0,T=a??d;S(()=>(b(e=>w??(e===null?void 0:e)),()=>{b(e=>e===w?null:e)}),[w,b]);let{height:E,props:te,ref:O,shouldPreventOpenAnimation:k,shouldRender:A,transitionStatus:j,width:M}=y({externalRef:t,hiddenUntilFound:ee,id:T,keepMounted:C,mounted:f,onOpenChange:p,open:m,setMounted:h,setOpen:v,transitionStatus:x}),{state:N,triggerId:P}=fn(),F={...N,transitionStatus:j},I=g(s,F),L=_(`div`,{...e,style:void 0},{state:F,ref:O,props:[te,{"aria-labelledby":P,role:`region`,style:{"--accordion-panel-height":E===void 0?`auto`:`${E}px`,"--accordion-panel-width":M===void 0?`auto`:`${M}px`}},c,I?{style:I}:void 0,k?{style:{animationName:`none`}}:void 0],stateAttributesMapping:pn});return A?L:null});function yn({className:e,...t}){return/* @__PURE__ */ (0,Q.jsx)(un,{"data-slot":`accordion`,className:r(`flex w-full flex-col`,e),...t})}function bn({className:e,...t}){return/* @__PURE__ */ (0,Q.jsx)(mn,{"data-slot":`accordion-item`,className:r(`not-last:border-b not-last:border-dashboard-border-subtle`,e),...t})}function xn({className:e,children:t,...n}){return/* @__PURE__ */ (0,Q.jsx)(hn,{className:`flex`,children:/* @__PURE__ */ (0,Q.jsxs)(_n,{"data-slot":`accordion-trigger`,className:r(`group/accordion-trigger relative flex min-w-0 flex-1 cursor-pointer items-center justify-between gap-3 rounded-sm py-2.5 text-left font-sans text-sm font-medium text-dashboard-text transition-colors hover:text-dashboard-text-solid outline-none focus-visible:outline-2 focus-visible:outline-dashboard-focus aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-dashboard-text-muted`,e),...n,children:[t,/* @__PURE__ */ (0,Q.jsx)(N,{"data-slot":`accordion-trigger-icon`,className:`pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden`}),/* @__PURE__ */ (0,Q.jsx)(P,{"data-slot":`accordion-trigger-icon`,className:`pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline`})]})})}function Sn({className:e,children:t,...n}){return/* @__PURE__ */ (0,Q.jsx)(vn,{"data-slot":`accordion-content`,className:`h-(--accordion-panel-height) overflow-hidden text-sm transition-[height] duration-180 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none`,...n,children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:r(`pt-0 pb-2.5`,e),children:t})})}function Cn({automation:e}){let t=e.kind===`event`&&e.trigger.problems.length>0;return/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-label":`Automation state`,"aria-live":`polite`,role:`status`,children:/* @__PURE__ */ (0,Q.jsx)(ft,{size:`compact`,tone:e.status===`paused`||e.status===`completed`?`neutral`:e.status===`blocked`||t?`warning`:`success`,children:e.status===`active`&&t?`Trigger unavailable`:e.status})})}function wn({automation:e}){let t=e.lastRunStatus?`Last run ${e.lastRunStatus}`:`Last run`;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[/* @__PURE__ */ (0,Q.jsx)(On,{automation:e}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:e.lastRunAt?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t,` ·`,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.lastRunAt,title:R(e.lastRunAt),children:Be(e.lastRunAt)})]}):e.lastRunStatus?`${t} · time not recorded`:e.totalRuns===0?`No runs yet`:`Last run time not recorded`})]})}function Tn(e){if(e.status===`blocked`||e.status===`paused`&&e.statusReason)return`fix`;if(e.kind===`event`&&e.trigger.problems.length>0)return`trigger`;if(e.lastRunStatus===`failed`||e.lastRunStatus===`blocked`)return`last_run`}function En(e){return Tn(e)!==void 0}function Dn({automation:e,editPath:t}){let n=Tn(e);if(!n)return null;let r=e.status===`paused`,i=e.kind===`event`?e.trigger.problems:[],a=n===`fix`,o=i.length>0,s=n===`last_run`;return/* @__PURE__ */ (0,Q.jsxs)(Y,{title:a?`Fix this before resuming`:o?`Trigger unavailable`:`Check the last run`,children:[a?/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 break-words`,children:[e.statusReason??`Check the last run to see what needs fixing.`,` `,!e.ownedByViewer&&e.credentialMode===`creator`?`It uses accounts connected by ${e.createdBy}. Ask them to resume it, or switch it to Junior's credentials first.`:null]}):null,o?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`my-1 list-disc pl-5`,children:i.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{className:`break-words`,children:e},e))}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:`Edit the trigger, or enable its plugin again.`})]}):null,s&&!a&&!o?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:e.status===`active`?`Future runs are still on.`:r?`Review the last result before resuming.`:`Review the last result for details.`}):null,o?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:t,children:`Change trigger`}):e.lastConversationId?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:st(e.lastConversationId),children:`Open last run`}):e.totalRuns>0?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:W(e.id,`runs`),children:`View run history`}):null]})}function On({automation:e}){let t;if(e.status===`completed`)t=`No future runs`;else if(e.status===`paused`)t=`No new runs while paused`;else if(e.status===`blocked`)t=`New runs are blocked until this is fixed`;else if(e.kind===`event`)t=e.trigger.problems.length===0?`Waiting for a matching event`:`Waiting for a trigger fix`;else if(e.nextRunAt){let t=Intl.DateTimeFormat().resolvedOptions().timeZone,n=R(e.nextRunAt,e.timezone),r=R(e.nextRunAt,t),i=Date.parse(e.nextRunAt)<=Date.now()?`Run was due`:`Next run`;return/* @__PURE__ */ (0,Q.jsx)(yn,{children:/* @__PURE__ */ (0,Q.jsxs)(bn,{value:`next-run`,children:[/* @__PURE__ */ (0,Q.jsx)(xn,{className:`py-1 text-sm font-normal`,children:/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[i,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:Be(e.nextRunAt)})]})}),/* @__PURE__ */ (0,Q.jsx)(Sn,{children:/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 mt-1 grid gap-1 border-l border-dashboard-border pl-3 text-xs leading-relaxed`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-dashboard-text-muted`,children:`Schedule time`}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0`,children:/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:n})}),r===n?null:/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`mt-1 text-dashboard-text-muted`,children:`Your time`}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0`,children:/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:r})})]})]})})]})})}else t=`Next run not scheduled`;return/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text`,children:t})}function kn(e){let{automation:t}=e;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 content-start gap-6`,children:[/* @__PURE__ */ (0,Q.jsx)(Dn,{automation:t,editPath:e.editPath}),/* @__PURE__ */ (0,Q.jsx)(An,{automation:t}),/* @__PURE__ */ (0,Q.jsx)(U,{padding:`sm`,children:/* @__PURE__ */ (0,Q.jsx)(on,{automation:t})}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`lg:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(Mn,{automation:t})})]}),/* @__PURE__ */ (0,Q.jsxs)(`aside`,{"aria-label":`Automation status`,className:`grid min-w-0 content-start gap-3 max-lg:row-start-1`,children:[/* @__PURE__ */ (0,Q.jsx)(Nn,{title:`Status`,children:/* @__PURE__ */ (0,Q.jsx)(wn,{automation:t})}),/* @__PURE__ */ (0,Q.jsx)(jn,{automation:t,range:e.range}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-lg:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(Mn,{automation:t})})]})]})}function An(e){let{automation:t}=e,n=t.ownedByViewer?`you`:t.createdBy;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 [&>section:first-child]:border-t-0 [&>section:first-child]:pt-0`,children:[/* @__PURE__ */ (0,Q.jsx)($,{title:`What to do`,children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`text-base leading-relaxed [overflow-wrap:anywhere]`,children:/* @__PURE__ */ (0,Q.jsx)($e,{mentions:t.mentions??[],text:t.instruction})})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`When to run`,children:t.kind===`scheduled`?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:oe(t)}):/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-1 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 break-words`,children:t.resource}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 break-words text-dashboard-text-muted`,children:t.trigger.events.join(`, `)}),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:t.trigger.filters})]})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`Where results go`,children:/* @__PURE__ */ (0,Q.jsx)(en,{outcomes:t.outcomes,destination:t.destination})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`Credentials`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:t.credentialMode===`creator`?`Uses accounts connected by ${n}.`:`System credentials only. Junior does not use anyone’s connected accounts.`})})]})}function jn(e){let{automation:t,range:n}=e,r=lt(!0,t.id),i=r.data?Me({days:r.data.executionDays,hours:r.data.executionHours,sixHours:r.data.executionSixHours,range:n}).reduce((e,t)=>({blocked:e.blocked+t.blocked,failed:e.failed+t.failed}),{blocked:0,failed:0}):void 0;return/* @__PURE__ */ (0,Q.jsx)(Nn,{title:n===1?`Last 24 hours`:`Last ${n} days`,children:/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-4 gap-y-3`,children:[/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Runs`,value:t.runs[n]}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Spend`,value:ze({total:t.costUsd[n]})}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Failed`,value:i?.failed??`—`}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Blocked`,value:i?.blocked??`—`})]})})}function Mn(e){let{automation:t}=e,n=f(),r=Xe(!0,t.id).data?.activeVersion;return/* @__PURE__ */ (0,Q.jsxs)(Nn,{title:`About`,children:[/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 grid gap-3 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Created by`,children:t.createdByEmail?/* @__PURE__ */ (0,Q.jsx)(p,{className:De,to:Le(t.createdByEmail),children:t.ownedByViewer?`You`:t.createdBy}):t.ownedByViewer?`You`:t.createdBy}),/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Created`,children:R(t.createdAt)}),/* @__PURE__ */ (0,Q.jsxs)(Fn,{label:`Destination`,children:[t.destination.label,` ·`,` `,t.destination.visibility===`private`?`private`:`public`]}),/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Version`,children:/* @__PURE__ */ (0,Q.jsx)(p,{className:De,to:G(W(t.id,`versions`),n.search),children:r?`Version ${r}`:`Version history`})})]}),t.ownedByViewer?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[t.destination.visibility===`private`?null:`You can edit, pause, or delete it because it is in a public channel. `,`Only `,t.createdBy,` can turn on their connected accounts, or resume or run it while it uses them.`]})]})}function Nn(e){return/* @__PURE__ */ (0,Q.jsxs)(U,{as:`section`,padding:`sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted`,children:e.title}),e.children]})}function Pn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-xs text-dashboard-text-muted`,children:e.label}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 mt-0.5 font-display text-xl font-light tabular-nums text-dashboard-text`,children:e.value})]})}function Fn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-xs text-dashboard-text-muted`,children:e.label}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 min-w-0 break-words`,children:e.children})]})}const In=[{color:`var(--color-emerald-300)`,key:`completed`,label:`Completed`},{color:`var(--color-rose-300)`,key:`failed`,label:`Failed`},{color:`var(--color-amber-300)`,key:`blocked`,label:`Blocked`}],Ln=Object.fromEntries(In.map(e=>[e.key,{color:e.color,label:e.label}]));function Rn(e){let t=e.bucketUnit??`day`,n=e.days,r=n.map(e=>e.completed+e.failed+e.blocked),i=Math.max(1,...r),a=r.some(e=>e>0);return/* @__PURE__ */ (0,Q.jsxs)(U,{className:`min-h-[15rem] p-4 sm:p-5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 font-display text-xl font-medium text-dashboard-text`,children:`Runs over time`}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted`,children:t===`hour`?`Terminal runs for this automation each hour.`:t===`6hour`?`Terminal runs for this automation each 6 hours.`:`Terminal runs for this automation each day.`})]}),/* @__PURE__ */ (0,Q.jsx)(Mt,{ariaLabel:`Automation execution status legend`,items:In}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`relative mt-3 overflow-hidden`,children:[/* @__PURE__ */ (0,Q.jsx)(kt,{className:`aspect-auto h-55 w-full`,config:Ln,children:/* @__PURE__ */ (0,Q.jsxs)(jt,{"aria-label":`Automation executions during the last ${e.range===1?`24 hours`:`${e.range} days`}`,data:n,margin:Tt,role:`img`,children:[/* @__PURE__ */ (0,Q.jsx)(Ct,{strokeDasharray:`3 5`,vertical:!1}),/* @__PURE__ */ (0,Q.jsx)(Ot,{maximum:i}),/* @__PURE__ */ (0,Q.jsx)(Dt,{keys:n.map(e=>e.date)}),/* @__PURE__ */ (0,Q.jsx)(Et,{content:/* @__PURE__ */ (0,Q.jsx)(wt,{rows:e=>[[`completed`,e.completed],[`failed`,e.failed],[`blocked`,e.blocked],[`total`,e.completed+e.failed+e.blocked]]})}),In.map(e=>/* @__PURE__ */ (0,Q.jsx)(At,{dataKey:e.key,fill:`var(--color-${e.key})`,fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,stackId:`status`},e.key))]})}),a?null:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted`,children:`No automation executions in this period.`})]})]})}const zn=`result`,Bn=[``,`completed`,`failed`,`blocked`],Vn=`grid-cols-[minmax(0,1fr)_5.5rem_5.5rem_5.5rem_auto_2rem]`;function Hn(e){let{automation:t}=e,n=lt(!0,t.id),[r,i]=We(zn,``,Bn),a=(0,Z.useMemo)(()=>(n.data?.executions??[]).filter(e=>!r||e.status===r),[n.data,r]),o=(0,Z.useMemo)(()=>(n.data?.executions??[]).map(e=>({...e,automationId:t.id,automationTitle:t.title,kind:t.kind})),[t,n.data]),s=_t(a.map(e=>e.executionId));return/* @__PURE__ */ (0,Q.jsxs)(vt,{details:s.runId?/* @__PURE__ */ (0,Q.jsx)(bt,{loading:!n.data&&!n.error,onClose:s.close,run:o.find(e=>e.executionId===s.runId),showAutomation:!1},s.runId):null,label:`Runs list`,listRef:s.listRef,children:[e.header,n.data?/* @__PURE__ */ (0,Q.jsx)(Un,{data:n.data,executions:a,onResultChange:i,onRowsKeyDown:s.onRowsKeyDown,onSelect:s.toggle,range:e.range,result:r,selectedRunId:s.runId}):n.error?/* @__PURE__ */ (0,Q.jsxs)(ct,{children:[`Runs could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void n.refetch(),children:`Try again`})]}):/* @__PURE__ */ (0,Q.jsx)(ke,{label:`Loading runs`,variant:`list`})]})}function Un(e){let{data:t,range:n}=e,r=(0,Z.useMemo)(()=>Kn(t.executions),[t.executions]);return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t.executionDays.length>0?/* @__PURE__ */ (0,Q.jsx)(Rn,{bucketUnit:Ne(n),days:Me({days:t.executionDays,hours:t.executionHours,sixHours:t.executionSixHours,range:n,emptySixHour:e=>({blocked:0,completed:0,date:e,failed:0})}),range:n}):null,/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-x-5 gap-y-3`,children:[/* @__PURE__ */ (0,Q.jsx)(xt,{ariaLabel:`Run result`,items:[{count:t.executions.length,label:`All`,value:``},{count:r.completed,label:`Completed`,value:`completed`},{count:r.failed,label:`Failed`,value:`failed`},{count:r.blocked,label:`Blocked`,value:`blocked`}],onChange:t=>e.onResultChange(t),value:e.result}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:[t.automation.totalRuns,` total · newest first`]})]}),e.executions.length===0?/* @__PURE__ */ (0,Q.jsx)(U,{padding:`md`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:t.executions.length===0?`This automation has not run yet.`:`No ${e.result} runs in the loaded history.`})}):/* @__PURE__ */ (0,Q.jsx)(U,{children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-[36rem]`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-hidden":`true`,className:H(`sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid`,Vn),children:[/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Run`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Duration`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Tokens`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Cost`})]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`min-w-0`,onKeyDown:e.onRowsKeyDown,role:`list`,children:e.executions.map(n=>/* @__PURE__ */ (0,Q.jsx)(Wn,{execution:n,fallbackTitle:t.automation.title,onSelect:()=>e.onSelect(n.executionId),selected:e.selectedRunId===n.executionId},n.executionId))})]})})}),t.truncated?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-center text-xs text-dashboard-text-muted`,children:`Showing the 100 most recent runs.`}):null]})}function Wn(e){let{execution:t}=e,n=ze(t.costUsd===void 0?void 0:{total:t.costUsd})||`—`,r=Ie(t.durationMs)||`—`,i=t.totalTokens===void 0?`—`:Re(t.totalTokens),a=se(t.status);return/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`border-b border-dashboard-border-subtle last:border-b-0`,"data-run-id":t.executionId,role:`listitem`,children:/* @__PURE__ */ (0,Q.jsxs)(St,{className:H(`grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5`,Vn),onSelect:e.onSelect,selected:e.selected,children:[/* @__PURE__ */ (0,Q.jsxs)(`button`,{"aria-expanded":e.selected,className:`block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus`,onClick:e.onSelect,type:`button`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 overflow-hidden`,children:[/* @__PURE__ */ (0,Q.jsx)(Ye,{className:`md:hidden`,label:t.status,tone:a}),/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium leading-snug text-dashboard-text`,children:ae(t,e.fallbackTitle)})]}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`mt-1 block truncate text-xs leading-relaxed text-dashboard-text-muted`,children:[R(t.executedAt),t.automationVersion?` · Version ${t.automationVersion}`:null]}),t.error?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block truncate text-xs leading-relaxed text-rose-300`,title:t.error,children:t.error}):null]}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Duration`,value:r}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Tokens`,value:i}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Cost`,value:n}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`hidden justify-self-center md:block`,children:/* @__PURE__ */ (0,Q.jsx)(Ye,{label:t.status,tone:a})}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-md:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(yt,{conversationId:t.conversationId})})]})})}function Gn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 max-md:flex max-md:items-center max-md:gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(`div`,{"aria-hidden":`true`,className:`mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block`,children:e.label}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`sr-only`,children:[e.label,`: `]}),e.value]})]})}function Kn(e){return e.reduce((e,t)=>(e[t.status]+=1,e),{blocked:0,completed:0,failed:0})}const qn=`version`;function Jn(e){let t=Xe(!0,e.automation.id);return t.error?/* @__PURE__ */ (0,Q.jsxs)(ct,{children:[`Version history could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void t.refetch(),children:`Try again`})]}):t.data?/* @__PURE__ */ (0,Q.jsx)(Yn,{automation:e.automation,data:t.data}):/* @__PURE__ */ (0,Q.jsx)(ke,{label:`Loading version history`,variant:`list`})}function Yn(e){let{automation:r,data:i}=e,[a,o]=m(),s=n(),[c,l]=(0,Z.useState)(),[u,d]=(0,Z.useState)(!1),f=r.status!==`completed`,p=Number(a.get(qn)),h=Math.max(0,i.versions.findIndex(e=>e.version===p)),g=i.versions[h],_=i.versions[h+1],v=e=>o(t=>{let n=new URLSearchParams(t);return n.set(qn,String(e)),n},{replace:!0}),y=`/api/automations/${encodeURIComponent(r.id)}`,b=t({mutationFn:async e=>{let t=await B(z,`${y}/edit`);return Te(z,`${y}/versions/${e}/activate`,{revision:t.revision})},onMutate:()=>l(void 0),onSuccess:async(e,t)=>{l(t),await s.invalidateQueries({queryKey:[`dashboard`,`automations`]})}});if(!g)return/* @__PURE__ */ (0,Q.jsx)(U,{padding:`md`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`No versions are saved yet. Junior saves a version each time the settings change.`})});let x=g.version===i.activeVersion;return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted`,children:f?`Each save creates a version. Making a version active saves its settings as a new version. It does not run the automation.`:`This automation has completed. Its versions are read-only.`}),c===void 0?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{role:`status`,className:`m-0 text-sm text-emerald-300`,children:[`Version `,c,` is active again. It was saved as a new version.`]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-4 lg:grid-cols-[17rem_minmax(0,1fr)] lg:gap-6`,children:[/* @__PURE__ */ (0,Q.jsxs)(`nav`,{"aria-label":`Versions`,className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-none gap-1 p-0 max-lg:max-h-64 max-lg:overflow-y-auto`,children:i.versions.map((e,t)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:/* @__PURE__ */ (0,Q.jsx)(Xn,{active:e.version===i.activeVersion,changes:rr(e,i.versions[t+1],i.truncated),onSelect:()=>v(e.version),selected:e.version===g.version,version:e})},e.version))}),i.truncated?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-2 px-3 text-xs text-dashboard-text-muted`,children:`Showing the 100 most recent versions.`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(U,{as:`section`,className:`min-w-0`,padding:`none`,variant:`default`,children:[/* @__PURE__ */ (0,Q.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-dashboard-border-subtle px-4 py-4 sm:px-5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`h2`,{className:`m-0 font-display text-lg font-medium`,children:[`Version `,g.version]}),x?/* @__PURE__ */ (0,Q.jsx)(ft,{size:`compact`,tone:`success`,children:`Active`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-1 mb-0 text-xs text-dashboard-text-muted`,children:[nr(g),` ·`,` `,R(g.createdAt),_?` · Compared with version ${_.version}`:``]})]}),f&&!x?/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`Make version ${g.version} active`,disabled:b.isPending,onClick:()=>d(!0),children:b.isPending&&b.variables===g.version?`Saving…`:`Make active`}):null]}),b.error&&b.variables===g.version?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`px-4 pt-4 sm:px-5`,children:/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`This version could not be made active.`,children:b.error instanceof V?b.error.code===`conflict`?`The automation changed. Try again.`:b.error.apiError??`Try again.`:`Try again.`})}):null,/* @__PURE__ */ (0,Q.jsx)(Qn,{automation:r,previous:_,version:g})]})]}),/* @__PURE__ */ (0,Q.jsx)(ot,{onOpenChange:d,open:u,children:/* @__PURE__ */ (0,Q.jsxs)(rt,{children:[/* @__PURE__ */ (0,Q.jsxs)(pt,{children:[`Make version `,g.version,` active?`]}),/* @__PURE__ */ (0,Q.jsxs)(mt,{children:[`Junior saves these settings as a new version. Future runs use them.`,r.ownedByViewer?null:` Only ${r.createdBy} can turn on their connected accounts.`]}),/* @__PURE__ */ (0,Q.jsxs)(Ge,{children:[/* @__PURE__ */ (0,Q.jsx)(qe,{children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Je,{onClick:()=>{b.mutate(g.version),d(!1)},variant:`primary`,children:`Make active`})]})]})})]})}function Xn(e){let{version:t}=e;return/* @__PURE__ */ (0,Q.jsxs)(`button`,{"aria-current":e.selected?`true`:void 0,className:H(`grid w-full min-w-0 cursor-pointer gap-0.5 rounded-md border-0 px-3 py-2.5 text-left transition-colors focus-visible:outline-2 focus-visible:outline-dashboard-focus`,e.selected?`bg-dashboard-accent/[0.08] text-dashboard-text`:`bg-transparent text-dashboard-text hover:bg-dashboard-fill-soft`),onClick:e.onSelect,type:`button`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[`Version `,t.version,e.active?/* @__PURE__ */ (0,Q.jsx)(ft,{size:`compact`,tone:`success`,children:`Active`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`truncate text-xs text-dashboard-text-muted`,children:[nr(t),` ·`,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:t.createdAt,children:Be(t.createdAt)})]}),e.changes?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`truncate text-xs text-dashboard-text-muted`,children:e.changes}):null]})}const Zn=[{key:`title`,label:`Title`},{key:`instruction`,label:`What to do`},{key:`when`,label:`When to run`},{key:`destination`,label:`Destination`},{key:`outcomes`,label:`Where results go`},{key:`credentialMode`,label:`Credentials`}];function Qn(e){let{automation:t,previous:n,version:r}=e,i=n?ir(n,r):[];return/* @__PURE__ */ (0,Q.jsx)(`dl`,{className:`m-0 divide-y divide-dashboard-border-subtle`,children:Zn.map(({key:e,label:a})=>{let o=i.includes(e);return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:H(`grid min-w-0 gap-2 px-4 py-4 sm:grid-cols-[9rem_minmax(0,1fr)] sm:gap-6 sm:px-5`,o&&`shadow-[inset_2px_0_0_var(--color-dashboard-accent)]`),children:[/* @__PURE__ */ (0,Q.jsxs)(`dt`,{className:`text-xs font-medium text-dashboard-text-muted`,children:[a,o?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block font-normal text-dashboard-accent-text`,children:`Changed`}):null]}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 min-w-0 text-sm leading-relaxed break-words`,children:o&&n&&e===`instruction`?/* @__PURE__ */ (0,Q.jsx)(er,{after:r.definition.instruction,before:n.definition.instruction}):o&&n?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-dashboard-text-muted line-through decoration-dashboard-text-muted/50`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Before: `}),$n(e,t,n)]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`After: `}),$n(e,t,r)]})]}):$n(e,t,r)})]},e)})})}function $n(e,t,n){let{definition:r}=n;switch(e){case`title`:return r.title??`First line of the instruction`;case`instruction`:return/* @__PURE__ */ (0,Q.jsx)($e,{mentions:t.mentions,text:r.instruction});case`when`:if(n.kind===`scheduled`){let{description:e,timezone:t}=n.definition.schedule;return e.includes(t)?e:`${e} (${t})`}return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[n.definition.trigger.label,n.definition.trigger.identifier?` · ${n.definition.trigger.identifier}`:null,/* @__PURE__ */ (0,Q.jsx)(`br`,{}),n.trigger.events.join(`, `),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:n.trigger.filters})]});case`destination`:return r.destination.channelId===t.destination.channelId&&r.destination.teamId===t.destination.teamId?t.destination.label:`Another destination · ${r.destination.channelId}`;case`outcomes`:return r.outcomes.length?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-decimal gap-1 pl-5`,children:r.outcomes.map((e,n)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:It(e,t.destination)},n))}):`No message on success`;case`credentialMode`:return r.credentialMode===`creator`?`Uses accounts connected by ${t.ownedByViewer?`you`:t.createdBy}.`:`System credentials only`}}function er(e){return/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`grid overflow-hidden rounded-md border border-dashboard-border-subtle font-mono text-xs leading-relaxed`,children:tr(e.before,e.after).map((e,t)=>/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:H(`grid grid-cols-[1.5rem_minmax(0,1fr)] whitespace-pre-wrap px-2 py-0.5`,e.kind===`added`&&`bg-emerald-500/10 text-emerald-200`,e.kind===`removed`&&`bg-rose-500/10 text-rose-200`),children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`select-none opacity-60`,children:e.kind===`added`?`+`:e.kind===`removed`?`−`:``}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[e.kind===`same`?null:/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:e.kind===`added`?`Added: `:`Removed: `}),e.value||` `]})]},t))})}function tr(e,t){let n=e.split(`
|
|
8
|
+
;const Nt=I(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]);var Z=/* @__PURE__ */ e(a(),1),Q=o();function Pt({automation:e,editPath:r,editVariant:i,onDelete:a}){let o=lt(),s=n(),c=e.status===`completed`,l=e.status===`paused`,u=e.status===`blocked`,d=!c,f=l||u?`resume`:`pause`,m=t({mutationFn:async()=>{let t=`/api/automations/${encodeURIComponent(e.id)}`,n=await B(z,`${t}/edit`);if(n.status!==e.status)throw Error(`The Automation changed. Reload the page before trying again.`);return Te(z,`${t}/lifecycle`,{action:f,revision:n.revision})},onSuccess:async e=>{await s.invalidateQueries({queryKey:[`dashboard`,`automations`]}),o.add({title:e.status===`blocked`?`Automation is still blocked`:f===`pause`?`Automation paused`:`Automation resumed`,description:e.status===`blocked`?`Fix the reported requirement before resuming again.`:f===`pause`?`Work already queued or running may finish.`:`Future triggers are enabled.`,type:e.status===`blocked`?`warning`:`success`})}});return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 justify-items-stretch gap-3 md:justify-items-end`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-label":`Automation actions`,className:`flex flex-wrap items-center gap-2`,role:`group`,children:[c?null:/* @__PURE__ */ (0,Q.jsxs)(p,{className:j({variant:i}),to:r,children:[/* @__PURE__ */ (0,Q.jsx)(F,{"aria-hidden":`true`,size:14}),`Edit automation`]}),d?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(M,{disabled:m.isPending,onClick:()=>m.mutate(),children:m.isPending?`Updating…`:f===`pause`?`Pause`:`Resume`}),/* @__PURE__ */ (0,Q.jsxs)(nt,{children:[/* @__PURE__ */ (0,Q.jsx)(et,{render:/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`About pausing`,size:`icon`}),children:/* @__PURE__ */ (0,Q.jsx)(re,{"aria-hidden":`true`,size:16})}),/* @__PURE__ */ (0,Q.jsx)(pt,{side:`bottom`,align:`end`,"aria-label":`About pausing`,children:/* @__PURE__ */ (0,Q.jsxs)(Ke,{children:[`Pausing stops new runs. Work already queued or running may finish. Resuming skips missed runs and waits for the next scheduled time or new event.`,l&&e.statusReason?` Removing the pause keeps the block until you fix it and resume again.`:``]})})]})]}):null,/* @__PURE__ */ (0,Q.jsxs)(de,{children:[/* @__PURE__ */ (0,Q.jsx)(le,{render:/* @__PURE__ */ (0,Q.jsx)(M,{focusableWhenDisabled:!0,"aria-label":`Delete automation`,size:`icon`,variant:`danger`,onClick:e=>a(e.currentTarget),disabled:m.isPending,children:/* @__PURE__ */ (0,Q.jsx)(L,{"aria-hidden":`true`,size:16})})}),/* @__PURE__ */ (0,Q.jsx)(ue,{size:`compact`,children:`Delete automation`})]})]}),m.error?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-w-sm`,children:/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`Could not update this automation.`,children:m.error instanceof V?m.error.apiError??`Try again.`:m.error.message})}):null]})}function Ft(e){let[r,i]=(0,Z.useState)(!0),a=n(),o=lt(),s=t({mutationFn:()=>Ee(`/api/automations/${encodeURIComponent(e.automation.id)}`),onSuccess:async()=>{await a.invalidateQueries({queryKey:[`dashboard`,`automations`]}),e.onDeleted(),o.add({title:`Automation deleted`,description:e.automation.title,type:`success`}),i(!1)}});return/* @__PURE__ */ (0,Q.jsx)(ft,{open:r,onOpenChange:(e,t)=>{s.isPending?t.cancel():i(e)},onOpenChangeComplete:t=>{t||e.onClose()},children:/* @__PURE__ */ (0,Q.jsxs)($e,{finalFocus:e.returnFocus,children:[/* @__PURE__ */ (0,Q.jsx)(qe,{children:`Delete automation?`}),/* @__PURE__ */ (0,Q.jsxs)(tt,{children:[`Delete`,` `,/* @__PURE__ */ (0,Q.jsx)(`strong`,{className:`font-medium text-dashboard-text`,children:e.automation.title}),`? This removes the Automation and stops future triggers. Work already queued or running may finish.`]}),s.error?/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`The automation could not be deleted. Try again.`}):null,/* @__PURE__ */ (0,Q.jsxs)(rt,{children:[/* @__PURE__ */ (0,Q.jsx)(dt,{disabled:s.isPending,children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Ge,{variant:`danger`,disabled:s.isPending,onClick:()=>s.mutate(),children:s.isPending?`Deleting…`:`Delete automation`})]})]})})}function It(e,t){return typeof e.destination==`string`?e.destination===`task_creator`?`Creator · Direct message`:`${t.label} · ${t.visibility}`:e.destination.channelId===t.channelId&&e.destination.teamId===t.teamId?`${t.label} · ${t.visibility}`:`Saved destination · ${e.destination.channelId}`}const Lt=[`sunday`,`monday`,`tuesday`,`wednesday`,`thursday`,`friday`,`saturday`];function Rt(e){return{title:e.title??``,instruction:e.instruction,credentialMode:e.credentialMode,outcomes:e.outcomes,trigger:e.kind===`event`?e.trigger:void 0}}function zt(e){let t=e.schedule.recurrence;if(e.schedule.kind===`recurring`&&t){let{time:n,weekdays:r,...i}=t;return{kind:`recurring`,...i,timezone:e.schedule.timezone,time:`${String(n.hour).padStart(2,`0`)}:${String(n.minute).padStart(2,`0`)}`,weekdays:r?.flatMap(e=>Lt[e]??[])}}if(e.nextRunAtMs){let t=new Intl.DateTimeFormat(`en-CA`,{timeZone:e.schedule.timezone,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}).formatToParts(e.nextRunAtMs),n=e=>t.find(t=>t.type===e)?.value??``;return{kind:`one_off`,timezone:e.schedule.timezone,timing:{type:`at`,date:`${n(`year`)}-${n(`month`)}-${n(`day`)}`,time:`${n(`hour`)}:${n(`minute`)}`}}}return{kind:`recurring`,frequency:`daily`,time:`09:00`,timezone:e.schedule.timezone}}function Bt(e,t){let n={};return t.title!==(e.title??``)&&(n.title=t.title),t.instruction!==e.instruction&&(n.instruction=t.instruction),t.credentialMode!==e.credentialMode&&(n.credentialMode=t.credentialMode),JSON.stringify(t.outcomes)!==JSON.stringify(e.outcomes)&&(n.outcomes=t.outcomes),e.kind===`scheduled`&&t.schedule&&(n.schedule=t.schedule),e.kind===`event`&&JSON.stringify(t.trigger)!==JSON.stringify(e.trigger)&&(n.trigger=t.trigger),n}const Vt={title:`Title`,instruction:`Instruction`,schedule:`Schedule`,trigger:`Trigger`,outcomes:`Where results go`,credentialMode:`Credentials`};function Ht(e){let t=Object.keys(Vt).filter(t=>e.changes[t]!==void 0),n=Ut(e.original),r=(t,n)=>Wt(t,n,e.summary);return/* @__PURE__ */ (0,Q.jsx)(`aside`,{"aria-label":`Your changes`,className:H(`min-w-0 lg:sticky lg:top-4 lg:self-start`,t.length===0&&`max-lg:hidden`),children:/* @__PURE__ */ (0,Q.jsxs)(U,{padding:`sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted`,children:`Your changes`}),t.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`No changes yet. Edit a section to see it here.`}):/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`m-0 grid list-none gap-3 p-0`,children:t.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`li`,{className:`grid min-w-0 gap-1 text-sm`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`font-medium`,children:Vt[t]}),/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`Undo ${Vt[t].toLowerCase()} change`,disabled:e.disabled,onClick:()=>e.onUndo(t),children:`Undo`})]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs text-dashboard-text-muted line-through decoration-dashboard-text-muted/50`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Saved: `}),r(n,t)]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 line-clamp-3 break-words whitespace-pre-wrap text-xs`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`New: `}),r(e.changes,t)]})]},t))}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted`,children:`Saving creates a new version. It does not run this automation.`})]})})}function Ut(e){let t=Rt(e);return e.kind===`scheduled`?{...t,schedule:zt(e)}:t}function Wt(e,t,n){switch(t){case`title`:return e.title||`First line of the instruction`;case`instruction`:return e.instruction||`Empty`;case`credentialMode`:return e.credentialMode===`creator`?n.ownedByViewer?`Your connected accounts`:`${n.createdBy}'s connected accounts`:`System credentials only`;case`outcomes`:return e.outcomes?.length?e.outcomes.map(e=>It(e,n.destination)).join(`, `):`No success message`;case`schedule`:return e.schedule?Kt(e.schedule):`Not set`;case`trigger`:{let t=e.trigger;if(!t)return`Not set`;let n=t.identifier?`${t.label} · ${t.identifier}`:`Any ${t.label}`,r=Object.keys(t.match??{}).length;return[n,t.events.join(`, `),r?`${r} ${r===1?`filter`:`filters`}`:``].filter(Boolean).join(` · `)}}}const Gt={daily:`day`,weekly:`week`,monthly:`month`,yearly:`year`};function Kt(e){if(e.kind===`one_off`)return`Once on ${e.timing.date} at ${e.timing.time} (${e.timezone})`;let t=e.interval??1,n=Gt[e.frequency];return`Every ${t===1?n:`${t} ${n}s`}${e.frequency===`weekly`&&e.weekdays?.length?` on ${e.weekdays.map(e=>e.slice(0,1).toUpperCase()+e.slice(1,3)).join(`, `)}`:e.frequency===`monthly`&&e.dayOfMonth?` on day ${e.dayOfMonth}`:e.frequency===`yearly`&&e.month&&e.dayOfMonth?` on ${String(e.month).padStart(2,`0`)}-${String(e.dayOfMonth).padStart(2,`0`)}`:``} at ${e.time} (${e.timezone})`}function qt(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function $(e){return/* @__PURE__ */ (0,Q.jsxs)(`section`,{className:H(`grid min-w-0 gap-5 border-t border-dashboard-border-emphasis py-8 md:grid-cols-[12rem_minmax(0,1fr)] md:gap-10`,e.changed&&`-ml-4 pl-4 shadow-[inset_2px_0_0_var(--color-dashboard-accent)] sm:-ml-5 sm:pl-5`),children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(Ue,{anchor:qt(e.title),className:`m-0 font-display text-lg font-medium`,title:e.title}),e.changed?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 text-xs text-dashboard-accent-text`,children:`Unsaved changes`}):null,e.detail?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-2 mb-0 text-sm leading-relaxed text-dashboard-text-muted`,children:e.detail}):null]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`grid min-w-0 content-start gap-5`,children:e.children})]})}function Jt(e){let t=e.value??zt(e.automation),[n,r]=(0,Z.useState)(e.value);(0,Z.useEffect)(()=>{let t=setTimeout(()=>r(e.value),300);return()=>clearTimeout(t)},[e.value]);let a=xe.safeParse(n),o=i({queryKey:[`dashboard`,`automation-schedule-preview`,e.automation.id,n],enabled:!!n&&a.success,retry:!1,queryFn:()=>Te(be,`/api/automations/${encodeURIComponent(e.automation.id)}/preview`,n)}),s=t.kind===`recurring`?t.frequency:`once`,c=t.kind===`recurring`?t.time:t.timing.time,l=e.value?o.data?.nextRunAtMs:e.automation.nextRunAtMs,u=e.value!==n||o.isFetching,d=o.error instanceof V?o.error.apiError:o.error?`Schedule preview could not be loaded. Try again.`:e.value&&!a.success&&!u?a.error.issues[0]?.message:void 0;return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-frequency`,children:`Repeat`}),/* @__PURE__ */ (0,Q.jsxs)(X,{id:`schedule-frequency`,value:s,onChange:n=>{let r=n.target.value;(r===`once`||r===`daily`||r===`weekly`||r===`monthly`||r===`yearly`)&&e.onChange(r===`once`?{kind:`one_off`,timezone:t.timezone??e.automation.schedule.timezone,timing:{type:`at`,date:``,time:c}}:{kind:`recurring`,timezone:t.timezone,time:c,frequency:r,interval:1,weekdays:r===`weekly`?[`monday`]:void 0,dayOfMonth:[`monthly`,`yearly`].includes(r)?1:void 0,month:r===`yearly`?1:void 0})},children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`once`,children:`Once`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`daily`,children:`Every day`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`weekly`,children:`Every week`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`monthly`,children:`Every month`}),/* @__PURE__ */ (0,Q.jsx)(`option`,{value:`yearly`,children:`Every year`})]})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-time`,children:`Time`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-time`,type:`time`,value:c,onChange:n=>e.onChange(t.kind===`recurring`?{...t,time:n.target.value}:{...t,timing:{type:`at`,date:t.timing.date,time:n.target.value}})})]})]}),t.kind===`recurring`?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t.frequency===`weekly`?/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-2 text-sm font-semibold`,children:`On`}),/* @__PURE__ */ (0,Q.jsx)(Fe,{className:`grid grid-cols-7 gap-1.5`,multiple:!0,onValueChange:n=>e.onChange({...t,weekdays:n}),value:t.weekdays??[],children:[...Lt.slice(1),Lt[0]].map(e=>/* @__PURE__ */ (0,Q.jsx)(Ae,{"aria-label":e,className:`h-auto min-h-11 min-w-0 border-dashboard-border-emphasis px-1 capitalize data-pressed:border-dashboard-focus/50 data-pressed:bg-dashboard-focus/10 data-pressed:text-dashboard-focus sm:min-h-10 sm:text-sm`,value:e,children:e.slice(0,3)},e))})]}):null,/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-interval`,children:`Interval`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-interval`,type:`number`,min:1,max:365,value:t.interval??1,onChange:n=>e.onChange({...t,interval:n.target.valueAsNumber})}),/* @__PURE__ */ (0,Q.jsx)(ct,{id:`schedule-interval-help`,children:`Number of calendar periods between runs.`})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-start`,children:`Start date`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-start`,type:`date`,value:t.startDate??``,onChange:n=>e.onChange({...t,startDate:n.target.value||void 0})})]})]}),t.frequency===`monthly`||t.frequency===`yearly`?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-day`,children:`Day of month`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-day`,type:`number`,min:1,max:31,value:t.dayOfMonth??1,onChange:n=>e.onChange({...t,dayOfMonth:n.target.valueAsNumber})})]}),t.frequency===`yearly`?/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-month`,children:`Month`}),/* @__PURE__ */ (0,Q.jsx)(X,{id:`schedule-month`,value:t.month??1,onChange:n=>e.onChange({...t,month:Number(n.target.value)}),children:Array.from({length:12},(e,t)=>/* @__PURE__ */ (0,Q.jsx)(`option`,{value:t+1,children:new Intl.DateTimeFormat(`en`,{month:`long`,timeZone:`UTC`}).format(new Date(Date.UTC(2026,t,1)))},t))})]}):null]}):null]}):/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-date`,children:`Date`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-date`,type:`date`,value:t.timing.date,onChange:n=>e.onChange({...t,timing:{type:`at`,time:c,date:n.target.value}})})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`schedule-timezone`,children:`Timezone`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`schedule-timezone`,list:`automation-timezones`,value:t.timezone??``,onChange:n=>e.onChange({...t,timezone:n.target.value})}),/* @__PURE__ */ (0,Q.jsx)(`datalist`,{id:`automation-timezones`,children:[`UTC`,...Intl.supportedValuesOf(`timeZone`)].map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{children:e},e))}),/* @__PURE__ */ (0,Q.jsx)(ct,{id:`schedule-timezone-help`,children:`Use an IANA timezone. The schedule follows local time, including daylight saving time.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{role:`status`,className:`flex gap-3 rounded-md bg-dashboard-fill-soft p-3 text-sm leading-relaxed`,children:[/* @__PURE__ */ (0,Q.jsx)(ie,{"aria-hidden":!0,size:17,className:`mt-0.5 shrink-0 text-dashboard-text-muted`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:u?`Checking schedule…`:d?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`text-rose-300`,children:d}),o.error?/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void o.refetch(),children:`Try again`}):null]}):l?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[`Next run`,` `,new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`,timeZone:e.value?o.data?.schedule.timezone??`UTC`:e.automation.schedule.timezone}).format(l)]}):`No next run.`})]}),e.value?/* @__PURE__ */ (0,Q.jsx)(M,{className:`w-fit`,onClick:()=>e.onChange(void 0),children:`Keep saved schedule`}):null]})}function Yt(e){return e.filters.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-1 text-xs text-dashboard-text-muted`,children:`No filters. Runs on every selected event.`}):/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`mt-1 text-xs text-dashboard-text-muted`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:`Every filter must match:`}),/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5`,children:e.filters.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{className:`break-words`,children:e},e))})]})}const Xt={resourceTypes:[],events:{},anyResourceFields:{}};function Zt(e,t){let n=e.events[t]?.reach;if(typeof n!=`object`)return;let r=n.anyOf.map(t=>e.anyResourceFields[t]?.description??t);return r.length===1?`needs a filter: ${r[0]}`:`needs one of these filters: ${r.join(`; or `)}`}function Qt(e){let[t,n]=(0,Z.useState)(),r=i({queryKey:[`dashboard`,`automation-event-catalog`],queryFn:({signal:e})=>B(fe,`/api/automations/event-catalog`,e),retry:!1}),a=r.data?.find(t=>t.namespace===e.value.namespace),o=a??Xt,s=a?.displayName??e.value.namespace,c=e.value.resourceType===void 0,l=ve(o,e.value),u=r.data?pe(o,e.value):[],d=!l||u.some(e=>e.reason!==`field_not_set`&&e.reason!==`filter_required`),f=r.data?.filter(e=>Se(e).length>0)??[],p=Object.entries(l?.fields??{}),m=p.filter(([t,n])=>e.value.match?.[t]!==void 0||ye(n,e.value.events).length===0),h=(t,n)=>{let r={...e.value.match};n===void 0?delete r[t]:r[t]=n,e.onChange({...e.value,match:r})};return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[r.error?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Event choices could not be loaded.`,children:[`Saved values are kept.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void r.refetch(),children:`Try again`})]}):r.isPending?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`status`,children:`Loading event choices…`}):null,d&&r.data?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Saved trigger · Kept unchanged`,children:[`Some saved values are not in the current catalog. You can edit other fields, or select a new resource type to replace the trigger.`,/* @__PURE__ */ (0,Q.jsx)($t,{displayName:s,source:o,trigger:e.value})]}):null,/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-resource`,children:d?`Replace trigger`:`Resource type`}),/* @__PURE__ */ (0,Q.jsxs)(X,{id:`trigger-resource`,value:d?``:`${e.value.namespace}:${e.value.resourceType??`*`}`,onChange:e=>{let[t,i]=e.target.value.split(`:`);if(i===`*`&&t){n({namespace:t,label:``,events:[]});return}let a=r.data?.find(e=>e.namespace===t)?.resourceTypes.find(e=>e.type===i);t&&a&&n({namespace:t,resourceType:a.type,identifier:``,label:``,events:[]})},children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:``,disabled:!0,children:`Keep saved trigger`}),f.map(e=>/* @__PURE__ */ (0,Q.jsxs)(`option`,{value:`${e.namespace}:*`,children:[e.displayName,` · any resource`]},`${e.namespace}:*`)),r.data?.flatMap(e=>e.resourceTypes.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`option`,{value:`${e.namespace}:${t.type}`,children:[e.displayName,` · `,t.type.replaceAll(`_`,` `)]},`${e.namespace}:${t.type}`)))]})]}),/* @__PURE__ */ (0,Q.jsx)(ft,{onOpenChange:e=>{e||n(void 0)},open:t!==void 0,children:/* @__PURE__ */ (0,Q.jsxs)($e,{children:[/* @__PURE__ */ (0,Q.jsx)(qe,{children:`Replace the saved trigger?`}),/* @__PURE__ */ (0,Q.jsx)(tt,{children:`Its resource, events, and filters will be cleared.`}),/* @__PURE__ */ (0,Q.jsxs)(rt,{children:[/* @__PURE__ */ (0,Q.jsx)(dt,{children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Ge,{onClick:()=>{t&&e.onChange(t),n(void 0)},variant:`primary`,children:`Replace trigger`})]})]})}),!d&&l?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-label`,children:c?`Trigger name`:`Resource name`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`trigger-label`,value:e.value.label,onChange:t=>e.onChange({...e.value,label:t.target.value})})]}),c?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:`Runs for every resource that the filters match.`}):/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`trigger-identifier`,children:`Resource identifier`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`trigger-identifier`,value:e.value.identifier??``,onChange:t=>e.onChange({...e.value,identifier:t.target.value})}),/* @__PURE__ */ (0,Q.jsx)(ct,{id:`trigger-identifier-help`,children:`Use the exact provider resource identifier, not its display name.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-2 text-sm font-semibold`,children:`Run on these events`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis`,children:l.events.map(t=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-start gap-3 px-3 py-3 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(it,{className:`mt-0.5`,checked:e.value.events.includes(t),disabled:e.disabled,onCheckedChange:()=>e.onChange({...e.value,events:e.value.events.includes(t)?e.value.events.filter(e=>e!==t):[...e.value.events,t]})}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`min-w-0 break-words`,children:[he(t),c&&Zt(o,t)?/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`text-dashboard-text-muted`,children:[` `,`· `,Zt(o,t)]}):null]})]},t))})]}),p.length?/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{className:`grid gap-4`,children:[/* @__PURE__ */ (0,Q.jsx)(`legend`,{className:`mb-3 text-sm font-semibold`,children:`Filters`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[`Every filter must match. Leave a filter blank to match any value.`,m.length<p.length?` Filters that a selected event does not set are hidden.`:null]}),m.map(([t,n])=>{let r=e.value.match?.[t],i=u.find(e=>e.field===t);return/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`match-${t}`,children:t}),Array.isArray(r)?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`break-all`,children:_e(t,n,r)}),` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>h(t,void 0),children:`Remove filter`})]}):n.kind===`boolean`||n.enum?/* @__PURE__ */ (0,Q.jsxs)(X,{id:`match-${t}`,value:r===void 0?``:String(r),onChange:e=>h(t,e.target.value===``?void 0:n.kind===`boolean`?e.target.value===`true`:e.target.value),children:[/* @__PURE__ */ (0,Q.jsx)(`option`,{value:``,children:`Any value`}),(n.enum??[`true`,`false`]).map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{children:e},e))]}):/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`match-${t}`,type:n.kind===`number`?`number`:`text`,step:`any`,value:r===void 0?``:String(r),onChange:e=>h(t,e.target.value===``?void 0:n.kind===`number`?e.target.valueAsNumber:e.target.value)}),n.description?/* @__PURE__ */ (0,Q.jsx)(ct,{id:`match-${t}-help`,children:n.description}):null,i?/* @__PURE__ */ (0,Q.jsx)(ht,{children:i.message}):null]},t)})]}):null]}):null,JSON.stringify(e.value)===JSON.stringify(e.original)?null:/* @__PURE__ */ (0,Q.jsx)(M,{className:`w-fit`,onClick:()=>e.onChange(e.original),children:`Keep saved trigger`})]})}function $t(e){let t=ge(e.source,e.trigger);return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`my-2 list-disc pl-5`,children:t.problems.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:e},e))}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-xs`,children:[/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 break-words`,children:[e.displayName,` ·`,` `,e.trigger.resourceType?.replaceAll(`_`,` `)??`any resource`,e.trigger.identifier?` · ${e.trigger.identifier}`:null]}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-1 break-words text-dashboard-text-muted`,children:t.events.join(`, `)}),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:t.filters})]})]})}function en(e){return e.outcomes.length?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-decimal gap-2 pl-5 text-sm`,children:e.outcomes.map((t,n)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:It(t,e.destination)},n))}):/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:`No success message`})}function tn(e){let t=e.original.length?e.original:[{action:`send_message`,destination:`current_conversation`}],n=[...e.original.flatMap((t,n)=>typeof t.destination==`string`?[]:[{value:`saved:${n}`,label:It(t,e.destination),outcome:t}]),{value:`current_conversation`,label:`${e.destination.label} · ${e.destination.visibility}`,outcome:{action:`send_message`,destination:`current_conversation`}},{value:`task_creator`,label:`Creator · Direct message`,outcome:{action:`send_message`,destination:`task_creator`}}];return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(Xe,{"aria-label":`Success messages`,disabled:e.disabled,className:`flex flex-wrap gap-x-6 gap-y-3`,onValueChange:n=>e.onChange(n?t:[]),value:e.value.length>0,children:[!0,!1].map(e=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`inline-flex min-h-8 cursor-pointer items-center gap-2 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(Qe,{value:e}),e?`Send a message`:`No success message`]},String(e)))}),e.value.length?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-4 sm:gap-2`,children:[e.value.map((t,r)=>{let i=e.original.findIndex(e=>JSON.stringify(e)===JSON.stringify(t));return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`w-4 text-xs text-dashboard-text-muted`,children:[r+1,`.`]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:H(`min-w-0 flex-1`,e.value.length>1&&`order-last basis-full sm:order-none sm:basis-auto`),children:/* @__PURE__ */ (0,Q.jsx)(X,{"aria-label":`Message ${r+1} destination`,value:typeof t.destination==`string`?t.destination:`saved:${i}`,onChange:t=>{let i=n.find(e=>e.value===t.target.value);i&&e.onChange(e.value.map((e,t)=>t===r?i.outcome:e))},children:n.map(e=>/* @__PURE__ */ (0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),e.value.length>1?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(M,{size:`icon`,className:`ml-auto sm:ml-0`,"aria-label":`Move message ${r+1} up`,disabled:r===0,onClick:()=>{let n=[...e.value],i=n[r-1];i&&(n[r-1]=t,n[r]=i,e.onChange(n))},children:/* @__PURE__ */ (0,Q.jsx)(Nt,{size:16})}),/* @__PURE__ */ (0,Q.jsx)(M,{size:`icon`,"aria-label":`Remove message ${r+1}`,onClick:()=>e.onChange(e.value.filter((e,t)=>t!==r)),children:/* @__PURE__ */ (0,Q.jsx)(L,{size:16})})]}):null]},r)}),e.value.length<5?/* @__PURE__ */ (0,Q.jsxs)(M,{className:`w-fit`,onClick:()=>e.onChange([...e.value,{action:`send_message`,destination:`task_creator`}]),children:[/* @__PURE__ */ (0,Q.jsx)(ce,{size:15}),`Add message`]}):null]}):/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm leading-relaxed text-dashboard-text-muted`,children:`Junior still does the work. No message is sent after success.`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[e.value.length?`Messages are sent in this order. `:``,`This does not limit actions in the instruction.`]})]})}function nn(e){let r=lt(),[i,a]=(0,Z.useState)(e.automation),[o,s]=(0,Z.useState)(()=>Rt(e.automation)),[c,d]=(0,Z.useState)({}),[f,m]=(0,Z.useState)(),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1),y=u(),b=n(),x=Bt(i,o),S=Object.keys(x).length>0,ee={kind:i.kind,revision:i.revision,...x},C=l(()=>S&&!v.current),w=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{C.state===`blocked`&&w.current?.focus()},[C.state]);let T=`/api/automations/${encodeURIComponent(i.id)}`;(0,Z.useEffect)(()=>{let e=e=>{S&&!v.current&&(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[S]);let E=()=>requestAnimationFrame(()=>(_.current?.querySelector(`[aria-invalid="true"]`)??_.current?.querySelector(`[data-save-error]`))?.focus()),D=t({mutationFn:()=>we(z,T,ee),onSuccess:async()=>{v.current=!0,await b.invalidateQueries({queryKey:[`dashboard`,`automations`]}),r.add({title:`Automation saved`,description:`Changes apply to future work.`,type:`success`}),y(e.returnPath)},onError:e=>{d(e instanceof V?e.fields??{}:{}),E()}});function te(e){f&&(s(e?{...Rt(f),...x}:Rt(f)),a(f),m(void 0),D.reset(),d({}))}let O=t({mutationFn:()=>B(z,`${T}/edit`),onSuccess:m}),k=D.error instanceof V&&D.error.code===`conflict`,A=e=>s(t=>({...t,...e})),j=e=>{A({[e]:Rt(i)[e]}),g(e=>e+1)},N=e=>Object.entries(c).filter(([t])=>t===e||t.startsWith(`${e}.`)).flatMap(([,e])=>e).join(` `)||void 0,P=i.kind===`scheduled`?`schedule`:`trigger`,F=i.ownedByViewer,I=e.summary.createdBy,L=!F&&i.credentialMode===`creator`&&(x.instruction!==void 0||x[P]!==void 0||x.outcomes!==void 0),ne=N(P),re=e=>({"aria-invalid":!!N(e)||void 0,"aria-describedby":N(e)?`${e}-error`:void 0});return/* @__PURE__ */ (0,Q.jsxs)(`form`,{ref:_,noValidate:!0,onSubmit:e=>{if(e.preventDefault(),D.isPending||k||!S)return;let t=Ce.safeParse(ee);if(t.success)d({}),D.mutate();else{let e={};for(let n of t.error.issues)(e[n.path.join(`.`)]??=[]).push(n.message);d(e),E()}},children:[C.state===`blocked`?/* @__PURE__ */ (0,Q.jsx)(`div`,{tabIndex:-1,ref:w,className:`mb-6 outline-none`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Discard unsaved changes?`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Your changes have not been saved.`}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>C.reset(),children:`Keep editing`}),/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>C.proceed(),children:`Discard changes`})]})]})}):null,D.error||Object.keys(c).length?/* @__PURE__ */ (0,Q.jsx)(`div`,{tabIndex:-1,"data-save-error":!0,className:`mb-6 outline-none`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{tone:k?`warning`:`error`,title:k?`This automation changed while you were editing.`:`Changes could not be saved.`,children:[/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-1`,children:[`Your edits are still here.`,` `,k?`Review the latest version before saving again.`:D.error instanceof V?D.error.apiError:`Check the fields below, or try again.`]}),k?/* @__PURE__ */ (0,Q.jsx)(M,{disabled:O.isPending,onClick:()=>O.mutate(),children:O.isPending?`Loading…`:`Review latest version`}):null,O.error?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,children:`The latest version could not be loaded. Try again.`}):null]})}):null,f?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`mb-6`,children:/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Compare your edits with the latest saved version`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Only the fields you changed are shown. Keeping your edits will replace these fields. Other saved fields stay unchanged.`}),Object.entries(x).map(([e,t])=>/* @__PURE__ */ (0,Q.jsxs)(`section`,{className:`my-4`,children:[/* @__PURE__ */ (0,Q.jsx)(`h3`,{className:`text-sm font-semibold capitalize`,children:e===`credentialMode`?`Credentials`:e}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Latest saved`}),/* @__PURE__ */ (0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-sm`,children:rn(e===`schedule`&&f.kind===`scheduled`?zt(f):f[e])})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{children:`Your edit`}),/* @__PURE__ */ (0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-sm`,children:rn(t)})]})]})]},e)),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>te(!0),children:`Keep my changed fields`}),/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>te(!1),children:`Use latest saved version`})]})]})}):null,F?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-0 mb-6 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted`,children:[I,` created this automation. You can edit it because it is in a public channel. Only `,I,` can turn on their connected accounts. Version history keeps every saved change.`]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10`,children:[/* @__PURE__ */ (0,Q.jsxs)(`fieldset`,{disabled:D.isPending,className:`min-w-0 [&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0`,children:[/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.title!==void 0||x.instruction!==void 0,title:`What to do`,detail:`Give Junior a clear instruction and a name you can find later.`,children:[/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`title`,children:`Title`}),/* @__PURE__ */ (0,Q.jsx)(K,{size:`comfortable`,id:`title`,value:o.title,placeholder:e.summary.title,onChange:e=>A({title:e.target.value}),...re(`title`)}),/* @__PURE__ */ (0,Q.jsx)(ht,{id:`title-error`,children:N(`title`)})]}),/* @__PURE__ */ (0,Q.jsxs)(q,{children:[/* @__PURE__ */ (0,Q.jsx)(J,{htmlFor:`instruction`,children:`Instruction`}),/* @__PURE__ */ (0,Q.jsx)(Ze,{id:`instruction`,rows:8,value:o.instruction,onChange:e=>A({instruction:e.target.value}),...re(`instruction`),className:`resize-y text-base leading-relaxed sm:text-sm`}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-right text-xs text-dashboard-text-muted`,children:[o.instruction.length.toLocaleString(),` / 4,000`]}),/* @__PURE__ */ (0,Q.jsx)(ht,{id:`instruction-error`,children:N(`instruction`)})]})]}),/* @__PURE__ */ (0,Q.jsx)($,{changed:x[P]!==void 0,title:`When to run`,detail:i.kind===`scheduled`?`Choose a schedule in a specific timezone.`:`Run when a matching event occurs.`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{id:`${P}-error`,tabIndex:-1,"aria-invalid":!!ne||void 0,className:`grid min-w-0 gap-5 outline-none`,children:[ne?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-rose-300`,children:ne}):null,i.kind===`scheduled`?/* @__PURE__ */ (0,Q.jsx)(Jt,{automation:i,value:o.schedule,onChange:e=>A({schedule:e})}):/* @__PURE__ */ (0,Q.jsx)(Qt,{value:o.trigger??i.trigger,original:i.trigger,disabled:D.isPending,onChange:e=>A({trigger:e})})]})}),/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.outcomes!==void 0,title:`Where results go`,detail:`Choose who gets a message after successful work.`,children:[N(`outcomes`)?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-rose-300`,children:N(`outcomes`)}):null,/* @__PURE__ */ (0,Q.jsx)(tn,{value:o.outcomes,original:i.outcomes,destination:e.summary.destination,disabled:D.isPending,onChange:e=>A({outcomes:e})})]}),/* @__PURE__ */ (0,Q.jsxs)($,{changed:x.credentialMode!==void 0,title:`Credentials`,detail:`Choose which connected accounts Junior can use.`,children:[/* @__PURE__ */ (0,Q.jsx)(Xe,{"aria-label":`Credential mode`,disabled:D.isPending,className:`divide-y divide-dashboard-border-subtle rounded-md border border-dashboard-border-emphasis`,onValueChange:e=>A({credentialMode:e}),value:L?`system`:o.credentialMode,children:[[`creator`,F?`Your connected accounts`:`${I}’s connected accounts`,F?`Uses accounts connected by you, the creator.`:`Uses accounts connected by ${I}. Only ${I} can turn this on.`],[`system`,`System credentials only`,F?`Does not use your connected accounts. Some work may not be possible.`:`Does not use anyone’s connected accounts. Some work may not be possible.`]].map(([e,t,n])=>/* @__PURE__ */ (0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 px-4 py-4 has-data-checked:bg-dashboard-fill-soft has-data-disabled:cursor-not-allowed has-data-disabled:opacity-60`,children:[/* @__PURE__ */ (0,Q.jsx)(Qe,{className:`mt-0.5`,value:e,disabled:e===`creator`&&!F&&(i.credentialMode!==`creator`||L)}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-dashboard-text-muted`,children:n})]})]},e))}),L?/* @__PURE__ */ (0,Q.jsxs)(Y,{title:`Saving switches this automation to system credentials.`,children:[`Only `,I,` can let a changed instruction,`,i.kind===`event`?` trigger,`:` schedule,`,` or result destination use their connected accounts.`]}):null,N(`credentialMode`)?/* @__PURE__ */ (0,Q.jsx)(`p`,{role:`alert`,children:N(`credentialMode`)}):null]})]},h),/* @__PURE__ */ (0,Q.jsx)(Ht,{changes:x,disabled:D.isPending,onUndo:j,original:i,summary:e.summary})]}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mb-5 text-xs leading-relaxed text-dashboard-text-muted sm:hidden`,children:`Changes apply to future work. Saving does not run this automation.`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`sticky bottom-0 z-20 -mx-4 border-t border-dashboard-border-emphasis bg-dashboard-bg px-4 py-4 sm:-mx-8 sm:px-8`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,role:`status`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs font-medium sm:text-sm`,children:D.isPending?`Saving…`:S?`Unsaved changes`:`Unchanged`}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 hidden text-xs text-dashboard-text-muted sm:block`,children:`Changes apply to future work. Saving does not run it.`})]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(p,{to:e.returnPath,className:`inline-flex min-h-11 items-center rounded-md border border-dashboard-border-emphasis px-3 text-sm text-dashboard-text no-underline sm:min-h-9`,children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(M,{type:`submit`,variant:`primary`,className:`min-h-11 sm:min-h-9`,disabled:!S||D.isPending||k,children:`Save changes`})]})]})})]})}function rn(e){return e==null?`Not set`:typeof e==`string`?e:JSON.stringify(e,null,2)}function an(){return/* @__PURE__ */ (0,Q.jsx)(`div`,{role:`status`,"aria-label":`Loading automation editor`,children:[`What to do`,`When to run`,`Where results go`,`Credentials`].map((e,t)=>/* @__PURE__ */ (0,Q.jsxs)($,{title:e,children:[/* @__PURE__ */ (0,Q.jsx)(Oe,{className:`h-4 w-24`}),/* @__PURE__ */ (0,Q.jsx)(Oe,{className:t===0?`h-48 w-full`:`h-20 w-full`})]},e))})}function on({automation:e}){let t=ot(!0,e.id),n=t.data?.executions.slice(0,3)??[];return/* @__PURE__ */ (0,Q.jsxs)(`section`,{"aria-label":`Recent runs`,className:`grid min-w-0 gap-2.5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[/* @__PURE__ */ (0,Q.jsx)(`h3`,{className:`m-0 text-xs font-medium text-dashboard-text-muted`,children:`Recent runs`}),e.totalRuns>0||n.length>0?/* @__PURE__ */ (0,Q.jsx)(p,{className:`${De} text-xs`,to:W(e.id,`runs`),children:`View all runs`}):null]}),t.isPending?/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-busy":`true`,role:`status`,className:`grid gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Loading recent runs`}),Array.from({length:3},(e,t)=>/* @__PURE__ */ (0,Q.jsx)(Oe,{className:`h-14 rounded-md`},t))]}):null,t.error?/* @__PURE__ */ (0,Q.jsxs)(mt,{children:[`Recent runs could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void t.refetch(),children:`Try again`})]}):null,t.data&&n.length===0?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:e.totalRuns===0?`No runs yet. Results will appear here after the first run.`:`No recent runs are available. Older run details may have expired.`}):null,n.length>0?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 list-none divide-y divide-dashboard-border-subtle p-0`,children:n.map(t=>{let n=[t.durationMs===void 0?void 0:Ie(t.durationMs),t.costUsd===void 0?void 0:ze({total:t.costUsd})].filter(Boolean).join(` · `),r=t.title===e.title?void 0:t.title,i=/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-1`,children:[/* @__PURE__ */ (0,Q.jsx)(ut,{size:`compact`,tone:t.status===`completed`?`success`:t.status===`failed`?`danger`:`warning`,children:t.status}),/* @__PURE__ */ (0,Q.jsx)(`time`,{className:`text-xs text-dashboard-text-muted`,dateTime:t.executedAt,title:R(t.executedAt),children:Be(t.executedAt)})]}),r||n?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-3 text-xs text-dashboard-text-muted`,children:[r?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 min-w-0 truncate text-dashboard-text`,title:r,children:r}):null,n?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 shrink-0 tabular-nums`,children:n}):null]}):null,t.conversationId?null:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:`No Conversation recorded`})]}),a=`grid min-w-0 gap-1 rounded-md px-2 py-2.5`;return/* @__PURE__ */ (0,Q.jsx)(`li`,{children:t.conversationId?/* @__PURE__ */ (0,Q.jsx)(p,{"aria-label":`Open ${t.status} run from ${R(t.executedAt)}`,className:`${a} text-inherit no-underline transition-colors hover:bg-dashboard-fill-hover focus-visible:outline-2 focus-visible:outline-dashboard-focus`,to:at(t.conversationId),children:i}):/* @__PURE__ */ (0,Q.jsx)(`div`,{className:a,children:i})},t.executionId)})}):null]})}const sn=/*#__PURE__*/ Z.createContext(void 0);function cn(){let e=Z.useContext(sn);if(e===void 0)throw Error(k(10));return e}const ln={value:()=>null},un=/*#__PURE__*/ Z.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,hiddenUntilFound:a,keepMounted:o,loopFocus:s,onValueChange:c,multiple:l=!1,orientation:u=`vertical`,value:d,defaultValue:f,style:p,...m}=e,h=f??w,g=Z.useRef([]),[v,y]=E({controlled:d,default:h,name:`Accordion`,state:`value`}),x=b((e,t,n)=>{let r;r=l?t?[...v,e]:v.filter(t=>t!==e):v[0]===e?[]:[e],c?.(r,n),!n.isCanceled&&y(r)}),S=Z.useMemo(()=>({value:v,disabled:i,orientation:u}),[v,i,u]),C=Z.useMemo(()=>({disabled:i,handleValueChange:x,hiddenUntilFound:a??!1,keepMounted:o??!1,state:S,value:v}),[i,x,a,o,S,v]),T=_(`div`,e,{state:S,ref:t,props:m,stateAttributesMapping:ln});return/*#__PURE__*/ (0,Q.jsx)(sn.Provider,{value:C,children:/*#__PURE__*/ (0,Q.jsx)(ee,{elementsRef:g,children:T})})}),dn=/*#__PURE__*/ Z.createContext(void 0);function fn(){let e=Z.useContext(dn);if(e===void 0)throw Error(k(9));return e}const pn={...x,index:e=>({"data-index":String(e)}),...v,value:()=>null},mn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{className:n,disabled:r=!1,onOpenChange:i,render:a,value:o,style:s,...c}=e,{ref:l,index:u}=O(),{disabled:d,handleValueChange:f,state:p,value:m}=cn(),h=A(),g=o??h,v=r||d,y=m.includes(g),x=b((e,t)=>{i?.(e,t),!t.isCanceled&&f(g,e,t)}),S=T({open:y,onOpenChange:x,disabled:v}),ee=Z.useMemo(()=>({...S,onOpenChange:x,state:{open:S.open,disabled:S.disabled,transitionStatus:S.transitionStatus}}),[S,x]),C=Z.useMemo(()=>({...p,hidden:!y&&!S.mounted,index:u,disabled:v,open:y}),[S.mounted,v,u,y,p]),w=A(),[E,D]=Z.useState(),k=E===null?void 0:E??w,j=Z.useMemo(()=>({defaultTriggerId:w,open:y,state:C,setTriggerId:D,triggerId:k}),[w,y,C,D,k]),M=_(`div`,e,{state:C,ref:[t,l],props:c,stateAttributesMapping:pn});return/*#__PURE__*/ (0,Q.jsx)(te.Provider,{value:ee,children:/*#__PURE__*/ (0,Q.jsx)(dn.Provider,{value:j,children:M})})}),hn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{render:n,className:r,style:i,...a}=e,{state:o}=fn();return _(`h3`,e,{state:o,ref:t,props:a,stateAttributesMapping:pn})}),gn={...pn,...C},_n=/*#__PURE__*/ Z.forwardRef(function(e,t){let{disabled:n,className:r,id:i,render:a,nativeButton:o=!0,style:s,...c}=e,{panelId:l,open:u,handleTrigger:d,disabled:f}=D(),{getButtonProps:p,buttonRef:m}=h({disabled:n||f,native:o}),{defaultTriggerId:g,state:v,setTriggerId:y}=fn(),b=i||void 0,x=b??g;return S(()=>(y(e=>b??(e===null?void 0:e)),()=>{y(e=>e===b?null:e)}),[b,y]),_(`button`,e,{state:v,ref:[t,m],props:[{"aria-controls":u?l:void 0,"aria-expanded":u,id:x,onClick:d},c,p],stateAttributesMapping:gn})}),vn=/*#__PURE__*/ Z.forwardRef(function(e,t){let{className:n,hiddenUntilFound:r,keepMounted:i,id:a,render:o,style:s,...c}=e,{hiddenUntilFound:l,keepMounted:u}=cn(),{defaultPanelId:d,mounted:f,onOpenChange:p,open:m,setMounted:h,setOpen:v,setPanelIdState:b,transitionStatus:x}=D(),ee=r??l,C=i??u,w=a||void 0,T=a??d;S(()=>(b(e=>w??(e===null?void 0:e)),()=>{b(e=>e===w?null:e)}),[w,b]);let{height:E,props:te,ref:O,shouldPreventOpenAnimation:k,shouldRender:A,transitionStatus:j,width:M}=y({externalRef:t,hiddenUntilFound:ee,id:T,keepMounted:C,mounted:f,onOpenChange:p,open:m,setMounted:h,setOpen:v,transitionStatus:x}),{state:N,triggerId:P}=fn(),F={...N,transitionStatus:j},I=g(s,F),L=_(`div`,{...e,style:void 0},{state:F,ref:O,props:[te,{"aria-labelledby":P,role:`region`,style:{"--accordion-panel-height":E===void 0?`auto`:`${E}px`,"--accordion-panel-width":M===void 0?`auto`:`${M}px`}},c,I?{style:I}:void 0,k?{style:{animationName:`none`}}:void 0],stateAttributesMapping:pn});return A?L:null});function yn({className:e,...t}){return/* @__PURE__ */ (0,Q.jsx)(un,{"data-slot":`accordion`,className:r(`flex w-full flex-col`,e),...t})}function bn({className:e,...t}){return/* @__PURE__ */ (0,Q.jsx)(mn,{"data-slot":`accordion-item`,className:r(`not-last:border-b not-last:border-dashboard-border-subtle`,e),...t})}function xn({className:e,children:t,...n}){return/* @__PURE__ */ (0,Q.jsx)(hn,{className:`flex`,children:/* @__PURE__ */ (0,Q.jsxs)(_n,{"data-slot":`accordion-trigger`,className:r(`group/accordion-trigger relative flex min-w-0 flex-1 cursor-pointer items-center justify-between gap-3 rounded-sm py-2.5 text-left font-sans text-sm font-medium text-dashboard-text transition-colors hover:text-dashboard-text-solid outline-none focus-visible:outline-2 focus-visible:outline-dashboard-focus aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-dashboard-text-muted`,e),...n,children:[t,/* @__PURE__ */ (0,Q.jsx)(N,{"data-slot":`accordion-trigger-icon`,className:`pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden`}),/* @__PURE__ */ (0,Q.jsx)(P,{"data-slot":`accordion-trigger-icon`,className:`pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline`})]})})}function Sn({className:e,children:t,...n}){return/* @__PURE__ */ (0,Q.jsx)(vn,{"data-slot":`accordion-content`,className:`h-(--accordion-panel-height) overflow-hidden text-sm transition-[height] duration-180 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none`,...n,children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:r(`pt-0 pb-2.5`,e),children:t})})}function Cn({automation:e}){let t=e.kind===`event`&&e.trigger.problems.length>0;return/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-label":`Automation state`,"aria-live":`polite`,role:`status`,children:/* @__PURE__ */ (0,Q.jsx)(ut,{size:`compact`,tone:e.status===`paused`||e.status===`completed`?`neutral`:e.status===`blocked`||t?`warning`:`success`,children:e.status===`active`&&t?`Trigger unavailable`:e.status})})}function wn({automation:e}){let t=e.lastRunStatus?`Last run ${e.lastRunStatus}`:`Last run`;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-1.5`,children:[/* @__PURE__ */ (0,Q.jsx)(On,{automation:e}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:e.lastRunAt?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t,` ·`,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.lastRunAt,title:R(e.lastRunAt),children:Be(e.lastRunAt)})]}):e.lastRunStatus?`${t} · time not recorded`:e.totalRuns===0?`No runs yet`:`Last run time not recorded`})]})}function Tn(e){if(e.status===`blocked`||e.status===`paused`&&e.statusReason)return`fix`;if(e.kind===`event`&&e.trigger.problems.length>0)return`trigger`;if(e.lastRunStatus===`failed`||e.lastRunStatus===`blocked`)return`last_run`}function En(e){return Tn(e)!==void 0}function Dn({automation:e,editPath:t}){let n=Tn(e);if(!n)return null;let r=e.status===`paused`,i=e.kind===`event`?e.trigger.problems:[],a=n===`fix`,o=i.length>0,s=n===`last_run`;return/* @__PURE__ */ (0,Q.jsxs)(Y,{title:a?`Fix this before resuming`:o?`Trigger unavailable`:`Check the last run`,children:[a?/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 break-words`,children:[e.statusReason??`Check the last run to see what needs fixing.`,` `,!e.ownedByViewer&&e.credentialMode===`creator`?`It uses accounts connected by ${e.createdBy}. Ask them to resume it, or switch it to Junior's credentials first.`:null]}):null,o?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`ul`,{className:`my-1 list-disc pl-5`,children:i.map(e=>/* @__PURE__ */ (0,Q.jsx)(`li`,{className:`break-words`,children:e},e))}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:`Edit the trigger, or enable its plugin again.`})]}):null,s&&!a&&!o?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0`,children:e.status===`active`?`Future runs are still on.`:r?`Review the last result before resuming.`:`Review the last result for details.`}):null,o?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:t,children:`Change trigger`}):e.lastConversationId?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:at(e.lastConversationId),children:`Open last run`}):e.totalRuns>0?/* @__PURE__ */ (0,Q.jsx)(p,{className:H(j({variant:`primary`}),`mt-3`),to:W(e.id,`runs`),children:`View run history`}):null]})}function On({automation:e}){let t;if(e.status===`completed`)t=`No future runs`;else if(e.status===`paused`)t=`No new runs while paused`;else if(e.status===`blocked`)t=`New runs are blocked until this is fixed`;else if(e.kind===`event`)t=e.trigger.problems.length===0?`Waiting for a matching event`:`Waiting for a trigger fix`;else if(e.nextRunAt){let t=Intl.DateTimeFormat().resolvedOptions().timeZone,n=R(e.nextRunAt,e.timezone),r=R(e.nextRunAt,t),i=Date.parse(e.nextRunAt)<=Date.now()?`Run was due`:`Next run`;return/* @__PURE__ */ (0,Q.jsx)(yn,{children:/* @__PURE__ */ (0,Q.jsxs)(bn,{value:`next-run`,children:[/* @__PURE__ */ (0,Q.jsx)(xn,{className:`py-1 text-sm font-normal`,children:/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[i,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:Be(e.nextRunAt)})]})}),/* @__PURE__ */ (0,Q.jsx)(Sn,{children:/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 mt-1 grid gap-1 border-l border-dashboard-border pl-3 text-xs leading-relaxed`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-dashboard-text-muted`,children:`Schedule time`}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0`,children:/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:n})}),r===n?null:/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`mt-1 text-dashboard-text-muted`,children:`Your time`}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0`,children:/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:e.nextRunAt,children:r})})]})]})})]})})}else t=`Next run not scheduled`;return/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text`,children:t})}function kn(e){let{automation:t}=e;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-6 lg:grid-cols-[minmax(0,1fr)_18rem] lg:gap-10`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 content-start gap-6`,children:[/* @__PURE__ */ (0,Q.jsx)(Dn,{automation:t,editPath:e.editPath}),/* @__PURE__ */ (0,Q.jsx)(An,{automation:t}),/* @__PURE__ */ (0,Q.jsx)(U,{padding:`sm`,children:/* @__PURE__ */ (0,Q.jsx)(on,{automation:t})}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`lg:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(Mn,{automation:t})})]}),/* @__PURE__ */ (0,Q.jsxs)(`aside`,{"aria-label":`Automation status`,className:`grid min-w-0 content-start gap-3 max-lg:row-start-1`,children:[/* @__PURE__ */ (0,Q.jsx)(Nn,{title:`Status`,children:/* @__PURE__ */ (0,Q.jsx)(wn,{automation:t})}),/* @__PURE__ */ (0,Q.jsx)(jn,{automation:t,range:e.range}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-lg:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(Mn,{automation:t})})]})]})}function An(e){let{automation:t}=e,n=t.ownedByViewer?`you`:t.createdBy;return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 [&>section:first-child]:border-t-0 [&>section:first-child]:pt-0`,children:[/* @__PURE__ */ (0,Q.jsx)($,{title:`What to do`,children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`text-base leading-relaxed [overflow-wrap:anywhere]`,children:/* @__PURE__ */ (0,Q.jsx)(st,{mentions:t.mentions??[],text:t.instruction})})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`When to run`,children:t.kind===`scheduled`?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:oe(t)}):/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-1 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 break-words`,children:t.resource}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 break-words text-dashboard-text-muted`,children:t.trigger.events.join(`, `)}),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:t.trigger.filters})]})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`Where results go`,children:/* @__PURE__ */ (0,Q.jsx)(en,{outcomes:t.outcomes,destination:t.destination})}),/* @__PURE__ */ (0,Q.jsx)($,{title:`Credentials`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm`,children:t.credentialMode===`creator`?`Uses accounts connected by ${n}.`:`System credentials only. Junior does not use anyone’s connected accounts.`})})]})}function jn(e){let{automation:t,range:n}=e,r=ot(!0,t.id),i=r.data?Me({days:r.data.executionDays,hours:r.data.executionHours,sixHours:r.data.executionSixHours,range:n}).reduce((e,t)=>({blocked:e.blocked+t.blocked,failed:e.failed+t.failed}),{blocked:0,failed:0}):void 0;return/* @__PURE__ */ (0,Q.jsx)(Nn,{title:n===1?`Last 24 hours`:`Last ${n} days`,children:/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 grid grid-cols-2 gap-x-4 gap-y-3`,children:[/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Runs`,value:t.runs[n]}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Spend`,value:ze({total:t.costUsd[n]})}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Failed`,value:i?.failed??`—`}),/* @__PURE__ */ (0,Q.jsx)(Pn,{label:`Blocked`,value:i?.blocked??`—`})]})})}function Mn(e){let{automation:t}=e,n=f(),r=Je(!0,t.id).data?.activeVersion;return/* @__PURE__ */ (0,Q.jsxs)(Nn,{title:`About`,children:[/* @__PURE__ */ (0,Q.jsxs)(`dl`,{className:`m-0 grid gap-3 text-sm`,children:[/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Created by`,children:t.createdByEmail?/* @__PURE__ */ (0,Q.jsx)(p,{className:De,to:Le(t.createdByEmail),children:t.ownedByViewer?`You`:t.createdBy}):t.ownedByViewer?`You`:t.createdBy}),/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Created`,children:R(t.createdAt)}),/* @__PURE__ */ (0,Q.jsxs)(Fn,{label:`Destination`,children:[t.destination.label,` ·`,` `,t.destination.visibility===`private`?`private`:`public`]}),/* @__PURE__ */ (0,Q.jsx)(Fn,{label:`Version`,children:/* @__PURE__ */ (0,Q.jsx)(p,{className:De,to:G(W(t.id,`versions`),n.search),children:r?`Version ${r}`:`Version history`})})]}),t.ownedByViewer?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-3 mb-0 text-xs leading-relaxed text-dashboard-text-muted`,children:[t.destination.visibility===`private`?null:`You can edit, pause, or delete it because it is in a public channel. `,`Only `,t.createdBy,` can turn on their connected accounts, or resume or run it while it uses them.`]})]})}function Nn(e){return/* @__PURE__ */ (0,Q.jsxs)(U,{as:`section`,padding:`sm`,children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 mb-3 font-sans text-xs font-medium text-dashboard-text-muted`,children:e.title}),e.children]})}function Pn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-xs text-dashboard-text-muted`,children:e.label}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 mt-0.5 font-display text-xl font-light tabular-nums text-dashboard-text`,children:e.value})]})}function Fn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-0.5`,children:[/* @__PURE__ */ (0,Q.jsx)(`dt`,{className:`text-xs text-dashboard-text-muted`,children:e.label}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 min-w-0 break-words`,children:e.children})]})}const In=[{color:`var(--color-emerald-300)`,key:`completed`,label:`Completed`},{color:`var(--color-rose-300)`,key:`failed`,label:`Failed`},{color:`var(--color-amber-300)`,key:`blocked`,label:`Blocked`}],Ln=Object.fromEntries(In.map(e=>[e.key,{color:e.color,label:e.label}]));function Rn(e){let t=e.bucketUnit??`day`,n=e.days,r=n.map(e=>e.completed+e.failed+e.blocked),i=Math.max(1,...r),a=r.some(e=>e>0);return/* @__PURE__ */ (0,Q.jsxs)(U,{className:`min-h-[15rem] p-4 sm:p-5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`h2`,{className:`m-0 font-display text-xl font-medium text-dashboard-text`,children:`Runs over time`}),/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`mt-1 mb-0 font-sans text-xs leading-relaxed text-dashboard-text-muted`,children:t===`hour`?`Terminal runs for this automation each hour.`:t===`6hour`?`Terminal runs for this automation each 6 hours.`:`Terminal runs for this automation each day.`})]}),/* @__PURE__ */ (0,Q.jsx)(Mt,{ariaLabel:`Automation execution status legend`,items:In}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`relative mt-3 overflow-hidden`,children:[/* @__PURE__ */ (0,Q.jsx)(kt,{className:`aspect-auto h-55 w-full`,config:Ln,children:/* @__PURE__ */ (0,Q.jsxs)(jt,{"aria-label":`Automation executions during the last ${e.range===1?`24 hours`:`${e.range} days`}`,data:n,margin:Tt,role:`img`,children:[/* @__PURE__ */ (0,Q.jsx)(Ct,{strokeDasharray:`3 5`,vertical:!1}),/* @__PURE__ */ (0,Q.jsx)(Ot,{maximum:i}),/* @__PURE__ */ (0,Q.jsx)(Dt,{keys:n.map(e=>e.date)}),/* @__PURE__ */ (0,Q.jsx)(Et,{content:/* @__PURE__ */ (0,Q.jsx)(wt,{rows:e=>[[`completed`,e.completed],[`failed`,e.failed],[`blocked`,e.blocked],[`total`,e.completed+e.failed+e.blocked]]})}),In.map(e=>/* @__PURE__ */ (0,Q.jsx)(At,{dataKey:e.key,fill:`var(--color-${e.key})`,fillOpacity:.82,isAnimationActive:!1,maxBarSize:13,stackId:`status`},e.key))]})}),a?null:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-0 grid place-items-center pt-12 font-sans text-xs text-dashboard-text-muted`,children:`No automation executions in this period.`})]})]})}const zn=`result`,Bn=[``,`completed`,`failed`,`blocked`],Vn=`grid-cols-[minmax(0,1fr)_5.5rem_5.5rem_5.5rem_auto_2rem]`;function Hn(e){let{automation:t}=e,n=ot(!0,t.id),[r,i]=We(zn,``,Bn),a=(0,Z.useMemo)(()=>(n.data?.executions??[]).filter(e=>!r||e.status===r),[n.data,r]),o=(0,Z.useMemo)(()=>(n.data?.executions??[]).map(e=>({...e,automationId:t.id,automationTitle:t.title,kind:t.kind})),[t,n.data]),s=_t(a.map(e=>e.executionId));return/* @__PURE__ */ (0,Q.jsxs)(vt,{details:s.runId?/* @__PURE__ */ (0,Q.jsx)(bt,{loading:!n.data&&!n.error,onClose:s.close,run:o.find(e=>e.executionId===s.runId),showAutomation:!1},s.runId):null,label:`Runs list`,listRef:s.listRef,children:[e.header,n.data?/* @__PURE__ */ (0,Q.jsx)(Un,{data:n.data,executions:a,onResultChange:i,onRowsKeyDown:s.onRowsKeyDown,onSelect:s.toggle,range:e.range,result:r,selectedRunId:s.runId}):n.error?/* @__PURE__ */ (0,Q.jsxs)(mt,{children:[`Runs could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void n.refetch(),children:`Try again`})]}):/* @__PURE__ */ (0,Q.jsx)(ke,{label:`Loading runs`,variant:`list`})]})}function Un(e){let{data:t,range:n}=e,r=(0,Z.useMemo)(()=>Kn(t.executions),[t.executions]);return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[t.executionDays.length>0?/* @__PURE__ */ (0,Q.jsx)(Rn,{bucketUnit:Ne(n),days:Me({days:t.executionDays,hours:t.executionHours,sixHours:t.executionSixHours,range:n,emptySixHour:e=>({blocked:0,completed:0,date:e,failed:0})}),range:n}):null,/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-x-5 gap-y-3`,children:[/* @__PURE__ */ (0,Q.jsx)(xt,{ariaLabel:`Run result`,items:[{count:t.executions.length,label:`All`,value:``},{count:r.completed,label:`Completed`,value:`completed`},{count:r.failed,label:`Failed`,value:`failed`},{count:r.blocked,label:`Blocked`,value:`blocked`}],onChange:t=>e.onResultChange(t),value:e.result}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`m-0 text-xs text-dashboard-text-muted`,children:[t.automation.totalRuns,` total · newest first`]})]}),e.executions.length===0?/* @__PURE__ */ (0,Q.jsx)(U,{padding:`md`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:t.executions.length===0?`This automation has not run yet.`:`No ${e.result} runs in the loaded history.`})}):/* @__PURE__ */ (0,Q.jsx)(U,{children:/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`min-w-0 overflow-x-auto`,children:/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-[36rem]`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{"aria-hidden":`true`,className:H(`sticky top-0 z-[1] hidden items-center gap-4 border-b border-dashboard-border-subtle bg-dashboard-overlay-soft px-4 py-2.5 font-sans font-medium text-xs text-dashboard-text-muted md:grid`,Vn),children:[/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Run`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Duration`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Tokens`}),/* @__PURE__ */ (0,Q.jsx)(`div`,{children:`Cost`})]}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`min-w-0`,onKeyDown:e.onRowsKeyDown,role:`list`,children:e.executions.map(n=>/* @__PURE__ */ (0,Q.jsx)(Wn,{execution:n,fallbackTitle:t.automation.title,onSelect:()=>e.onSelect(n.executionId),selected:e.selectedRunId===n.executionId},n.executionId))})]})})}),t.truncated?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-center text-xs text-dashboard-text-muted`,children:`Showing the 100 most recent runs.`}):null]})}function Wn(e){let{execution:t}=e,n=ze(t.costUsd===void 0?void 0:{total:t.costUsd})||`—`,r=Ie(t.durationMs)||`—`,i=t.totalTokens===void 0?`—`:Re(t.totalTokens),a=se(t.status);return/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`border-b border-dashboard-border-subtle last:border-b-0`,"data-run-id":t.executionId,role:`listitem`,children:/* @__PURE__ */ (0,Q.jsxs)(St,{className:H(`grid min-w-0 items-center gap-4 overflow-hidden px-4 py-3 max-md:grid-cols-1 max-md:gap-y-2 max-md:py-3.5`,Vn),onSelect:e.onSelect,selected:e.selected,children:[/* @__PURE__ */ (0,Q.jsxs)(`button`,{"aria-expanded":e.selected,className:`block min-w-0 cursor-pointer rounded-md border-0 bg-transparent p-0 text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus`,onClick:e.onSelect,type:`button`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 overflow-hidden`,children:[/* @__PURE__ */ (0,Q.jsx)(gt,{className:`md:hidden`,label:t.status,tone:a}),/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium leading-snug text-dashboard-text`,children:ae(t,e.fallbackTitle)})]}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`mt-1 block truncate text-xs leading-relaxed text-dashboard-text-muted`,children:[R(t.executedAt),t.automationVersion?` · Version ${t.automationVersion}`:null]}),t.error?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block truncate text-xs leading-relaxed text-rose-300`,title:t.error,children:t.error}):null]}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Duration`,value:r}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Tokens`,value:i}),/* @__PURE__ */ (0,Q.jsx)(Gn,{label:`Cost`,value:n}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`hidden justify-self-center md:block`,children:/* @__PURE__ */ (0,Q.jsx)(gt,{label:t.status,tone:a})}),/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`max-md:hidden`,children:/* @__PURE__ */ (0,Q.jsx)(yt,{conversationId:t.conversationId})})]})})}function Gn(e){return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0 max-md:flex max-md:items-center max-md:gap-2`,children:[/* @__PURE__ */ (0,Q.jsx)(`div`,{"aria-hidden":`true`,className:`mb-1 hidden font-sans font-medium text-2xs text-dashboard-text-muted max-md:mb-0 max-md:block`,children:e.label}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`truncate whitespace-nowrap font-mono text-xs text-dashboard-text-muted md:text-sm md:text-dashboard-text`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`sr-only`,children:[e.label,`: `]}),e.value]})]})}function Kn(e){return e.reduce((e,t)=>(e[t.status]+=1,e),{blocked:0,completed:0,failed:0})}const qn=`version`;function Jn(e){let t=Je(!0,e.automation.id);return t.error?/* @__PURE__ */ (0,Q.jsxs)(mt,{children:[`Version history could not be loaded.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void t.refetch(),children:`Try again`})]}):t.data?/* @__PURE__ */ (0,Q.jsx)(Yn,{automation:e.automation,data:t.data}):/* @__PURE__ */ (0,Q.jsx)(ke,{label:`Loading version history`,variant:`list`})}function Yn(e){let{automation:r,data:i}=e,[a,o]=m(),s=n(),[c,l]=(0,Z.useState)(),[u,d]=(0,Z.useState)(!1),f=r.status!==`completed`,p=Number(a.get(qn)),h=Math.max(0,i.versions.findIndex(e=>e.version===p)),g=i.versions[h],_=i.versions[h+1],v=e=>o(t=>{let n=new URLSearchParams(t);return n.set(qn,String(e)),n},{replace:!0}),y=`/api/automations/${encodeURIComponent(r.id)}`,b=t({mutationFn:async e=>{let t=await B(z,`${y}/edit`);return Te(z,`${y}/versions/${e}/activate`,{revision:t.revision})},onMutate:()=>l(void 0),onSuccess:async(e,t)=>{l(t),await s.invalidateQueries({queryKey:[`dashboard`,`automations`]})}});if(!g)return/* @__PURE__ */ (0,Q.jsx)(U,{padding:`md`,children:/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`No versions are saved yet. Junior saves a version each time the settings change.`})});let x=g.version===i.activeVersion;return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 max-w-2xl text-sm leading-relaxed text-dashboard-text-muted`,children:f?`Each save creates a version. Making a version active saves its settings as a new version. It does not run the automation.`:`This automation has completed. Its versions are read-only.`}),c===void 0?null:/* @__PURE__ */ (0,Q.jsxs)(`p`,{role:`status`,className:`m-0 text-sm text-emerald-300`,children:[`Version `,c,` is active again. It was saved as a new version.`]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid min-w-0 gap-4 lg:grid-cols-[17rem_minmax(0,1fr)] lg:gap-6`,children:[/* @__PURE__ */ (0,Q.jsxs)(`nav`,{"aria-label":`Versions`,className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-none gap-1 p-0 max-lg:max-h-64 max-lg:overflow-y-auto`,children:i.versions.map((e,t)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:/* @__PURE__ */ (0,Q.jsx)(Xn,{active:e.version===i.activeVersion,changes:rr(e,i.versions[t+1],i.truncated),onSelect:()=>v(e.version),selected:e.version===g.version,version:e})},e.version))}),i.truncated?/* @__PURE__ */ (0,Q.jsx)(`p`,{className:`m-0 mt-2 px-3 text-xs text-dashboard-text-muted`,children:`Showing the 100 most recent versions.`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(U,{as:`section`,className:`min-w-0`,padding:`none`,variant:`default`,children:[/* @__PURE__ */ (0,Q.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-dashboard-border-subtle px-4 py-4 sm:px-5`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`min-w-0`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`h2`,{className:`m-0 font-display text-lg font-medium`,children:[`Version `,g.version]}),x?/* @__PURE__ */ (0,Q.jsx)(ut,{size:`compact`,tone:`success`,children:`Active`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(`p`,{className:`mt-1 mb-0 text-xs text-dashboard-text-muted`,children:[nr(g),` ·`,` `,R(g.createdAt),_?` · Compared with version ${_.version}`:``]})]}),f&&!x?/* @__PURE__ */ (0,Q.jsx)(M,{"aria-label":`Make version ${g.version} active`,disabled:b.isPending,onClick:()=>d(!0),children:b.isPending&&b.variables===g.version?`Saving…`:`Make active`}):null]}),b.error&&b.variables===g.version?/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`px-4 pt-4 sm:px-5`,children:/* @__PURE__ */ (0,Q.jsx)(Y,{tone:`error`,title:`This version could not be made active.`,children:b.error instanceof V?b.error.code===`conflict`?`The automation changed. Try again.`:b.error.apiError??`Try again.`:`Try again.`})}):null,/* @__PURE__ */ (0,Q.jsx)(Qn,{automation:r,previous:_,version:g})]})]}),/* @__PURE__ */ (0,Q.jsx)(ft,{onOpenChange:d,open:u,children:/* @__PURE__ */ (0,Q.jsxs)($e,{children:[/* @__PURE__ */ (0,Q.jsxs)(qe,{children:[`Make version `,g.version,` active?`]}),/* @__PURE__ */ (0,Q.jsxs)(tt,{children:[`Junior saves these settings as a new version. Future runs use them.`,r.ownedByViewer?null:` Only ${r.createdBy} can turn on their connected accounts.`]}),/* @__PURE__ */ (0,Q.jsxs)(rt,{children:[/* @__PURE__ */ (0,Q.jsx)(dt,{children:`Cancel`}),/* @__PURE__ */ (0,Q.jsx)(Ge,{onClick:()=>{b.mutate(g.version),d(!1)},variant:`primary`,children:`Make active`})]})]})})]})}function Xn(e){let{version:t}=e;return/* @__PURE__ */ (0,Q.jsxs)(`button`,{"aria-current":e.selected?`true`:void 0,className:H(`grid w-full min-w-0 cursor-pointer gap-0.5 rounded-md border-0 px-3 py-2.5 text-left transition-colors focus-visible:outline-2 focus-visible:outline-dashboard-focus`,e.selected?`bg-dashboard-accent/[0.08] text-dashboard-text`:`bg-transparent text-dashboard-text hover:bg-dashboard-fill-soft`),onClick:e.onSelect,type:`button`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-sm font-medium`,children:[`Version `,t.version,e.active?/* @__PURE__ */ (0,Q.jsx)(ut,{size:`compact`,tone:`success`,children:`Active`}):null]}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`truncate text-xs text-dashboard-text-muted`,children:[nr(t),` ·`,` `,/* @__PURE__ */ (0,Q.jsx)(`time`,{dateTime:t.createdAt,children:Be(t.createdAt)})]}),e.changes?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`truncate text-xs text-dashboard-text-muted`,children:e.changes}):null]})}const Zn=[{key:`title`,label:`Title`},{key:`instruction`,label:`What to do`},{key:`when`,label:`When to run`},{key:`destination`,label:`Destination`},{key:`outcomes`,label:`Where results go`},{key:`credentialMode`,label:`Credentials`}];function Qn(e){let{automation:t,previous:n,version:r}=e,i=n?ir(n,r):[];return/* @__PURE__ */ (0,Q.jsx)(`dl`,{className:`m-0 divide-y divide-dashboard-border-subtle`,children:Zn.map(({key:e,label:a})=>{let o=i.includes(e);return/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:H(`grid min-w-0 gap-2 px-4 py-4 sm:grid-cols-[9rem_minmax(0,1fr)] sm:gap-6 sm:px-5`,o&&`shadow-[inset_2px_0_0_var(--color-dashboard-accent)]`),children:[/* @__PURE__ */ (0,Q.jsxs)(`dt`,{className:`text-xs font-medium text-dashboard-text-muted`,children:[a,o?/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`mt-1 block font-normal text-dashboard-accent-text`,children:`Changed`}):null]}),/* @__PURE__ */ (0,Q.jsx)(`dd`,{className:`m-0 min-w-0 text-sm leading-relaxed break-words`,children:o&&n&&e===`instruction`?/* @__PURE__ */ (0,Q.jsx)(er,{after:r.definition.instruction,before:n.definition.instruction}):o&&n?/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`text-dashboard-text-muted line-through decoration-dashboard-text-muted/50`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`Before: `}),$n(e,t,n)]}),/* @__PURE__ */ (0,Q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:`After: `}),$n(e,t,r)]})]}):$n(e,t,r)})]},e)})})}function $n(e,t,n){let{definition:r}=n;switch(e){case`title`:return r.title??`First line of the instruction`;case`instruction`:return/* @__PURE__ */ (0,Q.jsx)(st,{mentions:t.mentions,text:r.instruction});case`when`:if(n.kind===`scheduled`){let{description:e,timezone:t}=n.definition.schedule;return e.includes(t)?e:`${e} (${t})`}return/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[n.definition.trigger.label,n.definition.trigger.identifier?` · ${n.definition.trigger.identifier}`:null,/* @__PURE__ */ (0,Q.jsx)(`br`,{}),n.trigger.events.join(`, `),/* @__PURE__ */ (0,Q.jsx)(Yt,{filters:n.trigger.filters})]});case`destination`:return r.destination.channelId===t.destination.channelId&&r.destination.teamId===t.destination.teamId?t.destination.label:`Another destination · ${r.destination.channelId}`;case`outcomes`:return r.outcomes.length?/* @__PURE__ */ (0,Q.jsx)(`ol`,{className:`m-0 grid list-decimal gap-1 pl-5`,children:r.outcomes.map((e,n)=>/* @__PURE__ */ (0,Q.jsx)(`li`,{children:It(e,t.destination)},n))}):`No message on success`;case`credentialMode`:return r.credentialMode===`creator`?`Uses accounts connected by ${t.ownedByViewer?`you`:t.createdBy}.`:`System credentials only`}}function er(e){return/* @__PURE__ */ (0,Q.jsx)(`div`,{className:`grid overflow-hidden rounded-md border border-dashboard-border-subtle font-mono text-xs leading-relaxed`,children:tr(e.before,e.after).map((e,t)=>/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:H(`grid grid-cols-[1.5rem_minmax(0,1fr)] whitespace-pre-wrap px-2 py-0.5`,e.kind===`added`&&`bg-emerald-500/10 text-emerald-200`,e.kind===`removed`&&`bg-rose-500/10 text-rose-200`),children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`select-none opacity-60`,children:e.kind===`added`?`+`:e.kind===`removed`?`−`:``}),/* @__PURE__ */ (0,Q.jsxs)(`span`,{children:[e.kind===`same`?null:/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`sr-only`,children:e.kind===`added`?`Added: `:`Removed: `}),e.value||` `]})]},t))})}function tr(e,t){let n=e.split(`
|
|
9
9
|
`),r=t.split(`
|
|
10
|
-
`),i=Array.from({length:n.length+1},()=>Array.from({length:r.length+1},()=>0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,value:n[o]}),o++,s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`removed`,value:n[o++]}):a.push({kind:`added`,value:r[s++]});for(;o<n.length;)a.push({kind:`removed`,value:n[o++]});for(;s<r.length;)a.push({kind:`added`,value:r[s++]});return a}function nr(e){return e.editedBy?e.editedBy.fullName??e.editedBy.userName??e.editedBy.slackUserId:`Editor unknown`}function rr(e,t,n){if(!t)return e.version===1||!n?`First saved version`:void 0;let r=ir(t,e);return r.length===0?`No setting changes`:`Changed ${Zn.filter(({key:e})=>r.includes(e)).map(({label:e})=>e.toLowerCase()).join(`, `)}`}function ir(e,t){let n=e.definition,r=t.definition,i=e=>JSON.stringify(n[e])!==JSON.stringify(r[e]);return Zn.flatMap(({key:e})=>(e===`when`?i(`schedule`)||i(`trigger`):i(e))?[e]:[])}const ar=[`1`,`7`,`30`,`90`],or=[zn,`run`,qn],sr={edit:`Edit`,overview:`Overview`,runs:`Runs`,versions:`Versions`};function cr(e){let{automationId:t}=s(),n=f(),r=
|
|
10
|
+
`),i=Array.from({length:n.length+1},()=>Array.from({length:r.length+1},()=>0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,value:n[o]}),o++,s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`removed`,value:n[o++]}):a.push({kind:`added`,value:r[s++]});for(;o<n.length;)a.push({kind:`removed`,value:n[o++]});for(;s<r.length;)a.push({kind:`added`,value:r[s++]});return a}function nr(e){return e.editedBy?e.editedBy.fullName??e.editedBy.userName??e.editedBy.slackUserId:`Editor unknown`}function rr(e,t,n){if(!t)return e.version===1||!n?`First saved version`:void 0;let r=ir(t,e);return r.length===0?`No setting changes`:`Changed ${Zn.filter(({key:e})=>r.includes(e)).map(({label:e})=>e.toLowerCase()).join(`, `)}`}function ir(e,t){let n=e.definition,r=t.definition,i=e=>JSON.stringify(n[e])!==JSON.stringify(r[e]);return Zn.flatMap(({key:e})=>(e===`when`?i(`schedule`)||i(`trigger`):i(e))?[e]:[])}const ar=[`1`,`7`,`30`,`90`],or=[zn,`run`,qn],sr={edit:`Edit`,overview:`Overview`,runs:`Runs`,versions:`Versions`};function cr(e){let{automationId:t}=s(),n=f(),r=Ye(e.enabled,t),[i,a]=We(`range`,`30`,ar),o=Number(i);if(!t)return/* @__PURE__ */ (0,Q.jsx)(c,{replace:!0,to:`/automations/list`});let l=new URLSearchParams(n.search);for(let e of or)l.delete(e);let u=G(`/automations/list`,l),p=r.data,m=[`overview`,`runs`,`versions`].map(e=>({label:sr[e],to:W(t,e),isActive:t=>e===`overview`?!!(d(`/automations/:automationId`,t)||d(`/automations/:automationId/edit`,t)):!!d(`/automations/:automationId/${e}`,t)})),h=e.tab===`runs`&&!!p;return/* @__PURE__ */ (0,Q.jsx)(Ve,{ariaLabel:`Automation navigation`,className:h?`grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)] md:grid-rows-[minmax(0,1fr)]`:void 0,items:m,children:p?/* @__PURE__ */ (0,Q.jsx)(lr,{automation:p,listPath:u,onRangeChange:e=>a(String(e)),range:o,tab:e.tab}):/* @__PURE__ */ (0,Q.jsxs)(He,{children:[/* @__PURE__ */ (0,Q.jsx)(fr,{to:u}),/* @__PURE__ */ (0,Q.jsx)(Pe,{description:`Settings, runs, and versions for one automation.`,title:`Automation`}),r.error?/* @__PURE__ */ (0,Q.jsxs)(Y,{tone:`error`,title:`Automation could not be loaded.`,children:[r.error instanceof V&&r.error.status===404?`This automation was not found or is not visible to you.`:`Try again.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void r.refetch(),children:`Try again`})]}):/* @__PURE__ */ (0,Q.jsx)(ke,{label:`Loading automation`,variant:`list`})]})})}function lr(e){let{automation:t,tab:n}=e,r=f(),i=u(),[a,o]=(0,Z.useState)(!1),s=(0,Z.useRef)(null),l=t.status===`completed`;if(n===`edit`&&l)return/* @__PURE__ */ (0,Q.jsx)(c,{replace:!0,to:G(W(t.id),r.search)});let d=G(W(t.id,`edit`),r.search),p=/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(fr,{to:e.listPath}),/* @__PURE__ */ (0,Q.jsx)(Pe,{actions:n===`edit`?void 0:/* @__PURE__ */ (0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2 md:justify-end`,children:[n===`overview`||n===`runs`?/* @__PURE__ */ (0,Q.jsx)(je,{onChange:e.onRangeChange,value:e.range}):null,/* @__PURE__ */ (0,Q.jsx)(Pt,{automation:t,editPath:d,editVariant:n===`overview`&&En(t)?`default`:`primary`,onDelete:e=>{s.current=e,o(!0)}})]}),description:/* @__PURE__ */ (0,Q.jsx)(dr,{automation:t}),documentTitle:n===`overview`?t.title:`${t.title} · ${sr[n]}`,title:t.title})]}),m=a?/* @__PURE__ */ (0,Q.jsx)(Ft,{automation:t,onClose:()=>o(!1),onDeleted:()=>{s.current=null,i(e.listPath)},returnFocus:()=>s.current?.isConnected?s.current:!1}):null;return n===`runs`?/* @__PURE__ */ (0,Q.jsxs)(Q.Fragment,{children:[/* @__PURE__ */ (0,Q.jsx)(Hn,{automation:t,header:p,range:e.range}),m]}):/* @__PURE__ */ (0,Q.jsxs)(He,{children:[p,n===`overview`?/* @__PURE__ */ (0,Q.jsx)(kn,{automation:t,editPath:d,range:e.range}):null,n===`edit`?/* @__PURE__ */ (0,Q.jsx)(ur,{automation:t}):null,n===`versions`?/* @__PURE__ */ (0,Q.jsx)(Jn,{automation:t}):null,m]})}function ur(e){let{automation:t}=e,n=f(),r=i({queryKey:[`dashboard`,`automations`,`edit`,t.id],retry:!1,queryFn:({signal:e})=>B(z,`/api/automations/${encodeURIComponent(t.id)}/edit`,e)});return r.error&&!r.data?/* @__PURE__ */ (0,Q.jsxs)(Y,{tone:`error`,title:`Automation could not be loaded.`,children:[`It may no longer be available, or you may not have access.`,` `,/* @__PURE__ */ (0,Q.jsx)(M,{onClick:()=>void r.refetch(),children:`Try again`})]}):r.data?/* @__PURE__ */ (0,Q.jsx)(nn,{automation:r.data,summary:t,returnPath:G(W(t.id),n.search)},t.id):/* @__PURE__ */ (0,Q.jsx)(an,{})}function dr(e){let{automation:t}=e,n=[t.kind===`scheduled`?t.schedule:me(t.resource,t.trigger),t.destination.label,`Created by ${t.ownedByViewer?`you`:t.createdBy}`];return/* @__PURE__ */ (0,Q.jsx)(`span`,{className:`block min-w-0 overflow-hidden`,children:/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`-ml-4 flex min-w-0 flex-wrap items-center gap-y-1`,children:[/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`flex items-center`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block w-4`}),/* @__PURE__ */ (0,Q.jsx)(Cn,{automation:t})]}),n.map((e,t)=>/* @__PURE__ */ (0,Q.jsxs)(`span`,{className:`min-w-0 break-words`,children:[/* @__PURE__ */ (0,Q.jsx)(`span`,{"aria-hidden":`true`,className:H(`inline-block w-4 text-center opacity-45`,t===0&&`invisible`),children:`·`}),e]},t))]})})}function fr(e){return/* @__PURE__ */ (0,Q.jsxs)(p,{className:`flex w-fit items-center gap-2 font-display text-sm font-medium text-dashboard-text-muted no-underline transition-colors hover:text-dashboard-text`,to:e.to,children:[/* @__PURE__ */ (0,Q.jsx)(ne,{"aria-hidden":`true`,size:15,strokeWidth:1.8}),`All automations`]})}export{cr as AutomationPage};
|
package/dist/public/chunks/{AutomationRunDetails-op6rfaji.js → AutomationRunDetails-hyjcewq8.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{C as t,S as n,r,y as i}from"./vendor-react-ggbyvons.js";import{n as a}from"./button-loz3etho.js";import{V as o}from"./vendor-icons-mxz7yi04.js";import{i as s,n as c,t as l}from"./automationFormat-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-bnnw9q4a.js";import{C as t,S as n,r,y as i}from"./vendor-react-ggbyvons.js";import{n as a}from"./button-loz3etho.js";import{V as o}from"./vendor-icons-mxz7yi04.js";import{i as s,n as c,t as l}from"./automationFormat-nmiq4qj2.js";import{a as u,n as d,t as f}from"./tooltip-c9bbl0em.js";import{a as p,t as m}from"./styles-j0007fov.js";import{t as h}from"./PageContentSkeleton-b7dkba0l.js";import{b as g,l as _,n as v,p as y,y as b}from"./format-c4b0iyrx.js";import{t as x}from"./PageLayout-l6dhbimv.js";import{H as S,Tt as C,ht as w}from"../client-mgf2bxi7.js";var T=/* @__PURE__ */ e(t(),1),E=n();function D(e){let[t,n]=i(),r=(0,T.useRef)(null),a=t.get(`run`)??void 0,o=e=>n(t=>{let n=new URLSearchParams(t);return e?n.set(`run`,e):n.delete(`run`),n},{replace:!0}),s=e=>r.current?.querySelector(`[data-run-id="${CSS.escape(e)}"] button`);return{close:()=>{let e=a?s(a):void 0;o(void 0),(e??r.current)?.focus({preventScroll:!0})},listRef:r,onRowsKeyDown:t=>{if(!a||t.key!==`ArrowDown`&&t.key!==`ArrowUp`)return;let n=t.target.closest(`[data-run-id]`)?.getAttribute(`data-run-id`),r=n?e.indexOf(n):-1,i=e[r+(t.key===`ArrowDown`?1:-1)];r!==-1&&i&&(t.preventDefault(),o(i),s(i)?.focus())},runId:a,toggle:e=>o(e===a?void 0:e)}}function O(e){return/* @__PURE__ */ (0,E.jsxs)(`div`,{className:m(`grid h-full min-h-0 min-w-0`,e.details?`xl:grid-cols-[minmax(0,1fr)_25rem]`:void 0),children:[/* @__PURE__ */ (0,E.jsx)(`div`,{"aria-label":e.label,className:`min-h-0 overflow-y-auto overscroll-contain outline-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-dashboard-focus`,ref:e.listRef,role:`region`,tabIndex:0,children:/* @__PURE__ */ (0,E.jsx)(x,{children:e.children})}),e.details]})}function k(e){return e.conversationId?/* @__PURE__ */ (0,E.jsxs)(f,{children:[/* @__PURE__ */ (0,E.jsx)(u,{render:/* @__PURE__ */ (0,E.jsx)(r,{"aria-label":`Open conversation`,className:m(a({size:`icon`}),`size-8`),to:C(e.conversationId),children:/* @__PURE__ */ (0,E.jsx)(o,{"aria-hidden":`true`,size:15})})}),/* @__PURE__ */ (0,E.jsx)(d,{size:`compact`,children:`Open conversation`})]}):/* @__PURE__ */ (0,E.jsx)(`span`,{"aria-hidden":`true`})}function A(e){let{run:t}=e,n=t?c(t,t.automationTitle):`Run`;return/* @__PURE__ */ (0,E.jsx)(S,{actions:t?.conversationId?/* @__PURE__ */ (0,E.jsx)(r,{className:m(a(),`shrink-0 whitespace-nowrap`),to:C(t.conversationId),children:`Open conversation`}):void 0,label:`Run details`,onClose:e.onClose,sheetTitle:n,title:/* @__PURE__ */ (0,E.jsx)(`h2`,{className:`m-0 line-clamp-2 break-words font-display text-base font-medium text-dashboard-text`,children:n}),children:/* @__PURE__ */ (0,E.jsx)(`div`,{className:`p-4 [overflow-wrap:anywhere]`,children:t?/* @__PURE__ */ (0,E.jsx)(j,{run:t,showAutomation:e.showAutomation}):e.loading?/* @__PURE__ */ (0,E.jsx)(h,{label:`Loading run details`,variant:`panel`}):/* @__PURE__ */ (0,E.jsx)(`p`,{className:`m-0 text-sm text-dashboard-text-muted`,children:`This run is not in the loaded runs.`})})})}function j(e){let{run:t}=e;return/* @__PURE__ */ (0,E.jsxs)(`div`,{className:`grid min-w-0 gap-3`,children:[/* @__PURE__ */ (0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 px-1`,children:[/* @__PURE__ */ (0,E.jsx)(w,{tone:l(t.status),children:t.status}),/* @__PURE__ */ (0,E.jsx)(`time`,{className:`text-xs text-dashboard-text-muted`,dateTime:t.executedAt,title:s(t.executedAt),children:b(t.executedAt)})]}),t.error?/* @__PURE__ */ (0,E.jsx)(N,{title:`Error`,children:/* @__PURE__ */ (0,E.jsx)(`p`,{className:`m-0 whitespace-pre-wrap font-mono text-xs leading-relaxed text-rose-300`,children:t.error})}):null,/* @__PURE__ */ (0,E.jsx)(N,{title:`Run`,children:/* @__PURE__ */ (0,E.jsxs)(`dl`,{className:M,children:[/* @__PURE__ */ (0,E.jsx)(P,{label:`Trigger`,children:t.kind===`scheduled`?`Schedule`:`Event`}),t.scheduledFor?/* @__PURE__ */ (0,E.jsx)(P,{label:`Scheduled for`,children:s(t.scheduledFor)}):null,t.startedAt?/* @__PURE__ */ (0,E.jsx)(P,{label:`Started`,children:s(t.startedAt)}):null,/* @__PURE__ */ (0,E.jsx)(P,{label:`Finished`,children:s(t.executedAt)}),/* @__PURE__ */ (0,E.jsx)(P,{label:`Duration`,children:g(t.durationMs)||`—`}),/* @__PURE__ */ (0,E.jsx)(P,{label:`Tokens`,children:t.totalTokens===void 0?`—`:_(t.totalTokens)}),/* @__PURE__ */ (0,E.jsx)(P,{label:`Cost`,children:t.costUsd===void 0?`—`:y({total:t.costUsd})})]})}),/* @__PURE__ */ (0,E.jsx)(N,{title:`Setup`,children:/* @__PURE__ */ (0,E.jsxs)(`dl`,{className:M,children:[e.showAutomation?/* @__PURE__ */ (0,E.jsx)(P,{label:`Automation`,children:/* @__PURE__ */ (0,E.jsx)(r,{className:p,to:v(t.automationId),children:t.automationTitle})}):null,t.automationVersion?/* @__PURE__ */ (0,E.jsx)(P,{label:`Version`,children:/* @__PURE__ */ (0,E.jsxs)(r,{className:p,to:`${v(t.automationId,`versions`)}?version=${t.automationVersion}`,children:[`Version `,t.automationVersion]})}):null,t.credentialMode?/* @__PURE__ */ (0,E.jsx)(P,{label:`Accounts`,children:t.credentialMode===`creator`?`Creator’s connected accounts`:`Junior’s accounts only`}):null,/* @__PURE__ */ (0,E.jsx)(P,{label:`Run ID`,children:/* @__PURE__ */ (0,E.jsx)(`span`,{className:`font-mono`,children:t.executionId})})]})}),t.conversationId?null:/* @__PURE__ */ (0,E.jsx)(`p`,{className:`m-0 px-1 text-xs text-dashboard-text-muted`,children:`No Conversation was recorded for this run.`})]})}const M=`m-0 grid min-w-0 gap-2 text-xs leading-snug`;function N(e){return/* @__PURE__ */ (0,E.jsxs)(`section`,{className:`grid min-w-0 gap-2.5 rounded-lg border border-dashboard-border-subtle bg-dashboard-surface-panel p-3`,children:[/* @__PURE__ */ (0,E.jsx)(`h3`,{className:`m-0 font-sans text-xs font-medium text-dashboard-text-muted`,children:e.title}),e.children]})}function P(e){return/* @__PURE__ */ (0,E.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-4`,children:[/* @__PURE__ */ (0,E.jsx)(`dt`,{className:`shrink-0 text-dashboard-text-muted`,children:e.label}),/* @__PURE__ */ (0,E.jsx)(`dd`,{className:`m-0 min-w-0 break-words text-right tabular-nums text-dashboard-text`,children:e.children})]})}export{D as i,O as n,k as r,A as t};
|