@traiyani/chatsdk-react 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import ge from "axios";
2
2
  import { io as Xe } from "socket.io-client";
3
- import { jsxs as M, jsx as u, Fragment as et } from "react/jsx-runtime";
3
+ import { jsx as u, jsxs as M, Fragment as et } from "react/jsx-runtime";
4
4
  import * as V from "react";
5
- import tt, { useState as N, useRef as ne, useCallback as Ie, useEffect as P, createContext as at, useContext as st } from "react";
5
+ import tt, { useState as T, useRef as de, useEffect as P, useCallback as Ie, createContext as at, useContext as st } from "react";
6
6
  class nt {
7
7
  constructor(e) {
8
8
  this.api = null, this.config = null, this.chatSDK = e;
@@ -2418,7 +2418,7 @@ class gt {
2418
2418
  this.socket && (this.socket.off(e, t), (a = this.config) != null && a.enableLogging && console.log("🔇 SocketManager: Stopped listening to event:", e));
2419
2419
  }
2420
2420
  }
2421
- const ce = class ce {
2421
+ const ie = class ie {
2422
2422
  constructor() {
2423
2423
  this.config = null, this.isInitialized = !1, this.currentUser = null, this.auth = new nt(this), this.chatUsers = new rt(this), this.users = new ot(this), this.conversations = new it(this), this.messages = new ct(this), this.media = new lt(this), this.events = new dt(this), this.socket = new gt(this);
2424
2424
  }
@@ -2426,7 +2426,7 @@ const ce = class ce {
2426
2426
  * Get singleton instance of ChatSDK
2427
2427
  */
2428
2428
  static getInstance() {
2429
- return ce.instance || (ce.instance = new ce()), ce.instance;
2429
+ return ie.instance || (ie.instance = new ie()), ie.instance;
2430
2430
  }
2431
2431
  /**
2432
2432
  * Initialize ChatSDK with configuration
@@ -2545,8 +2545,8 @@ const ce = class ce {
2545
2545
  throw new Error("ChatSDK not initialized. Call ChatSDK.init() first.");
2546
2546
  }
2547
2547
  };
2548
- ce.instance = null;
2549
- let R = ce;
2548
+ ie.instance = null;
2549
+ let R = ie;
2550
2550
  R.getInstance();
2551
2551
  const ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2552
2552
  __proto__: null,
@@ -2559,15 +2559,15 @@ let ut = { data: "" }, mt = (c) => typeof window == "object" ? ((c ? c.querySele
2559
2559
  n[0] == "@" ? n[1] == "i" ? t = n + " " + o + ";" : a += n[1] == "f" ? se(o, n) : n + "{" + se(o, n[1] == "k" ? "" : e) + "}" : typeof o == "object" ? a += se(o, e ? e.replace(/([^,])+/g, (r) => n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g, (i) => /&/.test(i) ? i.replace(/&/g, r) : r ? r + " " + i : i)) : n) : o != null && (n = /^--/.test(n) ? n : n.replace(/[A-Z]/g, "-$&").toLowerCase(), s += se.p ? se.p(n, o) : n + ":" + o + ";");
2560
2560
  }
2561
2561
  return t + (e && s ? e + "{" + s + "}" : s) + a;
2562
- }, X = {}, Ne = (c) => {
2562
+ }, X = {}, Te = (c) => {
2563
2563
  if (typeof c == "object") {
2564
2564
  let e = "";
2565
- for (let t in c) e += t + Ne(c[t]);
2565
+ for (let t in c) e += t + Te(c[t]);
2566
2566
  return e;
2567
2567
  }
2568
2568
  return c;
2569
2569
  }, wt = (c, e, t, a, s) => {
2570
- let n = Ne(c), o = X[n] || (X[n] = ((i) => {
2570
+ let n = Te(c), o = X[n] || (X[n] = ((i) => {
2571
2571
  let l = 0, d = 11;
2572
2572
  for (; l < i.length; ) d = 101 * d + i.charCodeAt(l++) >>> 0;
2573
2573
  return "go" + d;
@@ -2602,7 +2602,7 @@ let ee = pe.bind({ k: 1 });
2602
2602
  function yt(c, e, t, a) {
2603
2603
  se.p = e, Ke = c, be = t, Me = a;
2604
2604
  }
2605
- function re(c, e) {
2605
+ function ne(c, e) {
2606
2606
  let t = this || {};
2607
2607
  return function() {
2608
2608
  let a = arguments;
@@ -2697,7 +2697,7 @@ from {
2697
2697
  to {
2698
2698
  transform: scale(1) rotate(90deg);
2699
2699
  opacity: 1;
2700
- }`, Ut = re("div")`
2700
+ }`, Ut = ne("div")`
2701
2701
  width: 20px;
2702
2702
  opacity: 0;
2703
2703
  height: 20px;
@@ -2737,7 +2737,7 @@ to {
2737
2737
  to {
2738
2738
  transform: rotate(360deg);
2739
2739
  }
2740
- `, It = re("div")`
2740
+ `, It = ne("div")`
2741
2741
  width: 12px;
2742
2742
  height: 12px;
2743
2743
  box-sizing: border-box;
@@ -2768,7 +2768,7 @@ to {
2768
2768
  100% {
2769
2769
  opacity: 1;
2770
2770
  height: 10px;
2771
- }`, Tt = re("div")`
2771
+ }`, Nt = ne("div")`
2772
2772
  width: 20px;
2773
2773
  opacity: 0;
2774
2774
  height: 20px;
@@ -2795,9 +2795,9 @@ to {
2795
2795
  height: 10px;
2796
2796
  width: 6px;
2797
2797
  }
2798
- `, Nt = re("div")`
2798
+ `, Tt = ne("div")`
2799
2799
  position: absolute;
2800
- `, Kt = re("div")`
2800
+ `, Kt = ne("div")`
2801
2801
  position: relative;
2802
2802
  display: flex;
2803
2803
  justify-content: center;
@@ -2812,7 +2812,7 @@ from {
2812
2812
  to {
2813
2813
  transform: scale(1);
2814
2814
  opacity: 1;
2815
- }`, Rt = re("div")`
2815
+ }`, Rt = ne("div")`
2816
2816
  position: relative;
2817
2817
  transform: scale(0.6);
2818
2818
  opacity: 0.4;
@@ -2821,14 +2821,14 @@ to {
2821
2821
  forwards;
2822
2822
  `, Bt = ({ toast: c }) => {
2823
2823
  let { icon: e, type: t, iconTheme: a } = c;
2824
- return e !== void 0 ? typeof e == "string" ? V.createElement(Rt, null, e) : e : t === "blank" ? null : V.createElement(Kt, null, V.createElement(It, { ...a }), t !== "loading" && V.createElement(Nt, null, t === "error" ? V.createElement(Ut, { ...a }) : V.createElement(Tt, { ...a })));
2824
+ return e !== void 0 ? typeof e == "string" ? V.createElement(Rt, null, e) : e : t === "blank" ? null : V.createElement(Kt, null, V.createElement(It, { ...a }), t !== "loading" && V.createElement(Tt, null, t === "error" ? V.createElement(Ut, { ...a }) : V.createElement(Nt, { ...a })));
2825
2825
  }, $t = (c) => `
2826
2826
  0% {transform: translate3d(0,${c * -200}%,0) scale(.6); opacity:.5;}
2827
2827
  100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
2828
2828
  `, Pt = (c) => `
2829
2829
  0% {transform: translate3d(0,0,-1px) scale(1); opacity:1;}
2830
2830
  100% {transform: translate3d(0,${c * -150}%,-1px) scale(.6); opacity:0;}
2831
- `, Ot = "0%{opacity:0;} 100%{opacity:1;}", jt = "0%{opacity:1;} 100%{opacity:0;}", Wt = re("div")`
2831
+ `, Ot = "0%{opacity:0;} 100%{opacity:1;}", jt = "0%{opacity:1;} 100%{opacity:0;}", Wt = ne("div")`
2832
2832
  display: flex;
2833
2833
  align-items: center;
2834
2834
  background: #fff;
@@ -2840,7 +2840,7 @@ to {
2840
2840
  pointer-events: auto;
2841
2841
  padding: 8px 10px;
2842
2842
  border-radius: 8px;
2843
- `, qt = re("div")`
2843
+ `, qt = ne("div")`
2844
2844
  display: flex;
2845
2845
  justify-content: center;
2846
2846
  margin: 4px 10px;
@@ -3081,9 +3081,9 @@ const Gt = {
3081
3081
  owner_label: "المالك:"
3082
3082
  }, Re = "chatsdk-root";
3083
3083
  let ue = null;
3084
- const na = (c) => {
3084
+ const aa = (c) => {
3085
3085
  ue = c;
3086
- }, ra = () => {
3086
+ }, sa = () => {
3087
3087
  if (ue && ue.isConnected)
3088
3088
  return ue;
3089
3089
  const c = document.querySelector(`.${Re}`);
@@ -3094,16 +3094,16 @@ const na = (c) => {
3094
3094
  en: Gt,
3095
3095
  ar: Ht
3096
3096
  };
3097
- let le = "en", Te = !1;
3097
+ let ce = "en", Ne = !1;
3098
3098
  const we = () => {
3099
- const c = le, e = Yt() ? "rtl" : "ltr";
3099
+ const c = ce, e = Yt() ? "rtl" : "ltr";
3100
3100
  Se((t) => {
3101
3101
  t.setAttribute("lang", c), t.setAttribute("dir", e);
3102
3102
  });
3103
- }, oa = (c) => {
3104
- fe[c] ? (le = c, localStorage.setItem("chatSDK_language", c)) : (console.warn(`Locale "${c}" not found, falling back to "en".`), le = "en"), we();
3105
- }, ia = () => le, Yt = () => le === "ar", w = (c, e) => {
3106
- let t = fe[le][c] || fe.en[c] || c;
3103
+ }, na = (c) => {
3104
+ fe[c] ? (ce = c, localStorage.setItem("chatSDK_language", c)) : (console.warn(`Locale "${c}" not found, falling back to "en".`), ce = "en"), we();
3105
+ }, ra = () => ce, Yt = () => ce === "ar", w = (c, e) => {
3106
+ let t = fe[ce][c] || fe.en[c] || c;
3107
3107
  if (e)
3108
3108
  for (const a in e)
3109
3109
  t = t.replace(
@@ -3112,13 +3112,17 @@ const we = () => {
3112
3112
  );
3113
3113
  return t;
3114
3114
  }, Be = () => {
3115
- if (Te) return;
3116
- Te = !0;
3115
+ if (Ne) return;
3116
+ Ne = !0;
3117
3117
  const c = localStorage.getItem("chatSDK_language");
3118
- c && fe[c] && (le = c), we();
3119
- }, Jt = ({ conversation: c, currentUser: e, onClose: t, onBack: a }) => {
3118
+ c && fe[c] && (ce = c), we();
3119
+ }, oa = ({ conversation: c, currentUser: e, onClose: t, onBack: a }) => {
3120
3120
  var Ee;
3121
- const [s, n] = N([]), [o, r] = N(""), [i, l] = N(!1), [d, h] = N(!1), [m, p] = N({}), [D, O] = N(!1), [Le, he] = N(!0), [y, C] = N(1), [j, H] = N(null), [B, J] = N(!1), [E, F] = N(!1), [T, x] = N(!1), [K, W] = N(null), [te, ae] = N(!1), Q = ne(null), de = ne(null), $ = ne(null), Y = ne(null), oe = 20, ie = Ie(() => {
3121
+ const [s, n] = T([]), [o, r] = T(""), [i, l] = T(!1), [d, h] = T(!1), [m, p] = T({}), [D, O] = T(!1), [Le, he] = T(!0), [y, C] = T(1), [j, H] = T(null), [B, J] = T(!1), [E, F] = T(!1), [N, x] = T(!1), [K, W] = T(null), [te, ae] = T(!1), Q = de(null), le = de(null), $ = de(null), Y = de(null), re = 20;
3122
+ P(() => {
3123
+ Be(), we();
3124
+ }, []);
3125
+ const oe = Ie(() => {
3122
3126
  if (!c || !e) return null;
3123
3127
  const g = c.participants || [];
3124
3128
  if (g.length === 0) return null;
@@ -3127,7 +3131,7 @@ const we = () => {
3127
3131
  const S = v.id || v.userId, k = v.externalUserId || v.external_user_id;
3128
3132
  return !(f && S && S === f || b && k && k === b) && (S || k);
3129
3133
  }) || null;
3130
- }, [c, e]), U = ie(), q = Ie(() => {
3134
+ }, [c, e]), U = oe(), q = Ie(() => {
3131
3135
  if (!c) return { userName: w("conversations_title"), productName: null, productImage: null, productMetadata: null };
3132
3136
  const g = U && (U.name || U.userName || U.displayName || U.externalUserId) || w("unknown_user"), f = c.productContext || c.product_context;
3133
3137
  return f ? {
@@ -3178,7 +3182,7 @@ const we = () => {
3178
3182
  ...c.metadata || {},
3179
3183
  blockedUsers: I
3180
3184
  };
3181
- const A = e.id || e.userId, L = ie(), Z = L ? L.id || L.userId || L.externalUserId || L.external_user_id : null;
3185
+ const A = e.id || e.userId, L = oe(), Z = L ? L.id || L.userId || L.externalUserId || L.external_user_id : null;
3182
3186
  J(I[A] === 1), F(Z ? I[Z] === 1 : !1);
3183
3187
  };
3184
3188
  return g.events.on("message.received", f), g.events.on("message.read.receipt", b), g.events.on("messages.read.receipt", v), g.events.on("conversation.block_status", S), () => {
@@ -3189,7 +3193,7 @@ const we = () => {
3189
3193
  J(!1), F(!1), H(null);
3190
3194
  return;
3191
3195
  }
3192
- const f = (c.metadata || {}).blockedUsers || {}, b = e.id || e.userId, v = ie(), S = v ? v.id || v.userId || v.externalUserId || v.external_user_id : null;
3196
+ const f = (c.metadata || {}).blockedUsers || {}, b = e.id || e.userId, v = oe(), S = v ? v.id || v.userId || v.externalUserId || v.external_user_id : null;
3193
3197
  J(f[b] === 1), F(S ? f[S] === 1 : !1), H({
3194
3198
  chatId: c.id,
3195
3199
  currentUserId: b,
@@ -3259,12 +3263,12 @@ const we = () => {
3259
3263
  try {
3260
3264
  const v = await R.getInstance().messages.getMessages({
3261
3265
  conversationId: c.id,
3262
- limit: oe,
3263
- offset: (g - 1) * oe
3266
+ limit: re,
3267
+ offset: (g - 1) * re
3264
3268
  }), S = v.sort(
3265
3269
  (k, _) => new Date(k.timestamp).getTime() - new Date(_.timestamp).getTime()
3266
3270
  );
3267
- f && g > 1 ? n((k) => [...S, ...k]) : n(S), he(v.length === oe), C(g);
3271
+ f && g > 1 ? n((k) => [...S, ...k]) : n(S), he(v.length === re), C(g);
3268
3272
  } catch {
3269
3273
  z.error(w("error_load_messages"));
3270
3274
  } finally {
@@ -3387,13 +3391,13 @@ const we = () => {
3387
3391
  z.error(w("failed_to_unblock"));
3388
3392
  }
3389
3393
  };
3390
- return i && s.length === 0 ? /* @__PURE__ */ M("div", { className: "chat-window", children: [
3394
+ return i && s.length === 0 ? /* @__PURE__ */ u("div", { className: "chatsdk-root", children: /* @__PURE__ */ M("div", { className: "chat-window", children: [
3391
3395
  /* @__PURE__ */ M("div", { className: "chat-header", children: [
3392
3396
  /* @__PURE__ */ u("div", { className: "chat-header-left", children: /* @__PURE__ */ u("h3", { style: { margin: 0 }, children: w("loading") }) }),
3393
3397
  /* @__PURE__ */ u("div", { className: "chat-header-actions", children: t && /* @__PURE__ */ u("button", { onClick: t, className: "close-button", children: "×" }) })
3394
3398
  ] }),
3395
3399
  /* @__PURE__ */ u("div", { className: "loading-messages", children: w("loading_messages") })
3396
- ] }) : /* @__PURE__ */ M("div", { className: "chat-window", children: [
3400
+ ] }) }) : /* @__PURE__ */ u("div", { className: "chatsdk-root", children: /* @__PURE__ */ M("div", { className: "chat-window", children: [
3397
3401
  /* @__PURE__ */ M("div", { className: "chat-header", children: [
3398
3402
  /* @__PURE__ */ M("div", { className: "chat-header-left", children: [
3399
3403
  a && /* @__PURE__ */ u("button", { className: "chat-back-btn", onClick: a, title: w("back") || "Back", children: /* @__PURE__ */ u("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ u("polyline", { points: "15 18 9 12 15 6" }) }) }),
@@ -3404,12 +3408,12 @@ const we = () => {
3404
3408
  U && /* @__PURE__ */ u("button", { onClick: He, className: "chat-action-btn", title: w("call") || "Call", children: /* @__PURE__ */ u("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ u("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }) }) }),
3405
3409
  t && /* @__PURE__ */ u("button", { onClick: t, className: "chat-action-btn", title: w("close") || "Close", children: /* @__PURE__ */ u("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ u("path", { d: "M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7" }) }) }),
3406
3410
  c && U && /* @__PURE__ */ M("div", { className: "chat-options-wrapper", children: [
3407
- /* @__PURE__ */ u("button", { onClick: () => x(!T), className: "chat-action-btn", title: w("options") || "Options", children: /* @__PURE__ */ M("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: [
3411
+ /* @__PURE__ */ u("button", { onClick: () => x(!N), className: "chat-action-btn", title: w("options") || "Options", children: /* @__PURE__ */ M("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: [
3408
3412
  /* @__PURE__ */ u("circle", { cx: "12", cy: "5", r: "2" }),
3409
3413
  /* @__PURE__ */ u("circle", { cx: "12", cy: "12", r: "2" }),
3410
3414
  /* @__PURE__ */ u("circle", { cx: "12", cy: "19", r: "2" })
3411
3415
  ] }) }),
3412
- T && /* @__PURE__ */ M("div", { className: "chat-options-menu", children: [
3416
+ N && /* @__PURE__ */ M("div", { className: "chat-options-menu", children: [
3413
3417
  !B && !E && /* @__PURE__ */ M("button", { onClick: Ze, className: "danger", children: [
3414
3418
  /* @__PURE__ */ M("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
3415
3419
  /* @__PURE__ */ u("circle", { cx: "12", cy: "12", r: "10" }),
@@ -3527,7 +3531,7 @@ const we = () => {
3527
3531
  type: "button",
3528
3532
  onClick: () => {
3529
3533
  var g;
3530
- return (g = de.current) == null ? void 0 : g.click();
3534
+ return (g = le.current) == null ? void 0 : g.click();
3531
3535
  },
3532
3536
  disabled: i || d || B,
3533
3537
  className: "attachment-btn",
@@ -3538,7 +3542,7 @@ const we = () => {
3538
3542
  /* @__PURE__ */ u(
3539
3543
  "input",
3540
3544
  {
3541
- ref: de,
3545
+ ref: le,
3542
3546
  type: "file",
3543
3547
  style: { display: "none" },
3544
3548
  accept: "image/*,video/*,audio/*,.pdf,.doc,.docx,.txt",
@@ -3561,19 +3565,16 @@ const we = () => {
3561
3565
  ),
3562
3566
  /* @__PURE__ */ u("button", { type: "submit", disabled: !o.trim() || i || d || B, className: "send-btn", children: w(d ? "uploading" : "send") })
3563
3567
  ] })
3564
- ] });
3565
- }, ca = (c) => {
3566
- const e = ne(null);
3567
- return P(() => {
3568
- Be(), we();
3569
- }, []), /* @__PURE__ */ u("div", { ref: e, className: "chatsdk-root", children: /* @__PURE__ */ u(Jt, { ...c }) });
3570
- }, Qt = ({
3568
+ ] }) });
3569
+ }, ia = ({
3571
3570
  currentUser: c,
3572
3571
  onSelectConversation: e,
3573
3572
  selectedConversationId: t
3574
3573
  }) => {
3575
- const [a, s] = N([]), [n, o] = N(!1), [r, i] = N(""), l = ne(t), d = ne(c.id);
3574
+ const [a, s] = T([]), [n, o] = T(!1), [r, i] = T(""), l = de(t), d = de(c.id);
3576
3575
  P(() => {
3576
+ Be(), we();
3577
+ }, []), P(() => {
3577
3578
  l.current = t;
3578
3579
  }, [t]), P(() => {
3579
3580
  d.current = c.id;
@@ -3584,11 +3585,11 @@ const we = () => {
3584
3585
  }, [c.id]), P(() => {
3585
3586
  var J;
3586
3587
  const y = R.getInstance(), C = (E) => {
3587
- const F = E.message, T = F.roomId || F.conversationId;
3588
+ const F = E.message, N = F.roomId || F.conversationId;
3588
3589
  s(
3589
3590
  (x) => x.map((K) => {
3590
- if (K.id === T) {
3591
- const W = F.senderId !== d.current, te = l.current !== T;
3591
+ if (K.id === N) {
3592
+ const W = F.senderId !== d.current, te = l.current !== N;
3592
3593
  return {
3593
3594
  ...K,
3594
3595
  lastMessage: F,
@@ -3597,14 +3598,14 @@ const we = () => {
3597
3598
  }
3598
3599
  return K;
3599
3600
  }).sort((K, W) => {
3600
- var Q, de;
3601
- const te = ((Q = K.lastMessage) == null ? void 0 : Q.timestamp) || K.createdAt, ae = ((de = W.lastMessage) == null ? void 0 : de.timestamp) || W.createdAt;
3601
+ var Q, le;
3602
+ const te = ((Q = K.lastMessage) == null ? void 0 : Q.timestamp) || K.createdAt, ae = ((le = W.lastMessage) == null ? void 0 : le.timestamp) || W.createdAt;
3602
3603
  return new Date(ae).getTime() - new Date(te).getTime();
3603
3604
  })
3604
- ), F.senderId !== d.current && l.current === T && R.getInstance().chatUsers.markMessageRead(F.id).then(() => {
3605
+ ), F.senderId !== d.current && l.current === N && R.getInstance().chatUsers.markMessageRead(F.id).then(() => {
3605
3606
  s(
3606
3607
  (K) => K.map(
3607
- (W) => W.id === T ? { ...W, unreadCount: 0 } : W
3608
+ (W) => W.id === N ? { ...W, unreadCount: 0 } : W
3608
3609
  )
3609
3610
  );
3610
3611
  }).catch((K) => {
@@ -3614,38 +3615,38 @@ const we = () => {
3614
3615
  var K, W, te, ae;
3615
3616
  const F = E.conversationId || ((K = E.conversation) == null ? void 0 : K.id) || ((W = E.conversation) == null ? void 0 : W.conversationId);
3616
3617
  if (!F) return;
3617
- const T = E.lastMessage || ((te = E.conversation) == null ? void 0 : te.lastMessage), x = (ae = E.conversation) == null ? void 0 : ae.unreadCount;
3618
+ const N = E.lastMessage || ((te = E.conversation) == null ? void 0 : te.lastMessage), x = (ae = E.conversation) == null ? void 0 : ae.unreadCount;
3618
3619
  s((Q) => Q.some(($) => $.id === F) ? Q.map(($) => {
3619
3620
  if ($.id !== F) return $;
3620
- const Y = l.current === F, oe = d.current;
3621
+ const Y = l.current === F, re = d.current;
3621
3622
  if (typeof x == "number")
3622
3623
  return {
3623
3624
  ...$,
3624
- lastMessage: T || $.lastMessage,
3625
+ lastMessage: N || $.lastMessage,
3625
3626
  unreadCount: Y ? 0 : x
3626
3627
  };
3627
- const ie = (T == null ? void 0 : T.senderId) && T.senderId !== oe, U = !!T && ie && !Y;
3628
+ const oe = (N == null ? void 0 : N.senderId) && N.senderId !== re, U = !!N && oe && !Y;
3628
3629
  return {
3629
3630
  ...$,
3630
- lastMessage: T || $.lastMessage,
3631
+ lastMessage: N || $.lastMessage,
3631
3632
  unreadCount: Y ? 0 : U ? $.unreadCount + 1 : $.unreadCount
3632
3633
  };
3633
3634
  }).sort(($, Y) => {
3634
3635
  var U, ke;
3635
- const oe = ((U = $.lastMessage) == null ? void 0 : U.timestamp) || $.createdAt, ie = ((ke = Y.lastMessage) == null ? void 0 : ke.timestamp) || Y.createdAt;
3636
- return new Date(ie).getTime() - new Date(oe).getTime();
3636
+ const re = ((U = $.lastMessage) == null ? void 0 : U.timestamp) || $.createdAt, oe = ((ke = Y.lastMessage) == null ? void 0 : ke.timestamp) || Y.createdAt;
3637
+ return new Date(oe).getTime() - new Date(re).getTime();
3637
3638
  }) : (m(), Q));
3638
3639
  }, H = (E) => {
3639
3640
  const F = E.conversationId || E.roomId;
3640
3641
  F && s(
3641
- (T) => T.map(
3642
+ (N) => N.map(
3642
3643
  (x) => x.id === F ? { ...x, unreadCount: 0 } : x
3643
3644
  )
3644
3645
  );
3645
3646
  }, B = (E) => {
3646
3647
  const F = E.roomId || E.conversationId;
3647
3648
  F && s(
3648
- (T) => T.map(
3649
+ (N) => N.map(
3649
3650
  (x) => x.id === F ? { ...x, unreadCount: 0 } : x
3650
3651
  )
3651
3652
  );
@@ -3690,7 +3691,7 @@ const we = () => {
3690
3691
  const C = r.toLowerCase().trim(), j = D(y).toLowerCase(), H = ((E = (J = y.productContext) == null ? void 0 : J.productName) == null ? void 0 : E.toLowerCase()) || "", B = O(y).toLowerCase();
3691
3692
  return j.includes(C) || H.includes(C) || B.includes(C);
3692
3693
  }) : a;
3693
- return n ? /* @__PURE__ */ u("div", { className: "conversation-list loading", children: /* @__PURE__ */ u("div", { className: "loading-spinner", children: w("loading_conversations") }) }) : /* @__PURE__ */ M("div", { className: "conversation-list", children: [
3694
+ return n ? /* @__PURE__ */ u("div", { className: "chatsdk-root", children: /* @__PURE__ */ u("div", { className: "conversation-list loading", children: /* @__PURE__ */ u("div", { className: "loading-spinner", children: w("loading_conversations") }) }) }) : /* @__PURE__ */ u("div", { className: "chatsdk-root", children: /* @__PURE__ */ M("div", { className: "conversation-list", children: [
3694
3695
  /* @__PURE__ */ u("div", { className: "conversation-list-header", children: /* @__PURE__ */ u("h3", { children: w("conversations_title") }) }),
3695
3696
  /* @__PURE__ */ u("div", { className: "conversation-search", children: /* @__PURE__ */ M("div", { className: "conversation-search-input", children: [
3696
3697
  /* @__PURE__ */ u("span", { className: "search-icon", children: /* @__PURE__ */ M("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
@@ -3742,14 +3743,9 @@ const we = () => {
3742
3743
  y.id
3743
3744
  );
3744
3745
  }) })
3745
- ] });
3746
- }, la = (c) => {
3747
- const e = ne(null);
3748
- return P(() => {
3749
- Be(), we();
3750
- }, []), /* @__PURE__ */ u("div", { ref: e, className: "chatsdk-root", children: /* @__PURE__ */ u(Qt, { ...c }) });
3751
- }, Zt = () => {
3752
- const [c, e] = N(() => typeof window < "u" && localStorage.getItem("chatSDK-theme") || "auto"), [t, a] = N(() => typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"), s = c === "auto" ? t : c;
3746
+ ] }) });
3747
+ }, Jt = () => {
3748
+ const [c, e] = T(() => typeof window < "u" && localStorage.getItem("chatSDK-theme") || "auto"), [t, a] = T(() => typeof window < "u" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"), s = c === "auto" ? t : c;
3753
3749
  P(() => {
3754
3750
  if (typeof window > "u" || !window.matchMedia) return;
3755
3751
  const r = window.matchMedia("(prefers-color-scheme: dark)"), i = (l) => {
@@ -3772,19 +3768,19 @@ const we = () => {
3772
3768
  n(c === "auto" ? t === "light" ? "dark" : "light" : s === "light" ? "dark" : "light");
3773
3769
  }
3774
3770
  };
3775
- }, $e = at(void 0), da = ({ children: c }) => {
3776
- const e = Zt();
3771
+ }, $e = at(void 0), ca = ({ children: c }) => {
3772
+ const e = Jt();
3777
3773
  return /* @__PURE__ */ u($e.Provider, { value: e, children: c });
3778
- }, Xt = () => {
3774
+ }, Qt = () => {
3779
3775
  const c = st($e);
3780
3776
  if (!c)
3781
3777
  throw new Error("useThemeContext must be used within a ThemeProvider");
3782
3778
  return c;
3783
- }, ga = ({
3779
+ }, la = ({
3784
3780
  className: c = "",
3785
3781
  showLabel: e = !1
3786
3782
  }) => {
3787
- const { theme: t, actualTheme: a, setTheme: s } = Xt(), n = () => {
3783
+ const { theme: t, actualTheme: a, setTheme: s } = Qt(), n = () => {
3788
3784
  switch (t) {
3789
3785
  case "light":
3790
3786
  return /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ u("path", { d: "M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z" }) });
@@ -3839,13 +3835,13 @@ const we = () => {
3839
3835
  ]
3840
3836
  }
3841
3837
  );
3842
- }, ha = () => {
3838
+ }, da = () => {
3843
3839
  var s;
3844
3840
  const c = localStorage.getItem("chatSDK-theme"), e = (s = window.matchMedia) == null ? void 0 : s.call(window, "(prefers-color-scheme: dark)").matches, t = c || "auto", a = t === "auto" ? e ? "dark" : "light" : t;
3845
3841
  Se((n) => {
3846
3842
  n.classList.add(`theme-${a}`), n.setAttribute("data-theme", a);
3847
3843
  });
3848
- }, ua = {
3844
+ }, ga = {
3849
3845
  // Material Design 3 Primary Colors
3850
3846
  primary: {
3851
3847
  main: "#2196F3",
@@ -3929,7 +3925,7 @@ const we = () => {
3929
3925
  black: "#000000",
3930
3926
  transparent: "transparent"
3931
3927
  }
3932
- }, ma = {
3928
+ }, ha = {
3933
3929
  primary: {
3934
3930
  main: "#90CAF9",
3935
3931
  onPrimary: "#0D47A1",
@@ -3977,7 +3973,7 @@ const we = () => {
3977
3973
  timestamp: "#BDBDBD",
3978
3974
  primaryText: "#FFFFFF"
3979
3975
  }
3980
- }, fa = {
3976
+ }, ua = {
3981
3977
  async init(c) {
3982
3978
  const { ChatSDK: e } = await Promise.resolve().then(() => ht);
3983
3979
  return e.getInstance().init(c);
@@ -3995,30 +3991,30 @@ const we = () => {
3995
3991
  export {
3996
3992
  nt as AuthManager,
3997
3993
  R as ChatSDK,
3998
- fa as ChatSDKHelpers,
3999
- ca as ChatWindow,
4000
- la as ConversationList,
3994
+ ua as ChatSDKHelpers,
3995
+ oa as ChatWindow,
3996
+ ia as ConversationList,
4001
3997
  it as ConversationManager,
4002
3998
  dt as EventManager,
4003
3999
  lt as MediaManager,
4004
4000
  ct as MessageManager,
4005
4001
  Ae as ParseUtils,
4006
4002
  gt as SocketManager,
4007
- da as ThemeProvider,
4008
- ga as ThemeToggle,
4003
+ ca as ThemeProvider,
4004
+ la as ThemeToggle,
4009
4005
  ot as UserManager,
4010
4006
  we as applyLanguageToDOM,
4011
- oa as changeLanguage,
4012
- ma as darkThemeConfig,
4013
- ia as getCurrentLanguage,
4014
- ra as getSDKRoot,
4007
+ na as changeLanguage,
4008
+ ha as darkThemeConfig,
4009
+ ra as getCurrentLanguage,
4010
+ sa as getSDKRoot,
4015
4011
  Be as initializeI18n,
4016
- ha as initializeTheme,
4012
+ da as initializeTheme,
4017
4013
  Yt as isRTL,
4018
- na as setSDKRoot,
4014
+ aa as setSDKRoot,
4019
4015
  w as t,
4020
- ua as themeConfig,
4021
- Zt as useTheme,
4022
- Xt as useThemeContext
4016
+ ga as themeConfig,
4017
+ Jt as useTheme,
4018
+ Qt as useThemeContext
4023
4019
  };
4024
4020
  //# sourceMappingURL=chatsdk-react.mjs.map