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