@channelhub/widget 0.1.7 → 0.1.8

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.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { jsx as e, jsxs as n, Fragment as te } from "react/jsx-runtime";
2
- import { forwardRef as Le, createElement as Pe, createContext as nt, useRef as ee, useState as y, useMemo as Ee, useCallback as We, useEffect as Y, useImperativeHandle as yt, useContext as Ne, Component as mt } from "react";
3
- import { createPortal as it } from "react-dom";
1
+ import { jsx as e, jsxs as n, Fragment as ne } from "react/jsx-runtime";
2
+ import { forwardRef as Le, createElement as Pe, createContext as rt, useRef as Z, useState as y, useMemo as Ee, useCallback as ke, useEffect as V, useImperativeHandle as mt, useContext as Ne, Component as xt } from "react";
3
+ import { createPortal as ot } from "react-dom";
4
4
  /**
5
5
  * @license lucide-react v0.468.0 - ISC
6
6
  *
7
7
  * This source code is licensed under the ISC license.
8
8
  * See the LICENSE file in the root directory of this source tree.
9
9
  */
10
- const bt = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), rt = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
10
+ const vt = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), at = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
11
11
  /**
12
12
  * @license lucide-react v0.468.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
16
  */
17
- var xt = {
17
+ var kt = {
18
18
  xmlns: "http://www.w3.org/2000/svg",
19
19
  width: 24,
20
20
  height: 24,
@@ -31,31 +31,31 @@ var xt = {
31
31
  * This source code is licensed under the ISC license.
32
32
  * See the LICENSE file in the root directory of this source tree.
33
33
  */
34
- const vt = Le(
34
+ const wt = Le(
35
35
  ({
36
36
  color: t = "currentColor",
37
37
  size: i = 24,
38
38
  strokeWidth: r = 2,
39
39
  absoluteStrokeWidth: o,
40
40
  className: s = "",
41
- children: C,
42
- iconNode: m,
43
- ...O
41
+ children: k,
42
+ iconNode: g,
43
+ ...$
44
44
  }, f) => Pe(
45
45
  "svg",
46
46
  {
47
47
  ref: f,
48
- ...xt,
48
+ ...kt,
49
49
  width: i,
50
50
  height: i,
51
51
  stroke: t,
52
52
  strokeWidth: o ? Number(r) * 24 / Number(i) : r,
53
- className: rt("lucide", s),
54
- ...O
53
+ className: at("lucide", s),
54
+ ...$
55
55
  },
56
56
  [
57
- ...m.map(([S, W]) => Pe(S, W)),
58
- ...Array.isArray(C) ? C : [C]
57
+ ...g.map(([x, R]) => Pe(x, R)),
58
+ ...Array.isArray(k) ? k : [k]
59
59
  ]
60
60
  )
61
61
  );
@@ -65,12 +65,12 @@ const vt = Le(
65
65
  * This source code is licensed under the ISC license.
66
66
  * See the LICENSE file in the root directory of this source tree.
67
67
  */
68
- const X = (t, i) => {
68
+ const G = (t, i) => {
69
69
  const r = Le(
70
- ({ className: o, ...s }, C) => Pe(vt, {
71
- ref: C,
70
+ ({ className: o, ...s }, k) => Pe(wt, {
71
+ ref: k,
72
72
  iconNode: i,
73
- className: rt(`lucide-${bt(t)}`, o),
73
+ className: at(`lucide-${vt(t)}`, o),
74
74
  ...s
75
75
  })
76
76
  );
@@ -82,7 +82,7 @@ const X = (t, i) => {
82
82
  * This source code is licensed under the ISC license.
83
83
  * See the LICENSE file in the root directory of this source tree.
84
84
  */
85
- const Ge = X("CheckCheck", [
85
+ const Xe = G("CheckCheck", [
86
86
  ["path", { d: "M18 6 7 17l-5-5", key: "116fxf" }],
87
87
  ["path", { d: "m22 10-7.5 7.5L13 16", key: "ke71qq" }]
88
88
  ]);
@@ -92,14 +92,14 @@ const Ge = X("CheckCheck", [
92
92
  * This source code is licensed under the ISC license.
93
93
  * See the LICENSE file in the root directory of this source tree.
94
94
  */
95
- const ot = X("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
95
+ const lt = G("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
96
96
  /**
97
97
  * @license lucide-react v0.468.0 - ISC
98
98
  *
99
99
  * This source code is licensed under the ISC license.
100
100
  * See the LICENSE file in the root directory of this source tree.
101
101
  */
102
- const kt = X("ChevronDown", [
102
+ const St = G("ChevronDown", [
103
103
  ["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]
104
104
  ]);
105
105
  /**
@@ -108,7 +108,7 @@ const kt = X("ChevronDown", [
108
108
  * This source code is licensed under the ISC license.
109
109
  * See the LICENSE file in the root directory of this source tree.
110
110
  */
111
- const wt = X("ChevronRight", [
111
+ const Ct = G("ChevronRight", [
112
112
  ["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]
113
113
  ]);
114
114
  /**
@@ -117,7 +117,7 @@ const wt = X("ChevronRight", [
117
117
  * This source code is licensed under the ISC license.
118
118
  * See the LICENSE file in the root directory of this source tree.
119
119
  */
120
- const St = X("CircleAlert", [
120
+ const It = G("CircleAlert", [
121
121
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
122
122
  ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
123
123
  ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
@@ -128,7 +128,7 @@ const St = X("CircleAlert", [
128
128
  * This source code is licensed under the ISC license.
129
129
  * See the LICENSE file in the root directory of this source tree.
130
130
  */
131
- const at = X("Ellipsis", [
131
+ const dt = G("Ellipsis", [
132
132
  ["circle", { cx: "12", cy: "12", r: "1", key: "41hilf" }],
133
133
  ["circle", { cx: "19", cy: "12", r: "1", key: "1wjl8i" }],
134
134
  ["circle", { cx: "5", cy: "12", r: "1", key: "1pcz8c" }]
@@ -139,7 +139,7 @@ const at = X("Ellipsis", [
139
139
  * This source code is licensed under the ISC license.
140
140
  * See the LICENSE file in the root directory of this source tree.
141
141
  */
142
- const Ct = X("Image", [
142
+ const zt = G("Image", [
143
143
  ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2", key: "1m3agn" }],
144
144
  ["circle", { cx: "9", cy: "9", r: "2", key: "af1f0g" }],
145
145
  ["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21", key: "1xmnt7" }]
@@ -150,7 +150,7 @@ const Ct = X("Image", [
150
150
  * This source code is licensed under the ISC license.
151
151
  * See the LICENSE file in the root directory of this source tree.
152
152
  */
153
- const It = X("Inbox", [
153
+ const Tt = G("Inbox", [
154
154
  ["polyline", { points: "22 12 16 12 14 15 10 15 8 12 2 12", key: "o97t9d" }],
155
155
  [
156
156
  "path",
@@ -166,7 +166,7 @@ const It = X("Inbox", [
166
166
  * This source code is licensed under the ISC license.
167
167
  * See the LICENSE file in the root directory of this source tree.
168
168
  */
169
- const zt = X("Info", [
169
+ const Rt = G("Info", [
170
170
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
171
171
  ["path", { d: "M12 16v-4", key: "1dtifu" }],
172
172
  ["path", { d: "M12 8h.01", key: "e9boi3" }]
@@ -177,7 +177,7 @@ const zt = X("Info", [
177
177
  * This source code is licensed under the ISC license.
178
178
  * See the LICENSE file in the root directory of this source tree.
179
179
  */
180
- const lt = X("LoaderCircle", [
180
+ const ct = G("LoaderCircle", [
181
181
  ["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]
182
182
  ]);
183
183
  /**
@@ -186,7 +186,16 @@ const lt = X("LoaderCircle", [
186
186
  * This source code is licensed under the ISC license.
187
187
  * See the LICENSE file in the root directory of this source tree.
188
188
  */
189
- const Tt = X("Paperclip", [
189
+ const Ye = G("MessageCircle", [
190
+ ["path", { d: "M7.9 20A9 9 0 1 0 4 16.1L2 22Z", key: "vv11sd" }]
191
+ ]);
192
+ /**
193
+ * @license lucide-react v0.468.0 - ISC
194
+ *
195
+ * This source code is licensed under the ISC license.
196
+ * See the LICENSE file in the root directory of this source tree.
197
+ */
198
+ const Wt = G("Paperclip", [
190
199
  ["path", { d: "M13.234 20.252 21 12.3", key: "1cbrk9" }],
191
200
  [
192
201
  "path",
@@ -202,7 +211,7 @@ const Tt = X("Paperclip", [
202
211
  * This source code is licensed under the ISC license.
203
212
  * See the LICENSE file in the root directory of this source tree.
204
213
  */
205
- const Rt = X("Play", [
214
+ const Bt = G("Play", [
206
215
  ["polygon", { points: "6 3 20 12 6 21 6 3", key: "1oa8hb" }]
207
216
  ]);
208
217
  /**
@@ -211,7 +220,7 @@ const Rt = X("Play", [
211
220
  * This source code is licensed under the ISC license.
212
221
  * See the LICENSE file in the root directory of this source tree.
213
222
  */
214
- const Xe = X("Search", [
223
+ const Je = G("Search", [
215
224
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
216
225
  ["path", { d: "m21 21-4.3-4.3", key: "1qie3q" }]
217
226
  ]);
@@ -221,7 +230,7 @@ const Xe = X("Search", [
221
230
  * This source code is licensed under the ISC license.
222
231
  * See the LICENSE file in the root directory of this source tree.
223
232
  */
224
- const Bt = X("Send", [
233
+ const $t = G("Send", [
225
234
  [
226
235
  "path",
227
236
  {
@@ -237,7 +246,7 @@ const Bt = X("Send", [
237
246
  * This source code is licensed under the ISC license.
238
247
  * See the LICENSE file in the root directory of this source tree.
239
248
  */
240
- const Wt = X("SlidersHorizontal", [
249
+ const Lt = G("SlidersHorizontal", [
241
250
  ["line", { x1: "21", x2: "14", y1: "4", y2: "4", key: "obuewd" }],
242
251
  ["line", { x1: "10", x2: "3", y1: "4", y2: "4", key: "1q6298" }],
243
252
  ["line", { x1: "21", x2: "12", y1: "12", y2: "12", key: "1iu8h1" }],
@@ -254,7 +263,7 @@ const Wt = X("SlidersHorizontal", [
254
263
  * This source code is licensed under the ISC license.
255
264
  * See the LICENSE file in the root directory of this source tree.
256
265
  */
257
- const $t = X("Smile", [
266
+ const Mt = G("Smile", [
258
267
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
259
268
  ["path", { d: "M8 14s1.5 2 4 2 4-2 4-2", key: "1y1vjs" }],
260
269
  ["line", { x1: "9", x2: "9.01", y1: "9", y2: "9", key: "yxxnd0" }],
@@ -266,7 +275,7 @@ const $t = X("Smile", [
266
275
  * This source code is licensed under the ISC license.
267
276
  * See the LICENSE file in the root directory of this source tree.
268
277
  */
269
- const je = X("X", [
278
+ const je = G("X", [
270
279
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
271
280
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
272
281
  ]);
@@ -276,7 +285,7 @@ const je = X("X", [
276
285
  * This source code is licensed under the ISC license.
277
286
  * See the LICENSE file in the root directory of this source tree.
278
287
  */
279
- const Lt = X("Zap", [
288
+ const Ht = G("Zap", [
280
289
  [
281
290
  "path",
282
291
  {
@@ -285,7 +294,7 @@ const Lt = X("Zap", [
285
294
  }
286
295
  ]
287
296
  ]);
288
- class Mt {
297
+ class st {
289
298
  constructor(i, r) {
290
299
  this.apiUrl = i, this.token = r;
291
300
  }
@@ -294,12 +303,12 @@ class Mt {
294
303
  authorization: `Bearer ${this.token}`,
295
304
  ...o ? {} : { "content-type": "application/json" },
296
305
  ...r == null ? void 0 : r.headers
297
- }, C = await fetch(`${this.apiUrl}${i}`, {
306
+ }, k = await fetch(`${this.apiUrl}${i}`, {
298
307
  ...r,
299
308
  headers: s
300
- }), m = await C.json().catch(() => null);
301
- if (!C.ok) throw new Error((m == null ? void 0 : m.message) ?? `Request failed (${C.status})`);
302
- return m;
309
+ }), g = await k.json().catch(() => null);
310
+ if (!k.ok) throw new Error((g == null ? void 0 : g.message) ?? `Request failed (${k.status})`);
311
+ return g;
303
312
  }
304
313
  listConnections() {
305
314
  return this.request("/v1/connections");
@@ -356,38 +365,38 @@ class Mt {
356
365
  }
357
366
  connectSSE(i) {
358
367
  const r = `${this.apiUrl}/v1/events?token=${encodeURIComponent(this.token)}`;
359
- let o, s, C = !1;
360
- const m = () => {
361
- o = new EventSource(r), o.addEventListener("message.new", (O) => {
362
- i("message.new", JSON.parse(O.data));
363
- }), o.addEventListener("conversation.updated", (O) => {
364
- i("conversation.updated", JSON.parse(O.data));
368
+ let o, s, k = !1;
369
+ const g = () => {
370
+ o = new EventSource(r), o.addEventListener("message.new", ($) => {
371
+ i("message.new", JSON.parse($.data));
372
+ }), o.addEventListener("conversation.updated", ($) => {
373
+ i("conversation.updated", JSON.parse($.data));
365
374
  }), o.onerror = () => {
366
- o.close(), C || (s = setTimeout(m, 5e3));
375
+ o.close(), k || (s = setTimeout(g, 5e3));
367
376
  };
368
377
  };
369
- return m(), () => {
370
- C = !0, clearTimeout(s), o == null || o.close();
378
+ return g(), () => {
379
+ k = !0, clearTimeout(s), o == null || o.close();
371
380
  };
372
381
  }
373
382
  }
374
- function dt({ src: t, alt: i = "", fallback: r, style: o }) {
383
+ function qe({ src: t, alt: i = "", fallback: r, style: o }) {
375
384
  return t ? /* @__PURE__ */ e("img", { src: t, alt: i, style: { width: 38, height: 38, borderRadius: "50%", objectFit: "cover", ...o } }) : /* @__PURE__ */ e("span", { style: { display: "grid", placeItems: "center", width: 38, height: 38, borderRadius: "50%", ...o }, children: r });
376
385
  }
377
- function Ht({ variant: t = "ghost", style: i, ...r }) {
386
+ function Et({ variant: t = "ghost", style: i, ...r }) {
378
387
  return /* @__PURE__ */ e("button", { ...r, style: { display: "inline-flex", alignItems: "center", justifyContent: "center", border: t === "outline" ? "1px solid #e7ebf2" : 0, borderRadius: 8, cursor: "pointer", font: "inherit", background: t === "default" ? "#2563eb" : "transparent", ...i } });
379
388
  }
380
- function Et({ style: t, ...i }) {
389
+ function jt({ style: t, ...i }) {
381
390
  return /* @__PURE__ */ e("input", { ...i, style: { width: "100%", minWidth: 0, border: 0, outline: 0, background: "transparent", font: "inherit", ...t } });
382
391
  }
383
- const ct = Le(
392
+ const ht = Le(
384
393
  ({ children: t, style: i }, r) => /* @__PURE__ */ e("div", { ref: r, style: { minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", ...i }, children: t })
385
- ), jt = Le(
394
+ ), At = Le(
386
395
  function({ style: i, ...r }, o) {
387
396
  return /* @__PURE__ */ e("textarea", { ref: o, ...r, style: { display: "block", width: "100%", minWidth: 0, boxSizing: "border-box", resize: "vertical", border: 0, outline: 0, background: "transparent", font: "inherit", ...i } });
388
397
  }
389
398
  );
390
- function At(t) {
399
+ function Ot(t) {
391
400
  return {
392
401
  id: t.contactId ?? t.providerConversationKey,
393
402
  name: t.contactName,
@@ -399,7 +408,7 @@ function At(t) {
399
408
  function Ae(t, i) {
400
409
  return {
401
410
  conversation: t,
402
- contact: At(t),
411
+ contact: Ot(t),
403
412
  provider: i == null ? void 0 : i.provider,
404
413
  recentMessages: i == null ? void 0 : i.recentMessages,
405
414
  linkContact: (i == null ? void 0 : i.linkContact) ?? (async () => {
@@ -410,7 +419,7 @@ function Ae(t, i) {
410
419
  })
411
420
  };
412
421
  }
413
- class Ot extends mt {
422
+ class Dt extends xt {
414
423
  constructor() {
415
424
  super(...arguments), this.state = { caught: !1 };
416
425
  }
@@ -421,14 +430,14 @@ class Ot extends mt {
421
430
  return this.state.caught ? null : this.props.children;
422
431
  }
423
432
  }
424
- const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, Je = [
433
+ const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, Ze = [
425
434
  { icon: "😊", emojis: ["😀", "😁", "😂", "🤣", "😊", "😇", "🙂", "😉", "😍", "🥰", "😘", "😋", "😎", "🤩", "😏", "😒", "😔", "😢", "😭", "😤", "😠", "🤯", "😱", "🥳", "😴", "🤔", "🤗", "🫡", "😮", "🤧", "🥺", "😶", "🫠", "🤭", "🤫"] },
426
435
  { icon: "👋", emojis: ["👍", "👎", "👏", "🙏", "🤝", "✌️", "🤞", "🫡", "💪", "🤜", "👊", "✊", "🖐", "👌", "🤌", "🤏", "☝️", "👆", "👇", "👉", "👈", "🤙", "💅", "🫶", "❤️", "🧡", "💛", "💚", "💙", "💜", "🖤", "💔", "❣️", "💕", "💯"] },
427
436
  { icon: "🐱", emojis: ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🙈", "🐔", "🐧", "🐦", "🦆", "🦅", "🦉", "🦋", "🐝", "🐛", "🐢", "🦎", "🐬", "🦈", "🐳", "🐙", "🦑"] },
428
437
  { icon: "🍕", emojis: ["🍎", "🍊", "🍋", "🍇", "🍓", "🍒", "🥝", "🥑", "🍔", "🍕", "🌮", "🍜", "🍣", "🍦", "🎂", "🍰", "🧁", "☕", "🧋", "🥤", "🍺", "🥂", "🍾", "🧃", "🧊"] },
429
438
  { icon: "⚽", emojis: ["⚽", "🏀", "🏈", "⚾", "🎾", "🏐", "🏓", "🎮", "🎲", "🎯", "🎳", "🏆", "🥇", "🎖", "🎁", "🎉", "🎊", "🎈", "🎭", "🎨", "🎬", "🎵", "🎸", "🎹", "🎺", "🪗", "🎻"] },
430
439
  { icon: "🌍", emojis: ["🌍", "🌈", "⭐", "🌙", "☀️", "⛅", "🌊", "🔥", "💧", "🌿", "🌸", "🌺", "🌻", "🍀", "🌴", "🏔", "🏖", "🏕", "🌃", "🏙", "🌅", "🌄", "🌠", "🌌", "🌋", "🏝"] }
431
- ], qe = nt(""), st = nt("");
440
+ ], Ve = rt(""), pt = rt("");
432
441
  function Ut() {
433
442
  try {
434
443
  const t = new AudioContext(), i = t.createOscillator(), r = t.createGain();
@@ -436,18 +445,18 @@ function Ut() {
436
445
  } catch {
437
446
  }
438
447
  }
439
- function Dt(t) {
448
+ function Pt(t) {
440
449
  if (!(t != null && t.metadata)) return;
441
450
  const i = t.metadata, r = i.pageName ?? i.displayName ?? i.username ?? i.name;
442
451
  return typeof r == "string" && r ? r : void 0;
443
452
  }
444
- function ht(t) {
453
+ function ut(t) {
445
454
  return t === "facebook" ? "Facebook Messenger" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo OA" : t === "livechat" ? "Live Chat" : "Channel";
446
455
  }
447
- function Ye(t) {
456
+ function _e(t) {
448
457
  return t === "facebook" ? "Facebook" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo" : t === "livechat" ? "Live Chat" : String(t ?? "");
449
458
  }
450
- const Pt = (t) => {
459
+ const Nt = (t) => {
451
460
  var r;
452
461
  const i = {
453
462
  "application/pdf": "PDF",
@@ -458,85 +467,85 @@ const Pt = (t) => {
458
467
  };
459
468
  return t ? i[t] ?? ((r = t.split("/")[1]) == null ? void 0 : r.toUpperCase()) ?? "Tệp" : "Tệp đính kèm";
460
469
  };
461
- function _e({ status: t }) {
462
- return t === "read" ? /* @__PURE__ */ e(Ge, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(Ge, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(ot, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
470
+ function Qe({ status: t }) {
471
+ return t === "read" ? /* @__PURE__ */ e(Xe, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(Xe, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(lt, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
463
472
  }
464
- const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: C, disableAttachments: m, disableNotificationSound: O, hideKeyboardHint: f, locale: S = "vi", extensions: W, onNewMessage: I, onConversationSelect: H }, R) {
465
- var l, g, b, M, Z;
466
- const E = ee(new Mt(i, r)), [j, A] = y([]), [F, K] = y([]), [ne, U] = y(), [w, _] = y(), k = ee(void 0), [L, se] = y(""), [z, D] = y({ provider: "all", unreadOnly: !1 }), [le, v] = y(!1), Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!0), [B, P] = y(""), [q, ie] = y(() => !!(W != null && W.length)), [re, V] = y(280), [ye, ke] = y(!1), [be, fe] = y(0), G = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", de = Ee(() => new Map(F.map((c) => [c.id, c])), [F]), me = ee(null), [we, Oe] = y(0), Se = We(async (c, u) => {
467
- c.contactId && await E.current.patchContact(c.contactId, u), A((T) => T.map(($) => $.id === c.id ? { ...$, contactExternalId: u ?? void 0 } : $)), _((T) => T && T.id === c.id ? { ...T, contactExternalId: u ?? void 0 } : T), fe((T) => T + 1);
468
- }, []), Ce = We(() => {
473
+ const yn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: k, disableAttachments: g, disableNotificationSound: $, hideKeyboardHint: f, locale: x = "vi", extensions: R, onNewMessage: I, onConversationSelect: E }, W) {
474
+ var l, m, v, A, Q;
475
+ const O = Z(new st(i, r)), [D, L] = y([]), [P, K] = y([]), [ee, U] = y(), [S, z] = y(), b = Z(void 0), [T, ie] = y(""), [B, N] = y({ provider: "all", unreadOnly: !1 }), [de, C] = y(!1), te = Z(null), q = Z(null), [w, _] = y(null), [he, h] = y(!0), [H, F] = y(""), [X, re] = y(() => !!(R != null && R.length)), [oe, Y] = y(280), [ye, we] = y(!1), [me, fe] = y(0), J = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", ce = Ee(() => new Map(P.map((c) => [c.id, c])), [P]), be = Z(null), [Se, Oe] = y(0), Ce = ke(async (c, u) => {
476
+ c.contactId && await O.current.patchContact(c.contactId, u), L((M) => M.map((j) => j.id === c.id ? { ...j, contactExternalId: u ?? void 0 } : j)), z((M) => M && M.id === c.id ? { ...M, contactExternalId: u ?? void 0 } : M), fe((M) => M + 1);
477
+ }, []), Ie = ke(() => {
469
478
  fe((c) => c + 1);
470
- }, []), Ie = Ee(() => {
471
- const c = new Set(F.map((u) => u.provider));
479
+ }, []), ze = Ee(() => {
480
+ const c = new Set(P.map((u) => u.provider));
472
481
  return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) => c.has(u));
473
- }, [F]), ue = Ee(() => {
482
+ }, [P]), ue = Ee(() => {
474
483
  var u;
475
484
  const c = {};
476
- for (const T of j) {
477
- const $ = ((u = de.get(T.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
478
- c[$] = (c[$] ?? 0) + 1;
485
+ for (const M of D) {
486
+ const j = ((u = ce.get(M.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
487
+ c[j] = (c[j] ?? 0) + 1;
479
488
  }
480
489
  return c;
481
- }, [j, de]);
490
+ }, [D, ce]);
482
491
  function Me(c) {
483
- const u = c.clientX, T = re;
484
- ke(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
485
- function $(xe) {
486
- const Re = Math.max(200, Math.min(480, T + (u - xe.clientX)));
487
- V(Re);
492
+ const u = c.clientX, M = oe;
493
+ we(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
494
+ function j(xe) {
495
+ const We = Math.max(200, Math.min(480, M + (u - xe.clientX)));
496
+ Y(We);
488
497
  }
489
- function ce() {
490
- ke(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", $), document.removeEventListener("mouseup", ce);
498
+ function se() {
499
+ we(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", j), document.removeEventListener("mouseup", se);
491
500
  }
492
- document.addEventListener("mousemove", $), document.addEventListener("mouseup", ce);
501
+ document.addEventListener("mousemove", j), document.addEventListener("mouseup", se);
493
502
  }
494
- const oe = We(async (c) => {
503
+ const ae = ke(async (c) => {
495
504
  try {
496
- const u = await E.current.listConversations(c);
497
- A((T) => c ? [...T, ...u.items] : u.items), U(u.nextCursor), !c && u.items.length && _((T) => T ?? (C ? u.items.find(($) => $.id === C) ?? u.items[0] : u.items[0])), P("");
505
+ const u = await O.current.listConversations(c);
506
+ L((M) => c ? [...M, ...u.items] : u.items), U(u.nextCursor), !c && u.items.length && z((M) => M ?? (k ? u.items.find((j) => j.id === k) ?? u.items[0] : u.items[0])), F("");
498
507
  } catch (u) {
499
- P(u instanceof Error ? u.message : "Không tải được hội thoại");
508
+ F(u instanceof Error ? u.message : "Không tải được hội thoại");
500
509
  } finally {
501
510
  h(!1);
502
511
  }
503
- }, [C]);
504
- Y(() => (E.current.listConnections().then(K).catch(() => {
505
- }), oe(), E.current.connectSSE((u, T) => {
512
+ }, [k]);
513
+ V(() => (O.current.listConnections().then(K).catch(() => {
514
+ }), ae(), O.current.connectSSE((u, M) => {
506
515
  if (u === "message.new" || u === "conversation.updated") {
507
- if (oe(), u === "message.new") {
508
- const $ = typeof T == "object" && T ? T : {}, ce = $.conversationId ? String($.conversationId) : "", xe = $.messageId ? String($.messageId) : "";
509
- if (($.direction ? String($.direction) : "") === "inbound" && !O && Ut(), ce && ce === k.current && xe && me.current) {
510
- const ft = me.current;
511
- E.current.getMessage(xe).then((gt) => {
512
- ft(gt);
516
+ if (ae(), u === "message.new") {
517
+ const j = typeof M == "object" && M ? M : {}, se = j.conversationId ? String(j.conversationId) : "", xe = j.messageId ? String(j.messageId) : "";
518
+ if ((j.direction ? String(j.direction) : "") === "inbound" && !$ && Ut(), se && se === b.current && xe && be.current) {
519
+ const yt = be.current;
520
+ O.current.getMessage(xe).then((bt) => {
521
+ yt(bt);
513
522
  }).catch(() => {
514
523
  });
515
524
  }
516
- I == null || I(ce || k.current || "");
525
+ I == null || I(se || b.current || "");
517
526
  }
518
- } else u === "message.status_updated" && Oe(($) => $ + 1);
519
- })), [oe, I]), Y(() => {
520
- k.current = w == null ? void 0 : w.id;
521
- }, [w]), Y(() => {
522
- w != null && w.unreadCount && E.current.markRead(w.id).then(() => oe()).catch(() => {
527
+ } else u === "message.status_updated" && Oe((j) => j + 1);
528
+ })), [ae, I]), V(() => {
529
+ b.current = S == null ? void 0 : S.id;
530
+ }, [S]), V(() => {
531
+ S != null && S.unreadCount && O.current.markRead(S.id).then(() => ae()).catch(() => {
523
532
  });
524
- }, [w == null ? void 0 : w.id]), Y(() => {
525
- if (!le) return;
533
+ }, [S == null ? void 0 : S.id]), V(() => {
534
+ if (!de) return;
526
535
  function c(u) {
527
- var T, $;
528
- (T = Q.current) != null && T.contains(u.target) || ($ = N.current) != null && $.contains(u.target) || v(!1);
536
+ var M, j;
537
+ (M = te.current) != null && M.contains(u.target) || (j = q.current) != null && j.contains(u.target) || C(!1);
529
538
  }
530
539
  return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
531
- }, [le]);
532
- const ze = Ee(() => {
533
- const c = L.toLowerCase().trim();
534
- return j.filter((u) => {
535
- var Re;
536
- const T = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), $ = ((Re = de.get(u.connectionId)) == null ? void 0 : Re.provider) ?? "unknown", ce = z.provider === "all" || $ === z.provider, xe = !z.unreadOnly || (u.unreadCount ?? 0) > 0;
537
- return ce && xe && (!c || T.includes(c));
540
+ }, [de]);
541
+ const Te = Ee(() => {
542
+ const c = T.toLowerCase().trim();
543
+ return D.filter((u) => {
544
+ var We;
545
+ const M = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), j = ((We = ce.get(u.connectionId)) == null ? void 0 : We.provider) ?? "unknown", se = B.provider === "all" || j === B.provider, xe = !B.unreadOnly || (u.unreadCount ?? 0) > 0;
546
+ return se && xe && (!c || M.includes(c));
538
547
  });
539
- }, [j, de, z, L]), Te = z.provider !== "all" || z.unreadOnly, ae = S === "en" ? {
548
+ }, [D, ce, B, T]), Re = B.provider !== "all" || B.unreadOnly, le = x === "en" ? {
540
549
  today: "TODAY",
541
550
  loadOlder: "↑ Load older messages",
542
551
  loading: "Loading messages…",
@@ -557,33 +566,33 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
557
566
  send: "Gửi",
558
567
  all: "Tất cả"
559
568
  };
560
- yt(R, () => ({
569
+ mt(W, () => ({
561
570
  openConversation: (c) => {
562
- const u = j.find((T) => T.id === c);
563
- u && _(u);
571
+ const u = D.find((M) => M.id === c);
572
+ u && z(u);
564
573
  },
565
- refresh: () => void oe()
566
- }), [j, oe]);
574
+ refresh: () => void ae()
575
+ }), [D, ae]);
567
576
  const He = {
568
577
  ...p.frame,
569
578
  height: s ?? 620,
570
579
  ...s ? { maxHeight: "none" } : {},
571
580
  fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif",
572
581
  borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px",
573
- gridTemplateColumns: q ? `minmax(260px, 300px) minmax(0, 1fr) ${re}px` : "minmax(260px, 300px) minmax(0, 1fr)",
582
+ gridTemplateColumns: X ? `minmax(260px, 300px) minmax(0, 1fr) ${oe}px` : "minmax(260px, 300px) minmax(0, 1fr)",
574
583
  transition: ye ? "none" : "grid-template-columns 220ms ease"
575
584
  };
576
585
  return he ? /* @__PURE__ */ n("div", { style: { ...p.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
577
586
  /* @__PURE__ */ e(Fe, {}),
578
587
  " Đang tải hộp thư…"
579
- ] }) : B && !j.length ? /* @__PURE__ */ n("div", { style: { ...p.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
580
- /* @__PURE__ */ e(St, { size: 16, strokeWidth: 2 }),
588
+ ] }) : H && !D.length ? /* @__PURE__ */ n("div", { style: { ...p.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
589
+ /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }),
581
590
  " ",
582
- B,
591
+ H,
583
592
  /* @__PURE__ */ e("button", { style: p.retry, onClick: () => {
584
- h(!0), oe();
593
+ h(!0), ae();
585
594
  }, children: "Thử lại" })
586
- ] }) : /* @__PURE__ */ e(qe.Provider, { value: i, children: /* @__PURE__ */ e(st.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
595
+ ] }) : /* @__PURE__ */ e(Ve.Provider, { value: i, children: /* @__PURE__ */ e(pt.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
587
596
  const c = window.scrollY;
588
597
  requestAnimationFrame(() => {
589
598
  window.scrollY !== c && window.scrollTo({ top: c, behavior: "instant" });
@@ -591,71 +600,71 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
591
600
  }, children: [
592
601
  /* @__PURE__ */ n("aside", { style: p.sidebar, children: [
593
602
  /* @__PURE__ */ n("div", { style: p.brand, children: [
594
- /* @__PURE__ */ e("div", { style: { ...p.brandMark, background: G, overflow: "hidden", padding: 0 }, children: (l = o == null ? void 0 : o.branding) != null && l.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((g = o == null ? void 0 : o.branding) == null ? void 0 : g.mark) ?? "C" }),
603
+ /* @__PURE__ */ e("div", { style: { ...p.brandMark, background: J, overflow: "hidden", padding: 0 }, children: (l = o == null ? void 0 : o.branding) != null && l.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((m = o == null ? void 0 : o.branding) == null ? void 0 : m.mark) ?? "C" }),
595
604
  /* @__PURE__ */ n("div", { children: [
596
- /* @__PURE__ */ e("strong", { children: ((b = o == null ? void 0 : o.branding) == null ? void 0 : b.name) ?? "Hộp thư" }),
597
- !((M = o == null ? void 0 : o.branding) != null && M.name) && /* @__PURE__ */ e("span", { style: p.eyebrow, children: "CHANNELHUB" })
605
+ /* @__PURE__ */ e("strong", { children: ((v = o == null ? void 0 : o.branding) == null ? void 0 : v.name) ?? "Hộp thư" }),
606
+ !((A = o == null ? void 0 : o.branding) != null && A.name) && /* @__PURE__ */ e("span", { style: p.eyebrow, children: "CHANNELHUB" })
598
607
  ] }),
599
- /* @__PURE__ */ e(Ht, { "aria-label": "Tùy chọn", style: p.iconButton, children: /* @__PURE__ */ e(at, { size: 16, strokeWidth: 2 }) })
608
+ /* @__PURE__ */ e(Et, { "aria-label": "Tùy chọn", style: p.iconButton, children: /* @__PURE__ */ e(dt, { size: 16, strokeWidth: 2 }) })
600
609
  ] }),
601
610
  /* @__PURE__ */ n("div", { style: p.search, children: [
602
- /* @__PURE__ */ e(Xe, { size: 16, strokeWidth: 2 }),
603
- /* @__PURE__ */ e(Et, { "aria-label": ae.searchPlaceholder, value: L, onChange: (c) => se(c.target.value), placeholder: ae.searchPlaceholder }),
604
- L && /* @__PURE__ */ e("button", { style: p.clear, onClick: () => se(""), "aria-label": "Xóa tìm kiếm", children: "×" })
611
+ /* @__PURE__ */ e(Je, { size: 16, strokeWidth: 2 }),
612
+ /* @__PURE__ */ e(jt, { "aria-label": le.searchPlaceholder, value: T, onChange: (c) => ie(c.target.value), placeholder: le.searchPlaceholder }),
613
+ T && /* @__PURE__ */ e("button", { style: p.clear, onClick: () => ie(""), "aria-label": "Xóa tìm kiếm", children: "×" })
605
614
  ] }),
606
- Te && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
607
- z.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
608
- /* @__PURE__ */ e($e, { provider: z.provider }),
609
- Ye(z.provider),
610
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(je, { size: 10 }) })
615
+ Re && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
616
+ B.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: J, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
617
+ /* @__PURE__ */ e($e, { provider: B.provider }),
618
+ _e(B.provider),
619
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: J, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => N((c) => ({ ...c, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(je, { size: 10 }) })
611
620
  ] }),
612
- z.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
613
- ae.unreadOnly,
614
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(je, { size: 10 }) })
621
+ B.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: J, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
622
+ le.unreadOnly,
623
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: J, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => N((c) => ({ ...c, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(je, { size: 10 }) })
615
624
  ] }),
616
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: d.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => D({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
625
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: d.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => N({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
617
626
  ] }),
618
627
  /* @__PURE__ */ n("div", { style: p.listHeader, children: [
619
628
  /* @__PURE__ */ n("span", { children: [
620
- ze.length,
629
+ Te.length,
621
630
  " hội thoại"
622
631
  ] }),
623
632
  /* @__PURE__ */ e(
624
633
  "button",
625
634
  {
626
- ref: Q,
627
- style: { ...p.iconButton, background: Te ? `${G}14` : "transparent", color: Te ? G : d.muted },
635
+ ref: te,
636
+ style: { ...p.iconButton, background: Re ? `${J}14` : "transparent", color: Re ? J : d.muted },
628
637
  "aria-label": "Bộ lọc",
629
638
  onClick: () => {
630
639
  var c;
631
- if (!le) {
632
- const u = (c = Q.current) == null ? void 0 : c.getBoundingClientRect();
633
- u && J({ top: u.bottom + 6, left: u.left });
640
+ if (!de) {
641
+ const u = (c = te.current) == null ? void 0 : c.getBoundingClientRect();
642
+ u && _({ top: u.bottom + 6, left: u.left });
634
643
  }
635
- v((u) => !u);
644
+ C((u) => !u);
636
645
  },
637
- children: /* @__PURE__ */ e(Wt, { size: 15, strokeWidth: 2 })
646
+ children: /* @__PURE__ */ e(Lt, { size: 15, strokeWidth: 2 })
638
647
  }
639
648
  )
640
649
  ] }),
641
- le && x && it(
650
+ de && w && ot(
642
651
  /* @__PURE__ */ n(
643
652
  "div",
644
653
  {
645
- ref: N,
646
- style: { position: "fixed", top: x.top, left: x.left, zIndex: 9999, background: d.white, border: `1px solid ${d.line}`, borderRadius: 10, padding: "12px 14px", boxShadow: "0 8px 24px rgba(23,32,51,.14)", minWidth: 210, fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif", fontSize: 13 },
654
+ ref: q,
655
+ style: { position: "fixed", top: w.top, left: w.left, zIndex: 9999, background: d.white, border: `1px solid ${d.line}`, borderRadius: 10, padding: "12px 14px", boxShadow: "0 8px 24px rgba(23,32,51,.14)", minWidth: 210, fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif", fontSize: 13 },
647
656
  children: [
648
657
  /* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
649
- ["all", ...Ie].map((c) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.provider === c ? `${G}0f` : "transparent" }, children: [
650
- /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider === c, onChange: () => D((u) => ({ ...u, provider: c })), style: { accentColor: G } }),
658
+ ["all", ...ze].map((c) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: B.provider === c ? `${J}0f` : "transparent" }, children: [
659
+ /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: B.provider === c, onChange: () => N((u) => ({ ...u, provider: c })), style: { accentColor: J } }),
651
660
  c === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
652
- ae.all,
661
+ le.all,
653
662
  " (",
654
- j.length,
663
+ D.length,
655
664
  ")"
656
665
  ] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: d.ink }, children: [
657
666
  /* @__PURE__ */ e($e, { provider: c }),
658
- Ye(c),
667
+ _e(c),
659
668
  " ",
660
669
  /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
661
670
  "(",
@@ -665,207 +674,207 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
665
674
  ] })
666
675
  ] }, c)),
667
676
  /* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${d.line}`, margin: "8px 0 6px" } }),
668
- /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.unreadOnly ? `${G}0f` : "transparent" }, children: [
669
- /* @__PURE__ */ e("input", { type: "checkbox", checked: z.unreadOnly, onChange: (c) => D((u) => ({ ...u, unreadOnly: c.target.checked })), style: { accentColor: G } }),
670
- /* @__PURE__ */ e("span", { style: { color: d.ink }, children: ae.unreadOnly })
677
+ /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: B.unreadOnly ? `${J}0f` : "transparent" }, children: [
678
+ /* @__PURE__ */ e("input", { type: "checkbox", checked: B.unreadOnly, onChange: (c) => N((u) => ({ ...u, unreadOnly: c.target.checked })), style: { accentColor: J } }),
679
+ /* @__PURE__ */ e("span", { style: { color: d.ink }, children: le.unreadOnly })
671
680
  ] })
672
681
  ]
673
682
  }
674
683
  ),
675
684
  document.body
676
685
  ),
677
- /* @__PURE__ */ n(ct, { style: p.conversationList, children: [
678
- ze.map((c) => {
686
+ /* @__PURE__ */ n(ht, { style: p.conversationList, children: [
687
+ Te.map((c) => {
679
688
  var u;
680
- return /* @__PURE__ */ e(Nt, { conversation: c, provider: (u = de.get(c.connectionId)) == null ? void 0 : u.provider, selected: (w == null ? void 0 : w.id) === c.id, primary: G, onSelect: () => {
681
- _(c), H == null || H(c.id), E.current.markRead(c.id).then(() => oe()).catch(() => {
689
+ return /* @__PURE__ */ e(Ft, { conversation: c, provider: (u = ce.get(c.connectionId)) == null ? void 0 : u.provider, selected: (S == null ? void 0 : S.id) === c.id, primary: J, onSelect: () => {
690
+ z(c), E == null || E(c.id), O.current.markRead(c.id).then(() => ae()).catch(() => {
682
691
  });
683
692
  } }, c.id);
684
693
  }),
685
- !ze.length && /* @__PURE__ */ n("div", { style: p.emptySmall, children: [
686
- /* @__PURE__ */ e("div", { style: p.emptyIcon, children: /* @__PURE__ */ e(Xe, { size: 16, strokeWidth: 2 }) }),
694
+ !Te.length && /* @__PURE__ */ n("div", { style: p.emptySmall, children: [
695
+ /* @__PURE__ */ e("div", { style: p.emptyIcon, children: /* @__PURE__ */ e(Je, { size: 16, strokeWidth: 2 }) }),
687
696
  /* @__PURE__ */ e("strong", { children: "Không tìm thấy" }),
688
697
  /* @__PURE__ */ e("span", { children: "Thử từ khóa hoặc bộ lọc khác." })
689
698
  ] }),
690
- ne && /* @__PURE__ */ e("button", { style: p.loadMore, onClick: () => void oe(ne), children: "Xem thêm hội thoại" })
699
+ ee && /* @__PURE__ */ e("button", { style: p.loadMore, onClick: () => void ae(ee), children: "Xem thêm hội thoại" })
691
700
  ] })
692
701
  ] }),
693
- /* @__PURE__ */ e("main", { style: p.main, children: w ? /* @__PURE__ */ e(
694
- Ft,
702
+ /* @__PURE__ */ e("main", { style: p.main, children: S ? /* @__PURE__ */ e(
703
+ Kt,
695
704
  {
696
- conversation: w,
697
- provider: (Z = de.get(w.connectionId)) == null ? void 0 : Z.provider,
698
- connection: de.get(w.connectionId),
699
- client: E.current,
700
- primary: G,
701
- error: B,
705
+ conversation: S,
706
+ provider: (Q = ce.get(S.connectionId)) == null ? void 0 : Q.provider,
707
+ connection: ce.get(S.connectionId),
708
+ client: O.current,
709
+ primary: J,
710
+ error: H,
702
711
  onRegisterAppend: (c) => {
703
- me.current = c;
712
+ be.current = c;
704
713
  },
705
- refreshKey: we,
706
- infoOpen: q,
707
- onToggleInfo: () => ie((c) => !c),
708
- t: ae,
709
- disableAttachments: m,
714
+ refreshKey: Se,
715
+ infoOpen: X,
716
+ onToggleInfo: () => re((c) => !c),
717
+ t: le,
718
+ disableAttachments: g,
710
719
  hideKeyboardHint: f,
711
- extensions: W,
712
- onLinkContact: (c) => Se(w, c),
713
- onRefreshContactInfo: Ce
720
+ extensions: R,
721
+ onLinkContact: (c) => Ce(S, c),
722
+ onRefreshContactInfo: Ie
714
723
  },
715
- w.id
716
- ) : /* @__PURE__ */ e(Gt, {}) }),
717
- q && w && /* @__PURE__ */ e(
718
- qt,
724
+ S.id
725
+ ) : /* @__PURE__ */ e(Xt, {}) }),
726
+ X && S && /* @__PURE__ */ e(
727
+ Vt,
719
728
  {
720
- conversation: w,
721
- connection: de.get(w.connectionId),
722
- primary: G,
723
- onClose: () => ie(!1),
724
- client: E.current,
729
+ conversation: S,
730
+ connection: ce.get(S.connectionId),
731
+ primary: J,
732
+ onClose: () => re(!1),
733
+ client: O.current,
725
734
  onStartResize: Me,
726
- extensions: W,
727
- extRefreshKey: be,
728
- onLinkContact: (c) => Se(w, c),
729
- onRefreshContactInfo: Ce
735
+ extensions: R,
736
+ extRefreshKey: me,
737
+ onLinkContact: (c) => Ce(S, c),
738
+ onRefreshContactInfo: Ie
730
739
  }
731
740
  )
732
741
  ] }) }) });
733
742
  });
734
- function Nt({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
735
- const [C, m] = y(!1), O = t.contactName ?? t.subject ?? t.providerConversationKey, f = t.unreadCount ?? 0, S = t.lastMessageText ?? "", W = t.lastMessageDirection === "outbound" ? "Bạn: " : "", I = S.length > 60 ? S.slice(0, 60) + "…" : S, H = S ? W + I : "";
736
- let R = "transparent";
737
- r ? R = "#eef2ff" : C ? R = "#f7f9fc" : f > 0 && (R = "#f0f4ff");
738
- const E = {
743
+ function Ft({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
744
+ const [k, g] = y(!1), $ = t.contactName ?? t.subject ?? t.providerConversationKey, f = t.unreadCount ?? 0, x = t.lastMessageText ?? "", R = t.lastMessageDirection === "outbound" ? "Bạn: " : "", I = x.length > 60 ? x.slice(0, 60) + "…" : x, E = x ? R + I : "";
745
+ let W = "transparent";
746
+ r ? W = "#eef2ff" : k ? W = "#f7f9fc" : f > 0 && (W = "#f0f4ff");
747
+ const O = {
739
748
  ...p.row,
740
- background: R,
741
- ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : f > 0 && !C ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
749
+ background: W,
750
+ ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : f > 0 && !k ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
742
751
  };
743
752
  return /* @__PURE__ */ n(
744
753
  "button",
745
754
  {
746
755
  onClick: s,
747
- style: E,
748
- onMouseEnter: () => m(!0),
749
- onMouseLeave: () => m(!1),
756
+ style: O,
757
+ onMouseEnter: () => g(!0),
758
+ onMouseLeave: () => g(!1),
750
759
  children: [
751
- /* @__PURE__ */ e(pt, { name: O, color: o, image: t.contactPictureUrl, provider: i }),
760
+ /* @__PURE__ */ e(ft, { name: $, color: o, image: t.contactPictureUrl, provider: i }),
752
761
  /* @__PURE__ */ n("span", { style: p.rowBody, children: [
753
762
  /* @__PURE__ */ n("span", { style: p.rowTop, children: [
754
- /* @__PURE__ */ e("strong", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: f > 0 ? 700 : 500 }, children: O }),
763
+ /* @__PURE__ */ e("strong", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: f > 0 ? 700 : 500 }, children: $ }),
755
764
  /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, flexShrink: 0 }, children: [
756
765
  /* @__PURE__ */ e("time", { style: { color: d.muted, fontSize: 11, whiteSpace: "nowrap" }, children: Ke(t.lastMessageAt) }),
757
766
  f > 0 && /* @__PURE__ */ e("span", { "aria-label": `${f} tin nhắn chưa đọc`, style: p.unreadBadge, children: f > 99 ? "99+" : f })
758
767
  ] })
759
768
  ] }),
760
- /* @__PURE__ */ e("span", { style: { ...p.rowBottom, color: f > 0 && !r ? "#4a5568" : d.muted }, children: /* @__PURE__ */ e("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", maxWidth: "100%" }, children: H || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" }) }) })
769
+ /* @__PURE__ */ e("span", { style: { ...p.rowBottom, color: f > 0 && !r ? "#4a5568" : d.muted }, children: /* @__PURE__ */ e("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", maxWidth: "100%" }, children: E || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" }) }) })
761
770
  ] })
762
771
  ]
763
772
  }
764
773
  );
765
774
  }
766
- function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s, error: C, onRegisterAppend: m, refreshKey: O, infoOpen: f, onToggleInfo: S, t: W, disableAttachments: I, hideKeyboardHint: H, extensions: R, onLinkContact: E, onRefreshContactInfo: j }) {
775
+ function Kt({ conversation: t, provider: i, connection: r, client: o, primary: s, error: k, onRegisterAppend: g, refreshKey: $, infoOpen: f, onToggleInfo: x, t: R, disableAttachments: I, hideKeyboardHint: E, extensions: W, onLinkContact: O, onRefreshContactInfo: D }) {
767
776
  var He;
768
- const [A, F] = y([]), [K, ne] = y(), [U, w] = y(""), [_, k] = y(!0), [L, se] = y(!1), [z, D] = y(""), le = ee(null), v = t.contactName ?? t.subject ?? t.providerConversationKey, Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!1), [B, P] = y(!1), [q, ie] = y(!1), [re, V] = y(0), ye = ee(null), ke = ee(null), be = ee(null), [fe, G] = y(!1), [de, me] = y(""), [we, Oe] = y([]), Se = ee(null), Ce = ee(null);
769
- Y(() => () => {
770
- x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl);
771
- }, [x == null ? void 0 : x.objectUrl]), Y(() => {
772
- if (!q) return;
773
- function l(g) {
774
- var b, M;
775
- (b = ke.current) != null && b.contains(g.target) || (M = ye.current) != null && M.contains(g.target) || ie(!1);
777
+ const [L, P] = y([]), [K, ee] = y(), [U, S] = y(""), [z, b] = y(!0), [T, ie] = y(!1), [B, N] = y(""), de = Z(null), C = t.contactName ?? t.subject ?? t.providerConversationKey, te = Z(null), q = Z(null), [w, _] = y(null), [he, h] = y(!1), [H, F] = y(!1), [X, re] = y(!1), [oe, Y] = y(0), ye = Z(null), we = Z(null), me = Z(null), [fe, J] = y(!1), [ce, be] = y(""), [Se, Oe] = y([]), Ce = Z(null), Ie = Z(null);
778
+ V(() => () => {
779
+ w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl);
780
+ }, [w == null ? void 0 : w.objectUrl]), V(() => {
781
+ if (!X) return;
782
+ function l(m) {
783
+ var v, A;
784
+ (v = we.current) != null && v.contains(m.target) || (A = ye.current) != null && A.contains(m.target) || re(!1);
776
785
  }
777
786
  return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
778
- }, [q]), Y(() => {
787
+ }, [X]), V(() => {
779
788
  o.listCannedResponses().then(Oe).catch(() => {
780
789
  });
781
- }, [o]), Y(() => {
790
+ }, [o]), V(() => {
782
791
  if (!fe) return;
783
- function l(g) {
784
- var b, M;
785
- (b = Ce.current) != null && b.contains(g.target) || (M = Se.current) != null && M.contains(g.target) || G(!1);
792
+ function l(m) {
793
+ var v, A;
794
+ (v = Ie.current) != null && v.contains(m.target) || (A = Ce.current) != null && A.contains(m.target) || J(!1);
786
795
  }
787
796
  return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
788
797
  }, [fe]);
789
- const Ie = ee(!0), ue = We(async (l, g) => {
790
- g || (Ie.current = !l);
798
+ const ze = Z(!0), ue = ke(async (l, m) => {
799
+ m || (ze.current = !l);
791
800
  try {
792
- const b = await o.listMessages(t.id, l);
793
- F((M) => l ? [...b.items, ...M] : b.items), ne(b.nextCursor);
794
- } catch (b) {
795
- D(b instanceof Error ? b.message : "Không tải được tin nhắn");
801
+ const v = await o.listMessages(t.id, l);
802
+ P((A) => l ? [...v.items, ...A] : v.items), ee(v.nextCursor);
803
+ } catch (v) {
804
+ N(v instanceof Error ? v.message : "Không tải được tin nhắn");
796
805
  } finally {
797
- g || k(!1);
806
+ m || b(!1);
798
807
  }
799
808
  }, [o, t.id]);
800
- Y(() => {
801
- k(!0), ue();
802
- }, [ue]), Y(() => {
803
- O && ue(void 0, !0);
804
- }, [O]), Y(() => {
805
- Ie.current && requestAnimationFrame(() => {
806
- const l = le.current;
809
+ V(() => {
810
+ b(!0), ue();
811
+ }, [ue]), V(() => {
812
+ $ && ue(void 0, !0);
813
+ }, [$]), V(() => {
814
+ ze.current && requestAnimationFrame(() => {
815
+ const l = de.current;
807
816
  l && (l.scrollTop = l.scrollHeight);
808
817
  });
809
- }, [A]), Y(() => (m == null || m((l) => {
810
- Ie.current = !0, F((g) => g.some((b) => b.id === l.id) ? g : [...g, l]);
818
+ }, [L]), V(() => (g == null || g((l) => {
819
+ ze.current = !0, P((m) => m.some((v) => v.id === l.id) ? m : [...m, l]);
811
820
  }), () => {
812
- m == null || m(null);
813
- }), [m]);
821
+ g == null || g(null);
822
+ }), [g]);
814
823
  async function Me(l) {
815
- var M;
816
- const g = (M = l.target.files) == null ? void 0 : M[0];
817
- if (!g) return;
824
+ var A;
825
+ const m = (A = l.target.files) == null ? void 0 : A[0];
826
+ if (!m) return;
818
827
  l.target.value = "";
819
- const b = URL.createObjectURL(g);
820
- J({ file: g, uploading: !0, objectUrl: b });
828
+ const v = URL.createObjectURL(m);
829
+ _({ file: m, uploading: !0, objectUrl: v });
821
830
  try {
822
- const Z = await o.uploadAttachment(g);
823
- J({ file: g, uploading: !1, url: Z.url, mimeType: Z.mimeType, attachmentType: Z.attachmentType, objectUrl: b });
831
+ const Q = await o.uploadAttachment(m);
832
+ _({ file: m, uploading: !1, url: Q.url, mimeType: Q.mimeType, attachmentType: Q.attachmentType, objectUrl: v });
824
833
  } catch {
825
- URL.revokeObjectURL(b), J(null), D("Không tải lên được tệp đính kèm");
834
+ URL.revokeObjectURL(v), _(null), N("Không tải lên được tệp đính kèm");
826
835
  }
827
836
  }
828
- async function oe(l) {
837
+ async function ae(l) {
829
838
  l.preventDefault();
830
- const g = U.trim(), b = x != null && x.url ? [{ url: x.url, mimeType: x.mimeType ?? "application/octet-stream", type: x.attachmentType }] : [];
831
- if (!(!g && !b.length || L)) {
832
- se(!0), D("");
839
+ const m = U.trim(), v = w != null && w.url ? [{ url: w.url, mimeType: w.mimeType ?? "application/octet-stream", type: w.attachmentType }] : [];
840
+ if (!(!m && !v.length || T)) {
841
+ ie(!0), N("");
833
842
  try {
834
- await o.sendMessage(t.id, g || void 0, b.length ? b : void 0), x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), w(""), J(null), await ue();
835
- } catch (M) {
836
- D(M instanceof Error ? M.message : "Không gửi được tin nhắn");
843
+ await o.sendMessage(t.id, m || void 0, v.length ? v : void 0), w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl), S(""), _(null), await ue();
844
+ } catch (A) {
845
+ N(A instanceof Error ? A.message : "Không gửi được tin nhắn");
837
846
  } finally {
838
- se(!1);
847
+ ie(!1);
839
848
  }
840
849
  }
841
850
  }
842
- function ze(l) {
843
- const g = be.current;
844
- if (!g) {
845
- w((c) => c + l), ie(!1);
851
+ function Te(l) {
852
+ const m = me.current;
853
+ if (!m) {
854
+ S((c) => c + l), re(!1);
846
855
  return;
847
856
  }
848
- const b = g.selectionStart ?? U.length, M = g.selectionEnd ?? U.length, Z = U.slice(0, b) + l + U.slice(M);
849
- w(Z), ie(!1), requestAnimationFrame(() => {
850
- g.focus(), g.selectionStart = g.selectionEnd = b + l.length;
857
+ const v = m.selectionStart ?? U.length, A = m.selectionEnd ?? U.length, Q = U.slice(0, v) + l + U.slice(A);
858
+ S(Q), re(!1), requestAnimationFrame(() => {
859
+ m.focus(), m.selectionStart = m.selectionEnd = v + l.length;
851
860
  });
852
861
  }
853
- function Te(l) {
854
- w(l), G(!1), me(""), requestAnimationFrame(() => {
855
- const g = be.current;
856
- g && (g.focus(), g.selectionStart = g.selectionEnd = l.length);
862
+ function Re(l) {
863
+ S(l), J(!1), be(""), requestAnimationFrame(() => {
864
+ const m = me.current;
865
+ m && (m.focus(), m.selectionStart = m.selectionEnd = l.length);
857
866
  });
858
867
  }
859
- const ae = !L && (U.trim().length > 0 || (x == null ? void 0 : x.url) != null && !x.uploading);
868
+ const le = !T && (U.trim().length > 0 || (w == null ? void 0 : w.url) != null && !w.uploading);
860
869
  return /* @__PURE__ */ n("section", { style: p.chat, children: [
861
870
  /* @__PURE__ */ n("header", { style: p.chatHeader, children: [
862
- /* @__PURE__ */ e(pt, { name: v, color: s, image: t.contactPictureUrl, provider: i }),
871
+ /* @__PURE__ */ e(ft, { name: C, color: s, image: t.contactPictureUrl, provider: i }),
863
872
  /* @__PURE__ */ n("div", { style: p.contact, children: [
864
- /* @__PURE__ */ e("strong", { style: p.contactName, children: v }),
865
- /* @__PURE__ */ e("span", { style: p.contactMeta, children: Dt(r) ?? ht(i) })
873
+ /* @__PURE__ */ e("strong", { style: p.contactName, children: C }),
874
+ /* @__PURE__ */ e("span", { style: p.contactMeta, children: Pt(r) ?? ut(i) })
866
875
  ] }),
867
876
  /* @__PURE__ */ n("div", { style: p.headerActions, children: [
868
- /* @__PURE__ */ e("button", { style: p.iconButton, "aria-label": "Thêm tùy chọn", children: /* @__PURE__ */ e(at, { size: 16, strokeWidth: 2 }) }),
877
+ /* @__PURE__ */ e("button", { style: p.iconButton, "aria-label": "Thêm tùy chọn", children: /* @__PURE__ */ e(dt, { size: 16, strokeWidth: 2 }) }),
869
878
  /* @__PURE__ */ e(
870
879
  "button",
871
880
  {
@@ -875,37 +884,37 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
875
884
  color: f ? s : d.muted
876
885
  },
877
886
  "aria-label": "Thông tin liên hệ",
878
- onClick: S,
879
- children: /* @__PURE__ */ e(zt, { size: 16, strokeWidth: 2 })
887
+ onClick: x,
888
+ children: /* @__PURE__ */ e(Rt, { size: 16, strokeWidth: 2 })
880
889
  }
881
890
  )
882
891
  ] })
883
892
  ] }),
884
- /* @__PURE__ */ n(ct, { ref: le, style: p.messageArea, children: [
885
- /* @__PURE__ */ e("div", { style: p.day, children: W.today }),
886
- K && /* @__PURE__ */ e("button", { onClick: () => void ue(K), style: p.historyButton, children: W.loadOlder }),
887
- _ && /* @__PURE__ */ n("div", { style: p.messageHint, children: [
893
+ /* @__PURE__ */ n(ht, { ref: de, style: p.messageArea, children: [
894
+ /* @__PURE__ */ e("div", { style: p.day, children: R.today }),
895
+ K && /* @__PURE__ */ e("button", { onClick: () => void ue(K), style: p.historyButton, children: R.loadOlder }),
896
+ z && /* @__PURE__ */ n("div", { style: p.messageHint, children: [
888
897
  /* @__PURE__ */ e(Fe, {}),
889
898
  " ",
890
- W.loading
899
+ R.loading
891
900
  ] }),
892
- !_ && !A.length && /* @__PURE__ */ e("div", { style: p.messageHint, children: W.noMessages }),
893
- A.map((l, g) => {
894
- const b = (R == null ? void 0 : R.flatMap((u) => u.messageEnrichments ?? [])) ?? [], M = l.direction === "inbound" && b.length > 0 && g >= A.length - 15, Z = M ? Ae(t, {
901
+ !z && !L.length && /* @__PURE__ */ e("div", { style: p.messageHint, children: R.noMessages }),
902
+ L.map((l, m) => {
903
+ const v = (W == null ? void 0 : W.flatMap((u) => u.messageEnrichments ?? [])) ?? [], A = l.direction === "inbound" && v.length > 0 && m >= L.length - 15, Q = A ? Ae(t, {
895
904
  provider: i,
896
- recentMessages: A.slice(-10),
897
- linkContact: E,
898
- refreshContactInfo: j,
899
- sendMessage: async (u, T) => {
900
- await o.sendMessage(t.id, u, T), await ue(void 0, !0);
905
+ recentMessages: L.slice(-10),
906
+ linkContact: O,
907
+ refreshContactInfo: D,
908
+ sendMessage: async (u, M) => {
909
+ await o.sendMessage(t.id, u, M), await ue(void 0, !0);
901
910
  }
902
- }) : null, c = M && Z ? b.map((u, T) => {
903
- var ce;
904
- const $ = (ce = l.text) == null ? void 0 : ce.match(u.pattern);
905
- return $ ? /* @__PURE__ */ e(Ot, { children: u.render($, Z, l) }, `${l.id}-${T}`) : null;
911
+ }) : null, c = A && Q ? v.map((u, M) => {
912
+ var se;
913
+ const j = (se = l.text) == null ? void 0 : se.match(u.pattern);
914
+ return j ? /* @__PURE__ */ e(Dt, { children: u.render(j, Q, l) }, `${l.id}-${M}`) : null;
906
915
  }).filter(Boolean) : [];
907
916
  return /* @__PURE__ */ n("div", { children: [
908
- /* @__PURE__ */ e(Kt, { message: l, primary: s }),
917
+ /* @__PURE__ */ e(qt, { message: l, primary: s }),
909
918
  c.length > 0 && /* @__PURE__ */ e("div", { style: { maxWidth: "min(70%, 480px)", marginTop: -4, marginBottom: 10, display: "flex", flexDirection: "column", gap: 6 }, children: c })
910
919
  ] }, l.id);
911
920
  })
@@ -914,7 +923,7 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
914
923
  "button",
915
924
  {
916
925
  type: "button",
917
- onClick: () => w(l),
926
+ onClick: () => S(l),
918
927
  style: {
919
928
  fontSize: 11,
920
929
  padding: "3px 10px",
@@ -929,8 +938,8 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
929
938
  },
930
939
  l
931
940
  )) }),
932
- /* @__PURE__ */ n("form", { onSubmit: oe, style: { flex: "0 0 auto", padding: "8px 14px 12px", borderTop: `1px solid ${d.line}`, background: d.white, position: "relative" }, children: [
933
- q && /* @__PURE__ */ n(
941
+ /* @__PURE__ */ n("form", { onSubmit: ae, style: { flex: "0 0 auto", padding: "8px 14px 12px", borderTop: `1px solid ${d.line}`, background: d.white, position: "relative" }, children: [
942
+ X && /* @__PURE__ */ n(
934
943
  "div",
935
944
  {
936
945
  ref: ye,
@@ -948,11 +957,11 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
948
957
  fontFamily: "inherit"
949
958
  },
950
959
  children: [
951
- /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Je.map((l, g) => /* @__PURE__ */ e(
960
+ /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Ze.map((l, m) => /* @__PURE__ */ e(
952
961
  "button",
953
962
  {
954
963
  type: "button",
955
- onClick: () => V(g),
964
+ onClick: () => Y(m),
956
965
  style: {
957
966
  flex: 1,
958
967
  border: 0,
@@ -961,19 +970,19 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
961
970
  fontSize: 16,
962
971
  cursor: "pointer",
963
972
  lineHeight: 1,
964
- borderBottom: re === g ? `2px solid ${s}` : "2px solid transparent",
965
- opacity: re === g ? 1 : 0.5,
973
+ borderBottom: oe === m ? `2px solid ${s}` : "2px solid transparent",
974
+ opacity: oe === m ? 1 : 0.5,
966
975
  transition: "opacity 100ms ease"
967
976
  },
968
977
  children: l.icon
969
978
  },
970
- g
979
+ m
971
980
  )) }),
972
- /* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (He = Je[re]) == null ? void 0 : He.emojis.map((l, g) => /* @__PURE__ */ e(
981
+ /* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (He = Ze[oe]) == null ? void 0 : He.emojis.map((l, m) => /* @__PURE__ */ e(
973
982
  "button",
974
983
  {
975
984
  type: "button",
976
- onClick: () => ze(l),
985
+ onClick: () => Te(l),
977
986
  style: {
978
987
  border: 0,
979
988
  background: "transparent",
@@ -984,15 +993,15 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
984
993
  lineHeight: 1,
985
994
  transition: "background 80ms ease"
986
995
  },
987
- onMouseEnter: (b) => {
988
- b.target.style.background = "#f3f4f6";
996
+ onMouseEnter: (v) => {
997
+ v.target.style.background = "#f3f4f6";
989
998
  },
990
- onMouseLeave: (b) => {
991
- b.target.style.background = "transparent";
999
+ onMouseLeave: (v) => {
1000
+ v.target.style.background = "transparent";
992
1001
  },
993
1002
  children: l
994
1003
  },
995
- g
1004
+ m
996
1005
  )) })
997
1006
  ]
998
1007
  }
@@ -1000,7 +1009,7 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1000
1009
  fe && /* @__PURE__ */ n(
1001
1010
  "div",
1002
1011
  {
1003
- ref: Se,
1012
+ ref: Ce,
1004
1013
  style: {
1005
1014
  position: "absolute",
1006
1015
  bottom: "calc(100% + 6px)",
@@ -1021,90 +1030,90 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1021
1030
  autoFocus: !0,
1022
1031
  type: "text",
1023
1032
  placeholder: "Tìm template…",
1024
- value: de,
1025
- onChange: (l) => me(l.target.value),
1033
+ value: ce,
1034
+ onChange: (l) => be(l.target.value),
1026
1035
  style: { width: "100%", boxSizing: "border-box", border: `1px solid ${d.line}`, borderRadius: 7, padding: "5px 8px", fontSize: 12, outline: "none", fontFamily: "inherit", color: d.ink }
1027
1036
  }
1028
1037
  ) }),
1029
1038
  /* @__PURE__ */ e("div", { style: { maxHeight: 220, overflowY: "auto" }, children: (() => {
1030
- const l = de.trim().toLowerCase(), g = l ? we.filter((b) => b.title.toLowerCase().includes(l) || b.content.toLowerCase().includes(l) || (b.shortcut ?? "").toLowerCase().includes(l)) : we;
1031
- return g.length ? g.map((b) => /* @__PURE__ */ n(
1039
+ const l = ce.trim().toLowerCase(), m = l ? Se.filter((v) => v.title.toLowerCase().includes(l) || v.content.toLowerCase().includes(l) || (v.shortcut ?? "").toLowerCase().includes(l)) : Se;
1040
+ return m.length ? m.map((v) => /* @__PURE__ */ n(
1032
1041
  "button",
1033
1042
  {
1034
1043
  type: "button",
1035
- onClick: () => Te(b.content),
1044
+ onClick: () => Re(v.content),
1036
1045
  style: { display: "block", width: "100%", textAlign: "left", border: 0, borderBottom: `1px solid ${d.line}`, background: "transparent", padding: "9px 12px", cursor: "pointer", fontFamily: "inherit" },
1037
- onMouseEnter: (M) => {
1038
- M.currentTarget.style.background = "#f7f9fc";
1046
+ onMouseEnter: (A) => {
1047
+ A.currentTarget.style.background = "#f7f9fc";
1039
1048
  },
1040
- onMouseLeave: (M) => {
1041
- M.currentTarget.style.background = "transparent";
1049
+ onMouseLeave: (A) => {
1050
+ A.currentTarget.style.background = "transparent";
1042
1051
  },
1043
1052
  children: [
1044
1053
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 2 }, children: [
1045
- /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: d.ink }, children: b.title }),
1046
- b.shortcut && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: s, background: `${s}18`, borderRadius: 4, padding: "1px 5px" }, children: b.shortcut })
1054
+ /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: d.ink }, children: v.title }),
1055
+ v.shortcut && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: s, background: `${s}18`, borderRadius: 4, padding: "1px 5px" }, children: v.shortcut })
1047
1056
  ] }),
1048
- /* @__PURE__ */ e("div", { style: { fontSize: 11, color: d.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: b.content })
1057
+ /* @__PURE__ */ e("div", { style: { fontSize: 11, color: d.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: v.content })
1049
1058
  ]
1050
1059
  },
1051
- b.id
1052
- )) : /* @__PURE__ */ e("div", { style: { padding: "24px 16px", textAlign: "center", color: d.muted, fontSize: 12 }, children: we.length === 0 ? "Chưa có template nào" : "Không tìm thấy" });
1060
+ v.id
1061
+ )) : /* @__PURE__ */ e("div", { style: { padding: "24px 16px", textAlign: "center", color: d.muted, fontSize: 12 }, children: Se.length === 0 ? "Chưa có template nào" : "Không tìm thấy" });
1053
1062
  })() })
1054
1063
  ]
1055
1064
  }
1056
1065
  ),
1057
1066
  /* @__PURE__ */ n("div", { style: { border: `1.5px solid ${d.line}`, borderRadius: 12, background: d.white, overflow: "hidden" }, children: [
1058
- x && /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "8px 12px", borderBottom: `1px solid ${d.line}`, fontSize: 12 }, children: [
1059
- x.uploading ? /* @__PURE__ */ n(te, { children: [
1067
+ w && /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "8px 12px", borderBottom: `1px solid ${d.line}`, fontSize: 12 }, children: [
1068
+ w.uploading ? /* @__PURE__ */ n(ne, { children: [
1060
1069
  /* @__PURE__ */ e(Fe, {}),
1061
1070
  /* @__PURE__ */ e("span", { style: { color: d.muted }, children: "Đang tải lên…" })
1062
- ] }) : x.attachmentType === "image" && x.objectUrl ? /* @__PURE__ */ e("img", { src: x.objectUrl, alt: "", style: { height: 48, width: 48, objectFit: "cover", borderRadius: 6 } }) : /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
1071
+ ] }) : w.attachmentType === "image" && w.objectUrl ? /* @__PURE__ */ e("img", { src: w.objectUrl, alt: "", style: { height: 48, width: 48, objectFit: "cover", borderRadius: 6 } }) : /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
1063
1072
  "📎 ",
1064
- x.file.name,
1073
+ w.file.name,
1065
1074
  " (",
1066
- Math.round(x.file.size / 1024),
1075
+ Math.round(w.file.size / 1024),
1067
1076
  " KB)"
1068
1077
  ] }),
1069
- !x.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1070
- x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), J(null);
1078
+ !w.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1079
+ w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl), _(null);
1071
1080
  }, style: { marginLeft: "auto", border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 16 }, "aria-label": "Xóa tệp đính kèm", children: "✕" })
1072
1081
  ] }),
1073
1082
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 2, padding: "4px 8px", borderBottom: "1px solid #f3f4f6" }, children: [
1074
1083
  /* @__PURE__ */ e(
1075
1084
  "button",
1076
1085
  {
1077
- ref: ke,
1086
+ ref: we,
1078
1087
  type: "button",
1079
1088
  title: "Chèn emoji",
1080
- onClick: () => ie((l) => !l),
1081
- style: { ...p.toolbarBtn, background: q ? `${s}18` : "transparent", color: q ? s : "#9ca3af" },
1082
- children: /* @__PURE__ */ e($t, { size: 13, strokeWidth: 2 })
1089
+ onClick: () => re((l) => !l),
1090
+ style: { ...p.toolbarBtn, background: X ? `${s}18` : "transparent", color: X ? s : "#9ca3af" },
1091
+ children: /* @__PURE__ */ e(Mt, { size: 13, strokeWidth: 2 })
1083
1092
  }
1084
1093
  ),
1085
1094
  !I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: p.toolbarBtn, onClick: () => {
1086
1095
  var l;
1087
- return (l = Q.current) == null ? void 0 : l.click();
1088
- }, children: /* @__PURE__ */ e(Ct, { size: 13, strokeWidth: 2 }) }),
1096
+ return (l = te.current) == null ? void 0 : l.click();
1097
+ }, children: /* @__PURE__ */ e(zt, { size: 13, strokeWidth: 2 }) }),
1089
1098
  !I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi tệp đính kèm", "aria-label": "Gửi tệp đính kèm", style: p.toolbarBtn, onClick: () => {
1090
1099
  var l;
1091
- return (l = N.current) == null ? void 0 : l.click();
1092
- }, children: /* @__PURE__ */ e(Tt, { size: 13, strokeWidth: 2 }) }),
1093
- !I && /* @__PURE__ */ n(te, { children: [
1094
- /* @__PURE__ */ e("input", { ref: Q, type: "file", style: { display: "none" }, onChange: Me, accept: "image/*,video/mp4" }),
1095
- /* @__PURE__ */ e("input", { ref: N, type: "file", style: { display: "none" }, onChange: Me, accept: ".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" })
1100
+ return (l = q.current) == null ? void 0 : l.click();
1101
+ }, children: /* @__PURE__ */ e(Wt, { size: 13, strokeWidth: 2 }) }),
1102
+ !I && /* @__PURE__ */ n(ne, { children: [
1103
+ /* @__PURE__ */ e("input", { ref: te, type: "file", style: { display: "none" }, onChange: Me, accept: "image/*,video/mp4" }),
1104
+ /* @__PURE__ */ e("input", { ref: q, type: "file", style: { display: "none" }, onChange: Me, accept: ".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" })
1096
1105
  ] }),
1097
1106
  /* @__PURE__ */ e(
1098
1107
  "button",
1099
1108
  {
1100
- ref: Ce,
1109
+ ref: Ie,
1101
1110
  type: "button",
1102
1111
  title: "Template nhanh",
1103
1112
  onClick: () => {
1104
- G((l) => !l), me("");
1113
+ J((l) => !l), be("");
1105
1114
  },
1106
1115
  style: { ...p.toolbarBtn, background: fe ? `${s}18` : "transparent", color: fe ? s : "#9ca3af" },
1107
- children: /* @__PURE__ */ e(Lt, { size: 13, strokeWidth: 2 })
1116
+ children: /* @__PURE__ */ e(Ht, { size: 13, strokeWidth: 2 })
1108
1117
  }
1109
1118
  ),
1110
1119
  /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 2px" } }),
@@ -1123,16 +1132,16 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1123
1132
  {
1124
1133
  type: "button",
1125
1134
  title: "Nghiêng",
1126
- onClick: () => P((l) => !l),
1127
- style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background: B ? `${s}18` : "transparent", color: B ? s : "#9ca3af", border: B ? `1px solid ${s}33` : "1px solid transparent" },
1135
+ onClick: () => F((l) => !l),
1136
+ style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background: H ? `${s}18` : "transparent", color: H ? s : "#9ca3af", border: H ? `1px solid ${s}33` : "1px solid transparent" },
1128
1137
  children: "I"
1129
1138
  }
1130
1139
  ),
1131
- !!(R != null && R.some((l) => {
1132
- var g;
1133
- return (((g = l.toolbarActions) == null ? void 0 : g.length) ?? 0) > 0;
1140
+ !!(W != null && W.some((l) => {
1141
+ var m;
1142
+ return (((m = l.toolbarActions) == null ? void 0 : m.length) ?? 0) > 0;
1134
1143
  })) && /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 4px" } }),
1135
- R == null ? void 0 : R.flatMap((l) => l.toolbarActions ?? []).map((l, g) => /* @__PURE__ */ n(
1144
+ W == null ? void 0 : W.flatMap((l) => l.toolbarActions ?? []).map((l, m) => /* @__PURE__ */ n(
1136
1145
  "button",
1137
1146
  {
1138
1147
  type: "button",
@@ -1153,43 +1162,43 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1153
1162
  whiteSpace: "nowrap"
1154
1163
  } : p.toolbarBtn,
1155
1164
  onClick: () => {
1156
- const b = (Z) => {
1157
- w((c) => c && !c.endsWith(" ") && !c.endsWith(`
1158
- `) ? `${c} ${Z}` : `${c}${Z}`), requestAnimationFrame(() => {
1165
+ const v = (Q) => {
1166
+ S((c) => c && !c.endsWith(" ") && !c.endsWith(`
1167
+ `) ? `${c} ${Q}` : `${c}${Q}`), requestAnimationFrame(() => {
1159
1168
  var c;
1160
- return (c = be.current) == null ? void 0 : c.focus();
1169
+ return (c = me.current) == null ? void 0 : c.focus();
1161
1170
  });
1162
- }, M = Ae(t, {
1171
+ }, A = Ae(t, {
1163
1172
  provider: i,
1164
- recentMessages: A.slice(-10),
1165
- linkContact: E,
1166
- refreshContactInfo: j,
1167
- sendMessage: async (Z, c) => {
1168
- await o.sendMessage(t.id, Z, c), await ue(void 0, !0);
1173
+ recentMessages: L.slice(-10),
1174
+ linkContact: O,
1175
+ refreshContactInfo: D,
1176
+ sendMessage: async (Q, c) => {
1177
+ await o.sendMessage(t.id, Q, c), await ue(void 0, !0);
1169
1178
  }
1170
1179
  });
1171
- l.onClick({ ...M, insertText: b });
1180
+ l.onClick({ ...A, insertText: v });
1172
1181
  },
1173
1182
  children: [
1174
1183
  l.icon,
1175
1184
  l.label && /* @__PURE__ */ e("span", { children: l.label })
1176
1185
  ]
1177
1186
  },
1178
- g
1187
+ m
1179
1188
  ))
1180
1189
  ] }),
1181
1190
  /* @__PURE__ */ e(
1182
- jt,
1191
+ At,
1183
1192
  {
1184
- ref: be,
1193
+ ref: me,
1185
1194
  "aria-label": "Soạn tin nhắn",
1186
1195
  rows: 2,
1187
1196
  value: U,
1188
- onChange: (l) => w(l.target.value),
1197
+ onChange: (l) => S(l.target.value),
1189
1198
  onKeyDown: (l) => {
1190
- l.key === "Enter" && !l.shiftKey && (l.preventDefault(), oe(l));
1199
+ l.key === "Enter" && !l.shiftKey && (l.preventDefault(), ae(l));
1191
1200
  },
1192
- placeholder: W.sendPlaceholder,
1201
+ placeholder: R.sendPlaceholder,
1193
1202
  style: {
1194
1203
  display: "block",
1195
1204
  width: "100%",
@@ -1206,7 +1215,7 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1206
1215
  font: "inherit",
1207
1216
  fontSize: 13,
1208
1217
  lineHeight: 1.45,
1209
- fontStyle: B ? "italic" : "normal",
1218
+ fontStyle: H ? "italic" : "normal",
1210
1219
  fontWeight: he ? 700 : 400
1211
1220
  }
1212
1221
  }
@@ -1221,11 +1230,11 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1221
1230
  "/1000"
1222
1231
  ] }),
1223
1232
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
1224
- !H && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1233
+ !E && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1225
1234
  /* @__PURE__ */ n(
1226
1235
  "button",
1227
1236
  {
1228
- disabled: !ae,
1237
+ disabled: !le,
1229
1238
  "aria-label": "Gửi tin nhắn",
1230
1239
  style: {
1231
1240
  display: "flex",
@@ -1236,15 +1245,15 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1236
1245
  borderRadius: 999,
1237
1246
  fontSize: 12,
1238
1247
  fontWeight: 600,
1239
- background: ae ? `linear-gradient(135deg,${s},#0ea5e9)` : "#e5e7eb",
1240
- color: ae ? "#fff" : "#9ca3af",
1241
- cursor: ae ? "pointer" : "not-allowed",
1242
- boxShadow: ae ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1248
+ background: le ? `linear-gradient(135deg,${s},#0ea5e9)` : "#e5e7eb",
1249
+ color: le ? "#fff" : "#9ca3af",
1250
+ cursor: le ? "pointer" : "not-allowed",
1251
+ boxShadow: le ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1243
1252
  transition: "all 150ms ease"
1244
1253
  },
1245
1254
  children: [
1246
- L ? /* @__PURE__ */ e(lt, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(Bt, { size: 12, strokeWidth: 2 }),
1247
- W.send
1255
+ T ? /* @__PURE__ */ e(ct, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e($t, { size: 12, strokeWidth: 2 }),
1256
+ R.send
1248
1257
  ]
1249
1258
  }
1250
1259
  )
@@ -1252,105 +1261,105 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1252
1261
  ] })
1253
1262
  ] })
1254
1263
  ] }),
1255
- (z || C) && /* @__PURE__ */ e("div", { role: "alert", style: p.error, children: z || C })
1264
+ (B || k) && /* @__PURE__ */ e("div", { role: "alert", style: p.error, children: B || k })
1256
1265
  ] });
1257
1266
  }
1258
- function Kt({ message: t, primary: i }) {
1259
- var K, ne, U, w, _;
1260
- const r = Ne(qe), o = Ne(st), s = (k) => k.startsWith("/v1/media/proxy") ? `${r}${k}&tok=${encodeURIComponent(o)}` : k, C = t.direction === "outbound", m = ((K = t.attachments) == null ? void 0 : K.filter((k) => k.type === "image")) ?? [], O = ((ne = t.attachments) == null ? void 0 : ne.filter((k) => k.type === "sticker")) ?? [], f = ((U = t.attachments) == null ? void 0 : U.filter((k) => k.type === "video")) ?? [], S = ((w = t.attachments) == null ? void 0 : w.filter((k) => k.type === "audio")) ?? [], W = ((_ = t.attachments) == null ? void 0 : _.filter((k) => k.type === "file")) ?? [], [I, H] = y(null), R = C ? "flex-end" : "flex-start", E = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
1267
+ function qt({ message: t, primary: i }) {
1268
+ var K, ee, U, S, z;
1269
+ const r = Ne(Ve), o = Ne(pt), s = (b) => b.startsWith("/v1/media/proxy") ? `${r}${b}&tok=${encodeURIComponent(o)}` : b, k = t.direction === "outbound", g = ((K = t.attachments) == null ? void 0 : K.filter((b) => b.type === "image")) ?? [], $ = ((ee = t.attachments) == null ? void 0 : ee.filter((b) => b.type === "sticker")) ?? [], f = ((U = t.attachments) == null ? void 0 : U.filter((b) => b.type === "video")) ?? [], x = ((S = t.attachments) == null ? void 0 : S.filter((b) => b.type === "audio")) ?? [], R = ((z = t.attachments) == null ? void 0 : z.filter((b) => b.type === "file")) ?? [], [I, E] = y(null), W = k ? "flex-end" : "flex-start", O = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
1261
1270
  Ke(t.occurredAt, !0),
1262
- C && /* @__PURE__ */ n(te, { children: [
1271
+ k && /* @__PURE__ */ n(ne, { children: [
1263
1272
  " ",
1264
- /* @__PURE__ */ e(_e, { status: t.status })
1273
+ /* @__PURE__ */ e(Qe, { status: t.status })
1265
1274
  ] })
1266
- ] }), j = /* @__PURE__ */ e("div", { style: { position: "absolute", bottom: 6, right: 8 }, children: /* @__PURE__ */ n("time", { style: { fontSize: 10, color: "#fff", textShadow: "0 1px 3px rgba(0,0,0,.5)", letterSpacing: 0.2, userSelect: "none" }, children: [
1275
+ ] }), D = /* @__PURE__ */ e("div", { style: { position: "absolute", bottom: 6, right: 8 }, children: /* @__PURE__ */ n("time", { style: { fontSize: 10, color: "#fff", textShadow: "0 1px 3px rgba(0,0,0,.5)", letterSpacing: 0.2, userSelect: "none" }, children: [
1267
1276
  Ke(t.occurredAt, !0),
1268
- C && /* @__PURE__ */ n(te, { children: [
1277
+ k && /* @__PURE__ */ n(ne, { children: [
1269
1278
  " ",
1270
- /* @__PURE__ */ e(_e, { status: t.status })
1279
+ /* @__PURE__ */ e(Qe, { status: t.status })
1271
1280
  ] })
1272
- ] }) }), A = C ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, F = !t.text && S.length === 0 && W.length === 0;
1273
- return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent: R, flexDirection: "column", alignItems: R }, children: [
1274
- O.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1275
- /* @__PURE__ */ e("img", { src: s(k.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1276
- F && m.length === 0 && f.length === 0 && L === O.length - 1 && j
1277
- ] }, `s${L}`)),
1278
- m.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => H({ url: s(k.url), kind: "image" }), children: [
1279
- /* @__PURE__ */ e("img", { src: s(k.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1280
- F && L === m.length - 1 && f.length === 0 && j
1281
- ] }, L)),
1282
- f.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => H({ url: s(k.url), kind: "video" }), children: [
1283
- /* @__PURE__ */ e("video", { src: s(k.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1284
- /* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,0,0,.25)" }, children: /* @__PURE__ */ e("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,.9)", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(Rt, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
1285
- F && L === f.length - 1 && j
1286
- ] }, L)),
1287
- (S.length > 0 || W.length > 0 || t.text || !m.length && !f.length && !O.length && !t.text) && /* @__PURE__ */ n("div", { style: A, children: [
1288
- S.map((k, L) => /* @__PURE__ */ e("audio", { src: s(k.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, L)),
1289
- W.map((k, L) => /* @__PURE__ */ n("a", { href: s(k.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: C ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
1281
+ ] }) }), L = k ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, P = !t.text && x.length === 0 && R.length === 0;
1282
+ return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent: W, flexDirection: "column", alignItems: W }, children: [
1283
+ $.map((b, T) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1284
+ /* @__PURE__ */ e("img", { src: s(b.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1285
+ P && g.length === 0 && f.length === 0 && T === $.length - 1 && D
1286
+ ] }, `s${T}`)),
1287
+ g.map((b, T) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => E({ url: s(b.url), kind: "image" }), children: [
1288
+ /* @__PURE__ */ e("img", { src: s(b.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1289
+ P && T === g.length - 1 && f.length === 0 && D
1290
+ ] }, T)),
1291
+ f.map((b, T) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => E({ url: s(b.url), kind: "video" }), children: [
1292
+ /* @__PURE__ */ e("video", { src: s(b.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1293
+ /* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,0,0,.25)" }, children: /* @__PURE__ */ e("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,.9)", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(Bt, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
1294
+ P && T === f.length - 1 && D
1295
+ ] }, T)),
1296
+ (x.length > 0 || R.length > 0 || t.text || !g.length && !f.length && !$.length && !t.text) && /* @__PURE__ */ n("div", { style: L, children: [
1297
+ x.map((b, T) => /* @__PURE__ */ e("audio", { src: s(b.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, T)),
1298
+ R.map((b, T) => /* @__PURE__ */ n("a", { href: s(b.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: k ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
1290
1299
  "📎 ",
1291
- Pt(k.mimeType)
1292
- ] }, L)),
1300
+ Nt(b.mimeType)
1301
+ ] }, T)),
1293
1302
  t.text && /* @__PURE__ */ e("p", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: t.text }),
1294
- !S.length && !W.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1295
- E
1303
+ !x.length && !R.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1304
+ O
1296
1305
  ] }),
1297
- I && it(
1298
- /* @__PURE__ */ n("div", { onClick: () => H(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
1299
- I.kind === "image" ? /* @__PURE__ */ e("img", { src: I.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (k) => k.stopPropagation() }) : /* @__PURE__ */ e("video", { src: I.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (k) => k.stopPropagation() }),
1300
- /* @__PURE__ */ e("button", { onClick: () => H(null), style: { position: "absolute", top: 16, right: 16, background: "rgba(255,255,255,.15)", border: "none", borderRadius: "50%", width: 36, height: 36, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ e(je, { size: 18 }) })
1306
+ I && ot(
1307
+ /* @__PURE__ */ n("div", { onClick: () => E(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
1308
+ I.kind === "image" ? /* @__PURE__ */ e("img", { src: I.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (b) => b.stopPropagation() }) : /* @__PURE__ */ e("video", { src: I.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (b) => b.stopPropagation() }),
1309
+ /* @__PURE__ */ e("button", { onClick: () => E(null), style: { position: "absolute", top: 16, right: 16, background: "rgba(255,255,255,.15)", border: "none", borderRadius: "50%", width: 36, height: 36, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ e(je, { size: 18 }) })
1301
1310
  ] }),
1302
1311
  document.body
1303
1312
  )
1304
1313
  ] });
1305
1314
  }
1306
- function qt({
1315
+ function Vt({
1307
1316
  conversation: t,
1308
1317
  connection: i,
1309
1318
  primary: r,
1310
1319
  onClose: o,
1311
1320
  client: s,
1312
- onStartResize: C,
1313
- extensions: m,
1314
- extRefreshKey: O,
1321
+ onStartResize: k,
1322
+ extensions: g,
1323
+ extRefreshKey: $,
1315
1324
  onLinkContact: f,
1316
- onRefreshContactInfo: S
1325
+ onRefreshContactInfo: x
1317
1326
  }) {
1318
- const W = t.contactName ?? t.subject ?? t.providerConversationKey, I = i == null ? void 0 : i.provider, H = !!(m != null && m.some((v) => v.contactInfoRows)), [R, E] = y({ channel: !0, stats: !1, extra: !0 }), j = (v) => E((Q) => ({ ...Q, [v]: !Q[v] })), [A, F] = y(""), [K, ne] = y(!1), [U, w] = y(!1), [_, k] = y(""), [L, se] = y([]), [z, D] = y(!1);
1319
- Y(() => {
1320
- F(""), w(!1), k(""), s.getNote(t.id).then((v) => {
1321
- v && F(v.content);
1327
+ const R = t.contactName ?? t.subject ?? t.providerConversationKey, I = i == null ? void 0 : i.provider, E = !!(g != null && g.some((C) => C.contactInfoRows)), [W, O] = y({ channel: !0, stats: !1, extra: !0 }), D = (C) => O((te) => ({ ...te, [C]: !te[C] })), [L, P] = y(""), [K, ee] = y(!1), [U, S] = y(!1), [z, b] = y(""), [T, ie] = y([]), [B, N] = y(!1);
1328
+ V(() => {
1329
+ P(""), S(!1), b(""), s.getNote(t.id).then((C) => {
1330
+ C && P(C.content);
1322
1331
  }).catch(() => {
1323
1332
  });
1324
- }, [t.id, s]), Y(() => {
1325
- if (!H || !m) return;
1326
- let v = !1;
1327
- const Q = Ae(t, {
1333
+ }, [t.id, s]), V(() => {
1334
+ if (!E || !g) return;
1335
+ let C = !1;
1336
+ const te = Ae(t, {
1328
1337
  provider: I,
1329
1338
  linkContact: f,
1330
- refreshContactInfo: S,
1331
- sendMessage: async (N, x) => {
1332
- await s.sendMessage(t.id, N, x);
1339
+ refreshContactInfo: x,
1340
+ sendMessage: async (q, w) => {
1341
+ await s.sendMessage(t.id, q, w);
1333
1342
  }
1334
1343
  });
1335
- return D(!0), Promise.allSettled(
1336
- m.filter((N) => N.contactInfoRows).map((N) => N.contactInfoRows(Q))
1337
- ).then((N) => {
1338
- if (v) return;
1339
- const x = N.filter((J) => J.status === "fulfilled").flatMap((J) => J.value);
1340
- se(x), D(!1);
1344
+ return N(!0), Promise.allSettled(
1345
+ g.filter((q) => q.contactInfoRows).map((q) => q.contactInfoRows(te))
1346
+ ).then((q) => {
1347
+ if (C) return;
1348
+ const w = q.filter((_) => _.status === "fulfilled").flatMap((_) => _.value);
1349
+ ie(w), N(!1);
1341
1350
  }), () => {
1342
- v = !0;
1351
+ C = !0;
1343
1352
  };
1344
- }, [t.id, t.contactExternalId, m, O, H, I, f, S, s]);
1345
- async function le() {
1346
- if (!(!A.trim() || K)) {
1347
- ne(!0), k("");
1353
+ }, [t.id, t.contactExternalId, g, $, E, I, f, x, s]);
1354
+ async function de() {
1355
+ if (!(!L.trim() || K)) {
1356
+ ee(!0), b("");
1348
1357
  try {
1349
- await s.upsertNote(t.id, A.trim()), w(!0), setTimeout(() => w(!1), 2e3);
1358
+ await s.upsertNote(t.id, L.trim()), S(!0), setTimeout(() => S(!1), 2e3);
1350
1359
  } catch {
1351
- k("Lưu thất bại");
1360
+ b("Lưu thất bại");
1352
1361
  } finally {
1353
- ne(!1);
1362
+ ee(!1);
1354
1363
  }
1355
1364
  }
1356
1365
  }
@@ -1358,13 +1367,13 @@ function qt({
1358
1367
  /* @__PURE__ */ e(
1359
1368
  "div",
1360
1369
  {
1361
- onMouseDown: C,
1370
+ onMouseDown: k,
1362
1371
  style: { position: "absolute", left: 0, top: 0, bottom: 0, width: 4, cursor: "col-resize", zIndex: 1 },
1363
- onMouseEnter: (v) => {
1364
- v.currentTarget.style.background = "rgba(0,0,0,0.07)";
1372
+ onMouseEnter: (C) => {
1373
+ C.currentTarget.style.background = "rgba(0,0,0,0.07)";
1365
1374
  },
1366
- onMouseLeave: (v) => {
1367
- v.currentTarget.style.background = "";
1375
+ onMouseLeave: (C) => {
1376
+ C.currentTarget.style.background = "";
1368
1377
  }
1369
1378
  }
1370
1379
  ),
@@ -1376,32 +1385,32 @@ function qt({
1376
1385
  /* @__PURE__ */ n("div", { style: p.infoPanelIdentity, children: [
1377
1386
  /* @__PURE__ */ n("span", { style: { ...p.avatarWrap, width: 48, height: 48 }, children: [
1378
1387
  /* @__PURE__ */ e(
1379
- dt,
1388
+ qe,
1380
1389
  {
1381
1390
  src: t.contactPictureUrl,
1382
- fallback: ut(W),
1391
+ fallback: gt(R),
1383
1392
  style: { ...p.avatar, width: 48, height: 48, fontSize: 16 }
1384
1393
  }
1385
1394
  ),
1386
1395
  /* @__PURE__ */ e("span", { style: { ...p.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e($e, { provider: I }) })
1387
1396
  ] }),
1388
- /* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: W }),
1397
+ /* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: R }),
1389
1398
  /* @__PURE__ */ e("span", { style: { fontSize: 11, color: d.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
1390
1399
  ] }),
1391
- /* @__PURE__ */ n(Ue, { label: "KÊNH", sectionKey: "channel", expanded: R.channel, onToggle: () => j("channel"), children: [
1400
+ /* @__PURE__ */ n(De, { label: "KÊNH", sectionKey: "channel", expanded: W.channel, onToggle: () => D("channel"), children: [
1392
1401
  /* @__PURE__ */ e(pe, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
1393
1402
  /* @__PURE__ */ e($e, { provider: I }),
1394
- /* @__PURE__ */ e("span", { children: ht(I) })
1403
+ /* @__PURE__ */ e("span", { children: ut(I) })
1395
1404
  ] }) }),
1396
1405
  /* @__PURE__ */ n(pe, { label: "ID hội thoại", children: [
1397
1406
  /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", fontSize: 11 }, children: [
1398
1407
  t.id.slice(0, 8),
1399
1408
  "…"
1400
1409
  ] }),
1401
- /* @__PURE__ */ e(Vt, { value: t.id })
1410
+ /* @__PURE__ */ e(Gt, { value: t.id })
1402
1411
  ] })
1403
1412
  ] }),
1404
- /* @__PURE__ */ n(Ue, { label: "THỐNG KÊ", sectionKey: "stats", expanded: R.stats, onToggle: () => j("stats"), children: [
1413
+ /* @__PURE__ */ n(De, { label: "THỐNG KÊ", sectionKey: "stats", expanded: W.stats, onToggle: () => D("stats"), children: [
1405
1414
  /* @__PURE__ */ e(pe, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
1406
1415
  (t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(pe, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
1407
1416
  /* @__PURE__ */ e(
@@ -1413,24 +1422,24 @@ function qt({
1413
1422
  ),
1414
1423
  /* @__PURE__ */ e(pe, { label: "Lần đầu", value: "—" })
1415
1424
  ] }),
1416
- /* @__PURE__ */ n(Ue, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: R.extra, onToggle: () => j("extra"), children: [
1417
- !H && /* @__PURE__ */ n(te, { children: [
1425
+ /* @__PURE__ */ n(De, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: W.extra, onToggle: () => D("extra"), children: [
1426
+ !E && /* @__PURE__ */ n(ne, { children: [
1418
1427
  /* @__PURE__ */ e(pe, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
1419
1428
  /* @__PURE__ */ e(pe, { label: "Email", value: "— chưa có", valueMuted: !0 }),
1420
1429
  /* @__PURE__ */ e(pe, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
1421
1430
  ] }),
1422
- z && L.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
1423
- L.map((v) => /* @__PURE__ */ e(pe, { label: v.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
1424
- v.onClick ? /* @__PURE__ */ e(
1431
+ B && T.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
1432
+ T.map((C) => /* @__PURE__ */ e(pe, { label: C.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
1433
+ C.onClick ? /* @__PURE__ */ e(
1425
1434
  "button",
1426
1435
  {
1427
1436
  type: "button",
1428
- onClick: v.onClick,
1437
+ onClick: C.onClick,
1429
1438
  style: { border: 0, background: "none", padding: 0, color: r, fontSize: 12, fontWeight: 600, cursor: "pointer", textDecoration: "underline" },
1430
- children: v.value
1439
+ children: C.value
1431
1440
  }
1432
- ) : v.href ? /* @__PURE__ */ e("a", { href: v.href, target: "_blank", rel: "noopener noreferrer", style: { color: r, fontSize: 12, fontWeight: 600 }, children: v.value }) : /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 500, color: d.ink }, children: v.value }),
1433
- v.badge && /* @__PURE__ */ e(
1441
+ ) : C.href ? /* @__PURE__ */ e("a", { href: C.href, target: "_blank", rel: "noopener noreferrer", style: { color: r, fontSize: 12, fontWeight: 600 }, children: C.value }) : /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 500, color: d.ink }, children: C.value }),
1442
+ C.badge && /* @__PURE__ */ e(
1434
1443
  "span",
1435
1444
  {
1436
1445
  style: {
@@ -1438,49 +1447,49 @@ function qt({
1438
1447
  fontWeight: 700,
1439
1448
  padding: "1px 7px",
1440
1449
  borderRadius: 999,
1441
- color: v.badge.color ?? r,
1442
- background: v.badge.bg ?? `${r}14`
1450
+ color: C.badge.color ?? r,
1451
+ background: C.badge.bg ?? `${r}14`
1443
1452
  },
1444
- children: v.badge.text
1453
+ children: C.badge.text
1445
1454
  }
1446
1455
  )
1447
- ] }) }, v.label))
1456
+ ] }) }, C.label))
1448
1457
  ] }),
1449
1458
  /* @__PURE__ */ n("div", { style: { padding: "12px 16px", display: "flex", flexDirection: "column", gap: 8 }, children: [
1450
- !(m != null && m.length) && /* @__PURE__ */ e("button", { style: { ...p.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1451
- m == null ? void 0 : m.flatMap((v) => v.sidebarActions ?? []).map((v, Q) => {
1452
- const N = v.variant === "primary";
1459
+ !(g != null && g.length) && /* @__PURE__ */ e("button", { style: { ...p.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1460
+ g == null ? void 0 : g.flatMap((C) => C.sidebarActions ?? []).map((C, te) => {
1461
+ const q = C.variant === "primary";
1453
1462
  return /* @__PURE__ */ n(
1454
1463
  "button",
1455
1464
  {
1456
1465
  style: {
1457
1466
  ...p.ghostButton,
1458
- background: N ? r : "#fff",
1459
- color: N ? "#fff" : d.ink,
1460
- borderColor: N ? r : d.line,
1461
- fontWeight: N ? 700 : 600,
1467
+ background: q ? r : "#fff",
1468
+ color: q ? "#fff" : d.ink,
1469
+ borderColor: q ? r : d.line,
1470
+ fontWeight: q ? 700 : 600,
1462
1471
  display: "flex",
1463
1472
  alignItems: "center",
1464
1473
  justifyContent: "center",
1465
1474
  gap: 6
1466
1475
  },
1467
1476
  onClick: () => {
1468
- const x = Ae(t, {
1477
+ const w = Ae(t, {
1469
1478
  provider: I,
1470
1479
  linkContact: f,
1471
- refreshContactInfo: S,
1472
- sendMessage: async (J, he) => {
1473
- await s.sendMessage(t.id, J, he);
1480
+ refreshContactInfo: x,
1481
+ sendMessage: async (_, he) => {
1482
+ await s.sendMessage(t.id, _, he);
1474
1483
  }
1475
1484
  });
1476
- v.onClick(x);
1485
+ C.onClick(w);
1477
1486
  },
1478
1487
  children: [
1479
- v.icon,
1480
- v.label
1488
+ C.icon,
1489
+ C.label
1481
1490
  ]
1482
1491
  },
1483
- Q
1492
+ te
1484
1493
  );
1485
1494
  }),
1486
1495
  /* @__PURE__ */ n("div", { style: { border: `1px solid ${d.line}`, borderRadius: 10, background: "#fff", overflow: "hidden" }, children: [
@@ -1488,8 +1497,8 @@ function qt({
1488
1497
  /* @__PURE__ */ e(
1489
1498
  "textarea",
1490
1499
  {
1491
- value: A,
1492
- onChange: (v) => F(v.target.value),
1500
+ value: L,
1501
+ onChange: (C) => P(C.target.value),
1493
1502
  placeholder: "Nhập ghi chú...",
1494
1503
  rows: 3,
1495
1504
  style: { display: "block", width: "100%", boxSizing: "border-box", border: 0, outline: 0, background: "transparent", resize: "none", padding: "8px 10px", font: "inherit", fontSize: 12, color: d.ink, lineHeight: 1.5 }
@@ -1497,18 +1506,18 @@ function qt({
1497
1506
  ),
1498
1507
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 10px 6px" }, children: [
1499
1508
  U ? /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, fontSize: 11, color: "#16a34a" }, children: [
1500
- /* @__PURE__ */ e(ot, { size: 11, strokeWidth: 2.5 }),
1509
+ /* @__PURE__ */ e(lt, { size: 11, strokeWidth: 2.5 }),
1501
1510
  " Đã lưu"
1502
- ] }) : _ ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: _ }) : /* @__PURE__ */ e("span", {}),
1511
+ ] }) : z ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: z }) : /* @__PURE__ */ e("span", {}),
1503
1512
  /* @__PURE__ */ e(
1504
1513
  "button",
1505
1514
  {
1506
1515
  type: "button",
1507
1516
  onClick: () => {
1508
- le();
1517
+ de();
1509
1518
  },
1510
- disabled: !A.trim() || K,
1511
- style: { padding: "4px 12px", border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: A.trim() && !K ? "linear-gradient(135deg,#f59e0b,#fbbf24)" : "#e5e7eb", color: A.trim() && !K ? "#fff" : "#9ca3af", cursor: A.trim() && !K ? "pointer" : "not-allowed" },
1519
+ disabled: !L.trim() || K,
1520
+ style: { padding: "4px 12px", border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: L.trim() && !K ? "linear-gradient(135deg,#f59e0b,#fbbf24)" : "#e5e7eb", color: L.trim() && !K ? "#fff" : "#9ca3af", cursor: L.trim() && !K ? "pointer" : "not-allowed" },
1512
1521
  children: K ? "Đang lưu…" : "Lưu ghi chú"
1513
1522
  }
1514
1523
  )
@@ -1518,21 +1527,21 @@ function qt({
1518
1527
  ] })
1519
1528
  ] });
1520
1529
  }
1521
- function Ue({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s }) {
1522
- const C = !!s, m = o ?? !0;
1530
+ function De({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s }) {
1531
+ const k = !!s, g = o ?? !0;
1523
1532
  return /* @__PURE__ */ n("div", { style: { borderTop: `1px solid ${d.line}` }, children: [
1524
1533
  /* @__PURE__ */ n(
1525
1534
  "div",
1526
1535
  {
1527
- style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: d.muted, textTransform: "uppercase", cursor: C ? "pointer" : "default" },
1536
+ style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: d.muted, textTransform: "uppercase", cursor: k ? "pointer" : "default" },
1528
1537
  onClick: s,
1529
1538
  children: [
1530
1539
  /* @__PURE__ */ e("span", { children: t }),
1531
- C && (m ? /* @__PURE__ */ e(kt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(wt, { size: 12, strokeWidth: 2 }))
1540
+ k && (g ? /* @__PURE__ */ e(St, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(Ct, { size: 12, strokeWidth: 2 }))
1532
1541
  ]
1533
1542
  }
1534
1543
  ),
1535
- m && i
1544
+ g && i
1536
1545
  ] });
1537
1546
  }
1538
1547
  function pe({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
@@ -1541,7 +1550,7 @@ function pe({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
1541
1550
  /* @__PURE__ */ e("span", { style: { color: o ?? (s ? d.muted : d.ink), textAlign: "right", minWidth: 0, display: "flex", alignItems: "center", justifyContent: "flex-end", flexWrap: "wrap", gap: 4, lineHeight: 1.4 }, children: r ?? i })
1542
1551
  ] });
1543
1552
  }
1544
- function Vt({ value: t }) {
1553
+ function Gt({ value: t }) {
1545
1554
  const [i, r] = y(!1);
1546
1555
  return /* @__PURE__ */ e(
1547
1556
  "button",
@@ -1558,31 +1567,31 @@ function Vt({ value: t }) {
1558
1567
  }
1559
1568
  );
1560
1569
  }
1561
- function Gt() {
1570
+ function Xt() {
1562
1571
  return /* @__PURE__ */ n("div", { style: p.empty, children: [
1563
- /* @__PURE__ */ e("div", { style: p.emptyHero, children: /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }) }),
1572
+ /* @__PURE__ */ e("div", { style: p.emptyHero, children: /* @__PURE__ */ e(Tt, { size: 16, strokeWidth: 2 }) }),
1564
1573
  /* @__PURE__ */ e("h2", { children: "Chọn một hội thoại" }),
1565
1574
  /* @__PURE__ */ e("p", { children: "Chọn hội thoại bên trái để xem và trả lời tin nhắn." })
1566
1575
  ] });
1567
1576
  }
1568
- function pt({ name: t, color: i, image: r, provider: o }) {
1577
+ function ft({ name: t, color: i, image: r, provider: o }) {
1569
1578
  return /* @__PURE__ */ n("span", { style: p.avatarWrap, children: [
1570
- /* @__PURE__ */ e(Xt, { name: t, color: i, image: r }),
1579
+ /* @__PURE__ */ e(Yt, { name: t, color: i, image: r }),
1571
1580
  o && /* @__PURE__ */ e("span", { style: p.providerBadge, children: /* @__PURE__ */ e($e, { provider: o }) })
1572
1581
  ] });
1573
1582
  }
1574
- function Xt({ name: t, color: i, image: r }) {
1575
- return /* @__PURE__ */ e(dt, { src: r, fallback: ut(t), style: { ...p.avatar, background: `${i}18`, color: i } });
1583
+ function Yt({ name: t, color: i, image: r }) {
1584
+ return /* @__PURE__ */ e(qe, { src: r, fallback: gt(t), style: { ...p.avatar, background: `${i}18`, color: i } });
1576
1585
  }
1577
1586
  function Fe() {
1578
- return /* @__PURE__ */ e(lt, { size: 14, style: p.spinner, "aria-hidden": "true" });
1587
+ return /* @__PURE__ */ e(ct, { size: 14, style: p.spinner, "aria-hidden": "true" });
1579
1588
  }
1580
- function ut(t) {
1589
+ function gt(t) {
1581
1590
  return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
1582
1591
  }
1583
1592
  const Jt = { livechat: "web" };
1584
1593
  function $e({ provider: t }) {
1585
- const i = Ne(qe), r = 14;
1594
+ const i = Ne(Ve), r = 14;
1586
1595
  if (!t) return null;
1587
1596
  const o = Jt[t] ?? t;
1588
1597
  return /* @__PURE__ */ e("img", { src: `${i}/static/logos/${o}.avif`, alt: t, width: r, height: r, style: { borderRadius: "50%", objectFit: "cover", display: "block" } });
@@ -1639,7 +1648,7 @@ const p = {
1639
1648
  infoPanelHeader: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 16px 12px", borderBottom: `1px solid ${d.line}`, flex: "0 0 auto" },
1640
1649
  infoPanelIdentity: { display: "flex", flexDirection: "column", alignItems: "center", padding: "20px 16px 16px", gap: 4 },
1641
1650
  ghostButton: { width: "100%", padding: "8px 12px", border: `1px solid ${d.line}`, borderRadius: 8, background: "transparent", fontSize: 12, cursor: "pointer", textAlign: "center" }
1642
- }, Yt = {
1651
+ }, Zt = {
1643
1652
  facebook: "#dbeafe",
1644
1653
  zalo: "#e0f2fe",
1645
1654
  instagram: "#fce7f3",
@@ -1655,7 +1664,7 @@ const p = {
1655
1664
  whatsapp: "web"
1656
1665
  };
1657
1666
  function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1658
- const o = Yt[t] ?? "#f1f5f9", s = _t[t], C = i.replace(/\/$/, "");
1667
+ const o = Zt[t] ?? "#f1f5f9", s = _t[t], k = i.replace(/\/$/, "");
1659
1668
  return /* @__PURE__ */ e(
1660
1669
  "div",
1661
1670
  {
@@ -1673,7 +1682,7 @@ function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1673
1682
  children: s ? /* @__PURE__ */ e(
1674
1683
  "img",
1675
1684
  {
1676
- src: `${C}/static/logos/${s}.avif`,
1685
+ src: `${k}/static/logos/${s}.avif`,
1677
1686
  alt: t,
1678
1687
  width: Math.round(r * 0.65),
1679
1688
  height: Math.round(r * 0.65),
@@ -1690,7 +1699,7 @@ const Be = {
1690
1699
  telegram: "Telegram",
1691
1700
  livechat: "Live Chat",
1692
1701
  whatsapp: "WhatsApp"
1693
- }, Zt = {
1702
+ }, Qt = {
1694
1703
  facebook: "#dbeafe",
1695
1704
  zalo: "#e0f2fe",
1696
1705
  instagram: "#fce7f3",
@@ -1698,11 +1707,11 @@ const Be = {
1698
1707
  livechat: "#ede9fe",
1699
1708
  whatsapp: "#dcfce7"
1700
1709
  };
1701
- function Ve(t) {
1710
+ function Ge(t) {
1702
1711
  const i = t.metadata;
1703
1712
  return String(i.displayName ?? i.pageName ?? i.username ?? i.name ?? t.externalAccountId);
1704
1713
  }
1705
- function Qt(t) {
1714
+ function en(t) {
1706
1715
  const i = Be[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
1707
1716
  return r ? `${i} · ${r}` : i;
1708
1717
  }
@@ -1981,68 +1990,68 @@ const a = {
1981
1990
  fontFamily: "inherit"
1982
1991
  }
1983
1992
  };
1984
- function Ze() {
1993
+ function et() {
1985
1994
  return /* @__PURE__ */ e("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ e("path", { d: "M7 1v12M1 7h12", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) });
1986
1995
  }
1987
1996
  function ve() {
1988
1997
  return /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ e("path", { d: "M10 3L5 8l5 5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) });
1989
1998
  }
1990
- function Qe() {
1999
+ function tt() {
1991
2000
  return /* @__PURE__ */ n("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: [
1992
2001
  /* @__PURE__ */ e("rect", { x: "4", y: "4", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.3" }),
1993
2002
  /* @__PURE__ */ e("path", { d: "M2.5 8H2a1 1 0 01-1-1V2a1 1 0 011-1h5a1 1 0 011 1v.5", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
1994
2003
  ] });
1995
2004
  }
1996
- function et() {
2005
+ function nt() {
1997
2006
  return /* @__PURE__ */ e("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: /* @__PURE__ */ e("path", { d: "M2 6l3 3 5-5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
1998
2007
  }
1999
- function en() {
2008
+ function tn() {
2000
2009
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0 }, children: [
2001
2010
  /* @__PURE__ */ e("circle", { cx: "5", cy: "6", r: "3.5", stroke: "#ca8a04", strokeWidth: "1.4" }),
2002
2011
  /* @__PURE__ */ e("path", { d: "M8 7.5l4.5 4.5M10.5 10l1.5 1.5", stroke: "#ca8a04", strokeWidth: "1.4", strokeLinecap: "round" })
2003
2012
  ] });
2004
2013
  }
2005
- function tn() {
2014
+ function nn() {
2006
2015
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0, marginTop: 1 }, children: [
2007
2016
  /* @__PURE__ */ e("circle", { cx: "7", cy: "7", r: "6", stroke: "currentColor", strokeWidth: "1.5" }),
2008
2017
  /* @__PURE__ */ e("path", { d: "M7 6v5M7 4.5v.01", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
2009
2018
  ] });
2010
2019
  }
2011
- let tt = !1;
2012
- function nn() {
2013
- if (tt || typeof document > "u") return;
2014
- tt = !0;
2020
+ let it = !1;
2021
+ function rn() {
2022
+ if (it || typeof document > "u") return;
2023
+ it = !0;
2015
2024
  const t = document.createElement("style");
2016
2025
  t.textContent = "@keyframes ch-spin{to{transform:rotate(360deg)}}", document.head.appendChild(t);
2017
2026
  }
2018
- function un({ apiUrl: t, token: i, onConnectionChange: r }) {
2019
- const o = t.replace(/\/$/, ""), [s, C] = y([]), [m, O] = y(!0), [f, S] = y({ name: "list" }), [W, I] = y(null), [H, R] = y(!1), [E, j] = y(""), [A, F] = y(""), [K, ne] = y(""), [U, w] = y(""), [_, k] = y(!1), [L, se] = y(!1), z = ee(null);
2020
- nn();
2021
- const D = We(async () => {
2027
+ function bn({ apiUrl: t, token: i, onConnectionChange: r }) {
2028
+ const o = t.replace(/\/$/, ""), [s, k] = y([]), [g, $] = y(!0), [f, x] = y({ name: "list" }), [R, I] = y(null), [E, W] = y(!1), [O, D] = y(""), [L, P] = y(""), [K, ee] = y(""), [U, S] = y(""), [z, b] = y(!1), [T, ie] = y(!1), B = Z(null);
2029
+ rn();
2030
+ const N = ke(async () => {
2022
2031
  try {
2023
2032
  const h = await fetch(`${o}/v1/connections`, {
2024
2033
  headers: { authorization: `Bearer ${i}` }
2025
2034
  });
2026
2035
  if (!h.ok) throw new Error("Không tải được kênh");
2027
- const B = await h.json();
2028
- C(B), r == null || r(B);
2036
+ const H = await h.json();
2037
+ k(H), r == null || r(H);
2029
2038
  } catch (h) {
2030
2039
  I(h instanceof Error ? h.message : "Lỗi tải dữ liệu");
2031
2040
  } finally {
2032
- O(!1);
2041
+ $(!1);
2033
2042
  }
2034
2043
  }, [o, i, r]);
2035
- Y(() => {
2036
- D();
2037
- }, [D]), Y(() => {
2038
- if (!W) return;
2044
+ V(() => {
2045
+ N();
2046
+ }, [N]), V(() => {
2047
+ if (!R) return;
2039
2048
  const h = setTimeout(() => I(null), 5e3);
2040
2049
  return () => clearTimeout(h);
2041
- }, [W]), Y(() => () => {
2042
- z.current && window.removeEventListener("message", z.current);
2050
+ }, [R]), V(() => () => {
2051
+ B.current && window.removeEventListener("message", B.current);
2043
2052
  }, []);
2044
- async function le(h, B) {
2045
- if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${B}"?
2053
+ async function de(h, H) {
2054
+ if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${H}"?
2046
2055
 
2047
2056
  Hành động này không thể hoàn tác.`))
2048
2057
  try {
@@ -2050,194 +2059,194 @@ Hành động này không thể hoàn tác.`))
2050
2059
  method: "DELETE",
2051
2060
  headers: { authorization: `Bearer ${i}` }
2052
2061
  })).ok) throw new Error("Không thể ngắt kết nối");
2053
- await D();
2054
- } catch (P) {
2055
- I(P instanceof Error ? P.message : "Lỗi ngắt kết nối");
2062
+ await N();
2063
+ } catch (F) {
2064
+ I(F instanceof Error ? F.message : "Lỗi ngắt kết nối");
2056
2065
  }
2057
2066
  }
2058
- async function v() {
2059
- if (!E.trim()) {
2067
+ async function C() {
2068
+ if (!O.trim()) {
2060
2069
  I("Vui lòng nhập Bot Token");
2061
2070
  return;
2062
2071
  }
2063
- if (!/^\d+:[A-Za-z0-9_-]+$/.test(E.trim())) {
2072
+ if (!/^\d+:[A-Za-z0-9_-]+$/.test(O.trim())) {
2064
2073
  I("Token không đúng định dạng");
2065
2074
  return;
2066
2075
  }
2067
- R(!0), I(null);
2076
+ W(!0), I(null);
2068
2077
  try {
2069
2078
  const h = await fetch(`${o}/v1/connect/telegram/start`, {
2070
2079
  method: "POST",
2071
2080
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2072
- body: JSON.stringify({ botToken: E.trim(), displayName: A.trim() || void 0 })
2073
- }), B = await h.json();
2074
- if (!h.ok || !B.connectionId) throw new Error(B.message ?? "Không thể kết nối Telegram");
2075
- j(""), F(""), await D(), S({ name: "list" });
2081
+ body: JSON.stringify({ botToken: O.trim(), displayName: L.trim() || void 0 })
2082
+ }), H = await h.json();
2083
+ if (!h.ok || !H.connectionId) throw new Error(H.message ?? "Không thể kết nối Telegram");
2084
+ D(""), P(""), await N(), x({ name: "list" });
2076
2085
  } catch (h) {
2077
2086
  I(h instanceof Error ? h.message : "Lỗi kết nối");
2078
2087
  } finally {
2079
- R(!1);
2088
+ W(!1);
2080
2089
  }
2081
2090
  }
2082
- async function Q() {
2091
+ async function te() {
2083
2092
  if (!K.trim()) {
2084
2093
  I("Vui lòng nhập tên widget");
2085
2094
  return;
2086
2095
  }
2087
- R(!0), I(null);
2096
+ W(!0), I(null);
2088
2097
  try {
2089
- const h = U.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean), B = await fetch(`${o}/v1/connect/livechat/start`, {
2098
+ const h = U.split(/[\n,]+/).map((X) => X.trim()).filter(Boolean), H = await fetch(`${o}/v1/connect/livechat/start`, {
2090
2099
  method: "POST",
2091
2100
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2092
2101
  body: JSON.stringify({ displayName: K.trim(), allowedDomains: h.length ? h : void 0 })
2093
- }), P = await B.json();
2094
- if (!B.ok || !P.connectionId || !P.embedScript) throw new Error(P.message ?? "Không thể tạo widget");
2095
- ne(""), w(""), await D(), S({
2102
+ }), F = await H.json();
2103
+ if (!H.ok || !F.connectionId || !F.embedScript) throw new Error(F.message ?? "Không thể tạo widget");
2104
+ ee(""), S(""), await N(), x({
2096
2105
  name: "livechat-result",
2097
- connectionId: P.connectionId,
2098
- embedScript: P.embedScript,
2099
- identitySecret: P.identitySecret ?? "",
2100
- allowedDomains: P.allowedDomains ?? []
2106
+ connectionId: F.connectionId,
2107
+ embedScript: F.embedScript,
2108
+ identitySecret: F.identitySecret ?? "",
2109
+ allowedDomains: F.allowedDomains ?? []
2101
2110
  });
2102
2111
  } catch (h) {
2103
2112
  I(h instanceof Error ? h.message : "Lỗi tạo widget");
2104
2113
  } finally {
2105
- R(!1);
2114
+ W(!1);
2106
2115
  }
2107
2116
  }
2108
- async function N(h) {
2117
+ async function q(h) {
2109
2118
  I(null);
2110
2119
  try {
2111
- const B = `${o}/static/oauth-popup.html`, P = await fetch(`${o}/v1/connect/${h}/start`, {
2120
+ const H = `${o}/static/oauth-popup.html`, F = await fetch(`${o}/v1/connect/${h}/start`, {
2112
2121
  method: "POST",
2113
2122
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2114
- body: JSON.stringify({ callbackUrl: B })
2115
- }), q = await P.json();
2116
- if (!P.ok || !q.authorizationUrl) throw new Error(q.message ?? "Không thể bắt đầu kết nối");
2117
- const ie = window.open(q.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
2118
- S({ name: "oauth-waiting", provider: h, popup: ie }), z.current && window.removeEventListener("message", z.current);
2119
- const re = (V) => {
2120
- if (V.data) {
2121
- if (V.data.type === "channelhub:oauth-select") {
2122
- S({
2123
+ body: JSON.stringify({ callbackUrl: H })
2124
+ }), X = await F.json();
2125
+ if (!F.ok || !X.authorizationUrl) throw new Error(X.message ?? "Không thể bắt đầu kết nối");
2126
+ const re = window.open(X.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
2127
+ x({ name: "oauth-waiting", provider: h, popup: re }), B.current && window.removeEventListener("message", B.current);
2128
+ const oe = (Y) => {
2129
+ if (Y.data) {
2130
+ if (Y.data.type === "channelhub:oauth-select") {
2131
+ x({
2123
2132
  name: "oauth-select",
2124
- provider: V.data.provider,
2125
- sessionId: String(V.data.sessionId ?? ""),
2126
- pages: V.data.pages ?? [],
2127
- popup: ie
2133
+ provider: Y.data.provider,
2134
+ sessionId: String(Y.data.sessionId ?? ""),
2135
+ pages: Y.data.pages ?? [],
2136
+ popup: re
2128
2137
  });
2129
2138
  return;
2130
2139
  }
2131
- V.data.type === "channelhub:oauth" && (window.removeEventListener("message", re), z.current = null, V.data.status === "active" ? (D(), S({ name: "list" })) : (I("Kết nối thất bại: " + String(V.data.error ?? "Không xác định")), S({ name: "list" })));
2140
+ Y.data.type === "channelhub:oauth" && (window.removeEventListener("message", oe), B.current = null, Y.data.status === "active" ? (N(), x({ name: "list" })) : (I("Kết nối thất bại: " + String(Y.data.error ?? "Không xác định")), x({ name: "list" })));
2132
2141
  }
2133
2142
  };
2134
- z.current = re, window.addEventListener("message", re);
2135
- } catch (B) {
2136
- I(B instanceof Error ? B.message : "Lỗi kết nối"), S({ name: "list" });
2143
+ B.current = oe, window.addEventListener("message", oe);
2144
+ } catch (H) {
2145
+ I(H instanceof Error ? H.message : "Lỗi kết nối"), x({ name: "list" });
2137
2146
  }
2138
2147
  }
2139
- function x(h, B) {
2148
+ function w(h, H) {
2140
2149
  navigator.clipboard.writeText(h).then(() => {
2141
- B === "script" ? (k(!0), setTimeout(() => k(!1), 2e3)) : (se(!0), setTimeout(() => se(!1), 2e3));
2150
+ H === "script" ? (b(!0), setTimeout(() => b(!1), 2e3)) : (ie(!0), setTimeout(() => ie(!1), 2e3));
2142
2151
  });
2143
2152
  }
2144
- function J() {
2153
+ function _() {
2145
2154
  const h = f.name === "oauth-waiting" || f.name === "oauth-select" ? f.popup : null;
2146
2155
  if (h)
2147
2156
  try {
2148
2157
  h.close();
2149
2158
  } catch {
2150
2159
  }
2151
- z.current && (window.removeEventListener("message", z.current), z.current = null), S({ name: "add" });
2160
+ B.current && (window.removeEventListener("message", B.current), B.current = null), x({ name: "add" });
2152
2161
  }
2153
2162
  async function he(h) {
2154
2163
  if (f.name !== "oauth-select") return;
2155
- const { provider: B, sessionId: P, popup: q } = f;
2156
- R(!0), I(null);
2157
- const ie = {
2164
+ const { provider: H, sessionId: F, popup: X } = f;
2165
+ W(!0), I(null);
2166
+ const re = {
2158
2167
  facebook: `${o}/v1/connect/facebook/select-page`,
2159
2168
  instagram: `${o}/v1/connect/instagram/select-account`,
2160
2169
  zalo: `${o}/v1/connect/zalo/select-oa`
2161
- }, re = {
2170
+ }, oe = {
2162
2171
  facebook: "pageId",
2163
2172
  instagram: "accountId",
2164
2173
  zalo: "oaId"
2165
2174
  };
2166
2175
  try {
2167
- const V = await fetch(ie[B] ?? `${o}/v1/connect/${B}/select-page`, {
2176
+ const Y = await fetch(re[H] ?? `${o}/v1/connect/${H}/select-page`, {
2168
2177
  method: "POST",
2169
2178
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2170
- body: JSON.stringify({ sessionId: P, [re[B] ?? "pageId"]: h })
2171
- }), ye = await V.json();
2172
- if (!V.ok || !ye.connectionId) throw new Error(ye.message ?? "Không thể kết nối");
2173
- if (q)
2179
+ body: JSON.stringify({ sessionId: F, [oe[H] ?? "pageId"]: h })
2180
+ }), ye = await Y.json();
2181
+ if (!Y.ok || !ye.connectionId) throw new Error(ye.message ?? "Không thể kết nối");
2182
+ if (X)
2174
2183
  try {
2175
- q.postMessage({ type: "channelhub:close-popup" }, "*");
2184
+ X.postMessage({ type: "channelhub:close-popup" }, "*");
2176
2185
  } catch {
2177
2186
  }
2178
- z.current && (window.removeEventListener("message", z.current), z.current = null), await D(), S({ name: "list" });
2179
- } catch (V) {
2180
- I(V instanceof Error ? V.message : "Lỗi kết nối");
2187
+ B.current && (window.removeEventListener("message", B.current), B.current = null), await N(), x({ name: "list" });
2188
+ } catch (Y) {
2189
+ I(Y instanceof Error ? Y.message : "Lỗi kết nối");
2181
2190
  } finally {
2182
- R(!1);
2191
+ W(!1);
2183
2192
  }
2184
2193
  }
2185
2194
  return /* @__PURE__ */ n("div", { style: a.root, children: [
2186
- W && /* @__PURE__ */ e("div", { style: a.errorBanner, children: W }),
2187
- f.name === "list" && /* @__PURE__ */ n(te, { children: [
2195
+ R && /* @__PURE__ */ e("div", { style: a.errorBanner, children: R }),
2196
+ f.name === "list" && /* @__PURE__ */ n(ne, { children: [
2188
2197
  /* @__PURE__ */ n("div", { style: a.header, children: [
2189
2198
  /* @__PURE__ */ e("div", { style: a.headerLeft, children: /* @__PURE__ */ n("div", { children: [
2190
2199
  /* @__PURE__ */ e("div", { style: a.title, children: "Kênh kết nối" }),
2191
- /* @__PURE__ */ e("div", { style: a.subtitle, children: m ? "Đang tải…" : `${s.filter((h) => h.status === "active").length} kênh đang hoạt động` })
2200
+ /* @__PURE__ */ e("div", { style: a.subtitle, children: g ? "Đang tải…" : `${s.filter((h) => h.status === "active").length} kênh đang hoạt động` })
2192
2201
  ] }) }),
2193
- /* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => S({ name: "add" }), children: [
2194
- /* @__PURE__ */ e(Ze, {}),
2202
+ /* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => x({ name: "add" }), children: [
2203
+ /* @__PURE__ */ e(et, {}),
2195
2204
  /* @__PURE__ */ e("span", { children: "Thêm kênh" })
2196
2205
  ] })
2197
2206
  ] }),
2198
2207
  /* @__PURE__ */ e("div", { style: a.divider }),
2199
- /* @__PURE__ */ e("div", { style: a.body, children: !m && s.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
2208
+ /* @__PURE__ */ e("div", { style: a.body, children: !g && s.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
2200
2209
  /* @__PURE__ */ e("div", { style: { width: 64, height: 64, borderRadius: 16, background: "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 40 }) }),
2201
2210
  /* @__PURE__ */ e("div", { style: a.emptyTitle, children: "Chưa có kênh nào được kết nối" }),
2202
2211
  /* @__PURE__ */ e("div", { style: a.emptyDesc, children: "Kết nối Facebook, Zalo OA, Telegram hoặc Live Chat để bắt đầu nhận tin nhắn từ khách hàng." }),
2203
- /* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => S({ name: "add" }), children: [
2204
- /* @__PURE__ */ e(Ze, {}),
2212
+ /* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => x({ name: "add" }), children: [
2213
+ /* @__PURE__ */ e(et, {}),
2205
2214
  "Kết nối kênh đầu tiên"
2206
2215
  ] })
2207
2216
  ] }) : /* @__PURE__ */ e("div", { children: s.map((h) => /* @__PURE__ */ e(
2208
- an,
2217
+ ln,
2209
2218
  {
2210
2219
  conn: h,
2211
2220
  apiUrl: o,
2212
- onDisconnect: () => void le(h.id, Ve(h))
2221
+ onDisconnect: () => void de(h.id, Ge(h))
2213
2222
  },
2214
2223
  h.id
2215
2224
  )) }) })
2216
2225
  ] }),
2217
- f.name === "add" && /* @__PURE__ */ n(te, { children: [
2226
+ f.name === "add" && /* @__PURE__ */ n(ne, { children: [
2218
2227
  /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2219
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2228
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => x({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2220
2229
  /* @__PURE__ */ n("div", { children: [
2221
2230
  /* @__PURE__ */ e("div", { style: a.title, children: "Thêm kênh mới" }),
2222
2231
  /* @__PURE__ */ e("div", { style: a.subtitle, children: "Chọn nền tảng bạn muốn kết nối" })
2223
2232
  ] })
2224
2233
  ] }) }),
2225
2234
  /* @__PURE__ */ e("div", { style: a.divider }),
2226
- /* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: ln.map((h) => /* @__PURE__ */ e(
2227
- dn,
2235
+ /* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: dn.map((h) => /* @__PURE__ */ e(
2236
+ cn,
2228
2237
  {
2229
2238
  provider: h,
2230
2239
  apiUrl: o,
2231
2240
  onClick: () => {
2232
- h.type === "oauth" ? N(h.id) : h.id === "telegram" ? S({ name: "connect-telegram" }) : S({ name: "connect-livechat" });
2241
+ h.type === "oauth" ? q(h.id) : h.id === "telegram" ? x({ name: "connect-telegram" }) : x({ name: "connect-livechat" });
2233
2242
  }
2234
2243
  },
2235
2244
  h.id
2236
2245
  )) }) })
2237
2246
  ] }),
2238
- f.name === "connect-telegram" && /* @__PURE__ */ n(te, { children: [
2247
+ f.name === "connect-telegram" && /* @__PURE__ */ n(ne, { children: [
2239
2248
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2240
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2249
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => x({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2241
2250
  /* @__PURE__ */ e(ge, { provider: "telegram", apiUrl: o, size: 44 }),
2242
2251
  /* @__PURE__ */ n("div", { children: [
2243
2252
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Kết nối Telegram Bot" }),
@@ -2246,7 +2255,7 @@ Hành động này không thể hoàn tác.`))
2246
2255
  ] }),
2247
2256
  /* @__PURE__ */ n("div", { style: a.form, children: [
2248
2257
  /* @__PURE__ */ n("div", { style: a.infoBox, children: [
2249
- /* @__PURE__ */ e(tn, {}),
2258
+ /* @__PURE__ */ e(nn, {}),
2250
2259
  /* @__PURE__ */ n("div", { children: [
2251
2260
  "Tạo bot mới bằng cách nhắn tin cho ",
2252
2261
  /* @__PURE__ */ e("strong", { children: "@BotFather" }),
@@ -2265,8 +2274,8 @@ Hành động này không thể hoàn tác.`))
2265
2274
  {
2266
2275
  style: a.input,
2267
2276
  type: "text",
2268
- value: E,
2269
- onChange: (h) => j(h.target.value),
2277
+ value: O,
2278
+ onChange: (h) => D(h.target.value),
2270
2279
  placeholder: "1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxx",
2271
2280
  autoComplete: "off",
2272
2281
  spellCheck: !1
@@ -2289,21 +2298,21 @@ Hành động này không thể hoàn tác.`))
2289
2298
  {
2290
2299
  style: a.input,
2291
2300
  type: "text",
2292
- value: A,
2293
- onChange: (h) => F(h.target.value),
2301
+ value: L,
2302
+ onChange: (h) => P(h.target.value),
2294
2303
  placeholder: "VD: Bot hỗ trợ cửa hàng"
2295
2304
  }
2296
2305
  )
2297
2306
  ] }),
2298
2307
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2299
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2300
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void v(), children: H ? "Đang kết nối…" : "Kết nối Telegram" })
2308
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => x({ name: "add" }), children: "Hủy" }),
2309
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: E, onClick: () => void C(), children: E ? "Đang kết nối…" : "Kết nối Telegram" })
2301
2310
  ] })
2302
2311
  ] })
2303
2312
  ] }),
2304
- f.name === "connect-livechat" && /* @__PURE__ */ n(te, { children: [
2313
+ f.name === "connect-livechat" && /* @__PURE__ */ n(ne, { children: [
2305
2314
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2306
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2315
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => x({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2307
2316
  /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2308
2317
  /* @__PURE__ */ n("div", { children: [
2309
2318
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Tạo Live Chat Widget" }),
@@ -2322,7 +2331,7 @@ Hành động này không thể hoàn tác.`))
2322
2331
  style: a.input,
2323
2332
  type: "text",
2324
2333
  value: K,
2325
- onChange: (h) => ne(h.target.value),
2334
+ onChange: (h) => ee(h.target.value),
2326
2335
  placeholder: "VD: Hỗ trợ website hanashop.vn"
2327
2336
  }
2328
2337
  )
@@ -2337,7 +2346,7 @@ Hành động này không thể hoàn tác.`))
2337
2346
  {
2338
2347
  style: { ...a.input, resize: "vertical", minHeight: 80, lineHeight: 1.5 },
2339
2348
  value: U,
2340
- onChange: (h) => w(h.target.value),
2349
+ onChange: (h) => S(h.target.value),
2341
2350
  placeholder: `https://myshop.com
2342
2351
  https://www.myshop.com`,
2343
2352
  spellCheck: !1
@@ -2346,14 +2355,14 @@ https://www.myshop.com`,
2346
2355
  /* @__PURE__ */ e("div", { style: a.inputHint, children: "Mỗi domain một dòng. Để trống để cho phép tất cả." })
2347
2356
  ] }),
2348
2357
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2349
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2350
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void Q(), children: H ? "Đang tạo…" : "Tạo widget" })
2358
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => x({ name: "add" }), children: "Hủy" }),
2359
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: E, onClick: () => void te(), children: E ? "Đang tạo…" : "Tạo widget" })
2351
2360
  ] })
2352
2361
  ] })
2353
2362
  ] }),
2354
- f.name === "livechat-result" && /* @__PURE__ */ n(te, { children: [
2363
+ f.name === "livechat-result" && /* @__PURE__ */ n(ne, { children: [
2355
2364
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2356
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2365
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => x({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2357
2366
  /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2358
2367
  /* @__PURE__ */ n("div", { children: [
2359
2368
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Widget đã được tạo!" }),
@@ -2374,11 +2383,11 @@ https://www.myshop.com`,
2374
2383
  /* @__PURE__ */ e("div", { style: a.codeLabel, children: "Mã nhúng" }),
2375
2384
  /* @__PURE__ */ n("div", { style: a.codeBlock, children: [
2376
2385
  /* @__PURE__ */ e("pre", { style: a.codePre, children: f.embedScript }),
2377
- /* @__PURE__ */ e("button", { style: { ...a.copyBtn, ..._ ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => x(f.embedScript, "script"), children: _ ? /* @__PURE__ */ n(te, { children: [
2378
- /* @__PURE__ */ e(et, {}),
2386
+ /* @__PURE__ */ e("button", { style: { ...a.copyBtn, ...z ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => w(f.embedScript, "script"), children: z ? /* @__PURE__ */ n(ne, { children: [
2387
+ /* @__PURE__ */ e(nt, {}),
2379
2388
  " Đã sao chép"
2380
- ] }) : /* @__PURE__ */ n(te, { children: [
2381
- /* @__PURE__ */ e(Qe, {}),
2389
+ ] }) : /* @__PURE__ */ n(ne, { children: [
2390
+ /* @__PURE__ */ e(tt, {}),
2382
2391
  " Sao chép"
2383
2392
  ] }) })
2384
2393
  ] })
@@ -2389,29 +2398,29 @@ https://www.myshop.com`,
2389
2398
  /* @__PURE__ */ e("span", { style: { ...a.labelHint, color: "#dc2626", fontWeight: 600 }, children: "Lưu ngay — chỉ hiển thị một lần" })
2390
2399
  ] }),
2391
2400
  /* @__PURE__ */ n("div", { style: a.secretRow, children: [
2392
- /* @__PURE__ */ e(en, {}),
2401
+ /* @__PURE__ */ e(tn, {}),
2393
2402
  /* @__PURE__ */ e("span", { style: a.secretLabel, children: "Secret:" }),
2394
2403
  /* @__PURE__ */ e("span", { style: a.secretValue, children: f.identitySecret }),
2395
2404
  /* @__PURE__ */ e(
2396
2405
  "button",
2397
2406
  {
2398
- onClick: () => x(f.identitySecret, "secret"),
2399
- style: { border: "none", background: "transparent", cursor: "pointer", color: L ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2400
- children: L ? /* @__PURE__ */ e(et, {}) : /* @__PURE__ */ e(Qe, {})
2407
+ onClick: () => w(f.identitySecret, "secret"),
2408
+ style: { border: "none", background: "transparent", cursor: "pointer", color: T ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2409
+ children: T ? /* @__PURE__ */ e(nt, {}) : /* @__PURE__ */ e(tt, {})
2401
2410
  }
2402
2411
  )
2403
2412
  ] }),
2404
2413
  /* @__PURE__ */ e("div", { style: { ...a.inputHint, marginTop: 6 }, children: "Dùng secret này để xác thực danh tính người dùng (HMAC). Giữ bí mật — không chia sẻ nơi công khai." })
2405
2414
  ] }),
2406
2415
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2407
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "list" }), children: "Về danh sách" }),
2408
- /* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => S({ name: "add" }), children: "Thêm kênh khác" })
2416
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => x({ name: "list" }), children: "Về danh sách" }),
2417
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => x({ name: "add" }), children: "Thêm kênh khác" })
2409
2418
  ] })
2410
2419
  ] })
2411
2420
  ] }),
2412
- f.name === "oauth-waiting" && /* @__PURE__ */ n(te, { children: [
2421
+ f.name === "oauth-waiting" && /* @__PURE__ */ n(ne, { children: [
2413
2422
  /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2414
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2423
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: _, children: /* @__PURE__ */ e(ve, {}) }),
2415
2424
  /* @__PURE__ */ n("div", { children: [
2416
2425
  /* @__PURE__ */ n("div", { style: a.title, children: [
2417
2426
  "Đang xác thực ",
@@ -2422,7 +2431,7 @@ https://www.myshop.com`,
2422
2431
  ] }) }),
2423
2432
  /* @__PURE__ */ n("div", { style: a.oauthWaiting, children: [
2424
2433
  /* @__PURE__ */ n("div", { style: { position: "relative", width: 72, height: 72 }, children: [
2425
- /* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: Zt[f.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 48 }) }),
2434
+ /* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: Qt[f.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 48 }) }),
2426
2435
  /* @__PURE__ */ n(
2427
2436
  "svg",
2428
2437
  {
@@ -2455,16 +2464,16 @@ https://www.myshop.com`,
2455
2464
  ] }),
2456
2465
  /* @__PURE__ */ e("div", { style: a.oauthDesc, children: "Một cửa sổ đăng nhập đã được mở. Vui lòng đăng nhập và cấp quyền truy cập để hoàn tất kết nối." }),
2457
2466
  /* @__PURE__ */ n("div", { style: { display: "flex", flexDirection: "column", gap: 8, alignItems: "flex-start", width: "100%", maxWidth: 280 }, children: [
2458
- /* @__PURE__ */ e(De, { done: !0, label: `Đã mở cửa sổ ${Be[f.provider]}` }),
2459
- /* @__PURE__ */ e(De, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2460
- /* @__PURE__ */ e(De, { label: "Lưu kết nối & quay về" })
2467
+ /* @__PURE__ */ e(Ue, { done: !0, label: `Đã mở cửa sổ ${Be[f.provider]}` }),
2468
+ /* @__PURE__ */ e(Ue, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2469
+ /* @__PURE__ */ e(Ue, { label: "Lưu kết nối & quay về" })
2461
2470
  ] }),
2462
- /* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: J, children: "Hủy và quay lại" })
2471
+ /* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: _, children: "Hủy và quay lại" })
2463
2472
  ] })
2464
2473
  ] }),
2465
- f.name === "oauth-select" && /* @__PURE__ */ n(te, { children: [
2474
+ f.name === "oauth-select" && /* @__PURE__ */ n(ne, { children: [
2466
2475
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2467
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2476
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: _, children: /* @__PURE__ */ e(ve, {}) }),
2468
2477
  /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 44 }),
2469
2478
  /* @__PURE__ */ n("div", { children: [
2470
2479
  /* @__PURE__ */ n("div", { style: a.connectTitle, children: [
@@ -2481,7 +2490,7 @@ https://www.myshop.com`,
2481
2490
  /* @__PURE__ */ e("div", { style: a.body, children: f.pages.length === 0 ? /* @__PURE__ */ e("div", { style: { textAlign: "center", color: "#94a3b8", fontSize: 13, padding: "24px 0" }, children: "Không tìm thấy trang/tài khoản nào. Hãy thử lại." }) : /* @__PURE__ */ e("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: f.pages.map((h) => /* @__PURE__ */ n(
2482
2491
  "button",
2483
2492
  {
2484
- disabled: H,
2493
+ disabled: E,
2485
2494
  onClick: () => void he(h.id),
2486
2495
  style: {
2487
2496
  display: "flex",
@@ -2491,8 +2500,8 @@ https://www.myshop.com`,
2491
2500
  borderRadius: 12,
2492
2501
  border: "1.5px solid #e2e8f0",
2493
2502
  background: "#fff",
2494
- cursor: H ? "not-allowed" : "pointer",
2495
- opacity: H ? 0.6 : 1,
2503
+ cursor: E ? "not-allowed" : "pointer",
2504
+ opacity: E ? 0.6 : 1,
2496
2505
  textAlign: "left",
2497
2506
  fontFamily: "inherit",
2498
2507
  transition: "border-color .15s, background .15s"
@@ -2502,7 +2511,7 @@ https://www.myshop.com`,
2502
2511
  /* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: h.name }),
2503
2512
  /* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: h.id })
2504
2513
  ] }),
2505
- /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: H ? "Đang kết nối…" : "Chọn →" })
2514
+ /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: E ? "Đang kết nối…" : "Chọn →" })
2506
2515
  ]
2507
2516
  },
2508
2517
  h.id
@@ -2510,7 +2519,7 @@ https://www.myshop.com`,
2510
2519
  ] })
2511
2520
  ] });
2512
2521
  }
2513
- function rn(t) {
2522
+ function on(t) {
2514
2523
  const i = t.metadata;
2515
2524
  if (typeof i.pictureUrl == "string") return i.pictureUrl;
2516
2525
  if (t.provider === "facebook")
@@ -2521,26 +2530,26 @@ function rn(t) {
2521
2530
  }
2522
2531
  return null;
2523
2532
  }
2524
- function on({ conn: t, apiUrl: i, size: r = 40 }) {
2525
- const [o, s] = y(!1), C = rn(t), m = Math.round(r * 0.28);
2526
- return C && !o ? /* @__PURE__ */ e(
2533
+ function an({ conn: t, apiUrl: i, size: r = 40 }) {
2534
+ const [o, s] = y(!1), k = on(t), g = Math.round(r * 0.28);
2535
+ return k && !o ? /* @__PURE__ */ e(
2527
2536
  "img",
2528
2537
  {
2529
- src: C,
2530
- alt: Ve(t),
2538
+ src: k,
2539
+ alt: Ge(t),
2531
2540
  referrerPolicy: "no-referrer",
2532
2541
  onError: () => s(!0),
2533
- style: { width: r, height: r, borderRadius: m, objectFit: "cover", flexShrink: 0, display: "block" }
2542
+ style: { width: r, height: r, borderRadius: g, objectFit: "cover", flexShrink: 0, display: "block" }
2534
2543
  }
2535
2544
  ) : /* @__PURE__ */ e(ge, { provider: t.provider, apiUrl: i, size: r });
2536
2545
  }
2537
- function an({ conn: t, apiUrl: i, onDisconnect: r }) {
2546
+ function ln({ conn: t, apiUrl: i, onDisconnect: r }) {
2538
2547
  const [o, s] = y(!1);
2539
2548
  return /* @__PURE__ */ n("div", { style: a.channelItem, children: [
2540
- /* @__PURE__ */ e(on, { conn: t, apiUrl: i, size: 40 }),
2549
+ /* @__PURE__ */ e(an, { conn: t, apiUrl: i, size: 40 }),
2541
2550
  /* @__PURE__ */ n("div", { style: a.channelInfo, children: [
2542
- /* @__PURE__ */ e("div", { style: a.channelName, children: Ve(t) }),
2543
- /* @__PURE__ */ e("div", { style: a.channelMeta, children: Qt(t) })
2551
+ /* @__PURE__ */ e("div", { style: a.channelName, children: Ge(t) }),
2552
+ /* @__PURE__ */ e("div", { style: a.channelMeta, children: en(t) })
2544
2553
  ] }),
2545
2554
  /* @__PURE__ */ n("div", { style: a.channelActions, children: [
2546
2555
  /* @__PURE__ */ e("span", { style: t.status === "active" ? a.badgeActive : a.badgeInactive, children: t.status === "active" ? "Hoạt động" : t.status }),
@@ -2560,14 +2569,14 @@ function an({ conn: t, apiUrl: i, onDisconnect: r }) {
2560
2569
  ] })
2561
2570
  ] });
2562
2571
  }
2563
- const ln = [
2572
+ const dn = [
2564
2573
  { id: "facebook", name: "Facebook", desc: "Fanpage & Messenger", type: "oauth" },
2565
2574
  { id: "zalo", name: "Zalo OA", desc: "Official Account", type: "oauth" },
2566
2575
  { id: "instagram", name: "Instagram", desc: "DM & Comments", type: "oauth" },
2567
2576
  { id: "telegram", name: "Telegram", desc: "Bot token", type: "token" },
2568
2577
  { id: "livechat", name: "Live Chat", desc: "Website widget", type: "livechat" }
2569
2578
  ];
2570
- function dn({ provider: t, apiUrl: i, onClick: r }) {
2579
+ function cn({ provider: t, apiUrl: i, onClick: r }) {
2571
2580
  const [o, s] = y(!1);
2572
2581
  return /* @__PURE__ */ n(
2573
2582
  "div",
@@ -2589,7 +2598,7 @@ function dn({ provider: t, apiUrl: i, onClick: r }) {
2589
2598
  }
2590
2599
  );
2591
2600
  }
2592
- function De({ done: t, active: i, label: r }) {
2601
+ function Ue({ done: t, active: i, label: r }) {
2593
2602
  return /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 10, fontSize: 13, color: t ? "#059669" : i ? "#0f172a" : "#94a3b8" }, children: [
2594
2603
  /* @__PURE__ */ e("div", { style: {
2595
2604
  width: 10,
@@ -2602,9 +2611,264 @@ function De({ done: t, active: i, label: r }) {
2602
2611
  r
2603
2612
  ] });
2604
2613
  }
2605
- console.log("[ChannelHub] widget v0.1.7 loaded");
2614
+ function sn(t) {
2615
+ return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
2616
+ }
2617
+ function hn(t) {
2618
+ if (!t) return "";
2619
+ const i = new Date(t);
2620
+ return i.toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? i.toLocaleTimeString("vi-VN", { hour: "2-digit", minute: "2-digit" }) : i.toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit" });
2621
+ }
2622
+ function mn({
2623
+ apiUrl: t,
2624
+ token: i,
2625
+ theme: r,
2626
+ locale: o = "vi",
2627
+ icon: s,
2628
+ onConversationSelect: k
2629
+ }) {
2630
+ const g = (r == null ? void 0 : r.primaryColor) ?? "#2563eb", $ = typeof s == "function" ? s({ size: 20, color: "currentColor" }) : s ?? /* @__PURE__ */ e(Ye, { size: 20, strokeWidth: 1.8 }), f = Z(new st(t, i)), [x, R] = y(!1), [I, E] = y([]), W = Z(null), O = Z(null), D = I.filter((z) => (z.unreadCount ?? 0) > 0), L = D.reduce((z, b) => z + (b.unreadCount ?? 0), 0), P = ke(async () => {
2631
+ try {
2632
+ const z = await f.current.listConversations();
2633
+ E(z.items);
2634
+ } catch {
2635
+ }
2636
+ }, []);
2637
+ V(() => (P(), f.current.connectSSE((b) => {
2638
+ (b === "message.new" || b === "conversation.updated") && P();
2639
+ })), [P]), V(() => {
2640
+ if (!x) return;
2641
+ const z = (b) => {
2642
+ var T, ie;
2643
+ (T = W.current) != null && T.contains(b.target) || (ie = O.current) != null && ie.contains(b.target) || R(!1);
2644
+ };
2645
+ return document.addEventListener("mousedown", z), () => document.removeEventListener("mousedown", z);
2646
+ }, [x]);
2647
+ const K = async (z) => {
2648
+ if (R(!1), k == null || k(z.id, z), (z.unreadCount ?? 0) > 0)
2649
+ try {
2650
+ await f.current.markRead(z.id), E(
2651
+ (b) => b.map((T) => T.id === z.id ? { ...T, unreadCount: 0 } : T)
2652
+ );
2653
+ } catch {
2654
+ }
2655
+ }, ee = o === "en" ? `${L} unread message${L !== 1 ? "s" : ""}` : `${L} tin nhắn chưa đọc`, U = o === "en" ? "No unread messages" : "Không có tin nhắn mới", S = o === "en" ? "Messages" : "Tin nhắn";
2656
+ return /* @__PURE__ */ n("div", { style: { position: "relative", display: "inline-block", fontFamily: (r == null ? void 0 : r.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif" }, children: [
2657
+ /* @__PURE__ */ n(
2658
+ "button",
2659
+ {
2660
+ ref: W,
2661
+ "aria-label": ee,
2662
+ "aria-haspopup": "true",
2663
+ "aria-expanded": x,
2664
+ onClick: () => R((z) => !z),
2665
+ style: {
2666
+ position: "relative",
2667
+ display: "inline-grid",
2668
+ placeItems: "center",
2669
+ width: 40,
2670
+ height: 40,
2671
+ border: 0,
2672
+ borderRadius: "50%",
2673
+ background: x ? `${g}18` : "transparent",
2674
+ color: x ? g : "#6b7280",
2675
+ cursor: "pointer",
2676
+ transition: "background 150ms ease, color 150ms ease"
2677
+ },
2678
+ children: [
2679
+ $,
2680
+ L > 0 && /* @__PURE__ */ e(
2681
+ "span",
2682
+ {
2683
+ "aria-hidden": "true",
2684
+ style: {
2685
+ position: "absolute",
2686
+ top: 4,
2687
+ right: 4,
2688
+ minWidth: 16,
2689
+ height: 16,
2690
+ borderRadius: 999,
2691
+ background: "#ef4444",
2692
+ color: "#fff",
2693
+ fontSize: 10,
2694
+ fontWeight: 800,
2695
+ lineHeight: "16px",
2696
+ textAlign: "center",
2697
+ padding: "0 4px",
2698
+ border: "2px solid #fff",
2699
+ boxSizing: "border-box"
2700
+ },
2701
+ children: L > 99 ? "99+" : L
2702
+ }
2703
+ )
2704
+ ]
2705
+ }
2706
+ ),
2707
+ x && /* @__PURE__ */ n(
2708
+ "div",
2709
+ {
2710
+ ref: O,
2711
+ role: "dialog",
2712
+ "aria-label": S,
2713
+ style: {
2714
+ position: "absolute",
2715
+ top: "calc(100% + 8px)",
2716
+ right: 0,
2717
+ zIndex: 9999,
2718
+ width: 360,
2719
+ maxHeight: 480,
2720
+ background: "#fff",
2721
+ border: "1px solid #e7ebf2",
2722
+ borderRadius: 14,
2723
+ boxShadow: "0 12px 40px rgba(23,32,51,.14)",
2724
+ overflow: "hidden",
2725
+ display: "flex",
2726
+ flexDirection: "column"
2727
+ },
2728
+ children: [
2729
+ /* @__PURE__ */ n("div", { style: {
2730
+ display: "flex",
2731
+ alignItems: "center",
2732
+ justifyContent: "space-between",
2733
+ padding: "14px 16px 10px",
2734
+ borderBottom: "1px solid #e7ebf2"
2735
+ }, children: [
2736
+ /* @__PURE__ */ e("span", { style: { fontSize: 16, fontWeight: 700, color: "#172033" }, children: S }),
2737
+ L > 0 && /* @__PURE__ */ n("span", { style: {
2738
+ fontSize: 11,
2739
+ fontWeight: 600,
2740
+ background: `${g}14`,
2741
+ color: g,
2742
+ borderRadius: 999,
2743
+ padding: "2px 8px"
2744
+ }, children: [
2745
+ L,
2746
+ " ",
2747
+ o === "en" ? "unread" : "chưa đọc"
2748
+ ] })
2749
+ ] }),
2750
+ /* @__PURE__ */ e("div", { style: { overflowY: "auto", flex: 1 }, children: D.length === 0 ? /* @__PURE__ */ n("div", { style: {
2751
+ display: "flex",
2752
+ flexDirection: "column",
2753
+ alignItems: "center",
2754
+ gap: 8,
2755
+ padding: "40px 24px",
2756
+ color: "#9aa5b5"
2757
+ }, children: [
2758
+ /* @__PURE__ */ e(Ye, { size: 28, strokeWidth: 1.5 }),
2759
+ /* @__PURE__ */ e("span", { style: { fontSize: 13 }, children: U })
2760
+ ] }) : D.map((z) => /* @__PURE__ */ e(
2761
+ pn,
2762
+ {
2763
+ conversation: z,
2764
+ primary: g,
2765
+ apiUrl: t,
2766
+ onSelect: K
2767
+ },
2768
+ z.id
2769
+ )) })
2770
+ ]
2771
+ }
2772
+ )
2773
+ ] });
2774
+ }
2775
+ function pn({
2776
+ conversation: t,
2777
+ primary: i,
2778
+ apiUrl: r,
2779
+ onSelect: o
2780
+ }) {
2781
+ const [s, k] = y(!1), g = t.contactName ?? t.providerConversationKey, $ = t.unreadCount ?? 0;
2782
+ return /* @__PURE__ */ n(
2783
+ "button",
2784
+ {
2785
+ onClick: () => o(t),
2786
+ onMouseEnter: () => k(!0),
2787
+ onMouseLeave: () => k(!1),
2788
+ style: {
2789
+ display: "flex",
2790
+ width: "100%",
2791
+ gap: 12,
2792
+ padding: "10px 16px",
2793
+ border: 0,
2794
+ borderBottom: "1px solid #f1f5f9",
2795
+ background: s ? "#f7f9fc" : $ > 0 ? "#f0f4ff" : "#fff",
2796
+ textAlign: "left",
2797
+ cursor: "pointer",
2798
+ transition: "background 100ms ease",
2799
+ alignItems: "center"
2800
+ },
2801
+ children: [
2802
+ /* @__PURE__ */ n("span", { style: { position: "relative", flex: "0 0 auto", width: 42, height: 42 }, children: [
2803
+ /* @__PURE__ */ e(
2804
+ qe,
2805
+ {
2806
+ src: t.contactPictureUrl,
2807
+ fallback: sn(g),
2808
+ style: {
2809
+ width: 42,
2810
+ height: 42,
2811
+ borderRadius: "50%",
2812
+ objectFit: "cover",
2813
+ display: "grid",
2814
+ placeItems: "center",
2815
+ fontSize: 13,
2816
+ fontWeight: 800,
2817
+ background: `${i}18`,
2818
+ color: i
2819
+ }
2820
+ }
2821
+ ),
2822
+ void 0
2823
+ ] }),
2824
+ /* @__PURE__ */ n("span", { style: { flex: 1, minWidth: 0 }, children: [
2825
+ /* @__PURE__ */ n("span", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 6 }, children: [
2826
+ /* @__PURE__ */ e("span", { style: {
2827
+ fontSize: 13,
2828
+ fontWeight: $ > 0 ? 700 : 500,
2829
+ color: "#172033",
2830
+ overflow: "hidden",
2831
+ textOverflow: "ellipsis",
2832
+ whiteSpace: "nowrap"
2833
+ }, children: g }),
2834
+ /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, flexShrink: 0 }, children: [
2835
+ /* @__PURE__ */ e("time", { style: { fontSize: 11, color: "#9aa5b5", whiteSpace: "nowrap" }, children: hn(t.lastMessageAt) }),
2836
+ $ > 0 && /* @__PURE__ */ e("span", { style: {
2837
+ display: "inline-grid",
2838
+ placeItems: "center",
2839
+ minWidth: 18,
2840
+ height: 18,
2841
+ borderRadius: 999,
2842
+ background: "#ef4444",
2843
+ color: "#fff",
2844
+ fontSize: 10,
2845
+ fontWeight: 800,
2846
+ padding: "0 4px"
2847
+ }, children: $ > 99 ? "99+" : $ })
2848
+ ] })
2849
+ ] }),
2850
+ /* @__PURE__ */ n("span", { style: {
2851
+ display: "block",
2852
+ marginTop: 2,
2853
+ fontSize: 12,
2854
+ color: $ > 0 ? "#374151" : "#9aa5b5",
2855
+ fontWeight: $ > 0 ? 500 : 400,
2856
+ overflow: "hidden",
2857
+ textOverflow: "ellipsis",
2858
+ whiteSpace: "nowrap"
2859
+ }, children: [
2860
+ t.lastMessageDirection === "outbound" && /* @__PURE__ */ e("span", { style: { color: "#9aa5b5" }, children: "Bạn: " }),
2861
+ t.lastMessageText || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" })
2862
+ ] })
2863
+ ] })
2864
+ ]
2865
+ }
2866
+ );
2867
+ }
2868
+ console.log("[ChannelHub] widget v0.1.8 loaded");
2606
2869
  export {
2607
- un as ChannelHubChannels,
2608
- Mt as ChannelHubClient,
2609
- pn as ChannelHubInbox
2870
+ bn as ChannelHubChannels,
2871
+ st as ChannelHubClient,
2872
+ yn as ChannelHubInbox,
2873
+ mn as ChannelHubNotificationBell
2610
2874
  };