@channelhub/widget 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { jsx as e, jsxs as n, Fragment as J } from "react/jsx-runtime";
2
- import { forwardRef as ze, createElement as je, createContext as Ze, useRef as X, useState as y, useMemo as Be, useCallback as De, useEffect as F, useImperativeHandle as pt, useContext as Ae, Component as ut } from "react";
3
- import { createPortal as Qe } from "react-dom";
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 g, 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";
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 ft = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), et = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
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();
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 gt = {
17
+ var xt = {
18
18
  xmlns: "http://www.w3.org/2000/svg",
19
19
  width: 24,
20
20
  height: 24,
@@ -31,31 +31,31 @@ var gt = {
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 yt = ze(
34
+ const vt = 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: k,
42
- iconNode: x,
43
- ...E
44
- }, g) => je(
41
+ children: C,
42
+ iconNode: m,
43
+ ...O
44
+ }, f) => Pe(
45
45
  "svg",
46
46
  {
47
- ref: g,
48
- ...gt,
47
+ ref: f,
48
+ ...xt,
49
49
  width: i,
50
50
  height: i,
51
51
  stroke: t,
52
52
  strokeWidth: o ? Number(r) * 24 / Number(i) : r,
53
- className: et("lucide", s),
54
- ...E
53
+ className: rt("lucide", s),
54
+ ...O
55
55
  },
56
56
  [
57
- ...x.map(([v, L]) => je(v, L)),
58
- ...Array.isArray(k) ? k : [k]
57
+ ...m.map(([S, B]) => Pe(S, B)),
58
+ ...Array.isArray(C) ? C : [C]
59
59
  ]
60
60
  )
61
61
  );
@@ -65,12 +65,12 @@ const yt = ze(
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 P = (t, i) => {
69
- const r = ze(
70
- ({ className: o, ...s }, k) => je(yt, {
71
- ref: k,
68
+ const X = (t, i) => {
69
+ const r = Le(
70
+ ({ className: o, ...s }, C) => Pe(vt, {
71
+ ref: C,
72
72
  iconNode: i,
73
- className: et(`lucide-${ft(t)}`, o),
73
+ className: rt(`lucide-${bt(t)}`, o),
74
74
  ...s
75
75
  })
76
76
  );
@@ -82,7 +82,7 @@ const P = (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 Fe = P("CheckCheck", [
85
+ const Ge = X("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 Fe = P("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 tt = P("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
95
+ const ot = X("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 mt = P("ChevronDown", [
102
+ const kt = X("ChevronDown", [
103
103
  ["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]
104
104
  ]);
105
105
  /**
@@ -108,7 +108,7 @@ const mt = P("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 bt = P("ChevronRight", [
111
+ const wt = X("ChevronRight", [
112
112
  ["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]
113
113
  ]);
114
114
  /**
@@ -117,7 +117,7 @@ const bt = P("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 xt = P("CircleAlert", [
120
+ const St = X("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 xt = P("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 nt = P("Ellipsis", [
131
+ const at = X("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 nt = P("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 vt = P("Image", [
142
+ const Ct = X("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 vt = P("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 kt = P("Inbox", [
153
+ const It = X("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 kt = P("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 wt = P("Info", [
169
+ const zt = X("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 wt = P("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 it = P("LoaderCircle", [
180
+ const lt = X("LoaderCircle", [
181
181
  ["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]
182
182
  ]);
183
183
  /**
@@ -186,7 +186,7 @@ const it = P("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 St = P("Paperclip", [
189
+ const Tt = X("Paperclip", [
190
190
  ["path", { d: "M13.234 20.252 21 12.3", key: "1cbrk9" }],
191
191
  [
192
192
  "path",
@@ -202,7 +202,7 @@ const St = P("Paperclip", [
202
202
  * This source code is licensed under the ISC license.
203
203
  * See the LICENSE file in the root directory of this source tree.
204
204
  */
205
- const Ct = P("Play", [
205
+ const Rt = X("Play", [
206
206
  ["polygon", { points: "6 3 20 12 6 21 6 3", key: "1oa8hb" }]
207
207
  ]);
208
208
  /**
@@ -211,7 +211,7 @@ const Ct = P("Play", [
211
211
  * This source code is licensed under the ISC license.
212
212
  * See the LICENSE file in the root directory of this source tree.
213
213
  */
214
- const Ke = P("Search", [
214
+ const Xe = X("Search", [
215
215
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
216
216
  ["path", { d: "m21 21-4.3-4.3", key: "1qie3q" }]
217
217
  ]);
@@ -221,7 +221,7 @@ const Ke = P("Search", [
221
221
  * This source code is licensed under the ISC license.
222
222
  * See the LICENSE file in the root directory of this source tree.
223
223
  */
224
- const It = P("Send", [
224
+ const Bt = X("Send", [
225
225
  [
226
226
  "path",
227
227
  {
@@ -237,7 +237,7 @@ const It = P("Send", [
237
237
  * This source code is licensed under the ISC license.
238
238
  * See the LICENSE file in the root directory of this source tree.
239
239
  */
240
- const zt = P("SlidersHorizontal", [
240
+ const Wt = X("SlidersHorizontal", [
241
241
  ["line", { x1: "21", x2: "14", y1: "4", y2: "4", key: "obuewd" }],
242
242
  ["line", { x1: "10", x2: "3", y1: "4", y2: "4", key: "1q6298" }],
243
243
  ["line", { x1: "21", x2: "12", y1: "12", y2: "12", key: "1iu8h1" }],
@@ -254,7 +254,7 @@ const zt = P("SlidersHorizontal", [
254
254
  * This source code is licensed under the ISC license.
255
255
  * See the LICENSE file in the root directory of this source tree.
256
256
  */
257
- const Tt = P("Smile", [
257
+ const $t = X("Smile", [
258
258
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
259
259
  ["path", { d: "M8 14s1.5 2 4 2 4-2 4-2", key: "1y1vjs" }],
260
260
  ["line", { x1: "9", x2: "9.01", y1: "9", y2: "9", key: "yxxnd0" }],
@@ -266,7 +266,7 @@ const Tt = P("Smile", [
266
266
  * This source code is licensed under the ISC license.
267
267
  * See the LICENSE file in the root directory of this source tree.
268
268
  */
269
- const We = P("X", [
269
+ const je = X("X", [
270
270
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
271
271
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
272
272
  ]);
@@ -276,7 +276,7 @@ const We = P("X", [
276
276
  * This source code is licensed under the ISC license.
277
277
  * See the LICENSE file in the root directory of this source tree.
278
278
  */
279
- const Rt = P("Zap", [
279
+ const Lt = X("Zap", [
280
280
  [
281
281
  "path",
282
282
  {
@@ -285,7 +285,7 @@ const Rt = P("Zap", [
285
285
  }
286
286
  ]
287
287
  ]);
288
- class Bt {
288
+ class Mt {
289
289
  constructor(i, r) {
290
290
  this.apiUrl = i, this.token = r;
291
291
  }
@@ -294,12 +294,12 @@ class Bt {
294
294
  authorization: `Bearer ${this.token}`,
295
295
  ...o ? {} : { "content-type": "application/json" },
296
296
  ...r == null ? void 0 : r.headers
297
- }, k = await fetch(`${this.apiUrl}${i}`, {
297
+ }, C = await fetch(`${this.apiUrl}${i}`, {
298
298
  ...r,
299
299
  headers: s
300
- }), x = await k.json().catch(() => null);
301
- if (!k.ok) throw new Error((x == null ? void 0 : x.message) ?? `Request failed (${k.status})`);
302
- return x;
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;
303
303
  }
304
304
  listConnections() {
305
305
  return this.request("/v1/connections");
@@ -356,38 +356,38 @@ class Bt {
356
356
  }
357
357
  connectSSE(i) {
358
358
  const r = `${this.apiUrl}/v1/events?token=${encodeURIComponent(this.token)}`;
359
- let o, s, k = !1;
360
- const x = () => {
361
- o = new EventSource(r), o.addEventListener("message.new", (E) => {
362
- i("message.new", JSON.parse(E.data));
363
- }), o.addEventListener("conversation.updated", (E) => {
364
- i("conversation.updated", JSON.parse(E.data));
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));
365
365
  }), o.onerror = () => {
366
- o.close(), k || (s = setTimeout(x, 5e3));
366
+ o.close(), C || (s = setTimeout(m, 5e3));
367
367
  };
368
368
  };
369
- return x(), () => {
370
- k = !0, clearTimeout(s), o == null || o.close();
369
+ return m(), () => {
370
+ C = !0, clearTimeout(s), o == null || o.close();
371
371
  };
372
372
  }
373
373
  }
374
- function rt({ src: t, alt: i = "", fallback: r, style: o }) {
374
+ function dt({ src: t, alt: i = "", fallback: r, style: o }) {
375
375
  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
376
  }
377
- function Wt({ variant: t = "ghost", style: i, ...r }) {
377
+ function Ht({ variant: t = "ghost", style: i, ...r }) {
378
378
  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
379
  }
380
- function Lt({ style: t, ...i }) {
380
+ function Et({ style: t, ...i }) {
381
381
  return /* @__PURE__ */ e("input", { ...i, style: { width: "100%", minWidth: 0, border: 0, outline: 0, background: "transparent", font: "inherit", ...t } });
382
382
  }
383
- const ot = ze(
383
+ const ct = Le(
384
384
  ({ children: t, style: i }, r) => /* @__PURE__ */ e("div", { ref: r, style: { minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", ...i }, children: t })
385
- ), $t = ze(
385
+ ), jt = Le(
386
386
  function({ style: i, ...r }, o) {
387
387
  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
388
  }
389
389
  );
390
- function Ht(t) {
390
+ function At(t) {
391
391
  return {
392
392
  id: t.contactId ?? t.providerConversationKey,
393
393
  name: t.contactName,
@@ -396,10 +396,21 @@ function Ht(t) {
396
396
  ...t.contactExternalId ? { externalId: t.contactExternalId } : {}
397
397
  };
398
398
  }
399
- function Le(t) {
400
- return { conversation: t, contact: Ht(t) };
399
+ function Ae(t, i) {
400
+ return {
401
+ conversation: t,
402
+ contact: At(t),
403
+ provider: i == null ? void 0 : i.provider,
404
+ recentMessages: i == null ? void 0 : i.recentMessages,
405
+ linkContact: (i == null ? void 0 : i.linkContact) ?? (async () => {
406
+ }),
407
+ refreshContactInfo: (i == null ? void 0 : i.refreshContactInfo) ?? (() => {
408
+ }),
409
+ sendMessage: (i == null ? void 0 : i.sendMessage) ?? (async () => {
410
+ })
411
+ };
401
412
  }
402
- class Mt extends ut {
413
+ class Ot extends mt {
403
414
  constructor() {
404
415
  super(...arguments), this.state = { caught: !1 };
405
416
  }
@@ -410,33 +421,33 @@ class Mt extends ut {
410
421
  return this.state.caught ? null : this.props.children;
411
422
  }
412
423
  }
413
- const l = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, qe = [
424
+ const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, Je = [
414
425
  { icon: "😊", emojis: ["😀", "😁", "😂", "🤣", "😊", "😇", "🙂", "😉", "😍", "🥰", "😘", "😋", "😎", "🤩", "😏", "😒", "😔", "😢", "😭", "😤", "😠", "🤯", "😱", "🥳", "😴", "🤔", "🤗", "🫡", "😮", "🤧", "🥺", "😶", "🫠", "🤭", "🤫"] },
415
426
  { icon: "👋", emojis: ["👍", "👎", "👏", "🙏", "🤝", "✌️", "🤞", "🫡", "💪", "🤜", "👊", "✊", "🖐", "👌", "🤌", "🤏", "☝️", "👆", "👇", "👉", "👈", "🤙", "💅", "🫶", "❤️", "🧡", "💛", "💚", "💙", "💜", "🖤", "💔", "❣️", "💕", "💯"] },
416
427
  { icon: "🐱", emojis: ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🙈", "🐔", "🐧", "🐦", "🦆", "🦅", "🦉", "🦋", "🐝", "🐛", "🐢", "🦎", "🐬", "🦈", "🐳", "🐙", "🦑"] },
417
428
  { icon: "🍕", emojis: ["🍎", "🍊", "🍋", "🍇", "🍓", "🍒", "🥝", "🥑", "🍔", "🍕", "🌮", "🍜", "🍣", "🍦", "🎂", "🍰", "🧁", "☕", "🧋", "🥤", "🍺", "🥂", "🍾", "🧃", "🧊"] },
418
429
  { icon: "⚽", emojis: ["⚽", "🏀", "🏈", "⚾", "🎾", "🏐", "🏓", "🎮", "🎲", "🎯", "🎳", "🏆", "🥇", "🎖", "🎁", "🎉", "🎊", "🎈", "🎭", "🎨", "🎬", "🎵", "🎸", "🎹", "🎺", "🪗", "🎻"] },
419
430
  { icon: "🌍", emojis: ["🌍", "🌈", "⭐", "🌙", "☀️", "⛅", "🌊", "🔥", "💧", "🌿", "🌸", "🌺", "🌻", "🍀", "🌴", "🏔", "🏖", "🏕", "🌃", "🏙", "🌅", "🌄", "🌠", "🌌", "🌋", "🏝"] }
420
- ], Pe = Ze(""), at = Ze("");
421
- function Et() {
431
+ ], qe = nt(""), st = nt("");
432
+ function Ut() {
422
433
  try {
423
434
  const t = new AudioContext(), i = t.createOscillator(), r = t.createGain();
424
435
  i.connect(r), r.connect(t.destination), i.type = "sine", i.frequency.setValueAtTime(880, t.currentTime), i.frequency.exponentialRampToValueAtTime(660, t.currentTime + 0.12), r.gain.setValueAtTime(0.25, t.currentTime), r.gain.exponentialRampToValueAtTime(1e-3, t.currentTime + 0.35), i.start(t.currentTime), i.stop(t.currentTime + 0.35);
425
436
  } catch {
426
437
  }
427
438
  }
428
- function jt(t) {
439
+ function Dt(t) {
429
440
  if (!(t != null && t.metadata)) return;
430
441
  const i = t.metadata, r = i.pageName ?? i.displayName ?? i.username ?? i.name;
431
442
  return typeof r == "string" && r ? r : void 0;
432
443
  }
433
- function lt(t) {
444
+ function ht(t) {
434
445
  return t === "facebook" ? "Facebook Messenger" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo OA" : t === "livechat" ? "Live Chat" : "Channel";
435
446
  }
436
- function Ve(t) {
447
+ function Ye(t) {
437
448
  return t === "facebook" ? "Facebook" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo" : t === "livechat" ? "Live Chat" : String(t ?? "");
438
449
  }
439
- const At = (t) => {
450
+ const Pt = (t) => {
440
451
  var r;
441
452
  const i = {
442
453
  "application/pdf": "PDF",
@@ -447,81 +458,85 @@ const At = (t) => {
447
458
  };
448
459
  return t ? i[t] ?? ((r = t.split("/")[1]) == null ? void 0 : r.toUpperCase()) ?? "Tệp" : "Tệp đính kèm";
449
460
  };
450
- function Ge({ status: t }) {
451
- return t === "read" ? /* @__PURE__ */ e(Fe, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(Fe, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(tt, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
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;
452
463
  }
453
- const dn = ze(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: k, disableAttachments: x, disableNotificationSound: E, hideKeyboardHint: g, locale: v = "vi", extensions: L, onNewMessage: C, onConversationSelect: R }, W) {
454
- var he, we, c, m, b;
455
- const B = X(new Bt(i, r)), [A, Z] = y([]), [N, M] = y([]), [O, Y] = y(), [I, V] = y(), h = X(void 0), [S, _] = y(""), [z, K] = y({ provider: "all", unreadOnly: !1 }), [oe, ue] = y(!1), w = X(null), ie = X(null), [Q, fe] = y(null), [le, p] = y(!0), [T, $] = y(""), [q, ae] = y(!1), [ee, U] = y(260), [de, ce] = y(!1), D = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", te = Be(() => new Map(N.map((d) => [d.id, d])), [N]), ge = X(null), [ve, $e] = y(0), Te = Be(() => {
456
- const d = new Set(N.map((u) => u.provider));
457
- return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) => d.has(u));
458
- }, [N]), Re = Be(() => {
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: B, onNewMessage: I, onConversationSelect: H }, $) {
465
+ var c, y, b, M, Z;
466
+ const E = ee(new Mt(i, r)), [j, A] = g([]), [F, K] = g([]), [ne, U] = g(), [w, _] = g(), k = ee(void 0), [L, ce] = g(""), [z, D] = g({ provider: "all", unreadOnly: !1 }), [le, v] = g(!1), Q = ee(null), N = ee(null), [x, J] = g(null), [se, h] = g(!0), [T, P] = g(""), [q, ie] = g(() => !!(B != null && B.length)), [re, V] = g(280), [ye, ke] = g(!1), [be, ue] = g(0), G = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", de = Ee(() => new Map(F.map((l) => [l.id, l])), [F]), me = ee(null), [we, Oe] = g(0), Se = We(async (l, u) => {
467
+ l.contactId && await E.current.patchContact(l.contactId, u), A((R) => R.map((W) => W.id === l.id ? { ...W, contactExternalId: u ?? void 0 } : W)), _((R) => R && R.id === l.id ? { ...R, contactExternalId: u ?? void 0 } : R), ue((R) => R + 1);
468
+ }, []), Ce = We(() => {
469
+ ue((l) => l + 1);
470
+ }, []), Ie = Ee(() => {
471
+ const l = new Set(F.map((u) => u.provider));
472
+ return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) => l.has(u));
473
+ }, [F]), pe = Ee(() => {
459
474
  var u;
460
- const d = {};
461
- for (const j of A) {
462
- const H = ((u = te.get(j.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
463
- d[H] = (d[H] ?? 0) + 1;
475
+ const l = {};
476
+ for (const R of j) {
477
+ const W = ((u = de.get(R.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
478
+ l[W] = (l[W] ?? 0) + 1;
464
479
  }
465
- return d;
466
- }, [A, te]);
467
- function ke(d) {
468
- const u = d.clientX, j = ee;
469
- ce(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
470
- function H(be) {
471
- const Se = Math.max(200, Math.min(480, j + (u - be.clientX)));
472
- U(Se);
480
+ return l;
481
+ }, [j, de]);
482
+ function Me(l) {
483
+ const u = l.clientX, R = re;
484
+ ke(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
485
+ function W(xe) {
486
+ const Re = Math.max(200, Math.min(480, R + (u - xe.clientX)));
487
+ V(Re);
473
488
  }
474
- function ne() {
475
- ce(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", H), document.removeEventListener("mouseup", ne);
489
+ function fe() {
490
+ ke(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", W), document.removeEventListener("mouseup", fe);
476
491
  }
477
- document.addEventListener("mousemove", H), document.addEventListener("mouseup", ne);
492
+ document.addEventListener("mousemove", W), document.addEventListener("mouseup", fe);
478
493
  }
479
- const G = De(async (d) => {
494
+ const oe = We(async (l) => {
480
495
  try {
481
- const u = await B.current.listConversations(d);
482
- Z((j) => d ? [...j, ...u.items] : u.items), Y(u.nextCursor), !d && u.items.length && V((j) => j ?? (k ? u.items.find((H) => H.id === k) ?? u.items[0] : u.items[0])), $("");
496
+ const u = await E.current.listConversations(l);
497
+ A((R) => l ? [...R, ...u.items] : u.items), U(u.nextCursor), !l && u.items.length && _((R) => R ?? (C ? u.items.find((W) => W.id === C) ?? u.items[0] : u.items[0])), P("");
483
498
  } catch (u) {
484
- $(u instanceof Error ? u.message : "Không tải được hội thoại");
499
+ P(u instanceof Error ? u.message : "Không tải được hội thoại");
485
500
  } finally {
486
- p(!1);
501
+ h(!1);
487
502
  }
488
- }, [k]);
489
- F(() => (B.current.listConnections().then(M).catch(() => {
490
- }), G(), B.current.connectSSE((u, j) => {
503
+ }, [C]);
504
+ Y(() => (E.current.listConnections().then(K).catch(() => {
505
+ }), oe(), E.current.connectSSE((u, R) => {
491
506
  if (u === "message.new" || u === "conversation.updated") {
492
- if (G(), u === "message.new") {
493
- const H = typeof j == "object" && j ? j : {}, ne = H.conversationId ? String(H.conversationId) : "", be = H.messageId ? String(H.messageId) : "";
494
- if ((H.direction ? String(H.direction) : "") === "inbound" && !E && Et(), ne && ne === h.current && be && ge.current) {
495
- const st = ge.current;
496
- B.current.getMessage(be).then((ht) => {
497
- st(ht);
507
+ if (oe(), u === "message.new") {
508
+ const W = typeof R == "object" && R ? R : {}, fe = W.conversationId ? String(W.conversationId) : "", xe = W.messageId ? String(W.messageId) : "";
509
+ if ((W.direction ? String(W.direction) : "") === "inbound" && !O && Ut(), fe && fe === k.current && xe && me.current) {
510
+ const ft = me.current;
511
+ E.current.getMessage(xe).then((gt) => {
512
+ ft(gt);
498
513
  }).catch(() => {
499
514
  });
500
515
  }
501
- C == null || C(ne || h.current || "");
516
+ I == null || I(fe || k.current || "");
502
517
  }
503
- } else u === "message.status_updated" && $e((H) => H + 1);
504
- })), [G, C]), F(() => {
505
- h.current = I == null ? void 0 : I.id;
506
- }, [I]), F(() => {
507
- I != null && I.unreadCount && B.current.markRead(I.id).then(() => G()).catch(() => {
518
+ } else u === "message.status_updated" && Oe((W) => W + 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(() => {
508
523
  });
509
- }, [I == null ? void 0 : I.id]), F(() => {
510
- if (!oe) return;
511
- function d(u) {
512
- var j, H;
513
- (j = w.current) != null && j.contains(u.target) || (H = ie.current) != null && H.contains(u.target) || ue(!1);
524
+ }, [w == null ? void 0 : w.id]), Y(() => {
525
+ if (!le) return;
526
+ function l(u) {
527
+ var R, W;
528
+ (R = Q.current) != null && R.contains(u.target) || (W = N.current) != null && W.contains(u.target) || v(!1);
514
529
  }
515
- return document.addEventListener("mousedown", d), () => document.removeEventListener("mousedown", d);
516
- }, [oe]);
517
- const ye = Be(() => {
518
- const d = S.toLowerCase().trim();
519
- return A.filter((u) => {
520
- var Se;
521
- const j = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), H = ((Se = te.get(u.connectionId)) == null ? void 0 : Se.provider) ?? "unknown", ne = z.provider === "all" || H === z.provider, be = !z.unreadOnly || (u.unreadCount ?? 0) > 0;
522
- return ne && be && (!d || j.includes(d));
530
+ return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
531
+ }, [le]);
532
+ const ze = Ee(() => {
533
+ const l = L.toLowerCase().trim();
534
+ return j.filter((u) => {
535
+ var Re;
536
+ const R = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), W = ((Re = de.get(u.connectionId)) == null ? void 0 : Re.provider) ?? "unknown", fe = z.provider === "all" || W === z.provider, xe = !z.unreadOnly || (u.unreadCount ?? 0) > 0;
537
+ return fe && xe && (!l || R.includes(l));
523
538
  });
524
- }, [A, te, z, S]), me = z.provider !== "all" || z.unreadOnly, se = v === "en" ? {
539
+ }, [j, de, z, L]), Te = z.provider !== "all" || z.unreadOnly, ae = S === "en" ? {
525
540
  today: "TODAY",
526
541
  loadOlder: "↑ Load older messages",
527
542
  loading: "Loading messages…",
@@ -542,351 +557,364 @@ const dn = ze(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
542
557
  send: "Gửi",
543
558
  all: "Tất cả"
544
559
  };
545
- pt(W, () => ({
546
- openConversation: (d) => {
547
- const u = A.find((j) => j.id === d);
548
- u && V(u);
560
+ yt($, () => ({
561
+ openConversation: (l) => {
562
+ const u = j.find((R) => R.id === l);
563
+ u && _(u);
549
564
  },
550
- refresh: () => void G()
551
- }), [A, G]);
565
+ refresh: () => void oe()
566
+ }), [j, oe]);
552
567
  const He = {
553
- ...f.frame,
568
+ ...p.frame,
554
569
  height: s ?? 620,
555
570
  ...s ? { maxHeight: "none" } : {},
556
571
  fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif",
557
572
  borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px",
558
- gridTemplateColumns: q ? `minmax(260px, 300px) minmax(0, 1fr) ${ee}px` : "minmax(260px, 300px) minmax(0, 1fr)",
559
- transition: de ? "none" : "grid-template-columns 220ms ease"
573
+ gridTemplateColumns: q ? `minmax(260px, 300px) minmax(0, 1fr) ${re}px` : "minmax(260px, 300px) minmax(0, 1fr)",
574
+ transition: ye ? "none" : "grid-template-columns 220ms ease"
560
575
  };
561
- return le ? /* @__PURE__ */ n("div", { style: { ...f.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
562
- /* @__PURE__ */ e(Oe, {}),
576
+ return se ? /* @__PURE__ */ n("div", { style: { ...p.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
577
+ /* @__PURE__ */ e(Fe, {}),
563
578
  " Đang tải hộp thư…"
564
- ] }) : T && !A.length ? /* @__PURE__ */ n("div", { style: { ...f.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
565
- /* @__PURE__ */ e(xt, { size: 16, strokeWidth: 2 }),
579
+ ] }) : T && !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 }),
566
581
  " ",
567
582
  T,
568
- /* @__PURE__ */ e("button", { style: f.retry, onClick: () => {
569
- p(!0), G();
583
+ /* @__PURE__ */ e("button", { style: p.retry, onClick: () => {
584
+ h(!0), oe();
570
585
  }, children: "Thử lại" })
571
- ] }) : /* @__PURE__ */ e(Pe.Provider, { value: i, children: /* @__PURE__ */ e(at.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
572
- const d = window.scrollY;
586
+ ] }) : /* @__PURE__ */ e(qe.Provider, { value: i, children: /* @__PURE__ */ e(st.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
587
+ const l = window.scrollY;
573
588
  requestAnimationFrame(() => {
574
- window.scrollY !== d && window.scrollTo({ top: d, behavior: "instant" });
589
+ window.scrollY !== l && window.scrollTo({ top: l, behavior: "instant" });
575
590
  });
576
591
  }, children: [
577
- /* @__PURE__ */ n("aside", { style: f.sidebar, children: [
578
- /* @__PURE__ */ n("div", { style: f.brand, children: [
579
- /* @__PURE__ */ e("div", { style: { ...f.brandMark, background: D, overflow: "hidden", padding: 0 }, children: (he = o == null ? void 0 : o.branding) != null && he.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((we = o == null ? void 0 : o.branding) == null ? void 0 : we.mark) ?? "C" }),
592
+ /* @__PURE__ */ n("aside", { style: p.sidebar, children: [
593
+ /* @__PURE__ */ n("div", { style: p.brand, children: [
594
+ /* @__PURE__ */ e("div", { style: { ...p.brandMark, background: G, overflow: "hidden", padding: 0 }, children: (c = o == null ? void 0 : o.branding) != null && c.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((y = o == null ? void 0 : o.branding) == null ? void 0 : y.mark) ?? "C" }),
580
595
  /* @__PURE__ */ n("div", { children: [
581
- /* @__PURE__ */ e("strong", { children: ((c = o == null ? void 0 : o.branding) == null ? void 0 : c.name) ?? "Hộp thư" }),
582
- !((m = o == null ? void 0 : o.branding) != null && m.name) && /* @__PURE__ */ e("span", { style: f.eyebrow, children: "CHANNELHUB" })
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" })
583
598
  ] }),
584
- /* @__PURE__ */ e(Wt, { "aria-label": "Tùy chọn", style: f.iconButton, children: /* @__PURE__ */ e(nt, { size: 16, strokeWidth: 2 }) })
599
+ /* @__PURE__ */ e(Ht, { "aria-label": "Tùy chọn", style: p.iconButton, children: /* @__PURE__ */ e(at, { size: 16, strokeWidth: 2 }) })
585
600
  ] }),
586
- /* @__PURE__ */ n("div", { style: f.search, children: [
587
- /* @__PURE__ */ e(Ke, { size: 16, strokeWidth: 2 }),
588
- /* @__PURE__ */ e(Lt, { "aria-label": se.searchPlaceholder, value: S, onChange: (d) => _(d.target.value), placeholder: se.searchPlaceholder }),
589
- S && /* @__PURE__ */ e("button", { style: f.clear, onClick: () => _(""), "aria-label": "Xóa tìm kiếm", children: "×" })
601
+ /* @__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: (l) => ce(l.target.value), placeholder: ae.searchPlaceholder }),
604
+ L && /* @__PURE__ */ e("button", { style: p.clear, onClick: () => ce(""), "aria-label": "Xóa tìm kiếm", children: "×" })
590
605
  ] }),
591
- me && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
592
- z.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: D, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
593
- /* @__PURE__ */ e(Ie, { provider: z.provider }),
594
- Ve(z.provider),
595
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: D, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => K((d) => ({ ...d, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(We, { size: 10 }) })
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((l) => ({ ...l, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(je, { size: 10 }) })
596
611
  ] }),
597
- z.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: D, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
598
- se.unreadOnly,
599
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: D, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => K((d) => ({ ...d, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(We, { size: 10 }) })
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((l) => ({ ...l, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(je, { size: 10 }) })
600
615
  ] }),
601
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: l.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => K({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
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ả" })
602
617
  ] }),
603
- /* @__PURE__ */ n("div", { style: f.listHeader, children: [
618
+ /* @__PURE__ */ n("div", { style: p.listHeader, children: [
604
619
  /* @__PURE__ */ n("span", { children: [
605
- ye.length,
620
+ ze.length,
606
621
  " hội thoại"
607
622
  ] }),
608
623
  /* @__PURE__ */ e(
609
624
  "button",
610
625
  {
611
- ref: w,
612
- style: { ...f.iconButton, background: me ? `${D}14` : "transparent", color: me ? D : l.muted },
626
+ ref: Q,
627
+ style: { ...p.iconButton, background: Te ? `${G}14` : "transparent", color: Te ? G : d.muted },
613
628
  "aria-label": "Bộ lọc",
614
629
  onClick: () => {
615
- var d;
616
- if (!oe) {
617
- const u = (d = w.current) == null ? void 0 : d.getBoundingClientRect();
618
- u && fe({ top: u.bottom + 6, left: u.left });
630
+ var l;
631
+ if (!le) {
632
+ const u = (l = Q.current) == null ? void 0 : l.getBoundingClientRect();
633
+ u && J({ top: u.bottom + 6, left: u.left });
619
634
  }
620
- ue((u) => !u);
635
+ v((u) => !u);
621
636
  },
622
- children: /* @__PURE__ */ e(zt, { size: 15, strokeWidth: 2 })
637
+ children: /* @__PURE__ */ e(Wt, { size: 15, strokeWidth: 2 })
623
638
  }
624
639
  )
625
640
  ] }),
626
- oe && Q && Qe(
641
+ le && x && it(
627
642
  /* @__PURE__ */ n(
628
643
  "div",
629
644
  {
630
- ref: ie,
631
- style: { position: "fixed", top: Q.top, left: Q.left, zIndex: 9999, background: l.white, border: `1px solid ${l.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 },
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 },
632
647
  children: [
633
- /* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: l.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
634
- ["all", ...Te].map((d) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.provider === d ? `${D}0f` : "transparent" }, children: [
635
- /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider === d, onChange: () => K((u) => ({ ...u, provider: d })), style: { accentColor: D } }),
636
- d === "all" ? /* @__PURE__ */ n("span", { style: { color: l.ink }, children: [
637
- se.all,
648
+ /* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
649
+ ["all", ...Ie].map((l) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.provider === l ? `${G}0f` : "transparent" }, children: [
650
+ /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider === l, onChange: () => D((u) => ({ ...u, provider: l })), style: { accentColor: G } }),
651
+ l === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
652
+ ae.all,
638
653
  " (",
639
- A.length,
654
+ j.length,
640
655
  ")"
641
- ] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: l.ink }, children: [
642
- /* @__PURE__ */ e(Ie, { provider: d }),
643
- Ve(d),
656
+ ] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: d.ink }, children: [
657
+ /* @__PURE__ */ e($e, { provider: l }),
658
+ Ye(l),
644
659
  " ",
645
- /* @__PURE__ */ n("span", { style: { color: l.muted }, children: [
660
+ /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
646
661
  "(",
647
- Re[d] ?? 0,
662
+ pe[l] ?? 0,
648
663
  ")"
649
664
  ] })
650
665
  ] })
651
- ] }, d)),
652
- /* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${l.line}`, margin: "8px 0 6px" } }),
653
- /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.unreadOnly ? `${D}0f` : "transparent" }, children: [
654
- /* @__PURE__ */ e("input", { type: "checkbox", checked: z.unreadOnly, onChange: (d) => K((u) => ({ ...u, unreadOnly: d.target.checked })), style: { accentColor: D } }),
655
- /* @__PURE__ */ e("span", { style: { color: l.ink }, children: se.unreadOnly })
666
+ ] }, l)),
667
+ /* @__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: (l) => D((u) => ({ ...u, unreadOnly: l.target.checked })), style: { accentColor: G } }),
670
+ /* @__PURE__ */ e("span", { style: { color: d.ink }, children: ae.unreadOnly })
656
671
  ] })
657
672
  ]
658
673
  }
659
674
  ),
660
675
  document.body
661
676
  ),
662
- /* @__PURE__ */ n(ot, { style: f.conversationList, children: [
663
- ye.map((d) => {
677
+ /* @__PURE__ */ n(ct, { style: p.conversationList, children: [
678
+ ze.map((l) => {
664
679
  var u;
665
- return /* @__PURE__ */ e(Ot, { conversation: d, provider: (u = te.get(d.connectionId)) == null ? void 0 : u.provider, selected: (I == null ? void 0 : I.id) === d.id, primary: D, onSelect: () => {
666
- V(d), R == null || R(d.id), B.current.markRead(d.id).then(() => G()).catch(() => {
680
+ return /* @__PURE__ */ e(Nt, { conversation: l, provider: (u = de.get(l.connectionId)) == null ? void 0 : u.provider, selected: (w == null ? void 0 : w.id) === l.id, primary: G, onSelect: () => {
681
+ _(l), H == null || H(l.id), E.current.markRead(l.id).then(() => oe()).catch(() => {
667
682
  });
668
- } }, d.id);
683
+ } }, l.id);
669
684
  }),
670
- !ye.length && /* @__PURE__ */ n("div", { style: f.emptySmall, children: [
671
- /* @__PURE__ */ e("div", { style: f.emptyIcon, children: /* @__PURE__ */ e(Ke, { size: 16, strokeWidth: 2 }) }),
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 }) }),
672
687
  /* @__PURE__ */ e("strong", { children: "Không tìm thấy" }),
673
688
  /* @__PURE__ */ e("span", { children: "Thử từ khóa hoặc bộ lọc khác." })
674
689
  ] }),
675
- O && /* @__PURE__ */ e("button", { style: f.loadMore, onClick: () => void G(O), children: "Xem thêm hội thoại" })
690
+ ne && /* @__PURE__ */ e("button", { style: p.loadMore, onClick: () => void oe(ne), children: "Xem thêm hội thoại" })
676
691
  ] })
677
692
  ] }),
678
- /* @__PURE__ */ e("main", { style: f.main, children: I ? /* @__PURE__ */ e(
679
- Ut,
693
+ /* @__PURE__ */ e("main", { style: p.main, children: w ? /* @__PURE__ */ e(
694
+ Ft,
680
695
  {
681
- conversation: I,
682
- provider: (b = te.get(I.connectionId)) == null ? void 0 : b.provider,
683
- connection: te.get(I.connectionId),
684
- client: B.current,
685
- primary: D,
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,
686
701
  error: T,
687
- onRegisterAppend: (d) => {
688
- ge.current = d;
702
+ onRegisterAppend: (l) => {
703
+ me.current = l;
689
704
  },
690
- refreshKey: ve,
705
+ refreshKey: we,
691
706
  infoOpen: q,
692
- onToggleInfo: () => ae((d) => !d),
693
- t: se,
694
- disableAttachments: x,
695
- hideKeyboardHint: g,
696
- extensions: L
707
+ onToggleInfo: () => ie((l) => !l),
708
+ t: ae,
709
+ disableAttachments: m,
710
+ hideKeyboardHint: f,
711
+ extensions: B,
712
+ onLinkContact: (l) => Se(w, l),
713
+ onRefreshContactInfo: Ce
697
714
  },
698
- I.id
699
- ) : /* @__PURE__ */ e(Ft, {}) }),
700
- q && I && /* @__PURE__ */ e(
701
- Pt,
715
+ w.id
716
+ ) : /* @__PURE__ */ e(Gt, {}) }),
717
+ q && w && /* @__PURE__ */ e(
718
+ qt,
702
719
  {
703
- conversation: I,
704
- connection: te.get(I.connectionId),
705
- primary: D,
706
- onClose: () => ae(!1),
707
- client: B.current,
708
- onStartResize: ke,
709
- extensions: L
720
+ conversation: w,
721
+ connection: de.get(w.connectionId),
722
+ primary: G,
723
+ onClose: () => ie(!1),
724
+ client: E.current,
725
+ onStartResize: Me,
726
+ extensions: B,
727
+ extRefreshKey: be,
728
+ onLinkContact: (l) => Se(w, l),
729
+ onRefreshContactInfo: Ce
710
730
  }
711
731
  )
712
732
  ] }) }) });
713
733
  });
714
- function Ot({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
715
- const [k, x] = y(!1), E = t.contactName ?? t.subject ?? t.providerConversationKey, g = t.unreadCount ?? 0, v = t.lastMessageText ?? "", L = t.lastMessageDirection === "outbound" ? "Bạn: " : "", C = v.length > 60 ? v.slice(0, 60) + "…" : v, R = v ? L + C : "";
716
- let W = "transparent";
717
- r ? W = "#eef2ff" : k ? W = "#f7f9fc" : g > 0 && (W = "#f0f4ff");
718
- const B = {
719
- ...f.row,
720
- background: W,
721
- ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : g > 0 && !k ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
734
+ function Nt({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
735
+ const [C, m] = g(!1), O = t.contactName ?? t.subject ?? t.providerConversationKey, f = t.unreadCount ?? 0, S = t.lastMessageText ?? "", B = t.lastMessageDirection === "outbound" ? "Bạn: " : "", I = S.length > 60 ? S.slice(0, 60) + "…" : S, H = S ? B + I : "";
736
+ let $ = "transparent";
737
+ r ? $ = "#eef2ff" : C ? $ = "#f7f9fc" : f > 0 && ($ = "#f0f4ff");
738
+ const E = {
739
+ ...p.row,
740
+ background: $,
741
+ ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : f > 0 && !C ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
722
742
  };
723
743
  return /* @__PURE__ */ n(
724
744
  "button",
725
745
  {
726
746
  onClick: s,
727
- style: B,
728
- onMouseEnter: () => x(!0),
729
- onMouseLeave: () => x(!1),
747
+ style: E,
748
+ onMouseEnter: () => m(!0),
749
+ onMouseLeave: () => m(!1),
730
750
  children: [
731
- /* @__PURE__ */ e(dt, { name: E, color: o, image: t.contactPictureUrl, provider: i }),
732
- /* @__PURE__ */ n("span", { style: f.rowBody, children: [
733
- /* @__PURE__ */ n("span", { style: f.rowTop, children: [
734
- /* @__PURE__ */ e("strong", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: g > 0 ? 700 : 500 }, children: E }),
751
+ /* @__PURE__ */ e(pt, { name: O, color: o, image: t.contactPictureUrl, provider: i }),
752
+ /* @__PURE__ */ n("span", { style: p.rowBody, children: [
753
+ /* @__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 }),
735
755
  /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, flexShrink: 0 }, children: [
736
- /* @__PURE__ */ e("time", { style: { color: l.muted, fontSize: 11, whiteSpace: "nowrap" }, children: Ue(t.lastMessageAt) }),
737
- g > 0 && /* @__PURE__ */ e("span", { "aria-label": `${g} tin nhắn chưa đọc`, style: f.unreadBadge, children: g > 99 ? "99+" : g })
756
+ /* @__PURE__ */ e("time", { style: { color: d.muted, fontSize: 11, whiteSpace: "nowrap" }, children: Ke(t.lastMessageAt) }),
757
+ f > 0 && /* @__PURE__ */ e("span", { "aria-label": `${f} tin nhắn chưa đọc`, style: p.unreadBadge, children: f > 99 ? "99+" : f })
738
758
  ] })
739
759
  ] }),
740
- /* @__PURE__ */ e("span", { style: { ...f.rowBottom, color: g > 0 && !r ? "#4a5568" : l.muted }, children: /* @__PURE__ */ e("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", maxWidth: "100%" }, children: R || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" }) }) })
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" }) }) })
741
761
  ] })
742
762
  ]
743
763
  }
744
764
  );
745
765
  }
746
- function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s, error: k, onRegisterAppend: x, refreshKey: E, infoOpen: g, onToggleInfo: v, t: L, disableAttachments: C, hideKeyboardHint: R, extensions: W }) {
747
- var we;
748
- const [B, A] = y([]), [Z, N] = y(), [M, O] = y(""), [Y, I] = y(!0), [V, h] = y(!1), [S, _] = y(""), z = X(null), K = t.contactName ?? t.subject ?? t.providerConversationKey, oe = X(null), ue = X(null), [w, ie] = y(null), [Q, fe] = y(!1), [le, p] = y(!1), [T, $] = y(!1), [q, ae] = y(0), ee = X(null), U = X(null), de = X(null), [ce, D] = y(!1), [te, ge] = y(""), [ve, $e] = y([]), Te = X(null), Re = X(null);
749
- F(() => () => {
750
- w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl);
751
- }, [w == null ? void 0 : w.objectUrl]), F(() => {
752
- if (!T) return;
753
- function c(m) {
754
- var b, d;
755
- (b = U.current) != null && b.contains(m.target) || (d = ee.current) != null && d.contains(m.target) || $(!1);
766
+ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s, error: C, onRegisterAppend: m, refreshKey: O, infoOpen: f, onToggleInfo: S, t: B, disableAttachments: I, hideKeyboardHint: H, extensions: $, onLinkContact: E, onRefreshContactInfo: j }) {
767
+ var He;
768
+ const [A, F] = g([]), [K, ne] = g(), [U, w] = g(""), [_, k] = g(!0), [L, ce] = g(!1), [z, D] = g(""), le = ee(null), v = t.contactName ?? t.subject ?? t.providerConversationKey, Q = ee(null), N = ee(null), [x, J] = g(null), [se, h] = g(!1), [T, P] = g(!1), [q, ie] = g(!1), [re, V] = g(0), ye = ee(null), ke = ee(null), be = ee(null), [ue, G] = g(!1), [de, me] = g(""), [we, Oe] = g([]), 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 c(y) {
774
+ var b, M;
775
+ (b = ke.current) != null && b.contains(y.target) || (M = ye.current) != null && M.contains(y.target) || ie(!1);
756
776
  }
757
777
  return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
758
- }, [T]), F(() => {
759
- o.listCannedResponses().then($e).catch(() => {
778
+ }, [q]), Y(() => {
779
+ o.listCannedResponses().then(Oe).catch(() => {
760
780
  });
761
- }, [o]), F(() => {
762
- if (!ce) return;
763
- function c(m) {
764
- var b, d;
765
- (b = Re.current) != null && b.contains(m.target) || (d = Te.current) != null && d.contains(m.target) || D(!1);
781
+ }, [o]), Y(() => {
782
+ if (!ue) return;
783
+ function c(y) {
784
+ var b, M;
785
+ (b = Ce.current) != null && b.contains(y.target) || (M = Se.current) != null && M.contains(y.target) || G(!1);
766
786
  }
767
787
  return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
768
- }, [ce]);
769
- const ke = X(!0), G = De(async (c, m) => {
770
- m || (ke.current = !c);
788
+ }, [ue]);
789
+ const Ie = ee(!0), pe = We(async (c, y) => {
790
+ y || (Ie.current = !c);
771
791
  try {
772
792
  const b = await o.listMessages(t.id, c);
773
- A((d) => c ? [...b.items, ...d] : b.items), N(b.nextCursor);
793
+ F((M) => c ? [...b.items, ...M] : b.items), ne(b.nextCursor);
774
794
  } catch (b) {
775
- _(b instanceof Error ? b.message : "Không tải được tin nhắn");
795
+ D(b instanceof Error ? b.message : "Không tải được tin nhắn");
776
796
  } finally {
777
- m || I(!1);
797
+ y || k(!1);
778
798
  }
779
799
  }, [o, t.id]);
780
- F(() => {
781
- I(!0), G();
782
- }, [G]), F(() => {
783
- E && G(void 0, !0);
784
- }, [E]), F(() => {
785
- ke.current && requestAnimationFrame(() => {
786
- const c = z.current;
800
+ Y(() => {
801
+ k(!0), pe();
802
+ }, [pe]), Y(() => {
803
+ O && pe(void 0, !0);
804
+ }, [O]), Y(() => {
805
+ Ie.current && requestAnimationFrame(() => {
806
+ const c = le.current;
787
807
  c && (c.scrollTop = c.scrollHeight);
788
808
  });
789
- }, [B]), F(() => (x == null || x((c) => {
790
- ke.current = !0, A((m) => m.some((b) => b.id === c.id) ? m : [...m, c]);
809
+ }, [A]), Y(() => (m == null || m((c) => {
810
+ Ie.current = !0, F((y) => y.some((b) => b.id === c.id) ? y : [...y, c]);
791
811
  }), () => {
792
- x == null || x(null);
793
- }), [x]);
794
- async function ye(c) {
795
- var d;
796
- const m = (d = c.target.files) == null ? void 0 : d[0];
797
- if (!m) return;
812
+ m == null || m(null);
813
+ }), [m]);
814
+ async function Me(c) {
815
+ var M;
816
+ const y = (M = c.target.files) == null ? void 0 : M[0];
817
+ if (!y) return;
798
818
  c.target.value = "";
799
- const b = URL.createObjectURL(m);
800
- ie({ file: m, uploading: !0, objectUrl: b });
819
+ const b = URL.createObjectURL(y);
820
+ J({ file: y, uploading: !0, objectUrl: b });
801
821
  try {
802
- const u = await o.uploadAttachment(m);
803
- ie({ file: m, uploading: !1, url: u.url, mimeType: u.mimeType, attachmentType: u.attachmentType, objectUrl: b });
822
+ const Z = await o.uploadAttachment(y);
823
+ J({ file: y, uploading: !1, url: Z.url, mimeType: Z.mimeType, attachmentType: Z.attachmentType, objectUrl: b });
804
824
  } catch {
805
- URL.revokeObjectURL(b), ie(null), _("Không tải lên được tệp đính kèm");
825
+ URL.revokeObjectURL(b), J(null), D("Không tải lên được tệp đính kèm");
806
826
  }
807
827
  }
808
- async function me(c) {
828
+ async function oe(c) {
809
829
  c.preventDefault();
810
- const m = M.trim(), b = w != null && w.url ? [{ url: w.url, mimeType: w.mimeType ?? "application/octet-stream", type: w.attachmentType }] : [];
811
- if (!(!m && !b.length || V)) {
812
- h(!0), _("");
830
+ const y = U.trim(), b = x != null && x.url ? [{ url: x.url, mimeType: x.mimeType ?? "application/octet-stream", type: x.attachmentType }] : [];
831
+ if (!(!y && !b.length || L)) {
832
+ ce(!0), D("");
813
833
  try {
814
- await o.sendMessage(t.id, m || void 0, b.length ? b : void 0), w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl), O(""), ie(null), await G();
815
- } catch (d) {
816
- _(d instanceof Error ? d.message : "Không gửi được tin nhắn");
834
+ await o.sendMessage(t.id, y || void 0, b.length ? b : void 0), x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), w(""), J(null), await pe();
835
+ } catch (M) {
836
+ D(M instanceof Error ? M.message : "Không gửi được tin nhắn");
817
837
  } finally {
818
- h(!1);
838
+ ce(!1);
819
839
  }
820
840
  }
821
841
  }
822
- function se(c) {
823
- const m = de.current;
824
- if (!m) {
825
- O((j) => j + c), $(!1);
842
+ function ze(c) {
843
+ const y = be.current;
844
+ if (!y) {
845
+ w((l) => l + c), ie(!1);
826
846
  return;
827
847
  }
828
- const b = m.selectionStart ?? M.length, d = m.selectionEnd ?? M.length, u = M.slice(0, b) + c + M.slice(d);
829
- O(u), $(!1), requestAnimationFrame(() => {
830
- m.focus(), m.selectionStart = m.selectionEnd = b + c.length;
848
+ const b = y.selectionStart ?? U.length, M = y.selectionEnd ?? U.length, Z = U.slice(0, b) + c + U.slice(M);
849
+ w(Z), ie(!1), requestAnimationFrame(() => {
850
+ y.focus(), y.selectionStart = y.selectionEnd = b + c.length;
831
851
  });
832
852
  }
833
- function He(c) {
834
- O(c), D(!1), ge(""), requestAnimationFrame(() => {
835
- const m = de.current;
836
- m && (m.focus(), m.selectionStart = m.selectionEnd = c.length);
853
+ function Te(c) {
854
+ w(c), G(!1), me(""), requestAnimationFrame(() => {
855
+ const y = be.current;
856
+ y && (y.focus(), y.selectionStart = y.selectionEnd = c.length);
837
857
  });
838
858
  }
839
- const he = !V && (M.trim().length > 0 || (w == null ? void 0 : w.url) != null && !w.uploading);
840
- return /* @__PURE__ */ n("section", { style: f.chat, children: [
841
- /* @__PURE__ */ n("header", { style: f.chatHeader, children: [
842
- /* @__PURE__ */ e(dt, { name: K, color: s, image: t.contactPictureUrl, provider: i }),
843
- /* @__PURE__ */ n("div", { style: f.contact, children: [
844
- /* @__PURE__ */ e("strong", { style: f.contactName, children: K }),
845
- /* @__PURE__ */ e("span", { style: f.contactMeta, children: jt(r) ?? lt(i) })
859
+ const ae = !L && (U.trim().length > 0 || (x == null ? void 0 : x.url) != null && !x.uploading);
860
+ return /* @__PURE__ */ n("section", { style: p.chat, children: [
861
+ /* @__PURE__ */ n("header", { style: p.chatHeader, children: [
862
+ /* @__PURE__ */ e(pt, { name: v, color: s, image: t.contactPictureUrl, provider: i }),
863
+ /* @__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) })
846
866
  ] }),
847
- /* @__PURE__ */ n("div", { style: f.headerActions, children: [
848
- /* @__PURE__ */ e("button", { style: f.iconButton, "aria-label": "Thêm tùy chọn", children: /* @__PURE__ */ e(nt, { size: 16, strokeWidth: 2 }) }),
867
+ /* @__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 }) }),
849
869
  /* @__PURE__ */ e(
850
870
  "button",
851
871
  {
852
872
  style: {
853
- ...f.iconButton,
854
- background: g ? `${s}14` : "transparent",
855
- color: g ? s : l.muted
873
+ ...p.iconButton,
874
+ background: f ? `${s}14` : "transparent",
875
+ color: f ? s : d.muted
856
876
  },
857
877
  "aria-label": "Thông tin liên hệ",
858
- onClick: v,
859
- children: /* @__PURE__ */ e(wt, { size: 16, strokeWidth: 2 })
878
+ onClick: S,
879
+ children: /* @__PURE__ */ e(zt, { size: 16, strokeWidth: 2 })
860
880
  }
861
881
  )
862
882
  ] })
863
883
  ] }),
864
- /* @__PURE__ */ n(ot, { ref: z, style: f.messageArea, children: [
865
- /* @__PURE__ */ e("div", { style: f.day, children: L.today }),
866
- Z && /* @__PURE__ */ e("button", { onClick: () => void G(Z), style: f.historyButton, children: L.loadOlder }),
867
- Y && /* @__PURE__ */ n("div", { style: f.messageHint, children: [
868
- /* @__PURE__ */ e(Oe, {}),
884
+ /* @__PURE__ */ n(ct, { ref: le, style: p.messageArea, children: [
885
+ /* @__PURE__ */ e("div", { style: p.day, children: B.today }),
886
+ K && /* @__PURE__ */ e("button", { onClick: () => void pe(K), style: p.historyButton, children: B.loadOlder }),
887
+ _ && /* @__PURE__ */ n("div", { style: p.messageHint, children: [
888
+ /* @__PURE__ */ e(Fe, {}),
869
889
  " ",
870
- L.loading
890
+ B.loading
871
891
  ] }),
872
- !Y && !B.length && /* @__PURE__ */ e("div", { style: f.messageHint, children: L.noMessages }),
873
- B.map((c, m) => {
874
- const b = (W == null ? void 0 : W.flatMap((u) => u.messageEnrichments ?? [])) ?? [], d = c.direction === "inbound" && b.length > 0 && m >= B.length - 15;
892
+ !_ && !A.length && /* @__PURE__ */ e("div", { style: p.messageHint, children: B.noMessages }),
893
+ A.map((c, y) => {
894
+ const b = ($ == null ? void 0 : $.flatMap((l) => l.messageEnrichments ?? [])) ?? [], M = c.direction === "inbound" && b.length > 0 && y >= A.length - 15, Z = M ? Ae(t, {
895
+ provider: i,
896
+ recentMessages: A.slice(-10),
897
+ linkContact: E,
898
+ refreshContactInfo: j,
899
+ sendMessage: async (l, u) => {
900
+ await o.sendMessage(t.id, l, u), await pe(void 0, !0);
901
+ }
902
+ }) : null;
875
903
  return /* @__PURE__ */ n("div", { children: [
876
- /* @__PURE__ */ e(Dt, { message: c, primary: s }),
877
- d && b.map((u, j) => {
878
- var ne;
879
- const H = (ne = c.text) == null ? void 0 : ne.match(u.pattern);
880
- return H ? /* @__PURE__ */ e(Mt, { children: u.render(H, Le(t)) }, j) : null;
904
+ /* @__PURE__ */ e(Kt, { message: c, primary: s }),
905
+ M && Z && b.map((l, u) => {
906
+ var W;
907
+ const R = (W = c.text) == null ? void 0 : W.match(l.pattern);
908
+ return R ? /* @__PURE__ */ e(Ot, { children: l.render(R, Z, c) }, `${c.id}-${u}`) : null;
881
909
  })
882
910
  ] }, c.id);
883
911
  })
884
912
  ] }),
885
- /* @__PURE__ */ e("div", { style: { display: "flex", gap: 6, flexWrap: "wrap", padding: "6px 14px 2px", borderTop: `1px solid ${l.line}` }, children: ["Cảm ơn bạn đã liên hệ 🙏", "Mình sẽ kiểm tra ngay", "Vui lòng chờ 1-2 phút"].map((c) => /* @__PURE__ */ e(
913
+ /* @__PURE__ */ e("div", { style: { display: "flex", gap: 6, flexWrap: "wrap", padding: "6px 14px 2px", borderTop: `1px solid ${d.line}` }, children: ["Cảm ơn bạn đã liên hệ 🙏", "Mình sẽ kiểm tra ngay", "Vui lòng chờ 1-2 phút"].map((c) => /* @__PURE__ */ e(
886
914
  "button",
887
915
  {
888
916
  type: "button",
889
- onClick: () => O(c),
917
+ onClick: () => w(c),
890
918
  style: {
891
919
  fontSize: 11,
892
920
  padding: "3px 10px",
@@ -901,18 +929,18 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
901
929
  },
902
930
  c
903
931
  )) }),
904
- /* @__PURE__ */ n("form", { onSubmit: me, style: { flex: "0 0 auto", padding: "8px 14px 12px", borderTop: `1px solid ${l.line}`, background: l.white, position: "relative" }, children: [
905
- T && /* @__PURE__ */ n(
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(
906
934
  "div",
907
935
  {
908
- ref: ee,
936
+ ref: ye,
909
937
  style: {
910
938
  position: "absolute",
911
939
  bottom: "calc(100% + 6px)",
912
940
  left: 0,
913
941
  zIndex: 100,
914
- background: l.white,
915
- border: `1px solid ${l.line}`,
942
+ background: d.white,
943
+ border: `1px solid ${d.line}`,
916
944
  borderRadius: 12,
917
945
  boxShadow: "0 8px 24px rgba(23,32,51,.14)",
918
946
  width: 280,
@@ -920,11 +948,11 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
920
948
  fontFamily: "inherit"
921
949
  },
922
950
  children: [
923
- /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${l.line}`, background: "#f9fafb" }, children: qe.map((c, m) => /* @__PURE__ */ e(
951
+ /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Je.map((c, y) => /* @__PURE__ */ e(
924
952
  "button",
925
953
  {
926
954
  type: "button",
927
- onClick: () => ae(m),
955
+ onClick: () => V(y),
928
956
  style: {
929
957
  flex: 1,
930
958
  border: 0,
@@ -933,19 +961,19 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
933
961
  fontSize: 16,
934
962
  cursor: "pointer",
935
963
  lineHeight: 1,
936
- borderBottom: q === m ? `2px solid ${s}` : "2px solid transparent",
937
- opacity: q === m ? 1 : 0.5,
964
+ borderBottom: re === y ? `2px solid ${s}` : "2px solid transparent",
965
+ opacity: re === y ? 1 : 0.5,
938
966
  transition: "opacity 100ms ease"
939
967
  },
940
968
  children: c.icon
941
969
  },
942
- m
970
+ y
943
971
  )) }),
944
- /* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (we = qe[q]) == null ? void 0 : we.emojis.map((c, m) => /* @__PURE__ */ e(
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((c, y) => /* @__PURE__ */ e(
945
973
  "button",
946
974
  {
947
975
  type: "button",
948
- onClick: () => se(c),
976
+ onClick: () => ze(c),
949
977
  style: {
950
978
  border: 0,
951
979
  background: "transparent",
@@ -964,22 +992,22 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
964
992
  },
965
993
  children: c
966
994
  },
967
- m
995
+ y
968
996
  )) })
969
997
  ]
970
998
  }
971
999
  ),
972
- ce && /* @__PURE__ */ n(
1000
+ ue && /* @__PURE__ */ n(
973
1001
  "div",
974
1002
  {
975
- ref: Te,
1003
+ ref: Se,
976
1004
  style: {
977
1005
  position: "absolute",
978
1006
  bottom: "calc(100% + 6px)",
979
1007
  left: 0,
980
1008
  zIndex: 100,
981
- background: l.white,
982
- border: `1px solid ${l.line}`,
1009
+ background: d.white,
1010
+ border: `1px solid ${d.line}`,
983
1011
  borderRadius: 12,
984
1012
  boxShadow: "0 8px 24px rgba(23,32,51,.14)",
985
1013
  width: 300,
@@ -987,96 +1015,96 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
987
1015
  fontFamily: "inherit"
988
1016
  },
989
1017
  children: [
990
- /* @__PURE__ */ e("div", { style: { padding: "8px 10px", borderBottom: `1px solid ${l.line}` }, children: /* @__PURE__ */ e(
1018
+ /* @__PURE__ */ e("div", { style: { padding: "8px 10px", borderBottom: `1px solid ${d.line}` }, children: /* @__PURE__ */ e(
991
1019
  "input",
992
1020
  {
993
1021
  autoFocus: !0,
994
1022
  type: "text",
995
1023
  placeholder: "Tìm template…",
996
- value: te,
997
- onChange: (c) => ge(c.target.value),
998
- style: { width: "100%", boxSizing: "border-box", border: `1px solid ${l.line}`, borderRadius: 7, padding: "5px 8px", fontSize: 12, outline: "none", fontFamily: "inherit", color: l.ink }
1024
+ value: de,
1025
+ onChange: (c) => me(c.target.value),
1026
+ 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 }
999
1027
  }
1000
1028
  ) }),
1001
1029
  /* @__PURE__ */ e("div", { style: { maxHeight: 220, overflowY: "auto" }, children: (() => {
1002
- const c = te.trim().toLowerCase(), m = c ? ve.filter((b) => b.title.toLowerCase().includes(c) || b.content.toLowerCase().includes(c) || (b.shortcut ?? "").toLowerCase().includes(c)) : ve;
1003
- return m.length ? m.map((b) => /* @__PURE__ */ n(
1030
+ const c = de.trim().toLowerCase(), y = c ? we.filter((b) => b.title.toLowerCase().includes(c) || b.content.toLowerCase().includes(c) || (b.shortcut ?? "").toLowerCase().includes(c)) : we;
1031
+ return y.length ? y.map((b) => /* @__PURE__ */ n(
1004
1032
  "button",
1005
1033
  {
1006
1034
  type: "button",
1007
- onClick: () => He(b.content),
1008
- style: { display: "block", width: "100%", textAlign: "left", border: 0, borderBottom: `1px solid ${l.line}`, background: "transparent", padding: "9px 12px", cursor: "pointer", fontFamily: "inherit" },
1009
- onMouseEnter: (d) => {
1010
- d.currentTarget.style.background = "#f7f9fc";
1035
+ onClick: () => Te(b.content),
1036
+ 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";
1011
1039
  },
1012
- onMouseLeave: (d) => {
1013
- d.currentTarget.style.background = "transparent";
1040
+ onMouseLeave: (M) => {
1041
+ M.currentTarget.style.background = "transparent";
1014
1042
  },
1015
1043
  children: [
1016
1044
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 2 }, children: [
1017
- /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: l.ink }, children: b.title }),
1045
+ /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: d.ink }, children: b.title }),
1018
1046
  b.shortcut && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: s, background: `${s}18`, borderRadius: 4, padding: "1px 5px" }, children: b.shortcut })
1019
1047
  ] }),
1020
- /* @__PURE__ */ e("div", { style: { fontSize: 11, color: l.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: b.content })
1048
+ /* @__PURE__ */ e("div", { style: { fontSize: 11, color: d.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: b.content })
1021
1049
  ]
1022
1050
  },
1023
1051
  b.id
1024
- )) : /* @__PURE__ */ e("div", { style: { padding: "24px 16px", textAlign: "center", color: l.muted, fontSize: 12 }, children: ve.length === 0 ? "Chưa có template nào" : "Không tìm thấy" });
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" });
1025
1053
  })() })
1026
1054
  ]
1027
1055
  }
1028
1056
  ),
1029
- /* @__PURE__ */ n("div", { style: { border: `1.5px solid ${l.line}`, borderRadius: 12, background: l.white, overflow: "hidden" }, children: [
1030
- w && /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "8px 12px", borderBottom: `1px solid ${l.line}`, fontSize: 12 }, children: [
1031
- w.uploading ? /* @__PURE__ */ n(J, { children: [
1032
- /* @__PURE__ */ e(Oe, {}),
1033
- /* @__PURE__ */ e("span", { style: { color: l.muted }, children: "Đang tải lên…" })
1034
- ] }) : 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: l.muted }, children: [
1057
+ /* @__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: [
1060
+ /* @__PURE__ */ e(Fe, {}),
1061
+ /* @__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: [
1035
1063
  "📎 ",
1036
- w.file.name,
1064
+ x.file.name,
1037
1065
  " (",
1038
- Math.round(w.file.size / 1024),
1066
+ Math.round(x.file.size / 1024),
1039
1067
  " KB)"
1040
1068
  ] }),
1041
- !w.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1042
- w != null && w.objectUrl && URL.revokeObjectURL(w.objectUrl), ie(null);
1043
- }, style: { marginLeft: "auto", border: 0, background: "none", color: l.muted, cursor: "pointer", fontSize: 16 }, "aria-label": "Xóa tệp đính kèm", children: "✕" })
1069
+ !x.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1070
+ x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), J(null);
1071
+ }, style: { marginLeft: "auto", border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 16 }, "aria-label": "Xóa tệp đính kèm", children: "✕" })
1044
1072
  ] }),
1045
1073
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 2, padding: "4px 8px", borderBottom: "1px solid #f3f4f6" }, children: [
1046
1074
  /* @__PURE__ */ e(
1047
1075
  "button",
1048
1076
  {
1049
- ref: U,
1077
+ ref: ke,
1050
1078
  type: "button",
1051
1079
  title: "Chèn emoji",
1052
- onClick: () => $((c) => !c),
1053
- style: { ...f.toolbarBtn, background: T ? `${s}18` : "transparent", color: T ? s : "#9ca3af" },
1054
- children: /* @__PURE__ */ e(Tt, { size: 13, strokeWidth: 2 })
1080
+ onClick: () => ie((c) => !c),
1081
+ style: { ...p.toolbarBtn, background: q ? `${s}18` : "transparent", color: q ? s : "#9ca3af" },
1082
+ children: /* @__PURE__ */ e($t, { size: 13, strokeWidth: 2 })
1055
1083
  }
1056
1084
  ),
1057
- !C && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: f.toolbarBtn, onClick: () => {
1085
+ !I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: p.toolbarBtn, onClick: () => {
1058
1086
  var c;
1059
- return (c = oe.current) == null ? void 0 : c.click();
1060
- }, children: /* @__PURE__ */ e(vt, { size: 13, strokeWidth: 2 }) }),
1061
- !C && /* @__PURE__ */ e("button", { type: "button", title: "Gửi tệp đính kèm", "aria-label": "Gửi tệp đính kèm", style: f.toolbarBtn, onClick: () => {
1087
+ return (c = Q.current) == null ? void 0 : c.click();
1088
+ }, children: /* @__PURE__ */ e(Ct, { size: 13, strokeWidth: 2 }) }),
1089
+ !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: () => {
1062
1090
  var c;
1063
- return (c = ue.current) == null ? void 0 : c.click();
1064
- }, children: /* @__PURE__ */ e(St, { size: 13, strokeWidth: 2 }) }),
1065
- !C && /* @__PURE__ */ n(J, { children: [
1066
- /* @__PURE__ */ e("input", { ref: oe, type: "file", style: { display: "none" }, onChange: ye, accept: "image/*,video/mp4" }),
1067
- /* @__PURE__ */ e("input", { ref: ue, type: "file", style: { display: "none" }, onChange: ye, accept: ".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" })
1091
+ return (c = N.current) == null ? void 0 : c.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" })
1068
1096
  ] }),
1069
1097
  /* @__PURE__ */ e(
1070
1098
  "button",
1071
1099
  {
1072
- ref: Re,
1100
+ ref: Ce,
1073
1101
  type: "button",
1074
1102
  title: "Template nhanh",
1075
1103
  onClick: () => {
1076
- D((c) => !c), ge("");
1104
+ G((c) => !c), me("");
1077
1105
  },
1078
- style: { ...f.toolbarBtn, background: ce ? `${s}18` : "transparent", color: ce ? s : "#9ca3af" },
1079
- children: /* @__PURE__ */ e(Rt, { size: 13, strokeWidth: 2 })
1106
+ style: { ...p.toolbarBtn, background: ue ? `${s}18` : "transparent", color: ue ? s : "#9ca3af" },
1107
+ children: /* @__PURE__ */ e(Lt, { size: 13, strokeWidth: 2 })
1080
1108
  }
1081
1109
  ),
1082
1110
  /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 2px" } }),
@@ -1085,8 +1113,8 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
1085
1113
  {
1086
1114
  type: "button",
1087
1115
  title: "In đậm",
1088
- onClick: () => fe((c) => !c),
1089
- style: { ...f.toolbarBtn, fontWeight: 700, fontSize: 12, background: Q ? `${s}18` : "transparent", color: Q ? s : "#9ca3af", border: Q ? `1px solid ${s}33` : "1px solid transparent" },
1116
+ onClick: () => h((c) => !c),
1117
+ style: { ...p.toolbarBtn, fontWeight: 700, fontSize: 12, background: se ? `${s}18` : "transparent", color: se ? s : "#9ca3af", border: se ? `1px solid ${s}33` : "1px solid transparent" },
1090
1118
  children: "B"
1091
1119
  }
1092
1120
  ),
@@ -1095,38 +1123,52 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
1095
1123
  {
1096
1124
  type: "button",
1097
1125
  title: "Nghiêng",
1098
- onClick: () => p((c) => !c),
1099
- style: { ...f.toolbarBtn, fontStyle: "italic", fontSize: 12, background: le ? `${s}18` : "transparent", color: le ? s : "#9ca3af", border: le ? `1px solid ${s}33` : "1px solid transparent" },
1126
+ onClick: () => P((c) => !c),
1127
+ style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background: T ? `${s}18` : "transparent", color: T ? s : "#9ca3af", border: T ? `1px solid ${s}33` : "1px solid transparent" },
1100
1128
  children: "I"
1101
1129
  }
1102
1130
  ),
1103
- W == null ? void 0 : W.flatMap((c) => c.toolbarActions ?? []).map((c, m) => /* @__PURE__ */ e(
1131
+ $ == null ? void 0 : $.flatMap((c) => c.toolbarActions ?? []).map((c, y) => /* @__PURE__ */ e(
1104
1132
  "button",
1105
1133
  {
1106
1134
  type: "button",
1107
1135
  title: c.tooltip,
1108
- style: f.toolbarBtn,
1136
+ style: p.toolbarBtn,
1109
1137
  onClick: () => {
1110
- const b = (d) => O((u) => u + d);
1111
- c.onClick({ ...Le(t), insertText: b });
1138
+ const b = (Z) => {
1139
+ w((l) => l && !l.endsWith(" ") && !l.endsWith(`
1140
+ `) ? `${l} ${Z}` : `${l}${Z}`), requestAnimationFrame(() => {
1141
+ var l;
1142
+ return (l = be.current) == null ? void 0 : l.focus();
1143
+ });
1144
+ }, M = Ae(t, {
1145
+ provider: i,
1146
+ recentMessages: A.slice(-10),
1147
+ linkContact: E,
1148
+ refreshContactInfo: j,
1149
+ sendMessage: async (Z, l) => {
1150
+ await o.sendMessage(t.id, Z, l), await pe(void 0, !0);
1151
+ }
1152
+ });
1153
+ c.onClick({ ...M, insertText: b });
1112
1154
  },
1113
1155
  children: c.icon
1114
1156
  },
1115
- m
1157
+ y
1116
1158
  ))
1117
1159
  ] }),
1118
1160
  /* @__PURE__ */ e(
1119
- $t,
1161
+ jt,
1120
1162
  {
1121
- ref: de,
1163
+ ref: be,
1122
1164
  "aria-label": "Soạn tin nhắn",
1123
1165
  rows: 2,
1124
- value: M,
1125
- onChange: (c) => O(c.target.value),
1166
+ value: U,
1167
+ onChange: (c) => w(c.target.value),
1126
1168
  onKeyDown: (c) => {
1127
- c.key === "Enter" && !c.shiftKey && (c.preventDefault(), me(c));
1169
+ c.key === "Enter" && !c.shiftKey && (c.preventDefault(), oe(c));
1128
1170
  },
1129
- placeholder: L.sendPlaceholder,
1171
+ placeholder: B.sendPlaceholder,
1130
1172
  style: {
1131
1173
  display: "block",
1132
1174
  width: "100%",
@@ -1138,31 +1180,31 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
1138
1180
  border: 0,
1139
1181
  outline: 0,
1140
1182
  background: "transparent",
1141
- color: l.ink,
1183
+ color: d.ink,
1142
1184
  padding: "8px 12px 4px",
1143
1185
  font: "inherit",
1144
1186
  fontSize: 13,
1145
1187
  lineHeight: 1.45,
1146
- fontStyle: le ? "italic" : "normal",
1147
- fontWeight: Q ? 700 : 400
1188
+ fontStyle: T ? "italic" : "normal",
1189
+ fontWeight: se ? 700 : 400
1148
1190
  }
1149
1191
  }
1150
1192
  ),
1151
1193
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 8px 6px 12px" }, children: [
1152
1194
  /* @__PURE__ */ n("span", { style: {
1153
1195
  fontSize: 11,
1154
- color: M.length > 1e3 ? "#ef4444" : M.length > 900 ? "#f59e0b" : "#9ca3af",
1155
- fontWeight: M.length > 1e3 ? 600 : 400
1196
+ color: U.length > 1e3 ? "#ef4444" : U.length > 900 ? "#f59e0b" : "#9ca3af",
1197
+ fontWeight: U.length > 1e3 ? 600 : 400
1156
1198
  }, children: [
1157
- M.length,
1199
+ U.length,
1158
1200
  "/1000"
1159
1201
  ] }),
1160
1202
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
1161
- !R && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1203
+ !H && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1162
1204
  /* @__PURE__ */ n(
1163
1205
  "button",
1164
1206
  {
1165
- disabled: !he,
1207
+ disabled: !ae,
1166
1208
  "aria-label": "Gửi tin nhắn",
1167
1209
  style: {
1168
1210
  display: "flex",
@@ -1173,15 +1215,15 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
1173
1215
  borderRadius: 999,
1174
1216
  fontSize: 12,
1175
1217
  fontWeight: 600,
1176
- background: he ? `linear-gradient(135deg,${s},#0ea5e9)` : "#e5e7eb",
1177
- color: he ? "#fff" : "#9ca3af",
1178
- cursor: he ? "pointer" : "not-allowed",
1179
- boxShadow: he ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1218
+ background: ae ? `linear-gradient(135deg,${s},#0ea5e9)` : "#e5e7eb",
1219
+ color: ae ? "#fff" : "#9ca3af",
1220
+ cursor: ae ? "pointer" : "not-allowed",
1221
+ boxShadow: ae ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1180
1222
  transition: "all 150ms ease"
1181
1223
  },
1182
1224
  children: [
1183
- V ? /* @__PURE__ */ e(it, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(It, { size: 12, strokeWidth: 2 }),
1184
- L.send
1225
+ L ? /* @__PURE__ */ e(lt, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(Bt, { size: 12, strokeWidth: 2 }),
1226
+ B.send
1185
1227
  ]
1186
1228
  }
1187
1229
  )
@@ -1189,202 +1231,264 @@ function Ut({ conversation: t, provider: i, connection: r, client: o, primary: s
1189
1231
  ] })
1190
1232
  ] })
1191
1233
  ] }),
1192
- (S || k) && /* @__PURE__ */ e("div", { role: "alert", style: f.error, children: S || k })
1234
+ (z || C) && /* @__PURE__ */ e("div", { role: "alert", style: p.error, children: z || C })
1193
1235
  ] });
1194
1236
  }
1195
- function Dt({ message: t, primary: i }) {
1196
- var M, O, Y, I, V;
1197
- const r = Ae(Pe), o = Ae(at), s = (h) => h.startsWith("/v1/media/proxy") ? `${r}${h}&tok=${encodeURIComponent(o)}` : h, k = t.direction === "outbound", x = ((M = t.attachments) == null ? void 0 : M.filter((h) => h.type === "image")) ?? [], E = ((O = t.attachments) == null ? void 0 : O.filter((h) => h.type === "sticker")) ?? [], g = ((Y = t.attachments) == null ? void 0 : Y.filter((h) => h.type === "video")) ?? [], v = ((I = t.attachments) == null ? void 0 : I.filter((h) => h.type === "audio")) ?? [], L = ((V = t.attachments) == null ? void 0 : V.filter((h) => h.type === "file")) ?? [], [C, R] = y(null), W = k ? "flex-end" : "flex-start", B = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
1198
- Ue(t.occurredAt, !0),
1199
- k && /* @__PURE__ */ n(J, { children: [
1237
+ function Kt({ message: t, primary: i }) {
1238
+ var K, ne, U, w, _;
1239
+ 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")) ?? [], B = ((_ = t.attachments) == null ? void 0 : _.filter((k) => k.type === "file")) ?? [], [I, H] = g(null), $ = 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: [
1240
+ Ke(t.occurredAt, !0),
1241
+ C && /* @__PURE__ */ n(te, { children: [
1200
1242
  " ",
1201
- /* @__PURE__ */ e(Ge, { status: t.status })
1243
+ /* @__PURE__ */ e(_e, { status: t.status })
1202
1244
  ] })
1203
- ] }), A = /* @__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: [
1204
- Ue(t.occurredAt, !0),
1205
- k && /* @__PURE__ */ n(J, { children: [
1245
+ ] }), 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: [
1246
+ Ke(t.occurredAt, !0),
1247
+ C && /* @__PURE__ */ n(te, { children: [
1206
1248
  " ",
1207
- /* @__PURE__ */ e(Ge, { status: t.status })
1249
+ /* @__PURE__ */ e(_e, { status: t.status })
1208
1250
  ] })
1209
- ] }) }), Z = k ? { ...f.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : f.bubbleIn, N = !t.text && v.length === 0 && L.length === 0;
1210
- return /* @__PURE__ */ n("div", { style: { ...f.messageLine, justifyContent: W, flexDirection: "column", alignItems: W }, children: [
1211
- E.map((h, S) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1212
- /* @__PURE__ */ e("img", { src: s(h.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1213
- N && x.length === 0 && g.length === 0 && S === E.length - 1 && A
1214
- ] }, `s${S}`)),
1215
- x.map((h, S) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => R({ url: s(h.url), kind: "image" }), children: [
1216
- /* @__PURE__ */ e("img", { src: s(h.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1217
- N && S === x.length - 1 && g.length === 0 && A
1218
- ] }, S)),
1219
- g.map((h, S) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => R({ url: s(h.url), kind: "video" }), children: [
1220
- /* @__PURE__ */ e("video", { src: s(h.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1221
- /* @__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(Ct, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
1222
- N && S === g.length - 1 && A
1223
- ] }, S)),
1224
- (v.length > 0 || L.length > 0 || t.text || !x.length && !g.length && !E.length && !t.text) && /* @__PURE__ */ n("div", { style: Z, children: [
1225
- v.map((h, S) => /* @__PURE__ */ e("audio", { src: s(h.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, S)),
1226
- L.map((h, S) => /* @__PURE__ */ n("a", { href: s(h.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: k ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
1251
+ ] }) }), A = C ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, F = !t.text && S.length === 0 && B.length === 0;
1252
+ return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent: $, flexDirection: "column", alignItems: $ }, children: [
1253
+ O.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1254
+ /* @__PURE__ */ e("img", { src: s(k.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1255
+ F && m.length === 0 && f.length === 0 && L === O.length - 1 && j
1256
+ ] }, `s${L}`)),
1257
+ m.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => H({ url: s(k.url), kind: "image" }), children: [
1258
+ /* @__PURE__ */ e("img", { src: s(k.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1259
+ F && L === m.length - 1 && f.length === 0 && j
1260
+ ] }, L)),
1261
+ f.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => H({ url: s(k.url), kind: "video" }), children: [
1262
+ /* @__PURE__ */ e("video", { src: s(k.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1263
+ /* @__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 } }) }) }),
1264
+ F && L === f.length - 1 && j
1265
+ ] }, L)),
1266
+ (S.length > 0 || B.length > 0 || t.text || !m.length && !f.length && !O.length && !t.text) && /* @__PURE__ */ n("div", { style: A, children: [
1267
+ S.map((k, L) => /* @__PURE__ */ e("audio", { src: s(k.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, L)),
1268
+ B.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: [
1227
1269
  "📎 ",
1228
- At(h.mimeType)
1229
- ] }, S)),
1270
+ Pt(k.mimeType)
1271
+ ] }, L)),
1230
1272
  t.text && /* @__PURE__ */ e("p", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: t.text }),
1231
- !v.length && !L.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1232
- B
1273
+ !S.length && !B.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1274
+ E
1233
1275
  ] }),
1234
- C && Qe(
1235
- /* @__PURE__ */ n("div", { onClick: () => R(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
1236
- C.kind === "image" ? /* @__PURE__ */ e("img", { src: C.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (h) => h.stopPropagation() }) : /* @__PURE__ */ e("video", { src: C.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (h) => h.stopPropagation() }),
1237
- /* @__PURE__ */ e("button", { onClick: () => R(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(We, { size: 18 }) })
1276
+ I && it(
1277
+ /* @__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: [
1278
+ 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() }),
1279
+ /* @__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 }) })
1238
1280
  ] }),
1239
1281
  document.body
1240
1282
  )
1241
1283
  ] });
1242
1284
  }
1243
- function Pt({
1285
+ function qt({
1244
1286
  conversation: t,
1245
1287
  connection: i,
1246
1288
  primary: r,
1247
1289
  onClose: o,
1248
1290
  client: s,
1249
- onStartResize: k,
1250
- extensions: x
1291
+ onStartResize: C,
1292
+ extensions: m,
1293
+ extRefreshKey: O,
1294
+ onLinkContact: f,
1295
+ onRefreshContactInfo: S
1251
1296
  }) {
1252
- const E = t.contactName ?? t.subject ?? t.providerConversationKey, g = i == null ? void 0 : i.provider, [v, L] = y({ channel: !0, stats: !1, extra: !1 }), C = (h) => L((S) => ({ ...S, [h]: !S[h] })), [R, W] = y(""), [B, A] = y(!1), [Z, N] = y(!1), [M, O] = y(""), [Y, I] = y([]);
1253
- F(() => {
1254
- W(""), N(!1), O(""), s.getNote(t.id).then((h) => {
1255
- h && W(h.content);
1297
+ const B = t.contactName ?? t.subject ?? t.providerConversationKey, I = i == null ? void 0 : i.provider, H = !!(m != null && m.some((v) => v.contactInfoRows)), [$, E] = g({ channel: !0, stats: !1, extra: !0 }), j = (v) => E((Q) => ({ ...Q, [v]: !Q[v] })), [A, F] = g(""), [K, ne] = g(!1), [U, w] = g(!1), [_, k] = g(""), [L, ce] = g([]), [z, D] = g(!1);
1298
+ Y(() => {
1299
+ F(""), w(!1), k(""), s.getNote(t.id).then((v) => {
1300
+ v && F(v.content);
1256
1301
  }).catch(() => {
1257
1302
  });
1258
- }, [t.id, s]), F(() => {
1259
- if (!(x != null && x.some((S) => S.contactInfoRows))) return;
1260
- const h = Le(t);
1261
- I([]), Promise.allSettled(
1262
- x.filter((S) => S.contactInfoRows).map((S) => S.contactInfoRows(h))
1263
- ).then((S) => {
1264
- const _ = S.filter((z) => z.status === "fulfilled").flatMap((z) => z.value);
1265
- I(_);
1303
+ }, [t.id, s]), Y(() => {
1304
+ if (!H || !m) return;
1305
+ let v = !1;
1306
+ const Q = Ae(t, {
1307
+ provider: I,
1308
+ linkContact: f,
1309
+ refreshContactInfo: S,
1310
+ sendMessage: async (N, x) => {
1311
+ await s.sendMessage(t.id, N, x);
1312
+ }
1266
1313
  });
1267
- }, [t.id, x]);
1268
- async function V() {
1269
- if (!(!R.trim() || B)) {
1270
- A(!0), O("");
1314
+ return D(!0), Promise.allSettled(
1315
+ m.filter((N) => N.contactInfoRows).map((N) => N.contactInfoRows(Q))
1316
+ ).then((N) => {
1317
+ if (v) return;
1318
+ const x = N.filter((J) => J.status === "fulfilled").flatMap((J) => J.value);
1319
+ ce(x), D(!1);
1320
+ }), () => {
1321
+ v = !0;
1322
+ };
1323
+ }, [t.id, t.contactExternalId, m, O, H, I, f, S, s]);
1324
+ async function le() {
1325
+ if (!(!A.trim() || K)) {
1326
+ ne(!0), k("");
1271
1327
  try {
1272
- await s.upsertNote(t.id, R.trim()), N(!0), setTimeout(() => N(!1), 2e3);
1328
+ await s.upsertNote(t.id, A.trim()), w(!0), setTimeout(() => w(!1), 2e3);
1273
1329
  } catch {
1274
- O("Lưu thất bại");
1330
+ k("Lưu thất bại");
1275
1331
  } finally {
1276
- A(!1);
1332
+ ne(!1);
1277
1333
  }
1278
1334
  }
1279
1335
  }
1280
- return /* @__PURE__ */ n("aside", { style: { ...f.infoPanel, position: "relative" }, children: [
1336
+ return /* @__PURE__ */ n("aside", { style: { ...p.infoPanel, position: "relative" }, children: [
1281
1337
  /* @__PURE__ */ e(
1282
1338
  "div",
1283
1339
  {
1284
- onMouseDown: k,
1340
+ onMouseDown: C,
1285
1341
  style: { position: "absolute", left: 0, top: 0, bottom: 0, width: 4, cursor: "col-resize", zIndex: 1 },
1286
- onMouseEnter: (h) => {
1287
- h.currentTarget.style.background = "rgba(0,0,0,0.07)";
1342
+ onMouseEnter: (v) => {
1343
+ v.currentTarget.style.background = "rgba(0,0,0,0.07)";
1288
1344
  },
1289
- onMouseLeave: (h) => {
1290
- h.currentTarget.style.background = "";
1345
+ onMouseLeave: (v) => {
1346
+ v.currentTarget.style.background = "";
1291
1347
  }
1292
1348
  }
1293
1349
  ),
1294
- /* @__PURE__ */ n("div", { style: f.infoPanelHeader, children: [
1295
- /* @__PURE__ */ e("span", { style: { fontWeight: 600, fontSize: 13, color: l.ink }, children: "Thông tin liên hệ" }),
1296
- /* @__PURE__ */ e("button", { style: f.iconButton, onClick: o, "aria-label": "Đóng", children: /* @__PURE__ */ e(We, { size: 16, strokeWidth: 2 }) })
1350
+ /* @__PURE__ */ n("div", { style: p.infoPanelHeader, children: [
1351
+ /* @__PURE__ */ e("span", { style: { fontWeight: 600, fontSize: 13, color: d.ink }, children: "Thông tin liên hệ" }),
1352
+ /* @__PURE__ */ e("button", { style: p.iconButton, onClick: o, "aria-label": "Đóng", children: /* @__PURE__ */ e(je, { size: 16, strokeWidth: 2 }) })
1297
1353
  ] }),
1298
1354
  /* @__PURE__ */ n("div", { style: { overflowY: "auto", flex: 1 }, children: [
1299
- /* @__PURE__ */ n("div", { style: f.infoPanelIdentity, children: [
1300
- /* @__PURE__ */ n("span", { style: { ...f.avatarWrap, width: 48, height: 48 }, children: [
1355
+ /* @__PURE__ */ n("div", { style: p.infoPanelIdentity, children: [
1356
+ /* @__PURE__ */ n("span", { style: { ...p.avatarWrap, width: 48, height: 48 }, children: [
1301
1357
  /* @__PURE__ */ e(
1302
- rt,
1358
+ dt,
1303
1359
  {
1304
1360
  src: t.contactPictureUrl,
1305
- fallback: ct(E),
1306
- style: { ...f.avatar, width: 48, height: 48, fontSize: 16 }
1361
+ fallback: ut(B),
1362
+ style: { ...p.avatar, width: 48, height: 48, fontSize: 16 }
1307
1363
  }
1308
1364
  ),
1309
- /* @__PURE__ */ e("span", { style: { ...f.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e(Ie, { provider: g }) })
1365
+ /* @__PURE__ */ e("span", { style: { ...p.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e($e, { provider: I }) })
1310
1366
  ] }),
1311
- /* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: l.ink, textAlign: "center" }, children: E }),
1312
- /* @__PURE__ */ e("span", { style: { fontSize: 11, color: l.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
1367
+ /* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: B }),
1368
+ /* @__PURE__ */ e("span", { style: { fontSize: 11, color: d.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
1313
1369
  ] }),
1314
- /* @__PURE__ */ n(Me, { label: "KÊNH", sectionKey: "channel", expanded: v.channel, onToggle: () => C("channel"), children: [
1315
- /* @__PURE__ */ e(re, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
1316
- /* @__PURE__ */ e(Ie, { provider: g }),
1317
- /* @__PURE__ */ e("span", { children: lt(g) })
1370
+ /* @__PURE__ */ n(Ue, { label: "KÊNH", sectionKey: "channel", expanded: $.channel, onToggle: () => j("channel"), children: [
1371
+ /* @__PURE__ */ e(he, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
1372
+ /* @__PURE__ */ e($e, { provider: I }),
1373
+ /* @__PURE__ */ e("span", { children: ht(I) })
1318
1374
  ] }) }),
1319
- /* @__PURE__ */ n(re, { label: "ID hội thoại", children: [
1375
+ /* @__PURE__ */ n(he, { label: "ID hội thoại", children: [
1320
1376
  /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", fontSize: 11 }, children: [
1321
1377
  t.id.slice(0, 8),
1322
1378
  "…"
1323
1379
  ] }),
1324
- /* @__PURE__ */ e(Nt, { value: t.id })
1380
+ /* @__PURE__ */ e(Vt, { value: t.id })
1325
1381
  ] })
1326
1382
  ] }),
1327
- /* @__PURE__ */ n(Me, { label: "THỐNG KÊ", sectionKey: "stats", expanded: v.stats, onToggle: () => C("stats"), children: [
1328
- /* @__PURE__ */ e(re, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
1329
- (t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(re, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
1383
+ /* @__PURE__ */ n(Ue, { label: "THỐNG KÊ", sectionKey: "stats", expanded: $.stats, onToggle: () => j("stats"), children: [
1384
+ /* @__PURE__ */ e(he, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
1385
+ (t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(he, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
1330
1386
  /* @__PURE__ */ e(
1331
- re,
1387
+ he,
1332
1388
  {
1333
1389
  label: "Gần nhất",
1334
1390
  value: t.lastMessageAt ? new Date(t.lastMessageAt).toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit", year: "numeric" }) : "—"
1335
1391
  }
1336
1392
  ),
1337
- /* @__PURE__ */ e(re, { label: "Lần đầu", value: "—" })
1393
+ /* @__PURE__ */ e(he, { label: "Lần đầu", value: "—" })
1338
1394
  ] }),
1339
- /* @__PURE__ */ n(Me, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: v.extra, onToggle: () => C("extra"), children: [
1340
- /* @__PURE__ */ e(re, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
1341
- /* @__PURE__ */ e(re, { label: "Email", value: "— chưa có", valueMuted: !0 }),
1342
- /* @__PURE__ */ e(re, { label: "Nhãn", value: "— chưa có", valueMuted: !0 }),
1343
- Y.map((h) => /* @__PURE__ */ e(re, { label: h.label, children: h.href ? /* @__PURE__ */ e("a", { href: h.href, target: "_blank", rel: "noopener noreferrer", style: { color: r, fontSize: 12 }, children: h.value }) : /* @__PURE__ */ e("span", { style: { fontSize: 12 }, children: h.value }) }, h.label))
1395
+ /* @__PURE__ */ n(Ue, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: $.extra, onToggle: () => j("extra"), children: [
1396
+ !H && /* @__PURE__ */ n(te, { children: [
1397
+ /* @__PURE__ */ e(he, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
1398
+ /* @__PURE__ */ e(he, { label: "Email", value: "— chưa có", valueMuted: !0 }),
1399
+ /* @__PURE__ */ e(he, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
1400
+ ] }),
1401
+ z && L.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
1402
+ L.map((v) => /* @__PURE__ */ e(he, { label: v.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
1403
+ v.onClick ? /* @__PURE__ */ e(
1404
+ "button",
1405
+ {
1406
+ type: "button",
1407
+ onClick: v.onClick,
1408
+ style: { border: 0, background: "none", padding: 0, color: r, fontSize: 12, fontWeight: 600, cursor: "pointer", textDecoration: "underline" },
1409
+ children: v.value
1410
+ }
1411
+ ) : 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 }),
1412
+ v.badge && /* @__PURE__ */ e(
1413
+ "span",
1414
+ {
1415
+ style: {
1416
+ fontSize: 10.5,
1417
+ fontWeight: 700,
1418
+ padding: "1px 7px",
1419
+ borderRadius: 999,
1420
+ color: v.badge.color ?? r,
1421
+ background: v.badge.bg ?? `${r}14`
1422
+ },
1423
+ children: v.badge.text
1424
+ }
1425
+ )
1426
+ ] }) }, v.label))
1344
1427
  ] }),
1345
1428
  /* @__PURE__ */ n("div", { style: { padding: "12px 16px", display: "flex", flexDirection: "column", gap: 8 }, children: [
1346
- /* @__PURE__ */ e("button", { style: { ...f.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1347
- x == null ? void 0 : x.flatMap((h) => h.sidebarActions ?? []).map((h, S) => /* @__PURE__ */ n(
1348
- "button",
1349
- {
1350
- style: { ...f.ghostButton, color: l.ink, borderColor: l.line, display: "flex", alignItems: "center", justifyContent: "center", gap: 6 },
1351
- onClick: () => {
1352
- h.onClick(Le(t));
1429
+ !(m != null && m.length) && /* @__PURE__ */ e("button", { style: { ...p.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1430
+ m == null ? void 0 : m.flatMap((v) => v.sidebarActions ?? []).map((v, Q) => {
1431
+ const N = v.variant === "primary";
1432
+ return /* @__PURE__ */ n(
1433
+ "button",
1434
+ {
1435
+ style: {
1436
+ ...p.ghostButton,
1437
+ background: N ? r : "#fff",
1438
+ color: N ? "#fff" : d.ink,
1439
+ borderColor: N ? r : d.line,
1440
+ fontWeight: N ? 700 : 600,
1441
+ display: "flex",
1442
+ alignItems: "center",
1443
+ justifyContent: "center",
1444
+ gap: 6
1445
+ },
1446
+ onClick: () => {
1447
+ const x = Ae(t, {
1448
+ provider: I,
1449
+ linkContact: f,
1450
+ refreshContactInfo: S,
1451
+ sendMessage: async (J, se) => {
1452
+ await s.sendMessage(t.id, J, se);
1453
+ }
1454
+ });
1455
+ v.onClick(x);
1456
+ },
1457
+ children: [
1458
+ v.icon,
1459
+ v.label
1460
+ ]
1353
1461
  },
1354
- children: [
1355
- h.icon,
1356
- h.label
1357
- ]
1358
- },
1359
- S
1360
- )),
1462
+ Q
1463
+ );
1464
+ }),
1361
1465
  /* @__PURE__ */ n("div", { style: { border: "1.5px solid #000", borderRadius: 10, background: "#fff", overflow: "hidden" }, children: [
1362
1466
  /* @__PURE__ */ e("div", { style: { display: "flex", alignItems: "center", gap: 6, padding: "7px 10px", borderBottom: "1px solid #fde68a", fontSize: 11, fontWeight: 600, color: "#92400e" }, children: "Ghi chú nội bộ" }),
1363
1467
  /* @__PURE__ */ e(
1364
1468
  "textarea",
1365
1469
  {
1366
- value: R,
1367
- onChange: (h) => W(h.target.value),
1470
+ value: A,
1471
+ onChange: (v) => F(v.target.value),
1368
1472
  placeholder: "Nhập ghi chú...",
1369
1473
  rows: 3,
1370
- style: { display: "block", width: "100%", boxSizing: "border-box", border: 0, outline: 0, background: "transparent", resize: "none", padding: "8px 10px", font: "inherit", fontSize: 12, color: l.ink, lineHeight: 1.5 }
1474
+ 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 }
1371
1475
  }
1372
1476
  ),
1373
1477
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 10px 6px" }, children: [
1374
- Z ? /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, fontSize: 11, color: "#16a34a" }, children: [
1375
- /* @__PURE__ */ e(tt, { size: 11, strokeWidth: 2.5 }),
1478
+ U ? /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, fontSize: 11, color: "#16a34a" }, children: [
1479
+ /* @__PURE__ */ e(ot, { size: 11, strokeWidth: 2.5 }),
1376
1480
  " Đã lưu"
1377
- ] }) : M ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: M }) : /* @__PURE__ */ e("span", {}),
1481
+ ] }) : _ ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: _ }) : /* @__PURE__ */ e("span", {}),
1378
1482
  /* @__PURE__ */ e(
1379
1483
  "button",
1380
1484
  {
1381
1485
  type: "button",
1382
1486
  onClick: () => {
1383
- V();
1487
+ le();
1384
1488
  },
1385
- disabled: !R.trim() || B,
1386
- style: { padding: "4px 12px", border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: R.trim() && !B ? "linear-gradient(135deg,#f59e0b,#fbbf24)" : "#e5e7eb", color: R.trim() && !B ? "#fff" : "#9ca3af", cursor: R.trim() && !B ? "pointer" : "not-allowed" },
1387
- children: B ? "Đang lưu…" : "Lưu ghi chú"
1489
+ disabled: !A.trim() || K,
1490
+ 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" },
1491
+ children: K ? "Đang lưu…" : "Lưu ghi chú"
1388
1492
  }
1389
1493
  )
1390
1494
  ] })
@@ -1393,35 +1497,35 @@ function Pt({
1393
1497
  ] })
1394
1498
  ] });
1395
1499
  }
1396
- function Me({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s }) {
1397
- const k = !!s, x = o ?? !0;
1398
- return /* @__PURE__ */ n("div", { style: { borderTop: `1px solid ${l.line}` }, children: [
1500
+ function Ue({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s }) {
1501
+ const C = !!s, m = o ?? !0;
1502
+ return /* @__PURE__ */ n("div", { style: { borderTop: `1px solid ${d.line}` }, children: [
1399
1503
  /* @__PURE__ */ n(
1400
1504
  "div",
1401
1505
  {
1402
- style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: l.muted, textTransform: "uppercase", cursor: k ? "pointer" : "default" },
1506
+ 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" },
1403
1507
  onClick: s,
1404
1508
  children: [
1405
1509
  /* @__PURE__ */ e("span", { children: t }),
1406
- k && (x ? /* @__PURE__ */ e(mt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(bt, { size: 12, strokeWidth: 2 }))
1510
+ C && (m ? /* @__PURE__ */ e(kt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(wt, { size: 12, strokeWidth: 2 }))
1407
1511
  ]
1408
1512
  }
1409
1513
  ),
1410
- x && i
1514
+ m && i
1411
1515
  ] });
1412
1516
  }
1413
- function re({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
1517
+ function he({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
1414
1518
  return /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: "3px 16px", fontSize: 12, gap: 8 }, children: [
1415
- /* @__PURE__ */ e("span", { style: { color: l.muted, flexShrink: 0 }, children: t }),
1416
- /* @__PURE__ */ e("span", { style: { color: o ?? (s ? l.muted : l.ink), textAlign: "right", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", display: "flex", alignItems: "center", gap: 4 }, children: r ?? i })
1519
+ /* @__PURE__ */ e("span", { style: { color: d.muted, flexShrink: 0 }, children: t }),
1520
+ /* @__PURE__ */ e("span", { style: { color: o ?? (s ? d.muted : d.ink), textAlign: "right", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", display: "flex", alignItems: "center", gap: 4 }, children: r ?? i })
1417
1521
  ] });
1418
1522
  }
1419
- function Nt({ value: t }) {
1420
- const [i, r] = y(!1);
1523
+ function Vt({ value: t }) {
1524
+ const [i, r] = g(!1);
1421
1525
  return /* @__PURE__ */ e(
1422
1526
  "button",
1423
1527
  {
1424
- style: { border: 0, background: "none", cursor: "pointer", color: l.muted, padding: 2, lineHeight: 1 },
1528
+ style: { border: 0, background: "none", cursor: "pointer", color: d.muted, padding: 2, lineHeight: 1 },
1425
1529
  title: "Sao chép",
1426
1530
  onClick: () => {
1427
1531
  navigator.clipboard.writeText(t).then(() => {
@@ -1433,52 +1537,52 @@ function Nt({ value: t }) {
1433
1537
  }
1434
1538
  );
1435
1539
  }
1436
- function Ft() {
1437
- return /* @__PURE__ */ n("div", { style: f.empty, children: [
1438
- /* @__PURE__ */ e("div", { style: f.emptyHero, children: /* @__PURE__ */ e(kt, { size: 16, strokeWidth: 2 }) }),
1540
+ function Gt() {
1541
+ return /* @__PURE__ */ n("div", { style: p.empty, children: [
1542
+ /* @__PURE__ */ e("div", { style: p.emptyHero, children: /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }) }),
1439
1543
  /* @__PURE__ */ e("h2", { children: "Chọn một hội thoại" }),
1440
1544
  /* @__PURE__ */ e("p", { children: "Chọn hội thoại bên trái để xem và trả lời tin nhắn." })
1441
1545
  ] });
1442
1546
  }
1443
- function dt({ name: t, color: i, image: r, provider: o }) {
1444
- return /* @__PURE__ */ n("span", { style: f.avatarWrap, children: [
1445
- /* @__PURE__ */ e(Kt, { name: t, color: i, image: r }),
1446
- o && /* @__PURE__ */ e("span", { style: f.providerBadge, children: /* @__PURE__ */ e(Ie, { provider: o }) })
1547
+ function pt({ name: t, color: i, image: r, provider: o }) {
1548
+ return /* @__PURE__ */ n("span", { style: p.avatarWrap, children: [
1549
+ /* @__PURE__ */ e(Xt, { name: t, color: i, image: r }),
1550
+ o && /* @__PURE__ */ e("span", { style: p.providerBadge, children: /* @__PURE__ */ e($e, { provider: o }) })
1447
1551
  ] });
1448
1552
  }
1449
- function Kt({ name: t, color: i, image: r }) {
1450
- return /* @__PURE__ */ e(rt, { src: r, fallback: ct(t), style: { ...f.avatar, background: `${i}18`, color: i } });
1553
+ function Xt({ name: t, color: i, image: r }) {
1554
+ return /* @__PURE__ */ e(dt, { src: r, fallback: ut(t), style: { ...p.avatar, background: `${i}18`, color: i } });
1451
1555
  }
1452
- function Oe() {
1453
- return /* @__PURE__ */ e(it, { size: 14, style: f.spinner, "aria-hidden": "true" });
1556
+ function Fe() {
1557
+ return /* @__PURE__ */ e(lt, { size: 14, style: p.spinner, "aria-hidden": "true" });
1454
1558
  }
1455
- function ct(t) {
1559
+ function ut(t) {
1456
1560
  return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
1457
1561
  }
1458
- const qt = { livechat: "web" };
1459
- function Ie({ provider: t }) {
1460
- const i = Ae(Pe), r = 14;
1562
+ const Jt = { livechat: "web" };
1563
+ function $e({ provider: t }) {
1564
+ const i = Ne(qe), r = 14;
1461
1565
  if (!t) return null;
1462
- const o = qt[t] ?? t;
1566
+ const o = Jt[t] ?? t;
1463
1567
  return /* @__PURE__ */ e("img", { src: `${i}/static/logos/${o}.avif`, alt: t, width: r, height: r, style: { borderRadius: "50%", objectFit: "cover", display: "block" } });
1464
1568
  }
1465
- function Ue(t, i = !1) {
1569
+ function Ke(t, i = !1) {
1466
1570
  if (!t) return "";
1467
1571
  const r = new Date(t);
1468
1572
  return r.toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? r.toLocaleTimeString("vi-VN", { hour: "2-digit", minute: "2-digit" }) : r.toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit" });
1469
1573
  }
1470
- const f = {
1471
- frame: { display: "grid", gridTemplateRows: "minmax(0, 1fr)", height: 620, maxHeight: "calc(100dvh - 220px)", minHeight: 0, overflow: "hidden", border: `1px solid ${l.line}`, background: l.white, color: l.ink, boxShadow: "0 18px 50px rgba(31,45,72,.10)" },
1472
- sidebar: { display: "flex", flexDirection: "column", minWidth: 0, minHeight: 0, borderRight: `1px solid ${l.line}`, background: l.white },
1574
+ const p = {
1575
+ frame: { display: "grid", gridTemplateRows: "minmax(0, 1fr)", height: 620, maxHeight: "calc(100dvh - 220px)", minHeight: 0, overflow: "hidden", border: `1px solid ${d.line}`, background: d.white, color: d.ink, boxShadow: "0 18px 50px rgba(31,45,72,.10)" },
1576
+ sidebar: { display: "flex", flexDirection: "column", minWidth: 0, minHeight: 0, borderRight: `1px solid ${d.line}`, background: d.white },
1473
1577
  brand: { display: "flex", alignItems: "center", gap: 10, padding: "20px 18px 16px" },
1474
1578
  brandMark: { display: "grid", placeItems: "center", width: 32, height: 32, borderRadius: 10, color: "#fff", fontWeight: 800 },
1475
- eyebrow: { display: "block", marginTop: 2, fontSize: 9, letterSpacing: 1.3, color: l.muted },
1476
- iconButton: { display: "inline-grid", placeItems: "center", width: 32, height: 32, marginLeft: "auto", border: 0, borderRadius: 8, background: "transparent", color: l.muted, cursor: "pointer" },
1477
- search: { display: "flex", alignItems: "center", gap: 8, margin: "0 14px 12px", padding: "9px 10px", border: `1px solid ${l.line}`, borderRadius: 9, color: l.muted, background: l.surface },
1478
- clear: { border: 0, background: "none", color: l.muted, cursor: "pointer", fontSize: 18 },
1479
- listHeader: { display: "flex", alignItems: "center", padding: "10px 18px", borderTop: `1px solid ${l.line}`, borderBottom: `1px solid ${l.line}`, color: l.muted, fontSize: 11, fontWeight: 700, letterSpacing: 0.4, textTransform: "uppercase" },
1579
+ eyebrow: { display: "block", marginTop: 2, fontSize: 9, letterSpacing: 1.3, color: d.muted },
1580
+ iconButton: { display: "inline-grid", placeItems: "center", width: 32, height: 32, marginLeft: "auto", border: 0, borderRadius: 8, background: "transparent", color: d.muted, cursor: "pointer" },
1581
+ search: { display: "flex", alignItems: "center", gap: 8, margin: "0 14px 12px", padding: "9px 10px", border: `1px solid ${d.line}`, borderRadius: 9, color: d.muted, background: d.surface },
1582
+ clear: { border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 18 },
1583
+ listHeader: { display: "flex", alignItems: "center", padding: "10px 18px", borderTop: `1px solid ${d.line}`, borderBottom: `1px solid ${d.line}`, color: d.muted, fontSize: 11, fontWeight: 700, letterSpacing: 0.4, textTransform: "uppercase" },
1480
1584
  conversationList: { overflowY: "auto", flex: 1, minHeight: 0 },
1481
- row: { display: "flex", width: "100%", gap: 11, padding: "10px 14px", border: 0, borderBottom: `1px solid ${l.line}`, background: "transparent", textAlign: "left", cursor: "pointer", transition: "background 120ms ease" },
1585
+ row: { display: "flex", width: "100%", gap: 11, padding: "10px 14px", border: 0, borderBottom: `1px solid ${d.line}`, background: "transparent", textAlign: "left", cursor: "pointer", transition: "background 120ms ease" },
1482
1586
  avatarWrap: { position: "relative", flex: "0 0 auto", width: 38, height: 38 },
1483
1587
  avatar: { flex: "0 0 auto", width: 38, height: 38, display: "grid", placeItems: "center", borderRadius: "50%", objectFit: "cover", fontSize: 12, fontWeight: 800 },
1484
1588
  providerBadge: { position: "absolute", left: -3, bottom: -3, display: "grid", placeItems: "center", width: 17, height: 17, border: "2px solid #fff", borderRadius: "50%", background: "#fff", color: "#64748b" },
@@ -1487,41 +1591,41 @@ const f = {
1487
1591
  rowBottom: { display: "flex", marginTop: 4, fontSize: 11, minWidth: 0, overflow: "hidden", lineHeight: 1.4 },
1488
1592
  unreadBadge: { display: "inline-grid", placeItems: "center", minWidth: 18, height: 18, borderRadius: 999, background: "#ef4444", color: "#fff", fontSize: 10, fontWeight: 800, padding: "0 5px" },
1489
1593
  loadMore: { width: "100%", border: 0, background: "transparent", color: "#4c72ca", padding: 14, cursor: "pointer", fontSize: 12 },
1490
- emptySmall: { display: "grid", justifyItems: "center", gap: 7, padding: "56px 24px", color: l.muted, fontSize: 12, textAlign: "center" },
1491
- emptyIcon: { display: "grid", placeItems: "center", width: 40, height: 40, borderRadius: 12, background: l.surface },
1492
- main: { minWidth: 0, minHeight: 0, overflow: "hidden", background: l.surface },
1594
+ emptySmall: { display: "grid", justifyItems: "center", gap: 7, padding: "56px 24px", color: d.muted, fontSize: 12, textAlign: "center" },
1595
+ emptyIcon: { display: "grid", placeItems: "center", width: 40, height: 40, borderRadius: 12, background: d.surface },
1596
+ main: { minWidth: 0, minHeight: 0, overflow: "hidden", background: d.surface },
1493
1597
  chat: { display: "flex", flexDirection: "column", height: "100%", minWidth: 0, minHeight: 0 },
1494
- chatHeader: { flex: "0 0 auto", display: "flex", alignItems: "center", gap: 10, padding: "0 16px 0 18px", height: 56, borderBottom: `1px solid ${l.line}`, background: l.white },
1598
+ chatHeader: { flex: "0 0 auto", display: "flex", alignItems: "center", gap: 10, padding: "0 16px 0 18px", height: 56, borderBottom: `1px solid ${d.line}`, background: d.white },
1495
1599
  contact: { display: "grid", gap: 3, minWidth: 0, flex: 1 },
1496
- contactName: { fontSize: 14, fontWeight: 600, color: l.ink, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" },
1497
- contactMeta: { display: "flex", alignItems: "center", gap: 5, fontSize: 11, color: l.muted },
1600
+ contactName: { fontSize: 14, fontWeight: 600, color: d.ink, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" },
1601
+ contactMeta: { display: "flex", alignItems: "center", gap: 5, fontSize: 11, color: d.muted },
1498
1602
  headerActions: { display: "flex", gap: 2, marginLeft: "auto" },
1499
1603
  messageArea: { flex: 1, minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", padding: "20px clamp(16px,5vw,56px)", background: "linear-gradient(180deg,#f9fbfe 0%,#f4f7fb 100%)" },
1500
1604
  day: { margin: "0 auto 18px", color: "#a1acbb", fontSize: 10, letterSpacing: 1.2, fontWeight: 700, textAlign: "center" },
1501
- historyButton: { display: "block", margin: "0 auto 18px", border: `1px solid ${l.line}`, borderRadius: 20, padding: "6px 12px", background: l.white, color: l.muted, cursor: "pointer", fontSize: 11 },
1502
- messageHint: { display: "flex", justifyContent: "center", alignItems: "center", gap: 8, padding: 40, color: l.muted, fontSize: 12 },
1605
+ historyButton: { display: "block", margin: "0 auto 18px", border: `1px solid ${d.line}`, borderRadius: 20, padding: "6px 12px", background: d.white, color: d.muted, cursor: "pointer", fontSize: 11 },
1606
+ messageHint: { display: "flex", justifyContent: "center", alignItems: "center", gap: 8, padding: 40, color: d.muted, fontSize: 12 },
1503
1607
  messageLine: { display: "flex", marginBottom: 10 },
1504
1608
  bubbleOut: { maxWidth: "min(70%,480px)", padding: "9px 13px", borderRadius: "14px 14px 3px 14px", boxShadow: "0 2px 5px rgba(30,43,65,.03)", fontSize: 14, lineHeight: 1.55 },
1505
- bubbleIn: { maxWidth: "min(70%,480px)", padding: "9px 13px", borderRadius: "14px 14px 14px 3px", border: `1px solid ${l.line}`, background: l.surface, boxShadow: "0 2px 5px rgba(30,43,65,.03)", fontSize: 14, lineHeight: 1.55 },
1609
+ bubbleIn: { maxWidth: "min(70%,480px)", padding: "9px 13px", borderRadius: "14px 14px 14px 3px", border: `1px solid ${d.line}`, background: d.surface, boxShadow: "0 2px 5px rgba(30,43,65,.03)", fontSize: 14, lineHeight: 1.55 },
1506
1610
  error: { padding: "8px 18px", background: "#fff2f0", color: "#b42318", fontSize: 12 },
1507
- empty: { display: "grid", placeItems: "center", alignContent: "center", height: "100%", padding: 30, textAlign: "center", color: l.muted },
1611
+ empty: { display: "grid", placeItems: "center", alignContent: "center", height: "100%", padding: 30, textAlign: "center", color: d.muted },
1508
1612
  emptyHero: { display: "grid", placeItems: "center", width: 64, height: 64, marginBottom: 16, borderRadius: 20, background: "#eaf0ff", color: "#5277d7" },
1509
- state: { display: "flex", alignItems: "center", justifyContent: "center", gap: 10, minHeight: 180, border: `1px solid ${l.line}`, background: l.white, color: l.muted, fontSize: 13 },
1613
+ state: { display: "flex", alignItems: "center", justifyContent: "center", gap: 10, minHeight: 180, border: `1px solid ${d.line}`, background: d.white, color: d.muted, fontSize: 13 },
1510
1614
  retry: { border: 0, borderRadius: 7, padding: "7px 10px", background: "#eff4ff", color: "#315dbb", cursor: "pointer" },
1511
1615
  spinner: { display: "inline-block", width: 14, height: 14, border: "2px solid #dbe3f3", borderTopColor: "#5277d7", borderRadius: "50%", animation: "channelhub-spin .7s linear infinite" },
1512
1616
  toolbarBtn: { display: "inline-grid", placeItems: "center", width: 26, height: 26, border: "1px solid transparent", borderRadius: 6, background: "transparent", color: "#9ca3af", cursor: "pointer", padding: 0, lineHeight: 1 },
1513
- infoPanel: { display: "flex", flexDirection: "column", borderLeft: `1px solid ${l.line}`, background: l.white, minHeight: 0, overflow: "hidden" },
1514
- infoPanelHeader: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 16px 12px", borderBottom: `1px solid ${l.line}`, flex: "0 0 auto" },
1617
+ infoPanel: { display: "flex", flexDirection: "column", borderLeft: `1px solid ${d.line}`, background: d.white, minHeight: 0, overflow: "hidden" },
1618
+ infoPanelHeader: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 16px 12px", borderBottom: `1px solid ${d.line}`, flex: "0 0 auto" },
1515
1619
  infoPanelIdentity: { display: "flex", flexDirection: "column", alignItems: "center", padding: "20px 16px 16px", gap: 4 },
1516
- ghostButton: { width: "100%", padding: "8px 12px", border: `1px solid ${l.line}`, borderRadius: 8, background: "transparent", fontSize: 12, cursor: "pointer", textAlign: "center" }
1517
- }, Vt = {
1620
+ ghostButton: { width: "100%", padding: "8px 12px", border: `1px solid ${d.line}`, borderRadius: 8, background: "transparent", fontSize: 12, cursor: "pointer", textAlign: "center" }
1621
+ }, Yt = {
1518
1622
  facebook: "#dbeafe",
1519
1623
  zalo: "#e0f2fe",
1520
1624
  instagram: "#fce7f3",
1521
1625
  telegram: "#cffafe",
1522
1626
  livechat: "#ede9fe",
1523
1627
  whatsapp: "#dcfce7"
1524
- }, Gt = {
1628
+ }, _t = {
1525
1629
  facebook: "facebook",
1526
1630
  instagram: "instagram",
1527
1631
  telegram: "telegram",
@@ -1529,8 +1633,8 @@ const f = {
1529
1633
  livechat: "web",
1530
1634
  whatsapp: "web"
1531
1635
  };
1532
- function pe({ provider: t, apiUrl: i, size: r = 40 }) {
1533
- const o = Vt[t] ?? "#f1f5f9", s = Gt[t], k = i.replace(/\/$/, "");
1636
+ function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1637
+ const o = Yt[t] ?? "#f1f5f9", s = _t[t], C = i.replace(/\/$/, "");
1534
1638
  return /* @__PURE__ */ e(
1535
1639
  "div",
1536
1640
  {
@@ -1548,7 +1652,7 @@ function pe({ provider: t, apiUrl: i, size: r = 40 }) {
1548
1652
  children: s ? /* @__PURE__ */ e(
1549
1653
  "img",
1550
1654
  {
1551
- src: `${k}/static/logos/${s}.avif`,
1655
+ src: `${C}/static/logos/${s}.avif`,
1552
1656
  alt: t,
1553
1657
  width: Math.round(r * 0.65),
1554
1658
  height: Math.round(r * 0.65),
@@ -1558,14 +1662,14 @@ function pe({ provider: t, apiUrl: i, size: r = 40 }) {
1558
1662
  }
1559
1663
  );
1560
1664
  }
1561
- const Ce = {
1665
+ const Be = {
1562
1666
  facebook: "Facebook",
1563
1667
  zalo: "Zalo OA",
1564
1668
  instagram: "Instagram",
1565
1669
  telegram: "Telegram",
1566
1670
  livechat: "Live Chat",
1567
1671
  whatsapp: "WhatsApp"
1568
- }, Xt = {
1672
+ }, Zt = {
1569
1673
  facebook: "#dbeafe",
1570
1674
  zalo: "#e0f2fe",
1571
1675
  instagram: "#fce7f3",
@@ -1573,12 +1677,12 @@ const Ce = {
1573
1677
  livechat: "#ede9fe",
1574
1678
  whatsapp: "#dcfce7"
1575
1679
  };
1576
- function Ne(t) {
1680
+ function Ve(t) {
1577
1681
  const i = t.metadata;
1578
1682
  return String(i.displayName ?? i.pageName ?? i.username ?? i.name ?? t.externalAccountId);
1579
1683
  }
1580
- function Jt(t) {
1581
- const i = Ce[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
1684
+ function Qt(t) {
1685
+ const i = Be[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
1582
1686
  return r ? `${i} · ${r}` : i;
1583
1687
  }
1584
1688
  const a = {
@@ -1856,264 +1960,264 @@ const a = {
1856
1960
  fontFamily: "inherit"
1857
1961
  }
1858
1962
  };
1859
- function Xe() {
1963
+ function Ze() {
1860
1964
  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" }) });
1861
1965
  }
1862
- function xe() {
1966
+ function ve() {
1863
1967
  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" }) });
1864
1968
  }
1865
- function Je() {
1969
+ function Qe() {
1866
1970
  return /* @__PURE__ */ n("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: [
1867
1971
  /* @__PURE__ */ e("rect", { x: "4", y: "4", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.3" }),
1868
1972
  /* @__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" })
1869
1973
  ] });
1870
1974
  }
1871
- function Ye() {
1975
+ function et() {
1872
1976
  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" }) });
1873
1977
  }
1874
- function Yt() {
1978
+ function en() {
1875
1979
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0 }, children: [
1876
1980
  /* @__PURE__ */ e("circle", { cx: "5", cy: "6", r: "3.5", stroke: "#ca8a04", strokeWidth: "1.4" }),
1877
1981
  /* @__PURE__ */ e("path", { d: "M8 7.5l4.5 4.5M10.5 10l1.5 1.5", stroke: "#ca8a04", strokeWidth: "1.4", strokeLinecap: "round" })
1878
1982
  ] });
1879
1983
  }
1880
- function _t() {
1984
+ function tn() {
1881
1985
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0, marginTop: 1 }, children: [
1882
1986
  /* @__PURE__ */ e("circle", { cx: "7", cy: "7", r: "6", stroke: "currentColor", strokeWidth: "1.5" }),
1883
1987
  /* @__PURE__ */ e("path", { d: "M7 6v5M7 4.5v.01", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
1884
1988
  ] });
1885
1989
  }
1886
- let _e = !1;
1887
- function Zt() {
1888
- if (_e || typeof document > "u") return;
1889
- _e = !0;
1990
+ let tt = !1;
1991
+ function nn() {
1992
+ if (tt || typeof document > "u") return;
1993
+ tt = !0;
1890
1994
  const t = document.createElement("style");
1891
1995
  t.textContent = "@keyframes ch-spin{to{transform:rotate(360deg)}}", document.head.appendChild(t);
1892
1996
  }
1893
- function cn({ apiUrl: t, token: i, onConnectionChange: r }) {
1894
- const o = t.replace(/\/$/, ""), [s, k] = y([]), [x, E] = y(!0), [g, v] = y({ name: "list" }), [L, C] = y(null), [R, W] = y(!1), [B, A] = y(""), [Z, N] = y(""), [M, O] = y(""), [Y, I] = y(""), [V, h] = y(!1), [S, _] = y(!1), z = X(null);
1895
- Zt();
1896
- const K = De(async () => {
1997
+ function un({ apiUrl: t, token: i, onConnectionChange: r }) {
1998
+ const o = t.replace(/\/$/, ""), [s, C] = g([]), [m, O] = g(!0), [f, S] = g({ name: "list" }), [B, I] = g(null), [H, $] = g(!1), [E, j] = g(""), [A, F] = g(""), [K, ne] = g(""), [U, w] = g(""), [_, k] = g(!1), [L, ce] = g(!1), z = ee(null);
1999
+ nn();
2000
+ const D = We(async () => {
1897
2001
  try {
1898
- const p = await fetch(`${o}/v1/connections`, {
2002
+ const h = await fetch(`${o}/v1/connections`, {
1899
2003
  headers: { authorization: `Bearer ${i}` }
1900
2004
  });
1901
- if (!p.ok) throw new Error("Không tải được kênh");
1902
- const T = await p.json();
1903
- k(T), r == null || r(T);
1904
- } catch (p) {
1905
- C(p instanceof Error ? p.message : "Lỗi tải dữ liệu");
2005
+ if (!h.ok) throw new Error("Không tải được kênh");
2006
+ const T = await h.json();
2007
+ C(T), r == null || r(T);
2008
+ } catch (h) {
2009
+ I(h instanceof Error ? h.message : "Lỗi tải dữ liệu");
1906
2010
  } finally {
1907
- E(!1);
2011
+ O(!1);
1908
2012
  }
1909
2013
  }, [o, i, r]);
1910
- F(() => {
1911
- K();
1912
- }, [K]), F(() => {
1913
- if (!L) return;
1914
- const p = setTimeout(() => C(null), 5e3);
1915
- return () => clearTimeout(p);
1916
- }, [L]), F(() => () => {
2014
+ Y(() => {
2015
+ D();
2016
+ }, [D]), Y(() => {
2017
+ if (!B) return;
2018
+ const h = setTimeout(() => I(null), 5e3);
2019
+ return () => clearTimeout(h);
2020
+ }, [B]), Y(() => () => {
1917
2021
  z.current && window.removeEventListener("message", z.current);
1918
2022
  }, []);
1919
- async function oe(p, T) {
2023
+ async function le(h, T) {
1920
2024
  if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${T}"?
1921
2025
 
1922
2026
  Hành động này không thể hoàn tác.`))
1923
2027
  try {
1924
- if (!(await fetch(`${o}/v1/connections/${p}`, {
2028
+ if (!(await fetch(`${o}/v1/connections/${h}`, {
1925
2029
  method: "DELETE",
1926
2030
  headers: { authorization: `Bearer ${i}` }
1927
2031
  })).ok) throw new Error("Không thể ngắt kết nối");
1928
- await K();
1929
- } catch ($) {
1930
- C($ instanceof Error ? $.message : "Lỗi ngắt kết nối");
2032
+ await D();
2033
+ } catch (P) {
2034
+ I(P instanceof Error ? P.message : "Lỗi ngắt kết nối");
1931
2035
  }
1932
2036
  }
1933
- async function ue() {
1934
- if (!B.trim()) {
1935
- C("Vui lòng nhập Bot Token");
2037
+ async function v() {
2038
+ if (!E.trim()) {
2039
+ I("Vui lòng nhập Bot Token");
1936
2040
  return;
1937
2041
  }
1938
- if (!/^\d+:[A-Za-z0-9_-]+$/.test(B.trim())) {
1939
- C("Token không đúng định dạng");
2042
+ if (!/^\d+:[A-Za-z0-9_-]+$/.test(E.trim())) {
2043
+ I("Token không đúng định dạng");
1940
2044
  return;
1941
2045
  }
1942
- W(!0), C(null);
2046
+ $(!0), I(null);
1943
2047
  try {
1944
- const p = await fetch(`${o}/v1/connect/telegram/start`, {
2048
+ const h = await fetch(`${o}/v1/connect/telegram/start`, {
1945
2049
  method: "POST",
1946
2050
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
1947
- body: JSON.stringify({ botToken: B.trim(), displayName: Z.trim() || void 0 })
1948
- }), T = await p.json();
1949
- if (!p.ok || !T.connectionId) throw new Error(T.message ?? "Không thể kết nối Telegram");
1950
- A(""), N(""), await K(), v({ name: "list" });
1951
- } catch (p) {
1952
- C(p instanceof Error ? p.message : "Lỗi kết nối");
2051
+ body: JSON.stringify({ botToken: E.trim(), displayName: A.trim() || void 0 })
2052
+ }), T = await h.json();
2053
+ if (!h.ok || !T.connectionId) throw new Error(T.message ?? "Không thể kết nối Telegram");
2054
+ j(""), F(""), await D(), S({ name: "list" });
2055
+ } catch (h) {
2056
+ I(h instanceof Error ? h.message : "Lỗi kết nối");
1953
2057
  } finally {
1954
- W(!1);
2058
+ $(!1);
1955
2059
  }
1956
2060
  }
1957
- async function w() {
1958
- if (!M.trim()) {
1959
- C("Vui lòng nhập tên widget");
2061
+ async function Q() {
2062
+ if (!K.trim()) {
2063
+ I("Vui lòng nhập tên widget");
1960
2064
  return;
1961
2065
  }
1962
- W(!0), C(null);
2066
+ $(!0), I(null);
1963
2067
  try {
1964
- const p = Y.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean), T = await fetch(`${o}/v1/connect/livechat/start`, {
2068
+ const h = U.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean), T = await fetch(`${o}/v1/connect/livechat/start`, {
1965
2069
  method: "POST",
1966
2070
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
1967
- body: JSON.stringify({ displayName: M.trim(), allowedDomains: p.length ? p : void 0 })
1968
- }), $ = await T.json();
1969
- if (!T.ok || !$.connectionId || !$.embedScript) throw new Error($.message ?? "Không thể tạo widget");
1970
- O(""), I(""), await K(), v({
2071
+ body: JSON.stringify({ displayName: K.trim(), allowedDomains: h.length ? h : void 0 })
2072
+ }), P = await T.json();
2073
+ if (!T.ok || !P.connectionId || !P.embedScript) throw new Error(P.message ?? "Không thể tạo widget");
2074
+ ne(""), w(""), await D(), S({
1971
2075
  name: "livechat-result",
1972
- connectionId: $.connectionId,
1973
- embedScript: $.embedScript,
1974
- identitySecret: $.identitySecret ?? "",
1975
- allowedDomains: $.allowedDomains ?? []
2076
+ connectionId: P.connectionId,
2077
+ embedScript: P.embedScript,
2078
+ identitySecret: P.identitySecret ?? "",
2079
+ allowedDomains: P.allowedDomains ?? []
1976
2080
  });
1977
- } catch (p) {
1978
- C(p instanceof Error ? p.message : "Lỗi tạo widget");
2081
+ } catch (h) {
2082
+ I(h instanceof Error ? h.message : "Lỗi tạo widget");
1979
2083
  } finally {
1980
- W(!1);
2084
+ $(!1);
1981
2085
  }
1982
2086
  }
1983
- async function ie(p) {
1984
- C(null);
2087
+ async function N(h) {
2088
+ I(null);
1985
2089
  try {
1986
- const T = `${o}/static/oauth-popup.html`, $ = await fetch(`${o}/v1/connect/${p}/start`, {
2090
+ const T = `${o}/static/oauth-popup.html`, P = await fetch(`${o}/v1/connect/${h}/start`, {
1987
2091
  method: "POST",
1988
2092
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
1989
2093
  body: JSON.stringify({ callbackUrl: T })
1990
- }), q = await $.json();
1991
- if (!$.ok || !q.authorizationUrl) throw new Error(q.message ?? "Không thể bắt đầu kết nối");
1992
- const ae = window.open(q.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
1993
- v({ name: "oauth-waiting", provider: p, popup: ae }), z.current && window.removeEventListener("message", z.current);
1994
- const ee = (U) => {
1995
- if (U.data) {
1996
- if (U.data.type === "channelhub:oauth-select") {
1997
- v({
2094
+ }), q = await P.json();
2095
+ if (!P.ok || !q.authorizationUrl) throw new Error(q.message ?? "Không thể bắt đầu kết nối");
2096
+ const ie = window.open(q.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
2097
+ S({ name: "oauth-waiting", provider: h, popup: ie }), z.current && window.removeEventListener("message", z.current);
2098
+ const re = (V) => {
2099
+ if (V.data) {
2100
+ if (V.data.type === "channelhub:oauth-select") {
2101
+ S({
1998
2102
  name: "oauth-select",
1999
- provider: U.data.provider,
2000
- sessionId: String(U.data.sessionId ?? ""),
2001
- pages: U.data.pages ?? [],
2002
- popup: ae
2103
+ provider: V.data.provider,
2104
+ sessionId: String(V.data.sessionId ?? ""),
2105
+ pages: V.data.pages ?? [],
2106
+ popup: ie
2003
2107
  });
2004
2108
  return;
2005
2109
  }
2006
- U.data.type === "channelhub:oauth" && (window.removeEventListener("message", ee), z.current = null, U.data.status === "active" ? (K(), v({ name: "list" })) : (C("Kết nối thất bại: " + String(U.data.error ?? "Không xác định")), v({ name: "list" })));
2110
+ 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" })));
2007
2111
  }
2008
2112
  };
2009
- z.current = ee, window.addEventListener("message", ee);
2113
+ z.current = re, window.addEventListener("message", re);
2010
2114
  } catch (T) {
2011
- C(T instanceof Error ? T.message : "Lỗi kết nối"), v({ name: "list" });
2115
+ I(T instanceof Error ? T.message : "Lỗi kết nối"), S({ name: "list" });
2012
2116
  }
2013
2117
  }
2014
- function Q(p, T) {
2015
- navigator.clipboard.writeText(p).then(() => {
2016
- T === "script" ? (h(!0), setTimeout(() => h(!1), 2e3)) : (_(!0), setTimeout(() => _(!1), 2e3));
2118
+ function x(h, T) {
2119
+ navigator.clipboard.writeText(h).then(() => {
2120
+ T === "script" ? (k(!0), setTimeout(() => k(!1), 2e3)) : (ce(!0), setTimeout(() => ce(!1), 2e3));
2017
2121
  });
2018
2122
  }
2019
- function fe() {
2020
- const p = g.name === "oauth-waiting" || g.name === "oauth-select" ? g.popup : null;
2021
- if (p)
2123
+ function J() {
2124
+ const h = f.name === "oauth-waiting" || f.name === "oauth-select" ? f.popup : null;
2125
+ if (h)
2022
2126
  try {
2023
- p.close();
2127
+ h.close();
2024
2128
  } catch {
2025
2129
  }
2026
- z.current && (window.removeEventListener("message", z.current), z.current = null), v({ name: "add" });
2130
+ z.current && (window.removeEventListener("message", z.current), z.current = null), S({ name: "add" });
2027
2131
  }
2028
- async function le(p) {
2029
- if (g.name !== "oauth-select") return;
2030
- const { provider: T, sessionId: $, popup: q } = g;
2031
- W(!0), C(null);
2032
- const ae = {
2132
+ async function se(h) {
2133
+ if (f.name !== "oauth-select") return;
2134
+ const { provider: T, sessionId: P, popup: q } = f;
2135
+ $(!0), I(null);
2136
+ const ie = {
2033
2137
  facebook: `${o}/v1/connect/facebook/select-page`,
2034
2138
  instagram: `${o}/v1/connect/instagram/select-account`,
2035
2139
  zalo: `${o}/v1/connect/zalo/select-oa`
2036
- }, ee = {
2140
+ }, re = {
2037
2141
  facebook: "pageId",
2038
2142
  instagram: "accountId",
2039
2143
  zalo: "oaId"
2040
2144
  };
2041
2145
  try {
2042
- const U = await fetch(ae[T] ?? `${o}/v1/connect/${T}/select-page`, {
2146
+ const V = await fetch(ie[T] ?? `${o}/v1/connect/${T}/select-page`, {
2043
2147
  method: "POST",
2044
2148
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2045
- body: JSON.stringify({ sessionId: $, [ee[T] ?? "pageId"]: p })
2046
- }), de = await U.json();
2047
- if (!U.ok || !de.connectionId) throw new Error(de.message ?? "Không thể kết nối");
2149
+ body: JSON.stringify({ sessionId: P, [re[T] ?? "pageId"]: h })
2150
+ }), ye = await V.json();
2151
+ if (!V.ok || !ye.connectionId) throw new Error(ye.message ?? "Không thể kết nối");
2048
2152
  if (q)
2049
2153
  try {
2050
2154
  q.postMessage({ type: "channelhub:close-popup" }, "*");
2051
2155
  } catch {
2052
2156
  }
2053
- z.current && (window.removeEventListener("message", z.current), z.current = null), await K(), v({ name: "list" });
2054
- } catch (U) {
2055
- C(U instanceof Error ? U.message : "Lỗi kết nối");
2157
+ z.current && (window.removeEventListener("message", z.current), z.current = null), await D(), S({ name: "list" });
2158
+ } catch (V) {
2159
+ I(V instanceof Error ? V.message : "Lỗi kết nối");
2056
2160
  } finally {
2057
- W(!1);
2161
+ $(!1);
2058
2162
  }
2059
2163
  }
2060
2164
  return /* @__PURE__ */ n("div", { style: a.root, children: [
2061
- L && /* @__PURE__ */ e("div", { style: a.errorBanner, children: L }),
2062
- g.name === "list" && /* @__PURE__ */ n(J, { children: [
2165
+ B && /* @__PURE__ */ e("div", { style: a.errorBanner, children: B }),
2166
+ f.name === "list" && /* @__PURE__ */ n(te, { children: [
2063
2167
  /* @__PURE__ */ n("div", { style: a.header, children: [
2064
2168
  /* @__PURE__ */ e("div", { style: a.headerLeft, children: /* @__PURE__ */ n("div", { children: [
2065
2169
  /* @__PURE__ */ e("div", { style: a.title, children: "Kênh kết nối" }),
2066
- /* @__PURE__ */ e("div", { style: a.subtitle, children: x ? "Đang tải…" : `${s.filter((p) => p.status === "active").length} kênh đang hoạt động` })
2170
+ /* @__PURE__ */ e("div", { style: a.subtitle, children: m ? "Đang tải…" : `${s.filter((h) => h.status === "active").length} kênh đang hoạt động` })
2067
2171
  ] }) }),
2068
- /* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => v({ name: "add" }), children: [
2069
- /* @__PURE__ */ e(Xe, {}),
2172
+ /* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => S({ name: "add" }), children: [
2173
+ /* @__PURE__ */ e(Ze, {}),
2070
2174
  /* @__PURE__ */ e("span", { children: "Thêm kênh" })
2071
2175
  ] })
2072
2176
  ] }),
2073
2177
  /* @__PURE__ */ e("div", { style: a.divider }),
2074
- /* @__PURE__ */ e("div", { style: a.body, children: !x && s.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
2075
- /* @__PURE__ */ e("div", { style: { width: 64, height: 64, borderRadius: 16, background: "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(pe, { provider: "livechat", apiUrl: o, size: 40 }) }),
2178
+ /* @__PURE__ */ e("div", { style: a.body, children: !m && s.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
2179
+ /* @__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 }) }),
2076
2180
  /* @__PURE__ */ e("div", { style: a.emptyTitle, children: "Chưa có kênh nào được kết nối" }),
2077
2181
  /* @__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." }),
2078
- /* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => v({ name: "add" }), children: [
2079
- /* @__PURE__ */ e(Xe, {}),
2182
+ /* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => S({ name: "add" }), children: [
2183
+ /* @__PURE__ */ e(Ze, {}),
2080
2184
  "Kết nối kênh đầu tiên"
2081
2185
  ] })
2082
- ] }) : /* @__PURE__ */ e("div", { children: s.map((p) => /* @__PURE__ */ e(
2083
- tn,
2186
+ ] }) : /* @__PURE__ */ e("div", { children: s.map((h) => /* @__PURE__ */ e(
2187
+ an,
2084
2188
  {
2085
- conn: p,
2189
+ conn: h,
2086
2190
  apiUrl: o,
2087
- onDisconnect: () => void oe(p.id, Ne(p))
2191
+ onDisconnect: () => void le(h.id, Ve(h))
2088
2192
  },
2089
- p.id
2193
+ h.id
2090
2194
  )) }) })
2091
2195
  ] }),
2092
- g.name === "add" && /* @__PURE__ */ n(J, { children: [
2196
+ f.name === "add" && /* @__PURE__ */ n(te, { children: [
2093
2197
  /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2094
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => v({ name: "list" }), children: /* @__PURE__ */ e(xe, {}) }),
2198
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2095
2199
  /* @__PURE__ */ n("div", { children: [
2096
2200
  /* @__PURE__ */ e("div", { style: a.title, children: "Thêm kênh mới" }),
2097
2201
  /* @__PURE__ */ e("div", { style: a.subtitle, children: "Chọn nền tảng bạn muốn kết nối" })
2098
2202
  ] })
2099
2203
  ] }) }),
2100
2204
  /* @__PURE__ */ e("div", { style: a.divider }),
2101
- /* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: nn.map((p) => /* @__PURE__ */ e(
2102
- rn,
2205
+ /* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: ln.map((h) => /* @__PURE__ */ e(
2206
+ dn,
2103
2207
  {
2104
- provider: p,
2208
+ provider: h,
2105
2209
  apiUrl: o,
2106
2210
  onClick: () => {
2107
- p.type === "oauth" ? ie(p.id) : p.id === "telegram" ? v({ name: "connect-telegram" }) : v({ name: "connect-livechat" });
2211
+ h.type === "oauth" ? N(h.id) : h.id === "telegram" ? S({ name: "connect-telegram" }) : S({ name: "connect-livechat" });
2108
2212
  }
2109
2213
  },
2110
- p.id
2214
+ h.id
2111
2215
  )) }) })
2112
2216
  ] }),
2113
- g.name === "connect-telegram" && /* @__PURE__ */ n(J, { children: [
2217
+ f.name === "connect-telegram" && /* @__PURE__ */ n(te, { children: [
2114
2218
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2115
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => v({ name: "add" }), children: /* @__PURE__ */ e(xe, {}) }),
2116
- /* @__PURE__ */ e(pe, { provider: "telegram", apiUrl: o, size: 44 }),
2219
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2220
+ /* @__PURE__ */ e(ge, { provider: "telegram", apiUrl: o, size: 44 }),
2117
2221
  /* @__PURE__ */ n("div", { children: [
2118
2222
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Kết nối Telegram Bot" }),
2119
2223
  /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhập Bot Token để bắt đầu nhận tin nhắn" })
@@ -2121,7 +2225,7 @@ Hành động này không thể hoàn tác.`))
2121
2225
  ] }),
2122
2226
  /* @__PURE__ */ n("div", { style: a.form, children: [
2123
2227
  /* @__PURE__ */ n("div", { style: a.infoBox, children: [
2124
- /* @__PURE__ */ e(_t, {}),
2228
+ /* @__PURE__ */ e(tn, {}),
2125
2229
  /* @__PURE__ */ n("div", { children: [
2126
2230
  "Tạo bot mới bằng cách nhắn tin cho ",
2127
2231
  /* @__PURE__ */ e("strong", { children: "@BotFather" }),
@@ -2140,8 +2244,8 @@ Hành động này không thể hoàn tác.`))
2140
2244
  {
2141
2245
  style: a.input,
2142
2246
  type: "text",
2143
- value: B,
2144
- onChange: (p) => A(p.target.value),
2247
+ value: E,
2248
+ onChange: (h) => j(h.target.value),
2145
2249
  placeholder: "1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxx",
2146
2250
  autoComplete: "off",
2147
2251
  spellCheck: !1
@@ -2164,22 +2268,22 @@ Hành động này không thể hoàn tác.`))
2164
2268
  {
2165
2269
  style: a.input,
2166
2270
  type: "text",
2167
- value: Z,
2168
- onChange: (p) => N(p.target.value),
2271
+ value: A,
2272
+ onChange: (h) => F(h.target.value),
2169
2273
  placeholder: "VD: Bot hỗ trợ cửa hàng"
2170
2274
  }
2171
2275
  )
2172
2276
  ] }),
2173
2277
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2174
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => v({ name: "add" }), children: "Hủy" }),
2175
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: R, onClick: () => void ue(), children: R ? "Đang kết nối…" : "Kết nối Telegram" })
2278
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2279
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void v(), children: H ? "Đang kết nối…" : "Kết nối Telegram" })
2176
2280
  ] })
2177
2281
  ] })
2178
2282
  ] }),
2179
- g.name === "connect-livechat" && /* @__PURE__ */ n(J, { children: [
2283
+ f.name === "connect-livechat" && /* @__PURE__ */ n(te, { children: [
2180
2284
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2181
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => v({ name: "add" }), children: /* @__PURE__ */ e(xe, {}) }),
2182
- /* @__PURE__ */ e(pe, { provider: "livechat", apiUrl: o, size: 44 }),
2285
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2286
+ /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2183
2287
  /* @__PURE__ */ n("div", { children: [
2184
2288
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Tạo Live Chat Widget" }),
2185
2289
  /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhúng vào website để nhận tin nhắn từ khách hàng" })
@@ -2196,8 +2300,8 @@ Hành động này không thể hoàn tác.`))
2196
2300
  {
2197
2301
  style: a.input,
2198
2302
  type: "text",
2199
- value: M,
2200
- onChange: (p) => O(p.target.value),
2303
+ value: K,
2304
+ onChange: (h) => ne(h.target.value),
2201
2305
  placeholder: "VD: Hỗ trợ website hanashop.vn"
2202
2306
  }
2203
2307
  )
@@ -2211,8 +2315,8 @@ Hành động này không thể hoàn tác.`))
2211
2315
  "textarea",
2212
2316
  {
2213
2317
  style: { ...a.input, resize: "vertical", minHeight: 80, lineHeight: 1.5 },
2214
- value: Y,
2215
- onChange: (p) => I(p.target.value),
2318
+ value: U,
2319
+ onChange: (h) => w(h.target.value),
2216
2320
  placeholder: `https://myshop.com
2217
2321
  https://www.myshop.com`,
2218
2322
  spellCheck: !1
@@ -2221,15 +2325,15 @@ https://www.myshop.com`,
2221
2325
  /* @__PURE__ */ e("div", { style: a.inputHint, children: "Mỗi domain một dòng. Để trống để cho phép tất cả." })
2222
2326
  ] }),
2223
2327
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2224
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => v({ name: "add" }), children: "Hủy" }),
2225
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: R, onClick: () => void w(), children: R ? "Đang tạo…" : "Tạo widget" })
2328
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2329
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void Q(), children: H ? "Đang tạo…" : "Tạo widget" })
2226
2330
  ] })
2227
2331
  ] })
2228
2332
  ] }),
2229
- g.name === "livechat-result" && /* @__PURE__ */ n(J, { children: [
2333
+ f.name === "livechat-result" && /* @__PURE__ */ n(te, { children: [
2230
2334
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2231
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => v({ name: "list" }), children: /* @__PURE__ */ e(xe, {}) }),
2232
- /* @__PURE__ */ e(pe, { provider: "livechat", apiUrl: o, size: 44 }),
2335
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2336
+ /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2233
2337
  /* @__PURE__ */ n("div", { children: [
2234
2338
  /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Widget đã được tạo!" }),
2235
2339
  /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Sao chép mã nhúng và dán vào website của bạn" })
@@ -2248,56 +2352,56 @@ https://www.myshop.com`,
2248
2352
  /* @__PURE__ */ n("div", { children: [
2249
2353
  /* @__PURE__ */ e("div", { style: a.codeLabel, children: "Mã nhúng" }),
2250
2354
  /* @__PURE__ */ n("div", { style: a.codeBlock, children: [
2251
- /* @__PURE__ */ e("pre", { style: a.codePre, children: g.embedScript }),
2252
- /* @__PURE__ */ e("button", { style: { ...a.copyBtn, ...V ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => Q(g.embedScript, "script"), children: V ? /* @__PURE__ */ n(J, { children: [
2253
- /* @__PURE__ */ e(Ye, {}),
2355
+ /* @__PURE__ */ e("pre", { style: a.codePre, children: f.embedScript }),
2356
+ /* @__PURE__ */ e("button", { style: { ...a.copyBtn, ..._ ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => x(f.embedScript, "script"), children: _ ? /* @__PURE__ */ n(te, { children: [
2357
+ /* @__PURE__ */ e(et, {}),
2254
2358
  " Đã sao chép"
2255
- ] }) : /* @__PURE__ */ n(J, { children: [
2256
- /* @__PURE__ */ e(Je, {}),
2359
+ ] }) : /* @__PURE__ */ n(te, { children: [
2360
+ /* @__PURE__ */ e(Qe, {}),
2257
2361
  " Sao chép"
2258
2362
  ] }) })
2259
2363
  ] })
2260
2364
  ] }),
2261
- g.identitySecret && /* @__PURE__ */ n("div", { children: [
2365
+ f.identitySecret && /* @__PURE__ */ n("div", { children: [
2262
2366
  /* @__PURE__ */ n("div", { style: a.codeLabel, children: [
2263
2367
  "Identity Secret ",
2264
2368
  /* @__PURE__ */ e("span", { style: { ...a.labelHint, color: "#dc2626", fontWeight: 600 }, children: "Lưu ngay — chỉ hiển thị một lần" })
2265
2369
  ] }),
2266
2370
  /* @__PURE__ */ n("div", { style: a.secretRow, children: [
2267
- /* @__PURE__ */ e(Yt, {}),
2371
+ /* @__PURE__ */ e(en, {}),
2268
2372
  /* @__PURE__ */ e("span", { style: a.secretLabel, children: "Secret:" }),
2269
- /* @__PURE__ */ e("span", { style: a.secretValue, children: g.identitySecret }),
2373
+ /* @__PURE__ */ e("span", { style: a.secretValue, children: f.identitySecret }),
2270
2374
  /* @__PURE__ */ e(
2271
2375
  "button",
2272
2376
  {
2273
- onClick: () => Q(g.identitySecret, "secret"),
2274
- style: { border: "none", background: "transparent", cursor: "pointer", color: S ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2275
- children: S ? /* @__PURE__ */ e(Ye, {}) : /* @__PURE__ */ e(Je, {})
2377
+ onClick: () => x(f.identitySecret, "secret"),
2378
+ style: { border: "none", background: "transparent", cursor: "pointer", color: L ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2379
+ children: L ? /* @__PURE__ */ e(et, {}) : /* @__PURE__ */ e(Qe, {})
2276
2380
  }
2277
2381
  )
2278
2382
  ] }),
2279
2383
  /* @__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." })
2280
2384
  ] }),
2281
2385
  /* @__PURE__ */ n("div", { style: a.formActions, children: [
2282
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => v({ name: "list" }), children: "Về danh sách" }),
2283
- /* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => v({ name: "add" }), children: "Thêm kênh khác" })
2386
+ /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "list" }), children: "Về danh sách" }),
2387
+ /* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => S({ name: "add" }), children: "Thêm kênh khác" })
2284
2388
  ] })
2285
2389
  ] })
2286
2390
  ] }),
2287
- g.name === "oauth-waiting" && /* @__PURE__ */ n(J, { children: [
2391
+ f.name === "oauth-waiting" && /* @__PURE__ */ n(te, { children: [
2288
2392
  /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2289
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: fe, children: /* @__PURE__ */ e(xe, {}) }),
2393
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2290
2394
  /* @__PURE__ */ n("div", { children: [
2291
2395
  /* @__PURE__ */ n("div", { style: a.title, children: [
2292
2396
  "Đang xác thực ",
2293
- Ce[g.provider]
2397
+ Be[f.provider]
2294
2398
  ] }),
2295
2399
  /* @__PURE__ */ e("div", { style: a.subtitle, children: "Vui lòng hoàn thành trong cửa sổ bật lên" })
2296
2400
  ] })
2297
2401
  ] }) }),
2298
2402
  /* @__PURE__ */ n("div", { style: a.oauthWaiting, children: [
2299
2403
  /* @__PURE__ */ n("div", { style: { position: "relative", width: 72, height: 72 }, children: [
2300
- /* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: Xt[g.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(pe, { provider: g.provider, apiUrl: o, size: 48 }) }),
2404
+ /* @__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 }) }),
2301
2405
  /* @__PURE__ */ n(
2302
2406
  "svg",
2303
2407
  {
@@ -2326,38 +2430,38 @@ https://www.myshop.com`,
2326
2430
  ] }),
2327
2431
  /* @__PURE__ */ n("div", { style: a.oauthTitle, children: [
2328
2432
  "Đang chờ xác thực với ",
2329
- Ce[g.provider]
2433
+ Be[f.provider]
2330
2434
  ] }),
2331
2435
  /* @__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." }),
2332
2436
  /* @__PURE__ */ n("div", { style: { display: "flex", flexDirection: "column", gap: 8, alignItems: "flex-start", width: "100%", maxWidth: 280 }, children: [
2333
- /* @__PURE__ */ e(Ee, { done: !0, label: `Đã mở cửa sổ ${Ce[g.provider]}` }),
2334
- /* @__PURE__ */ e(Ee, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2335
- /* @__PURE__ */ e(Ee, { label: "Lưu kết nối & quay về" })
2437
+ /* @__PURE__ */ e(De, { done: !0, label: `Đã mở cửa sổ ${Be[f.provider]}` }),
2438
+ /* @__PURE__ */ e(De, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2439
+ /* @__PURE__ */ e(De, { label: "Lưu kết nối & quay về" })
2336
2440
  ] }),
2337
- /* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: fe, children: "Hủy và quay lại" })
2441
+ /* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: J, children: "Hủy và quay lại" })
2338
2442
  ] })
2339
2443
  ] }),
2340
- g.name === "oauth-select" && /* @__PURE__ */ n(J, { children: [
2444
+ f.name === "oauth-select" && /* @__PURE__ */ n(te, { children: [
2341
2445
  /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2342
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: fe, children: /* @__PURE__ */ e(xe, {}) }),
2343
- /* @__PURE__ */ e(pe, { provider: g.provider, apiUrl: o, size: 44 }),
2446
+ /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2447
+ /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 44 }),
2344
2448
  /* @__PURE__ */ n("div", { children: [
2345
2449
  /* @__PURE__ */ n("div", { style: a.connectTitle, children: [
2346
2450
  "Chọn ",
2347
- g.provider === "instagram" ? "tài khoản" : "trang"
2451
+ f.provider === "instagram" ? "tài khoản" : "trang"
2348
2452
  ] }),
2349
2453
  /* @__PURE__ */ n("div", { style: a.connectDesc, children: [
2350
2454
  "Chọn ",
2351
- Ce[g.provider],
2455
+ Be[f.provider],
2352
2456
  " bạn muốn kết nối với ChannelHub"
2353
2457
  ] })
2354
2458
  ] })
2355
2459
  ] }),
2356
- /* @__PURE__ */ e("div", { style: a.body, children: g.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: g.pages.map((p) => /* @__PURE__ */ n(
2460
+ /* @__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(
2357
2461
  "button",
2358
2462
  {
2359
- disabled: R,
2360
- onClick: () => void le(p.id),
2463
+ disabled: H,
2464
+ onClick: () => void se(h.id),
2361
2465
  style: {
2362
2466
  display: "flex",
2363
2467
  alignItems: "center",
@@ -2366,26 +2470,26 @@ https://www.myshop.com`,
2366
2470
  borderRadius: 12,
2367
2471
  border: "1.5px solid #e2e8f0",
2368
2472
  background: "#fff",
2369
- cursor: R ? "not-allowed" : "pointer",
2370
- opacity: R ? 0.6 : 1,
2473
+ cursor: H ? "not-allowed" : "pointer",
2474
+ opacity: H ? 0.6 : 1,
2371
2475
  textAlign: "left",
2372
2476
  fontFamily: "inherit",
2373
2477
  transition: "border-color .15s, background .15s"
2374
2478
  },
2375
2479
  children: [
2376
2480
  /* @__PURE__ */ n("div", { children: [
2377
- /* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: p.name }),
2378
- /* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: p.id })
2481
+ /* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: h.name }),
2482
+ /* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: h.id })
2379
2483
  ] }),
2380
- /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: R ? "Đang kết nối…" : "Chọn →" })
2484
+ /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: H ? "Đang kết nối…" : "Chọn →" })
2381
2485
  ]
2382
2486
  },
2383
- p.id
2487
+ h.id
2384
2488
  )) }) })
2385
2489
  ] })
2386
2490
  ] });
2387
2491
  }
2388
- function Qt(t) {
2492
+ function rn(t) {
2389
2493
  const i = t.metadata;
2390
2494
  if (typeof i.pictureUrl == "string") return i.pictureUrl;
2391
2495
  if (t.provider === "facebook")
@@ -2396,26 +2500,26 @@ function Qt(t) {
2396
2500
  }
2397
2501
  return null;
2398
2502
  }
2399
- function en({ conn: t, apiUrl: i, size: r = 40 }) {
2400
- const [o, s] = y(!1), k = Qt(t), x = Math.round(r * 0.28);
2401
- return k && !o ? /* @__PURE__ */ e(
2503
+ function on({ conn: t, apiUrl: i, size: r = 40 }) {
2504
+ const [o, s] = g(!1), C = rn(t), m = Math.round(r * 0.28);
2505
+ return C && !o ? /* @__PURE__ */ e(
2402
2506
  "img",
2403
2507
  {
2404
- src: k,
2405
- alt: Ne(t),
2508
+ src: C,
2509
+ alt: Ve(t),
2406
2510
  referrerPolicy: "no-referrer",
2407
2511
  onError: () => s(!0),
2408
- style: { width: r, height: r, borderRadius: x, objectFit: "cover", flexShrink: 0, display: "block" }
2512
+ style: { width: r, height: r, borderRadius: m, objectFit: "cover", flexShrink: 0, display: "block" }
2409
2513
  }
2410
- ) : /* @__PURE__ */ e(pe, { provider: t.provider, apiUrl: i, size: r });
2514
+ ) : /* @__PURE__ */ e(ge, { provider: t.provider, apiUrl: i, size: r });
2411
2515
  }
2412
- function tn({ conn: t, apiUrl: i, onDisconnect: r }) {
2413
- const [o, s] = y(!1);
2516
+ function an({ conn: t, apiUrl: i, onDisconnect: r }) {
2517
+ const [o, s] = g(!1);
2414
2518
  return /* @__PURE__ */ n("div", { style: a.channelItem, children: [
2415
- /* @__PURE__ */ e(en, { conn: t, apiUrl: i, size: 40 }),
2519
+ /* @__PURE__ */ e(on, { conn: t, apiUrl: i, size: 40 }),
2416
2520
  /* @__PURE__ */ n("div", { style: a.channelInfo, children: [
2417
- /* @__PURE__ */ e("div", { style: a.channelName, children: Ne(t) }),
2418
- /* @__PURE__ */ e("div", { style: a.channelMeta, children: Jt(t) })
2521
+ /* @__PURE__ */ e("div", { style: a.channelName, children: Ve(t) }),
2522
+ /* @__PURE__ */ e("div", { style: a.channelMeta, children: Qt(t) })
2419
2523
  ] }),
2420
2524
  /* @__PURE__ */ n("div", { style: a.channelActions, children: [
2421
2525
  /* @__PURE__ */ e("span", { style: t.status === "active" ? a.badgeActive : a.badgeInactive, children: t.status === "active" ? "Hoạt động" : t.status }),
@@ -2435,15 +2539,15 @@ function tn({ conn: t, apiUrl: i, onDisconnect: r }) {
2435
2539
  ] })
2436
2540
  ] });
2437
2541
  }
2438
- const nn = [
2542
+ const ln = [
2439
2543
  { id: "facebook", name: "Facebook", desc: "Fanpage & Messenger", type: "oauth" },
2440
2544
  { id: "zalo", name: "Zalo OA", desc: "Official Account", type: "oauth" },
2441
2545
  { id: "instagram", name: "Instagram", desc: "DM & Comments", type: "oauth" },
2442
2546
  { id: "telegram", name: "Telegram", desc: "Bot token", type: "token" },
2443
2547
  { id: "livechat", name: "Live Chat", desc: "Website widget", type: "livechat" }
2444
2548
  ];
2445
- function rn({ provider: t, apiUrl: i, onClick: r }) {
2446
- const [o, s] = y(!1);
2549
+ function dn({ provider: t, apiUrl: i, onClick: r }) {
2550
+ const [o, s] = g(!1);
2447
2551
  return /* @__PURE__ */ n(
2448
2552
  "div",
2449
2553
  {
@@ -2455,7 +2559,7 @@ function rn({ provider: t, apiUrl: i, onClick: r }) {
2455
2559
  onMouseEnter: () => s(!0),
2456
2560
  onMouseLeave: () => s(!1),
2457
2561
  children: [
2458
- /* @__PURE__ */ e(pe, { provider: t.id, apiUrl: i, size: 44 }),
2562
+ /* @__PURE__ */ e(ge, { provider: t.id, apiUrl: i, size: 44 }),
2459
2563
  /* @__PURE__ */ n("div", { children: [
2460
2564
  /* @__PURE__ */ e("div", { style: a.providerName, children: t.name }),
2461
2565
  /* @__PURE__ */ e("div", { style: a.providerDesc, children: t.desc })
@@ -2464,7 +2568,7 @@ function rn({ provider: t, apiUrl: i, onClick: r }) {
2464
2568
  }
2465
2569
  );
2466
2570
  }
2467
- function Ee({ done: t, active: i, label: r }) {
2571
+ function De({ done: t, active: i, label: r }) {
2468
2572
  return /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 10, fontSize: 13, color: t ? "#059669" : i ? "#0f172a" : "#94a3b8" }, children: [
2469
2573
  /* @__PURE__ */ e("div", { style: {
2470
2574
  width: 10,
@@ -2477,9 +2581,9 @@ function Ee({ done: t, active: i, label: r }) {
2477
2581
  r
2478
2582
  ] });
2479
2583
  }
2480
- console.log("[ChannelHub] widget v0.1.5 loaded");
2584
+ console.log("[ChannelHub] widget v0.1.6 loaded");
2481
2585
  export {
2482
- cn as ChannelHubChannels,
2483
- Bt as ChannelHubClient,
2484
- dn as ChannelHubInbox
2586
+ un as ChannelHubChannels,
2587
+ Mt as ChannelHubClient,
2588
+ pn as ChannelHubInbox
2485
2589
  };