@bigbinary/neeto-rules-frontend 2.7.2 → 2.7.3

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