import{j as l}from"./vendor-react-DrAK5R0M.js";import{h,F as x}from"./workflowConstants-CDSIF4v3.js";import{X as v,f as j}from"./vendor-icons-Cu2Ube6F.js";const p="h-7 px-2 rounded border border-border bg-background text-xs text-foreground placeholder:text-muted-foreground outline-none focus:ring-1 focus:ring-ring",N="h-7 px-1.5 rounded border border-border bg-background text-xs text-foreground outline-none focus:ring-1 focus:ring-ring cursor-pointer";function k({conditions:n,onChange:a,disabled:s,triggerEvent:d=""}){function m(){a([...n,{field:"",op:"eq",value:""}])}function i(e,r){a(n.map((o,t)=>t===e?{...o,...r}:o))}function g(e){a(n.filter((r,o)=>o!==e))}const f=["exists","not_exists"],u=h(d),c=`workflow-filter-fields-${d||"generic"}`.replace(/[^a-zA-Z0-9_-]/g,"-");return l.jsxs("div",{className:"space-y-2",children:[!s&&u.length>0&&l.jsx("datalist",{id:c,children:u.map(e=>l.jsx("option",{value:e.field,label:`${e.group}: ${e.label}`},e.field))}),n.length===0?l.jsx("p",{className:"text-xs text-muted-foreground italic",children:"No conditions — workflow runs for all matching events"}):l.jsx("div",{className:"space-y-1.5",children:n.map((e,r)=>{var o;return l.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[l.jsx("input",{value:e.field,onChange:t=>i(r,{field:t.target.value}),placeholder:"Field name",disabled:s,list:s?void 0:c,className:`${p} w-32`,title:(o=u.find(t=>t.field===e.field))==null?void 0:o.hint}),l.jsx("select",{value:e.op,onChange:t=>i(r,{op:t.target.value}),disabled:s,className:`${N} w-32`,children:x.map(t=>l.jsx("option",{value:t.value,children:t.label},t.value))}),!f.includes(e.op)&&l.jsx("input",{value:e.value,onChange:t=>i(r,{value:t.target.value}),placeholder:"Value",disabled:s,className:`${p} flex-1 min-w-[80px]`}),!s&&l.jsx("button",{type:"button",onClick:()=>g(r),className:"flex-shrink-0 text-muted-foreground hover:text-destructive transition-colors",children:l.jsx(v,{className:"w-3.5 h-3.5"})})]},r)})}),n.filter(e=>e.field).length>0&&l.jsxs("p",{className:"text-xs text-muted-foreground italic",children:["Only runs when"," ",n.filter(e=>e.field).map(e=>{var o;const r=((o=x.find(t=>t.value===e.op))==null?void 0:o.label)??e.op;return f.includes(e.op)?`${e.field} ${r}`:`${e.field} ${r} "${e.value}"`}).join(" AND ")]}),!s&&l.jsxs("button",{type:"button",onClick:m,className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[l.jsx(j,{className:"w-3.5 h-3.5"}),"Add condition"]})]})}export{k as W};
