@notificationapi/react 1.6.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/assets/Badge.js +4 -3
  2. package/dist/assets/Box.js +26 -24
  3. package/dist/assets/Button.js +20 -18
  4. package/dist/assets/ButtonBase.js +193 -185
  5. package/dist/assets/DefaultPropsProvider.js +416 -4199
  6. package/dist/assets/DefaultPropsProvider2.js +992 -0
  7. package/dist/assets/Divider.js +2 -1
  8. package/dist/assets/GlobalStyles.js +23 -0
  9. package/dist/assets/Grow.js +87 -92
  10. package/dist/assets/IconButton.js +8 -7
  11. package/dist/assets/List.js +12 -11
  12. package/dist/assets/Modal.js +18 -17
  13. package/dist/assets/Notification.js +787 -770
  14. package/dist/assets/Paper.js +6 -6
  15. package/dist/assets/Popover.js +38 -37
  16. package/dist/assets/Portal.js +38 -48
  17. package/dist/assets/Stack.js +32 -30
  18. package/dist/assets/Typography.js +84 -97
  19. package/dist/assets/createSvgIcon.js +25 -24
  20. package/dist/assets/createTheme.js +2828 -0
  21. package/dist/assets/dividerClasses.js +16 -15
  22. package/dist/assets/exactProp.js +13 -0
  23. package/dist/assets/index.js +19 -148
  24. package/dist/assets/index2.js +151 -0
  25. package/dist/assets/useTheme.js +6 -7
  26. package/dist/assets/{useTheme2.js → useThemeWithoutDefault.js} +63 -67
  27. package/dist/assets/utils.js +2 -2
  28. package/dist/components/Notifications/DefaultEmpty.d.ts +0 -1
  29. package/dist/components/Notifications/Inbox.d.ts +0 -1
  30. package/dist/components/Notifications/Inbox.js +592 -582
  31. package/dist/components/Notifications/InboxHeader.js +31 -30
  32. package/dist/components/Notifications/Notification.d.ts +0 -1
  33. package/dist/components/Notifications/Notification.js +4 -2
  34. package/dist/components/Notifications/NotificationCounter.d.ts +0 -1
  35. package/dist/components/Notifications/NotificationFeed.d.ts +0 -1
  36. package/dist/components/Notifications/NotificationFeed.js +40 -32
  37. package/dist/components/Notifications/NotificationLauncher.d.ts +0 -1
  38. package/dist/components/Notifications/NotificationLauncher.js +90 -64
  39. package/dist/components/Notifications/NotificationPopup.d.ts +0 -1
  40. package/dist/components/Notifications/NotificationPopup.js +76 -65
  41. package/dist/components/Notifications/UnreadBadge.d.ts +0 -1
  42. package/dist/components/Preferences/NotificationPreferencesInline.js +57 -39
  43. package/dist/components/Preferences/NotificationPreferencesPopup.js +111 -99
  44. package/dist/components/Preferences/PreferenceInput.d.ts +0 -1
  45. package/dist/components/Preferences/PreferenceInput.js +427 -414
  46. package/dist/components/Preferences/Preferences.js +329 -278
  47. package/dist/components/Preferences/channelUtils.d.ts +0 -1
  48. package/dist/components/Provider/context.d.ts +0 -1
  49. package/dist/components/Provider/index.d.ts +4 -2
  50. package/dist/components/Provider/index.js +986 -375
  51. package/dist/components/Slack/SlackConnect.js +8 -7
  52. package/dist/components/WebPush/WebPushOptInMessage.d.ts +0 -1
  53. package/dist/main.d.ts +2 -1
  54. package/dist/main.js +6 -3
  55. package/dist/utils/theme.d.ts +17 -0
  56. package/dist/utils/theme.js +104 -0
  57. package/package.json +7 -3
@@ -1,45 +1,650 @@
1
- import { jsx as oe } from "react/jsx-runtime";
2
- import { useMemo as K, useState as k, useCallback as A, useRef as F, useEffect as E, useContext as ie } from "react";
3
- import { NotificationAPIContext as B } from "./context.js";
4
- import { createDebugLogger as ne, formatApiCall as C } from "../../utils/debug.js";
5
- const re = async (o, e, d, a, c, p, I, l) => {
6
- const h = se(a, c, p), b = `https://${e}/${a}/users/${encodeURIComponent(
7
- c
8
- )}/${d}`, w = {
9
- Authorization: `Basic ${h}`
1
+ import { jsx as M, jsxs as He } from "react/jsx-runtime";
2
+ import * as w from "react";
3
+ import { useMemo as pe, useState as F, useCallback as B, useRef as Se, useEffect as ce, useContext as Ge } from "react";
4
+ import { NotificationAPIContext as je } from "./context.js";
5
+ import { createDebugLogger as ze, formatApiCall as ae } from "../../utils/debug.js";
6
+ import { createNotificationAPITheme as Oe } from "../../utils/theme.js";
7
+ import { a as Be, D as Je, T as J } from "../../assets/DefaultPropsProvider2.js";
8
+ import { P as I, c as Ye, t as Qe, s as Xe } from "../../assets/createTheme.js";
9
+ import { R as Ze } from "../../assets/index.js";
10
+ import { u as et } from "../../assets/useThemeWithoutDefault.js";
11
+ import { e as Ve } from "../../assets/exactProp.js";
12
+ import { G as tt } from "../../assets/GlobalStyles.js";
13
+ const we = /* @__PURE__ */ w.createContext(null);
14
+ process.env.NODE_ENV !== "production" && (we.displayName = "ThemeContext");
15
+ function be() {
16
+ const t = w.useContext(we);
17
+ return process.env.NODE_ENV !== "production" && w.useDebugValue(t), t;
18
+ }
19
+ const ot = typeof Symbol == "function" && Symbol.for, nt = ot ? Symbol.for("mui.nested") : "__THEME_NESTED__";
20
+ function it(t, e) {
21
+ if (typeof e == "function") {
22
+ const c = e(t);
23
+ return process.env.NODE_ENV !== "production" && (c || console.error(["MUI: You should return an object from your theme function, i.e.", "<ThemeProvider theme={() => ({})} />"].join(`
24
+ `))), c;
25
+ }
26
+ return {
27
+ ...t,
28
+ ...e
10
29
  };
11
- l && l.log("HTTP Request:", {
12
- method: o,
30
+ }
31
+ function ge(t) {
32
+ const {
33
+ children: e,
34
+ theme: c
35
+ } = t, n = be();
36
+ process.env.NODE_ENV !== "production" && n === null && typeof c == "function" && console.error(["MUI: You are providing a theme function prop to the ThemeProvider component:", "<ThemeProvider theme={outerTheme => outerTheme} />", "", "However, no outer theme is present.", "Make sure a theme is already injected higher in the React tree or provide a theme object."].join(`
37
+ `));
38
+ const l = w.useMemo(() => {
39
+ const u = n === null ? {
40
+ ...c
41
+ } : it(n, c);
42
+ return u != null && (u[nt] = n !== null), u;
43
+ }, [c, n]);
44
+ return /* @__PURE__ */ M(we.Provider, {
45
+ value: l,
46
+ children: e
47
+ });
48
+ }
49
+ process.env.NODE_ENV !== "production" && (ge.propTypes = {
50
+ /**
51
+ * Your component tree.
52
+ */
53
+ children: I.node,
54
+ /**
55
+ * A theme object. You can provide a function to extend the outer theme.
56
+ */
57
+ theme: I.oneOfType([I.object, I.func]).isRequired
58
+ });
59
+ process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && (ge.propTypes = Ve(ge.propTypes));
60
+ const $e = {};
61
+ function Le(t, e, c, n = !1) {
62
+ return w.useMemo(() => {
63
+ const l = t && e[t] || e;
64
+ if (typeof c == "function") {
65
+ const u = c(l), d = t ? {
66
+ ...e,
67
+ [t]: u
68
+ } : u;
69
+ return n ? () => d : d;
70
+ }
71
+ return t ? {
72
+ ...e,
73
+ [t]: c
74
+ } : {
75
+ ...e,
76
+ ...c
77
+ };
78
+ }, [t, e, c, n]);
79
+ }
80
+ function de(t) {
81
+ const {
82
+ children: e,
83
+ theme: c,
84
+ themeId: n
85
+ } = t, l = et($e), u = be() || $e;
86
+ process.env.NODE_ENV !== "production" && (l === null && typeof c == "function" || n && l && !l[n] && typeof c == "function") && console.error(["MUI: You are providing a theme function prop to the ThemeProvider component:", "<ThemeProvider theme={outerTheme => outerTheme} />", "", "However, no outer theme is present.", "Make sure a theme is already injected higher in the React tree or provide a theme object."].join(`
87
+ `));
88
+ const d = Le(n, l, c), f = Le(n, u, c, !0), k = (n ? d[n] : d).direction === "rtl";
89
+ return /* @__PURE__ */ M(ge, {
90
+ theme: f,
91
+ children: /* @__PURE__ */ M(Be.Provider, {
92
+ value: d,
93
+ children: /* @__PURE__ */ M(Ze, {
94
+ value: k,
95
+ children: /* @__PURE__ */ M(Je, {
96
+ value: n ? d[n].components : d.components,
97
+ children: e
98
+ })
99
+ })
100
+ })
101
+ });
102
+ }
103
+ process.env.NODE_ENV !== "production" && (de.propTypes = {
104
+ // ┌────────────────────────────── Warning ──────────────────────────────┐
105
+ // │ These PropTypes are generated from the TypeScript type definitions. │
106
+ // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
107
+ // └─────────────────────────────────────────────────────────────────────┘
108
+ /**
109
+ * Your component tree.
110
+ */
111
+ children: I.node,
112
+ /**
113
+ * A theme object. You can provide a function to extend the outer theme.
114
+ */
115
+ theme: I.oneOfType([I.func, I.object]).isRequired,
116
+ /**
117
+ * The design system's unique id for getting the corresponded theme when there are multiple design systems.
118
+ */
119
+ themeId: I.string
120
+ });
121
+ process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && (de.propTypes = Ve(de.propTypes));
122
+ const ke = "mode", Ce = "color-scheme", rt = "data-color-scheme";
123
+ function st(t) {
124
+ const {
125
+ defaultMode: e = "system",
126
+ defaultLightColorScheme: c = "light",
127
+ defaultDarkColorScheme: n = "dark",
128
+ modeStorageKey: l = ke,
129
+ colorSchemeStorageKey: u = Ce,
130
+ attribute: d = rt,
131
+ colorSchemeNode: f = "document.documentElement",
132
+ nonce: k
133
+ } = t || {};
134
+ let S = "", y = d;
135
+ if (d === "class" && (y = ".%s"), d === "data" && (y = "[data-%s]"), y.startsWith(".")) {
136
+ const b = y.substring(1);
137
+ S += `${f}.classList.remove('${b}'.replace('%s', light), '${b}'.replace('%s', dark));
138
+ ${f}.classList.add('${b}'.replace('%s', colorScheme));`;
139
+ }
140
+ const P = y.match(/\[([^\]]+)\]/);
141
+ if (P) {
142
+ const [b, N] = P[1].split("=");
143
+ N || (S += `${f}.removeAttribute('${b}'.replace('%s', light));
144
+ ${f}.removeAttribute('${b}'.replace('%s', dark));`), S += `
145
+ ${f}.setAttribute('${b}'.replace('%s', colorScheme), ${N ? `${N}.replace('%s', colorScheme)` : '""'});`;
146
+ } else
147
+ S += `${f}.setAttribute('${y}', colorScheme);`;
148
+ return /* @__PURE__ */ M("script", {
149
+ suppressHydrationWarning: !0,
150
+ nonce: typeof window > "u" ? k : "",
151
+ dangerouslySetInnerHTML: {
152
+ __html: `(function() {
153
+ try {
154
+ let colorScheme = '';
155
+ const mode = localStorage.getItem('${l}') || '${e}';
156
+ const dark = localStorage.getItem('${u}-dark') || '${n}';
157
+ const light = localStorage.getItem('${u}-light') || '${c}';
158
+ if (mode === 'system') {
159
+ // handle system mode
160
+ const mql = window.matchMedia('(prefers-color-scheme: dark)');
161
+ if (mql.matches) {
162
+ colorScheme = dark
163
+ } else {
164
+ colorScheme = light
165
+ }
166
+ }
167
+ if (mode === 'light') {
168
+ colorScheme = light;
169
+ }
170
+ if (mode === 'dark') {
171
+ colorScheme = dark;
172
+ }
173
+ if (colorScheme) {
174
+ ${S}
175
+ }
176
+ } catch(e){}})();`
177
+ }
178
+ }, "mui-color-scheme-init");
179
+ }
180
+ function Ue(t) {
181
+ if (typeof window < "u" && typeof window.matchMedia == "function" && t === "system")
182
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
183
+ }
184
+ function _e(t, e) {
185
+ if (t.mode === "light" || t.mode === "system" && t.systemMode === "light")
186
+ return e("light");
187
+ if (t.mode === "dark" || t.mode === "system" && t.systemMode === "dark")
188
+ return e("dark");
189
+ }
190
+ function ct(t) {
191
+ return _e(t, (e) => {
192
+ if (e === "light")
193
+ return t.lightColorScheme;
194
+ if (e === "dark")
195
+ return t.darkColorScheme;
196
+ });
197
+ }
198
+ function ye(t, e) {
199
+ if (typeof window > "u")
200
+ return;
201
+ let c;
202
+ try {
203
+ c = localStorage.getItem(t) || void 0, c || localStorage.setItem(t, e);
204
+ } catch {
205
+ }
206
+ return c || e;
207
+ }
208
+ function at(t) {
209
+ const {
210
+ defaultMode: e = "light",
211
+ defaultLightColorScheme: c,
212
+ defaultDarkColorScheme: n,
213
+ supportedColorSchemes: l = [],
214
+ modeStorageKey: u = ke,
215
+ colorSchemeStorageKey: d = Ce,
216
+ storageWindow: f = typeof window > "u" ? void 0 : window,
217
+ noSsr: k = !1
218
+ } = t, S = l.join(","), y = l.length > 1, [P, b] = w.useState(() => {
219
+ const h = ye(u, e), g = ye(`${d}-light`, c), m = ye(`${d}-dark`, n);
220
+ return {
221
+ mode: h,
222
+ systemMode: Ue(h),
223
+ lightColorScheme: g,
224
+ darkColorScheme: m
225
+ };
226
+ }), [N, K] = w.useState(k || !y);
227
+ w.useEffect(() => {
228
+ K(!0);
229
+ }, []);
230
+ const G = ct(P), R = w.useCallback((h) => {
231
+ b((g) => {
232
+ if (h === g.mode)
233
+ return g;
234
+ const m = h ?? e;
235
+ try {
236
+ localStorage.setItem(u, m);
237
+ } catch {
238
+ }
239
+ return {
240
+ ...g,
241
+ mode: m,
242
+ systemMode: Ue(m)
243
+ };
244
+ });
245
+ }, [u, e]), A = w.useCallback((h) => {
246
+ h ? typeof h == "string" ? h && !S.includes(h) ? console.error(`\`${h}\` does not exist in \`theme.colorSchemes\`.`) : b((g) => {
247
+ const m = {
248
+ ...g
249
+ };
250
+ return _e(g, (D) => {
251
+ try {
252
+ localStorage.setItem(`${d}-${D}`, h);
253
+ } catch {
254
+ }
255
+ D === "light" && (m.lightColorScheme = h), D === "dark" && (m.darkColorScheme = h);
256
+ }), m;
257
+ }) : b((g) => {
258
+ const m = {
259
+ ...g
260
+ }, D = h.light === null ? c : h.light, p = h.dark === null ? n : h.dark;
261
+ if (D)
262
+ if (!S.includes(D))
263
+ console.error(`\`${D}\` does not exist in \`theme.colorSchemes\`.`);
264
+ else {
265
+ m.lightColorScheme = D;
266
+ try {
267
+ localStorage.setItem(`${d}-light`, D);
268
+ } catch {
269
+ }
270
+ }
271
+ if (p)
272
+ if (!S.includes(p))
273
+ console.error(`\`${p}\` does not exist in \`theme.colorSchemes\`.`);
274
+ else {
275
+ m.darkColorScheme = p;
276
+ try {
277
+ localStorage.setItem(`${d}-dark`, p);
278
+ } catch {
279
+ }
280
+ }
281
+ return m;
282
+ }) : b((g) => {
283
+ try {
284
+ localStorage.setItem(`${d}-light`, c), localStorage.setItem(`${d}-dark`, n);
285
+ } catch {
286
+ }
287
+ return {
288
+ ...g,
289
+ lightColorScheme: c,
290
+ darkColorScheme: n
291
+ };
292
+ });
293
+ }, [S, d, c, n]), j = w.useCallback((h) => {
294
+ P.mode === "system" && b((g) => {
295
+ const m = h != null && h.matches ? "dark" : "light";
296
+ return g.systemMode === m ? g : {
297
+ ...g,
298
+ systemMode: m
299
+ };
300
+ });
301
+ }, [P.mode]), _ = w.useRef(j);
302
+ return _.current = j, w.useEffect(() => {
303
+ if (typeof window.matchMedia != "function" || !y)
304
+ return;
305
+ const h = (...m) => _.current(...m), g = window.matchMedia("(prefers-color-scheme: dark)");
306
+ return g.addListener(h), h(g), () => {
307
+ g.removeListener(h);
308
+ };
309
+ }, [y]), w.useEffect(() => {
310
+ if (f && y) {
311
+ const h = (g) => {
312
+ const m = g.newValue;
313
+ typeof g.key == "string" && g.key.startsWith(d) && (!m || S.match(m)) && (g.key.endsWith("light") && A({
314
+ light: m
315
+ }), g.key.endsWith("dark") && A({
316
+ dark: m
317
+ })), g.key === u && (!m || ["light", "dark", "system"].includes(m)) && R(m || e);
318
+ };
319
+ return f.addEventListener("storage", h), () => {
320
+ f.removeEventListener("storage", h);
321
+ };
322
+ }
323
+ }, [A, R, u, d, S, e, f, y]), {
324
+ ...P,
325
+ mode: N ? P.mode : void 0,
326
+ systemMode: N ? P.systemMode : void 0,
327
+ colorScheme: N ? G : void 0,
328
+ setMode: R,
329
+ setColorScheme: A
330
+ };
331
+ }
332
+ const dt = "*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
333
+ function lt(t) {
334
+ const {
335
+ themeId: e,
336
+ /**
337
+ * This `theme` object needs to follow a certain structure to
338
+ * be used correctly by the finel `CssVarsProvider`. It should have a
339
+ * `colorSchemes` key with the light and dark (and any other) palette.
340
+ * It should also ideally have a vars object created using `prepareCssVars`.
341
+ */
342
+ theme: c = {},
343
+ modeStorageKey: n = ke,
344
+ colorSchemeStorageKey: l = Ce,
345
+ disableTransitionOnChange: u = !1,
346
+ defaultColorScheme: d,
347
+ resolveTheme: f
348
+ } = t, k = {
349
+ allColorSchemes: [],
350
+ colorScheme: void 0,
351
+ darkColorScheme: void 0,
352
+ lightColorScheme: void 0,
353
+ mode: void 0,
354
+ setColorScheme: () => {
355
+ },
356
+ setMode: () => {
357
+ },
358
+ systemMode: void 0
359
+ }, S = /* @__PURE__ */ w.createContext(void 0);
360
+ process.env.NODE_ENV !== "production" && (S.displayName = "ColorSchemeContext");
361
+ const y = () => w.useContext(S) || k, P = {}, b = {};
362
+ function N(A) {
363
+ var Te, Me, Ae, De;
364
+ const {
365
+ children: j,
366
+ theme: _,
367
+ modeStorageKey: h = n,
368
+ colorSchemeStorageKey: g = l,
369
+ disableTransitionOnChange: m = u,
370
+ storageWindow: D = typeof window > "u" ? void 0 : window,
371
+ documentNode: p = typeof document > "u" ? void 0 : document,
372
+ colorSchemeNode: L = typeof document > "u" ? void 0 : document.documentElement,
373
+ disableNestedContext: Y = !1,
374
+ disableStyleSheetGeneration: Q = !1,
375
+ defaultMode: le = "system",
376
+ noSsr: X
377
+ } = A, Z = w.useRef(!1), ee = be(), te = w.useContext(S), oe = !!te && !Y, ue = w.useMemo(() => _ || (typeof c == "function" ? c() : c), [_]), ne = ue[e], T = ne || ue, {
378
+ colorSchemes: W = P,
379
+ components: fe = b,
380
+ cssVarPrefix: o
381
+ } = T, r = Object.keys(W).filter((E) => !!W[E]).join(","), i = w.useMemo(() => r.split(","), [r]), a = typeof d == "string" ? d : d.light, C = typeof d == "string" ? d : d.dark, v = W[a] && W[C] ? le : ((Me = (Te = W[T.defaultColorScheme]) == null ? void 0 : Te.palette) == null ? void 0 : Me.mode) || ((Ae = T.palette) == null ? void 0 : Ae.mode), {
382
+ mode: q,
383
+ setMode: H,
384
+ systemMode: ie,
385
+ lightColorScheme: Ie,
386
+ darkColorScheme: Ne,
387
+ colorScheme: Ke,
388
+ setColorScheme: ve
389
+ } = at({
390
+ supportedColorSchemes: i,
391
+ defaultLightColorScheme: a,
392
+ defaultDarkColorScheme: C,
393
+ modeStorageKey: h,
394
+ colorSchemeStorageKey: g,
395
+ defaultMode: v,
396
+ storageWindow: D,
397
+ noSsr: X
398
+ });
399
+ let me = q, U = Ke;
400
+ oe && (me = te.mode, U = te.colorScheme);
401
+ const z = w.useMemo(() => {
402
+ var se;
403
+ const E = U || T.defaultColorScheme, O = ((se = T.generateThemeVars) == null ? void 0 : se.call(T)) || T.vars, $ = {
404
+ ...T,
405
+ components: fe,
406
+ colorSchemes: W,
407
+ cssVarPrefix: o,
408
+ vars: O
409
+ };
410
+ if (typeof $.generateSpacing == "function" && ($.spacing = $.generateSpacing()), E) {
411
+ const x = W[E];
412
+ x && typeof x == "object" && Object.keys(x).forEach((V) => {
413
+ x[V] && typeof x[V] == "object" ? $[V] = {
414
+ ...$[V],
415
+ ...x[V]
416
+ } : $[V] = x[V];
417
+ });
418
+ }
419
+ return f ? f($) : $;
420
+ }, [T, U, fe, W, o]), re = T.colorSchemeSelector;
421
+ w.useEffect(() => {
422
+ if (U && L && re && re !== "media") {
423
+ const E = re;
424
+ let O = re;
425
+ if (E === "class" && (O = ".%s"), E === "data" && (O = "[data-%s]"), E != null && E.startsWith("data-") && !E.includes("%s") && (O = `[${E}="%s"]`), O.startsWith("."))
426
+ L.classList.remove(...i.map(($) => O.substring(1).replace("%s", $))), L.classList.add(O.substring(1).replace("%s", U));
427
+ else {
428
+ const $ = O.replace("%s", U).match(/\[([^\]]+)\]/);
429
+ if ($) {
430
+ const [se, x] = $[1].split("=");
431
+ x || i.forEach((V) => {
432
+ L.removeAttribute(se.replace(U, V));
433
+ }), L.setAttribute(se, x ? x.replace(/"|'/g, "") : "");
434
+ } else
435
+ L.setAttribute(O, U);
436
+ }
437
+ }
438
+ }, [U, re, L, i]), w.useEffect(() => {
439
+ let E;
440
+ if (m && Z.current && p) {
441
+ const O = p.createElement("style");
442
+ O.appendChild(p.createTextNode(dt)), p.head.appendChild(O), window.getComputedStyle(p.body), E = setTimeout(() => {
443
+ p.head.removeChild(O);
444
+ }, 1);
445
+ }
446
+ return () => {
447
+ clearTimeout(E);
448
+ };
449
+ }, [U, m, p]), w.useEffect(() => (Z.current = !0, () => {
450
+ Z.current = !1;
451
+ }), []);
452
+ const qe = w.useMemo(() => ({
453
+ allColorSchemes: i,
454
+ colorScheme: U,
455
+ darkColorScheme: Ne,
456
+ lightColorScheme: Ie,
457
+ mode: me,
458
+ setColorScheme: ve,
459
+ setMode: process.env.NODE_ENV === "production" ? H : (E) => {
460
+ z.colorSchemeSelector === "media" && console.error(["MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).", "To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.", "To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually"].join(`
461
+ `)), H(E);
462
+ },
463
+ systemMode: ie
464
+ }), [i, U, Ne, Ie, me, ve, H, ie, z.colorSchemeSelector]);
465
+ let Pe = !0;
466
+ (Q || T.cssVariables === !1 || oe && (ee == null ? void 0 : ee.cssVarPrefix) === o) && (Pe = !1);
467
+ const Ee = /* @__PURE__ */ He(w.Fragment, {
468
+ children: [/* @__PURE__ */ M(de, {
469
+ themeId: ne ? e : void 0,
470
+ theme: z,
471
+ children: j
472
+ }), Pe && /* @__PURE__ */ M(tt, {
473
+ styles: ((De = z.generateStyleSheets) == null ? void 0 : De.call(z)) || []
474
+ })]
475
+ });
476
+ return oe ? Ee : /* @__PURE__ */ M(S.Provider, {
477
+ value: qe,
478
+ children: Ee
479
+ });
480
+ }
481
+ process.env.NODE_ENV !== "production" && (N.propTypes = {
482
+ /**
483
+ * The component tree.
484
+ */
485
+ children: I.node,
486
+ /**
487
+ * The node used to attach the color-scheme attribute
488
+ */
489
+ colorSchemeNode: I.any,
490
+ /**
491
+ * localStorage key used to store `colorScheme`
492
+ */
493
+ colorSchemeStorageKey: I.string,
494
+ /**
495
+ * The default mode when the storage is empty,
496
+ * require the theme to have `colorSchemes` with light and dark.
497
+ */
498
+ defaultMode: I.string,
499
+ /**
500
+ * If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
501
+ */
502
+ disableNestedContext: I.bool,
503
+ /**
504
+ * If `true`, the style sheet won't be generated.
505
+ *
506
+ * This is useful for controlling nested CssVarsProvider behavior.
507
+ */
508
+ disableStyleSheetGeneration: I.bool,
509
+ /**
510
+ * Disable CSS transitions when switching between modes or color schemes.
511
+ */
512
+ disableTransitionOnChange: I.bool,
513
+ /**
514
+ * The document to attach the attribute to.
515
+ */
516
+ documentNode: I.any,
517
+ /**
518
+ * The key in the local storage used to store current color scheme.
519
+ */
520
+ modeStorageKey: I.string,
521
+ /**
522
+ * If `true`, the mode will be the same value as the storage without an extra rerendering after the hydration.
523
+ * You should use this option in conjuction with `InitColorSchemeScript` component.
524
+ */
525
+ noSsr: I.bool,
526
+ /**
527
+ * The window that attaches the 'storage' event listener.
528
+ * @default window
529
+ */
530
+ storageWindow: I.any,
531
+ /**
532
+ * The calculated theme object that will be passed through context.
533
+ */
534
+ theme: I.object
535
+ });
536
+ const K = typeof d == "string" ? d : d.light, G = typeof d == "string" ? d : d.dark;
537
+ return {
538
+ CssVarsProvider: N,
539
+ useColorScheme: y,
540
+ getInitColorSchemeScript: (A) => st({
541
+ colorSchemeStorageKey: l,
542
+ defaultLightColorScheme: K,
543
+ defaultDarkColorScheme: G,
544
+ modeStorageKey: n,
545
+ ...A
546
+ })
547
+ };
548
+ }
549
+ function xe({
550
+ theme: t,
551
+ ...e
552
+ }) {
553
+ const c = J in t ? t[J] : void 0;
554
+ return /* @__PURE__ */ M(de, {
555
+ ...e,
556
+ themeId: c ? J : void 0,
557
+ theme: c || t
558
+ });
559
+ }
560
+ const he = {
561
+ attribute: "data-mui-color-scheme",
562
+ colorSchemeStorageKey: "mui-color-scheme",
563
+ defaultLightColorScheme: "light",
564
+ defaultDarkColorScheme: "dark",
565
+ modeStorageKey: "mui-mode"
566
+ }, {
567
+ CssVarsProvider: ut,
568
+ useColorScheme: At,
569
+ getInitColorSchemeScript: Dt
570
+ } = lt({
571
+ themeId: J,
572
+ // @ts-ignore ignore module augmentation tests
573
+ theme: () => Ye({
574
+ cssVariables: !0
575
+ }),
576
+ colorSchemeStorageKey: he.colorSchemeStorageKey,
577
+ modeStorageKey: he.modeStorageKey,
578
+ defaultColorScheme: {
579
+ light: he.defaultLightColorScheme,
580
+ dark: he.defaultDarkColorScheme
581
+ },
582
+ resolveTheme: (t) => {
583
+ const e = {
584
+ ...t,
585
+ typography: Qe(t.palette, t.typography)
586
+ };
587
+ return e.unstable_sx = function(n) {
588
+ return Xe({
589
+ sx: n,
590
+ theme: this
591
+ });
592
+ }, e;
593
+ }
594
+ }), ft = ut;
595
+ function ht({
596
+ theme: t,
597
+ ...e
598
+ }) {
599
+ return typeof t == "function" ? /* @__PURE__ */ M(xe, {
600
+ theme: t,
601
+ ...e
602
+ }) : "colorSchemes" in (J in t ? t[J] : t) ? /* @__PURE__ */ M(ft, {
603
+ theme: t,
604
+ ...e
605
+ }) : /* @__PURE__ */ M(xe, {
606
+ theme: t,
607
+ ...e
608
+ });
609
+ }
610
+ const gt = async (t, e, c, n, l, u, d, f) => {
611
+ const k = mt(n, l, u), S = `https://${e}/${n}/users/${encodeURIComponent(
612
+ l
613
+ )}/${c}`, y = {
614
+ Authorization: `Basic ${k}`
615
+ };
616
+ f && f.log("HTTP Request:", {
617
+ method: t,
13
618
  host: e,
14
- url: b,
15
- body: I
619
+ url: S,
620
+ body: d
16
621
  });
17
- const N = Date.now();
622
+ const P = Date.now();
18
623
  try {
19
- const m = await fetch(b, {
20
- method: o,
21
- body: JSON.stringify(I),
22
- headers: w
624
+ const b = await fetch(S, {
625
+ method: t,
626
+ body: JSON.stringify(d),
627
+ headers: y
23
628
  });
24
- l && l.log("HTTP Response:", m);
629
+ f && f.log("HTTP Response:", b);
25
630
  try {
26
- const P = await m.json();
27
- return l && l.log("Response Data:", P), P;
28
- } catch (P) {
29
- l && l.warn("Failed to parse response as JSON:", P);
631
+ const N = await b.json();
632
+ return f && f.log("Response Data:", N), N;
633
+ } catch (N) {
634
+ f && f.warn("Failed to parse response as JSON:", N);
30
635
  return;
31
636
  }
32
- } catch (m) {
33
- const P = Date.now() - N;
34
- throw l && l.error("HTTP Request Failed:", {
35
- error: m,
36
- url: b,
37
- headers: w,
38
- duration: `${P}ms`
39
- }), m;
637
+ } catch (b) {
638
+ const N = Date.now() - P;
639
+ throw f && f.error("HTTP Request Failed:", {
640
+ error: b,
641
+ url: S,
642
+ headers: y,
643
+ duration: `${N}ms`
644
+ }), b;
40
645
  }
41
- }, se = (o, e, d) => btoa(d ? o + ":" + e + ":" + d : o + ":" + e);
42
- class G {
646
+ }, mt = (t, e, c) => btoa(c ? t + ":" + e + ":" + c : t + ":" + e);
647
+ class Re {
43
648
  constructor(e = !1) {
44
649
  this.debug = e;
45
650
  }
@@ -53,7 +658,7 @@ class G {
53
658
  this.debug && console.error("[NotificationAPI js core SDK Debug]", ...e);
54
659
  }
55
660
  }
56
- const J = {
661
+ const We = {
57
662
  host: "api.notificationapi.com",
58
663
  websocketHost: "ws.notificationapi.com",
59
664
  userId: "",
@@ -68,11 +673,11 @@ const J = {
68
673
  // 24 hours
69
674
  debug: !1,
70
675
  sdkDevMode: !1
71
- }, n = {
72
- config: J,
73
- logger: new G(!1),
74
- init: function(o) {
75
- return this.config = { ...J, ...o }, this.logger = new G(this.config.debug), this.logger.log("Initialized with config:", {
676
+ }, s = {
677
+ config: We,
678
+ logger: new Re(!1),
679
+ init: function(t) {
680
+ return this.config = { ...We, ...t }, this.logger = new Re(this.config.debug), this.logger.log("Initialized with config:", {
76
681
  userId: this.config.userId,
77
682
  clientId: this.config.clientId,
78
683
  host: this.config.host,
@@ -84,92 +689,92 @@ const J = {
84
689
  };
85
690
  },
86
691
  rest: {
87
- generic: function(o, e, d) {
88
- return n.logger.log(
89
- `API Call: ${o} ${e}`,
90
- d ? { body: d } : ""
91
- ), re(
92
- o,
93
- n.config.host,
692
+ generic: function(t, e, c) {
693
+ return s.logger.log(
694
+ `API Call: ${t} ${e}`,
695
+ c ? { body: c } : ""
696
+ ), gt(
697
+ t,
698
+ s.config.host,
94
699
  e,
95
- n.config.clientId,
96
- n.config.userId,
97
- n.config.hashedUserId,
98
- d,
99
- n.logger
700
+ s.config.clientId,
701
+ s.config.userId,
702
+ s.config.hashedUserId,
703
+ c,
704
+ s.logger
100
705
  );
101
706
  },
102
707
  // The functions below are nice wrappers over the generic
103
708
  // rest api function above. They must follow REST API naming:
104
709
  // Method + Resource, representing the end-point.
105
- getNotifications: function(o, e) {
106
- return n.rest.generic(
710
+ getNotifications: function(t, e) {
711
+ return s.rest.generic(
107
712
  "GET",
108
- `notifications/INAPP_WEB?count=${e}&before=${o}`
713
+ `notifications/INAPP_WEB?count=${e}&before=${t}`
109
714
  );
110
715
  },
111
- patchNotifications: function(o) {
112
- return n.rest.generic(
716
+ patchNotifications: function(t) {
717
+ return s.rest.generic(
113
718
  "PATCH",
114
719
  "notifications/INAPP_WEB",
115
- o
720
+ t
116
721
  );
117
722
  },
118
723
  getPreferences: function() {
119
- return n.rest.generic("GET", "preferences");
724
+ return s.rest.generic("GET", "preferences");
120
725
  },
121
- postPreferences: function(o) {
122
- return n.rest.generic(
726
+ postPreferences: function(t) {
727
+ return s.rest.generic(
123
728
  "POST",
124
729
  "preferences",
125
- o
730
+ t
126
731
  );
127
732
  },
128
- postUser: function(o) {
129
- return n.rest.generic("POST", "", o);
733
+ postUser: function(t) {
734
+ return s.rest.generic("POST", "", t);
130
735
  },
131
736
  getUserAccountMetadata: function() {
132
- return n.rest.generic("GET", "account_metadata");
737
+ return s.rest.generic("GET", "account_metadata");
133
738
  }
134
739
  },
135
740
  websocket: {
136
741
  object: void 0,
137
742
  connect: function() {
138
- let o = `wss://${n.config.websocketHost}?userId=${encodeURIComponent(n.config.userId)}&envId=${n.config.clientId}`;
139
- return n.config.hashedUserId && (o += `&userIdHash=${encodeURIComponent(n.config.hashedUserId)}`), n.logger.log("WebSocket connecting to:", o), n.websocket.object = new WebSocket(o), n.websocket.object.onopen = () => {
140
- n.logger.log("WebSocket connection opened");
141
- }, n.websocket.object.onclose = (e) => {
142
- n.logger.log("WebSocket connection closed:", {
743
+ let t = `wss://${s.config.websocketHost}?userId=${encodeURIComponent(s.config.userId)}&envId=${s.config.clientId}`;
744
+ return s.config.hashedUserId && (t += `&userIdHash=${encodeURIComponent(s.config.hashedUserId)}`), s.logger.log("WebSocket connecting to:", t), s.websocket.object = new WebSocket(t), s.websocket.object.onopen = () => {
745
+ s.logger.log("WebSocket connection opened");
746
+ }, s.websocket.object.onclose = (e) => {
747
+ s.logger.log("WebSocket connection closed:", {
143
748
  code: e.code,
144
749
  reason: e.reason,
145
750
  wasClean: e.wasClean
146
751
  });
147
- }, n.websocket.object.onerror = (e) => {
148
- n.logger.error("WebSocket error:", e);
149
- }, n.websocket.object.onmessage = (e) => {
150
- n.logger.log(
752
+ }, s.websocket.object.onerror = (e) => {
753
+ s.logger.error("WebSocket error:", e);
754
+ }, s.websocket.object.onmessage = (e) => {
755
+ s.logger.log(
151
756
  "WebSocket message received:",
152
757
  e.data
153
758
  );
154
- const d = JSON.parse(e.data);
155
- if (!(!d || !d.route) && d.route === "inapp_web/new_notifications") {
156
- const a = d;
157
- n.logger.log(
759
+ const c = JSON.parse(e.data);
760
+ if (!(!c || !c.route) && c.route === "inapp_web/new_notifications") {
761
+ const n = c;
762
+ s.logger.log(
158
763
  "New notifications received:",
159
- a.payload.notifications
160
- ), n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
161
- a.payload.notifications
764
+ n.payload.notifications
765
+ ), s.config.onNewInAppNotifications && s.config.onNewInAppNotifications(
766
+ n.payload.notifications
162
767
  );
163
768
  }
164
- }, n.websocket.object;
769
+ }, s.websocket.object;
165
770
  },
166
- disconnect: function(o) {
771
+ disconnect: function(t) {
167
772
  var e;
168
- n.websocket.object && (n.logger.log("WebSocket disconnecting"), (e = n.websocket.object) == null || e.close(), o && o(n.websocket.object));
773
+ s.websocket.object && (s.logger.log("WebSocket disconnecting"), (e = s.websocket.object) == null || e.close(), t && t(s.websocket.object));
169
774
  }
170
775
  },
171
776
  openWebSocket: function() {
172
- return n.websocket.connect(() => {
777
+ return s.websocket.connect(() => {
173
778
  setTimeout(
174
779
  () => {
175
780
  this.websocket.disconnect(() => {
@@ -183,106 +788,106 @@ const J = {
183
788
  // These functions are developer friendly wrappers over the rest APIs
184
789
  // They may or may not do additional tasks.
185
790
  // e.g. identify simply maps to postUsers
186
- getInAppNotifications: async (o) => {
187
- n.logger.log(
791
+ getInAppNotifications: async (t) => {
792
+ s.logger.log(
188
793
  "getInAppNotifications called with params:",
189
- o
794
+ t
190
795
  );
191
- const e = o.maxCountNeeded || n.config.getInAppDefaultCount, d = o.oldestNeeded || n.config.getInAppDefaultOldest;
192
- n.logger.log("Fetching notifications with:", {
796
+ const e = t.maxCountNeeded || s.config.getInAppDefaultCount, c = t.oldestNeeded || s.config.getInAppDefaultOldest;
797
+ s.logger.log("Fetching notifications with:", {
193
798
  maxCountNeeded: e,
194
- oldestNeeded: d,
195
- before: o.before
799
+ oldestNeeded: c,
800
+ before: t.before
196
801
  });
197
- let a = [], c = o.before, p = !0, I = !0;
198
- for (; I; ) {
199
- const l = (await n.rest.getNotifications(
200
- c,
802
+ let n = [], l = t.before, u = !0, d = !0;
803
+ for (; d; ) {
804
+ const f = (await s.rest.getNotifications(
805
+ l,
201
806
  e
202
- )).notifications, h = l.filter(
203
- (b) => !a.find((w) => w.id === b.id)
807
+ )).notifications, k = f.filter(
808
+ (S) => !n.find((y) => y.id === S.id)
204
809
  );
205
- n.logger.log(
206
- `Received ${l.length} notifications, ${h.length} unique`
207
- ), c = h.reduce(
208
- (b, w) => b < w.date ? b : w.date,
209
- o.before
210
- ), a = [...a, ...h], p = h.length > 0, I = !0, (!p || a.length >= e || c < d) && (I = !1, n.logger.log("Stopping fetch loop:", {
211
- hasMore: p,
212
- totalResults: a.length,
810
+ s.logger.log(
811
+ `Received ${f.length} notifications, ${k.length} unique`
812
+ ), l = k.reduce(
813
+ (S, y) => S < y.date ? S : y.date,
814
+ t.before
815
+ ), n = [...n, ...k], u = k.length > 0, d = !0, (!u || n.length >= e || l < c) && (d = !1, s.logger.log("Stopping fetch loop:", {
816
+ hasMore: u,
817
+ totalResults: n.length,
213
818
  maxCountNeeded: e,
214
- oldestReceived: c,
215
- oldestNeeded: d
819
+ oldestReceived: l,
820
+ oldestNeeded: c
216
821
  }));
217
822
  }
218
- return n.logger.log("getInAppNotifications completed:", {
219
- totalItems: a.length,
220
- hasMore: p,
221
- oldestReceived: c
823
+ return s.logger.log("getInAppNotifications completed:", {
824
+ totalItems: n.length,
825
+ hasMore: u,
826
+ oldestReceived: l
222
827
  }), {
223
- items: a,
224
- hasMore: p,
225
- oldestReceived: c
828
+ items: n,
829
+ hasMore: u,
830
+ oldestReceived: l
226
831
  };
227
832
  },
228
- updateInAppNotifications: async (o) => {
229
- n.logger.log(
833
+ updateInAppNotifications: async (t) => {
834
+ s.logger.log(
230
835
  "updateInAppNotifications called with params:",
231
- o
836
+ t
232
837
  );
233
838
  const e = {
234
- trackingIds: o.ids
839
+ trackingIds: t.ids
235
840
  };
236
- return o.archived === !0 ? e.archived = (/* @__PURE__ */ new Date()).toISOString() : o.archived === !1 && (e.archived = null), o.clicked === !0 ? e.clicked = (/* @__PURE__ */ new Date()).toISOString() : o.clicked === !1 && (e.clicked = null), o.opened === !0 ? e.opened = (/* @__PURE__ */ new Date()).toISOString() : o.opened === !1 && (e.opened = null), n.logger.log(
841
+ return t.archived === !0 ? e.archived = (/* @__PURE__ */ new Date()).toISOString() : t.archived === !1 && (e.archived = null), t.clicked === !0 ? e.clicked = (/* @__PURE__ */ new Date()).toISOString() : t.clicked === !1 && (e.clicked = null), t.opened === !0 ? e.opened = (/* @__PURE__ */ new Date()).toISOString() : t.opened === !1 && (e.opened = null), s.logger.log(
237
842
  "Updating notifications with body:",
238
843
  e
239
- ), n.rest.patchNotifications(e);
844
+ ), s.rest.patchNotifications(e);
240
845
  },
241
- getPreferences: async () => n.rest.getPreferences(),
242
- updateDeliveryOption: async (o) => n.rest.postPreferences([o]),
243
- identify: async (o) => {
244
- if (o.id && o.id !== n.config.userId)
846
+ getPreferences: async () => s.rest.getPreferences(),
847
+ updateDeliveryOption: async (t) => s.rest.postPreferences([t]),
848
+ identify: async (t) => {
849
+ if (t.id && t.id !== s.config.userId)
245
850
  throw new Error(
246
851
  "The id in the parameters does not match the initialized userId."
247
852
  );
248
- return n.rest.postUser(o);
853
+ return s.rest.postUser(t);
249
854
  },
250
- getUserAccountMetadata: async () => n.rest.getUserAccountMetadata(),
855
+ getUserAccountMetadata: async () => s.rest.getUserAccountMetadata(),
251
856
  user: {
252
- get: async () => n.rest.generic("GET", "")
857
+ get: async () => s.rest.generic("GET", "")
253
858
  },
254
859
  slack: {
255
- getOAuthUrl: (o) => {
256
- const e = n.config.sdkDevMode ? "localhost:3001" : n.config.host.replace("api.", "app."), d = (o == null ? void 0 : o.destinationUrl) || window.location.href, a = encodeURIComponent(
860
+ getOAuthUrl: (t) => {
861
+ const e = s.config.sdkDevMode ? "localhost:3001" : s.config.host.replace("api.", "app."), c = (t == null ? void 0 : t.destinationUrl) || window.location.href, n = encodeURIComponent(
257
862
  JSON.stringify({
258
- destination: d,
259
- userId: n.config.userId,
260
- clientId: n.config.clientId,
261
- hashedUserId: n.config.hashedUserId
863
+ destination: c,
864
+ userId: s.config.userId,
865
+ clientId: s.config.clientId,
866
+ hashedUserId: s.config.hashedUserId
262
867
  })
263
868
  );
264
- return `https://slack.com/oauth/v2/authorize?client_id=1146598856352.8825220259395&scope=chat:write,channels:read,channels:join,chat:write.customize,chat:write.public,groups:read,im:read,users:read&redirect_uri=https://${e}/slack/oauth/callback&state=${a}`;
869
+ return `https://slack.com/oauth/v2/authorize?client_id=1146598856352.8825220259395&scope=chat:write,channels:read,channels:join,chat:write.customize,chat:write.public,groups:read,im:read,users:read&redirect_uri=https://${e}/slack/oauth/callback&state=${n}`;
265
870
  },
266
- getChannels: async () => await n.rest.generic(
871
+ getChannels: async () => await s.rest.generic(
267
872
  "GET",
268
873
  "slack/channels"
269
874
  ),
270
- setChannel: async (o) => n.identify({
271
- slackChannel: o
875
+ setChannel: async (t) => s.identify({
876
+ slackChannel: t
272
877
  })
273
878
  }
274
- }, V = typeof window < "u", ae = (o) => {
275
- const e = K(
276
- () => ne(o.debug || !1),
277
- [o.debug]
879
+ }, Fe = typeof window < "u", pt = (t) => {
880
+ const e = pe(
881
+ () => ze(t.debug || !1),
882
+ [t.debug]
278
883
  );
279
884
  e.log("NotificationAPI Provider initializing", {
280
- clientId: o.clientId,
281
- userId: "userId" in o ? o.userId : o.user.id,
282
- debug: o.debug || !1,
885
+ clientId: t.clientId,
886
+ userId: "userId" in t ? t.userId : t.user.id,
887
+ debug: t.debug || !1,
283
888
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
284
889
  });
285
- const a = {
890
+ const n = {
286
891
  ...{
287
892
  apiURL: "api.notificationapi.com",
288
893
  wsURL: "ws.notificationapi.com",
@@ -293,144 +898,148 @@ const J = {
293
898
  webPushOptInMessage: "AUTOMATIC",
294
899
  customServiceWorkerPath: "/notificationapi-service-worker.js"
295
900
  },
296
- ...o,
297
- user: "userId" in o ? { id: o.userId } : o.user
901
+ ...t,
902
+ user: "userId" in t ? { id: t.userId } : t.user
298
903
  };
299
- e.log("Configuration loaded", a);
300
- const [c, p] = k(), [I, l] = k(), [h, b] = k(), [w, N] = k(!1), [m, P] = k((/* @__PURE__ */ new Date()).toISOString()), [U, x] = k(!0), [v, y] = k(a.webPushOptInMessage), [M, _] = k(!1), $ = A(() => {
301
- a.playSoundOnNewNotification && (e.log("Playing notification sound", {
302
- soundPath: a.newNotificationSoundPath
303
- }), new Audio(a.newNotificationSoundPath).play().catch((r) => {
904
+ e.log("Configuration loaded", n);
905
+ const [l, u] = F(), [d, f] = F(), [k, S] = F(), [y, P] = F(!1), [b, N] = F((/* @__PURE__ */ new Date()).toISOString()), [K, G] = F(!0), [R, A] = F(n.webPushOptInMessage), [j, _] = F(!1), h = B(() => {
906
+ n.playSoundOnNewNotification && (e.log("Playing notification sound", {
907
+ soundPath: n.newNotificationSoundPath
908
+ }), new Audio(n.newNotificationSoundPath).play().catch((r) => {
304
909
  e.error("Failed to play new notification sound", r), console.log("Failed to play new notification sound:", r);
305
910
  }));
306
911
  }, [
307
- a.newNotificationSoundPath,
308
- a.playSoundOnNewNotification,
912
+ n.newNotificationSoundPath,
913
+ n.playSoundOnNewNotification,
309
914
  e
310
- ]), O = A(
311
- (t) => {
915
+ ]), g = B(
916
+ (o) => {
312
917
  e.group("Adding notifications to state"), e.log("Received notifications", {
313
- count: (t == null ? void 0 : t.length) || 0,
314
- notifications: t
918
+ count: (o == null ? void 0 : o.length) || 0,
919
+ notifications: o
315
920
  });
316
921
  const r = (/* @__PURE__ */ new Date()).toISOString();
317
- p((i) => {
318
- const s = (i == null ? void 0 : i.length) || 0;
319
- e.log("Current notifications count", s), t = Array.isArray(t) ? t : [], t = t.filter((g) => {
320
- const S = g.expDate && new Date(g.expDate).toISOString() > r, L = new Date(g.date).getTime() > new Date(r).getTime() + 1e3, z = !S && !L;
321
- return z || e.log("Filtering out notification", {
322
- id: g.id,
323
- reason: S ? "expired" : "future",
324
- expDate: g.expDate,
325
- date: g.date
326
- }), z;
922
+ u((i) => {
923
+ const a = (i == null ? void 0 : i.length) || 0;
924
+ e.log("Current notifications count", a), o = Array.isArray(o) ? o : [], o = o.filter((v) => {
925
+ const q = v.expDate && new Date(v.expDate).toISOString() > r, H = new Date(v.date).getTime() > new Date(r).getTime() + 1e3, ie = !q && !H;
926
+ return ie || e.log("Filtering out notification", {
927
+ id: v.id,
928
+ reason: q ? "expired" : "future",
929
+ expDate: v.expDate,
930
+ date: v.date
931
+ }), ie;
327
932
  }), i = Array.isArray(i) ? i : [];
328
- const u = [
329
- ...t.filter((g) => {
330
- const S = i.find((L) => L.id === g.id);
331
- return S && e.log("Filtering out duplicate notification", { id: g.id }), !S;
933
+ const C = [
934
+ ...o.filter((v) => {
935
+ const q = i.find((H) => H.id === v.id);
936
+ return q && e.log("Filtering out duplicate notification", { id: v.id }), !q;
332
937
  }),
333
938
  ...i
334
939
  ];
335
940
  return e.log("State updated", {
336
- previousCount: s,
337
- newCount: u.length,
338
- addedCount: t.length
339
- }), e.groupEnd(), u;
941
+ previousCount: a,
942
+ newCount: C.length,
943
+ addedCount: o.length
944
+ }), e.groupEnd(), C;
340
945
  });
341
946
  },
342
947
  [e]
343
- ), f = K(() => {
948
+ ), { onNewNotifications: m } = t, D = B(
949
+ (o) => {
950
+ e.log("Received new in-app notifications via WebSocket", {
951
+ count: (o == null ? void 0 : o.length) || 0,
952
+ notifications: o
953
+ }), h(), g(o), m && (e.log("Calling onNewNotifications callback", {
954
+ count: (o == null ? void 0 : o.length) || 0
955
+ }), m(o));
956
+ },
957
+ [h, g, m, e]
958
+ ), p = pe(() => {
344
959
  e.group("Initializing NotificationAPI client");
345
- const t = {
346
- clientId: a.clientId,
347
- userId: a.user.id,
348
- hashedUserId: a.hashedUserId,
349
- host: a.apiURL,
350
- websocketHost: a.wsURL,
351
- debug: a.debug
960
+ const o = {
961
+ clientId: n.clientId,
962
+ userId: n.user.id,
963
+ hashedUserId: n.hashedUserId,
964
+ host: n.apiURL,
965
+ websocketHost: n.wsURL,
966
+ debug: n.debug
352
967
  };
353
- e.log("Client configuration", t);
354
- const r = o.client ? o.client : n.init({
355
- ...t,
356
- onNewInAppNotifications: (s) => {
357
- e.log("Received new in-app notifications via WebSocket", {
358
- count: (s == null ? void 0 : s.length) || 0,
359
- notifications: s
360
- }), $(), O(s);
361
- }
968
+ e.log("Client configuration", o);
969
+ const r = t.client ? t.client : s.init({
970
+ ...o,
971
+ onNewInAppNotifications: D
362
972
  }), i = {
363
- email: a.user.email,
364
- number: a.user.number
973
+ email: n.user.email,
974
+ number: n.user.number
365
975
  };
366
976
  return e.log("Identifying user", i), r.identify(i), e.groupEnd(), r;
367
977
  }, [
368
- a.clientId,
369
- a.user.id,
370
- a.user.email,
371
- a.user.number,
372
- a.hashedUserId,
373
- a.debug,
374
- O,
375
- $,
376
- o.client,
377
- a.apiURL,
378
- a.wsURL,
978
+ n.clientId,
979
+ n.user.id,
980
+ n.user.email,
981
+ n.user.number,
982
+ n.hashedUserId,
983
+ n.debug,
984
+ D,
985
+ t.client,
986
+ n.apiURL,
987
+ n.wsURL,
379
988
  e
380
- ]), j = A(
381
- async (t, r) => {
989
+ ]), L = B(
990
+ async (o, r) => {
382
991
  var i;
383
992
  e.group("Fetching notifications"), e.log(
384
993
  "Fetch parameters",
385
- C("GET", "/notifications", { date: t, count: r })
994
+ ae("GET", "/notifications", { date: o, count: r })
386
995
  );
387
996
  try {
388
- const s = await f.rest.getNotifications(t, r);
997
+ const a = await p.rest.getNotifications(o, r);
389
998
  e.log("Fetch successful", {
390
- notificationsCount: ((i = s.notifications) == null ? void 0 : i.length) || 0,
391
- oldestReceived: s.oldestReceived,
392
- couldLoadMore: s.couldLoadMore
393
- }), P(s.oldestReceived), x(s.couldLoadMore), O(s.notifications), e.groupEnd();
394
- } catch (s) {
395
- throw e.error("Failed to fetch notifications", s, { date: t, count: r }), e.groupEnd(), s;
999
+ notificationsCount: ((i = a.notifications) == null ? void 0 : i.length) || 0,
1000
+ oldestReceived: a.oldestReceived,
1001
+ couldLoadMore: a.couldLoadMore
1002
+ }), N(a.oldestReceived), G(a.couldLoadMore), g(a.notifications), e.groupEnd();
1003
+ } catch (a) {
1004
+ throw e.error("Failed to fetch notifications", a, { date: o, count: r }), e.groupEnd(), a;
396
1005
  }
397
1006
  },
398
- [O, f.rest, e]
399
- ), D = F(U), T = F(w), q = F(m);
400
- E(() => {
401
- D.current = U, T.current = w, q.current = m;
402
- }, [U, w, m]);
403
- const W = A(
404
- async (t) => {
405
- if (e.group(`Loading notifications (${t ? "initial" : "more"})`), e.log("Load conditions", {
406
- initial: t,
407
- hasMore: D.current,
408
- loading: T.current
409
- }), !t && (!D.current || T.current)) {
1007
+ [g, p.rest, e]
1008
+ ), Y = Se(K), Q = Se(y), le = Se(b);
1009
+ ce(() => {
1010
+ Y.current = K, Q.current = y, le.current = b;
1011
+ }, [K, y, b]);
1012
+ const X = B(
1013
+ async (o) => {
1014
+ if (e.group(`Loading notifications (${o ? "initial" : "more"})`), e.log("Load conditions", {
1015
+ initial: o,
1016
+ hasMore: Y.current,
1017
+ loading: Q.current
1018
+ }), !o && (!Y.current || Q.current)) {
410
1019
  e.log("Skipping load - conditions not met"), e.groupEnd();
411
1020
  return;
412
1021
  }
413
- N(!0), e.log("Loading started");
1022
+ P(!0), e.log("Loading started");
414
1023
  try {
415
- await j(
416
- t ? (/* @__PURE__ */ new Date()).toISOString() : q.current,
417
- t ? a.initialLoadMaxCount : 1e3
1024
+ await L(
1025
+ o ? (/* @__PURE__ */ new Date()).toISOString() : le.current,
1026
+ o ? n.initialLoadMaxCount : 1e3
418
1027
  ), e.log("Loading completed successfully");
419
1028
  } catch (r) {
420
1029
  throw e.error("Loading failed", r), r;
421
1030
  } finally {
422
- N(!1), e.groupEnd();
1031
+ P(!1), e.groupEnd();
423
1032
  }
424
1033
  },
425
- [a.initialLoadMaxCount, j, e]
426
- ), Q = async (t) => {
427
- if (e.group("Marking notifications as clicked"), e.log("Requested IDs", t), !c) {
1034
+ [n.initialLoadMaxCount, L, e]
1035
+ ), Z = async (o) => {
1036
+ if (e.group("Marking notifications as clicked"), e.log("Requested IDs", o), !l) {
428
1037
  e.warn("No notifications available"), e.groupEnd();
429
1038
  return;
430
1039
  }
431
- const r = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((s) => t.includes(s.id) && !s.clicked).map((s) => s.id);
1040
+ const r = (/* @__PURE__ */ new Date()).toISOString(), i = l.filter((a) => o.includes(a.id) && !a.clicked).map((a) => a.id);
432
1041
  if (e.log("Filtered IDs for update", {
433
- requestedCount: t.length,
1042
+ requestedCount: o.length,
434
1043
  actualCount: i.length,
435
1044
  ids: i
436
1045
  }), i.length === 0) {
@@ -440,23 +1049,23 @@ const J = {
440
1049
  try {
441
1050
  e.log(
442
1051
  "Updating notifications via API",
443
- C("PUT", "/notifications/clicked", { ids: i })
444
- ), f.updateInAppNotifications({ ids: i, clicked: !0 }), p((s) => {
445
- if (!s) return [];
446
- const u = [...s];
447
- return u.filter((g) => i.includes(g.id)).forEach((g) => {
448
- g.clicked = r;
449
- }), e.log("Local state updated", { updatedCount: i.length }), u;
1052
+ ae("PUT", "/notifications/clicked", { ids: i })
1053
+ ), p.updateInAppNotifications({ ids: i, clicked: !0 }), u((a) => {
1054
+ if (!a) return [];
1055
+ const C = [...a];
1056
+ return C.filter((v) => i.includes(v.id)).forEach((v) => {
1057
+ v.clicked = r;
1058
+ }), e.log("Local state updated", { updatedCount: i.length }), C;
450
1059
  }), e.groupEnd();
451
- } catch (s) {
452
- throw e.error("Failed to mark notifications as clicked", s, { ids: i }), e.groupEnd(), s;
1060
+ } catch (a) {
1061
+ throw e.error("Failed to mark notifications as clicked", a, { ids: i }), e.groupEnd(), a;
453
1062
  }
454
- }, X = async () => {
455
- if (e.group("Marking notifications as opened"), !c) {
1063
+ }, ee = async () => {
1064
+ if (e.group("Marking notifications as opened"), !l) {
456
1065
  e.warn("No notifications available"), e.groupEnd();
457
1066
  return;
458
1067
  }
459
- const t = (/* @__PURE__ */ new Date()).toISOString(), r = c.filter((i) => !i.opened || !i.seen).map((i) => i.id);
1068
+ const o = (/* @__PURE__ */ new Date()).toISOString(), r = l.filter((i) => !i.opened || !i.seen).map((i) => i.id);
460
1069
  if (e.log("Notifications to mark as opened", { count: r.length, ids: r }), r.length === 0) {
461
1070
  e.log("All notifications already opened"), e.groupEnd();
462
1071
  return;
@@ -464,26 +1073,26 @@ const J = {
464
1073
  try {
465
1074
  e.log(
466
1075
  "Updating notifications via API",
467
- C("PUT", "/notifications/opened", { ids: r })
468
- ), f.updateInAppNotifications({
1076
+ ae("PUT", "/notifications/opened", { ids: r })
1077
+ ), p.updateInAppNotifications({
469
1078
  ids: r,
470
1079
  opened: !0
471
- }), p((i) => {
1080
+ }), u((i) => {
472
1081
  if (!i) return [];
473
- const s = [...i];
474
- return s.filter((u) => r.includes(u.id)).forEach((u) => {
475
- u.opened = t, u.seen = !0;
476
- }), e.log("Local state updated", { updatedCount: r.length }), s;
1082
+ const a = [...i];
1083
+ return a.filter((C) => r.includes(C.id)).forEach((C) => {
1084
+ C.opened = o, C.seen = !0;
1085
+ }), e.log("Local state updated", { updatedCount: r.length }), a;
477
1086
  }), e.groupEnd();
478
1087
  } catch (i) {
479
1088
  throw e.error("Failed to mark notifications as opened", i, { ids: r }), e.groupEnd(), i;
480
1089
  }
481
- }, Y = async (t) => {
482
- if (e.group("Marking notifications as unarchived"), e.log("Requested operation", { ids: t }), !c) {
1090
+ }, te = async (o) => {
1091
+ if (e.group("Marking notifications as unarchived"), e.log("Requested operation", { ids: o }), !l) {
483
1092
  e.warn("No notifications available"), e.groupEnd();
484
1093
  return;
485
1094
  }
486
- const r = c.filter((i) => i.archived && (t === "ALL" || t.includes(i.id))).map((i) => i.id);
1095
+ const r = l.filter((i) => i.archived && (o === "ALL" || o.includes(i.id))).map((i) => i.id);
487
1096
  if (e.log("Filtered notifications for unarchiving", {
488
1097
  count: r.length,
489
1098
  ids: r
@@ -494,26 +1103,26 @@ const J = {
494
1103
  try {
495
1104
  e.log(
496
1105
  "Updating notifications via API",
497
- C("PUT", "/notifications/unarchived", { ids: r })
498
- ), f.updateInAppNotifications({
1106
+ ae("PUT", "/notifications/unarchived", { ids: r })
1107
+ ), p.updateInAppNotifications({
499
1108
  ids: r,
500
1109
  archived: !1
501
- }), p((i) => {
1110
+ }), u((i) => {
502
1111
  if (!i) return [];
503
- const s = [...i];
504
- return s.filter((u) => r.includes(u.id)).forEach((u) => {
505
- u.archived = void 0;
506
- }), e.log("Local state updated", { unarchivedCount: r.length }), s;
1112
+ const a = [...i];
1113
+ return a.filter((C) => r.includes(C.id)).forEach((C) => {
1114
+ C.archived = void 0;
1115
+ }), e.log("Local state updated", { unarchivedCount: r.length }), a;
507
1116
  }), e.groupEnd();
508
1117
  } catch (i) {
509
1118
  throw e.error("Failed to unarchive notifications", i, { ids: r }), e.groupEnd(), i;
510
1119
  }
511
- }, Z = async (t) => {
512
- if (e.group("Marking notifications as archived"), e.log("Requested operation", { ids: t }), !c) {
1120
+ }, oe = async (o) => {
1121
+ if (e.group("Marking notifications as archived"), e.log("Requested operation", { ids: o }), !l) {
513
1122
  e.warn("No notifications available"), e.groupEnd();
514
1123
  return;
515
1124
  }
516
- const r = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((s) => !s.archived && (t === "ALL" || t.includes(s.id))).map((s) => s.id);
1125
+ const r = (/* @__PURE__ */ new Date()).toISOString(), i = l.filter((a) => !a.archived && (o === "ALL" || o.includes(a.id))).map((a) => a.id);
517
1126
  if (e.log("Filtered notifications for archiving", {
518
1127
  count: i.length,
519
1128
  ids: i
@@ -524,63 +1133,63 @@ const J = {
524
1133
  try {
525
1134
  e.log(
526
1135
  "Updating notifications via API",
527
- C("PUT", "/notifications/archived", { ids: i })
528
- ), f.updateInAppNotifications({ ids: i, archived: !0 }), p((s) => {
529
- if (!s) return [];
530
- const u = [...s];
531
- return u.filter((g) => i.includes(g.id)).forEach((g) => {
532
- g.archived = r;
533
- }), e.log("Local state updated", { archivedCount: i.length }), u;
1136
+ ae("PUT", "/notifications/archived", { ids: i })
1137
+ ), p.updateInAppNotifications({ ids: i, archived: !0 }), u((a) => {
1138
+ if (!a) return [];
1139
+ const C = [...a];
1140
+ return C.filter((v) => i.includes(v.id)).forEach((v) => {
1141
+ v.archived = r;
1142
+ }), e.log("Local state updated", { archivedCount: i.length }), C;
534
1143
  }), e.groupEnd();
535
- } catch (s) {
536
- throw e.error("Failed to archive notifications", s, { ids: i }), e.groupEnd(), s;
1144
+ } catch (a) {
1145
+ throw e.error("Failed to archive notifications", a, { ids: i }), e.groupEnd(), a;
537
1146
  }
538
- }, ee = (t, r, i, s) => (e.log("Updating single delivery preference", {
539
- notificationId: t,
1147
+ }, ue = (o, r, i, a) => (e.log("Updating single delivery preference", {
1148
+ notificationId: o,
540
1149
  channel: r,
541
1150
  delivery: i,
542
- subNotificationId: s
543
- }), H([
1151
+ subNotificationId: a
1152
+ }), ne([
544
1153
  {
545
- notificationId: t,
1154
+ notificationId: o,
546
1155
  channel: r,
547
1156
  delivery: i,
548
- subNotificationId: s
1157
+ subNotificationId: a
549
1158
  }
550
- ])), H = (t) => {
551
- e.group("Updating delivery preferences"), e.log("Preference updates", { count: t.length, params: t });
1159
+ ])), ne = (o) => {
1160
+ e.group("Updating delivery preferences"), e.log("Preference updates", { count: o.length, params: o });
552
1161
  try {
553
- f.rest.postPreferences(t).then(() => {
1162
+ p.rest.postPreferences(o).then(() => {
554
1163
  e.log(
555
1164
  "Preferences updated successfully, fetching latest preferences"
556
- ), f.getPreferences().then((r) => {
557
- var i, s, u;
1165
+ ), p.getPreferences().then((r) => {
1166
+ var i, a, C;
558
1167
  e.log("Latest preferences fetched", {
559
1168
  preferencesCount: ((i = r.preferences) == null ? void 0 : i.length) || 0,
560
- notificationsCount: ((s = r.notifications) == null ? void 0 : s.length) || 0,
561
- subNotificationsCount: ((u = r.subNotifications) == null ? void 0 : u.length) || 0
562
- }), l(r), e.groupEnd();
1169
+ notificationsCount: ((a = r.notifications) == null ? void 0 : a.length) || 0,
1170
+ subNotificationsCount: ((C = r.subNotifications) == null ? void 0 : C.length) || 0
1171
+ }), f(r), e.groupEnd();
563
1172
  }).catch((r) => {
564
1173
  e.error("Failed to fetch updated preferences", r), e.groupEnd();
565
1174
  });
566
1175
  }).catch((r) => {
567
- e.error("Failed to update preferences", r, { params: t }), e.groupEnd();
1176
+ e.error("Failed to update preferences", r, { params: o }), e.groupEnd();
568
1177
  });
569
1178
  } catch (r) {
570
- throw e.error("Error in updateDeliveries", r, { params: t }), e.groupEnd(), r;
1179
+ throw e.error("Error in updateDeliveries", r, { params: o }), e.groupEnd(), r;
571
1180
  }
572
- }, R = A(() => {
1181
+ }, T = B(() => {
573
1182
  e.group("Requesting web push permission"), e.log("Service worker support check", {
574
1183
  supported: "serviceWorker" in navigator,
575
- customServiceWorkerPath: a.customServiceWorkerPath
576
- }), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(a.customServiceWorkerPath).then(async (t) => {
577
- e.log("Service worker registered successfully"), y(!1), de().then(async (r) => {
578
- e.log("Notification permission result", { permission: r }), r === "granted" ? (e.log("Permission granted, subscribing to push manager"), await t.pushManager.subscribe({
1184
+ customServiceWorkerPath: n.customServiceWorkerPath
1185
+ }), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(n.customServiceWorkerPath).then(async (o) => {
1186
+ e.log("Service worker registered successfully"), A(!1), yt().then(async (r) => {
1187
+ e.log("Notification permission result", { permission: r }), r === "granted" ? (e.log("Permission granted, subscribing to push manager"), await o.pushManager.subscribe({
579
1188
  userVisibleOnly: !0,
580
- applicationServerKey: h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey
1189
+ applicationServerKey: k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey
581
1190
  }).then(async (i) => {
582
1191
  e.log("Push subscription successful");
583
- const s = {
1192
+ const a = {
584
1193
  webPushTokens: [
585
1194
  {
586
1195
  sub: {
@@ -590,116 +1199,118 @@ const J = {
590
1199
  }
591
1200
  ]
592
1201
  };
593
- e.log("Identifying user with web push tokens"), await f.identify(s), localStorage.setItem("hideWebPushOptInMessage", "true"), e.log("Web push setup completed successfully"), e.groupEnd();
1202
+ e.log("Identifying user with web push tokens"), await p.identify(a), localStorage.setItem("hideWebPushOptInMessage", "true"), e.log("Web push setup completed successfully"), e.groupEnd();
594
1203
  })) : r === "denied" && (e.warn("Permission for notifications was denied"), console.log("Permission for notifications was denied"), e.groupEnd());
595
1204
  });
596
- }).catch((t) => {
1205
+ }).catch((o) => {
597
1206
  e.error(
598
1207
  "Service worker registration or push subscription failed",
599
- t,
1208
+ o,
600
1209
  {
601
- errorCode: t.code,
602
- customServiceWorkerPath: a.customServiceWorkerPath
1210
+ errorCode: o.code,
1211
+ customServiceWorkerPath: n.customServiceWorkerPath
603
1212
  }
604
- ), t.code === 18 ? console.error(
1213
+ ), o.code === 18 ? console.error(
605
1214
  "NotificationAPI guide: Probably you are not setup the service worker correctly. Please check the documentation at https://docs.notificationapi.com/guides/web-push#step-by-step-implementation Step 3: Service Worker Setup."
606
- ) : t.code === 19 ? console.error(
1215
+ ) : o.code === 19 ? console.error(
607
1216
  "The operation is aborted. This can happen if the user denies the permission request."
608
- ) : t.code === 20 ? console.error(
1217
+ ) : o.code === 20 ? console.error(
609
1218
  "The operation is invalid. This can occur if the provided application server key is invalid. Please contact NotificationAPI support."
610
- ) : t.code === 21 ? console.error(
1219
+ ) : o.code === 21 ? console.error(
611
1220
  "The operation is not allowed. This can happen if the user has blocked notifications for the site. Please check your browser site settings Notifications part."
612
- ) : t.code === 22 ? console.error(
1221
+ ) : o.code === 22 ? console.error(
613
1222
  "The operation is not supported. This can occur if the browser does not support the required features."
614
- ) : console.error(t), e.groupEnd();
1223
+ ) : console.error(o), e.groupEnd();
615
1224
  })) : (e.warn("Service worker not supported in this browser"), e.groupEnd());
616
1225
  }, [
617
- f,
618
- a.customServiceWorkerPath,
619
- h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey,
1226
+ p,
1227
+ n.customServiceWorkerPath,
1228
+ k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey,
620
1229
  e
621
1230
  ]);
622
- E(() => {
623
- e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), p([]), N(!1), l(void 0), P((/* @__PURE__ */ new Date()).toISOString()), x(!0), W(!0), e.log("Opening WebSocket connection"), f.openWebSocket(), e.log("Fetching user preferences"), f.getPreferences().then((t) => {
624
- var r, i, s;
1231
+ ce(() => {
1232
+ e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), u([]), P(!1), f(void 0), N((/* @__PURE__ */ new Date()).toISOString()), G(!0), X(!0), e.log("Opening WebSocket connection"), p.openWebSocket(), e.log("Fetching user preferences"), p.getPreferences().then((o) => {
1233
+ var r, i, a;
625
1234
  e.log("Initial preferences loaded", {
626
- preferencesCount: ((r = t.preferences) == null ? void 0 : r.length) || 0,
627
- notificationsCount: ((i = t.notifications) == null ? void 0 : i.length) || 0,
628
- subNotificationsCount: ((s = t.subNotifications) == null ? void 0 : s.length) || 0
629
- }), l(t), e.groupEnd();
630
- }).catch((t) => {
631
- e.error("Failed to fetch initial preferences", t), e.groupEnd();
1235
+ preferencesCount: ((r = o.preferences) == null ? void 0 : r.length) || 0,
1236
+ notificationsCount: ((i = o.notifications) == null ? void 0 : i.length) || 0,
1237
+ subNotificationsCount: ((a = o.subNotifications) == null ? void 0 : a.length) || 0
1238
+ }), f(o), e.groupEnd();
1239
+ }).catch((o) => {
1240
+ e.error("Failed to fetch initial preferences", o), e.groupEnd();
632
1241
  });
633
- }, [f, W, R, e]), E(() => {
634
- e.group("Fetching user account metadata"), f.getUserAccountMetadata().then((t) => {
1242
+ }, [p, X, T, e]), ce(() => {
1243
+ e.group("Fetching user account metadata"), p.getUserAccountMetadata().then((o) => {
635
1244
  e.log("User account metadata loaded", {
636
- hasWebPushEnabled: t.userAccountMetadata.hasWebPushEnabled,
637
- environmentVapidPublicKey: t.userAccountMetadata.environmentVapidPublicKey ? "present" : "missing"
638
- }), b(t), V && "Notification" in window && typeof Notification.requestPermission == "function" ? (e.log("Browser notification support detected", {
1245
+ hasWebPushEnabled: o.userAccountMetadata.hasWebPushEnabled,
1246
+ environmentVapidPublicKey: o.userAccountMetadata.environmentVapidPublicKey ? "present" : "missing"
1247
+ }), S(o), Fe && "Notification" in window && typeof Notification.requestPermission == "function" ? (e.log("Browser notification support detected", {
639
1248
  permission: Notification.permission
640
1249
  }), Notification.permission !== "default" && (e.log(
641
1250
  "Setting webPushOptInMessage to false (permission already set)"
642
- ), y(!1))) : (e.log(
1251
+ ), A(!1))) : (e.log(
643
1252
  "Browser notification not supported, using server setting",
644
1253
  {
645
- hasWebPushEnabled: t.userAccountMetadata.hasWebPushEnabled
1254
+ hasWebPushEnabled: o.userAccountMetadata.hasWebPushEnabled
646
1255
  }
647
- ), y(t.userAccountMetadata.hasWebPushEnabled)), e.groupEnd();
648
- }).catch((t) => {
649
- e.error("Failed to fetch user account metadata", t), e.groupEnd();
1256
+ ), A(o.userAccountMetadata.hasWebPushEnabled)), e.groupEnd();
1257
+ }).catch((o) => {
1258
+ e.error("Failed to fetch user account metadata", o), e.groupEnd();
650
1259
  });
651
- }, [f, e]), E(() => {
652
- if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", v), v === "AUTOMATIC") {
653
- const t = localStorage.getItem("hideWebPushOptInMessage") === "true";
1260
+ }, [p, e]), ce(() => {
1261
+ if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", R), R === "AUTOMATIC") {
1262
+ const o = localStorage.getItem("hideWebPushOptInMessage") === "true";
654
1263
  e.log("Automatic mode - checking localStorage", {
655
- hideMessage: t,
656
- shouldShow: !t
657
- }), y(!t);
1264
+ hideMessage: o,
1265
+ shouldShow: !o
1266
+ }), A(!o);
658
1267
  }
659
1268
  e.groupEnd();
660
- }, [v, e]), E(() => {
661
- e.group("Handling webPushOptIn state"), e.log("webPushOptIn state", M), M && (e.log("User opted in for web push, requesting permission"), R()), e.groupEnd();
662
- }, [M, R, e]);
663
- const te = {
664
- notifications: c,
665
- preferences: I,
666
- userAccountMetaData: h,
667
- webPushOptInMessage: v,
668
- loadNotifications: W,
669
- markAsOpened: X,
670
- markAsArchived: Z,
671
- markAsUnarchived: Y,
672
- markAsClicked: Q,
673
- updateDelivery: ee,
674
- updateDeliveries: H,
675
- getClient: () => f,
676
- setWebPushOptInMessage: y,
1269
+ }, [R, e]), ce(() => {
1270
+ e.group("Handling webPushOptIn state"), e.log("webPushOptIn state", j), j && (e.log("User opted in for web push, requesting permission"), T()), e.groupEnd();
1271
+ }, [j, T, e]);
1272
+ const W = {
1273
+ notifications: l,
1274
+ preferences: d,
1275
+ userAccountMetaData: k,
1276
+ webPushOptInMessage: R,
1277
+ loadNotifications: X,
1278
+ markAsOpened: ee,
1279
+ markAsArchived: oe,
1280
+ markAsUnarchived: te,
1281
+ markAsClicked: Z,
1282
+ updateDelivery: ue,
1283
+ updateDeliveries: ne,
1284
+ getClient: () => p,
1285
+ setWebPushOptInMessage: A,
677
1286
  setWebPushOptIn: _
678
1287
  };
679
- return e.log("NotificationAPI Provider rendering", {
680
- notificationsCount: (c == null ? void 0 : c.length) || 0,
681
- hasPreferences: !!I,
682
- hasUserAccountMetaData: !!h,
683
- webPushOptInMessage: v,
684
- webPushOptIn: M
685
- }), /* @__PURE__ */ oe(B.Provider, { value: te, children: o.children });
686
- }, ce = () => {
687
- const o = ie(B);
688
- if (!o)
1288
+ e.log("NotificationAPI Provider rendering", {
1289
+ notificationsCount: (l == null ? void 0 : l.length) || 0,
1290
+ hasPreferences: !!d,
1291
+ hasUserAccountMetaData: !!k,
1292
+ webPushOptInMessage: R,
1293
+ webPushOptIn: j
1294
+ });
1295
+ const fe = pe(() => t.theme ? Oe(t.theme) : Oe("light"), [t.theme]);
1296
+ return /* @__PURE__ */ M(ht, { theme: fe, children: /* @__PURE__ */ M(je.Provider, { value: W, children: t.children }) });
1297
+ }, St = () => {
1298
+ const t = Ge(je);
1299
+ if (!t)
689
1300
  throw new Error("useMyContext must be used within a MyProvider");
690
- return o;
1301
+ return t;
691
1302
  };
692
- ae.useNotificationAPIContext = ce;
693
- const de = async () => {
694
- if (V && "Notification" in window && typeof Notification.requestPermission == "function")
1303
+ pt.useNotificationAPIContext = St;
1304
+ const yt = async () => {
1305
+ if (Fe && "Notification" in window && typeof Notification.requestPermission == "function")
695
1306
  try {
696
1307
  return await Notification.requestPermission();
697
- } catch (o) {
698
- return console.error("Error requesting notification permission:", o), "default";
1308
+ } catch (t) {
1309
+ return console.error("Error requesting notification permission:", t), "default";
699
1310
  }
700
1311
  else
701
1312
  return console.warn("Web Push Notifications are not supported in this browser."), "default";
702
1313
  };
703
1314
  export {
704
- ae as NotificationAPIProvider
1315
+ pt as NotificationAPIProvider
705
1316
  };