1import{q as e}from"./index-Chw7iKGq.js";import{e as i}from"./vendor-feOCaMQ1.js";import{p as r,P as v,a as k,A}from"./index-B48rNwjt.js";import{a as C}from"./format-xZY8HryR.js";const d={workspace_id:"",project_id:"",name:"",description:"",trigger:{kind:"task.status_changed",config:{}},actions:[{kind:"task.notify",config:{}}],enabled:!0};function E(){const[m,x]=i.useState([]),[a,l]=i.useState(d),[h,c]=i.useState(""),[g,u]=i.useState(!1),o=i.useCallback(async()=>{try{x(await r.listAutomations()),c("")}catch(t){c((t==null?void 0:t.message)||"Failed to load automations.")}},[]);i.useEffect(()=>{o()},[o]);const p=(t,s)=>{const n=[...a.actions];n[t]={...n[t],kind:s},l({...a,actions:n})},j=()=>l({...a,actions:[...a.actions,{kind:"task.notify",config:{}}]}),y=t=>l({...a,actions:a.actions.filter((s,n)=>n!==t)}),N=async()=>{if(a.name.trim()){u(!0);try{a.id?await r.updateAutomation(a.id,a):await r.createAutomation(a),l(d),await o()}catch(t){c((t==null?void 0:t.message)||"Failed to save.")}finally{u(!1)}}},f=async t=>{if(confirm("Delete this rule?"))try{await r.deleteAutomation(t),await o()}catch(s){c((s==null?void 0:s.message)||"Failed to delete.")}},b=async t=>{try{await r.updateAutomation(t.id,{...t,enabled:!t.enabled}),await o()}catch(s){c((s==null?void 0:s.message)||"Failed to toggle.")}};return e.jsxs(v,{eyebrow:"BeetlPM · Automations",title:"Rules",subtitle:"When-X-do-Y. The Monday/Asana automation surface â every rule is auditable in the run log under each card.",appLayoutTitle:"BeetlPM · Automations",children:[h&&e.jsx("div",{className:"alert-error",style:{marginBottom:12},children:h}),e.jsxs("div",{className:"pm-card",style:{padding:16,display:"flex",flexDirection:"column",gap:8},children:[e.jsx("input",{className:"input",placeholder:"Rule name (e.g. 'Notify owner when blocked')",value:a.name,onChange:t=>l({...a,name:t.target.value})}),e.jsx("input",{className:"input",placeholder:"Description",value:a.description,onChange:t=>l({...a,description:t.target.value})}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("label",{style:{fontSize:13,color:"var(--text3)",minWidth:60},children:"When"}),e.jsx("select",{className:"select",value:a.trigger.kind,onChange:t=>l({...a,trigger:{...a.trigger,kind:t.target.value}}),children:k.map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,color:"var(--text3)",marginBottom:4},children:"Then do"}),a.actions.map((t,s)=>e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:6},children:[e.jsx("select",{className:"select",value:t.kind,onChange:n=>p(s,n.target.value),children:A.map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx("button",{className:"btn danger",onClick:()=>y(s),children:"Remove"})]},s)),e.jsx("button",{className:"btn",onClick:j,children:"+ Action"})]}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("label",{style:{fontSize:13,color:"var(--text3)"},children:[e.jsx("input",{type:"checkbox",checked:a.enabled,onChange:t=>l({...a,enabled:t.target.checked})})," ","Enabled"]}),e.jsx("button",{className:"btn primary",disabled:g||!a.name.trim(),onClick:N,children:a.id?"Save rule":"Create rule"}),a.id&&e.jsx("button",{className:"btn",onClick:()=>l(d),children:"Cancel"})]})]}),e.jsxs("table",{className:"table",style:{marginTop:16},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"th",children:"Name"}),e.jsx("th",{className:"th",children:"Trigger"}),e.jsx("th",{className:"th",children:"Actions"}),e.jsx("th",{className:"th",children:"Last run"}),e.jsx("th",{className:"th",children:"Runs"}),e.jsx("th",{className:"th",children:"On"}),e.jsx("th",{className:"th",style:{width:180}})]})}),e.jsx("tbody",{children:m.length===0?e.jsx("tr",{className:"tr",children:e.jsx("td",{className:"td",colSpan:7,style:{color:"var(--text3)"},children:"No automations yet."})}):m.map(t=>{var s;return e.jsxs("tr",{className:"tr",children:[e.jsx("td",{className:"td",children:t.name}),e.jsx("td",{className:"td",children:(s=t.trigger)==null?void 0:s.kind}),e.jsx("td",{className:"td",style:{color:"var(--text3)"},children:(t.actions||[]).map(n=>n.kind).join(", ")||"â"}),e.jsx("td",{className:"td",children:t.last_run_at?C(t.last_run_at):"â"}),e.jsx("td",{className:"td",children:t.run_count||0}),e.jsx("td",{className:"td",children:e.jsx("input",{type:"checkbox",checked:!!t.enabled,onChange:()=>b(t)})}),e.jsxs("td",{className:"td",style:{textAlign:"right"},children:[e.jsx("button",{className:"btn",onClick:()=>l({...d,...t}),children:"Edit"}),e.jsx("button",{className:"btn danger",onClick:()=>f(t.id),style:{marginLeft:6},children:"Delete"})]})]},t.id)})})]})]})}export{E as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.