@mx-cartographer/experiences 7.11.24 → 7.12.1

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.
@@ -1,1153 +0,0 @@
1
- import { jsx as i, jsxs as N, Fragment as Te } from "react/jsx-runtime";
2
- import h, { useEffect as ne, useState as ie } from "react";
3
- import { observer as U } from "mobx-react-lite";
4
- import W from "@mui/material/Stack";
5
- import re from "@mui/material/Button";
6
- import { CategoryIcon as be, MerchantLogo as Pe, P as ue, Text as pe, H3 as Be } from "@mxenabled/mxui";
7
- import { Icon as Ve, Close as Ge, ChevronLeft as ke, ChevronRight as fe } from "@mxenabled/mx-icons";
8
- import { L as ze } from "./Loader-D3rjKx72.mjs";
9
- import $ from "@mui/material/Box";
10
- import ae from "@mui/material/IconButton";
11
- import { alpha as T, useTheme as j } from "@mui/material/styles";
12
- import { useInView as Re } from "react-intersection-observer";
13
- import { b as Ue } from "./Category-CevNQ03n.mjs";
14
- import Ke from "@mui/material/styles/useTheme";
15
- import { b as Fe } from "./Localization-CPkpIwIx.mjs";
16
- import He from "@mui/material/CircularProgress";
17
- import { makeAutoObservable as se, runInAction as Oe } from "mobx";
18
- import { G as he, a as $e, u as je, b as Ye } from "./useCombineEvents-B5am53e-.mjs";
19
- import { B as me } from "./BeatApi-EFHXULDx.mjs";
20
- import { u as Xe } from "./useWidgetLoadTimer-DgN1bTyu.mjs";
21
- import Ze from "@mui/material/Card";
22
- import Qe from "@mui/material/CardActionArea";
23
- import qe from "@mui/material/Avatar";
24
- const Ce = {
25
- featureVersion: "spendVsIncomeTrends"
26
- };
27
- class Je {
28
- copyApi = new he("/", "");
29
- copyObject = {};
30
- namespace = "experiences";
31
- translationKey = "micro_insights";
32
- constructor() {
33
- se(this);
34
- }
35
- // NOTE: Not sure if this is special case, but other stores have this deprecation todo
36
- // DEPRECATED: Initialize api in constructor and use loadCopy instead
37
- // TODO: Remove this function
38
- initialize = async (e, o) => {
39
- this.copyApi = new he(e, o), await this.loadCopy();
40
- };
41
- loadCopy = async () => {
42
- const e = await this.copyApi.getGlobalCopy(this.namespace, this.translationKey);
43
- Oe(() => {
44
- this.copyObject = e[this.translationKey];
45
- });
46
- };
47
- get cardsCopy() {
48
- return this.copyObject.cards;
49
- }
50
- get carouselCopy() {
51
- return this.copyObject.carousel;
52
- }
53
- get zeroStateCopy() {
54
- return this.copyObject.zero_state;
55
- }
56
- }
57
- const ce = {
58
- BillAmountNotStandard: "BillAmountNotStandard",
59
- CanadianUpcomingDeadlineAlert: "CanadianUpcomingDeadlineAlert",
60
- DuplicatePaymentV2: "DuplicatePaymentV2",
61
- IntroducePulse: "IntroducePulse",
62
- LargeTransaction: "LargeTransaction",
63
- MonthlySpendToIncomeComparisonV2: "MonthlySpendToIncomeComparisonV2",
64
- QuarterlySummary: "QuarterlySummary",
65
- SpendingPlanCategorySpending: "SpendingPlanCategorySpending",
66
- SubscriptionPriceIncrease: "SubscriptionPriceIncrease",
67
- UncategorizedTransactionsV2: "UncategorizedTransactionsV2",
68
- UpcomingBill: "UpcomingBill",
69
- UnifiedDeposit: "UnifiedDeposit",
70
- WeeklySpendingPlanSummary: "WeeklySpendingPlanSummary",
71
- WeeklyNewMerchantsV2: "WeeklyNewMerchantsV2",
72
- MonthlySpendComparison: "MonthlySpendComparison",
73
- MonthlySpendToIncomeComparison: "MonthlySpendToIncomeComparison"
74
- }, R = window?.app?.clientConfig?.microwidget_instance_id || "", Ee = {
75
- INSIGHTS_MICRO_WIDGET: "/micro-insights-carousel"
76
- }, ye = (t) => `on${t}Click`, We = (t) => `on${t}View`, Ne = (t) => `on${t}ViewFirstTime`, le = (t) => t.replace(/([a-z])([A-Z])/g, "$1 $2"), et = () => Object.values(ce).reduce(
77
- (t, e) => ({
78
- ...t,
79
- [ye(e)]: {
80
- action: v.MICRO_BEAT_CLICKED,
81
- category: D.BEAT_INTERACTION,
82
- label: le(e),
83
- value: R
84
- }
85
- }),
86
- {}
87
- ), tt = () => Object.values(ce).reduce(
88
- (t, e) => ({
89
- ...t,
90
- [We(e)]: {
91
- action: v.MICRO_BEAT_DISPLAYED,
92
- category: D.BEAT_INTERACTION,
93
- label: le(e),
94
- value: R
95
- }
96
- }),
97
- {}
98
- ), ot = () => Object.values(ce).reduce(
99
- (t, e) => ({
100
- ...t,
101
- [Ne(e)]: {
102
- action: v.MICRO_BEAT_DISPLAYED_FIRST_TIME,
103
- category: D.BEAT_INTERACTION,
104
- label: le(e),
105
- value: R
106
- }
107
- }),
108
- {}
109
- ), L = {
110
- CARD: "Card",
111
- CAROUSEL_CONTROL: "Carousel Control",
112
- MICRO_WIDGET: "Micro Widget",
113
- VIEW_MORE: "View More"
114
- }, D = {
115
- MICRO_WIDGET_INTERACTION: "Micro Widget Interaction",
116
- BEAT_INTERACTION: "Beat Interaction"
117
- }, O = {
118
- ON_CAROUSEL_BACK_CLICK: "onCarouselBackClick",
119
- ON_CAROUSEL_BACK_SWIPE: "onCarouselBackSwipe",
120
- ON_CAROUSEL_FORWARD_CLICK: "onCarouselForwardClick",
121
- ON_CAROUSEL_FORWARD_SWIPE: "onCarouselForwardSwipe",
122
- ON_NO_RELEVANT_INSIGHTS_CLICKED: "onNoRelevantInsightsClicked",
123
- ON_VIEW_MORE_CLICKED: "onViewMoreClicked"
124
- }, Me = {
125
- ON_VIEW_MORE_VIEWED: "onViewMoreCardView"
126
- }, v = {
127
- CONTROL_BACKWARD: "Control Backward",
128
- CONTROL_FORWARD: "Control Forward",
129
- MICRO_BEAT_CLICKED: "Micro Beat Clicked",
130
- MICRO_BEAT_DISPLAYED: "Micro Beat Displayed",
131
- MICRO_BEAT_DISPLAYED_FIRST_TIME: "Micro Beat Displayed For First Time",
132
- SWIPE_BACKWARD: "Swipe Backward",
133
- SWIPE_FORWARD: "Swipe Forward"
134
- }, G = {
135
- MICRO_WIDGET_CAROUSEL: "Micro Widget Carousel",
136
- MICRO_WIDGET_CAROUSEL_ZERO_STATE: "Micro Widget Carousel Zero State",
137
- MICRO_WIDGET_CAROUSEL_NO_RELEVANT_INSIGHTS: "Micro Widget Carousel No Relevant Insights"
138
- }, ge = {
139
- [G.MICRO_WIDGET_CAROUSEL]: {
140
- label: L.MICRO_WIDGET,
141
- name: G.MICRO_WIDGET_CAROUSEL,
142
- path: Ee.INSIGHTS_MICRO_WIDGET,
143
- value: R
144
- },
145
- // zero state
146
- [G.MICRO_WIDGET_CAROUSEL_ZERO_STATE]: {
147
- label: L.MICRO_WIDGET,
148
- name: G.MICRO_WIDGET_CAROUSEL_ZERO_STATE,
149
- path: Ee.INSIGHTS_MICRO_WIDGET,
150
- value: R
151
- },
152
- // no relevant cards
153
- [G.MICRO_WIDGET_CAROUSEL_NO_RELEVANT_INSIGHTS]: {
154
- label: L.MICRO_WIDGET,
155
- name: G.MICRO_WIDGET_CAROUSEL_NO_RELEVANT_INSIGHTS,
156
- path: "/micro-widget",
157
- value: R
158
- }
159
- }, Ie = {
160
- // carousel control interaction events - clicks and swipes
161
- [O.ON_CAROUSEL_BACK_CLICK]: {
162
- action: v.CONTROL_BACKWARD,
163
- category: D.MICRO_WIDGET_INTERACTION,
164
- label: L.CAROUSEL_CONTROL,
165
- value: R
166
- },
167
- [O.ON_CAROUSEL_FORWARD_CLICK]: {
168
- action: v.CONTROL_FORWARD,
169
- category: D.MICRO_WIDGET_INTERACTION,
170
- label: L.CAROUSEL_CONTROL,
171
- value: R
172
- },
173
- [O.ON_CAROUSEL_BACK_SWIPE]: {
174
- action: v.SWIPE_BACKWARD,
175
- category: D.MICRO_WIDGET_INTERACTION,
176
- label: L.CAROUSEL_CONTROL,
177
- value: R
178
- },
179
- [O.ON_CAROUSEL_FORWARD_SWIPE]: {
180
- action: v.SWIPE_FORWARD,
181
- category: D.MICRO_WIDGET_INTERACTION,
182
- label: L.CAROUSEL_CONTROL,
183
- value: R
184
- },
185
- // read more card events
186
- [O.ON_VIEW_MORE_CLICKED]: {
187
- action: v.MICRO_BEAT_CLICKED,
188
- category: D.BEAT_INTERACTION,
189
- label: L.VIEW_MORE,
190
- value: R
191
- },
192
- [Me.ON_VIEW_MORE_VIEWED]: {
193
- action: v.MICRO_BEAT_DISPLAYED,
194
- category: D.BEAT_INTERACTION,
195
- label: L.VIEW_MORE,
196
- value: R
197
- },
198
- ...et(),
199
- ...tt(),
200
- ...ot()
201
- }, Ae = async (t, e) => !e || !Ie[t] ? null : e.sendAnalyticEvent(Ie[t]).then((o) => o).catch((o) => {
202
- throw o;
203
- }), Se = async (t, e) => !e || !ge[t] ? null : e.sendAnalyticsPageview(ge[t]).then((o) => o).catch((o) => {
204
- throw o;
205
- });
206
- class it {
207
- onAnalyticEvent = Ae;
208
- onAnalyticPageView = Se;
209
- beatApi = new me("/", "");
210
- constructor() {
211
- se(this);
212
- }
213
- initialize = async (e, o, n) => {
214
- this.onAnalyticEvent = (r, a) => {
215
- Ae(r, a).then((s) => s).catch((s) => {
216
- throw s.status === 401 && n(), s;
217
- });
218
- }, this.onAnalyticPageView = (r, a) => {
219
- Se(r, a).then((s) => s).catch((s) => {
220
- throw s.status === 401 && n(), s;
221
- });
222
- }, this.beatApi = new me(e, o);
223
- };
224
- updateBeat = async (e) => {
225
- this.beatApi.updateBeat(e);
226
- };
227
- updateOffer = async (e) => {
228
- this.beatApi.updateOffer(e);
229
- };
230
- }
231
- class nt {
232
- copyStore;
233
- endpoint = "/";
234
- insightsMicroWidgetStore;
235
- session = null;
236
- token = "";
237
- isInitialized = !1;
238
- constructor() {
239
- this.copyStore = new Je(), this.insightsMicroWidgetStore = new it(), se(this);
240
- }
241
- initialize = async (e, o, n) => {
242
- await this.copyStore.initialize(e, o), await this.insightsMicroWidgetStore.initialize(e, o, n);
243
- const r = await $e(e, o, "1.0.0", "Micro Insights Carousel");
244
- Oe(() => {
245
- this.session = r, this.isInitialized = !0;
246
- });
247
- };
248
- }
249
- const Y = h.createContext(null), rt = ({
250
- onEvent: t,
251
- onPageview: e,
252
- store: o,
253
- children: n
254
- }) => /* @__PURE__ */ i(Y.Provider, { value: { onEvent: t, onPageview: e, store: o, children: n }, children: n }), at = ({ beat: t }) => {
255
- const { primary_category_guid: e, category_guids: o } = t, n = e || o?.[0] || Ue.UNCATEGORIZED;
256
- return /* @__PURE__ */ i(be, { categoryGuid: n, size: 32, sx: { minWidth: 32 } });
257
- }, st = ({
258
- bgColor: t,
259
- name: e,
260
- iconColor: o = "primary"
261
- }) => /* @__PURE__ */ i(
262
- qe,
263
- {
264
- sx: {
265
- bgcolor: t,
266
- width: 32,
267
- height: 32
268
- },
269
- variant: "rounded",
270
- children: /* @__PURE__ */ i(Ve, { color: o, fill: !0, name: e, size: 20 })
271
- }
272
- ), f = st, ct = ({ beat: t }) => {
273
- const { category_guids: e, merchant_guids: o, primary_category_guid: n, primary_merchant_guid: r } = t;
274
- return /* @__PURE__ */ i(
275
- Pe,
276
- {
277
- categoryGuid: n || e && e[0] || "",
278
- merchantGuid: r || o[0],
279
- size: 32,
280
- sx: {
281
- display: "flex",
282
- mt: 2,
283
- minWidth: 32
284
- }
285
- }
286
- );
287
- }, lt = (t) => t ? t.data ? t.data.map((e) => {
288
- const o = {};
289
- return t.names?.map((n, r) => {
290
- o[n] = e[r];
291
- }), o;
292
- }) : [] : [], dt = (t) => {
293
- const e = lt(t), o = e.length / 2, n = e.slice(0, o), r = e.slice(o);
294
- return !n.length || !r.length ? "primary" : n[0].amount > r[0].amount ? "error" : n[0].amount < r[0].amount ? "success" : "primary";
295
- }, _t = ({ beat: t }) => {
296
- const e = Ke(), o = dt(t.data_series), n = e.palette[o].main;
297
- return /* @__PURE__ */ i(f, { bgColor: T(n, 0.15), iconColor: o, name: "bar_chart" });
298
- }, ut = {
299
- 0: (t, e) => /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "error" }),
300
- 1: (t) => /* @__PURE__ */ i(at, { beat: t }),
301
- 2: (t) => /* @__PURE__ */ i(ct, { beat: t }),
302
- 3: (t) => /* @__PURE__ */ i(_t, { beat: t }),
303
- 4: (t, e) => /* @__PURE__ */ i(
304
- f,
305
- {
306
- bgColor: T(e.palette.secondary.main, 0.15),
307
- iconColor: "secondary",
308
- name: "info"
309
- }
310
- ),
311
- 5: (t, e) => /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "campaign" }),
312
- // TODO: Waiting for the backend to accommodate icon types 6, 7, 8, and 9
313
- 6: (t, e) => /* @__PURE__ */ i(
314
- f,
315
- {
316
- bgColor: T(e.palette.success.main, 0.15),
317
- iconColor: "success",
318
- name: "check_circle"
319
- }
320
- ),
321
- 7: (t, e) => /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "today" }),
322
- 8: (t, e) => /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "calendar_clock" }),
323
- 9: (t, e) => /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "celebration" })
324
- }, pt = ({ beat: t }) => {
325
- const e = j(), { icon_type: o } = t, n = o != null ? ut[o] : null;
326
- return n ? n(t, e) : /* @__PURE__ */ i(f, { bgColor: T(e.palette.primary.main, 0.15), name: "error" });
327
- }, x = () => {
328
- const t = h.useContext(Y);
329
- if (!t)
330
- throw new Error("useCopyStore() must be used within the InsightsMicroWidgetDataProvider");
331
- return t.store.copyStore;
332
- }, ht = () => {
333
- const t = h.useContext(Y);
334
- if (!t?.store?.insightsMicroWidgetStore)
335
- throw new Error(
336
- "useInsightsMicroWidgetStore() must be used within the InsightsMicroWidgetDataProvider"
337
- );
338
- return t.store.insightsMicroWidgetStore;
339
- }, X = () => {
340
- const t = h.useContext(Y);
341
- if (!t)
342
- throw new Error("useEvent() must be used within the InsightsMicroWidgetDataProvider");
343
- return { onEvent: t.onEvent };
344
- }, we = () => {
345
- const t = h.useContext(Y);
346
- if (!t)
347
- throw new Error("usePageview() must be used within the InsightsMicroWidgetDataProvider");
348
- return { onPageview: t.onPageview };
349
- }, mt = {
350
- LARGE: 180,
351
- STANDARD: 154,
352
- XLARGE: 200,
353
- XXLARGE: 248
354
- }, Ct = 50, Le = 1, Et = h.forwardRef(
355
- function({
356
- ariaLabel: e,
357
- cardSx: o,
358
- closeAriaLabel: n,
359
- description: r,
360
- icon: a,
361
- isActiveCard: s,
362
- hasCardEffect: p = !1,
363
- heightOverrides: m,
364
- onClose: C,
365
- onCardClick: u,
366
- onPrimaryAction: c,
367
- onSecondaryAction: _,
368
- primaryActionText: l,
369
- secondaryActionText: A,
370
- title: E,
371
- variant: S,
372
- widthOverrides: g,
373
- ...b
374
- }, M) {
375
- const k = !!(c && l), I = !!(_ && A), P = p ? Ze : $, w = /* @__PURE__ */ N(Te, { children: [
376
- C && /* @__PURE__ */ i(
377
- ae,
378
- {
379
- "aria-label": n,
380
- onClick: (d) => {
381
- d.stopPropagation(), C?.();
382
- },
383
- onMouseDown: (d) => {
384
- d.stopPropagation();
385
- },
386
- onTouchStart: (d) => {
387
- d.stopPropagation();
388
- },
389
- sx: { minHeight: 40, minWidth: 40, position: "absolute", right: 4, top: 4 },
390
- children: /* @__PURE__ */ i(Ge, {})
391
- }
392
- ),
393
- /* @__PURE__ */ N(W, { sx: { gap: 6, height: "100%", justifyContent: "space-between" }, children: [
394
- /* @__PURE__ */ N(W, { sx: { flexDirection: "row", gap: 12 }, children: [
395
- a && a,
396
- /* @__PURE__ */ N(W, { sx: { gap: 6 }, children: [
397
- /* @__PURE__ */ i(W, { sx: { flexDirection: "row", justifyContent: "space-between" }, children: /* @__PURE__ */ i(ue, { bold: !0, sx: { lineHeight: "16px" }, variant: "body1", children: E }) }),
398
- /* @__PURE__ */ i(
399
- ue,
400
- {
401
- dangerouslySetInnerHTML: { __html: r },
402
- sx: {
403
- display: "-webkit-box",
404
- overflow: "hidden",
405
- textOverflow: "ellipsis",
406
- WebkitBoxOrient: "vertical",
407
- WebkitLineClamp: k ? 2 : 3
408
- },
409
- variant: "subtitle2"
410
- }
411
- )
412
- ] })
413
- ] }),
414
- k && /* @__PURE__ */ N(
415
- W,
416
- {
417
- sx: {
418
- alignItems: "center",
419
- flexDirection: "row",
420
- height: 28,
421
- pb: 4,
422
- pl: a ? 36 : 0
423
- },
424
- children: [
425
- k && /* @__PURE__ */ i(
426
- re,
427
- {
428
- onClick: (d) => {
429
- d.stopPropagation(), c?.();
430
- },
431
- onMouseDown: (d) => {
432
- d.stopPropagation();
433
- },
434
- onTouchStart: (d) => {
435
- d.stopPropagation();
436
- },
437
- size: "small",
438
- sx: { px: 8, ml: a ? 0 : -8 },
439
- variant: "text",
440
- children: /* @__PURE__ */ i(pe, { bold: !0, variant: "body2", children: l })
441
- }
442
- ),
443
- I && /* @__PURE__ */ i(
444
- re,
445
- {
446
- onClick: (d) => {
447
- d.stopPropagation(), _?.();
448
- },
449
- onMouseDown: (d) => {
450
- d.stopPropagation();
451
- },
452
- onTouchStart: (d) => {
453
- d.stopPropagation();
454
- },
455
- size: "small",
456
- sx: { px: 8 },
457
- variant: "text",
458
- children: /* @__PURE__ */ i(pe, { bold: !0, sx: { color: "text.secondary" }, variant: "body2", children: A })
459
- }
460
- )
461
- ]
462
- }
463
- )
464
- ] })
465
- ] });
466
- return /* @__PURE__ */ i(
467
- P,
468
- {
469
- "aria-hidden": !s,
470
- "aria-label": e,
471
- ref: M,
472
- role: "group",
473
- sx: {
474
- backgroundColor: "background.paper",
475
- height: m ? "100%" : 120,
476
- minWidth: g ? `${g}px` : "100%",
477
- position: "relative",
478
- my: 1,
479
- ...o
480
- },
481
- tabIndex: u || !s ? -1 : 0,
482
- variant: S,
483
- ...b,
484
- children: u ? /* @__PURE__ */ i(
485
- Qe,
486
- {
487
- onClick: u,
488
- sx: {
489
- pb: 8,
490
- pt: 16,
491
- px: 16,
492
- height: "100%"
493
- },
494
- children: w
495
- }
496
- ) : /* @__PURE__ */ i($, { sx: { pb: 8, pt: 16, px: 16, height: "100%" }, children: w })
497
- }
498
- );
499
- }
500
- ), q = Et, gt = ({
501
- ariaLabel: t,
502
- beat: e,
503
- index: o,
504
- isActiveCard: n,
505
- onCardClick: r,
506
- posthog: a,
507
- widthOverrides: s,
508
- variant: p,
509
- showIcon: m,
510
- heightOverrides: C
511
- }) => {
512
- const { ref: u, inView: c } = Re({
513
- threshold: Le
514
- }), { cardsCopy: _ } = x(), { onEvent: l } = X(), { updateBeat: A, updateOffer: E } = ht();
515
- ne(() => {
516
- c && (e.has_been_displayed ? l(We(e.template)) : (e.guid.startsWith("OFR") ? E({
517
- ...e,
518
- has_been_displayed: !0
519
- }) : A({
520
- ...e,
521
- has_been_displayed: !0
522
- }), l(Ne(e.template))));
523
- }, [c]), ne(() => {
524
- if (c && e)
525
- if (e.template === "MarketingOffer") {
526
- const g = e;
527
- a?.capture("viewed_messaging_insight", {
528
- template: e.template,
529
- campaign_guid: g.campaign_guid,
530
- campaign_name: g.pulse_campaign_name
531
- });
532
- } else
533
- a?.capture("viewed_insight", {
534
- beat_guid: e.guid,
535
- template: e.template,
536
- position: o
537
- });
538
- }, [e, o, c]);
539
- const S = () => {
540
- if (r && r(e), l(ye(e.template)), e.template === "MarketingOffer") {
541
- const g = e;
542
- a?.capture("clicked_messaging_insight", {
543
- template: e.template,
544
- campaign_guid: g.campaign_guid,
545
- campaign_name: g.pulse_campaign_name
546
- });
547
- } else
548
- a?.capture("clicked_insight", {
549
- beat_guid: e.guid,
550
- template: e.template,
551
- position: o
552
- });
553
- };
554
- return /* @__PURE__ */ i(
555
- q,
556
- {
557
- "aria-roledescription": "slide",
558
- ariaLabel: t,
559
- cardSx: {
560
- borderRadius: 2
561
- },
562
- description: e?.html_micro_description && e?.html_micro_description.length > 0 ? e.html_micro_description : e.html_description || "",
563
- hasCardEffect: !0,
564
- heightOverrides: C,
565
- icon: m && /* @__PURE__ */ i(pt, { beat: e }),
566
- isActiveCard: n,
567
- onCardClick: S,
568
- onPrimaryAction: S,
569
- primaryActionText: e.micro_call_to_action || _.micro_card_cta,
570
- ref: u,
571
- title: e.micro_title && e.micro_title.length > 0 ? e.micro_title : e.title,
572
- variant: p,
573
- widthOverrides: s
574
- }
575
- );
576
- }, It = ({
577
- currentBeatIndex: t,
578
- numBeats: e,
579
- onNextClick: o,
580
- onPreviousClick: n,
581
- scrollRightBoundary: r,
582
- scrollX: a,
583
- shouldApplyDotAnimation: s = !1,
584
- visibleCardsCount: p = 1
585
- }) => {
586
- const m = j(), { carouselCopy: C } = x(), u = Math.floor(a) > r || t - p + 1 === 0, c = a < 0 || e - 1 === t, _ = m.palette.grey[500], l = m.palette.primary.main;
587
- return /* @__PURE__ */ N(
588
- W,
589
- {
590
- direction: "row",
591
- sx: {
592
- alignItems: "center",
593
- justifyContent: "center",
594
- pt: 4,
595
- width: "100%",
596
- // we were using `gap` instead of margin, but it doesn't work in safari browsers older than iOS 14.1
597
- "& button:first-child": {
598
- mr: 8
599
- }
600
- },
601
- children: [
602
- /* @__PURE__ */ i(
603
- ae,
604
- {
605
- "aria-disabled": u,
606
- "aria-label": C.previous_insight_cta_aria,
607
- disabled: u,
608
- onClick: n,
609
- children: /* @__PURE__ */ i(
610
- ke,
611
- {
612
- style: {
613
- color: u ? _ : l
614
- }
615
- }
616
- )
617
- }
618
- ),
619
- Array.from({ length: e }).map((A, E) => {
620
- const S = E === t;
621
- return /* @__PURE__ */ i(
622
- $,
623
- {
624
- className: "mx-insights-micro-carousel-dots",
625
- sx: {
626
- bgcolor: S ? l : _,
627
- height: 8,
628
- mr: 8,
629
- // existing comment from meganthan "we were using `gap` instead of margin, but it doesn't work in safari browsers older than iOS 14.1"
630
- ...s ? {
631
- borderRadius: "4px",
632
- transformOrigin: "center",
633
- transition: "all 0.5s ease-out",
634
- willChange: "width, background-color"
635
- } : {
636
- borderRadius: "50%",
637
- p: 0
638
- },
639
- width: S && s ? 24 : 8
640
- }
641
- },
642
- `carousel-button-${E}`
643
- );
644
- }),
645
- /* @__PURE__ */ i(
646
- ae,
647
- {
648
- "aria-disabled": c,
649
- "aria-label": C.next_insight_cta_aria,
650
- disabled: c,
651
- onClick: o,
652
- children: /* @__PURE__ */ i(
653
- fe,
654
- {
655
- style: {
656
- color: c ? _ : l
657
- }
658
- }
659
- )
660
- }
661
- )
662
- ]
663
- }
664
- );
665
- }, At = ({
666
- activeCardIndex: t,
667
- beats: e,
668
- cardWidth: o,
669
- showCTAColocatedWithText: n,
670
- heightOverrides: r,
671
- onCardClick: a,
672
- posthog: s,
673
- showIcon: p,
674
- variant: m
675
- }) => {
676
- const { carouselCopy: C } = x(), u = {
677
- showCTAColocatedWithText: n,
678
- heightOverrides: r,
679
- posthog: s,
680
- showIcon: p,
681
- variant: m
682
- };
683
- return /* @__PURE__ */ N(Te, { children: [
684
- e.map((c, _) => {
685
- const l = _ + 1, A = e.length + 1, E = Fe(
686
- C.card_position_in_carousel_aria,
687
- l.toString(),
688
- A.toString()
689
- ), S = c.micro_title && c.micro_title.length > 0, g = c.micro_description && c.micro_description.length > 0, b = S ? c.micro_title : c.title, M = g ? c.micro_description : c.description;
690
- return /* @__PURE__ */ i(
691
- gt,
692
- {
693
- ariaLabel: `${E}: ${b}, ${M}`,
694
- beat: c,
695
- index: _,
696
- isActiveCard: _ === t,
697
- onCardClick: a,
698
- widthOverrides: o || void 0,
699
- ...u
700
- },
701
- `${c.guid} ${_}`
702
- );
703
- }),
704
- /* @__PURE__ */ i(
705
- Mt,
706
- {
707
- isActiveCard: t === e.length,
708
- onCardClick: a,
709
- widthOverrides: o || void 0,
710
- ...u
711
- }
712
- )
713
- ] });
714
- }, St = ({
715
- analyticsMetadata: t,
716
- allowSingleCardPeeking: e = !1,
717
- beats: o = [],
718
- showCTAColocatedWithText: n,
719
- heightOverrides: r,
720
- onCardClick: a,
721
- posthog: s,
722
- showCarouselControls: p,
723
- showIcon: m,
724
- showWithMargin: C = !0,
725
- variant: u,
726
- widthOverrides: c,
727
- visibleCardsCount: _ = 1
728
- // Default to 1 card visible
729
- }) => {
730
- const l = h.useRef(null), A = h.useRef(null), [E, S] = h.useState(0), [g, b] = h.useState(null), [M, k] = h.useState(null), [I, P] = h.useState(null), { carouselCopy: w } = x(), { onEvent: d } = X();
731
- h.useEffect(() => {
732
- if (l.current && !e) {
733
- const y = l.current.offsetWidth, F = 8;
734
- let z;
735
- if (_ > 1) {
736
- const de = (y - (_ - 1) * F) / _ / 3;
737
- z = (y - de - (_ - 1) * F) / _;
738
- } else
739
- z = y;
740
- P(z);
741
- }
742
- }, [_, l.current?.offsetWidth]), h.useEffect(() => {
743
- const y = A.current?.offsetWidth;
744
- if (typeof y == "number" && e) {
745
- const F = (H) => {
746
- const _e = [
747
- { maxWidth: 375, cardWidth: 268 },
748
- { maxWidth: 444, cardWidth: 300 },
749
- { maxWidth: 599, cardWidth: 350 },
750
- { maxWidth: 749, cardWidth: 450 },
751
- { maxWidth: 900, cardWidth: 600 }
752
- ].find((xe) => H <= xe.maxWidth);
753
- return _e ? _e.cardWidth : 750;
754
- };
755
- P(F(y));
756
- const z = () => {
757
- const H = A.current?.offsetWidth;
758
- typeof H == "number" && P(F(H));
759
- };
760
- return window.addEventListener("resize", z), () => {
761
- window.removeEventListener("resize", z);
762
- };
763
- }
764
- }, [e, A]);
765
- const J = () => {
766
- d(O.ON_CAROUSEL_FORWARD_CLICK, t), l.current && I && l.current.scrollTo({
767
- left: E + I + 8,
768
- top: 0,
769
- behavior: "smooth"
770
- });
771
- }, Z = () => {
772
- d(O.ON_CAROUSEL_BACK_CLICK, t), l.current && I && l.current.scrollTo({
773
- left: Math.max(0, E - (I + 8)),
774
- top: 0,
775
- behavior: "smooth"
776
- });
777
- }, Q = () => {
778
- l.current && S(l.current.scrollLeft);
779
- }, ee = () => {
780
- if (!M || !g) return;
781
- M - g > Ct ? d(O.ON_CAROUSEL_FORWARD_SWIPE, t) : d(O.ON_CAROUSEL_BACK_SWIPE, t);
782
- }, te = (y) => {
783
- b(y.targetTouches[0].clientX);
784
- }, oe = (y) => {
785
- b(null), k(y.targetTouches[0].clientX);
786
- }, K = I ? Math.round(E / (I + 8)) : 0, B = l.current ? l.current.scrollWidth - l.current.offsetWidth : 0;
787
- return /* @__PURE__ */ N(
788
- W,
789
- {
790
- "aria-label": w.carousel_title,
791
- "aria-roledescription": "carousel",
792
- ref: A,
793
- role: "region",
794
- sx: {
795
- alignItems: "center",
796
- boxSizing: "border-box",
797
- height: r,
798
- width: c || "100%"
799
- },
800
- children: [
801
- /* @__PURE__ */ i(
802
- W,
803
- {
804
- direction: "row",
805
- onScroll: Q,
806
- onTouchEnd: ee,
807
- onTouchMove: te,
808
- onTouchStart: oe,
809
- ref: l,
810
- sx: {
811
- alignItems: "center",
812
- height: r && "100%",
813
- gap: 8,
814
- listStyleType: "none",
815
- m: 0,
816
- maxWidth: C ? "calc(100% - 32px)" : "100%",
817
- overflowX: "auto",
818
- overflowY: "hidden",
819
- p: 0,
820
- scrollbarWidth: "none",
821
- "-ms-overflow-style": "none",
822
- "-webkit-overflow-scrolling": "touch",
823
- "&::-webkit-scrollbar": {
824
- display: "none"
825
- }
826
- },
827
- children: /* @__PURE__ */ i(
828
- At,
829
- {
830
- activeCardIndex: K,
831
- beats: o,
832
- cardWidth: I,
833
- heightOverrides: r,
834
- onCardClick: a,
835
- posthog: s,
836
- showCTAColocatedWithText: n,
837
- showIcon: m,
838
- variant: u
839
- }
840
- )
841
- }
842
- ),
843
- p && /* @__PURE__ */ i(
844
- It,
845
- {
846
- currentBeatIndex: K + _ - 1,
847
- numBeats: o.length + 1,
848
- onNextClick: J,
849
- onPreviousClick: Z,
850
- scrollRightBoundary: B,
851
- scrollX: E,
852
- shouldApplyDotAnimation: e,
853
- visibleCardsCount: _
854
- }
855
- )
856
- ]
857
- }
858
- );
859
- }, Tt = U(St), ft = ({
860
- analyticsMetadata: t,
861
- onCardClick: e,
862
- posthog: o,
863
- widthOverrides: n,
864
- headerSx: r
865
- }) => {
866
- const { carouselCopy: a } = x(), { onEvent: s } = X(), p = () => {
867
- s && (s(O.ON_VIEW_MORE_CLICKED, t), e(), o?.capture("clicked_view_more"));
868
- };
869
- return a ? /* @__PURE__ */ N(
870
- W,
871
- {
872
- alignItems: "center",
873
- direction: "row",
874
- justifyContent: "space-between",
875
- spacing: 2,
876
- sx: {
877
- p: 16,
878
- pb: 8,
879
- width: n || void 0,
880
- ...r
881
- },
882
- children: [
883
- /* @__PURE__ */ i(Be, { children: a.carousel_title }),
884
- /* @__PURE__ */ i(
885
- re,
886
- {
887
- endIcon: /* @__PURE__ */ i(fe, { size: 20 }),
888
- onClick: p,
889
- size: "small",
890
- variant: "text",
891
- children: a.view_all_insights_in_full_feed_cta_aria
892
- }
893
- )
894
- ]
895
- }
896
- ) : /* @__PURE__ */ i(ze, {});
897
- }, Rt = U(ft), Ot = ({
898
- heightOverrides: t,
899
- widthOverrides: e,
900
- children: o
901
- }) => {
902
- const { carouselCopy: n } = x();
903
- return /* @__PURE__ */ i(
904
- $,
905
- {
906
- "aria-label": n?.carousel_title,
907
- "aria-roledescription": "carousel",
908
- role: "group",
909
- sx: {
910
- boxSizing: "border-box",
911
- height: t ? void 0 : "100%",
912
- m: "0 auto",
913
- width: e ? void 0 : "100%"
914
- },
915
- children: o
916
- }
917
- );
918
- }, De = ({
919
- ariaLabel: t,
920
- heightOverrides: e,
921
- onCardClick: o,
922
- posthog: n,
923
- showIcon: r,
924
- variant: a
925
- }) => {
926
- const { cardsCopy: s } = x(), p = j(), { onEvent: m } = X(), { onPageview: C } = we();
927
- h.useEffect(() => {
928
- C(G.MICRO_WIDGET_CAROUSEL_NO_RELEVANT_INSIGHTS);
929
- }, []);
930
- const u = () => {
931
- o && o(), m(O.ON_NO_RELEVANT_INSIGHTS_CLICKED), n?.capture("clicked_insight", {
932
- template: "no_relevant_insights"
933
- });
934
- };
935
- return /* @__PURE__ */ i(
936
- q,
937
- {
938
- ariaLabel: t,
939
- cardSx: {
940
- borderRadius: 2
941
- },
942
- description: s.no_relevant_insights_card_description,
943
- hasCardEffect: !0,
944
- heightOverrides: e,
945
- icon: r && /* @__PURE__ */ i(f, { bgColor: T(p.palette.primary.main, 0.15), name: "lightbulb" }),
946
- onCardClick: u,
947
- onPrimaryAction: u,
948
- primaryActionText: s.micro_card_cta,
949
- title: s.no_relevant_insights_card_title,
950
- variant: a
951
- }
952
- );
953
- }, Jt = U(De), ve = ({
954
- ariaLabel: t,
955
- heightOverrides: e,
956
- onCardClick: o,
957
- showIcon: n,
958
- variant: r
959
- }) => {
960
- const { onPageview: a } = we(), { zeroStateCopy: s } = x(), p = j();
961
- return h.useEffect(() => {
962
- a(G.MICRO_WIDGET_CAROUSEL_ZERO_STATE);
963
- }, []), /* @__PURE__ */ i(
964
- q,
965
- {
966
- ariaLabel: t,
967
- cardSx: {
968
- borderRadius: 2
969
- },
970
- description: s.carousel_zero_state_description,
971
- hasCardEffect: !0,
972
- heightOverrides: e,
973
- icon: n && /* @__PURE__ */ i(f, { bgColor: T(p.palette.primary.main, 0.15), name: "lightbulb" }),
974
- onCardClick: o,
975
- title: s.carousel_zero_state_title,
976
- variant: r
977
- }
978
- );
979
- }, eo = U(ve), yt = () => /* @__PURE__ */ i(
980
- $,
981
- {
982
- sx: {
983
- alignItems: "center",
984
- display: "flex",
985
- height: "100%",
986
- justifyContent: "center",
987
- width: "100%"
988
- },
989
- children: /* @__PURE__ */ i(He, {})
990
- }
991
- ), V = new nt(), Wt = ({
992
- allowSingleCardPeeking: t,
993
- areBeatsLoading: e,
994
- beats: o = [],
995
- // This also determines the length of the carousel controls (beat.length + 1)
996
- showCTAColocatedWithText: n = !0,
997
- endpoint: r = "/",
998
- heightOverrides: a,
999
- headerSx: s,
1000
- logOutUser: p,
1001
- onCardClick: m = () => {
1002
- },
1003
- onEvent: C = () => {
1004
- },
1005
- onPageview: u = () => {
1006
- },
1007
- posthog: c,
1008
- showBorder: _ = !0,
1009
- showCarouselControls: l,
1010
- showHeader: A,
1011
- showIcon: E,
1012
- showWithMargin: S = !0,
1013
- token: g = "",
1014
- userHasFullInsightFeedBeats: b,
1015
- variant: M,
1016
- visibleCardsCount: k = 1,
1017
- widthOverrides: I
1018
- }) => {
1019
- const [P, w] = ie("STANDARD"), [d, J] = ie(!1), [Z, Q] = ie(!1), ee = je([C], V), te = Ye([u], V);
1020
- Xe({
1021
- widgetName: "InsightsMicroWidget",
1022
- isLoaded: d
1023
- }), h.useEffect(() => {
1024
- !V.isInitialized && !Z && (V.initialize(r, g, p).catch(() => Q(!1)), Q(!0));
1025
- }, [r, g, p, V.isInitialized, Z]), h.useEffect(() => {
1026
- const B = window.innerHeight;
1027
- B < 180 ? w("STANDARD") : B >= 180 && B < 200 ? w("LARGE") : B >= 200 && B < 248 ? w("XLARGE") : B >= 248 && w("XXLARGE");
1028
- }, [window.innerHeight]), h.useEffect(() => {
1029
- J(!e && V.isInitialized);
1030
- }, [e, V.isInitialized]);
1031
- const oe = {
1032
- showCTAColocatedWithText: n,
1033
- heightOverrides: a,
1034
- onCardClick: m,
1035
- posthog: c,
1036
- showIcon: E,
1037
- showWithMargin: S,
1038
- widthOverrides: I
1039
- }, K = {
1040
- carouselSize: P,
1041
- variant: M,
1042
- showCTAColocatedWithText: n,
1043
- heightOverrides: a,
1044
- onCardClick: m,
1045
- posthog: c,
1046
- showIcon: E
1047
- };
1048
- return /* @__PURE__ */ i(rt, { onEvent: ee, onPageview: te, store: V, children: /* @__PURE__ */ N(Ot, { heightOverrides: a, widthOverrides: I, children: [
1049
- !d && /* @__PURE__ */ i(yt, {}),
1050
- d && A && /* @__PURE__ */ i(
1051
- Rt,
1052
- {
1053
- analyticsMetadata: Ce,
1054
- headerSx: s,
1055
- onCardClick: m,
1056
- posthog: c,
1057
- widthOverrides: I
1058
- }
1059
- ),
1060
- d && !!o.length && /* @__PURE__ */ i(
1061
- Tt,
1062
- {
1063
- allowSingleCardPeeking: t,
1064
- analyticsMetadata: Ce,
1065
- beats: o,
1066
- showCarouselControls: l,
1067
- variant: _ ? M : void 0,
1068
- visibleCardsCount: k,
1069
- ...oe
1070
- }
1071
- ),
1072
- d && !o.length && /* @__PURE__ */ i(
1073
- W,
1074
- {
1075
- sx: {
1076
- alignItems: "center",
1077
- height: a,
1078
- width: I || "100%"
1079
- },
1080
- children: /* @__PURE__ */ i(
1081
- W,
1082
- {
1083
- sx: {
1084
- height: `calc(${mt[P]}px - 44px)`,
1085
- width: S ? `calc(${I}px - 32px)` : "100%"
1086
- },
1087
- children: b ? /* @__PURE__ */ i(De, { ...K }) : /* @__PURE__ */ i(ve, { ...K })
1088
- }
1089
- )
1090
- }
1091
- )
1092
- ] }) });
1093
- }, to = U(Wt), Nt = ({
1094
- ariaLabel: t,
1095
- heightOverrides: e,
1096
- isActiveCard: o,
1097
- onCardClick: n,
1098
- posthog: r,
1099
- widthOverrides: a,
1100
- showIcon: s,
1101
- variant: p
1102
- }) => {
1103
- const m = j(), { ref: C, inView: u } = Re({
1104
- threshold: Le
1105
- }), { cardsCopy: c } = x(), { onEvent: _ } = X();
1106
- ne(() => {
1107
- u && (_(Me.ON_VIEW_MORE_VIEWED), r?.capture("viewed_insight", {
1108
- template: "view_more_card"
1109
- }));
1110
- }, [u]);
1111
- const l = () => {
1112
- n && n(), _(O.ON_VIEW_MORE_CLICKED), r?.capture("clicked_insight", {
1113
- template: "view_more_card"
1114
- });
1115
- };
1116
- return /* @__PURE__ */ i(
1117
- q,
1118
- {
1119
- "aria-roledescription": "slide",
1120
- ariaLabel: t,
1121
- cardSx: {
1122
- borderRadius: 2
1123
- },
1124
- description: c.view_more_card_description,
1125
- hasCardEffect: !0,
1126
- heightOverrides: e,
1127
- icon: s && /* @__PURE__ */ i(f, { bgColor: T(m.palette.primary.main, 0.15), name: "show_chart" }),
1128
- isActiveCard: o,
1129
- onCardClick: l,
1130
- onPrimaryAction: l,
1131
- primaryActionText: c.micro_card_cta,
1132
- ref: C,
1133
- title: c.view_more_card_title,
1134
- variant: p,
1135
- widthOverrides: a
1136
- }
1137
- );
1138
- }, Mt = U(Nt);
1139
- export {
1140
- nt as A,
1141
- f as B,
1142
- Rt as C,
1143
- rt as I,
1144
- Tt as M,
1145
- Jt as N,
1146
- Ce as T,
1147
- Mt as V,
1148
- eo as Z,
1149
- gt as a,
1150
- to as b,
1151
- _t as c,
1152
- q as d
1153
- };