@bigbinary/neeto-rules-frontend 2.5.65 → 2.6.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.
Files changed (60) hide show
  1. package/README.md +7 -3
  2. package/app/javascript/src/translations/en.json +104 -1
  3. package/dist/.ready +1 -1
  4. package/dist/NeetoRules.js +3 -3
  5. package/dist/NeetoRules.js.map +1 -1
  6. package/dist/NeetoRulesBuilder.js +4341 -0
  7. package/dist/NeetoRulesBuilder.js.map +1 -0
  8. package/dist/NeetoRulesForm.js +114 -5534
  9. package/dist/NeetoRulesForm.js.map +1 -1
  10. package/dist/RulePreview.js +1 -1
  11. package/dist/cjs/NeetoRules.js +3 -3
  12. package/dist/cjs/NeetoRules.js.map +1 -1
  13. package/dist/cjs/NeetoRulesBuilder.js +4343 -0
  14. package/dist/cjs/NeetoRulesBuilder.js.map +1 -0
  15. package/dist/cjs/NeetoRulesForm.js +171 -5610
  16. package/dist/cjs/NeetoRulesForm.js.map +1 -1
  17. package/dist/cjs/RulePreview.js +1 -1
  18. package/dist/cjs/hooks.js +6 -6
  19. package/dist/cjs/index.js +17 -11
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/v2/NeetoRulesForm.js +9 -8
  22. package/dist/cjs/v2/NeetoRulesForm.js.map +1 -1
  23. package/dist/cjs/v2/index.js +2 -1
  24. package/dist/cjs/v2/index.js.map +1 -1
  25. package/dist/hooks.js +4 -4
  26. package/dist/index-3f8Yrbst.js +5561 -0
  27. package/dist/index-3f8Yrbst.js.map +1 -0
  28. package/dist/index-CkYo0ca_.js +5511 -0
  29. package/dist/index-CkYo0ca_.js.map +1 -0
  30. package/dist/index.js +15 -10
  31. package/dist/index.js.map +1 -1
  32. package/dist/keyboardShortcuts-BvIE6AHg.js +88 -0
  33. package/dist/keyboardShortcuts-BvIE6AHg.js.map +1 -0
  34. package/dist/keyboardShortcuts-NxcrOxzv.js +92 -0
  35. package/dist/keyboardShortcuts-NxcrOxzv.js.map +1 -0
  36. package/dist/{useActiveField-9aCscxu8.js → useCustomDataStore-BtKYtLVc.js} +12 -12
  37. package/dist/useCustomDataStore-BtKYtLVc.js.map +1 -0
  38. package/dist/{useActiveField-CPw24qyf.js → useCustomDataStore-DxFx8aCf.js} +12 -12
  39. package/dist/useCustomDataStore-DxFx8aCf.js.map +1 -0
  40. package/dist/useDebouncedUpdate-C4iFSO2Q.js +21 -0
  41. package/dist/useDebouncedUpdate-C4iFSO2Q.js.map +1 -0
  42. package/dist/useDebouncedUpdate-CroNcSyb.js +19 -0
  43. package/dist/useDebouncedUpdate-CroNcSyb.js.map +1 -0
  44. package/dist/{useUtilityStore-BV6jVHMM.js → useUtilityStore-CCUYS1mS.js} +9 -2
  45. package/dist/useUtilityStore-CCUYS1mS.js.map +1 -0
  46. package/dist/{useUtilityStore-_59l0Cmi.js → useUtilityStore-C_U20IMX.js} +9 -2
  47. package/dist/useUtilityStore-C_U20IMX.js.map +1 -0
  48. package/dist/v2/NeetoRulesForm.js +2 -1
  49. package/dist/v2/NeetoRulesForm.js.map +1 -1
  50. package/dist/v2/index.js +2 -1
  51. package/dist/v2/index.js.map +1 -1
  52. package/package.json +19 -19
  53. package/dist/useActiveField-9aCscxu8.js.map +0 -1
  54. package/dist/useActiveField-CPw24qyf.js.map +0 -1
  55. package/dist/useDebouncedUpdate-DDFcag0p.js +0 -108
  56. package/dist/useDebouncedUpdate-DDFcag0p.js.map +0 -1
  57. package/dist/useDebouncedUpdate-sW5WvXe0.js +0 -103
  58. package/dist/useDebouncedUpdate-sW5WvXe0.js.map +0 -1
  59. package/dist/useUtilityStore-BV6jVHMM.js.map +0 -1
  60. package/dist/useUtilityStore-_59l0Cmi.js.map +0 -1
@@ -0,0 +1,4343 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty');
5
+ var keyboardShortcuts = require('../keyboardShortcuts-NxcrOxzv.js');
6
+ var shallow = require('zustand/shallow');
7
+ var react = require('react');
8
+ var classNames = require('classnames');
9
+ var formik = require('formik');
10
+ var neetoCist = require('@bigbinary/neeto-cist');
11
+ var Container = require('@bigbinary/neeto-molecules/Container');
12
+ var Header = require('@bigbinary/neeto-molecules/Header');
13
+ var Spinner = require('@bigbinary/neetoui/Spinner');
14
+ var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
15
+ var reactI18next = require('react-i18next');
16
+ var index = require('../index-3f8Yrbst.js');
17
+ var useCustomDataStore = require('../useCustomDataStore-DxFx8aCf.js');
18
+ var useUtilityStore = require('../useUtilityStore-C_U20IMX.js');
19
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
20
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
21
+ var Plus = require('@bigbinary/neeto-icons/Plus');
22
+ var Button = require('@bigbinary/neetoui/Button');
23
+ var ramda = require('ramda');
24
+ var Delete = require('@bigbinary/neeto-icons/Delete');
25
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
26
+ var jsxRuntime = require('react/jsx-runtime');
27
+ var i18next = require('i18next');
28
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
29
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
30
+ var Search = require('@bigbinary/neeto-icons/Search');
31
+ var Input = require('@bigbinary/neetoui/Input');
32
+ var Typography = require('@bigbinary/neetoui/Typography');
33
+ var Checkbox = require('@bigbinary/neetoui/Checkbox');
34
+ var Radio = require('@bigbinary/neetoui/Radio');
35
+ var Textarea = require('@bigbinary/neetoui/Textarea');
36
+ var Input$1 = require('@bigbinary/neetoui/formik/Input');
37
+ var Select = require('@bigbinary/neetoui/formik/Select');
38
+ var Select$1 = require('@bigbinary/neetoui/Select');
39
+ var Up = require('@bigbinary/neeto-icons/Up');
40
+ var Down = require('@bigbinary/neeto-icons/Down');
41
+ var Tooltip = require('@bigbinary/neetoui/Tooltip');
42
+ var MultiEmailInput = require('@bigbinary/neetoui/MultiEmailInput');
43
+ require('@babel/runtime/helpers/typeof');
44
+ require('../useAutomationRulesApi-C1T2E1AN.js');
45
+ require('@tanstack/react-query');
46
+ require('axios');
47
+ require('../index-DFwPrb81.js');
48
+ require('yup');
49
+ require('@bigbinary/neetoui/formik/Radio');
50
+ require('@bigbinary/neetoui/managers');
51
+ require('@bigbinary/neeto-icons/Close');
52
+ require('@bigbinary/neeto-icons/Collapse');
53
+ require('@bigbinary/neetoui/Callout');
54
+ require('@bigbinary/neeto-icons/Left');
55
+ require('@bigbinary/neetoui/formik/Textarea');
56
+ require('@bigbinary/neetoui/formik/Switch');
57
+ require('@monaco-editor/react');
58
+ require('@bigbinary/neeto-icons/Help');
59
+ require('@bigbinary/neeto-molecules/DynamicVariables');
60
+ require('@bigbinary/neetoui/Label');
61
+ require('@bigbinary/neeto-commons-frontend/utils');
62
+ require('@bigbinary/neetoui/DatePicker');
63
+ require('../utils-B3roKiff.js');
64
+ require('@bigbinary/neeto-commons-frontend/initializers');
65
+ require('@bigbinary/neetoui/formik/MultiEmailInput');
66
+ require('@bigbinary/neeto-editor/FormikEditor');
67
+ require('@bigbinary/neeto-icons/Refresh');
68
+ require('@bigbinary/neeto-hotkeys');
69
+ require('@bigbinary/neeto-icons/Check');
70
+ require('react-select/creatable');
71
+ require('@babel/runtime/helpers/toArray');
72
+ require('@bigbinary/neeto-molecules/PhoneNumber');
73
+ require('@bigbinary/neetoui/Tag');
74
+ require('react-select');
75
+ require('../constants-BjXYr8nk.js');
76
+ require('@bigbinary/neetoui/TimePicker');
77
+ require('@bigbinary/neeto-editor/utils');
78
+ require('zustand');
79
+
80
+ var _TOKEN_TO_PANEL_TYPE;
81
+ var PARAM_KIND = {
82
+ ENUM_SINGLE: "enum-single",
83
+ ENUM_MULTI: "enum-multi"
84
+ };
85
+ var UNIT_MINUTES = {
86
+ minutes: 1,
87
+ hours: 60,
88
+ days: 1440
89
+ };
90
+
91
+ /* eslint-disable @bigbinary/neeto/hard-coded-strings-should-be-localized */
92
+ /* eslint-disable @bigbinary/neeto/neetocommons-tips */
93
+ var TIME_UNITS = [{
94
+ label: "minutes",
95
+ value: "minutes"
96
+ }, {
97
+ label: "hours",
98
+ value: "hours"
99
+ }, {
100
+ label: "days",
101
+ value: "days"
102
+ }];
103
+ /* eslint-enable @bigbinary/neeto/hard-coded-strings-should-be-localized */
104
+ /* eslint-enable @bigbinary/neeto/neetocommons-tips */
105
+
106
+ var LEAD_TIME_UNITS = TIME_UNITS;
107
+ var CONDITION_VERBS = {
108
+ IS: "is",
109
+ IS_NOT: "is_not",
110
+ ANY_OF: "any_of",
111
+ NONE_OF: "none_of",
112
+ ALL_OF: "all_of",
113
+ LESS_THAN: "less_than",
114
+ GREATER_THAN: "greater_than"
115
+ };
116
+ var VERB_TOKENS = {
117
+ MULTI_VALUE: "_of",
118
+ CONTAINS: "contains"
119
+ };
120
+ var DEFAULT_SCHEMA = {
121
+ triggers: {
122
+ fieldKey: "events",
123
+ options: []
124
+ },
125
+ actor: {
126
+ enabled: false,
127
+ options: [],
128
+ fieldKey: "performer"
129
+ },
130
+ conditions: {
131
+ fields: [],
132
+ fieldKey: "conditions",
133
+ connectorMode: "shared"
134
+ },
135
+ actions: {
136
+ options: [],
137
+ channelMeta: {},
138
+ recipients: [],
139
+ fieldKey: "actions"
140
+ },
141
+ delay: {
142
+ enabled: false,
143
+ fieldKey: "execution_delay",
144
+ units: []
145
+ },
146
+ integrations: {},
147
+ slots: {}
148
+ };
149
+ var STATUS_KEYS = {
150
+ ENABLED: "enabled",
151
+ DISABLED: "disabled"
152
+ };
153
+ var JOIN_TYPE = {
154
+ and: "and_operator",
155
+ or: "or_operator"
156
+ };
157
+ var CONDITION_MODE = {
158
+ AND: "and",
159
+ OR: "or"
160
+ };
161
+ var BUILDER_PANEL_TYPES = {
162
+ TRIGGER: "builder-trigger",
163
+ ACTOR: "builder-actor",
164
+ CONDITION_FIELD: "builder-condition-field",
165
+ OPERATOR: "builder-operator",
166
+ CONNECTOR: "builder-connector",
167
+ CONDITION_VALUE: "builder-condition-value",
168
+ ACTION_CHANNEL: "builder-action-channel",
169
+ ACTION_CONFIG: "builder-action-config",
170
+ RECIPIENT: "builder-recipient",
171
+ DELAY: "builder-delay",
172
+ LEAD_TIME: "builder-lead-time",
173
+ NAME: "builder-name",
174
+ SCOPE: "builder-scope"
175
+ };
176
+ var BUILDER_ANCHORS = {
177
+ TRIGGER_ADD: "trigger-add",
178
+ TRIGGER_REPLACE: "trigger-replace",
179
+ TRIGGER_ACTOR: "trigger-actor",
180
+ TRIGGER_LEAD_TIME: "trigger-lead-time",
181
+ COND_FIELD: "cond-field",
182
+ COND_OP_TOGGLE: "cond-op-toggle",
183
+ COND_CONNECTOR: "cond-connector",
184
+ COND_VALUES: "cond-values",
185
+ ACTION_ADD: "action-add",
186
+ ACTION_CHANNEL: "action-channel",
187
+ ACTION_CONFIG: "action-config",
188
+ ACTION_RECIPIENT: "action-recipient",
189
+ RULE_DELAY: "rule-delay",
190
+ META_NAME: "meta-name",
191
+ SCOPE: "scope"
192
+ };
193
+ var TOKEN_TO_PANEL_TYPE = (_TOKEN_TO_PANEL_TYPE = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_TOKEN_TO_PANEL_TYPE, BUILDER_ANCHORS.TRIGGER_ADD, BUILDER_PANEL_TYPES.TRIGGER), BUILDER_ANCHORS.TRIGGER_REPLACE, BUILDER_PANEL_TYPES.TRIGGER), BUILDER_ANCHORS.TRIGGER_ACTOR, BUILDER_PANEL_TYPES.ACTOR), BUILDER_ANCHORS.COND_FIELD, BUILDER_PANEL_TYPES.CONDITION_FIELD), BUILDER_ANCHORS.COND_OP_TOGGLE, BUILDER_PANEL_TYPES.OPERATOR), BUILDER_ANCHORS.COND_CONNECTOR, BUILDER_PANEL_TYPES.CONNECTOR), BUILDER_ANCHORS.COND_VALUES, BUILDER_PANEL_TYPES.CONDITION_VALUE), BUILDER_ANCHORS.ACTION_ADD, BUILDER_PANEL_TYPES.ACTION_CHANNEL), BUILDER_ANCHORS.ACTION_CHANNEL, BUILDER_PANEL_TYPES.ACTION_CHANNEL), BUILDER_ANCHORS.ACTION_CONFIG, BUILDER_PANEL_TYPES.ACTION_CONFIG), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_TOKEN_TO_PANEL_TYPE, BUILDER_ANCHORS.ACTION_RECIPIENT, BUILDER_PANEL_TYPES.RECIPIENT), BUILDER_ANCHORS.RULE_DELAY, BUILDER_PANEL_TYPES.DELAY), BUILDER_ANCHORS.TRIGGER_LEAD_TIME, BUILDER_PANEL_TYPES.LEAD_TIME), BUILDER_ANCHORS.META_NAME, BUILDER_PANEL_TYPES.NAME), BUILDER_ANCHORS.SCOPE, BUILDER_PANEL_TYPES.SCOPE));
194
+ var LARGE_PANEL_TYPES = [BUILDER_PANEL_TYPES.ACTION_CONFIG, BUILDER_PANEL_TYPES.SCOPE, BUILDER_PANEL_TYPES.NAME];
195
+ var CONDITION_ANCHORS = [BUILDER_ANCHORS.COND_FIELD, BUILDER_ANCHORS.COND_OP_TOGGLE, BUILDER_ANCHORS.COND_VALUES, BUILDER_ANCHORS.COND_CONNECTOR];
196
+ var ACTION_ANCHORS = [BUILDER_ANCHORS.ACTION_CHANNEL, BUILDER_ANCHORS.ACTION_CONFIG, BUILDER_ANCHORS.ACTION_RECIPIENT];
197
+ var PANE_SEARCH_THRESHOLD = 8;
198
+ var CONFIG_FOCUSABLE_SELECTOR = 'input:not([type="radio"]):not([type="checkbox"]), textarea, [contenteditable="true"]';
199
+ var SMS_TYPES = ["sms", "smsToNumbers"];
200
+ var RECIPIENT_FOCUSABLE_SELECTOR = 'input, textarea, [contenteditable="true"]';
201
+ var SMS_TO_NUMBERS = "smsToNumbers";
202
+ var SWAP_CHANNEL_ORDER = ["email", "sms", "slack", "webhook", "calendar_invite"];
203
+ var DEFAULT_DELAY_UNITS = TIME_UNITS;
204
+
205
+ var useClearingHover = function useClearingHover() {
206
+ var _useState = react.useState(false),
207
+ _useState2 = _slicedToArray(_useState, 2),
208
+ clearing = _useState2[0],
209
+ setClearing = _useState2[1];
210
+ var clearingHoverProps = {
211
+ onMouseEnter: function onMouseEnter() {
212
+ return setClearing(true);
213
+ },
214
+ onMouseLeave: function onMouseLeave() {
215
+ return setClearing(false);
216
+ }
217
+ };
218
+ var resetClearing = function resetClearing() {
219
+ return setClearing(false);
220
+ };
221
+ return {
222
+ clearing: clearing,
223
+ clearingHoverProps: clearingHoverProps,
224
+ resetClearing: resetClearing
225
+ };
226
+ };
227
+
228
+ var TOKEN_STATE = {
229
+ FILLED: "filled",
230
+ MUTED: "muted",
231
+ // eslint-disable-next-line @bigbinary/neeto/hard-coded-strings-should-be-localized
232
+ PLACEHOLDER: "placeholder",
233
+ PLACEHOLDER_NEXT: "placeholder-next",
234
+ DISABLED: "disabled"
235
+ };
236
+ var STATE_CLASS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TOKEN_STATE.PLACEHOLDER, "mb-placeholder"), TOKEN_STATE.PLACEHOLDER_NEXT, "mb-placeholder mb-placeholder-next"), TOKEN_STATE.DISABLED, "mb-placeholder mb-placeholder-disabled"), TOKEN_STATE.FILLED, "mb-tok"), TOKEN_STATE.MUTED, "mb-tok mb-tok-muted");
237
+
238
+ var _excluded = ["children", "state", "active", "invalid", "onClick", "className", "dataTestid"];
239
+ function ownKeys$c(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
240
+ function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
241
+ var Token = function Token(_ref) {
242
+ var children = _ref.children,
243
+ _ref$state = _ref.state,
244
+ state = _ref$state === void 0 ? TOKEN_STATE.FILLED : _ref$state,
245
+ _ref$active = _ref.active,
246
+ active = _ref$active === void 0 ? false : _ref$active,
247
+ _ref$invalid = _ref.invalid,
248
+ invalid = _ref$invalid === void 0 ? false : _ref$invalid,
249
+ onClick = _ref.onClick,
250
+ className = _ref.className,
251
+ dataTestid = _ref.dataTestid,
252
+ rest = _objectWithoutProperties(_ref, _excluded);
253
+ var isInteractive = typeof onClick === "function" && state !== TOKEN_STATE.DISABLED;
254
+ return /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread$c(_objectSpread$c({
255
+ "data-testid": dataTestid,
256
+ role: isInteractive ? "button" : undefined,
257
+ tabIndex: isInteractive ? 0 : undefined,
258
+ className: classNames(
259
+ // eslint-disable-next-line security/detect-object-injection
260
+ STATE_CLASS[state] || STATE_CLASS.filled, className, {
261
+ "mb-tok-active": active,
262
+ "mb-tok-invalid": invalid
263
+ }),
264
+ onClick: isInteractive ? onClick : undefined,
265
+ onKeyDown: isInteractive ? function (event) {
266
+ if (!(event.key === "Enter" || event.key === " ")) return;
267
+ event.preventDefault();
268
+ onClick(event);
269
+ } : undefined
270
+ }, rest), {}, {
271
+ children: children
272
+ }));
273
+ };
274
+
275
+ function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
276
+ function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
277
+ var humanize = function humanize(value) {
278
+ return String(value !== null && value !== void 0 ? value : "").replace(/[._]/g, " ").trim();
279
+ };
280
+ var isContainsVerb = function isContainsVerb(verb) {
281
+ return verb.includes(VERB_TOKENS.MULTI_VALUE) && verb.includes(VERB_TOKENS.CONTAINS);
282
+ };
283
+ var isNumericVerb = function isNumericVerb(verb) {
284
+ return verb === CONDITION_VERBS.LESS_THAN || verb === CONDITION_VERBS.GREATER_THAN;
285
+ };
286
+
287
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
288
+ var isExcludeVerb = function isExcludeVerb(verb) {
289
+ return [CONDITION_VERBS.IS, CONDITION_VERBS.IS_NOT, CONDITION_VERBS.ANY_OF, CONDITION_VERBS.NONE_OF].includes(verb);
290
+ };
291
+ var isMultiValueVerb = function isMultiValueVerb(verb) {
292
+ return String(verb).includes(VERB_TOKENS.MULTI_VALUE);
293
+ };
294
+ var sentencify = function sentencify(label) {
295
+ return label ? label.charAt(0).toLowerCase() + label.slice(1) : label;
296
+ };
297
+ var matchesTrigger = function matchesTrigger(name) {
298
+ return function (option) {
299
+ return option.eventValue === name || option.value === name || option.id === name;
300
+ };
301
+ };
302
+ var triggerOption = function triggerOption(_ref) {
303
+ var _schema$triggers;
304
+ var schema = _ref.schema,
305
+ name = _ref.name;
306
+ return ((schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.options) || []).find(matchesTrigger(name));
307
+ };
308
+ var triggerLabel = function triggerLabel(_ref2) {
309
+ var schema = _ref2.schema,
310
+ trigger = _ref2.trigger;
311
+ var option = triggerOption({
312
+ schema: schema,
313
+ name: trigger === null || trigger === void 0 ? void 0 : trigger.name
314
+ });
315
+ return (option === null || option === void 0 ? void 0 : option.plain) || sentencify((option === null || option === void 0 ? void 0 : option.label) || humanize(trigger === null || trigger === void 0 ? void 0 : trigger.name));
316
+ };
317
+ var performerLabel = function performerLabel(_ref3) {
318
+ var _schema$actor;
319
+ var schema = _ref3.schema,
320
+ performer = _ref3.performer;
321
+ var option = ((schema === null || schema === void 0 || (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.options) || []).find(function (candidate) {
322
+ return candidate.value === performer || candidate.id === performer;
323
+ });
324
+ return sentencify((option === null || option === void 0 ? void 0 : option.label) || humanize(performer));
325
+ };
326
+ var conditionField = function conditionField(_ref4) {
327
+ var _schema$conditions;
328
+ var schema = _ref4.schema,
329
+ field = _ref4.field;
330
+ return ((schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (option) {
331
+ return option.value === field || option.id === field;
332
+ });
333
+ };
334
+ var conditionFieldLabel = function conditionFieldLabel(_ref5) {
335
+ var schema = _ref5.schema,
336
+ condition = _ref5.condition;
337
+ var field = conditionField({
338
+ schema: schema,
339
+ field: condition === null || condition === void 0 ? void 0 : condition.field
340
+ });
341
+ return String((field === null || field === void 0 ? void 0 : field.label) || humanize(condition === null || condition === void 0 ? void 0 : condition.field)).toLowerCase();
342
+ };
343
+ var operatorLabel = function operatorLabel(_ref6) {
344
+ var _schema$conditions2;
345
+ var schema = _ref6.schema,
346
+ condition = _ref6.condition;
347
+ var map = (schema === null || schema === void 0 || (_schema$conditions2 = schema.conditions) === null || _schema$conditions2 === void 0 ? void 0 : _schema$conditions2.operatorLabels) || {};
348
+ return map[condition === null || condition === void 0 ? void 0 : condition.verb] || humanize(condition === null || condition === void 0 ? void 0 : condition.verb);
349
+ };
350
+ var conditionNeedsValue = function conditionNeedsValue(_ref7) {
351
+ var schema = _ref7.schema,
352
+ condition = _ref7.condition;
353
+ var field = conditionField({
354
+ schema: schema,
355
+ field: condition === null || condition === void 0 ? void 0 : condition.field
356
+ });
357
+ return !((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(condition === null || condition === void 0 ? void 0 : condition.verb);
358
+ };
359
+ var conditionValueLabel = function conditionValueLabel(_ref8) {
360
+ var _ref9, _meta$value;
361
+ var schema = _ref8.schema,
362
+ condition = _ref8.condition;
363
+ var meta = (condition === null || condition === void 0 ? void 0 : condition.metadata) || {};
364
+ var raw = (_ref9 = (_meta$value = meta.value) !== null && _meta$value !== void 0 ? _meta$value : meta.values) !== null && _ref9 !== void 0 ? _ref9 : meta.label;
365
+ if (ramda.isNil(raw) || ramda.isEmpty(raw)) return null;
366
+ var field = conditionField({
367
+ schema: schema,
368
+ field: condition === null || condition === void 0 ? void 0 : condition.field
369
+ });
370
+ var options = (field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options) || [];
371
+ var isEnum = neetoCist.isNotEmpty(options);
372
+ var labelFor = function labelFor(value) {
373
+ var _ref0, _option$label;
374
+ var option = options.find(function (candidate) {
375
+ var _candidate$value;
376
+ return ((_candidate$value = candidate.value) !== null && _candidate$value !== void 0 ? _candidate$value : candidate.id) === value;
377
+ });
378
+ var label = option ? (_ref0 = (_option$label = option.label) !== null && _option$label !== void 0 ? _option$label : option.value) !== null && _ref0 !== void 0 ? _ref0 : option.id : value;
379
+ return isEnum ? String(label).toLowerCase() : label;
380
+ };
381
+ var connector = String((condition === null || condition === void 0 ? void 0 : condition.verb) || "").includes(CONDITION_VERBS.ALL_OF) ? i18next.t("neetoRules.operators.and") : i18next.t("neetoRules.operators.or");
382
+ return Array.isArray(raw) ? raw.map(labelFor).join(" ".concat(connector, " ")) : String(labelFor(raw));
383
+ };
384
+ var actionOption = function actionOption(_ref1) {
385
+ var _schema$actions;
386
+ var schema = _ref1.schema,
387
+ name = _ref1.name;
388
+ return ((schema === null || schema === void 0 || (_schema$actions = schema.actions) === null || _schema$actions === void 0 ? void 0 : _schema$actions.options) || []).find(function (option) {
389
+ return option.value === name || option.id === name;
390
+ });
391
+ };
392
+ var channelOption = function channelOption(_ref10) {
393
+ var _schema$actions2;
394
+ var schema = _ref10.schema,
395
+ channel = _ref10.channel;
396
+ return ((schema === null || schema === void 0 || (_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 ? void 0 : _schema$actions2.options) || []).find(function (option) {
397
+ var _option$value;
398
+ return ((_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.id) === channel;
399
+ });
400
+ };
401
+ var actionParts = function actionParts(_ref11) {
402
+ var _actions$actionForNam, _action$recipient, _actions$channelMeta, _find, _find2, _channelMeta$needsRec, _actions$configValueL;
403
+ var schema = _ref11.schema,
404
+ action = _ref11.action;
405
+ var actions = (schema === null || schema === void 0 ? void 0 : schema.actions) || {};
406
+ var resolved = action !== null && action !== void 0 && action.channel ? {
407
+ channel: action.channel,
408
+ recipient: action.recipient
409
+ } : ((_actions$actionForNam = actions.actionForName) === null || _actions$actionForNam === void 0 ? void 0 : _actions$actionForNam.call(actions, action === null || action === void 0 ? void 0 : action.name)) || {};
410
+ var channel = resolved.channel;
411
+ var recipientValue = (_action$recipient = action === null || action === void 0 ? void 0 : action.recipient) !== null && _action$recipient !== void 0 ? _action$recipient : resolved.recipient;
412
+ var option = channel ? channelOption({
413
+ schema: schema,
414
+ channel: channel
415
+ }) : actionOption({
416
+ schema: schema,
417
+ name: action === null || action === void 0 ? void 0 : action.name
418
+ });
419
+
420
+ // eslint-disable-next-line security/detect-object-injection
421
+ var channelMeta = ((_actions$channelMeta = actions.channelMeta) === null || _actions$channelMeta === void 0 ? void 0 : _actions$channelMeta[channel]) || {};
422
+ var matchesRecipient = function matchesRecipient(recipient) {
423
+ var _recipient$value;
424
+ return ((_recipient$value = recipient.value) !== null && _recipient$value !== void 0 ? _recipient$value : recipient.id) === recipientValue;
425
+ };
426
+ var recipientLabel = ((_find = (actions.recipients || []).find(matchesRecipient)) === null || _find === void 0 ? void 0 : _find.label) || ((_find2 = ((option === null || option === void 0 ? void 0 : option.recipients) || []).find(matchesRecipient)) === null || _find2 === void 0 ? void 0 : _find2.label) || recipientValue;
427
+ return {
428
+ option: option,
429
+ channel: channel,
430
+ label: (option === null || option === void 0 ? void 0 : option.label) || humanize(action === null || action === void 0 ? void 0 : action.name),
431
+ verb: channelMeta.verb || (channel ? i18next.t("neetoRules.builder.send") : (option === null || option === void 0 ? void 0 : option.plain) || (option === null || option === void 0 ? void 0 : option.label)) || humanize(action === null || action === void 0 ? void 0 : action.name),
432
+ paramKind: !channel && (option === null || option === void 0 ? void 0 : option.paramType),
433
+ valueNoun: option === null || option === void 0 ? void 0 : option.valueNoun,
434
+ valueNounPlural: option === null || option === void 0 ? void 0 : option.valueNounPlural,
435
+ mediumLabel: channelMeta.mediumLabel || (option === null || option === void 0 ? void 0 : option.mediumLabel),
436
+ icon: channelMeta.icon || (option === null || option === void 0 ? void 0 : option.icon),
437
+ needsRecipient: (_channelMeta$needsRec = channelMeta.needsRecipient) !== null && _channelMeta$needsRec !== void 0 ? _channelMeta$needsRec : option === null || option === void 0 ? void 0 : option.needsRecipient,
438
+ separator: channelMeta.separator || (option === null || option === void 0 ? void 0 : option.separator),
439
+ configValue: ((_actions$configValueL = actions.configValueLabel) === null || _actions$configValueL === void 0 ? void 0 : _actions$configValueL.call(actions, action)) || "",
440
+ configValuePlaceholder: channelMeta.valuePlaceholder || (option === null || option === void 0 ? void 0 : option.valuePlaceholder),
441
+ recipient: recipientValue,
442
+ recipientLabel: recipientLabel,
443
+ configTitle: channelMeta.configTitle || (option === null || option === void 0 ? void 0 : option.configTitle),
444
+ configSubtitle: channelMeta.configSubtitle || (option === null || option === void 0 ? void 0 : option.configSubtitle),
445
+ recipientTitle: channelMeta.recipientTitle || (option === null || option === void 0 ? void 0 : option.recipientTitle),
446
+ recipientSubtitle: channelMeta.recipientSubtitle || (option === null || option === void 0 ? void 0 : option.recipientSubtitle)
447
+ };
448
+ };
449
+ var hasTrigger = function hasTrigger(rule) {
450
+ return !ramda.isEmpty((rule === null || rule === void 0 ? void 0 : rule.triggers) || []);
451
+ };
452
+ var hasAction = function hasAction(rule) {
453
+ return ((rule === null || rule === void 0 ? void 0 : rule.actions) || []).some(function (action) {
454
+ return action === null || action === void 0 ? void 0 : action.name;
455
+ });
456
+ };
457
+ var isRuleComplete = function isRuleComplete(rule) {
458
+ return hasTrigger(rule) && hasAction(rule);
459
+ };
460
+ var invalidScopeIndexes = function invalidScopeIndexes(_ref12) {
461
+ var _scope$requiresPhone;
462
+ var rule = _ref12.rule,
463
+ schema = _ref12.schema;
464
+ var scope = schema === null || schema === void 0 ? void 0 : schema.scope;
465
+ if (!(scope !== null && scope !== void 0 && scope.enabled) || !((_scope$requiresPhone = scope.requiresPhone) !== null && _scope$requiresPhone !== void 0 && _scope$requiresPhone.call(scope, (rule === null || rule === void 0 ? void 0 : rule.actions) || []))) return [];
466
+ return ((rule === null || rule === void 0 ? void 0 : rule.scope) || []).reduce(function (indexes, item, index) {
467
+ var _item$value, _item$hasPhoneField;
468
+ var value = (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item;
469
+ var option = (scope.options || []).find(function (candidate) {
470
+ var _candidate$value2;
471
+ return ((_candidate$value2 = candidate.value) !== null && _candidate$value2 !== void 0 ? _candidate$value2 : candidate.id) === value;
472
+ });
473
+ var hasPhoneField = (_item$hasPhoneField = item === null || item === void 0 ? void 0 : item.hasPhoneField) !== null && _item$hasPhoneField !== void 0 ? _item$hasPhoneField : option === null || option === void 0 ? void 0 : option.hasPhoneField;
474
+ if (hasPhoneField === false) indexes.push(index);
475
+ return indexes;
476
+ }, []);
477
+ };
478
+ var minutesToParts = function minutesToParts(minutes) {
479
+ var total = Number(minutes) || 0;
480
+ if (total && total % UNIT_MINUTES.days === 0) {
481
+ return {
482
+ value: total / UNIT_MINUTES.days,
483
+ unit: "days"
484
+ };
485
+ }
486
+ if (total && total % UNIT_MINUTES.hours === 0) {
487
+ return {
488
+ value: total / UNIT_MINUTES.hours,
489
+ unit: "hours"
490
+ };
491
+ }
492
+ return {
493
+ value: total,
494
+ unit: "minutes"
495
+ };
496
+ };
497
+ var partsToMinutes = function partsToMinutes(_ref13) {
498
+ var value = _ref13.value,
499
+ unit = _ref13.unit;
500
+ return (
501
+ // eslint-disable-next-line security/detect-object-injection
502
+ (Number(value) || 0) * (UNIT_MINUTES[unit] || 1)
503
+ );
504
+ };
505
+ var leadTimeLabel = function leadTimeLabel(minutes) {
506
+ var _minutesToParts = minutesToParts(minutes),
507
+ value = _minutesToParts.value,
508
+ unit = _minutesToParts.unit;
509
+ var unitLabel = value === 1 ? unit.replace(/s$/, "") : unit;
510
+ return "".concat(value, " ").concat(unitLabel);
511
+ };
512
+ var normalizeTriggers = function normalizeTriggers(triggers) {
513
+ if (Array.isArray(triggers)) return {
514
+ options: triggers
515
+ };
516
+ return triggers || {};
517
+ };
518
+ var normalizeSchema = function normalizeSchema() {
519
+ var rawSchema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
520
+ return ramda.mergeDeepRight(DEFAULT_SCHEMA, _objectSpread$b(_objectSpread$b({}, rawSchema), {}, {
521
+ triggers: normalizeTriggers(rawSchema.triggers)
522
+ }));
523
+ };
524
+ var joinTypeFor = function joinTypeFor(mode) {
525
+ return mode === CONDITION_MODE.OR ? JOIN_TYPE.or : JOIN_TYPE.and;
526
+ };
527
+ var modeFromJoinType = function modeFromJoinType(joinType) {
528
+ return joinType === JOIN_TYPE.or ? CONDITION_MODE.OR : CONDITION_MODE.AND;
529
+ };
530
+
531
+ // eslint-disable-next-line security/detect-object-injection
532
+ var valueAt = function valueAt(_ref14) {
533
+ var _values$key;
534
+ var values = _ref14.values,
535
+ key = _ref14.key;
536
+ return values === null || values === void 0 || (_values$key = values[key]) === null || _values$key === void 0 ? void 0 : _values$key.value;
537
+ };
538
+ var asArray = function asArray(maybeArray) {
539
+ return Array.isArray(maybeArray) ? maybeArray : [];
540
+ };
541
+ var fieldKeysFromSchema = function fieldKeysFromSchema() {
542
+ var _schema$triggers2, _schema$actor2, _schema$conditions3, _schema$actions3, _schema$delay, _schema$triggers3, _schema$scope;
543
+ var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
544
+ return {
545
+ triggers: ((_schema$triggers2 = schema.triggers) === null || _schema$triggers2 === void 0 ? void 0 : _schema$triggers2.fieldKey) || "events",
546
+ performer: ((_schema$actor2 = schema.actor) === null || _schema$actor2 === void 0 ? void 0 : _schema$actor2.fieldKey) || "performer",
547
+ conditions: ((_schema$conditions3 = schema.conditions) === null || _schema$conditions3 === void 0 ? void 0 : _schema$conditions3.fieldKey) || "conditions",
548
+ actions: ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3.fieldKey) || "actions",
549
+ delay: ((_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.fieldKey) || "execution_delay",
550
+ leadTime: (_schema$triggers3 = schema.triggers) === null || _schema$triggers3 === void 0 || (_schema$triggers3 = _schema$triggers3.leadTime) === null || _schema$triggers3 === void 0 ? void 0 : _schema$triggers3.fieldKey,
551
+ scope: ((_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.fieldKey) || "meetingIds",
552
+ status: "status",
553
+ name: "name"
554
+ };
555
+ };
556
+ var valuesToRuleModel = function valuesToRuleModel() {
557
+ var _valueAt, _conditions$;
558
+ var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
559
+ _ref15$values = _ref15.values,
560
+ values = _ref15$values === void 0 ? {} : _ref15$values,
561
+ _ref15$schema = _ref15.schema,
562
+ schema = _ref15$schema === void 0 ? {} : _ref15$schema;
563
+ var keys = fieldKeysFromSchema(schema);
564
+ var conditions = asArray(valueAt({
565
+ values: values,
566
+ key: keys.conditions
567
+ }));
568
+ var rawDelay = valueAt({
569
+ values: values,
570
+ key: keys.delay
571
+ });
572
+ return {
573
+ name: valueAt({
574
+ values: values,
575
+ key: keys.name
576
+ }) || "",
577
+ active: valueAt({
578
+ values: values,
579
+ key: keys.status
580
+ }) !== STATUS_KEYS.DISABLED,
581
+ triggers: asArray(valueAt({
582
+ values: values,
583
+ key: keys.triggers
584
+ })),
585
+ performer: (_valueAt = valueAt({
586
+ values: values,
587
+ key: keys.performer
588
+ })) !== null && _valueAt !== void 0 ? _valueAt : null,
589
+ conditions: conditions,
590
+ conditionMode: modeFromJoinType((_conditions$ = conditions[0]) === null || _conditions$ === void 0 ? void 0 : _conditions$.joinType),
591
+ delay: ramda.isNil(rawDelay) || ramda.isEmpty(rawDelay) ? null : rawDelay,
592
+ actions: asArray(valueAt({
593
+ values: values,
594
+ key: keys.actions
595
+ })),
596
+ leadTime: keys.leadTime ? valueAt({
597
+ values: values,
598
+ key: keys.leadTime
599
+ }) : null,
600
+ scope: asArray(valueAt({
601
+ values: values,
602
+ key: keys.scope
603
+ }))
604
+ };
605
+ };
606
+ var setTriggers = function setTriggers(_ref16) {
607
+ var schema = _ref16.schema,
608
+ triggers = _ref16.triggers;
609
+ return {
610
+ path: "".concat(fieldKeysFromSchema(schema).triggers, ".value"),
611
+ value: triggers
612
+ };
613
+ };
614
+ var setPerformer = function setPerformer(_ref17) {
615
+ var schema = _ref17.schema,
616
+ performer = _ref17.performer;
617
+ return {
618
+ path: "".concat(fieldKeysFromSchema(schema).performer, ".value"),
619
+ value: performer
620
+ };
621
+ };
622
+ var setActions = function setActions(_ref18) {
623
+ var schema = _ref18.schema,
624
+ actions = _ref18.actions;
625
+ return {
626
+ path: "".concat(fieldKeysFromSchema(schema).actions, ".value"),
627
+ value: actions
628
+ };
629
+ };
630
+ var setConditions = function setConditions(_ref19) {
631
+ var schema = _ref19.schema,
632
+ conditions = _ref19.conditions;
633
+ return {
634
+ path: "".concat(fieldKeysFromSchema(schema).conditions, ".value"),
635
+ value: conditions
636
+ };
637
+ };
638
+ var setConditionMode = function setConditionMode(_ref20) {
639
+ var schema = _ref20.schema,
640
+ conditions = _ref20.conditions,
641
+ joinType = _ref20.joinType;
642
+ return setConditions({
643
+ schema: schema,
644
+ conditions: conditions.map(function (condition) {
645
+ return ramda.assoc("joinType", joinTypeFor(joinType), condition);
646
+ })
647
+ });
648
+ };
649
+ var setDelay = function setDelay(_ref21) {
650
+ var schema = _ref21.schema,
651
+ delay = _ref21.delay;
652
+ return {
653
+ path: "".concat(fieldKeysFromSchema(schema).delay, ".value"),
654
+ value: delay !== null && delay !== void 0 ? delay : {}
655
+ };
656
+ };
657
+ var setActive = function setActive(_ref22) {
658
+ var schema = _ref22.schema,
659
+ active = _ref22.active;
660
+ return {
661
+ path: "".concat(fieldKeysFromSchema(schema).status, ".value"),
662
+ value: active ? STATUS_KEYS.ENABLED : STATUS_KEYS.DISABLED
663
+ };
664
+ };
665
+ var setScope = function setScope(_ref23) {
666
+ var schema = _ref23.schema,
667
+ scope = _ref23.scope;
668
+ return {
669
+ path: "".concat(fieldKeysFromSchema(schema).scope, ".value"),
670
+ value: scope
671
+ };
672
+ };
673
+ var removeArrayItem = function removeArrayItem(_ref24) {
674
+ var values = _ref24.values,
675
+ fieldKey = _ref24.fieldKey,
676
+ index = _ref24.index;
677
+ var list = asArray(valueAt({
678
+ values: values,
679
+ key: fieldKey
680
+ }));
681
+ // eslint-disable-next-line security/detect-object-injection
682
+ var removed = list[index];
683
+ var nextList = list.filter(function (_, i) {
684
+ return i !== index;
685
+ });
686
+ var result = [{
687
+ path: "".concat(fieldKey, ".value"),
688
+ value: nextList
689
+ }];
690
+ if (removed !== null && removed !== void 0 && removed.id) {
691
+ var _values$fieldKey;
692
+ // eslint-disable-next-line security/detect-object-injection
693
+ var deleted = asArray(values === null || values === void 0 || (_values$fieldKey = values[fieldKey]) === null || _values$fieldKey === void 0 ? void 0 : _values$fieldKey.deleted);
694
+ result.push({
695
+ path: "".concat(fieldKey, ".deleted"),
696
+ value: [].concat(_toConsumableArray(deleted), [_objectSpread$b(_objectSpread$b({}, removed), {}, {
697
+ _destroy: true
698
+ })])
699
+ });
700
+ }
701
+ return result;
702
+ };
703
+
704
+ function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
705
+ function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
706
+ var ConditionRow = function ConditionRow(_ref) {
707
+ var _schema$conditions;
708
+ var rule = _ref.rule,
709
+ schema = _ref.schema,
710
+ condition = _ref.condition,
711
+ index = _ref.index,
712
+ handleToken = _ref.onToken,
713
+ handleAddCondition = _ref.onAddCondition,
714
+ handleRemove = _ref.onRemove,
715
+ _ref$isActive = _ref.isActive,
716
+ isActive = _ref$isActive === void 0 ? function () {
717
+ return false;
718
+ } : _ref$isActive,
719
+ _ref$isInvalid = _ref.isInvalid,
720
+ isInvalid = _ref$isInvalid === void 0 ? function () {
721
+ return false;
722
+ } : _ref$isInvalid;
723
+ var _useTranslation = reactI18next.useTranslation(),
724
+ t = _useTranslation.t;
725
+ var isFirst = index === 0;
726
+ var hasField = !!(condition !== null && condition !== void 0 && condition.field);
727
+ var hasVerb = !!(condition !== null && condition !== void 0 && condition.verb);
728
+ var conditionField = ((schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (field) {
729
+ var _field$value;
730
+ return ((_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : field.id) === (condition === null || condition === void 0 ? void 0 : condition.field);
731
+ });
732
+ var operatorPlaceholder = (conditionField === null || conditionField === void 0 ? void 0 : conditionField.operatorPlaceholder) || t("neetoRules.builder.selectOperator");
733
+ var value = conditionValueLabel({
734
+ schema: schema,
735
+ condition: condition
736
+ });
737
+ var needsValue = conditionNeedsValue({
738
+ schema: schema,
739
+ condition: condition
740
+ });
741
+ var _useClearingHover = useClearingHover(),
742
+ clearing = _useClearingHover.clearing,
743
+ clearingHoverProps = _useClearingHover.clearingHoverProps;
744
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
745
+ className: classNames("mb-row", {
746
+ clearing: clearing
747
+ }),
748
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
749
+ className: "mb-sentence",
750
+ children: [isFirst ? /*#__PURE__*/jsxRuntime.jsx("span", {
751
+ className: "mb-fixed",
752
+ children: t("neetoRules.operators.and")
753
+ }) : /*#__PURE__*/jsxRuntime.jsx(Token, {
754
+ active: isActive({
755
+ type: BUILDER_ANCHORS.COND_CONNECTOR,
756
+ index: index
757
+ }),
758
+ className: "mb-tok-muted",
759
+ dataTestid: "cond-connector-".concat(index),
760
+ onClick: handleToken && function () {
761
+ return handleToken({
762
+ type: BUILDER_ANCHORS.COND_CONNECTOR,
763
+ index: index
764
+ });
765
+ },
766
+ children: rule.conditionMode === CONDITION_MODE.OR ? t("neetoRules.operators.or") : t("neetoRules.operators.and")
767
+ }), hasField ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
768
+ children: [/*#__PURE__*/jsxRuntime.jsx(Token, {
769
+ active: isActive({
770
+ type: BUILDER_ANCHORS.COND_FIELD,
771
+ index: index
772
+ }),
773
+ dataTestid: "cond-field-".concat(index),
774
+ onClick: handleToken && function () {
775
+ return handleToken({
776
+ type: BUILDER_ANCHORS.COND_FIELD,
777
+ index: index
778
+ });
779
+ },
780
+ children: conditionFieldLabel({
781
+ schema: schema,
782
+ condition: condition
783
+ })
784
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
785
+ active: isActive({
786
+ type: BUILDER_ANCHORS.COND_OP_TOGGLE,
787
+ index: index
788
+ }),
789
+ dataTestid: "cond-op-".concat(index),
790
+ state: hasVerb ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
791
+ invalid: isInvalid({
792
+ type: BUILDER_ANCHORS.COND_OP_TOGGLE,
793
+ index: index
794
+ }),
795
+ onClick: handleToken && function () {
796
+ return handleToken({
797
+ type: BUILDER_ANCHORS.COND_OP_TOGGLE,
798
+ index: index
799
+ });
800
+ },
801
+ children: hasVerb ? sentencify(operatorLabel({
802
+ schema: schema,
803
+ condition: condition
804
+ })) : operatorPlaceholder
805
+ }), hasVerb && needsValue && /*#__PURE__*/jsxRuntime.jsx(Token, {
806
+ active: isActive({
807
+ type: BUILDER_ANCHORS.COND_VALUES,
808
+ index: index
809
+ }),
810
+ dataTestid: "cond-values-".concat(index),
811
+ state: value ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
812
+ invalid: isInvalid({
813
+ type: BUILDER_ANCHORS.COND_VALUES,
814
+ index: index
815
+ }),
816
+ onClick: handleToken && function () {
817
+ return handleToken({
818
+ type: BUILDER_ANCHORS.COND_VALUES,
819
+ index: index
820
+ });
821
+ },
822
+ children: value || t("neetoRules.form.addValue")
823
+ })]
824
+ }) : /*#__PURE__*/jsxRuntime.jsx(Token, {
825
+ active: isActive({
826
+ type: BUILDER_ANCHORS.COND_FIELD,
827
+ index: index
828
+ }),
829
+ dataTestid: "cond-field-".concat(index),
830
+ invalid: isInvalid({
831
+ type: BUILDER_ANCHORS.COND_FIELD,
832
+ index: index
833
+ }),
834
+ state: TOKEN_STATE.PLACEHOLDER_NEXT,
835
+ onClick: handleToken && function () {
836
+ return handleToken({
837
+ type: BUILDER_ANCHORS.COND_FIELD,
838
+ index: index
839
+ });
840
+ },
841
+ children: t("neetoRules.builder.selectCondition")
842
+ })]
843
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
844
+ className: "mb-row-actions",
845
+ children: [handleAddCondition && /*#__PURE__*/jsxRuntime.jsx(Button, {
846
+ "data-testid": "cond-add-".concat(index),
847
+ icon: Plus,
848
+ size: "small",
849
+ style: "text",
850
+ tooltipProps: {
851
+ content: t("neetoRules.builder.aria.addAnotherCondition"),
852
+ position: "top"
853
+ },
854
+ onClick: handleAddCondition
855
+ }), handleRemove && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$a({
856
+ "data-testid": "cond-remove-".concat(index),
857
+ icon: Delete,
858
+ size: "small",
859
+ style: "text",
860
+ tooltipProps: {
861
+ content: t("neetoRules.builder.aria.deleteCondition"),
862
+ position: "top"
863
+ },
864
+ onClick: handleRemove
865
+ }, clearingHoverProps))]
866
+ })]
867
+ });
868
+ };
869
+
870
+ var Connector = function Connector(_ref) {
871
+ var _ref$active = _ref.active,
872
+ active = _ref$active === void 0 ? false : _ref$active;
873
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
874
+ "aria-hidden": true,
875
+ className: classNames("mb-arrow", {
876
+ "is-active": active
877
+ }),
878
+ children: /*#__PURE__*/jsxRuntime.jsx("svg", {
879
+ fill: "none",
880
+ height: "28",
881
+ viewBox: "0 0 24 28",
882
+ width: "24",
883
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
884
+ d: "M12 2 V22 M5 15 l7 7 l7 -7",
885
+ stroke: "currentColor",
886
+ strokeLinecap: "round",
887
+ strokeLinejoin: "round",
888
+ strokeWidth: "2"
889
+ })
890
+ })
891
+ });
892
+ };
893
+
894
+ function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
895
+ function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
896
+ var DelayRow = function DelayRow(_ref) {
897
+ var rule = _ref.rule,
898
+ handleToken = _ref.onToken,
899
+ handleRemove = _ref.onRemove,
900
+ _ref$isActive = _ref.isActive,
901
+ isActive = _ref$isActive === void 0 ? function () {
902
+ return false;
903
+ } : _ref$isActive,
904
+ _ref$isInvalid = _ref.isInvalid,
905
+ isInvalid = _ref$isInvalid === void 0 ? function () {
906
+ return false;
907
+ } : _ref$isInvalid;
908
+ var _useTranslation = reactI18next.useTranslation(),
909
+ t = _useTranslation.t;
910
+ var delay = rule.delay;
911
+ var _useClearingHover = useClearingHover(),
912
+ clearing = _useClearingHover.clearing,
913
+ clearingHoverProps = _useClearingHover.clearingHoverProps;
914
+ if (!delay) return null;
915
+ var label = [delay.value, delay.unit].filter(function (part) {
916
+ return part !== "" && !ramda.isNil(part);
917
+ }).join(" ");
918
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
919
+ className: classNames("mb-row", {
920
+ clearing: clearing
921
+ }),
922
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
923
+ className: "mb-sentence",
924
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
925
+ className: "mb-fixed",
926
+ children: t("neetoRules.form.delayExecutionBy")
927
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
928
+ dataTestid: "rule-delay",
929
+ state: label ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
930
+ active: isActive({
931
+ type: BUILDER_ANCHORS.RULE_DELAY,
932
+ index: undefined
933
+ }),
934
+ invalid: isInvalid({
935
+ type: BUILDER_ANCHORS.RULE_DELAY,
936
+ index: undefined
937
+ }),
938
+ onClick: handleToken && function () {
939
+ return handleToken({
940
+ type: BUILDER_ANCHORS.RULE_DELAY
941
+ });
942
+ },
943
+ children: label || t("neetoRules.builder.setDelay")
944
+ })]
945
+ }), handleRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
946
+ className: "mb-row-actions",
947
+ children: /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$9({
948
+ "data-testid": "rule-delay-remove",
949
+ icon: Delete,
950
+ size: "small",
951
+ style: "text",
952
+ tooltipProps: {
953
+ content: t("neetoRules.builder.aria.removeDelay"),
954
+ position: "top"
955
+ },
956
+ onClick: handleRemove
957
+ }, clearingHoverProps))
958
+ })]
959
+ });
960
+ };
961
+
962
+ var MetaBlock = reactUtils.withT(function (_ref) {
963
+ var t = _ref.t,
964
+ rule = _ref.rule,
965
+ _ref$showName = _ref.showName,
966
+ showName = _ref$showName === void 0 ? true : _ref$showName,
967
+ _ref$isInvalid = _ref.isInvalid,
968
+ isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
969
+ handleEditName = _ref.onEditName,
970
+ handleToggleActive = _ref.onToggleActive;
971
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
972
+ className: "mb-meta",
973
+ children: [showName && /*#__PURE__*/jsxRuntime.jsxs("div", {
974
+ className: "mb-meta-field",
975
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
976
+ className: "mb-meta-label",
977
+ children: t("neetoRules.builder.automationName")
978
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
979
+ role: handleEditName ? "button" : undefined,
980
+ tabIndex: handleEditName ? 0 : undefined,
981
+ className: classNames("mb-meta-input-wrap", {
982
+ "mb-meta-invalid": isInvalid
983
+ }),
984
+ onClick: handleEditName,
985
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
986
+ className: "mb-meta-name-display",
987
+ children: rule.name
988
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
989
+ "aria-hidden": true,
990
+ className: "mb-meta-edit",
991
+ children: /*#__PURE__*/jsxRuntime.jsx("svg", {
992
+ fill: "none",
993
+ height: "14",
994
+ viewBox: "0 0 24 24",
995
+ width: "14",
996
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
997
+ d: "M12 20h9 M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z",
998
+ stroke: "currentColor",
999
+ strokeLinecap: "round",
1000
+ strokeLinejoin: "round",
1001
+ strokeWidth: "2"
1002
+ })
1003
+ })
1004
+ })]
1005
+ })]
1006
+ }), /*#__PURE__*/jsxRuntime.jsxs("label", {
1007
+ className: "mb-meta-active",
1008
+ children: [/*#__PURE__*/jsxRuntime.jsx("input", {
1009
+ checked: rule.active,
1010
+ readOnly: !handleToggleActive,
1011
+ type: "checkbox",
1012
+ onChange: handleToggleActive || undefined
1013
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
1014
+ "aria-hidden": true,
1015
+ className: "mb-checkbox",
1016
+ children: /*#__PURE__*/jsxRuntime.jsx("svg", {
1017
+ fill: "none",
1018
+ height: "12",
1019
+ viewBox: "0 0 14 14",
1020
+ width: "12",
1021
+ children: /*#__PURE__*/jsxRuntime.jsx("path", {
1022
+ d: "M2 7l3.5 3.5L12 3.5"
1023
+ })
1024
+ })
1025
+ }), t("neetoRules.builder.activateThisAutomation")]
1026
+ })]
1027
+ });
1028
+ });
1029
+
1030
+ function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1031
+ function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1032
+ var itemLabel = function itemLabel(item) {
1033
+ return (item === null || item === void 0 ? void 0 : item.label) || (item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.value) || String(item !== null && item !== void 0 ? item : "");
1034
+ };
1035
+ var ScopeBlock = function ScopeBlock(_ref) {
1036
+ var _schema$scope;
1037
+ var rule = _ref.rule,
1038
+ schema = _ref.schema,
1039
+ handleToken = _ref.onToken,
1040
+ handleRemoveScope = _ref.onRemoveScope,
1041
+ _ref$isActive = _ref.isActive,
1042
+ isActive = _ref$isActive === void 0 ? function () {
1043
+ return false;
1044
+ } : _ref$isActive,
1045
+ _ref$isInvalid = _ref.isInvalid,
1046
+ isInvalid = _ref$isInvalid === void 0 ? function () {
1047
+ return false;
1048
+ } : _ref$isInvalid;
1049
+ var _useTranslation = reactI18next.useTranslation(),
1050
+ t = _useTranslation.t;
1051
+ var scope = rule.scope || [];
1052
+ var placeholder = (schema === null || schema === void 0 || (_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.placeholder) || t("neetoRules.builder.scope.placeholder");
1053
+ if (ramda.isEmpty(scope)) {
1054
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
1055
+ className: "mb-row",
1056
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
1057
+ className: "mb-sentence",
1058
+ children: /*#__PURE__*/jsxRuntime.jsx(Token, {
1059
+ active: isActive({
1060
+ type: BUILDER_ANCHORS.SCOPE,
1061
+ index: undefined
1062
+ }),
1063
+ dataTestid: "scope-add",
1064
+ state: TOKEN_STATE.PLACEHOLDER_NEXT,
1065
+ onClick: handleToken && function () {
1066
+ return handleToken({
1067
+ type: BUILDER_ANCHORS.SCOPE
1068
+ });
1069
+ },
1070
+ children: placeholder
1071
+ })
1072
+ })
1073
+ });
1074
+ }
1075
+ return scope.map(function (item, index) {
1076
+ var _item$value;
1077
+ return /*#__PURE__*/react.createElement(ScopeRow, {
1078
+ index: index,
1079
+ isActive: isActive,
1080
+ isInvalid: isInvalid,
1081
+ item: item,
1082
+ schema: schema,
1083
+ isLast: index === scope.length - 1,
1084
+ key: ((_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item) || index,
1085
+ onRemoveScope: handleRemoveScope,
1086
+ onToken: handleToken
1087
+ });
1088
+ });
1089
+ };
1090
+ var ScopeRow = function ScopeRow(_ref2) {
1091
+ var _schema$scope2;
1092
+ var schema = _ref2.schema,
1093
+ item = _ref2.item,
1094
+ index = _ref2.index,
1095
+ handleToken = _ref2.onToken,
1096
+ handleRemoveScope = _ref2.onRemoveScope,
1097
+ isActive = _ref2.isActive,
1098
+ isInvalid = _ref2.isInvalid,
1099
+ isLast = _ref2.isLast;
1100
+ var _useTranslation2 = reactI18next.useTranslation(),
1101
+ t = _useTranslation2.t;
1102
+ var _useClearingHover = useClearingHover(),
1103
+ clearing = _useClearingHover.clearing,
1104
+ clearingHoverProps = _useClearingHover.clearingHoverProps;
1105
+ var lead = (schema === null || schema === void 0 || (_schema$scope2 = schema.scope) === null || _schema$scope2 === void 0 ? void 0 : _schema$scope2.lead) || t("neetoRules.builder.scope.lead");
1106
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1107
+ className: classNames("mb-row", {
1108
+ clearing: clearing
1109
+ }),
1110
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
1111
+ className: "mb-sentence",
1112
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1113
+ className: "mb-fixed",
1114
+ children: lead
1115
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1116
+ active: isActive({
1117
+ type: BUILDER_ANCHORS.SCOPE,
1118
+ index: undefined
1119
+ }),
1120
+ dataTestid: "scope-".concat(index),
1121
+ invalid: isInvalid({
1122
+ type: BUILDER_ANCHORS.SCOPE,
1123
+ index: index
1124
+ }),
1125
+ onClick: handleToken && function () {
1126
+ return handleToken({
1127
+ type: BUILDER_ANCHORS.SCOPE
1128
+ });
1129
+ },
1130
+ children: itemLabel(item)
1131
+ })]
1132
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1133
+ className: "mb-row-actions",
1134
+ children: [handleToken && isLast && /*#__PURE__*/jsxRuntime.jsx(Button, {
1135
+ "data-testid": "scope-add-".concat(index),
1136
+ icon: Plus,
1137
+ size: "small",
1138
+ style: "text",
1139
+ tooltipProps: {
1140
+ content: t("neetoRules.builder.aria.addAnotherBookingPage"),
1141
+ position: "top"
1142
+ },
1143
+ onClick: function onClick() {
1144
+ return handleToken({
1145
+ type: BUILDER_ANCHORS.SCOPE
1146
+ });
1147
+ }
1148
+ }), handleRemoveScope && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$8({
1149
+ "data-testid": "scope-remove-".concat(index),
1150
+ icon: Delete,
1151
+ size: "small",
1152
+ style: "text",
1153
+ tooltipProps: {
1154
+ content: t("neetoRules.builder.aria.removeBookingPage"),
1155
+ position: "top"
1156
+ },
1157
+ onClick: function onClick() {
1158
+ return handleRemoveScope(index);
1159
+ }
1160
+ }, clearingHoverProps))]
1161
+ })]
1162
+ });
1163
+ };
1164
+
1165
+ function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1166
+ function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1167
+ var ActionRow = function ActionRow(_ref) {
1168
+ var schema = _ref.schema,
1169
+ action = _ref.action,
1170
+ index = _ref.index,
1171
+ position = _ref.position,
1172
+ handleToken = _ref.onToken,
1173
+ handleAddAction = _ref.onAddAction,
1174
+ handleRemove = _ref.onRemove,
1175
+ _ref$isActive = _ref.isActive,
1176
+ isActive = _ref$isActive === void 0 ? function () {
1177
+ return false;
1178
+ } : _ref$isActive,
1179
+ _ref$isInvalid = _ref.isInvalid,
1180
+ isInvalid = _ref$isInvalid === void 0 ? function () {
1181
+ return false;
1182
+ } : _ref$isInvalid;
1183
+ var _useTranslation = reactI18next.useTranslation(),
1184
+ t = _useTranslation.t;
1185
+ var _actionParts = actionParts({
1186
+ schema: schema,
1187
+ action: action
1188
+ }),
1189
+ option = _actionParts.option,
1190
+ label = _actionParts.label,
1191
+ verb = _actionParts.verb,
1192
+ mediumLabel = _actionParts.mediumLabel,
1193
+ MediumIcon = _actionParts.icon,
1194
+ needsRecipient = _actionParts.needsRecipient,
1195
+ recipient = _actionParts.recipient,
1196
+ recipientLabel = _actionParts.recipientLabel,
1197
+ separator = _actionParts.separator,
1198
+ configValue = _actionParts.configValue,
1199
+ configValuePlaceholder = _actionParts.configValuePlaceholder,
1200
+ paramKind = _actionParts.paramKind,
1201
+ valueNoun = _actionParts.valueNoun,
1202
+ valueNounPlural = _actionParts.valueNounPlural;
1203
+ var hasParamTail = paramKind === PARAM_KIND.ENUM_SINGLE || paramKind === PARAM_KIND.ENUM_MULTI;
1204
+ var multiPlaceholder = valueNounPlural ? t("neetoRules.builder.selectNoun", {
1205
+ noun: valueNounPlural
1206
+ }) : t("neetoRules.form.selectValues");
1207
+ var singlePlaceholder = valueNoun ? t("neetoRules.builder.selectNoun", {
1208
+ noun: valueNoun
1209
+ }) : t("neetoRules.form.selectValue");
1210
+ var paramPlaceholder = paramKind === PARAM_KIND.ENUM_MULTI ? multiPlaceholder : singlePlaceholder;
1211
+ var connector = (position !== null && position !== void 0 ? position : index) === 0 ? t("neetoRules.common.then") : t("neetoRules.operators.and");
1212
+ var verbLabel = sentencify(verb || label);
1213
+ var isVerbActive = isActive({
1214
+ type: BUILDER_ANCHORS.ACTION_CHANNEL,
1215
+ index: index
1216
+ }) || isActive({
1217
+ type: BUILDER_ANCHORS.ACTION_ADD,
1218
+ index: index
1219
+ });
1220
+ var configLabel = mediumLabel || sentencify(option === null || option === void 0 ? void 0 : option.placeholder);
1221
+ var isConfigured = neetoCist.isNotEmpty(action === null || action === void 0 ? void 0 : action.metadata);
1222
+ var _useClearingHover = useClearingHover(),
1223
+ clearing = _useClearingHover.clearing,
1224
+ clearingHoverProps = _useClearingHover.clearingHoverProps;
1225
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1226
+ className: classNames("mb-row mb-row-draggable", {
1227
+ clearing: clearing
1228
+ }),
1229
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
1230
+ className: "mb-sentence",
1231
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1232
+ className: "mb-fixed",
1233
+ children: connector
1234
+ }), separator ? /*#__PURE__*/jsxRuntime.jsxs(Token, {
1235
+ active: isVerbActive,
1236
+ className: "mb-tok-medium",
1237
+ dataTestid: "action-verb-".concat(index),
1238
+ onClick: handleToken && function () {
1239
+ return handleToken({
1240
+ type: BUILDER_ANCHORS.ACTION_CHANNEL,
1241
+ index: index
1242
+ });
1243
+ },
1244
+ children: [verbLabel, MediumIcon && /*#__PURE__*/jsxRuntime.jsx(MediumIcon, {
1245
+ size: 14
1246
+ }), configLabel]
1247
+ }) : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1248
+ children: [/*#__PURE__*/jsxRuntime.jsx(Token, {
1249
+ active: isVerbActive,
1250
+ dataTestid: "action-verb-".concat(index),
1251
+ onClick: handleToken && function () {
1252
+ return handleToken({
1253
+ type: BUILDER_ANCHORS.ACTION_CHANNEL,
1254
+ index: index
1255
+ });
1256
+ },
1257
+ children: verbLabel
1258
+ }), hasParamTail ? /*#__PURE__*/jsxRuntime.jsx(Token, {
1259
+ dataTestid: "action-config-value-".concat(index),
1260
+ state: configValue ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
1261
+ active: isActive({
1262
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1263
+ index: index
1264
+ }),
1265
+ invalid: isInvalid({
1266
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1267
+ index: index
1268
+ }),
1269
+ onClick: handleToken && function () {
1270
+ return handleToken({
1271
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1272
+ index: index
1273
+ });
1274
+ },
1275
+ children: configValue || paramPlaceholder
1276
+ }) : configLabel && /*#__PURE__*/jsxRuntime.jsxs(Token, {
1277
+ className: "mb-tok-medium",
1278
+ dataTestid: "action-config-".concat(index),
1279
+ state: isConfigured ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
1280
+ active: isActive({
1281
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1282
+ index: index
1283
+ }),
1284
+ invalid: isInvalid({
1285
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1286
+ index: index
1287
+ }),
1288
+ onClick: handleToken && function () {
1289
+ return handleToken({
1290
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1291
+ index: index
1292
+ });
1293
+ },
1294
+ children: [MediumIcon && /*#__PURE__*/jsxRuntime.jsx(MediumIcon, {
1295
+ size: 14
1296
+ }), configLabel]
1297
+ })]
1298
+ }), separator && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1299
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1300
+ className: "mb-fixed",
1301
+ children: separator
1302
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1303
+ active: isActive({
1304
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1305
+ index: index
1306
+ }),
1307
+ dataTestid: "action-config-value-".concat(index),
1308
+ state: configValue ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
1309
+ invalid: isInvalid({
1310
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1311
+ index: index
1312
+ }),
1313
+ onClick: handleToken && function () {
1314
+ return handleToken({
1315
+ type: BUILDER_ANCHORS.ACTION_CONFIG,
1316
+ index: index
1317
+ });
1318
+ },
1319
+ children: configValue || sentencify(configValuePlaceholder) || t("neetoRules.builder.selectFallback")
1320
+ })]
1321
+ }), needsRecipient && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1322
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1323
+ className: "mb-fixed",
1324
+ children: t("neetoRules.common.to")
1325
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1326
+ dataTestid: "action-recipient-".concat(index),
1327
+ state: recipient ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
1328
+ active: isActive({
1329
+ type: BUILDER_ANCHORS.ACTION_RECIPIENT,
1330
+ index: index
1331
+ }),
1332
+ invalid: isInvalid({
1333
+ type: BUILDER_ANCHORS.ACTION_RECIPIENT,
1334
+ index: index
1335
+ }),
1336
+ onClick: handleToken && function () {
1337
+ return handleToken({
1338
+ type: BUILDER_ANCHORS.ACTION_RECIPIENT,
1339
+ index: index
1340
+ });
1341
+ },
1342
+ children: recipient ? String(recipientLabel).toLowerCase() : t("neetoRules.builder.selectRecipient")
1343
+ })]
1344
+ })]
1345
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1346
+ className: "mb-row-actions",
1347
+ children: [handleAddAction && /*#__PURE__*/jsxRuntime.jsx(Button, {
1348
+ "data-testid": "action-add-".concat(index),
1349
+ icon: Plus,
1350
+ size: "small",
1351
+ style: "text",
1352
+ tooltipProps: {
1353
+ content: t("neetoRules.builder.aria.addAnotherAction"),
1354
+ position: "top"
1355
+ },
1356
+ onClick: handleAddAction
1357
+ }), handleRemove && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$7({
1358
+ "data-testid": "action-remove-".concat(index),
1359
+ icon: Delete,
1360
+ size: "small",
1361
+ style: "text",
1362
+ tooltipProps: {
1363
+ content: t("neetoRules.builder.aria.deleteAction"),
1364
+ position: "top"
1365
+ },
1366
+ onClick: handleRemove
1367
+ }, clearingHoverProps))]
1368
+ })]
1369
+ });
1370
+ };
1371
+
1372
+ var ThenBlock = function ThenBlock(_ref) {
1373
+ var rule = _ref.rule,
1374
+ schema = _ref.schema,
1375
+ handleToken = _ref.onToken,
1376
+ handleAddAction = _ref.onAddAction,
1377
+ handleRemoveAction = _ref.onRemoveAction,
1378
+ _ref$isActive = _ref.isActive,
1379
+ isActive = _ref$isActive === void 0 ? function () {
1380
+ return false;
1381
+ } : _ref$isActive,
1382
+ _ref$isInvalid = _ref.isInvalid,
1383
+ isInvalid = _ref$isInvalid === void 0 ? function () {
1384
+ return false;
1385
+ } : _ref$isInvalid,
1386
+ _ref$adding = _ref.adding,
1387
+ adding = _ref$adding === void 0 ? false : _ref$adding;
1388
+ var _useTranslation = reactI18next.useTranslation(),
1389
+ t = _useTranslation.t;
1390
+ var named = rule.actions.map(function (action, index) {
1391
+ return {
1392
+ action: action,
1393
+ index: index
1394
+ };
1395
+ }).filter(function (_ref2) {
1396
+ var action = _ref2.action;
1397
+ return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
1398
+ });
1399
+ if (ramda.isEmpty(named)) {
1400
+ var isTriggerSet = hasTrigger(rule);
1401
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
1402
+ className: "mb-row",
1403
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
1404
+ className: "mb-sentence",
1405
+ children: /*#__PURE__*/jsxRuntime.jsx(Token, {
1406
+ active: isActive({
1407
+ type: BUILDER_ANCHORS.ACTION_ADD,
1408
+ index: 0
1409
+ }),
1410
+ dataTestid: "action-add",
1411
+ invalid: isInvalid({
1412
+ type: BUILDER_ANCHORS.ACTION_ADD,
1413
+ index: 0
1414
+ }),
1415
+ state: isTriggerSet ? TOKEN_STATE.PLACEHOLDER_NEXT : TOKEN_STATE.DISABLED,
1416
+ title: isTriggerSet ? undefined : t("neetoRules.builder.pickTriggerFirst"),
1417
+ onClick: isTriggerSet ? handleAddAction : undefined,
1418
+ children: t("neetoRules.builder.thenDoThis")
1419
+ })
1420
+ })
1421
+ });
1422
+ }
1423
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1424
+ children: [named.map(function (_ref3, position) {
1425
+ var _action$id;
1426
+ var action = _ref3.action,
1427
+ index = _ref3.index;
1428
+ return /*#__PURE__*/react.createElement(ActionRow, {
1429
+ action: action,
1430
+ index: index,
1431
+ isActive: isActive,
1432
+ isInvalid: isInvalid,
1433
+ position: position,
1434
+ schema: schema,
1435
+ key: (_action$id = action.id) !== null && _action$id !== void 0 ? _action$id : index,
1436
+ onAddAction: position === named.length - 1 && handleAddAction,
1437
+ onRemove: handleRemoveAction && function () {
1438
+ return handleRemoveAction(index);
1439
+ },
1440
+ onToken: handleToken
1441
+ });
1442
+ }), adding && /*#__PURE__*/jsxRuntime.jsx("div", {
1443
+ className: "mb-row",
1444
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
1445
+ className: "mb-sentence",
1446
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1447
+ className: "mb-fixed",
1448
+ children: t("neetoRules.operators.and")
1449
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1450
+ active: true,
1451
+ dataTestid: "action-add-next",
1452
+ state: TOKEN_STATE.PLACEHOLDER_NEXT,
1453
+ onClick: handleAddAction,
1454
+ children: t("neetoRules.form.doThis")
1455
+ })]
1456
+ })
1457
+ })]
1458
+ });
1459
+ };
1460
+
1461
+ function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1462
+ function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1463
+ var WhenBlock = function WhenBlock(_ref) {
1464
+ var _schema$actor;
1465
+ var rule = _ref.rule,
1466
+ schema = _ref.schema,
1467
+ handleToken = _ref.onToken,
1468
+ handleAddCondition = _ref.onAddCondition,
1469
+ handleClearTrigger = _ref.onClearTrigger,
1470
+ _ref$isActive = _ref.isActive,
1471
+ isActive = _ref$isActive === void 0 ? function () {
1472
+ return false;
1473
+ } : _ref$isActive,
1474
+ _ref$isInvalid = _ref.isInvalid,
1475
+ isInvalid = _ref$isInvalid === void 0 ? function () {
1476
+ return false;
1477
+ } : _ref$isInvalid;
1478
+ var _useTranslation = reactI18next.useTranslation(),
1479
+ t = _useTranslation.t;
1480
+ var triggers = rule.triggers,
1481
+ performer = rule.performer;
1482
+ var isActorEnabled = schema === null || schema === void 0 || (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.enabled;
1483
+ var _useClearingHover = useClearingHover(),
1484
+ clearing = _useClearingHover.clearing,
1485
+ clearingHoverProps = _useClearingHover.clearingHoverProps,
1486
+ resetClearing = _useClearingHover.resetClearing;
1487
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
1488
+ var hasLeadTimeFor = function hasLeadTimeFor(name) {
1489
+ var _schema$triggers;
1490
+ return ((schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 || (_schema$triggers = _schema$triggers.leadTime) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.appliesTo) || []).includes(name);
1491
+ };
1492
+ if (ramda.isEmpty(triggers)) {
1493
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
1494
+ className: "mb-row",
1495
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
1496
+ className: "mb-sentence",
1497
+ children: /*#__PURE__*/jsxRuntime.jsx(Token, {
1498
+ dataTestid: "trigger-add",
1499
+ state: TOKEN_STATE.PLACEHOLDER_NEXT,
1500
+ onClick: handleToken && function () {
1501
+ return handleToken({
1502
+ type: BUILDER_ANCHORS.TRIGGER_ADD
1503
+ });
1504
+ },
1505
+ children: t("neetoRules.builder.whenThisHappens")
1506
+ })
1507
+ })
1508
+ });
1509
+ }
1510
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1511
+ className: classNames("mb-row", {
1512
+ clearing: clearing
1513
+ }),
1514
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
1515
+ className: "mb-sentence",
1516
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1517
+ className: "mb-fixed",
1518
+ children: t("neetoRules.common.when")
1519
+ }), triggers.map(function (trigger, index) {
1520
+ var _trigger$id;
1521
+ return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
1522
+ children: [index > 0 && /*#__PURE__*/jsxRuntime.jsx("span", {
1523
+ className: "mb-fixed",
1524
+ children: t("neetoRules.operators.or")
1525
+ }), hasLeadTimeFor(trigger.name) && /*#__PURE__*/jsxRuntime.jsx(Token, {
1526
+ dataTestid: "trigger-lead-time-".concat(index),
1527
+ active: isActive({
1528
+ type: BUILDER_ANCHORS.TRIGGER_LEAD_TIME,
1529
+ index: index
1530
+ }),
1531
+ onClick: handleToken && function () {
1532
+ return handleToken({
1533
+ type: BUILDER_ANCHORS.TRIGGER_LEAD_TIME,
1534
+ index: index
1535
+ });
1536
+ },
1537
+ children: leadTimeLabel(rule.leadTime)
1538
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1539
+ dataTestid: "trigger-".concat(index),
1540
+ active: isActive({
1541
+ type: BUILDER_ANCHORS.TRIGGER_REPLACE,
1542
+ index: index
1543
+ }) || index === 0 && isActive({
1544
+ type: BUILDER_ANCHORS.TRIGGER_ADD,
1545
+ index: undefined
1546
+ }),
1547
+ onClick: handleToken && function () {
1548
+ return handleToken({
1549
+ type: BUILDER_ANCHORS.TRIGGER_REPLACE,
1550
+ index: index,
1551
+ trigger: trigger
1552
+ });
1553
+ },
1554
+ children: triggerLabel({
1555
+ schema: schema,
1556
+ trigger: trigger
1557
+ })
1558
+ })]
1559
+ }, (_trigger$id = trigger.id) !== null && _trigger$id !== void 0 ? _trigger$id : index);
1560
+ }), isActorEnabled && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
1561
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1562
+ className: "mb-fixed",
1563
+ children: t("neetoRules.common.by")
1564
+ }), /*#__PURE__*/jsxRuntime.jsx(Token, {
1565
+ dataTestid: "trigger-actor",
1566
+ state: performer ? TOKEN_STATE.FILLED : TOKEN_STATE.MUTED,
1567
+ active: isActive({
1568
+ type: BUILDER_ANCHORS.TRIGGER_ACTOR,
1569
+ index: undefined
1570
+ }),
1571
+ invalid: isInvalid({
1572
+ type: BUILDER_ANCHORS.TRIGGER_ACTOR,
1573
+ index: undefined
1574
+ }),
1575
+ onClick: handleToken && function () {
1576
+ return handleToken({
1577
+ type: BUILDER_ANCHORS.TRIGGER_ACTOR
1578
+ });
1579
+ },
1580
+ children: performer ? performerLabel({
1581
+ schema: schema,
1582
+ performer: performer
1583
+ }) : t("neetoRules.builder.selectActor")
1584
+ })]
1585
+ })]
1586
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1587
+ className: "mb-row-actions",
1588
+ children: [handleAddCondition && /*#__PURE__*/jsxRuntime.jsx(Button, {
1589
+ "data-testid": "trigger-add-condition",
1590
+ icon: Plus,
1591
+ size: "small",
1592
+ style: "text",
1593
+ tooltipProps: {
1594
+ content: t("neetoRules.builder.aria.addCondition"),
1595
+ position: "top"
1596
+ },
1597
+ onClick: handleAddCondition
1598
+ }), handleClearTrigger && /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread$6({
1599
+ "data-testid": "trigger-clear",
1600
+ icon: Delete,
1601
+ size: "small",
1602
+ style: "text",
1603
+ tooltipProps: {
1604
+ content: t("neetoRules.builder.aria.clearTrigger"),
1605
+ position: "top"
1606
+ },
1607
+ onClick: function onClick() {
1608
+ resetClearing();
1609
+ handleClearTrigger();
1610
+ }
1611
+ }, clearingHoverProps))]
1612
+ })]
1613
+ });
1614
+ };
1615
+
1616
+ function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1617
+ function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1618
+ var usePaneCascade = function usePaneCascade(schema) {
1619
+ var _useUtilityStore = useUtilityStore.useUtilityStore(shallow.useShallow(function (store) {
1620
+ return {
1621
+ setPanelState: store["setPanelState"],
1622
+ resetPanelState: store["resetPanelState"]
1623
+ };
1624
+ })),
1625
+ setPanelState = _useUtilityStore.setPanelState,
1626
+ resetPanelState = _useUtilityStore.resetPanelState;
1627
+ var openType = react.useCallback(function (_ref) {
1628
+ var type = _ref.type,
1629
+ _ref$data = _ref.data,
1630
+ data = _ref$data === void 0 ? {} : _ref$data;
1631
+ return setPanelState({
1632
+ type: type,
1633
+ variant: "builder",
1634
+ size: LARGE_PANEL_TYPES.includes(type) ? "large" : "small",
1635
+ data: _objectSpread$5({
1636
+ schema: schema
1637
+ }, data)
1638
+ });
1639
+ }, [schema, setPanelState]);
1640
+ var openPane = react.useCallback(function (token) {
1641
+ var type = TOKEN_TO_PANEL_TYPE[token === null || token === void 0 ? void 0 : token.type];
1642
+ if (!type) return;
1643
+ openType({
1644
+ type: type,
1645
+ data: {
1646
+ anchor: token.type,
1647
+ index: token.index
1648
+ }
1649
+ });
1650
+ }, [openType]);
1651
+ return {
1652
+ openPane: openPane,
1653
+ openType: openType,
1654
+ closePane: resetPanelState
1655
+ };
1656
+ };
1657
+
1658
+ var useRuleModel = function useRuleModel(schema) {
1659
+ var _useFormikContext = formik.useFormikContext(),
1660
+ values = _useFormikContext.values,
1661
+ setFieldValue = _useFormikContext.setFieldValue;
1662
+ var apply = function apply(_ref) {
1663
+ var path = _ref.path,
1664
+ value = _ref.value;
1665
+ return setFieldValue(path, value);
1666
+ };
1667
+ var applyAll = function applyAll(edits) {
1668
+ return edits.forEach(apply);
1669
+ };
1670
+ var rule = react.useMemo(function () {
1671
+ return valuesToRuleModel({
1672
+ values: values,
1673
+ schema: schema
1674
+ });
1675
+ }, [values, schema]);
1676
+ return {
1677
+ rule: rule,
1678
+ fieldKeys: fieldKeysFromSchema(schema),
1679
+ setTriggers: function setTriggers$1(triggers) {
1680
+ return apply(setTriggers({
1681
+ schema: schema,
1682
+ triggers: triggers
1683
+ }));
1684
+ },
1685
+ setPerformer: function setPerformer$1(performer) {
1686
+ return apply(setPerformer({
1687
+ schema: schema,
1688
+ performer: performer
1689
+ }));
1690
+ },
1691
+ setActions: function setActions$1(actions) {
1692
+ return apply(setActions({
1693
+ schema: schema,
1694
+ actions: actions
1695
+ }));
1696
+ },
1697
+ setConditions: function setConditions$1(conditions) {
1698
+ return apply(setConditions({
1699
+ schema: schema,
1700
+ conditions: conditions
1701
+ }));
1702
+ },
1703
+ setConditionMode: function setConditionMode$1(joinType) {
1704
+ return apply(setConditionMode({
1705
+ schema: schema,
1706
+ conditions: rule.conditions,
1707
+ joinType: joinType
1708
+ }));
1709
+ },
1710
+ setDelay: function setDelay$1(delay) {
1711
+ return apply(setDelay({
1712
+ schema: schema,
1713
+ delay: delay
1714
+ }));
1715
+ },
1716
+ setActive: function setActive$1(active) {
1717
+ return apply(setActive({
1718
+ schema: schema,
1719
+ active: active
1720
+ }));
1721
+ },
1722
+ setScope: function setScope$1(scope) {
1723
+ return apply(setScope({
1724
+ schema: schema,
1725
+ scope: scope
1726
+ }));
1727
+ },
1728
+ removeCondition: function removeCondition(index) {
1729
+ return applyAll(removeArrayItem({
1730
+ values: values,
1731
+ fieldKey: fieldKeysFromSchema(schema).conditions,
1732
+ index: index
1733
+ }));
1734
+ },
1735
+ removeAction: function removeAction(index) {
1736
+ return applyAll(removeArrayItem({
1737
+ values: values,
1738
+ fieldKey: fieldKeysFromSchema(schema).actions,
1739
+ index: index
1740
+ }));
1741
+ }
1742
+ };
1743
+ };
1744
+
1745
+ function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1746
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1747
+ var triggerValue = function triggerValue(option) {
1748
+ var _ref, _option$eventValue;
1749
+ return (_ref = (_option$eventValue = option.eventValue) !== null && _option$eventValue !== void 0 ? _option$eventValue : option.value) !== null && _ref !== void 0 ? _ref : option.id;
1750
+ };
1751
+ var optionValue = function optionValue(option) {
1752
+ var _option$value;
1753
+ return (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.id;
1754
+ };
1755
+ var normalizeOptions = function normalizeOptions(options) {
1756
+ return (options || []).map(function (option) {
1757
+ return typeof option === "string" ? neetoCist.toLabelAndValue(option) : option;
1758
+ });
1759
+ };
1760
+ var groupByCategory = function groupByCategory(options) {
1761
+ var groups = [];
1762
+ var indexByCategory = {};
1763
+ options.forEach(function (option) {
1764
+ var category = option.category || "";
1765
+ // eslint-disable-next-line security/detect-object-injection
1766
+ if (indexByCategory[category] === undefined) {
1767
+ // eslint-disable-next-line security/detect-object-injection
1768
+ indexByCategory[category] = groups.length;
1769
+ groups.push([category, []]);
1770
+ }
1771
+ // eslint-disable-next-line security/detect-object-injection
1772
+ groups[indexByCategory[category]][1].push(option);
1773
+ });
1774
+ return groups;
1775
+ };
1776
+ var conditionAt = function conditionAt(_ref2) {
1777
+ var rule = _ref2.rule,
1778
+ index = _ref2.index;
1779
+ return (
1780
+ // eslint-disable-next-line security/detect-object-injection
1781
+ rule.conditions[index] || {}
1782
+ );
1783
+ };
1784
+
1785
+ // eslint-disable-next-line security/detect-object-injection
1786
+ var actionAt = function actionAt(_ref3) {
1787
+ var rule = _ref3.rule,
1788
+ index = _ref3.index;
1789
+ return rule.actions[index] || {};
1790
+ };
1791
+ var findField = function findField(_ref4) {
1792
+ var _schema$conditions;
1793
+ var schema = _ref4.schema,
1794
+ value = _ref4.value;
1795
+ return (((_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (field) {
1796
+ return optionValue(field) === value;
1797
+ });
1798
+ };
1799
+ var findActionOption = function findActionOption(_ref5) {
1800
+ var _schema$actions;
1801
+ var schema = _ref5.schema,
1802
+ name = _ref5.name;
1803
+ return (((_schema$actions = schema.actions) === null || _schema$actions === void 0 ? void 0 : _schema$actions.options) || []).find(function (option) {
1804
+ return optionValue(option) === name;
1805
+ });
1806
+ };
1807
+ var channelOf = function channelOf(_ref6) {
1808
+ var _schema$actions2, _schema$actions2$acti;
1809
+ var schema = _ref6.schema,
1810
+ action = _ref6.action;
1811
+ return (action === null || action === void 0 ? void 0 : action.channel) || ((_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$acti = _schema$actions2.actionForName) === null || _schema$actions2$acti === void 0 || (_schema$actions2$acti = _schema$actions2$acti.call(_schema$actions2, action === null || action === void 0 ? void 0 : action.name)) === null || _schema$actions2$acti === void 0 ? void 0 : _schema$actions2$acti.channel);
1812
+ };
1813
+ var channelMetaOf = function channelMetaOf(_ref7) {
1814
+ var _schema$actions3;
1815
+ var schema = _ref7.schema,
1816
+ action = _ref7.action;
1817
+ return ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 || (_schema$actions3 = _schema$actions3.channelMeta) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3[channelOf({
1818
+ schema: schema,
1819
+ action: action
1820
+ })]) || {};
1821
+ };
1822
+ var actionHasConfig = function actionHasConfig(_ref8) {
1823
+ var _schema$actions4, _schema$actions5;
1824
+ var schema = _ref8.schema,
1825
+ action = _ref8.action;
1826
+ var meta = channelMetaOf({
1827
+ schema: schema,
1828
+ action: action
1829
+ });
1830
+ if (meta.mediumLabel) return true;
1831
+ var option = findActionOption({
1832
+ schema: schema,
1833
+ name: action === null || action === void 0 ? void 0 : action.name
1834
+ });
1835
+ if (option !== null && option !== void 0 && option.component || option !== null && option !== void 0 && option.renderConfig) return true;
1836
+ if ((_schema$actions4 = schema.actions) !== null && _schema$actions4 !== void 0 && _schema$actions4.hasConfig) return schema.actions.hasConfig(action);
1837
+ return !!((_schema$actions5 = schema.actions) !== null && _schema$actions5 !== void 0 && _schema$actions5.renderConfig);
1838
+ };
1839
+ var recipientsFor = function recipientsFor(_ref9) {
1840
+ var _schema$actions6, _schema$actions7;
1841
+ var schema = _ref9.schema,
1842
+ action = _ref9.action;
1843
+ var channel = channelOf({
1844
+ schema: schema,
1845
+ action: action
1846
+ });
1847
+ if (channel && (_schema$actions6 = schema.actions) !== null && _schema$actions6 !== void 0 && _schema$actions6.recipientsFor) {
1848
+ return schema.actions.recipientsFor(channel);
1849
+ }
1850
+ var option = findActionOption({
1851
+ schema: schema,
1852
+ name: channel
1853
+ });
1854
+ if (option !== null && option !== void 0 && option.recipients) return option.recipients;
1855
+ return ((_schema$actions7 = schema.actions) === null || _schema$actions7 === void 0 ? void 0 : _schema$actions7.recipients) || [];
1856
+ };
1857
+ var nextTriggers = function nextTriggers(_ref0) {
1858
+ var _schema$triggers;
1859
+ var schema = _ref0.schema,
1860
+ rule = _ref0.rule,
1861
+ value = _ref0.value;
1862
+ if ((_schema$triggers = schema.triggers) !== null && _schema$triggers !== void 0 && _schema$triggers.multi) {
1863
+ var names = ramda.pluck("name", rule.triggers);
1864
+ return names.includes(value) ? neetoCist.removeBy({
1865
+ name: value
1866
+ }, rule.triggers) : [].concat(_toConsumableArray(rule.triggers), [{
1867
+ name: value
1868
+ }]);
1869
+ }
1870
+ return [{
1871
+ name: value
1872
+ }];
1873
+ };
1874
+ var nextConditionAt = function nextConditionAt(_ref1) {
1875
+ var _field$allowMatching;
1876
+ var schema = _ref1.schema,
1877
+ rule = _ref1.rule,
1878
+ index = _ref1.index,
1879
+ value = _ref1.value;
1880
+ var field = findField({
1881
+ schema: schema,
1882
+ value: value
1883
+ });
1884
+ var previous = conditionAt({
1885
+ rule: rule,
1886
+ index: index
1887
+ });
1888
+ var first = field === null || field === void 0 || (_field$allowMatching = field.allowMatching) === null || _field$allowMatching === void 0 ? void 0 : _field$allowMatching[0];
1889
+ var defaultVerb = first && !((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(first) ? first : undefined;
1890
+ var verb = ((field === null || field === void 0 ? void 0 : field.allowMatching) || []).includes(previous.verb) ? previous.verb : defaultVerb;
1891
+ return _objectSpread$4(_objectSpread$4({}, previous), {}, {
1892
+ field: value,
1893
+ kind: field === null || field === void 0 ? void 0 : field.kind,
1894
+ verb: verb,
1895
+ metadata: {}
1896
+ });
1897
+ };
1898
+ var nextActionAt = function nextActionAt(_ref10) {
1899
+ var _schema$actions8;
1900
+ var schema = _ref10.schema,
1901
+ rule = _ref10.rule,
1902
+ index = _ref10.index,
1903
+ value = _ref10.value;
1904
+ if (!((_schema$actions8 = schema.actions) !== null && _schema$actions8 !== void 0 && _schema$actions8.resolveName)) {
1905
+ var option = findActionOption({
1906
+ schema: schema,
1907
+ name: value
1908
+ });
1909
+ var _prev = actionAt({
1910
+ rule: rule,
1911
+ index: index
1912
+ });
1913
+ if (option !== null && option !== void 0 && option.recipients) {
1914
+ var _channelChanged = _prev.channel !== value;
1915
+ return _objectSpread$4(_objectSpread$4({}, _prev), {}, {
1916
+ channel: value,
1917
+ recipient: _channelChanged ? undefined : _prev.recipient,
1918
+ name: "",
1919
+ type: option === null || option === void 0 ? void 0 : option.type,
1920
+ metadata: _channelChanged ? {} : _prev.metadata
1921
+ });
1922
+ }
1923
+ return _objectSpread$4(_objectSpread$4({}, _prev), {}, {
1924
+ channel: undefined,
1925
+ recipient: undefined,
1926
+ name: value,
1927
+ type: option === null || option === void 0 ? void 0 : option.type,
1928
+ metadata: {}
1929
+ });
1930
+ }
1931
+ var prev = actionAt({
1932
+ rule: rule,
1933
+ index: index
1934
+ });
1935
+ var prevChannel = channelOf({
1936
+ schema: schema,
1937
+ action: prev
1938
+ });
1939
+ var channelChanged = prevChannel !== value;
1940
+ var recipient = channelChanged ? undefined : prev.recipient;
1941
+ if (channelChanged) {
1942
+ var _schema$actions9;
1943
+ var channelRecipients =
1944
+ // eslint-disable-next-line security/detect-object-injection
1945
+ ((_schema$actions9 = schema.actions) === null || _schema$actions9 === void 0 || (_schema$actions9 = _schema$actions9.recipientsByChannel) === null || _schema$actions9 === void 0 ? void 0 : _schema$actions9[value]) || [];
1946
+ if (channelRecipients.length === 1) {
1947
+ var _channelRecipients = _slicedToArray(channelRecipients, 1);
1948
+ recipient = _channelRecipients[0];
1949
+ }
1950
+ }
1951
+ return _objectSpread$4(_objectSpread$4({}, prev), {}, {
1952
+ channel: value,
1953
+ recipient: recipient,
1954
+ name: schema.actions.resolveName({
1955
+ channel: value,
1956
+ recipient: recipient
1957
+ }),
1958
+ metadata: channelChanged ? {} : prev.metadata
1959
+ });
1960
+ };
1961
+ var nextActionRecipientAt = function nextActionRecipientAt(_ref11) {
1962
+ var _schema$actions0;
1963
+ var schema = _ref11.schema,
1964
+ rule = _ref11.rule,
1965
+ index = _ref11.index,
1966
+ value = _ref11.value;
1967
+ var prev = actionAt({
1968
+ rule: rule,
1969
+ index: index
1970
+ });
1971
+ var channel = channelOf({
1972
+ schema: schema,
1973
+ action: prev
1974
+ });
1975
+ return _objectSpread$4(_objectSpread$4({}, prev), {}, {
1976
+ recipient: value,
1977
+ name: (_schema$actions0 = schema.actions) !== null && _schema$actions0 !== void 0 && _schema$actions0.resolveName ? schema.actions.resolveName({
1978
+ channel: channel,
1979
+ recipient: value
1980
+ }) : value
1981
+ });
1982
+ };
1983
+ var descriptorFor = function descriptorFor(_ref12) {
1984
+ var _schema$actor2, _schema$conditions2;
1985
+ var anchor = _ref12.anchor,
1986
+ schema = _ref12.schema,
1987
+ rule = _ref12.rule,
1988
+ index = _ref12.index;
1989
+ switch (anchor) {
1990
+ case BUILDER_ANCHORS.TRIGGER_ADD:
1991
+ case BUILDER_ANCHORS.TRIGGER_REPLACE:
1992
+ {
1993
+ var _schema$triggers2, _schema$actor, _schema$triggers3;
1994
+ var multi = !!((_schema$triggers2 = schema.triggers) !== null && _schema$triggers2 !== void 0 && _schema$triggers2.multi);
1995
+ var isReplace = anchor === BUILDER_ANCHORS.TRIGGER_REPLACE;
1996
+ var triggerTitle = isReplace ? multi && i18next.t("neetoRules.builder.panes.changeTriggers") || i18next.t("neetoRules.builder.panes.changeTrigger") : multi && i18next.t("neetoRules.builder.panes.whenEllipsis") || i18next.t("neetoRules.builder.panes.addTrigger");
1997
+ var triggerSubtitle = multi && i18next.t("neetoRules.builder.panes.triggerSubtitleMulti") || (isReplace ? i18next.t("neetoRules.builder.panes.triggerSubtitleReplace") : i18next.t("neetoRules.builder.panes.triggerSubtitleAdd"));
1998
+ return {
1999
+ title: triggerTitle,
2000
+ subtitle: triggerSubtitle,
2001
+ multi: multi,
2002
+ cascade: !!((_schema$actor = schema.actor) !== null && _schema$actor !== void 0 && _schema$actor.enabled),
2003
+ options: (((_schema$triggers3 = schema.triggers) === null || _schema$triggers3 === void 0 ? void 0 : _schema$triggers3.options) || []).map(function (option) {
2004
+ return {
2005
+ label: option.paneLabel || option.label,
2006
+ value: triggerValue(option),
2007
+ category: option.category
2008
+ };
2009
+ }),
2010
+ selectedValues: ramda.pluck("name", rule.triggers)
2011
+ };
2012
+ }
2013
+ case BUILDER_ANCHORS.TRIGGER_ACTOR:
2014
+ return {
2015
+ title: i18next.t("neetoRules.builder.panes.actorTitle"),
2016
+ subtitle: i18next.t("neetoRules.builder.panes.actorSubtitle"),
2017
+ options: (((_schema$actor2 = schema.actor) === null || _schema$actor2 === void 0 ? void 0 : _schema$actor2.options) || []).map(function (option) {
2018
+ return {
2019
+ label: option.label,
2020
+ value: optionValue(option)
2021
+ };
2022
+ }),
2023
+ selectedValues: [rule.performer]
2024
+ };
2025
+ case BUILDER_ANCHORS.COND_FIELD:
2026
+ return {
2027
+ title: i18next.t("neetoRules.builder.panes.addCondition"),
2028
+ subtitle: i18next.t("neetoRules.builder.panes.condFieldSubtitle"),
2029
+ cascade: true,
2030
+ options: (((_schema$conditions2 = schema.conditions) === null || _schema$conditions2 === void 0 ? void 0 : _schema$conditions2.fields) || []).map(function (field) {
2031
+ return {
2032
+ label: field.paneLabel || field.label,
2033
+ value: optionValue(field),
2034
+ category: field.category
2035
+ };
2036
+ }),
2037
+ selectedValues: [conditionAt({
2038
+ rule: rule,
2039
+ index: index
2040
+ }).field]
2041
+ };
2042
+ case BUILDER_ANCHORS.COND_OP_TOGGLE:
2043
+ {
2044
+ var _schema$conditions3;
2045
+ var field = findField({
2046
+ schema: schema,
2047
+ value: conditionAt({
2048
+ rule: rule,
2049
+ index: index
2050
+ }).field
2051
+ });
2052
+ var labels = ((_schema$conditions3 = schema.conditions) === null || _schema$conditions3 === void 0 ? void 0 : _schema$conditions3.operatorLabels) || {};
2053
+ var verbs = (field === null || field === void 0 ? void 0 : field.allowMatching) || [];
2054
+ var fieldLabel = (field === null || field === void 0 ? void 0 : field.paneLabel) || (field === null || field === void 0 ? void 0 : field.label) || "";
2055
+ var isContains = neetoCist.isNotEmpty(verbs) && verbs.every(isContainsVerb);
2056
+ var isNumeric = !isContains && verbs.some(isNumericVerb);
2057
+ var isExclude = !isContains && !isNumeric && verbs.some(isExcludeVerb);
2058
+ var hasOptions = neetoCist.isNotEmpty(normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options)));
2059
+ var containsVariant = hasOptions ? "Values" : "Keywords";
2060
+ var numericOrExcludeVariant = isExclude ? "Exclude" : "";
2061
+ var nonContainsVariant = isNumeric ? "Number" : numericOrExcludeVariant;
2062
+ var variant = isContains ? containsVariant : nonContainsVariant;
2063
+ return {
2064
+ title: i18next.t("neetoRules.builder.panes.operatorTitle".concat(variant)),
2065
+ subtitle: variant ? i18next.t("neetoRules.builder.panes.operatorSubtitle".concat(variant), {
2066
+ field: fieldLabel
2067
+ }) : i18next.t("neetoRules.builder.panes.operatorSubtitle"),
2068
+ cascade: true,
2069
+ options: verbs.map(function (verb) {
2070
+ return {
2071
+ // eslint-disable-next-line security/detect-object-injection
2072
+ label: labels[verb] || humanize(verb),
2073
+ value: verb
2074
+ };
2075
+ }),
2076
+ selectedValues: [conditionAt({
2077
+ rule: rule,
2078
+ index: index
2079
+ }).verb]
2080
+ };
2081
+ }
2082
+ case BUILDER_ANCHORS.COND_CONNECTOR:
2083
+ return {
2084
+ title: i18next.t("neetoRules.builder.panes.connectorTitle"),
2085
+ subtitle: i18next.t("neetoRules.builder.panes.connectorSubtitle"),
2086
+ options: [{
2087
+ label: i18next.t("neetoRules.builder.panes.connectorAndOption"),
2088
+ value: CONDITION_MODE.AND
2089
+ }, {
2090
+ label: i18next.t("neetoRules.builder.panes.connectorOrOption"),
2091
+ value: CONDITION_MODE.OR
2092
+ }],
2093
+ selectedValues: [rule.conditionMode]
2094
+ };
2095
+ case BUILDER_ANCHORS.ACTION_ADD:
2096
+ case BUILDER_ANCHORS.ACTION_CHANNEL:
2097
+ {
2098
+ var _schema$actions10, _schema$actions11, _channelOf;
2099
+ var isSwap = anchor === BUILDER_ANCHORS.ACTION_CHANNEL;
2100
+ var channelMetaFor = function channelMetaFor(value) {
2101
+ var _schema$actions1;
2102
+ return (
2103
+ // eslint-disable-next-line security/detect-object-injection
2104
+ ((_schema$actions1 = schema.actions) === null || _schema$actions1 === void 0 || (_schema$actions1 = _schema$actions1.channelMeta) === null || _schema$actions1 === void 0 ? void 0 : _schema$actions1[value]) || {}
2105
+ );
2106
+ };
2107
+ var rank = function rank(value) {
2108
+ var idx = SWAP_CHANNEL_ORDER.indexOf(value);
2109
+ return idx === -1 ? SWAP_CHANNEL_ORDER.length : idx;
2110
+ };
2111
+ var sourceOptions = isSwap ? _toConsumableArray(((_schema$actions10 = schema.actions) === null || _schema$actions10 === void 0 ? void 0 : _schema$actions10.options) || []).sort(function (optionA, optionB) {
2112
+ return rank(optionValue(optionA)) - rank(optionValue(optionB));
2113
+ }) : ((_schema$actions11 = schema.actions) === null || _schema$actions11 === void 0 ? void 0 : _schema$actions11.options) || [];
2114
+ return {
2115
+ title: isSwap ? i18next.t("neetoRules.builder.panes.actionSwapTitle") : i18next.t("neetoRules.builder.panes.actionAddTitle"),
2116
+ subtitle: isSwap ? i18next.t("neetoRules.builder.panes.actionSwapSubtitle") : i18next.t("neetoRules.builder.panes.actionAddSubtitle"),
2117
+ cascade: true,
2118
+ options: sourceOptions.map(function (option) {
2119
+ var value = optionValue(option);
2120
+ var meta = channelMetaFor(value);
2121
+ return {
2122
+ label: isSwap ? meta.channelLabel || option.label : option.label,
2123
+ value: value,
2124
+ category: option.category,
2125
+ disabled: !!option.disabled,
2126
+ icon: (isSwap ? meta.icon : option.icon) || option.icon
2127
+ };
2128
+ }),
2129
+ selectedValues: [(_channelOf = channelOf({
2130
+ schema: schema,
2131
+ action: actionAt({
2132
+ rule: rule,
2133
+ index: index
2134
+ })
2135
+ })) !== null && _channelOf !== void 0 ? _channelOf : actionAt({
2136
+ rule: rule,
2137
+ index: index
2138
+ }).name]
2139
+ };
2140
+ }
2141
+ case BUILDER_ANCHORS.ACTION_RECIPIENT:
2142
+ {
2143
+ var _schema$actions12;
2144
+ var action = actionAt({
2145
+ rule: rule,
2146
+ index: index
2147
+ });
2148
+ var channel = channelOf({
2149
+ schema: schema,
2150
+ action: action
2151
+ });
2152
+ // eslint-disable-next-line security/detect-object-injection
2153
+ var meta = ((_schema$actions12 = schema.actions) === null || _schema$actions12 === void 0 || (_schema$actions12 = _schema$actions12.channelMeta) === null || _schema$actions12 === void 0 ? void 0 : _schema$actions12[channel]) || {};
2154
+ var option = findActionOption({
2155
+ schema: schema,
2156
+ name: channel
2157
+ });
2158
+ return {
2159
+ title: meta.recipientTitle || (option === null || option === void 0 ? void 0 : option.recipientTitle) || i18next.t("neetoRules.builder.panes.recipientTitle"),
2160
+ subtitle: meta.recipientSubtitle || (option === null || option === void 0 ? void 0 : option.recipientSubtitle) || i18next.t("neetoRules.builder.panes.recipientSubtitle"),
2161
+ options: recipientsFor({
2162
+ schema: schema,
2163
+ action: action
2164
+ }).map(function (recipient) {
2165
+ return {
2166
+ label: recipient.label,
2167
+ value: optionValue(recipient)
2168
+ };
2169
+ }),
2170
+ selectedValues: [action.recipient]
2171
+ };
2172
+ }
2173
+ case BUILDER_ANCHORS.SCOPE:
2174
+ {
2175
+ var _sc$requiresPhone;
2176
+ var sc = schema.scope || {};
2177
+ var selected = (rule.scope || []).map(function (item) {
2178
+ var _item$value;
2179
+ return (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : item;
2180
+ });
2181
+ var requiresPhone = ((_sc$requiresPhone = sc.requiresPhone) === null || _sc$requiresPhone === void 0 ? void 0 : _sc$requiresPhone.call(sc, rule.actions)) || false;
2182
+ return {
2183
+ title: selected.length ? sc.paneChangeTitle || i18next.t("neetoRules.builder.panes.scopeChangeTitle") : sc.paneTitle || i18next.t("neetoRules.builder.panes.scopeTitle"),
2184
+ subtitle: sc.paneSubtitle || i18next.t("neetoRules.builder.panes.scopeSubtitle"),
2185
+ multi: true,
2186
+ options: (sc.options || []).map(function (option) {
2187
+ var value = optionValue(option);
2188
+ var blockedNoPhone = requiresPhone && option.hasPhoneField === false;
2189
+ var isSelected = selected.includes(value);
2190
+ return {
2191
+ label: option.label,
2192
+ value: value,
2193
+ disabled: (!!option.disabled || blockedNoPhone) && !isSelected,
2194
+ disabledReason: blockedNoPhone && sc.disabledReason,
2195
+ disabledTooltip: blockedNoPhone && sc.disabledTooltip
2196
+ };
2197
+ }),
2198
+ selectedValues: selected
2199
+ };
2200
+ }
2201
+ default:
2202
+ return {
2203
+ title: "",
2204
+ subtitle: "",
2205
+ options: [],
2206
+ selectedValues: []
2207
+ };
2208
+ }
2209
+ };
2210
+ var commitFor = function commitFor(_ref13) {
2211
+ var anchor = _ref13.anchor,
2212
+ schema = _ref13.schema,
2213
+ rule = _ref13.rule,
2214
+ index = _ref13.index,
2215
+ value = _ref13.value,
2216
+ helpers = _ref13.helpers;
2217
+ var setTriggers = helpers.setTriggers,
2218
+ setPerformer = helpers.setPerformer,
2219
+ setConditionMode = helpers.setConditionMode,
2220
+ setFieldValue = helpers.setFieldValue,
2221
+ fieldKeys = helpers.fieldKeys;
2222
+ switch (anchor) {
2223
+ case BUILDER_ANCHORS.TRIGGER_ADD:
2224
+ case BUILDER_ANCHORS.TRIGGER_REPLACE:
2225
+ {
2226
+ var _schema$triggers4, _schema$triggers5;
2227
+ if ((_schema$triggers4 = schema.triggers) !== null && _schema$triggers4 !== void 0 && _schema$triggers4.multi) {
2228
+ var names = ramda.pluck("name", rule.triggers);
2229
+ setTriggers(names.includes(value) ? neetoCist.removeBy({
2230
+ name: value
2231
+ }, rule.triggers) : [].concat(_toConsumableArray(rule.triggers), [{
2232
+ name: value
2233
+ }]));
2234
+ return "stay";
2235
+ }
2236
+ setTriggers([{
2237
+ name: value
2238
+ }]);
2239
+ var leadTime = (_schema$triggers5 = schema.triggers) === null || _schema$triggers5 === void 0 ? void 0 : _schema$triggers5.leadTime;
2240
+ if (leadTime !== null && leadTime !== void 0 && leadTime.fieldKey && (leadTime.appliesTo || []).includes(value) && !rule.leadTime) {
2241
+ var _leadTime$default;
2242
+ // eslint-disable-next-line @bigbinary/neeto/use-common-constants
2243
+ setFieldValue("".concat(leadTime.fieldKey, ".value"), (_leadTime$default = leadTime["default"]) !== null && _leadTime$default !== void 0 ? _leadTime$default : 10);
2244
+ }
2245
+ return "stay";
2246
+ }
2247
+ case BUILDER_ANCHORS.TRIGGER_ACTOR:
2248
+ setPerformer(value);
2249
+ return "stay";
2250
+ case BUILDER_ANCHORS.COND_FIELD:
2251
+ {
2252
+ setFieldValue("".concat(fieldKeys.conditions, ".value.").concat(index), nextConditionAt({
2253
+ schema: schema,
2254
+ rule: rule,
2255
+ index: index,
2256
+ value: value
2257
+ }));
2258
+ return "stay";
2259
+ }
2260
+ case BUILDER_ANCHORS.COND_OP_TOGGLE:
2261
+ setFieldValue("".concat(fieldKeys.conditions, ".value.").concat(index, ".verb"), value);
2262
+ return "stay";
2263
+ case BUILDER_ANCHORS.COND_CONNECTOR:
2264
+ setConditionMode(value);
2265
+ return "stay";
2266
+ case BUILDER_ANCHORS.ACTION_ADD:
2267
+ case BUILDER_ANCHORS.ACTION_CHANNEL:
2268
+ {
2269
+ setFieldValue("".concat(fieldKeys.actions, ".value.").concat(index), nextActionAt({
2270
+ schema: schema,
2271
+ rule: rule,
2272
+ index: index,
2273
+ value: value
2274
+ }));
2275
+ return "stay";
2276
+ }
2277
+ case BUILDER_ANCHORS.ACTION_RECIPIENT:
2278
+ {
2279
+ setFieldValue("".concat(fieldKeys.actions, ".value.").concat(index), nextActionRecipientAt({
2280
+ schema: schema,
2281
+ rule: rule,
2282
+ index: index,
2283
+ value: value
2284
+ }));
2285
+ return "stay";
2286
+ }
2287
+ case BUILDER_ANCHORS.SCOPE:
2288
+ {
2289
+ var sc = schema.scope || {};
2290
+ var key = sc.fieldKey || "scope";
2291
+ var current = rule.scope || [];
2292
+ var has = current.some(function (item) {
2293
+ var _item$value2;
2294
+ return ((_item$value2 = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value2 !== void 0 ? _item$value2 : item) === value;
2295
+ });
2296
+ var next = has ? current.filter(function (item) {
2297
+ var _item$value3;
2298
+ return ((_item$value3 = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value3 !== void 0 ? _item$value3 : item) !== value;
2299
+ }) : [].concat(_toConsumableArray(current), [(sc.options || []).find(function (option) {
2300
+ return optionValue(option) === value;
2301
+ }) || {
2302
+ value: value
2303
+ }]);
2304
+ setFieldValue("".concat(key, ".value"), next);
2305
+ return "stay";
2306
+ }
2307
+ default:
2308
+ return "close";
2309
+ }
2310
+ };
2311
+ var continueTargetFor = function continueTargetFor(_ref14) {
2312
+ var _schema$actor3;
2313
+ var anchor = _ref14.anchor,
2314
+ schema = _ref14.schema,
2315
+ rule = _ref14.rule,
2316
+ index = _ref14.index;
2317
+ switch (anchor) {
2318
+ case BUILDER_ANCHORS.TRIGGER_ADD:
2319
+ case BUILDER_ANCHORS.TRIGGER_REPLACE:
2320
+ return (_schema$actor3 = schema.actor) !== null && _schema$actor3 !== void 0 && _schema$actor3.enabled ? {
2321
+ type: BUILDER_PANEL_TYPES.ACTOR,
2322
+ data: {
2323
+ anchor: BUILDER_ANCHORS.TRIGGER_ACTOR
2324
+ }
2325
+ } : null;
2326
+ case BUILDER_ANCHORS.COND_FIELD:
2327
+ return {
2328
+ type: BUILDER_PANEL_TYPES.OPERATOR,
2329
+ data: {
2330
+ index: index,
2331
+ anchor: BUILDER_ANCHORS.COND_OP_TOGGLE
2332
+ }
2333
+ };
2334
+ case BUILDER_ANCHORS.COND_OP_TOGGLE:
2335
+ {
2336
+ var condition = conditionAt({
2337
+ rule: rule,
2338
+ index: index
2339
+ });
2340
+ var field = findField({
2341
+ schema: schema,
2342
+ value: condition.field
2343
+ });
2344
+ if (((field === null || field === void 0 ? void 0 : field.noValueForVerbs) || []).includes(condition.verb)) return null;
2345
+ return {
2346
+ type: BUILDER_PANEL_TYPES.CONDITION_VALUE,
2347
+ data: {
2348
+ index: index,
2349
+ anchor: BUILDER_ANCHORS.COND_VALUES
2350
+ }
2351
+ };
2352
+ }
2353
+ case BUILDER_ANCHORS.ACTION_ADD:
2354
+ case BUILDER_ANCHORS.ACTION_CHANNEL:
2355
+ {
2356
+ var action = actionAt({
2357
+ rule: rule,
2358
+ index: index
2359
+ });
2360
+ if (actionHasConfig({
2361
+ schema: schema,
2362
+ action: action
2363
+ })) {
2364
+ return {
2365
+ type: BUILDER_PANEL_TYPES.ACTION_CONFIG,
2366
+ data: {
2367
+ index: index,
2368
+ anchor: BUILDER_ANCHORS.ACTION_CONFIG
2369
+ }
2370
+ };
2371
+ }
2372
+ return channelMetaOf({
2373
+ schema: schema,
2374
+ action: action
2375
+ }).needsRecipient ? {
2376
+ type: BUILDER_PANEL_TYPES.RECIPIENT,
2377
+ data: {
2378
+ index: index,
2379
+ anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
2380
+ }
2381
+ } : null;
2382
+ }
2383
+ case BUILDER_ANCHORS.ACTION_RECIPIENT:
2384
+ return null;
2385
+ default:
2386
+ return null;
2387
+ }
2388
+ };
2389
+ var replaceAt = function replaceAt(_ref15) {
2390
+ var list = _ref15.list,
2391
+ index = _ref15.index,
2392
+ item = _ref15.item;
2393
+ var next = _toConsumableArray(list);
2394
+ // eslint-disable-next-line security/detect-object-injection
2395
+ next[index] = item;
2396
+ return next;
2397
+ };
2398
+ var applyPreview = function applyPreview(_ref16) {
2399
+ var rule = _ref16.rule,
2400
+ schema = _ref16.schema,
2401
+ anchor = _ref16.anchor,
2402
+ index = _ref16.index,
2403
+ value = _ref16.value;
2404
+ switch (anchor) {
2405
+ case BUILDER_ANCHORS.TRIGGER_ADD:
2406
+ case BUILDER_ANCHORS.TRIGGER_REPLACE:
2407
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2408
+ triggers: Array.isArray(value) ? value.map(function (name) {
2409
+ return {
2410
+ name: name
2411
+ };
2412
+ }) : nextTriggers({
2413
+ schema: schema,
2414
+ rule: rule,
2415
+ value: value
2416
+ })
2417
+ });
2418
+ case BUILDER_ANCHORS.TRIGGER_ACTOR:
2419
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2420
+ performer: value
2421
+ });
2422
+ case BUILDER_ANCHORS.COND_FIELD:
2423
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2424
+ conditions: replaceAt({
2425
+ list: rule.conditions,
2426
+ index: index,
2427
+ item: nextConditionAt({
2428
+ schema: schema,
2429
+ rule: rule,
2430
+ index: index,
2431
+ value: value
2432
+ })
2433
+ })
2434
+ });
2435
+ case BUILDER_ANCHORS.COND_OP_TOGGLE:
2436
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2437
+ conditions: replaceAt({
2438
+ list: rule.conditions,
2439
+ index: index,
2440
+ item: _objectSpread$4(_objectSpread$4({}, conditionAt({
2441
+ rule: rule,
2442
+ index: index
2443
+ })), {}, {
2444
+ verb: value
2445
+ })
2446
+ })
2447
+ });
2448
+ case BUILDER_ANCHORS.COND_CONNECTOR:
2449
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2450
+ conditionMode: value
2451
+ });
2452
+ case BUILDER_ANCHORS.ACTION_ADD:
2453
+ case BUILDER_ANCHORS.ACTION_CHANNEL:
2454
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2455
+ actions: replaceAt({
2456
+ list: rule.actions,
2457
+ index: index,
2458
+ item: nextActionAt({
2459
+ schema: schema,
2460
+ rule: rule,
2461
+ index: index,
2462
+ value: value
2463
+ })
2464
+ })
2465
+ });
2466
+ case BUILDER_ANCHORS.ACTION_RECIPIENT:
2467
+ return _objectSpread$4(_objectSpread$4({}, rule), {}, {
2468
+ actions: replaceAt({
2469
+ list: rule.actions,
2470
+ index: index,
2471
+ item: nextActionRecipientAt({
2472
+ schema: schema,
2473
+ rule: rule,
2474
+ index: index,
2475
+ value: value
2476
+ })
2477
+ })
2478
+ });
2479
+ default:
2480
+ return rule;
2481
+ }
2482
+ };
2483
+
2484
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2485
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2486
+ var Canvas = function Canvas(_ref) {
2487
+ var _schema$scope, _schema$scope2, _schema$conditions, _schema$triggers, _schema$delay, _schema$meta$showName, _schema$meta;
2488
+ var schema = _ref.schema;
2489
+ var _useTranslation = reactI18next.useTranslation(),
2490
+ t = _useTranslation.t;
2491
+ var _usePaneCascade = usePaneCascade(schema),
2492
+ openPane = _usePaneCascade.openPane,
2493
+ closePane = _usePaneCascade.closePane;
2494
+ var _useFormikContext = formik.useFormikContext(),
2495
+ errors = _useFormikContext.errors,
2496
+ submitCount = _useFormikContext.submitCount;
2497
+ var _useRuleModel = useRuleModel(schema),
2498
+ rule = _useRuleModel.rule,
2499
+ fieldKeys = _useRuleModel.fieldKeys,
2500
+ setTriggers = _useRuleModel.setTriggers,
2501
+ setPerformer = _useRuleModel.setPerformer,
2502
+ setConditions = _useRuleModel.setConditions,
2503
+ setActions = _useRuleModel.setActions,
2504
+ setDelay = _useRuleModel.setDelay,
2505
+ removeCondition = _useRuleModel.removeCondition,
2506
+ removeAction = _useRuleModel.removeAction,
2507
+ setActive = _useRuleModel.setActive,
2508
+ setScope = _useRuleModel.setScope;
2509
+ var _useUtilityStore = useUtilityStore.useUtilityStore(shallow.useShallow(function (store) {
2510
+ return {
2511
+ builderPreview: store["builderPreview"],
2512
+ panelState: store["panelState"]
2513
+ };
2514
+ })),
2515
+ builderPreview = _useUtilityStore.builderPreview,
2516
+ panelState = _useUtilityStore.panelState;
2517
+ var displayRule = react.useMemo(function () {
2518
+ return builderPreview ? applyPreview(_objectSpread$3({
2519
+ rule: rule,
2520
+ schema: schema
2521
+ }, builderPreview)) : rule;
2522
+ }, [rule, schema, builderPreview]);
2523
+ var activeToken = (panelState === null || panelState === void 0 ? void 0 : panelState.data) || {};
2524
+ var isActive = function isActive(_ref2) {
2525
+ var type = _ref2.type,
2526
+ index = _ref2.index;
2527
+ return !!(panelState !== null && panelState !== void 0 && panelState.type) && activeToken.anchor === type && activeToken.index === index;
2528
+ };
2529
+ var addingAction = !!(panelState !== null && panelState !== void 0 && panelState.type) && activeToken.anchor === BUILDER_ANCHORS.ACTION_ADD && activeToken.index === rule.actions.length && !builderPreview;
2530
+ var flatErrors = react.useMemo(function () {
2531
+ return keyboardShortcuts.flatten(errors || {});
2532
+ }, [errors]);
2533
+ var _useState = react.useState(false),
2534
+ _useState2 = _slicedToArray(_useState, 2),
2535
+ flashing = _useState2[0],
2536
+ setFlashing = _useState2[1];
2537
+ var lastSubmitCount = react.useRef(submitCount);
2538
+ react.useEffect(function () {
2539
+ if (submitCount <= lastSubmitCount.current) return undefined;
2540
+ lastSubmitCount.current = submitCount;
2541
+ if (ramda.isEmpty(flatErrors) && isRuleComplete(rule) && ramda.isEmpty(invalidScopeIndexes({
2542
+ rule: rule,
2543
+ schema: schema
2544
+ }))) {
2545
+ return undefined;
2546
+ }
2547
+ setFlashing(true);
2548
+ var timer = setTimeout(function () {
2549
+ return setFlashing(false);
2550
+ }, 2200);
2551
+ return function () {
2552
+ return clearTimeout(timer);
2553
+ };
2554
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2555
+ }, [submitCount]);
2556
+ var hasErrorAt = function hasErrorAt(_ref3) {
2557
+ var prefix = _ref3.prefix,
2558
+ _ref3$exclude = _ref3.exclude,
2559
+ exclude = _ref3$exclude === void 0 ? [] : _ref3$exclude;
2560
+ return Object.keys(flatErrors).some(function (key) {
2561
+ return (key === prefix || key.startsWith("".concat(prefix, "."))) && !exclude.some(function (sub) {
2562
+ return key === "".concat(prefix, ".").concat(sub) || key.startsWith("".concat(prefix, ".").concat(sub, "."));
2563
+ });
2564
+ });
2565
+ };
2566
+ var isInvalid = function isInvalid(_ref4) {
2567
+ var _schema$actions, _schema$actions$actio, _schema$actions2, _schema$actions2$rend, _schema$actions3, _schema$actions3$rend, _schema$actions4, _schema$actions4$opti, _schema$actions5, _schema$actions5$opti;
2568
+ var type = _ref4.type,
2569
+ index = _ref4.index;
2570
+ if (!flashing) return false;
2571
+ var conditionMeta = "".concat(fieldKeys.conditions, ".value.").concat(index, ".metadata");
2572
+ var actionMeta = "".concat(fieldKeys.actions, ".value.").concat(index, ".metadata");
2573
+ // eslint-disable-next-line security/detect-object-injection
2574
+ var actionItem = rule.actions[index] || {};
2575
+ var channel = actionItem.channel || ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$actio = _schema$actions.actionForName) === null || _schema$actions$actio === void 0 || (_schema$actions$actio = _schema$actions$actio.call(_schema$actions, actionItem.name)) === null || _schema$actions$actio === void 0 ? void 0 : _schema$actions$actio.channel);
2576
+ var hasRecipientEditor = !!((_schema$actions2 = schema.actions) !== null && _schema$actions2 !== void 0 && (_schema$actions2$rend = _schema$actions2.renderRecipientEditor) !== null && _schema$actions2$rend !== void 0 && _schema$actions2$rend.call(_schema$actions2, {
2577
+ channel: channel,
2578
+ name: actionMeta,
2579
+ action: actionItem
2580
+ }));
2581
+ var hasRecipientField = !!((_schema$actions3 = schema.actions) !== null && _schema$actions3 !== void 0 && (_schema$actions3$rend = _schema$actions3.renderRecipientField) !== null && _schema$actions3$rend !== void 0 && _schema$actions3$rend.call(_schema$actions3, {
2582
+ channel: channel,
2583
+ recipient: actionItem.recipient,
2584
+ name: actionMeta,
2585
+ action: actionItem
2586
+ }));
2587
+ var flatOption = ((_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForName) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.call(_schema$actions4, actionItem.name)) || ((_schema$actions5 = schema.actions) === null || _schema$actions5 === void 0 || (_schema$actions5$opti = _schema$actions5.optionForChannel) === null || _schema$actions5$opti === void 0 ? void 0 : _schema$actions5$opti.call(_schema$actions5, channel));
2588
+ var recipientFields = [].concat(_toConsumableArray(hasRecipientEditor || hasRecipientField ? ["emails"] : []), _toConsumableArray((flatOption === null || flatOption === void 0 ? void 0 : flatOption.type) === "smsToNumbers" ? ["phoneNumbers"] : []));
2589
+ switch (type) {
2590
+ case BUILDER_ANCHORS.TRIGGER_ACTOR:
2591
+ {
2592
+ var _schema$actor;
2593
+ var actorKey = (_schema$actor = schema.actor) === null || _schema$actor === void 0 ? void 0 : _schema$actor.fieldKey;
2594
+ return !!actorKey && hasErrorAt({
2595
+ prefix: "".concat(actorKey, ".value")
2596
+ });
2597
+ }
2598
+ case BUILDER_ANCHORS.COND_FIELD:
2599
+ return hasErrorAt({
2600
+ prefix: "".concat(fieldKeys.conditions, ".value.").concat(index, ".field")
2601
+ });
2602
+ case BUILDER_ANCHORS.COND_OP_TOGGLE:
2603
+ {
2604
+ // eslint-disable-next-line security/detect-object-injection
2605
+ var condition = rule.conditions[index] || {};
2606
+ return !!condition.field && !condition.verb;
2607
+ }
2608
+ case BUILDER_ANCHORS.COND_VALUES:
2609
+ return hasErrorAt({
2610
+ prefix: conditionMeta
2611
+ });
2612
+ case BUILDER_ANCHORS.ACTION_CONFIG:
2613
+ return hasErrorAt({
2614
+ prefix: actionMeta,
2615
+ exclude: recipientFields
2616
+ });
2617
+ case BUILDER_ANCHORS.ACTION_RECIPIENT:
2618
+ return recipientFields.some(function (field) {
2619
+ return hasErrorAt({
2620
+ prefix: "".concat(actionMeta, ".").concat(field)
2621
+ });
2622
+ });
2623
+ case BUILDER_ANCHORS.ACTION_ADD:
2624
+ return !rule.actions.some(function (item) {
2625
+ return (item === null || item === void 0 ? void 0 : item.channel) || (item === null || item === void 0 ? void 0 : item.name);
2626
+ });
2627
+ case BUILDER_ANCHORS.RULE_DELAY:
2628
+ return hasErrorAt({
2629
+ prefix: "".concat(fieldKeys.delay, ".value")
2630
+ });
2631
+ case BUILDER_ANCHORS.SCOPE:
2632
+ return invalidScopeIndexes({
2633
+ rule: rule,
2634
+ schema: schema
2635
+ }).includes(index);
2636
+ case BUILDER_ANCHORS.META_NAME:
2637
+ return hasErrorAt({
2638
+ prefix: "".concat(fieldKeys.name, ".value")
2639
+ });
2640
+ default:
2641
+ return false;
2642
+ }
2643
+ };
2644
+ var closePaneIfTargeting = function closePaneIfTargeting(_ref5) {
2645
+ var anchors = _ref5.anchors,
2646
+ index = _ref5.index;
2647
+ if (panelState !== null && panelState !== void 0 && panelState.type && anchors.includes(activeToken.anchor) && activeToken.index === index) {
2648
+ closePane();
2649
+ }
2650
+ };
2651
+ var handleRemoveCondition = function handleRemoveCondition(index) {
2652
+ closePaneIfTargeting({
2653
+ anchors: CONDITION_ANCHORS,
2654
+ index: index
2655
+ });
2656
+ removeCondition(index);
2657
+ };
2658
+ var handleRemoveAction = function handleRemoveAction(index) {
2659
+ closePaneIfTargeting({
2660
+ anchors: ACTION_ANCHORS,
2661
+ index: index
2662
+ });
2663
+ removeAction(index);
2664
+ var remaining = rule.actions.filter(function (_, i) {
2665
+ return i !== index;
2666
+ });
2667
+ if (!remaining.some(function (action) {
2668
+ return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
2669
+ })) {
2670
+ setScope([]);
2671
+ }
2672
+ };
2673
+ var handleRemoveDelay = function handleRemoveDelay() {
2674
+ closePaneIfTargeting({
2675
+ anchors: [BUILDER_ANCHORS.RULE_DELAY],
2676
+ index: undefined
2677
+ });
2678
+ setDelay(null);
2679
+ };
2680
+ var isTriggerSet = hasTrigger(rule);
2681
+ var hasAction = rule.actions.some(function (action) {
2682
+ return (action === null || action === void 0 ? void 0 : action.channel) || (action === null || action === void 0 ? void 0 : action.name);
2683
+ });
2684
+ var isScopeEnabled = (schema === null || schema === void 0 || (_schema$scope = schema.scope) === null || _schema$scope === void 0 ? void 0 : _schema$scope.enabled) && isTriggerSet && hasAction;
2685
+ var isScopeComplete = !(schema !== null && schema !== void 0 && (_schema$scope2 = schema.scope) !== null && _schema$scope2 !== void 0 && _schema$scope2.enabled) || neetoCist.isNotEmpty(rule.scope || []);
2686
+ var isComplete = isRuleComplete(rule) && isScopeComplete;
2687
+ var handleRemoveScope = function handleRemoveScope(index) {
2688
+ return setScope((rule.scope || []).filter(function (_, i) {
2689
+ return i !== index;
2690
+ }));
2691
+ };
2692
+ var conditionFields = (schema === null || schema === void 0 || (_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || [];
2693
+ var canAddCondition = neetoCist.isNotEmpty(conditionFields);
2694
+ var leadTimeAppliesTo = (schema === null || schema === void 0 || (_schema$triggers = schema.triggers) === null || _schema$triggers === void 0 || (_schema$triggers = _schema$triggers.leadTime) === null || _schema$triggers === void 0 ? void 0 : _schema$triggers.appliesTo) || [];
2695
+ var hasLeadTimeTrigger = rule.triggers.some(function (trigger) {
2696
+ return leadTimeAppliesTo.includes(trigger.name);
2697
+ });
2698
+ var isDelayEnabled = (schema === null || schema === void 0 || (_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.enabled) && !hasLeadTimeTrigger;
2699
+ react.useEffect(function () {
2700
+ if (hasLeadTimeTrigger && rule.delay) setDelay(null);
2701
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2702
+ }, [hasLeadTimeTrigger, rule.delay]);
2703
+ var handleAddCondition = function handleAddCondition() {
2704
+ if (ramda.isEmpty(conditionFields)) return;
2705
+ setConditions([].concat(_toConsumableArray(rule.conditions), [{
2706
+ joinType: joinTypeFor(rule.conditionMode),
2707
+ metadata: {}
2708
+ }]));
2709
+ openPane({
2710
+ type: BUILDER_ANCHORS.COND_FIELD,
2711
+ index: rule.conditions.length
2712
+ });
2713
+ };
2714
+ var handleClearTrigger = function handleClearTrigger() {
2715
+ setTriggers([]);
2716
+ setPerformer(null);
2717
+ setConditions([]);
2718
+ setDelay(null);
2719
+ setActions([]);
2720
+ setScope([]);
2721
+ closePane();
2722
+ };
2723
+ var handleAddAction = function handleAddAction() {
2724
+ openPane({
2725
+ type: BUILDER_ANCHORS.ACTION_ADD,
2726
+ index: rule.actions.length
2727
+ });
2728
+ };
2729
+ var slotCtx = {
2730
+ rule: rule,
2731
+ schema: schema,
2732
+ openPane: openPane
2733
+ };
2734
+ var renderSlot = function renderSlot(name) {
2735
+ var _schema$slots$name, _schema$slots, _schema$slots$name2;
2736
+ return (// eslint-disable-next-line security/detect-object-injection
2737
+ (_schema$slots$name = schema === null || schema === void 0 || (_schema$slots = schema.slots) === null || _schema$slots === void 0 || (_schema$slots$name2 = _schema$slots[name]) === null || _schema$slots$name2 === void 0 ? void 0 : _schema$slots$name2.call(_schema$slots, slotCtx)) !== null && _schema$slots$name !== void 0 ? _schema$slots$name : null
2738
+ );
2739
+ };
2740
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
2741
+ className: "neeto-rules-builder",
2742
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
2743
+ className: "mb-canvas neeto-rules-main-card",
2744
+ children: [/*#__PURE__*/jsxRuntime.jsx(WhenBlock, {
2745
+ isActive: isActive,
2746
+ isInvalid: isInvalid,
2747
+ schema: schema,
2748
+ rule: displayRule,
2749
+ onClearTrigger: isTriggerSet && handleClearTrigger,
2750
+ onToken: openPane,
2751
+ onAddCondition: canAddCondition && ramda.isEmpty(displayRule.conditions) && handleAddCondition
2752
+ }), renderSlot("afterWhen"), displayRule.conditions.map(function (condition, index) {
2753
+ var _condition$id;
2754
+ return /*#__PURE__*/react.createElement(ConditionRow, {
2755
+ condition: condition,
2756
+ index: index,
2757
+ isActive: isActive,
2758
+ isInvalid: isInvalid,
2759
+ schema: schema,
2760
+ key: (_condition$id = condition.id) !== null && _condition$id !== void 0 ? _condition$id : index,
2761
+ rule: displayRule,
2762
+ onRemove: function onRemove() {
2763
+ return handleRemoveCondition(index);
2764
+ },
2765
+ onToken: openPane,
2766
+ onAddCondition: canAddCondition && index === displayRule.conditions.length - 1 && handleAddCondition
2767
+ });
2768
+ }), renderSlot("afterConditions"), /*#__PURE__*/jsxRuntime.jsx(Connector, {
2769
+ active: isTriggerSet
2770
+ }), isDelayEnabled && isTriggerSet && (rule.delay ? /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
2771
+ children: [/*#__PURE__*/jsxRuntime.jsx(DelayRow, {
2772
+ isActive: isActive,
2773
+ isInvalid: isInvalid,
2774
+ rule: rule,
2775
+ onRemove: handleRemoveDelay,
2776
+ onToken: openPane
2777
+ }), /*#__PURE__*/jsxRuntime.jsx(Connector, {
2778
+ active: true
2779
+ })]
2780
+ }) : /*#__PURE__*/jsxRuntime.jsx("div", {
2781
+ className: "mb-add-row",
2782
+ children: /*#__PURE__*/jsxRuntime.jsx(Button, {
2783
+ icon: Plus,
2784
+ iconPosition: "left",
2785
+ label: t("neetoRules.common.addDelay"),
2786
+ size: "small",
2787
+ style: "tertiary",
2788
+ onClick: function onClick() {
2789
+ return openPane({
2790
+ type: BUILDER_ANCHORS.RULE_DELAY
2791
+ });
2792
+ }
2793
+ })
2794
+ })), /*#__PURE__*/jsxRuntime.jsx(ThenBlock, {
2795
+ isActive: isActive,
2796
+ isInvalid: isInvalid,
2797
+ schema: schema,
2798
+ adding: addingAction,
2799
+ rule: displayRule,
2800
+ onAddAction: handleAddAction,
2801
+ onRemoveAction: handleRemoveAction,
2802
+ onToken: openPane
2803
+ }), renderSlot("afterActions"), isScopeEnabled && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
2804
+ children: [/*#__PURE__*/jsxRuntime.jsx(Connector, {
2805
+ active: true
2806
+ }), /*#__PURE__*/jsxRuntime.jsx(ScopeBlock, {
2807
+ isActive: isActive,
2808
+ isInvalid: isInvalid,
2809
+ schema: schema,
2810
+ rule: displayRule,
2811
+ onRemoveScope: handleRemoveScope,
2812
+ onToken: openPane
2813
+ })]
2814
+ }), isComplete && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
2815
+ children: [/*#__PURE__*/jsxRuntime.jsx(Connector, {
2816
+ active: true
2817
+ }), /*#__PURE__*/jsxRuntime.jsx(MetaBlock, {
2818
+ rule: rule,
2819
+ isInvalid: isInvalid({
2820
+ type: BUILDER_ANCHORS.META_NAME
2821
+ }),
2822
+ showName: (_schema$meta$showName = schema === null || schema === void 0 || (_schema$meta = schema.meta) === null || _schema$meta === void 0 ? void 0 : _schema$meta.showName) !== null && _schema$meta$showName !== void 0 ? _schema$meta$showName : true,
2823
+ onEditName: function onEditName() {
2824
+ return openPane({
2825
+ type: BUILDER_ANCHORS.META_NAME
2826
+ });
2827
+ },
2828
+ onToggleActive: function onToggleActive(event) {
2829
+ return setActive(event.target.checked);
2830
+ }
2831
+ })]
2832
+ })]
2833
+ })
2834
+ });
2835
+ };
2836
+
2837
+ var restoreTokens = function restoreTokens(text) {
2838
+ return text ? text.replace(/\[\[/g, "{{").replace(/\]\]/g, "}}") : text;
2839
+ };
2840
+ var ActionConfigFields = function ActionConfigFields(_ref) {
2841
+ var name = _ref.name,
2842
+ option = _ref.option,
2843
+ action = _ref.action,
2844
+ _ref$searchTerm = _ref.searchTerm,
2845
+ searchTerm = _ref$searchTerm === void 0 ? "" : _ref$searchTerm;
2846
+ var _useTranslation = reactI18next.useTranslation(),
2847
+ t = _useTranslation.t;
2848
+ var _useFormikContext = formik.useFormikContext(),
2849
+ values = _useFormikContext.values,
2850
+ setFieldValue = _useFormikContext.setFieldValue,
2851
+ setFieldTouched = _useFormikContext.setFieldTouched,
2852
+ errors = _useFormikContext.errors,
2853
+ touched = _useFormikContext.touched;
2854
+ var type = option === null || option === void 0 ? void 0 : option.type;
2855
+ var options = normalizeOptions(option === null || option === void 0 ? void 0 : option.dropdownOptions);
2856
+ var valuePath = "".concat(name, ".value");
2857
+ var fieldError = function fieldError(path) {
2858
+ return formik.getIn(touched, path) && formik.getIn(errors, path);
2859
+ };
2860
+ var term = searchTerm.trim().toLowerCase();
2861
+ var filterOptions = function filterOptions(list) {
2862
+ return term ? list.filter(function (item) {
2863
+ return String(item.label).toLowerCase().includes(term);
2864
+ }) : list;
2865
+ };
2866
+ var hint = restoreTokens(option === null || option === void 0 ? void 0 : option.dynamicValuesHint);
2867
+ var hintBlock = hint ? /*#__PURE__*/jsxRuntime.jsx(Typography, {
2868
+ className: "neeto-ui-text-gray-500",
2869
+ style: "body3",
2870
+ children: hint
2871
+ }) : null;
2872
+ var noOptionsMessage = function noOptionsMessage() {
2873
+ var noun = (option === null || option === void 0 ? void 0 : option.valueNounPlural) || (option === null || option === void 0 ? void 0 : option.valueNoun);
2874
+ return /*#__PURE__*/jsxRuntime.jsx(Typography, {
2875
+ className: "neeto-ui-text-gray-500",
2876
+ style: "body2",
2877
+ children: noun ? t("neetoRules.builder.config.noOptionsFor", {
2878
+ field: noun
2879
+ }) : t("neetoRules.builder.config.noOptions")
2880
+ });
2881
+ };
2882
+ var noMatches = /*#__PURE__*/jsxRuntime.jsx("div", {
2883
+ className: "mb-pane-empty",
2884
+ children: t("neetoRules.builder.noMatches")
2885
+ });
2886
+ if (type === "emailChannel") {
2887
+ var _getIn, _action$metadata;
2888
+ var subjectPath = "".concat(name, ".subject");
2889
+ var bodyPath = "".concat(name, ".body");
2890
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2891
+ className: "flex flex-col gap-4",
2892
+ children: [/*#__PURE__*/jsxRuntime.jsx(Input, {
2893
+ required: true,
2894
+ error: fieldError(subjectPath),
2895
+ label: t("neetoRules.builder.config.subject"),
2896
+ placeholder: t("neetoRules.builder.config.subjectPlaceholder"),
2897
+ size: "large",
2898
+ value: (_getIn = formik.getIn(values, subjectPath)) !== null && _getIn !== void 0 ? _getIn : "",
2899
+ onBlur: function onBlur() {
2900
+ return setFieldTouched(subjectPath, true);
2901
+ },
2902
+ onChange: function onChange(event) {
2903
+ return setFieldValue(subjectPath, event.target.value);
2904
+ }
2905
+ }), /*#__PURE__*/jsxRuntime.jsx(index.EditorAction, {
2906
+ required: true,
2907
+ label: t("neetoRules.builder.config.body"),
2908
+ name: bodyPath,
2909
+ placeholder: t("neetoRules.builder.config.bodyPlaceholder"),
2910
+ value: action === null || action === void 0 || (_action$metadata = action.metadata) === null || _action$metadata === void 0 ? void 0 : _action$metadata.body,
2911
+ variables: option === null || option === void 0 ? void 0 : option.variables
2912
+ }), hintBlock]
2913
+ });
2914
+ }
2915
+ if (type === "multiSelect") {
2916
+ if (ramda.isEmpty(options)) return noOptionsMessage();
2917
+ var current = formik.getIn(values, valuePath) || [];
2918
+ var filtered = filterOptions(options);
2919
+ if (term && ramda.isEmpty(filtered)) return noMatches;
2920
+ var toggle = function toggle(value) {
2921
+ setFieldTouched(valuePath, true);
2922
+ setFieldValue(valuePath, current.includes(value) ? current.filter(neetoCist.isNot(value)) : [].concat(_toConsumableArray(current), [value]));
2923
+ };
2924
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2925
+ className: "flex flex-col gap-y-1",
2926
+ children: [filtered.map(function (item) {
2927
+ return /*#__PURE__*/jsxRuntime.jsx(Checkbox, {
2928
+ checked: current.includes(item.value),
2929
+ label: item.label,
2930
+ onChange: function onChange() {
2931
+ return toggle(item.value);
2932
+ }
2933
+ }, item.value);
2934
+ }), fieldError(valuePath) && /*#__PURE__*/jsxRuntime.jsx("p", {
2935
+ className: "neeto-ui-input__error",
2936
+ children: fieldError(valuePath)
2937
+ })]
2938
+ });
2939
+ }
2940
+ if (type === "dropdown") {
2941
+ if (ramda.isEmpty(options)) return noOptionsMessage();
2942
+ var _current = formik.getIn(values, valuePath);
2943
+ var _filtered = filterOptions(options);
2944
+ if (term && ramda.isEmpty(_filtered)) return noMatches;
2945
+ return /*#__PURE__*/jsxRuntime.jsx(Radio, {
2946
+ stacked: true,
2947
+ error: fieldError(valuePath),
2948
+ value: _current !== null && _current !== void 0 ? _current : "",
2949
+ onBlur: function onBlur() {
2950
+ return setFieldTouched(valuePath, true);
2951
+ },
2952
+ onChange: function onChange(event) {
2953
+ var picked = options.find(function (item) {
2954
+ return String(item.value) === event.target.value;
2955
+ });
2956
+ setFieldValue(valuePath, picked ? picked.value : event.target.value);
2957
+ },
2958
+ children: _filtered.map(function (item) {
2959
+ return /*#__PURE__*/jsxRuntime.jsx(Radio.Item, {
2960
+ label: item.label,
2961
+ value: item.value
2962
+ }, item.value);
2963
+ })
2964
+ });
2965
+ }
2966
+ if (type === "note") {
2967
+ var _action$metadata2;
2968
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2969
+ className: "flex flex-col gap-2",
2970
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.EditorAction, {
2971
+ required: true,
2972
+ label: t("neetoRules.builder.config.note"),
2973
+ name: valuePath,
2974
+ placeholder: t("neetoRules.builder.config.bodyPlaceholder"),
2975
+ value: action === null || action === void 0 || (_action$metadata2 = action.metadata) === null || _action$metadata2 === void 0 ? void 0 : _action$metadata2.value,
2976
+ variables: option === null || option === void 0 ? void 0 : option.variables
2977
+ }), hintBlock]
2978
+ });
2979
+ }
2980
+ if (type === "textarea" || type === "number") {
2981
+ var _getIn2, _getIn3;
2982
+ return type === "number" ? /*#__PURE__*/jsxRuntime.jsx(Input, {
2983
+ required: true,
2984
+ error: fieldError(valuePath),
2985
+ label: t("neetoRules.builder.config.value"),
2986
+ size: "large",
2987
+ type: "number",
2988
+ value: (_getIn2 = formik.getIn(values, valuePath)) !== null && _getIn2 !== void 0 ? _getIn2 : "",
2989
+ onBlur: function onBlur() {
2990
+ return setFieldTouched(valuePath, true);
2991
+ },
2992
+ onChange: function onChange(event) {
2993
+ return setFieldValue(valuePath, event.target.value);
2994
+ }
2995
+ }) : /*#__PURE__*/jsxRuntime.jsx(Textarea, {
2996
+ required: true,
2997
+ error: fieldError(valuePath),
2998
+ label: t("neetoRules.builder.config.message"),
2999
+ rows: 5,
3000
+ size: "large",
3001
+ value: (_getIn3 = formik.getIn(values, valuePath)) !== null && _getIn3 !== void 0 ? _getIn3 : "",
3002
+ onBlur: function onBlur() {
3003
+ return setFieldTouched(valuePath, true);
3004
+ },
3005
+ onChange: function onChange(event) {
3006
+ return setFieldValue(valuePath, event.target.value);
3007
+ }
3008
+ });
3009
+ }
3010
+ return /*#__PURE__*/jsxRuntime.jsx(Typography, {
3011
+ style: "body2",
3012
+ children: t("neetoRules.builder.noConfig")
3013
+ });
3014
+ };
3015
+
3016
+ function _regenerator$1() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2$1(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2$1(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2$1(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2$1(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2$1(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2$1(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2$1(u), _regeneratorDefine2$1(u, o, "Generator"), _regeneratorDefine2$1(u, n, function () { return this; }), _regeneratorDefine2$1(u, "toString", function () { return "[object Generator]"; }), (_regenerator$1 = function _regenerator() { return { w: i, m: f }; })(); }
3017
+ function _regeneratorDefine2$1(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2$1 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2$1(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2$1(e, r, n, t); }
3018
+ var keysUnder = function keysUnder(_ref) {
3019
+ var obj = _ref.obj,
3020
+ prefix = _ref.prefix,
3021
+ _ref$exclude = _ref.exclude,
3022
+ exclude = _ref$exclude === void 0 ? [] : _ref$exclude;
3023
+ return Object.keys(keyboardShortcuts.flatten(obj || {})).filter(function (key) {
3024
+ return (key === prefix || key.startsWith("".concat(prefix, "."))) && !exclude.some(function (sub) {
3025
+ return key === "".concat(prefix, ".").concat(sub) || key.startsWith("".concat(prefix, ".").concat(sub, "."));
3026
+ });
3027
+ });
3028
+ };
3029
+ var usePaneValidation = function usePaneValidation(prefix) {
3030
+ var _useFormikContext = formik.useFormikContext(),
3031
+ validateForm = _useFormikContext.validateForm,
3032
+ setFieldTouched = _useFormikContext.setFieldTouched,
3033
+ errors = _useFormikContext.errors;
3034
+ var errorsRef = react.useRef(errors);
3035
+ errorsRef.current = errors;
3036
+ react.useEffect(function () {
3037
+ keysUnder({
3038
+ obj: errorsRef.current,
3039
+ prefix: prefix
3040
+ }).forEach(function (key) {
3041
+ return setFieldTouched(key, false, false);
3042
+ });
3043
+ return function () {
3044
+ keysUnder({
3045
+ obj: errorsRef.current,
3046
+ prefix: prefix
3047
+ }).forEach(function (key) {
3048
+ return setFieldTouched(key, true, false);
3049
+ });
3050
+ };
3051
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3052
+ }, [prefix]);
3053
+ var validate = /*#__PURE__*/function () {
3054
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator$1().m(function _callee() {
3055
+ var exclude,
3056
+ nextErrors,
3057
+ offending,
3058
+ _args = arguments;
3059
+ return _regenerator$1().w(function (_context) {
3060
+ while (1) switch (_context.n) {
3061
+ case 0:
3062
+ exclude = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
3063
+ _context.n = 1;
3064
+ return validateForm();
3065
+ case 1:
3066
+ nextErrors = _context.v;
3067
+ offending = keysUnder({
3068
+ obj: nextErrors,
3069
+ prefix: prefix,
3070
+ exclude: exclude
3071
+ });
3072
+ offending.forEach(function (key) {
3073
+ return setFieldTouched(key, true, false);
3074
+ });
3075
+ return _context.a(2, ramda.isEmpty(offending));
3076
+ }
3077
+ }, _callee);
3078
+ }));
3079
+ return function validate() {
3080
+ return _ref2.apply(this, arguments);
3081
+ };
3082
+ }();
3083
+ return {
3084
+ validate: validate
3085
+ };
3086
+ };
3087
+
3088
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
3089
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3090
+ var ConfigPane = function ConfigPane(_ref) {
3091
+ var _schema$actions, _schema$actions$optio, _schema$actions2, _schema$actions2$opti, _schema$actions3, _schema$actions4, _schema$actions4$opti, _hostRenderConfig;
3092
+ var schema = _ref.schema,
3093
+ index$1 = _ref.index;
3094
+ var _useTranslation = reactI18next.useTranslation(),
3095
+ t = _useTranslation.t;
3096
+ var _useRuleModel = useRuleModel(schema),
3097
+ rule = _useRuleModel.rule,
3098
+ fieldKeys = _useRuleModel.fieldKeys;
3099
+ var _useFormikContext = formik.useFormikContext(),
3100
+ setFieldValue = _useFormikContext.setFieldValue;
3101
+ var _usePaneCascade = usePaneCascade(schema),
3102
+ openType = _usePaneCascade.openType,
3103
+ closePane = _usePaneCascade.closePane;
3104
+ var bodyRef = react.useRef(null);
3105
+ var _useState = react.useState(""),
3106
+ _useState2 = _slicedToArray(_useState, 2),
3107
+ searchTerm = _useState2[0],
3108
+ setSearchTerm = _useState2[1];
3109
+
3110
+ // eslint-disable-next-line security/detect-object-injection
3111
+ var action = rule.actions[index$1] || {};
3112
+ var base = "".concat(fieldKeys.actions, ".value.").concat(index$1);
3113
+ var _actionParts = actionParts({
3114
+ schema: schema,
3115
+ action: action
3116
+ }),
3117
+ option = _actionParts.option,
3118
+ channel = _actionParts.channel,
3119
+ verb = _actionParts.verb,
3120
+ mediumLabel = _actionParts.mediumLabel,
3121
+ needsRecipient = _actionParts.needsRecipient,
3122
+ configTitle = _actionParts.configTitle,
3123
+ configSubtitle = _actionParts.configSubtitle;
3124
+ var name = "".concat(base, ".metadata");
3125
+ var flatOption = ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$optio = _schema$actions.optionForName) === null || _schema$actions$optio === void 0 ? void 0 : _schema$actions$optio.call(_schema$actions, action.name)) || ((_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$opti = _schema$actions2.optionForChannel) === null || _schema$actions2$opti === void 0 ? void 0 : _schema$actions2$opti.call(_schema$actions2, channel)) || option;
3126
+ var isSms = SMS_TYPES.includes(flatOption === null || flatOption === void 0 ? void 0 : flatOption.type);
3127
+ var disabledReason = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.isDisabled) && flatOption.disabledReason;
3128
+ var hostRenderConfig = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.renderConfig) || (flatOption === null || flatOption === void 0 ? void 0 : flatOption.component) || ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 ? void 0 : _schema$actions3.renderConfig);
3129
+ var showSearch = normalizeOptions(flatOption === null || flatOption === void 0 ? void 0 : flatOption.dropdownOptions).length >= PANE_SEARCH_THRESHOLD;
3130
+ var shouldAdvanceToRecipient = !!needsRecipient;
3131
+ var _usePaneValidation = usePaneValidation(name),
3132
+ validate = _usePaneValidation.validate;
3133
+ var channelRepName = (_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForChannel) === null || _schema$actions4$opti === void 0 || (_schema$actions4$opti = _schema$actions4$opti.call(_schema$actions4, channel)) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.value;
3134
+ var unnamedOnOpen = react.useRef(!action.name);
3135
+ react.useEffect(function () {
3136
+ if (!unnamedOnOpen.current || !channelRepName) return undefined;
3137
+ setFieldValue("".concat(base, ".name"), channelRepName);
3138
+ return function () {
3139
+ return setFieldValue("".concat(base, ".name"), "");
3140
+ };
3141
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3142
+ }, [base, channelRepName]);
3143
+ react.useEffect(function () {
3144
+ if (isSms) return undefined;
3145
+ var frame;
3146
+ var attempts = 0;
3147
+ var _focusFirst = function focusFirst() {
3148
+ var _bodyRef$current;
3149
+ var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector(CONFIG_FOCUSABLE_SELECTOR);
3150
+ if (first) {
3151
+ first.focus();
3152
+ } else if (attempts++ < 20) {
3153
+ frame = requestAnimationFrame(_focusFirst);
3154
+ }
3155
+ };
3156
+ frame = requestAnimationFrame(_focusFirst);
3157
+ return function () {
3158
+ return cancelAnimationFrame(frame);
3159
+ };
3160
+ }, [isSms, action.name]);
3161
+ var title = configTitle || mediumLabel && t("neetoRules.builder.setUpMediumLabel", {
3162
+ verb: verb || t("neetoRules.builder.setUp"),
3163
+ mediumLabel: mediumLabel
3164
+ }) || (option === null || option === void 0 ? void 0 : option.label) || t("neetoRules.builder.setUpAction");
3165
+ var handleContinue = /*#__PURE__*/function () {
3166
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
3167
+ return _regenerator().w(function (_context) {
3168
+ while (1) switch (_context.n) {
3169
+ case 0:
3170
+ _context.n = 1;
3171
+ return validate(["emails"]);
3172
+ case 1:
3173
+ if (_context.v) {
3174
+ _context.n = 2;
3175
+ break;
3176
+ }
3177
+ return _context.a(2);
3178
+ case 2:
3179
+ if (shouldAdvanceToRecipient) {
3180
+ openType({
3181
+ type: BUILDER_PANEL_TYPES.RECIPIENT,
3182
+ data: {
3183
+ index: index$1,
3184
+ anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
3185
+ }
3186
+ });
3187
+ } else {
3188
+ closePane();
3189
+ }
3190
+ case 3:
3191
+ return _context.a(2);
3192
+ }
3193
+ }, _callee);
3194
+ }));
3195
+ return function handleContinue() {
3196
+ return _ref2.apply(this, arguments);
3197
+ };
3198
+ }();
3199
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3200
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3201
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3202
+ className: "flex w-full flex-col gap-y-2",
3203
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3204
+ style: "h3",
3205
+ children: title
3206
+ }), configSubtitle && /*#__PURE__*/jsxRuntime.jsx(Typography, {
3207
+ className: "neeto-ui-text-gray-500",
3208
+ style: "body2",
3209
+ children: configSubtitle
3210
+ }), showSearch && /*#__PURE__*/jsxRuntime.jsx("div", {
3211
+ className: "mb-pane-search",
3212
+ children: /*#__PURE__*/jsxRuntime.jsx(Input, {
3213
+ placeholder: t("neetoRules.builder.searchPlaceholder"),
3214
+ prefix: /*#__PURE__*/jsxRuntime.jsx(Search, {}),
3215
+ size: "large",
3216
+ value: searchTerm,
3217
+ onChange: function onChange(event) {
3218
+ return setSearchTerm(event.target.value);
3219
+ }
3220
+ })
3221
+ })]
3222
+ })
3223
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
3224
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3225
+ ref: bodyRef,
3226
+ children: [disabledReason && /*#__PURE__*/jsxRuntime.jsx("div", {
3227
+ className: "mb-4",
3228
+ children: /*#__PURE__*/jsxRuntime.jsx(index.ErrorCallout, {
3229
+ message: disabledReason,
3230
+ selectedField: flatOption
3231
+ })
3232
+ }), isSms ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3233
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.SmsFields, {
3234
+ action: action,
3235
+ index: index$1,
3236
+ name: name,
3237
+ shouldAutoFocus: true,
3238
+ selectedField: flatOption,
3239
+ showPhoneNumberInput: false
3240
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3241
+ className: "neeto-ui-text-gray-500 mt-2",
3242
+ style: "body3",
3243
+ children: t("neetoRules.builder.config.smsSegmentHint")
3244
+ })]
3245
+ }) : (_hostRenderConfig = hostRenderConfig === null || hostRenderConfig === void 0 ? void 0 : hostRenderConfig({
3246
+ name: name,
3247
+ action: action,
3248
+ option: flatOption,
3249
+ searchTerm: searchTerm
3250
+ })) !== null && _hostRenderConfig !== void 0 ? _hostRenderConfig : /*#__PURE__*/jsxRuntime.jsx(ActionConfigFields, {
3251
+ action: action,
3252
+ name: name,
3253
+ searchTerm: searchTerm,
3254
+ option: flatOption
3255
+ })]
3256
+ })
3257
+ }), shouldAdvanceToRecipient && /*#__PURE__*/jsxRuntime.jsx(index.Panel.Footer, {
3258
+ children: /*#__PURE__*/jsxRuntime.jsx(Button, {
3259
+ label: t("neetoRules.buttons.continue"),
3260
+ size: "large",
3261
+ onClick: handleContinue
3262
+ })
3263
+ })]
3264
+ });
3265
+ };
3266
+
3267
+ var DelayPane = function DelayPane(_ref) {
3268
+ var _schema$delay;
3269
+ var schema = _ref.schema;
3270
+ var _useTranslation = reactI18next.useTranslation(),
3271
+ t = _useTranslation.t;
3272
+ var _useRuleModel = useRuleModel(schema),
3273
+ fieldKeys = _useRuleModel.fieldKeys;
3274
+ var _useFormikContext = formik.useFormikContext(),
3275
+ setFieldValue = _useFormikContext.setFieldValue;
3276
+ var bodyRef = react.useRef(null);
3277
+ var name = fieldKeys.delay;
3278
+ var _useField = formik.useField("".concat(name, ".value")),
3279
+ _useField2 = _slicedToArray(_useField, 1),
3280
+ value = _useField2[0].value;
3281
+ var units = normalizeOptions((_schema$delay = schema.delay) === null || _schema$delay === void 0 ? void 0 : _schema$delay.units);
3282
+ var unitOptions = neetoCist.isNotEmpty(units) ? units : DEFAULT_DELAY_UNITS;
3283
+ usePaneValidation("".concat(name, ".value"));
3284
+ react.useEffect(function () {
3285
+ if (ramda.isEmpty(value || {})) {
3286
+ var _unitOptions$0$value, _unitOptions$;
3287
+ setFieldValue("".concat(name, ".value"), {
3288
+ value: 10,
3289
+ unit: (_unitOptions$0$value = (_unitOptions$ = unitOptions[0]) === null || _unitOptions$ === void 0 ? void 0 : _unitOptions$.value) !== null && _unitOptions$0$value !== void 0 ? _unitOptions$0$value : "minutes"
3290
+ });
3291
+ }
3292
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3293
+ }, []);
3294
+ react.useEffect(function () {
3295
+ var _bodyRef$current;
3296
+ var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector("input");
3297
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
3298
+ if (first) setTimeout(function () {
3299
+ return first.focus();
3300
+ }, 0);
3301
+ }, []);
3302
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3303
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3304
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3305
+ className: "flex flex-col gap-y-1",
3306
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3307
+ style: "h3",
3308
+ children: t("neetoRules.common.addDelay")
3309
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3310
+ className: "neeto-ui-text-gray-500",
3311
+ style: "body2",
3312
+ children: t("neetoRules.helpText.addDelay")
3313
+ })]
3314
+ })
3315
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
3316
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3317
+ className: "flex flex-col gap-y-1.5",
3318
+ ref: bodyRef,
3319
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3320
+ className: "neeto-ui-text-gray-800",
3321
+ style: "body2",
3322
+ weight: "medium",
3323
+ children: t("neetoRules.builder.waitFor")
3324
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
3325
+ className: "flex items-start gap-x-2",
3326
+ children: [/*#__PURE__*/jsxRuntime.jsx(Input$1, {
3327
+ className: "w-44",
3328
+ max: 999,
3329
+ min: 1,
3330
+ name: "".concat(name, ".value.value"),
3331
+ placeholder: t("neetoRules.placeholders.enterDelay"),
3332
+ size: "large",
3333
+ type: "number"
3334
+ }), /*#__PURE__*/jsxRuntime.jsx(Select, {
3335
+ defaultValue: neetoCist.findBy({
3336
+ value: value === null || value === void 0 ? void 0 : value.unit
3337
+ }, unitOptions),
3338
+ menuPosition: "fixed",
3339
+ name: "".concat(name, ".value.unit"),
3340
+ options: unitOptions,
3341
+ size: "large",
3342
+ onChange: function onChange(option) {
3343
+ return setFieldValue("".concat(name, ".value.unit"), option === null || option === void 0 ? void 0 : option.value);
3344
+ }
3345
+ })]
3346
+ })]
3347
+ })
3348
+ })]
3349
+ });
3350
+ };
3351
+
3352
+ var toNumber = function toNumber(value) {
3353
+ return value === "" || ramda.isNil(value) ? null : Number(value);
3354
+ };
3355
+ var clamp = function clamp(_ref) {
3356
+ var value = _ref.value,
3357
+ min = _ref.min,
3358
+ max = _ref.max;
3359
+ var next = value;
3360
+ if (!ramda.isNil(min)) next = Math.max(min, next);
3361
+ if (!ramda.isNil(max)) next = Math.min(max, next);
3362
+ return next;
3363
+ };
3364
+ var asText = function asText(value) {
3365
+ return value === "" || ramda.isNil(value) ? "" : String(value);
3366
+ };
3367
+
3368
+ var NumberStepper = function NumberStepper(_ref) {
3369
+ var value = _ref.value,
3370
+ onChange = _ref.onChange,
3371
+ label = _ref.label,
3372
+ _ref$min = _ref.min,
3373
+ min = _ref$min === void 0 ? 1 : _ref$min,
3374
+ max = _ref.max,
3375
+ required = _ref.required;
3376
+ var _useTranslation = reactI18next.useTranslation(),
3377
+ t = _useTranslation.t;
3378
+ var _useState = react.useState(null),
3379
+ _useState2 = _slicedToArray(_useState, 2),
3380
+ draft = _useState2[0],
3381
+ setDraft = _useState2[1];
3382
+ var display = draft !== null && draft !== void 0 ? draft : asText(value);
3383
+ var commit = function commit(raw) {
3384
+ setDraft(raw);
3385
+ onChange(raw === "" ? min !== null && min !== void 0 ? min : 0 : clamp({
3386
+ value: Number(raw),
3387
+ min: min,
3388
+ max: max
3389
+ }));
3390
+ };
3391
+ var step = function step(delta) {
3392
+ setDraft(null);
3393
+ var base = Number.isFinite(toNumber(value)) ? toNumber(value) : min !== null && min !== void 0 ? min : 0;
3394
+ onChange(clamp({
3395
+ value: base + delta,
3396
+ min: min,
3397
+ max: max
3398
+ }));
3399
+ };
3400
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
3401
+ className: "mb-stepper",
3402
+ children: [/*#__PURE__*/jsxRuntime.jsx(Input, {
3403
+ label: label,
3404
+ min: min,
3405
+ required: required,
3406
+ autoFocus: true,
3407
+ type: "number",
3408
+ value: display,
3409
+ onBlur: function onBlur() {
3410
+ return setDraft(null);
3411
+ },
3412
+ onChange: function onChange(event) {
3413
+ return commit(event.target.value);
3414
+ },
3415
+ onFocus: function onFocus(event) {
3416
+ return event.target.select();
3417
+ }
3418
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
3419
+ className: "mb-stepper-controls",
3420
+ children: [/*#__PURE__*/jsxRuntime.jsx("button", {
3421
+ "aria-label": t("neetoRules.builder.aria.increase"),
3422
+ className: "mb-stepper-btn",
3423
+ tabIndex: -1,
3424
+ type: "button",
3425
+ onClick: function onClick() {
3426
+ return step(1);
3427
+ },
3428
+ children: /*#__PURE__*/jsxRuntime.jsx(Up, {})
3429
+ }), /*#__PURE__*/jsxRuntime.jsx("button", {
3430
+ "aria-label": t("neetoRules.builder.aria.decrease"),
3431
+ className: "mb-stepper-btn",
3432
+ tabIndex: -1,
3433
+ type: "button",
3434
+ onClick: function onClick() {
3435
+ return step(-1);
3436
+ },
3437
+ children: /*#__PURE__*/jsxRuntime.jsx(Down, {})
3438
+ })]
3439
+ })]
3440
+ });
3441
+ };
3442
+
3443
+ var LeadTimePane = function LeadTimePane(_ref) {
3444
+ var schema = _ref.schema;
3445
+ var _useTranslation = reactI18next.useTranslation(),
3446
+ t = _useTranslation.t;
3447
+ var _useFormikContext = formik.useFormikContext(),
3448
+ setFieldValue = _useFormikContext.setFieldValue;
3449
+ var _useRuleModel = useRuleModel(schema),
3450
+ rule = _useRuleModel.rule,
3451
+ fieldKeys = _useRuleModel.fieldKeys;
3452
+ var _minutesToParts = minutesToParts(rule.leadTime),
3453
+ amount = _minutesToParts.value,
3454
+ unit = _minutesToParts.unit;
3455
+ var path = "".concat(fieldKeys.leadTime, ".value");
3456
+ var update = function update(_ref2) {
3457
+ var value = _ref2.value,
3458
+ nextUnit = _ref2.unit;
3459
+ return setFieldValue(path, partsToMinutes({
3460
+ value: value,
3461
+ unit: nextUnit
3462
+ }));
3463
+ };
3464
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3465
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3466
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3467
+ className: "flex flex-col gap-y-1",
3468
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3469
+ style: "h3",
3470
+ children: t("neetoRules.builder.leadTimeTitle")
3471
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3472
+ className: "neeto-ui-text-gray-500",
3473
+ style: "body2",
3474
+ children: t("neetoRules.builder.leadTimeSubtitle")
3475
+ })]
3476
+ })
3477
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
3478
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3479
+ className: "flex items-end gap-x-3",
3480
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
3481
+ className: "flex-1",
3482
+ children: /*#__PURE__*/jsxRuntime.jsx(NumberStepper, {
3483
+ label: t("neetoRules.builder.before"),
3484
+ value: amount,
3485
+ onChange: function onChange(value) {
3486
+ return update({
3487
+ value: value === "" ? 0 : value,
3488
+ unit: unit
3489
+ });
3490
+ }
3491
+ })
3492
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
3493
+ className: "w-32 shrink-0",
3494
+ children: /*#__PURE__*/jsxRuntime.jsx(Select$1, {
3495
+ isSearchable: false,
3496
+ options: LEAD_TIME_UNITS,
3497
+ value: neetoCist.findBy({
3498
+ value: unit
3499
+ }, LEAD_TIME_UNITS) || null,
3500
+ onChange: function onChange(option) {
3501
+ return update({
3502
+ value: amount,
3503
+ unit: option === null || option === void 0 ? void 0 : option.value
3504
+ });
3505
+ }
3506
+ })
3507
+ })]
3508
+ })
3509
+ })]
3510
+ });
3511
+ };
3512
+
3513
+ var NamePane = function NamePane(_ref) {
3514
+ var schema = _ref.schema;
3515
+ var _useTranslation = reactI18next.useTranslation(),
3516
+ t = _useTranslation.t;
3517
+ var _useRuleModel = useRuleModel(schema),
3518
+ fieldKeys = _useRuleModel.fieldKeys;
3519
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3520
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3521
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3522
+ className: "flex flex-col gap-y-1",
3523
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3524
+ style: "h3",
3525
+ children: t("neetoRules.builder.automationName")
3526
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3527
+ className: "neeto-ui-text-gray-500",
3528
+ style: "body2",
3529
+ children: t("neetoRules.builder.nameSubtitle")
3530
+ })]
3531
+ })
3532
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
3533
+ children: /*#__PURE__*/jsxRuntime.jsx(Input$1, {
3534
+ autoFocus: true,
3535
+ required: true,
3536
+ label: t("neetoRules.common.name"),
3537
+ name: "".concat(fieldKeys.name, ".value"),
3538
+ placeholder: t("neetoRules.builder.nameYourAutomation"),
3539
+ size: "large"
3540
+ })
3541
+ })]
3542
+ });
3543
+ };
3544
+
3545
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3546
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3547
+ var OptionsPane = function OptionsPane(_ref) {
3548
+ var schema = _ref.schema,
3549
+ anchor = _ref.anchor,
3550
+ index$1 = _ref.index,
3551
+ _ref$belowContent = _ref.belowContent,
3552
+ belowContent = _ref$belowContent === void 0 ? null : _ref$belowContent;
3553
+ var _useTranslation = reactI18next.useTranslation(),
3554
+ t = _useTranslation.t;
3555
+ var _useFormikContext = formik.useFormikContext(),
3556
+ setFieldValue = _useFormikContext.setFieldValue;
3557
+ var _useRuleModel = useRuleModel(schema),
3558
+ rule = _useRuleModel.rule,
3559
+ fieldKeys = _useRuleModel.fieldKeys,
3560
+ setTriggers = _useRuleModel.setTriggers,
3561
+ setPerformer = _useRuleModel.setPerformer,
3562
+ setConditionMode = _useRuleModel.setConditionMode;
3563
+ var _usePaneCascade = usePaneCascade(schema),
3564
+ openType = _usePaneCascade.openType,
3565
+ closePane = _usePaneCascade.closePane;
3566
+ var _useUtilityStore = useUtilityStore.useUtilityStore(shallow.useShallow(function (store) {
3567
+ return {
3568
+ setBuilderPreview: store["setBuilderPreview"]
3569
+ };
3570
+ })),
3571
+ setBuilderPreview = _useUtilityStore.setBuilderPreview;
3572
+ var _useState = react.useState(""),
3573
+ _useState2 = _slicedToArray(_useState, 2),
3574
+ searchTerm = _useState2[0],
3575
+ setSearchTerm = _useState2[1];
3576
+ var searchRef = react.useRef(null);
3577
+
3578
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3579
+ react.useEffect(function () {
3580
+ return function () {
3581
+ return setBuilderPreview(null);
3582
+ };
3583
+ }, []);
3584
+ react.useEffect(function () {
3585
+ var _searchRef$current;
3586
+ (_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 || (_searchRef$current = _searchRef$current.querySelector("input")) === null || _searchRef$current === void 0 || _searchRef$current.focus();
3587
+ }, []);
3588
+ var _useMemo = react.useMemo(function () {
3589
+ return descriptorFor({
3590
+ anchor: anchor,
3591
+ schema: schema,
3592
+ rule: rule,
3593
+ index: index$1
3594
+ });
3595
+ }, [anchor, schema, rule, index$1]),
3596
+ title = _useMemo.title,
3597
+ subtitle = _useMemo.subtitle,
3598
+ multi = _useMemo.multi,
3599
+ options = _useMemo.options,
3600
+ selectedValues = _useMemo.selectedValues,
3601
+ cascade = _useMemo.cascade;
3602
+ var helpers = {
3603
+ setTriggers: setTriggers,
3604
+ setPerformer: setPerformer,
3605
+ setConditionMode: setConditionMode,
3606
+ setFieldValue: setFieldValue,
3607
+ fieldKeys: fieldKeys
3608
+ };
3609
+ var showSearch = (schema === null || schema === void 0 ? void 0 : schema.searchable) !== false && options.length >= PANE_SEARCH_THRESHOLD;
3610
+ var term = searchTerm.trim().toLowerCase();
3611
+ var filtered = react.useMemo(function () {
3612
+ return term ? options.filter(function (option) {
3613
+ return option.label.toLowerCase().includes(term);
3614
+ }) : options;
3615
+ }, [options, term]);
3616
+ var groups = react.useMemo(function () {
3617
+ return groupByCategory(filtered);
3618
+ }, [filtered]);
3619
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
3620
+ var isSelected = function isSelected(value) {
3621
+ return selectedValues.includes(value);
3622
+ };
3623
+ var handleSelect = function handleSelect(value) {
3624
+ setBuilderPreview(null);
3625
+ var result = commitFor({
3626
+ anchor: anchor,
3627
+ schema: schema,
3628
+ rule: rule,
3629
+ index: index$1,
3630
+ value: value,
3631
+ helpers: helpers
3632
+ });
3633
+ if (result === "close") closePane();
3634
+ };
3635
+ var multiCandidate = function multiCandidate(optionValue) {
3636
+ return selectedValues.includes(optionValue) ? selectedValues.filter(neetoCist.isNot(optionValue)) : [].concat(_toConsumableArray(selectedValues.filter(Boolean)), [optionValue]);
3637
+ };
3638
+ var previewHandlers = function previewHandlers(optionValue) {
3639
+ var value = multi ? multiCandidate(optionValue) : optionValue;
3640
+ return {
3641
+ onMouseEnter: function onMouseEnter() {
3642
+ return setBuilderPreview({
3643
+ anchor: anchor,
3644
+ index: index$1,
3645
+ value: value
3646
+ });
3647
+ },
3648
+ onMouseLeave: function onMouseLeave() {
3649
+ return setBuilderPreview(null);
3650
+ }
3651
+ };
3652
+ };
3653
+ var handleContinue = function handleContinue() {
3654
+ var target = continueTargetFor({
3655
+ anchor: anchor,
3656
+ schema: schema,
3657
+ rule: rule,
3658
+ index: index$1
3659
+ });
3660
+ if (target) openType({
3661
+ type: target.type,
3662
+ data: target.data
3663
+ });else closePane();
3664
+ };
3665
+ var optionLabel = function optionLabel(option) {
3666
+ var Icon = option.icon;
3667
+ if (!Icon && !option.disabledReason) return option.label;
3668
+ return /*#__PURE__*/jsxRuntime.jsxs("span", {
3669
+ className: "mb-pane-option",
3670
+ children: [Icon && /*#__PURE__*/jsxRuntime.jsx(Icon, {
3671
+ size: 20
3672
+ }), option.label, option.disabledReason && (option.disabledTooltip ? /*#__PURE__*/jsxRuntime.jsx(Tooltip, {
3673
+ content: option.disabledTooltip,
3674
+ position: "top",
3675
+ children: /*#__PURE__*/jsxRuntime.jsx("span", {
3676
+ className: "mb-pane-warn",
3677
+ children: option.disabledReason
3678
+ })
3679
+ }) : /*#__PURE__*/jsxRuntime.jsx("span", {
3680
+ className: "mb-pane-warn",
3681
+ children: option.disabledReason
3682
+ }))]
3683
+ });
3684
+ };
3685
+ var renderGroupHeader = function renderGroupHeader(category) {
3686
+ return category && /*#__PURE__*/jsxRuntime.jsx("div", {
3687
+ className: "mb-pane-group",
3688
+ children: category
3689
+ });
3690
+ };
3691
+ var renderBody = function renderBody() {
3692
+ var _selectedValues$;
3693
+ if (ramda.isEmpty(filtered)) {
3694
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
3695
+ className: "mb-pane-empty",
3696
+ children: t("neetoRules.builder.noMatches")
3697
+ });
3698
+ }
3699
+ if (multi) {
3700
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
3701
+ className: "flex flex-col",
3702
+ children: groups.map(function (_ref2) {
3703
+ var _ref3 = _slicedToArray(_ref2, 2),
3704
+ category = _ref3[0],
3705
+ items = _ref3[1];
3706
+ return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
3707
+ children: [renderGroupHeader(category), items.map(function (option) {
3708
+ return /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$2(_objectSpread$2({
3709
+ checked: isSelected(option.value),
3710
+ disabled: option.disabled,
3711
+ label: optionLabel(option),
3712
+ labelProps: previewHandlers(option.value),
3713
+ onChange: function onChange() {
3714
+ return handleSelect(option.value);
3715
+ }
3716
+ }, option.icon || option.disabledReason ? {
3717
+ dataTestid: option.value
3718
+ } : {}), previewHandlers(option.value)), option.value);
3719
+ })]
3720
+ }, category || "_uncategorized");
3721
+ })
3722
+ });
3723
+ }
3724
+ return /*#__PURE__*/jsxRuntime.jsx(Radio, {
3725
+ stacked: true,
3726
+ value: (_selectedValues$ = selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues[0]) !== null && _selectedValues$ !== void 0 ? _selectedValues$ : "",
3727
+ onChange: function onChange(event) {
3728
+ return handleSelect(event.target.value);
3729
+ },
3730
+ children: groups.flatMap(function (_ref4) {
3731
+ var _ref5 = _slicedToArray(_ref4, 2),
3732
+ category = _ref5[0],
3733
+ items = _ref5[1];
3734
+ return [category ? /*#__PURE__*/jsxRuntime.jsx("div", {
3735
+ className: "mb-pane-group",
3736
+ children: category
3737
+ }, "group-".concat(category)) : null].concat(_toConsumableArray(items.map(function (option) {
3738
+ return /*#__PURE__*/jsxRuntime.jsx(Radio.Item, _objectSpread$2(_objectSpread$2({
3739
+ disabled: option.disabled,
3740
+ label: optionLabel(option),
3741
+ labelProps: previewHandlers(option.value),
3742
+ value: option.value
3743
+ }, option.icon || option.disabledReason ? {
3744
+ dataTestid: option.value
3745
+ } : {}), previewHandlers(option.value)), option.value);
3746
+ })));
3747
+ }).filter(Boolean)
3748
+ });
3749
+ };
3750
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3751
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3752
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3753
+ className: "flex w-full flex-col gap-y-2",
3754
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3755
+ style: "h3",
3756
+ children: title
3757
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3758
+ className: "neeto-ui-text-gray-500",
3759
+ style: "body2",
3760
+ children: subtitle
3761
+ }), showSearch && /*#__PURE__*/jsxRuntime.jsx("div", {
3762
+ className: "mb-pane-search",
3763
+ ref: searchRef,
3764
+ children: /*#__PURE__*/jsxRuntime.jsx(Input, {
3765
+ placeholder: t("neetoRules.builder.searchPlaceholder"),
3766
+ prefix: /*#__PURE__*/jsxRuntime.jsx(Search, {}),
3767
+ size: "large",
3768
+ value: searchTerm,
3769
+ onChange: function onChange(event) {
3770
+ return setSearchTerm(event.target.value);
3771
+ }
3772
+ })
3773
+ })]
3774
+ })
3775
+ }), /*#__PURE__*/jsxRuntime.jsxs(index.Panel.Body, {
3776
+ children: [renderBody(), belowContent]
3777
+ }), cascade && /*#__PURE__*/jsxRuntime.jsx(index.Panel.Footer, {
3778
+ children: /*#__PURE__*/jsxRuntime.jsx(Button, {
3779
+ disabled: !selectedValues.some(Boolean),
3780
+ label: t("neetoRules.buttons.continue"),
3781
+ size: "large",
3782
+ onClick: handleContinue
3783
+ })
3784
+ })]
3785
+ });
3786
+ };
3787
+
3788
+ var RecipientField = function RecipientField(_ref) {
3789
+ var field = _ref.field,
3790
+ name = _ref.name,
3791
+ dropdownOptions = _ref.dropdownOptions,
3792
+ placeholder = _ref.placeholder;
3793
+ var _useTranslation = reactI18next.useTranslation(),
3794
+ t = _useTranslation.t;
3795
+ var _useFormikContext = formik.useFormikContext(),
3796
+ values = _useFormikContext.values,
3797
+ setFieldValue = _useFormikContext.setFieldValue,
3798
+ setFieldTouched = _useFormikContext.setFieldTouched,
3799
+ errors = _useFormikContext.errors,
3800
+ touched = _useFormikContext.touched;
3801
+ var fieldError = function fieldError(path) {
3802
+ return formik.getIn(touched, path) && formik.getIn(errors, path);
3803
+ };
3804
+ if (field === "emails") {
3805
+ var _path = "".concat(name, ".emails");
3806
+ var _current = formik.getIn(values, _path) || [];
3807
+ return /*#__PURE__*/jsxRuntime.jsx(MultiEmailInput, {
3808
+ required: true,
3809
+ error: fieldError(_path),
3810
+ label: t("neetoRules.builder.config.emailAddresses"),
3811
+ placeholder: t("neetoRules.builder.config.emailPlaceholder"),
3812
+ size: "large",
3813
+ value: _current.map(function (email) {
3814
+ return {
3815
+ label: email,
3816
+ value: email,
3817
+ valid: true
3818
+ };
3819
+ }),
3820
+ onBlur: function onBlur() {
3821
+ return setFieldTouched(_path, true);
3822
+ },
3823
+ onChange: function onChange(items) {
3824
+ return setFieldValue(_path, ramda.pluck("value", items || []));
3825
+ }
3826
+ });
3827
+ }
3828
+ var path = "".concat(name, ".value");
3829
+ var current = formik.getIn(values, path);
3830
+ var options = normalizeOptions(dropdownOptions);
3831
+ return /*#__PURE__*/jsxRuntime.jsx(Select$1, {
3832
+ options: options,
3833
+ placeholder: placeholder,
3834
+ required: true,
3835
+ error: fieldError(path),
3836
+ label: t("neetoRules.builder.config.recipient"),
3837
+ size: "large",
3838
+ value: neetoCist.findBy({
3839
+ value: current
3840
+ }, options) || null,
3841
+ onBlur: function onBlur() {
3842
+ return setFieldTouched(path, true);
3843
+ },
3844
+ onChange: function onChange(option) {
3845
+ return setFieldValue(path, option === null || option === void 0 ? void 0 : option.value);
3846
+ }
3847
+ });
3848
+ };
3849
+
3850
+ var RecipientPane = function RecipientPane(_ref) {
3851
+ var _schema$actions, _schema$actions$actio, _schema$actions2, _schema$actions2$rend, _schema$actions3, _schema$actions3$opti, _schema$actions4, _schema$actions4$opti, _schema$actions5, _schema$actions6, _schema$actions$rende, _schema$actions7, _schema$actions7$rend, _action$metadata, _schema$actions8;
3852
+ var schema = _ref.schema,
3853
+ index$1 = _ref.index;
3854
+ var _useTranslation = reactI18next.useTranslation(),
3855
+ t = _useTranslation.t;
3856
+ var _useRuleModel = useRuleModel(schema),
3857
+ rule = _useRuleModel.rule,
3858
+ fieldKeys = _useRuleModel.fieldKeys;
3859
+ var bodyRef = react.useRef(null);
3860
+ var belowRef = react.useRef(null);
3861
+
3862
+ // eslint-disable-next-line security/detect-object-injection
3863
+ var action = rule.actions[index$1] || {};
3864
+ var channel = action.channel || ((_schema$actions = schema.actions) === null || _schema$actions === void 0 || (_schema$actions$actio = _schema$actions.actionForName) === null || _schema$actions$actio === void 0 || (_schema$actions$actio = _schema$actions$actio.call(_schema$actions, action.name)) === null || _schema$actions$actio === void 0 ? void 0 : _schema$actions$actio.channel);
3865
+ var name = "".concat(fieldKeys.actions, ".value.").concat(index$1, ".metadata");
3866
+ var editor = (_schema$actions2 = schema.actions) === null || _schema$actions2 === void 0 || (_schema$actions2$rend = _schema$actions2.renderRecipientEditor) === null || _schema$actions2$rend === void 0 ? void 0 : _schema$actions2$rend.call(_schema$actions2, {
3867
+ channel: channel,
3868
+ name: name,
3869
+ action: action
3870
+ });
3871
+ var flatOption = ((_schema$actions3 = schema.actions) === null || _schema$actions3 === void 0 || (_schema$actions3$opti = _schema$actions3.optionForName) === null || _schema$actions3$opti === void 0 ? void 0 : _schema$actions3$opti.call(_schema$actions3, action.name)) || ((_schema$actions4 = schema.actions) === null || _schema$actions4 === void 0 || (_schema$actions4$opti = _schema$actions4.optionForChannel) === null || _schema$actions4$opti === void 0 ? void 0 : _schema$actions4$opti.call(_schema$actions4, channel));
3872
+ var isSmsToNumbers = (flatOption === null || flatOption === void 0 ? void 0 : flatOption.type) === SMS_TO_NUMBERS;
3873
+ var recipientFieldPath = isSmsToNumbers ? "".concat(name, ".phoneNumbers") : "".concat(name, ".emails");
3874
+ usePaneValidation(recipientFieldPath);
3875
+ react.useEffect(function () {
3876
+ var _bodyRef$current;
3877
+ if (!editor) return;
3878
+ var first = (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.querySelector(RECIPIENT_FOCUSABLE_SELECTOR);
3879
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference
3880
+ if (first) setTimeout(function () {
3881
+ return first.focus();
3882
+ }, 0);
3883
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3884
+ }, [!editor]);
3885
+ var recipientConfig = (((_schema$actions5 = schema.actions) === null || _schema$actions5 === void 0 ? void 0 : _schema$actions5.options) || []).flatMap(function (option) {
3886
+ return option.recipients || [];
3887
+ }).concat(((_schema$actions6 = schema.actions) === null || _schema$actions6 === void 0 ? void 0 : _schema$actions6.recipients) || []).find(function (item) {
3888
+ var _item$value;
3889
+ return ((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item.id) === action.recipient;
3890
+ });
3891
+ var builtInRecipientField = recipientConfig !== null && recipientConfig !== void 0 && recipientConfig.field ? /*#__PURE__*/jsxRuntime.jsx(RecipientField, {
3892
+ name: name,
3893
+ dropdownOptions: recipientConfig.dropdownOptions,
3894
+ field: recipientConfig.field,
3895
+ placeholder: recipientConfig.placeholder
3896
+ }) : null;
3897
+ var recipientField = (_schema$actions$rende = (_schema$actions7 = schema.actions) === null || _schema$actions7 === void 0 || (_schema$actions7$rend = _schema$actions7.renderRecipientField) === null || _schema$actions7$rend === void 0 ? void 0 : _schema$actions7$rend.call(_schema$actions7, {
3898
+ channel: channel,
3899
+ recipient: action.recipient,
3900
+ name: name,
3901
+ action: action
3902
+ })) !== null && _schema$actions$rende !== void 0 ? _schema$actions$rende : builtInRecipientField;
3903
+ var phoneField = isSmsToNumbers ? /*#__PURE__*/jsxRuntime.jsx(index.PhoneNumberField, {
3904
+ name: "".concat(name, ".phoneNumbers"),
3905
+ phoneNumbers: (_action$metadata = action.metadata) === null || _action$metadata === void 0 ? void 0 : _action$metadata.phoneNumbers
3906
+ }) : null;
3907
+ var belowField = phoneField || recipientField;
3908
+ var belowContent = belowField ? /*#__PURE__*/jsxRuntime.jsx("div", {
3909
+ className: "mt-5",
3910
+ ref: belowRef,
3911
+ children: belowField
3912
+ }) : null;
3913
+ react.useEffect(function () {
3914
+ if (!belowField) return undefined;
3915
+ var timer = setTimeout(function () {
3916
+ var _belowRef$current;
3917
+ return (_belowRef$current = belowRef.current) === null || _belowRef$current === void 0 || (_belowRef$current = _belowRef$current.querySelector(RECIPIENT_FOCUSABLE_SELECTOR)) === null || _belowRef$current === void 0 ? void 0 : _belowRef$current.focus();
3918
+ }, 0);
3919
+ return function () {
3920
+ return clearTimeout(timer);
3921
+ };
3922
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3923
+ }, [!!belowField]);
3924
+ if (!editor) {
3925
+ return /*#__PURE__*/jsxRuntime.jsx(OptionsPane, {
3926
+ belowContent: belowContent,
3927
+ index: index$1,
3928
+ schema: schema,
3929
+ anchor: BUILDER_ANCHORS.ACTION_RECIPIENT
3930
+ });
3931
+ }
3932
+
3933
+ // eslint-disable-next-line security/detect-object-injection
3934
+ var meta = ((_schema$actions8 = schema.actions) === null || _schema$actions8 === void 0 || (_schema$actions8 = _schema$actions8.channelMeta) === null || _schema$actions8 === void 0 ? void 0 : _schema$actions8[channel]) || {};
3935
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
3936
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
3937
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3938
+ className: "flex w-full flex-col gap-y-2",
3939
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
3940
+ style: "h3",
3941
+ children: meta.recipientTitle || t("neetoRules.builder.panes.recipientTitle")
3942
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
3943
+ className: "neeto-ui-text-gray-500",
3944
+ style: "body2",
3945
+ children: meta.recipientSubtitle || t("neetoRules.builder.panes.recipientSubtitle")
3946
+ })]
3947
+ })
3948
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
3949
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
3950
+ ref: bodyRef,
3951
+ children: editor
3952
+ })
3953
+ })]
3954
+ });
3955
+ };
3956
+
3957
+ var ConditionValueFields = function ConditionValueFields(_ref) {
3958
+ var name = _ref.name,
3959
+ field = _ref.field,
3960
+ _ref$searchTerm = _ref.searchTerm,
3961
+ searchTerm = _ref$searchTerm === void 0 ? "" : _ref$searchTerm;
3962
+ var _useTranslation = reactI18next.useTranslation(),
3963
+ t = _useTranslation.t;
3964
+ var _useFormikContext = formik.useFormikContext(),
3965
+ values = _useFormikContext.values,
3966
+ setFieldValue = _useFormikContext.setFieldValue,
3967
+ setFieldTouched = _useFormikContext.setFieldTouched,
3968
+ errors = _useFormikContext.errors,
3969
+ touched = _useFormikContext.touched;
3970
+ var type = field === null || field === void 0 ? void 0 : field.type;
3971
+ var valueType = (field === null || field === void 0 ? void 0 : field.valueType) || type;
3972
+ var valuePath = "".concat(name, ".metadata.value");
3973
+ var valuesPath = "".concat(name, ".metadata.values");
3974
+ var enumOptions = normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options));
3975
+ var fieldError = function fieldError(path) {
3976
+ return formik.getIn(touched, path) && formik.getIn(errors, path);
3977
+ };
3978
+ var term = searchTerm.trim().toLowerCase();
3979
+ var filterOptions = function filterOptions(list) {
3980
+ return term ? list.filter(function (option) {
3981
+ return String(option.label).toLowerCase().includes(term);
3982
+ }) : list;
3983
+ };
3984
+ var noMatches = /*#__PURE__*/jsxRuntime.jsx("div", {
3985
+ className: "mb-pane-empty",
3986
+ children: t("neetoRules.builder.noMatches")
3987
+ });
3988
+ if (type === "multi-select" && neetoCist.isNotEmpty(enumOptions)) {
3989
+ var current = formik.getIn(values, valuesPath) || [];
3990
+ var filtered = filterOptions(enumOptions);
3991
+ if (term && ramda.isEmpty(filtered)) return noMatches;
3992
+ var toggle = function toggle(value) {
3993
+ setFieldTouched(valuesPath, true);
3994
+ setFieldValue(valuesPath, current.includes(value) ? current.filter(neetoCist.isNot(value)) : [].concat(_toConsumableArray(current), [value]));
3995
+ };
3996
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
3997
+ className: "flex flex-col gap-y-1",
3998
+ children: [filtered.map(function (option) {
3999
+ return /*#__PURE__*/jsxRuntime.jsx(Checkbox, {
4000
+ checked: current.includes(option.value),
4001
+ label: option.label,
4002
+ onChange: function onChange() {
4003
+ return toggle(option.value);
4004
+ }
4005
+ }, option.value);
4006
+ }), fieldError(valuesPath) && /*#__PURE__*/jsxRuntime.jsx("p", {
4007
+ className: "neeto-ui-input__error",
4008
+ children: fieldError(valuesPath)
4009
+ })]
4010
+ });
4011
+ }
4012
+ if (type === "multi-select") {
4013
+ return /*#__PURE__*/jsxRuntime.jsx(Typography, {
4014
+ className: "neeto-ui-text-gray-500",
4015
+ style: "body2",
4016
+ children: field !== null && field !== void 0 && field.label ? t("neetoRules.builder.config.noOptionsFor", {
4017
+ field: field.label
4018
+ }) : t("neetoRules.builder.config.noOptions")
4019
+ });
4020
+ }
4021
+ if (type === "multi-select-create") {
4022
+ var _current = formik.getIn(values, valuesPath) || [];
4023
+ return /*#__PURE__*/jsxRuntime.jsx(Select$1, {
4024
+ autoFocus: true,
4025
+ isCreateable: true,
4026
+ isMulti: true,
4027
+ required: true,
4028
+ error: fieldError(valuesPath),
4029
+ label: t("neetoRules.builder.config.keywords"),
4030
+ placeholder: t("neetoRules.builder.config.keywordsPlaceholder"),
4031
+ size: "large",
4032
+ value: _current.map(neetoCist.toLabelAndValue),
4033
+ onBlur: function onBlur() {
4034
+ return setFieldTouched(valuesPath, true);
4035
+ },
4036
+ onChange: function onChange(selected) {
4037
+ return setFieldValue(valuesPath, ramda.pluck("value", selected || []));
4038
+ }
4039
+ });
4040
+ }
4041
+ if (neetoCist.isNotEmpty(enumOptions)) {
4042
+ var _current2 = formik.getIn(values, valuePath);
4043
+ var _filtered = filterOptions(enumOptions);
4044
+ if (term && ramda.isEmpty(_filtered)) return noMatches;
4045
+ return /*#__PURE__*/jsxRuntime.jsx(Radio, {
4046
+ stacked: true,
4047
+ error: fieldError(valuePath),
4048
+ value: _current2 !== null && _current2 !== void 0 ? _current2 : "",
4049
+ onBlur: function onBlur() {
4050
+ return setFieldTouched(valuePath, true);
4051
+ },
4052
+ onChange: function onChange(event) {
4053
+ return setFieldValue(valuePath, event.target.value);
4054
+ },
4055
+ children: _filtered.map(function (option) {
4056
+ return /*#__PURE__*/jsxRuntime.jsx(Radio.Item, {
4057
+ label: String(option.label).toLowerCase(),
4058
+ value: option.value
4059
+ }, option.value);
4060
+ })
4061
+ });
4062
+ }
4063
+ if (valueType === "number") {
4064
+ var _getIn;
4065
+ return /*#__PURE__*/jsxRuntime.jsx(Input, {
4066
+ autoFocus: true,
4067
+ required: true,
4068
+ error: fieldError(valuePath),
4069
+ label: t("neetoRules.common.value"),
4070
+ size: "large",
4071
+ type: "number",
4072
+ value: (_getIn = formik.getIn(values, valuePath)) !== null && _getIn !== void 0 ? _getIn : "",
4073
+ onBlur: function onBlur() {
4074
+ return setFieldTouched(valuePath, true);
4075
+ },
4076
+ onChange: function onChange(event) {
4077
+ return setFieldValue(valuePath, event.target.value === "" ? "" : Number(event.target.value));
4078
+ }
4079
+ });
4080
+ }
4081
+ return /*#__PURE__*/jsxRuntime.jsx(Input$1, {
4082
+ autoFocus: true,
4083
+ required: true,
4084
+ label: t("neetoRules.common.value"),
4085
+ name: valuePath,
4086
+ size: "large",
4087
+ type: valueType === "email" ? "email" : "text",
4088
+ placeholder: (field === null || field === void 0 ? void 0 : field.placeholder) || (valueType === "email" ? t("neetoRules.builder.config.exampleEmail") : undefined)
4089
+ });
4090
+ };
4091
+
4092
+ var ValuePane = function ValuePane(_ref) {
4093
+ var _schema$conditions;
4094
+ var schema = _ref.schema,
4095
+ index$1 = _ref.index;
4096
+ var _useTranslation = reactI18next.useTranslation(),
4097
+ t = _useTranslation.t;
4098
+ var _useFormikContext = formik.useFormikContext(),
4099
+ setFieldValue = _useFormikContext.setFieldValue;
4100
+ var _useRuleModel = useRuleModel(schema),
4101
+ rule = _useRuleModel.rule,
4102
+ fieldKeys = _useRuleModel.fieldKeys;
4103
+ var _useState = react.useState(""),
4104
+ _useState2 = _slicedToArray(_useState, 2),
4105
+ searchTerm = _useState2[0],
4106
+ setSearchTerm = _useState2[1];
4107
+ var searchRef = react.useRef(null);
4108
+
4109
+ // eslint-disable-next-line security/detect-object-injection
4110
+ var condition = rule.conditions[index$1] || {};
4111
+ var field = (((_schema$conditions = schema.conditions) === null || _schema$conditions === void 0 ? void 0 : _schema$conditions.fields) || []).find(function (candidate) {
4112
+ return optionValue(candidate) === condition.field;
4113
+ });
4114
+ var base = "".concat(fieldKeys.conditions, ".value.").concat(index$1);
4115
+ usePaneValidation("".concat(base, ".metadata"));
4116
+ var enumOptions = normalizeOptions((field === null || field === void 0 ? void 0 : field.values) || (field === null || field === void 0 ? void 0 : field.dropdownOptions) || (field === null || field === void 0 ? void 0 : field.options));
4117
+ var showSearch = enumOptions.length >= PANE_SEARCH_THRESHOLD;
4118
+ var renderBody = function renderBody() {
4119
+ var _schema$conditions2;
4120
+ if ((_schema$conditions2 = schema.conditions) !== null && _schema$conditions2 !== void 0 && _schema$conditions2.renderValue) {
4121
+ return schema.conditions.renderValue({
4122
+ name: base,
4123
+ condition: condition,
4124
+ field: field,
4125
+ setFieldValue: setFieldValue,
4126
+ searchTerm: searchTerm
4127
+ });
4128
+ }
4129
+ return /*#__PURE__*/jsxRuntime.jsx(ConditionValueFields, {
4130
+ field: field,
4131
+ searchTerm: searchTerm,
4132
+ name: base
4133
+ });
4134
+ };
4135
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
4136
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.Panel.Header, {
4137
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
4138
+ className: "flex w-full flex-col gap-y-2",
4139
+ children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
4140
+ style: "h3",
4141
+ children: t("neetoRules.builder.pickValue", {
4142
+ field: (field === null || field === void 0 ? void 0 : field.label) || t("neetoRules.builder.valueWord")
4143
+ })
4144
+ }), /*#__PURE__*/jsxRuntime.jsx(Typography, {
4145
+ className: "neeto-ui-text-gray-500",
4146
+ style: "body2",
4147
+ children: (field === null || field === void 0 ? void 0 : field.valueSubtitle) || (isMultiValueVerb(condition === null || condition === void 0 ? void 0 : condition.verb) ? t("neetoRules.builder.valuesSubtitle", {
4148
+ field: (field === null || field === void 0 ? void 0 : field.label) || t("neetoRules.builder.valueWord")
4149
+ }) : t("neetoRules.builder.valueSubtitle"))
4150
+ }), showSearch && /*#__PURE__*/jsxRuntime.jsx("div", {
4151
+ className: "mb-pane-search",
4152
+ ref: searchRef,
4153
+ children: /*#__PURE__*/jsxRuntime.jsx(Input, {
4154
+ placeholder: t("neetoRules.builder.searchPlaceholder"),
4155
+ prefix: /*#__PURE__*/jsxRuntime.jsx(Search, {}),
4156
+ size: "large",
4157
+ value: searchTerm,
4158
+ onChange: function onChange(event) {
4159
+ return setSearchTerm(event.target.value);
4160
+ }
4161
+ })
4162
+ })]
4163
+ })
4164
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel.Body, {
4165
+ children: renderBody()
4166
+ })]
4167
+ });
4168
+ };
4169
+
4170
+ var _BUILDER_PANEL_TYPE_C;
4171
+ var BUILDER_PANEL_TYPE_CONFIG_MAP = (_BUILDER_PANEL_TYPE_C = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_BUILDER_PANEL_TYPE_C, BUILDER_PANEL_TYPES.TRIGGER, {
4172
+ component: OptionsPane
4173
+ }), BUILDER_PANEL_TYPES.ACTOR, {
4174
+ component: OptionsPane
4175
+ }), BUILDER_PANEL_TYPES.CONDITION_FIELD, {
4176
+ component: OptionsPane
4177
+ }), BUILDER_PANEL_TYPES.OPERATOR, {
4178
+ component: OptionsPane
4179
+ }), BUILDER_PANEL_TYPES.CONNECTOR, {
4180
+ component: OptionsPane
4181
+ }), BUILDER_PANEL_TYPES.ACTION_CHANNEL, {
4182
+ component: OptionsPane
4183
+ }), BUILDER_PANEL_TYPES.RECIPIENT, {
4184
+ component: RecipientPane
4185
+ }), BUILDER_PANEL_TYPES.CONDITION_VALUE, {
4186
+ component: ValuePane
4187
+ }), BUILDER_PANEL_TYPES.ACTION_CONFIG, {
4188
+ component: ConfigPane
4189
+ }), BUILDER_PANEL_TYPES.DELAY, {
4190
+ component: DelayPane
4191
+ }), _defineProperty(_defineProperty(_defineProperty(_BUILDER_PANEL_TYPE_C, BUILDER_PANEL_TYPES.LEAD_TIME, {
4192
+ component: LeadTimePane
4193
+ }), BUILDER_PANEL_TYPES.NAME, {
4194
+ component: NamePane
4195
+ }), BUILDER_PANEL_TYPES.SCOPE, {
4196
+ component: OptionsPane
4197
+ }));
4198
+
4199
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4200
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4201
+ var Form = function Form(_ref) {
4202
+ var _schema$meta$showName, _schema$meta;
4203
+ var _ref$data = _ref.data,
4204
+ data = _ref$data === void 0 ? {} : _ref$data,
4205
+ _ref$schema = _ref.schema,
4206
+ rawSchema = _ref$schema === void 0 ? {} : _ref$schema,
4207
+ url = _ref.automationRulesEndpoint,
4208
+ title = _ref.title,
4209
+ _ref$breadcrumbs = _ref.breadcrumbs,
4210
+ breadcrumbs = _ref$breadcrumbs === void 0 ? {} : _ref$breadcrumbs,
4211
+ _ref$isLoading = _ref.isLoading,
4212
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
4213
+ className = _ref.className,
4214
+ _ref$handleSubmit = _ref.handleSubmit,
4215
+ handleSubmit = _ref$handleSubmit === void 0 ? neetoCist.noop : _ref$handleSubmit,
4216
+ _ref$handleCancel = _ref.handleCancel,
4217
+ handleCancel = _ref$handleCancel === void 0 ? neetoCist.noop : _ref$handleCancel,
4218
+ _ref$payloadKey = _ref.payloadKey,
4219
+ payloadKey = _ref$payloadKey === void 0 ? "rule" : _ref$payloadKey,
4220
+ _ref$isNameGeneration = _ref.isNameGenerationDisabled,
4221
+ isNameGenerationDisabled = _ref$isNameGeneration === void 0 ? false : _ref$isNameGeneration;
4222
+ var _useTranslation = reactI18next.useTranslation(),
4223
+ t = _useTranslation.t;
4224
+ var formikRef = react.useRef(null);
4225
+ var formRef = react.useRef(null);
4226
+ var _useCustomDataStore = useCustomDataStore.useCustomDataStore(shallow.useShallow(function (store) {
4227
+ return {
4228
+ customData: store["customData"]
4229
+ };
4230
+ })),
4231
+ customData = _useCustomDataStore.customData;
4232
+ var _useUtilityStore = useUtilityStore.useUtilityStore(shallow.useShallow(function (store) {
4233
+ return {
4234
+ resetPanelState: store["resetPanelState"],
4235
+ errorFields: store["errorFields"]
4236
+ };
4237
+ })),
4238
+ resetPanelState = _useUtilityStore.resetPanelState,
4239
+ errorFields = _useUtilityStore.errorFields;
4240
+ var initialValues = react.useMemo(function () {
4241
+ return index.formatData(data);
4242
+ }, [data]);
4243
+ var schema = react.useMemo(function () {
4244
+ return normalizeSchema(rawSchema);
4245
+ }, [rawSchema]);
4246
+ var isNameRequired = isNameGenerationDisabled || ((_schema$meta$showName = (_schema$meta = schema.meta) === null || _schema$meta === void 0 ? void 0 : _schema$meta.showName) !== null && _schema$meta$showName !== void 0 ? _schema$meta$showName : true);
4247
+ var _usePollRuleName = index.usePollRuleName({
4248
+ url: url,
4249
+ formikRef: formikRef,
4250
+ payloadKey: payloadKey,
4251
+ isNameGenerationDisabled: isNameGenerationDisabled
4252
+ }),
4253
+ waitForGeneratedRuleName = _usePollRuleName.waitForGeneratedRuleName,
4254
+ saveRuleName = _usePollRuleName.saveRuleName,
4255
+ isCancelledNameGeneration = _usePollRuleName.isCancelledNameGeneration;
4256
+
4257
+ // eslint-disable-next-line @bigbinary/neeto/prefer-function-reference, react-hooks/exhaustive-deps
4258
+ react.useEffect(function () {
4259
+ return function () {
4260
+ return resetPanelState();
4261
+ };
4262
+ }, []);
4263
+ var submitForm = function submitForm(values, formikBag) {
4264
+ if (neetoCist.isNotEmpty(errorFields)) {
4265
+ formikBag.setSubmitting(false);
4266
+ return;
4267
+ }
4268
+ var rule = valuesToRuleModel({
4269
+ values: values,
4270
+ schema: schema
4271
+ });
4272
+ if (!isRuleComplete(rule) || invalidScopeIndexes({
4273
+ rule: rule,
4274
+ schema: schema
4275
+ }).length) {
4276
+ formikBag.setSubmitting(false);
4277
+ return;
4278
+ }
4279
+ if (isCancelledNameGeneration) {
4280
+ saveRuleName(values);
4281
+ return;
4282
+ }
4283
+ var payload = index.buildPayload(data, values);
4284
+ resetPanelState();
4285
+ handleSubmit(payload, formikBag, waitForGeneratedRuleName);
4286
+ };
4287
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Formik, {
4288
+ enableReinitialize: true,
4289
+ initialValues: _objectSpread$1(_objectSpread$1({}, index.DEFAULT_INITIAL_VALUE), initialValues),
4290
+ innerRef: formikRef,
4291
+ validationSchema: index.getValidationSchema({
4292
+ data: data,
4293
+ customData: customData,
4294
+ isNameGenerationDisabled: isNameRequired
4295
+ }),
4296
+ onSubmit: submitForm,
4297
+ children: function children() {
4298
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
4299
+ className: "flex neeto-rules-main-content h-full w-full",
4300
+ children: [/*#__PURE__*/jsxRuntime.jsx(index.TouchErrors, {}), /*#__PURE__*/jsxRuntime.jsxs(Container, {
4301
+ className: "neeto-rules-main-content__container max-h-full",
4302
+ children: [/*#__PURE__*/jsxRuntime.jsx(Header, {
4303
+ breadcrumbs: breadcrumbs,
4304
+ title: title || t("neetoRules.common.title")
4305
+ }), isLoading ? /*#__PURE__*/jsxRuntime.jsx("div", {
4306
+ className: "flex h-full w-full items-center justify-center",
4307
+ children: /*#__PURE__*/jsxRuntime.jsx(Spinner, {})
4308
+ }) : /*#__PURE__*/jsxRuntime.jsxs(formik.Form, {
4309
+ ref: formRef,
4310
+ className: classNames(["w-full neeto-rules-main-content__form max-w-5xl", className]),
4311
+ children: [/*#__PURE__*/jsxRuntime.jsx(Canvas, {
4312
+ schema: schema
4313
+ }), /*#__PURE__*/jsxRuntime.jsx(index.ScrollToErrorField, {
4314
+ formRef: formRef
4315
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
4316
+ className: "neeto-ui-bg-white sticky bottom-0 py-6",
4317
+ children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
4318
+ cancelButtonProps: {
4319
+ onClick: handleCancel
4320
+ },
4321
+ submitButtonProps: {
4322
+ "data-testid": "form-submit-button"
4323
+ }
4324
+ })
4325
+ })]
4326
+ })]
4327
+ }), /*#__PURE__*/jsxRuntime.jsx(index.Panel, {
4328
+ configMap: BUILDER_PANEL_TYPE_CONFIG_MAP
4329
+ })]
4330
+ });
4331
+ }
4332
+ });
4333
+ };
4334
+
4335
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4336
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4337
+ var NeetoRulesBuilder = function NeetoRulesBuilder(_ref) {
4338
+ var rest = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
4339
+ return /*#__PURE__*/jsxRuntime.jsx(Form, _objectSpread({}, rest));
4340
+ };
4341
+
4342
+ module.exports = NeetoRulesBuilder;
4343
+ //# sourceMappingURL=NeetoRulesBuilder.js.map