@notificationapi/react 1.7.0 → 1.9.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 (47) hide show
  1. package/dist/assets/Badge.js +60 -64
  2. package/dist/assets/Box.js +26 -24
  3. package/dist/assets/Button.js +22 -19
  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 +22 -18
  8. package/dist/assets/GlobalStyles.js +23 -0
  9. package/dist/assets/Grow.js +1513 -120
  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 +8 -8
  15. package/dist/assets/Popover.js +37 -36
  16. package/dist/assets/Portal.js +39 -49
  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/exactProp.js +13 -0
  22. package/dist/assets/index.js +19 -148
  23. package/dist/assets/index2.js +151 -0
  24. package/dist/assets/useControlled.js +49 -0
  25. package/dist/assets/usePreviousProps.js +10 -0
  26. package/dist/assets/useTheme.js +6 -7
  27. package/dist/assets/{useTheme2.js → useThemeWithoutDefault.js} +63 -67
  28. package/dist/assets/utils.js +4 -4
  29. package/dist/components/Notifications/Inbox.js +593 -583
  30. package/dist/components/Notifications/InboxHeader.js +360 -1754
  31. package/dist/components/Notifications/Notification.js +4 -2
  32. package/dist/components/Notifications/NotificationFeed.js +40 -32
  33. package/dist/components/Notifications/NotificationLauncher.js +90 -64
  34. package/dist/components/Notifications/NotificationPopup.js +76 -65
  35. package/dist/components/Preferences/NotificationPreferencesInline.js +57 -39
  36. package/dist/components/Preferences/NotificationPreferencesPopup.js +111 -99
  37. package/dist/components/Preferences/PreferenceInput.js +427 -414
  38. package/dist/components/Preferences/Preferences.js +329 -278
  39. package/dist/components/Provider/index.d.ts +2 -0
  40. package/dist/components/Provider/index.js +1008 -401
  41. package/dist/components/Slack/SlackConnect.js +4627 -2024
  42. package/dist/main.d.ts +2 -0
  43. package/dist/main.js +6 -3
  44. package/dist/utils/theme.d.ts +17 -0
  45. package/dist/utils/theme.js +104 -0
  46. package/package.json +1 -1
  47. package/dist/assets/dividerClasses.js +0 -56
@@ -1,45 +1,650 @@
1
- import { jsx as ie } from "react/jsx-runtime";
2
- import { useMemo as J, useState as N, useCallback as k, useRef as x, useEffect as E, useContext as re } from "react";
3
- import { NotificationAPIContext as _ } from "./context.js";
4
- import { createDebugLogger as se, formatApiCall as C } from "../../utils/debug.js";
5
- const ae = async (o, e, d, a, c, p, I, l) => {
6
- const h = ce(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 v = 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() - v;
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
- }, ce = (o, e, d) => btoa(d ? o + ":" + e + ":" + d : o + ":" + e);
42
- class B {
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 B {
53
658
  this.debug && console.error("[NotificationAPI js core SDK Debug]", ...e);
54
659
  }
55
660
  }
56
- const V = {
661
+ const We = {
57
662
  host: "api.notificationapi.com",
58
663
  websocketHost: "ws.notificationapi.com",
59
664
  userId: "",
@@ -68,11 +673,11 @@ const V = {
68
673
  // 24 hours
69
674
  debug: !1,
70
675
  sdkDevMode: !1
71
- }, i = {
72
- config: V,
73
- logger: new B(!1),
74
- init: function(o) {
75
- return this.config = { ...V, ...o }, this.logger = new B(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 V = {
84
689
  };
85
690
  },
86
691
  rest: {
87
- generic: function(o, e, d) {
88
- return i.logger.log(
89
- `API Call: ${o} ${e}`,
90
- d ? { body: d } : ""
91
- ), ae(
92
- o,
93
- i.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
- i.config.clientId,
96
- i.config.userId,
97
- i.config.hashedUserId,
98
- d,
99
- i.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 i.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 i.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 i.rest.generic("GET", "preferences");
724
+ return s.rest.generic("GET", "preferences");
120
725
  },
121
- postPreferences: function(o) {
122
- return i.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 i.rest.generic("POST", "", o);
733
+ postUser: function(t) {
734
+ return s.rest.generic("POST", "", t);
130
735
  },
131
736
  getUserAccountMetadata: function() {
132
- return i.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://${i.config.websocketHost}?userId=${encodeURIComponent(i.config.userId)}&envId=${i.config.clientId}`;
139
- return i.config.hashedUserId && (o += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.logger.log("WebSocket connecting to:", o), i.websocket.object = new WebSocket(o), i.websocket.object.onopen = () => {
140
- i.logger.log("WebSocket connection opened");
141
- }, i.websocket.object.onclose = (e) => {
142
- i.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
- }, i.websocket.object.onerror = (e) => {
148
- i.logger.error("WebSocket error:", e);
149
- }, i.websocket.object.onmessage = (e) => {
150
- i.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
- i.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
- ), i.config.onNewInAppNotifications && i.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
- }, i.websocket.object;
769
+ }, s.websocket.object;
165
770
  },
166
- disconnect: function(o) {
771
+ disconnect: function(t) {
167
772
  var e;
168
- i.websocket.object && (i.logger.log("WebSocket disconnecting"), (e = i.websocket.object) == null || e.close(), o && o(i.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 i.websocket.connect(() => {
777
+ return s.websocket.connect(() => {
173
778
  setTimeout(
174
779
  () => {
175
780
  this.websocket.disconnect(() => {
@@ -183,106 +788,106 @@ const V = {
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
- i.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 || i.config.getInAppDefaultCount, d = o.oldestNeeded || i.config.getInAppDefaultOldest;
192
- i.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 i.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
- i.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, i.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 i.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
- i.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), i.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
- ), i.rest.patchNotifications(e);
844
+ ), s.rest.patchNotifications(e);
240
845
  },
241
- getPreferences: async () => i.rest.getPreferences(),
242
- updateDeliveryOption: async (o) => i.rest.postPreferences([o]),
243
- identify: async (o) => {
244
- if (o.id && o.id !== i.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 i.rest.postUser(o);
853
+ return s.rest.postUser(t);
249
854
  },
250
- getUserAccountMetadata: async () => i.rest.getUserAccountMetadata(),
855
+ getUserAccountMetadata: async () => s.rest.getUserAccountMetadata(),
251
856
  user: {
252
- get: async () => i.rest.generic("GET", "")
857
+ get: async () => s.rest.generic("GET", "")
253
858
  },
254
859
  slack: {
255
- getOAuthUrl: (o) => {
256
- const e = i.config.sdkDevMode ? "localhost:3001" : i.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: i.config.userId,
260
- clientId: i.config.clientId,
261
- hashedUserId: i.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 i.rest.generic(
871
+ getChannels: async () => await s.rest.generic(
267
872
  "GET",
268
873
  "slack/channels"
269
874
  ),
270
- setChannel: async (o) => i.identify({
271
- slackChannel: o
875
+ setChannel: async (t) => s.identify({
876
+ slackChannel: t
272
877
  })
273
878
  }
274
- }, Q = typeof window < "u", de = (o) => {
275
- const e = J(
276
- () => se(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,174 +898,174 @@ const V = {
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] = N(), [I, l] = N(), [h, b] = N(), [w, v] = N(!1), [m, P] = N((/* @__PURE__ */ new Date()).toISOString()), [U, $] = N(!0), [y, S] = N(a.webPushOptInMessage), [M, X] = N(!1), j = k(() => {
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 = k(
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((n) => {
318
- const s = (n == null ? void 0 : n.length) || 0;
319
- e.log("Current notifications count", s), t = Array.isArray(t) ? t : [], t = t.filter((g) => {
320
- const A = g.expDate && new Date(g.expDate).toISOString() > r, F = new Date(g.date).getTime() > new Date(r).getTime() + 1e3, G = !A && !F;
321
- return G || e.log("Filtering out notification", {
322
- id: g.id,
323
- reason: A ? "expired" : "future",
324
- expDate: g.expDate,
325
- date: g.date
326
- }), G;
327
- }), n = Array.isArray(n) ? n : [];
328
- const u = [
329
- ...t.filter((g) => {
330
- const A = n.find((F) => F.id === g.id);
331
- return A && e.log("Filtering out duplicate notification", { id: g.id }), !A;
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;
932
+ }), i = Array.isArray(i) ? i : [];
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
- ...n
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
- ), { onNewNotifications: D } = o, q = k(
344
- (t) => {
948
+ ), { onNewNotifications: m } = t, D = B(
949
+ (o) => {
345
950
  e.log("Received new in-app notifications via WebSocket", {
346
- count: (t == null ? void 0 : t.length) || 0,
347
- notifications: t
348
- }), j(), O(t), D && (e.log("Calling onNewNotifications callback", {
349
- count: (t == null ? void 0 : t.length) || 0
350
- }), D(t));
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));
351
956
  },
352
- [j, O, D, e]
353
- ), f = J(() => {
957
+ [h, g, m, e]
958
+ ), p = pe(() => {
354
959
  e.group("Initializing NotificationAPI client");
355
- const t = {
356
- clientId: a.clientId,
357
- userId: a.user.id,
358
- hashedUserId: a.hashedUserId,
359
- host: a.apiURL,
360
- websocketHost: a.wsURL,
361
- 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
362
967
  };
363
- e.log("Client configuration", t);
364
- const r = o.client ? o.client : i.init({
365
- ...t,
366
- onNewInAppNotifications: q
367
- }), n = {
368
- email: a.user.email,
369
- number: a.user.number
968
+ e.log("Client configuration", o);
969
+ const r = t.client ? t.client : s.init({
970
+ ...o,
971
+ onNewInAppNotifications: D
972
+ }), i = {
973
+ email: n.user.email,
974
+ number: n.user.number
370
975
  };
371
- return e.log("Identifying user", n), r.identify(n), e.groupEnd(), r;
976
+ return e.log("Identifying user", i), r.identify(i), e.groupEnd(), r;
372
977
  }, [
373
- a.clientId,
374
- a.user.id,
375
- a.user.email,
376
- a.user.number,
377
- a.hashedUserId,
378
- a.debug,
379
- q,
380
- o.client,
381
- a.apiURL,
382
- 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,
383
988
  e
384
- ]), H = k(
385
- async (t, r) => {
386
- var n;
989
+ ]), L = B(
990
+ async (o, r) => {
991
+ var i;
387
992
  e.group("Fetching notifications"), e.log(
388
993
  "Fetch parameters",
389
- C("GET", "/notifications", { date: t, count: r })
994
+ ae("GET", "/notifications", { date: o, count: r })
390
995
  );
391
996
  try {
392
- const s = await f.rest.getNotifications(t, r);
997
+ const a = await p.rest.getNotifications(o, r);
393
998
  e.log("Fetch successful", {
394
- notificationsCount: ((n = s.notifications) == null ? void 0 : n.length) || 0,
395
- oldestReceived: s.oldestReceived,
396
- couldLoadMore: s.couldLoadMore
397
- }), P(s.oldestReceived), $(s.couldLoadMore), O(s.notifications), e.groupEnd();
398
- } catch (s) {
399
- 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;
400
1005
  }
401
1006
  },
402
- [O, f.rest, e]
403
- ), T = x(U), W = x(w), z = x(m);
404
- E(() => {
405
- T.current = U, W.current = w, z.current = m;
406
- }, [U, w, m]);
407
- const R = k(
408
- async (t) => {
409
- if (e.group(`Loading notifications (${t ? "initial" : "more"})`), e.log("Load conditions", {
410
- initial: t,
411
- hasMore: T.current,
412
- loading: W.current
413
- }), !t && (!T.current || W.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)) {
414
1019
  e.log("Skipping load - conditions not met"), e.groupEnd();
415
1020
  return;
416
1021
  }
417
- v(!0), e.log("Loading started");
1022
+ P(!0), e.log("Loading started");
418
1023
  try {
419
- await H(
420
- t ? (/* @__PURE__ */ new Date()).toISOString() : z.current,
421
- t ? a.initialLoadMaxCount : 1e3
1024
+ await L(
1025
+ o ? (/* @__PURE__ */ new Date()).toISOString() : le.current,
1026
+ o ? n.initialLoadMaxCount : 1e3
422
1027
  ), e.log("Loading completed successfully");
423
1028
  } catch (r) {
424
1029
  throw e.error("Loading failed", r), r;
425
1030
  } finally {
426
- v(!1), e.groupEnd();
1031
+ P(!1), e.groupEnd();
427
1032
  }
428
1033
  },
429
- [a.initialLoadMaxCount, H, e]
430
- ), Y = async (t) => {
431
- 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) {
432
1037
  e.warn("No notifications available"), e.groupEnd();
433
1038
  return;
434
1039
  }
435
- const r = (/* @__PURE__ */ new Date()).toISOString(), n = 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);
436
1041
  if (e.log("Filtered IDs for update", {
437
- requestedCount: t.length,
438
- actualCount: n.length,
439
- ids: n
440
- }), n.length === 0) {
1042
+ requestedCount: o.length,
1043
+ actualCount: i.length,
1044
+ ids: i
1045
+ }), i.length === 0) {
441
1046
  e.log("No notifications to update"), e.groupEnd();
442
1047
  return;
443
1048
  }
444
1049
  try {
445
1050
  e.log(
446
1051
  "Updating notifications via API",
447
- C("PUT", "/notifications/clicked", { ids: n })
448
- ), f.updateInAppNotifications({ ids: n, clicked: !0 }), p((s) => {
449
- if (!s) return [];
450
- const u = [...s];
451
- return u.filter((g) => n.includes(g.id)).forEach((g) => {
452
- g.clicked = r;
453
- }), e.log("Local state updated", { updatedCount: n.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;
454
1059
  }), e.groupEnd();
455
- } catch (s) {
456
- throw e.error("Failed to mark notifications as clicked", s, { ids: n }), e.groupEnd(), s;
1060
+ } catch (a) {
1061
+ throw e.error("Failed to mark notifications as clicked", a, { ids: i }), e.groupEnd(), a;
457
1062
  }
458
- }, Z = async () => {
459
- if (e.group("Marking notifications as opened"), !c) {
1063
+ }, ee = async () => {
1064
+ if (e.group("Marking notifications as opened"), !l) {
460
1065
  e.warn("No notifications available"), e.groupEnd();
461
1066
  return;
462
1067
  }
463
- const t = (/* @__PURE__ */ new Date()).toISOString(), r = c.filter((n) => !n.opened || !n.seen).map((n) => n.id);
1068
+ const o = (/* @__PURE__ */ new Date()).toISOString(), r = l.filter((i) => !i.opened || !i.seen).map((i) => i.id);
464
1069
  if (e.log("Notifications to mark as opened", { count: r.length, ids: r }), r.length === 0) {
465
1070
  e.log("All notifications already opened"), e.groupEnd();
466
1071
  return;
@@ -468,26 +1073,26 @@ const V = {
468
1073
  try {
469
1074
  e.log(
470
1075
  "Updating notifications via API",
471
- C("PUT", "/notifications/opened", { ids: r })
472
- ), f.updateInAppNotifications({
1076
+ ae("PUT", "/notifications/opened", { ids: r })
1077
+ ), p.updateInAppNotifications({
473
1078
  ids: r,
474
1079
  opened: !0
475
- }), p((n) => {
476
- if (!n) return [];
477
- const s = [...n];
478
- return s.filter((u) => r.includes(u.id)).forEach((u) => {
479
- u.opened = t, u.seen = !0;
480
- }), e.log("Local state updated", { updatedCount: r.length }), s;
1080
+ }), u((i) => {
1081
+ if (!i) return [];
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;
481
1086
  }), e.groupEnd();
482
- } catch (n) {
483
- throw e.error("Failed to mark notifications as opened", n, { ids: r }), e.groupEnd(), n;
1087
+ } catch (i) {
1088
+ throw e.error("Failed to mark notifications as opened", i, { ids: r }), e.groupEnd(), i;
484
1089
  }
485
- }, ee = async (t) => {
486
- 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) {
487
1092
  e.warn("No notifications available"), e.groupEnd();
488
1093
  return;
489
1094
  }
490
- const r = c.filter((n) => n.archived && (t === "ALL" || t.includes(n.id))).map((n) => n.id);
1095
+ const r = l.filter((i) => i.archived && (o === "ALL" || o.includes(i.id))).map((i) => i.id);
491
1096
  if (e.log("Filtered notifications for unarchiving", {
492
1097
  count: r.length,
493
1098
  ids: r
@@ -498,212 +1103,214 @@ const V = {
498
1103
  try {
499
1104
  e.log(
500
1105
  "Updating notifications via API",
501
- C("PUT", "/notifications/unarchived", { ids: r })
502
- ), f.updateInAppNotifications({
1106
+ ae("PUT", "/notifications/unarchived", { ids: r })
1107
+ ), p.updateInAppNotifications({
503
1108
  ids: r,
504
1109
  archived: !1
505
- }), p((n) => {
506
- if (!n) return [];
507
- const s = [...n];
508
- return s.filter((u) => r.includes(u.id)).forEach((u) => {
509
- u.archived = void 0;
510
- }), e.log("Local state updated", { unarchivedCount: r.length }), s;
1110
+ }), u((i) => {
1111
+ if (!i) return [];
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;
511
1116
  }), e.groupEnd();
512
- } catch (n) {
513
- throw e.error("Failed to unarchive notifications", n, { ids: r }), e.groupEnd(), n;
1117
+ } catch (i) {
1118
+ throw e.error("Failed to unarchive notifications", i, { ids: r }), e.groupEnd(), i;
514
1119
  }
515
- }, te = async (t) => {
516
- 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) {
517
1122
  e.warn("No notifications available"), e.groupEnd();
518
1123
  return;
519
1124
  }
520
- const r = (/* @__PURE__ */ new Date()).toISOString(), n = 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);
521
1126
  if (e.log("Filtered notifications for archiving", {
522
- count: n.length,
523
- ids: n
524
- }), n.length === 0) {
1127
+ count: i.length,
1128
+ ids: i
1129
+ }), i.length === 0) {
525
1130
  e.log("No unarchived notifications to archive"), e.groupEnd();
526
1131
  return;
527
1132
  }
528
1133
  try {
529
1134
  e.log(
530
1135
  "Updating notifications via API",
531
- C("PUT", "/notifications/archived", { ids: n })
532
- ), f.updateInAppNotifications({ ids: n, archived: !0 }), p((s) => {
533
- if (!s) return [];
534
- const u = [...s];
535
- return u.filter((g) => n.includes(g.id)).forEach((g) => {
536
- g.archived = r;
537
- }), e.log("Local state updated", { archivedCount: n.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;
538
1143
  }), e.groupEnd();
539
- } catch (s) {
540
- throw e.error("Failed to archive notifications", s, { ids: n }), e.groupEnd(), s;
1144
+ } catch (a) {
1145
+ throw e.error("Failed to archive notifications", a, { ids: i }), e.groupEnd(), a;
541
1146
  }
542
- }, oe = (t, r, n, s) => (e.log("Updating single delivery preference", {
543
- notificationId: t,
1147
+ }, ue = (o, r, i, a) => (e.log("Updating single delivery preference", {
1148
+ notificationId: o,
544
1149
  channel: r,
545
- delivery: n,
546
- subNotificationId: s
547
- }), K([
1150
+ delivery: i,
1151
+ subNotificationId: a
1152
+ }), ne([
548
1153
  {
549
- notificationId: t,
1154
+ notificationId: o,
550
1155
  channel: r,
551
- delivery: n,
552
- subNotificationId: s
1156
+ delivery: i,
1157
+ subNotificationId: a
553
1158
  }
554
- ])), K = (t) => {
555
- 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 });
556
1161
  try {
557
- f.rest.postPreferences(t).then(() => {
1162
+ p.rest.postPreferences(o).then(() => {
558
1163
  e.log(
559
1164
  "Preferences updated successfully, fetching latest preferences"
560
- ), f.getPreferences().then((r) => {
561
- var n, s, u;
1165
+ ), p.getPreferences().then((r) => {
1166
+ var i, a, C;
562
1167
  e.log("Latest preferences fetched", {
563
- preferencesCount: ((n = r.preferences) == null ? void 0 : n.length) || 0,
564
- notificationsCount: ((s = r.notifications) == null ? void 0 : s.length) || 0,
565
- subNotificationsCount: ((u = r.subNotifications) == null ? void 0 : u.length) || 0
566
- }), l(r), e.groupEnd();
1168
+ preferencesCount: ((i = r.preferences) == null ? void 0 : i.length) || 0,
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();
567
1172
  }).catch((r) => {
568
1173
  e.error("Failed to fetch updated preferences", r), e.groupEnd();
569
1174
  });
570
1175
  }).catch((r) => {
571
- e.error("Failed to update preferences", r, { params: t }), e.groupEnd();
1176
+ e.error("Failed to update preferences", r, { params: o }), e.groupEnd();
572
1177
  });
573
1178
  } catch (r) {
574
- 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;
575
1180
  }
576
- }, L = k(() => {
1181
+ }, T = B(() => {
577
1182
  e.group("Requesting web push permission"), e.log("Service worker support check", {
578
1183
  supported: "serviceWorker" in navigator,
579
- customServiceWorkerPath: a.customServiceWorkerPath
580
- }), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(a.customServiceWorkerPath).then(async (t) => {
581
- e.log("Service worker registered successfully"), S(!1), le().then(async (r) => {
582
- 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({
583
1188
  userVisibleOnly: !0,
584
- applicationServerKey: h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey
585
- }).then(async (n) => {
1189
+ applicationServerKey: k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey
1190
+ }).then(async (i) => {
586
1191
  e.log("Push subscription successful");
587
- const s = {
1192
+ const a = {
588
1193
  webPushTokens: [
589
1194
  {
590
1195
  sub: {
591
- endpoint: n.toJSON().endpoint,
592
- keys: n.toJSON().keys
1196
+ endpoint: i.toJSON().endpoint,
1197
+ keys: i.toJSON().keys
593
1198
  }
594
1199
  }
595
1200
  ]
596
1201
  };
597
- 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();
598
1203
  })) : r === "denied" && (e.warn("Permission for notifications was denied"), console.log("Permission for notifications was denied"), e.groupEnd());
599
1204
  });
600
- }).catch((t) => {
1205
+ }).catch((o) => {
601
1206
  e.error(
602
1207
  "Service worker registration or push subscription failed",
603
- t,
1208
+ o,
604
1209
  {
605
- errorCode: t.code,
606
- customServiceWorkerPath: a.customServiceWorkerPath
1210
+ errorCode: o.code,
1211
+ customServiceWorkerPath: n.customServiceWorkerPath
607
1212
  }
608
- ), t.code === 18 ? console.error(
1213
+ ), o.code === 18 ? console.error(
609
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."
610
- ) : t.code === 19 ? console.error(
1215
+ ) : o.code === 19 ? console.error(
611
1216
  "The operation is aborted. This can happen if the user denies the permission request."
612
- ) : t.code === 20 ? console.error(
1217
+ ) : o.code === 20 ? console.error(
613
1218
  "The operation is invalid. This can occur if the provided application server key is invalid. Please contact NotificationAPI support."
614
- ) : t.code === 21 ? console.error(
1219
+ ) : o.code === 21 ? console.error(
615
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."
616
- ) : t.code === 22 ? console.error(
1221
+ ) : o.code === 22 ? console.error(
617
1222
  "The operation is not supported. This can occur if the browser does not support the required features."
618
- ) : console.error(t), e.groupEnd();
1223
+ ) : console.error(o), e.groupEnd();
619
1224
  })) : (e.warn("Service worker not supported in this browser"), e.groupEnd());
620
1225
  }, [
621
- f,
622
- a.customServiceWorkerPath,
623
- h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey,
1226
+ p,
1227
+ n.customServiceWorkerPath,
1228
+ k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey,
624
1229
  e
625
1230
  ]);
626
- E(() => {
627
- e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), p([]), v(!1), l(void 0), P((/* @__PURE__ */ new Date()).toISOString()), $(!0), R(!0), e.log("Opening WebSocket connection"), f.openWebSocket(), e.log("Fetching user preferences"), f.getPreferences().then((t) => {
628
- var r, n, 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;
629
1234
  e.log("Initial preferences loaded", {
630
- preferencesCount: ((r = t.preferences) == null ? void 0 : r.length) || 0,
631
- notificationsCount: ((n = t.notifications) == null ? void 0 : n.length) || 0,
632
- subNotificationsCount: ((s = t.subNotifications) == null ? void 0 : s.length) || 0
633
- }), l(t), e.groupEnd();
634
- }).catch((t) => {
635
- 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();
636
1241
  });
637
- }, [f, R, L, e]), E(() => {
638
- 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) => {
639
1244
  e.log("User account metadata loaded", {
640
- hasWebPushEnabled: t.userAccountMetadata.hasWebPushEnabled,
641
- environmentVapidPublicKey: t.userAccountMetadata.environmentVapidPublicKey ? "present" : "missing"
642
- }), b(t), Q && "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", {
643
1248
  permission: Notification.permission
644
1249
  }), Notification.permission !== "default" && (e.log(
645
1250
  "Setting webPushOptInMessage to false (permission already set)"
646
- ), S(!1))) : (e.log(
1251
+ ), A(!1))) : (e.log(
647
1252
  "Browser notification not supported, using server setting",
648
1253
  {
649
- hasWebPushEnabled: t.userAccountMetadata.hasWebPushEnabled
1254
+ hasWebPushEnabled: o.userAccountMetadata.hasWebPushEnabled
650
1255
  }
651
- ), S(t.userAccountMetadata.hasWebPushEnabled)), e.groupEnd();
652
- }).catch((t) => {
653
- 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();
654
1259
  });
655
- }, [f, e]), E(() => {
656
- if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", y), y === "AUTOMATIC") {
657
- 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";
658
1263
  e.log("Automatic mode - checking localStorage", {
659
- hideMessage: t,
660
- shouldShow: !t
661
- }), S(!t);
1264
+ hideMessage: o,
1265
+ shouldShow: !o
1266
+ }), A(!o);
662
1267
  }
663
1268
  e.groupEnd();
664
- }, [y, e]), E(() => {
665
- e.group("Handling webPushOptIn state"), e.log("webPushOptIn state", M), M && (e.log("User opted in for web push, requesting permission"), L()), e.groupEnd();
666
- }, [M, L, e]);
667
- const ne = {
668
- notifications: c,
669
- preferences: I,
670
- userAccountMetaData: h,
671
- webPushOptInMessage: y,
672
- loadNotifications: R,
673
- markAsOpened: Z,
674
- markAsArchived: te,
675
- markAsUnarchived: ee,
676
- markAsClicked: Y,
677
- updateDelivery: oe,
678
- updateDeliveries: K,
679
- getClient: () => f,
680
- setWebPushOptInMessage: S,
681
- setWebPushOptIn: X
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,
1286
+ setWebPushOptIn: _
682
1287
  };
683
- return e.log("NotificationAPI Provider rendering", {
684
- notificationsCount: (c == null ? void 0 : c.length) || 0,
685
- hasPreferences: !!I,
686
- hasUserAccountMetaData: !!h,
687
- webPushOptInMessage: y,
688
- webPushOptIn: M
689
- }), /* @__PURE__ */ ie(_.Provider, { value: ne, children: o.children });
690
- }, ue = () => {
691
- const o = re(_);
692
- 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)
693
1300
  throw new Error("useMyContext must be used within a MyProvider");
694
- return o;
1301
+ return t;
695
1302
  };
696
- de.useNotificationAPIContext = ue;
697
- const le = async () => {
698
- if (Q && "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")
699
1306
  try {
700
1307
  return await Notification.requestPermission();
701
- } catch (o) {
702
- return console.error("Error requesting notification permission:", o), "default";
1308
+ } catch (t) {
1309
+ return console.error("Error requesting notification permission:", t), "default";
703
1310
  }
704
1311
  else
705
1312
  return console.warn("Web Push Notifications are not supported in this browser."), "default";
706
1313
  };
707
1314
  export {
708
- de as NotificationAPIProvider
1315
+ pt as NotificationAPIProvider
709
1316
  };