@channelhub/widget 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { jsx as e, jsxs as n, Fragment as te } from "react/jsx-runtime";
2
- import { forwardRef as Le, createElement as Pe, createContext as nt, useRef as ee, useState as y, useMemo as Ee, useCallback as We, useEffect as Y, useImperativeHandle as yt, useContext as Ne, Component as mt } from "react";
3
- import { createPortal as it } from "react-dom";
1
+ import { jsx as e, jsxs as n, Fragment as ie } from "react/jsx-runtime";
2
+ import { forwardRef as Pe, createElement as et, createContext as wt, useRef as J, useState as y, useMemo as $e, useEffect as X, useCallback as we, useImperativeHandle as Bt, useContext as tt, Component as Lt } from "react";
3
+ import { createPortal as St } from "react-dom";
4
4
  /**
5
5
  * @license lucide-react v0.468.0 - ISC
6
6
  *
7
7
  * This source code is licensed under the ISC license.
8
8
  * See the LICENSE file in the root directory of this source tree.
9
9
  */
10
- const bt = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), rt = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
10
+ const Mt = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), Ct = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
11
11
  /**
12
12
  * @license lucide-react v0.468.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
16
  */
17
- var xt = {
17
+ var Ht = {
18
18
  xmlns: "http://www.w3.org/2000/svg",
19
19
  width: 24,
20
20
  height: 24,
@@ -31,31 +31,31 @@ var xt = {
31
31
  * This source code is licensed under the ISC license.
32
32
  * See the LICENSE file in the root directory of this source tree.
33
33
  */
34
- const vt = Le(
34
+ const At = Pe(
35
35
  ({
36
36
  color: t = "currentColor",
37
37
  size: i = 24,
38
38
  strokeWidth: r = 2,
39
39
  absoluteStrokeWidth: o,
40
- className: s = "",
41
- children: C,
40
+ className: h = "",
41
+ children: S,
42
42
  iconNode: m,
43
- ...O
44
- }, f) => Pe(
43
+ ...M
44
+ }, w) => et(
45
45
  "svg",
46
46
  {
47
- ref: f,
48
- ...xt,
47
+ ref: w,
48
+ ...Ht,
49
49
  width: i,
50
50
  height: i,
51
51
  stroke: t,
52
52
  strokeWidth: o ? Number(r) * 24 / Number(i) : r,
53
- className: rt("lucide", s),
54
- ...O
53
+ className: Ct("lucide", h),
54
+ ...M
55
55
  },
56
56
  [
57
- ...m.map(([S, W]) => Pe(S, W)),
58
- ...Array.isArray(C) ? C : [C]
57
+ ...m.map(([v, W]) => et(v, W)),
58
+ ...Array.isArray(S) ? S : [S]
59
59
  ]
60
60
  )
61
61
  );
@@ -65,13 +65,13 @@ const vt = Le(
65
65
  * This source code is licensed under the ISC license.
66
66
  * See the LICENSE file in the root directory of this source tree.
67
67
  */
68
- const X = (t, i) => {
69
- const r = Le(
70
- ({ className: o, ...s }, C) => Pe(vt, {
71
- ref: C,
68
+ const Y = (t, i) => {
69
+ const r = Pe(
70
+ ({ className: o, ...h }, S) => et(At, {
71
+ ref: S,
72
72
  iconNode: i,
73
- className: rt(`lucide-${bt(t)}`, o),
74
- ...s
73
+ className: Ct(`lucide-${Mt(t)}`, o),
74
+ ...h
75
75
  })
76
76
  );
77
77
  return r.displayName = `${t}`, r;
@@ -82,7 +82,7 @@ const X = (t, i) => {
82
82
  * This source code is licensed under the ISC license.
83
83
  * See the LICENSE file in the root directory of this source tree.
84
84
  */
85
- const Ge = X("CheckCheck", [
85
+ const ht = Y("CheckCheck", [
86
86
  ["path", { d: "M18 6 7 17l-5-5", key: "116fxf" }],
87
87
  ["path", { d: "m22 10-7.5 7.5L13 16", key: "ke71qq" }]
88
88
  ]);
@@ -92,14 +92,14 @@ const Ge = X("CheckCheck", [
92
92
  * This source code is licensed under the ISC license.
93
93
  * See the LICENSE file in the root directory of this source tree.
94
94
  */
95
- const ot = X("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
95
+ const lt = Y("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
96
96
  /**
97
97
  * @license lucide-react v0.468.0 - ISC
98
98
  *
99
99
  * This source code is licensed under the ISC license.
100
100
  * See the LICENSE file in the root directory of this source tree.
101
101
  */
102
- const kt = X("ChevronDown", [
102
+ const nt = Y("ChevronDown", [
103
103
  ["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]
104
104
  ]);
105
105
  /**
@@ -108,7 +108,7 @@ const kt = X("ChevronDown", [
108
108
  * This source code is licensed under the ISC license.
109
109
  * See the LICENSE file in the root directory of this source tree.
110
110
  */
111
- const wt = X("ChevronRight", [
111
+ const jt = Y("ChevronRight", [
112
112
  ["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]
113
113
  ]);
114
114
  /**
@@ -117,7 +117,7 @@ const wt = X("ChevronRight", [
117
117
  * This source code is licensed under the ISC license.
118
118
  * See the LICENSE file in the root directory of this source tree.
119
119
  */
120
- const St = X("CircleAlert", [
120
+ const Et = Y("CircleAlert", [
121
121
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
122
122
  ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
123
123
  ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
@@ -128,7 +128,7 @@ const St = X("CircleAlert", [
128
128
  * This source code is licensed under the ISC license.
129
129
  * See the LICENSE file in the root directory of this source tree.
130
130
  */
131
- const at = X("Ellipsis", [
131
+ const It = Y("Ellipsis", [
132
132
  ["circle", { cx: "12", cy: "12", r: "1", key: "41hilf" }],
133
133
  ["circle", { cx: "19", cy: "12", r: "1", key: "1wjl8i" }],
134
134
  ["circle", { cx: "5", cy: "12", r: "1", key: "1pcz8c" }]
@@ -139,7 +139,7 @@ const at = X("Ellipsis", [
139
139
  * This source code is licensed under the ISC license.
140
140
  * See the LICENSE file in the root directory of this source tree.
141
141
  */
142
- const Ct = X("Image", [
142
+ const Ot = Y("Image", [
143
143
  ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2", key: "1m3agn" }],
144
144
  ["circle", { cx: "9", cy: "9", r: "2", key: "af1f0g" }],
145
145
  ["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21", key: "1xmnt7" }]
@@ -150,7 +150,7 @@ const Ct = X("Image", [
150
150
  * This source code is licensed under the ISC license.
151
151
  * See the LICENSE file in the root directory of this source tree.
152
152
  */
153
- const It = X("Inbox", [
153
+ const Ut = Y("Inbox", [
154
154
  ["polyline", { points: "22 12 16 12 14 15 10 15 8 12 2 12", key: "o97t9d" }],
155
155
  [
156
156
  "path",
@@ -166,7 +166,7 @@ const It = X("Inbox", [
166
166
  * This source code is licensed under the ISC license.
167
167
  * See the LICENSE file in the root directory of this source tree.
168
168
  */
169
- const zt = X("Info", [
169
+ const Dt = Y("Info", [
170
170
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
171
171
  ["path", { d: "M12 16v-4", key: "1dtifu" }],
172
172
  ["path", { d: "M12 8h.01", key: "e9boi3" }]
@@ -177,7 +177,7 @@ const zt = X("Info", [
177
177
  * This source code is licensed under the ISC license.
178
178
  * See the LICENSE file in the root directory of this source tree.
179
179
  */
180
- const lt = X("LoaderCircle", [
180
+ const zt = Y("LoaderCircle", [
181
181
  ["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]
182
182
  ]);
183
183
  /**
@@ -186,7 +186,16 @@ const lt = X("LoaderCircle", [
186
186
  * This source code is licensed under the ISC license.
187
187
  * See the LICENSE file in the root directory of this source tree.
188
188
  */
189
- const Tt = X("Paperclip", [
189
+ const pt = Y("MessageCircle", [
190
+ ["path", { d: "M7.9 20A9 9 0 1 0 4 16.1L2 22Z", key: "vv11sd" }]
191
+ ]);
192
+ /**
193
+ * @license lucide-react v0.468.0 - ISC
194
+ *
195
+ * This source code is licensed under the ISC license.
196
+ * See the LICENSE file in the root directory of this source tree.
197
+ */
198
+ const Pt = Y("Paperclip", [
190
199
  ["path", { d: "M13.234 20.252 21 12.3", key: "1cbrk9" }],
191
200
  [
192
201
  "path",
@@ -202,7 +211,7 @@ const Tt = X("Paperclip", [
202
211
  * This source code is licensed under the ISC license.
203
212
  * See the LICENSE file in the root directory of this source tree.
204
213
  */
205
- const Rt = X("Play", [
214
+ const Nt = Y("Play", [
206
215
  ["polygon", { points: "6 3 20 12 6 21 6 3", key: "1oa8hb" }]
207
216
  ]);
208
217
  /**
@@ -211,7 +220,7 @@ const Rt = X("Play", [
211
220
  * This source code is licensed under the ISC license.
212
221
  * See the LICENSE file in the root directory of this source tree.
213
222
  */
214
- const Xe = X("Search", [
223
+ const ut = Y("Search", [
215
224
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
216
225
  ["path", { d: "m21 21-4.3-4.3", key: "1qie3q" }]
217
226
  ]);
@@ -221,7 +230,7 @@ const Xe = X("Search", [
221
230
  * This source code is licensed under the ISC license.
222
231
  * See the LICENSE file in the root directory of this source tree.
223
232
  */
224
- const Bt = X("Send", [
233
+ const Ft = Y("Send", [
225
234
  [
226
235
  "path",
227
236
  {
@@ -237,7 +246,7 @@ const Bt = X("Send", [
237
246
  * This source code is licensed under the ISC license.
238
247
  * See the LICENSE file in the root directory of this source tree.
239
248
  */
240
- const Wt = X("SlidersHorizontal", [
249
+ const Kt = Y("SlidersHorizontal", [
241
250
  ["line", { x1: "21", x2: "14", y1: "4", y2: "4", key: "obuewd" }],
242
251
  ["line", { x1: "10", x2: "3", y1: "4", y2: "4", key: "1q6298" }],
243
252
  ["line", { x1: "21", x2: "12", y1: "12", y2: "12", key: "1iu8h1" }],
@@ -254,7 +263,7 @@ const Wt = X("SlidersHorizontal", [
254
263
  * This source code is licensed under the ISC license.
255
264
  * See the LICENSE file in the root directory of this source tree.
256
265
  */
257
- const $t = X("Smile", [
266
+ const qt = Y("Smile", [
258
267
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
259
268
  ["path", { d: "M8 14s1.5 2 4 2 4-2 4-2", key: "1y1vjs" }],
260
269
  ["line", { x1: "9", x2: "9.01", y1: "9", y2: "9", key: "yxxnd0" }],
@@ -266,7 +275,30 @@ const $t = X("Smile", [
266
275
  * This source code is licensed under the ISC license.
267
276
  * See the LICENSE file in the root directory of this source tree.
268
277
  */
269
- const je = X("X", [
278
+ const Vt = Y("UserCheck", [
279
+ ["path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", key: "1yyitq" }],
280
+ ["circle", { cx: "9", cy: "7", r: "4", key: "nufk8" }],
281
+ ["polyline", { points: "16 11 18 13 22 9", key: "1pwet4" }]
282
+ ]);
283
+ /**
284
+ * @license lucide-react v0.468.0 - ISC
285
+ *
286
+ * This source code is licensed under the ISC license.
287
+ * See the LICENSE file in the root directory of this source tree.
288
+ */
289
+ const ft = Y("UserPlus", [
290
+ ["path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", key: "1yyitq" }],
291
+ ["circle", { cx: "9", cy: "7", r: "4", key: "nufk8" }],
292
+ ["line", { x1: "19", x2: "19", y1: "8", y2: "14", key: "1bvyxn" }],
293
+ ["line", { x1: "22", x2: "16", y1: "11", y2: "11", key: "1shjgl" }]
294
+ ]);
295
+ /**
296
+ * @license lucide-react v0.468.0 - ISC
297
+ *
298
+ * This source code is licensed under the ISC license.
299
+ * See the LICENSE file in the root directory of this source tree.
300
+ */
301
+ const Ue = Y("X", [
270
302
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
271
303
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
272
304
  ]);
@@ -276,7 +308,7 @@ const je = X("X", [
276
308
  * This source code is licensed under the ISC license.
277
309
  * See the LICENSE file in the root directory of this source tree.
278
310
  */
279
- const Lt = X("Zap", [
311
+ const Gt = Y("Zap", [
280
312
  [
281
313
  "path",
282
314
  {
@@ -285,22 +317,31 @@ const Lt = X("Zap", [
285
317
  }
286
318
  ]
287
319
  ]);
288
- class Mt {
320
+ class it {
289
321
  constructor(i, r) {
290
322
  this.apiUrl = i, this.token = r;
291
323
  }
292
324
  async request(i, r, o) {
293
- const s = {
325
+ const h = {
294
326
  authorization: `Bearer ${this.token}`,
295
327
  ...o ? {} : { "content-type": "application/json" },
296
328
  ...r == null ? void 0 : r.headers
297
- }, C = await fetch(`${this.apiUrl}${i}`, {
329
+ }, S = await fetch(`${this.apiUrl}${i}`, {
298
330
  ...r,
299
- headers: s
300
- }), m = await C.json().catch(() => null);
301
- if (!C.ok) throw new Error((m == null ? void 0 : m.message) ?? `Request failed (${C.status})`);
331
+ headers: h
332
+ }), m = await S.json().catch(() => null);
333
+ if (!S.ok) throw new Error((m == null ? void 0 : m.message) ?? `Request failed (${S.status})`);
302
334
  return m;
303
335
  }
336
+ getSessionMe() {
337
+ return this.request("/v1/auth/session/me");
338
+ }
339
+ assignConversation(i, r) {
340
+ return this.request(`/v1/conversations/${encodeURIComponent(i)}/assignee`, {
341
+ method: "PATCH",
342
+ body: JSON.stringify({ agent: r })
343
+ });
344
+ }
304
345
  listConnections() {
305
346
  return this.request("/v1/connections");
306
347
  }
@@ -356,38 +397,38 @@ class Mt {
356
397
  }
357
398
  connectSSE(i) {
358
399
  const r = `${this.apiUrl}/v1/events?token=${encodeURIComponent(this.token)}`;
359
- let o, s, C = !1;
400
+ let o, h, S = !1;
360
401
  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));
402
+ o = new EventSource(r), o.addEventListener("message.new", (M) => {
403
+ i("message.new", JSON.parse(M.data));
404
+ }), o.addEventListener("conversation.updated", (M) => {
405
+ i("conversation.updated", JSON.parse(M.data));
365
406
  }), o.onerror = () => {
366
- o.close(), C || (s = setTimeout(m, 5e3));
407
+ o.close(), S || (h = setTimeout(m, 5e3));
367
408
  };
368
409
  };
369
410
  return m(), () => {
370
- C = !0, clearTimeout(s), o == null || o.close();
411
+ S = !0, clearTimeout(h), o == null || o.close();
371
412
  };
372
413
  }
373
414
  }
374
415
  function dt({ src: t, alt: i = "", fallback: r, style: o }) {
375
416
  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
417
  }
377
- function Ht({ variant: t = "ghost", style: i, ...r }) {
418
+ function Xt({ variant: t = "ghost", style: i, ...r }) {
378
419
  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
420
  }
380
- function Et({ style: t, ...i }) {
421
+ function Yt({ style: t, ...i }) {
381
422
  return /* @__PURE__ */ e("input", { ...i, style: { width: "100%", minWidth: 0, border: 0, outline: 0, background: "transparent", font: "inherit", ...t } });
382
423
  }
383
- const ct = Le(
424
+ const Rt = Pe(
384
425
  ({ children: t, style: i }, r) => /* @__PURE__ */ e("div", { ref: r, style: { minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", ...i }, children: t })
385
- ), jt = Le(
426
+ ), Jt = Pe(
386
427
  function({ style: i, ...r }, o) {
387
428
  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
429
  }
389
430
  );
390
- function At(t) {
431
+ function Zt(t) {
391
432
  return {
392
433
  id: t.contactId ?? t.providerConversationKey,
393
434
  name: t.contactName,
@@ -396,10 +437,10 @@ function At(t) {
396
437
  ...t.contactExternalId ? { externalId: t.contactExternalId } : {}
397
438
  };
398
439
  }
399
- function Ae(t, i) {
440
+ function Je(t, i) {
400
441
  return {
401
442
  conversation: t,
402
- contact: At(t),
443
+ contact: Zt(t),
403
444
  provider: i == null ? void 0 : i.provider,
404
445
  recentMessages: i == null ? void 0 : i.recentMessages,
405
446
  linkContact: (i == null ? void 0 : i.linkContact) ?? (async () => {
@@ -410,7 +451,7 @@ function Ae(t, i) {
410
451
  })
411
452
  };
412
453
  }
413
- class Ot extends mt {
454
+ class _t extends Lt {
414
455
  constructor() {
415
456
  super(...arguments), this.state = { caught: !1 };
416
457
  }
@@ -421,33 +462,33 @@ class Ot extends mt {
421
462
  return this.state.caught ? null : this.props.children;
422
463
  }
423
464
  }
424
- const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, Je = [
465
+ const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, gt = [
425
466
  { icon: "😊", emojis: ["😀", "😁", "😂", "🤣", "😊", "😇", "🙂", "😉", "😍", "🥰", "😘", "😋", "😎", "🤩", "😏", "😒", "😔", "😢", "😭", "😤", "😠", "🤯", "😱", "🥳", "😴", "🤔", "🤗", "🫡", "😮", "🤧", "🥺", "😶", "🫠", "🤭", "🤫"] },
426
467
  { icon: "👋", emojis: ["👍", "👎", "👏", "🙏", "🤝", "✌️", "🤞", "🫡", "💪", "🤜", "👊", "✊", "🖐", "👌", "🤌", "🤏", "☝️", "👆", "👇", "👉", "👈", "🤙", "💅", "🫶", "❤️", "🧡", "💛", "💚", "💙", "💜", "🖤", "💔", "❣️", "💕", "💯"] },
427
468
  { icon: "🐱", emojis: ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🙈", "🐔", "🐧", "🐦", "🦆", "🦅", "🦉", "🦋", "🐝", "🐛", "🐢", "🦎", "🐬", "🦈", "🐳", "🐙", "🦑"] },
428
469
  { icon: "🍕", emojis: ["🍎", "🍊", "🍋", "🍇", "🍓", "🍒", "🥝", "🥑", "🍔", "🍕", "🌮", "🍜", "🍣", "🍦", "🎂", "🍰", "🧁", "☕", "🧋", "🥤", "🍺", "🥂", "🍾", "🧃", "🧊"] },
429
470
  { icon: "⚽", emojis: ["⚽", "🏀", "🏈", "⚾", "🎾", "🏐", "🏓", "🎮", "🎲", "🎯", "🎳", "🏆", "🥇", "🎖", "🎁", "🎉", "🎊", "🎈", "🎭", "🎨", "🎬", "🎵", "🎸", "🎹", "🎺", "🪗", "🎻"] },
430
471
  { icon: "🌍", emojis: ["🌍", "🌈", "⭐", "🌙", "☀️", "⛅", "🌊", "🔥", "💧", "🌿", "🌸", "🌺", "🌻", "🍀", "🌴", "🏔", "🏖", "🏕", "🌃", "🏙", "🌅", "🌄", "🌠", "🌌", "🌋", "🏝"] }
431
- ], qe = nt(""), st = nt("");
432
- function Ut() {
472
+ ], st = wt(""), Tt = wt("");
473
+ function Qt() {
433
474
  try {
434
475
  const t = new AudioContext(), i = t.createOscillator(), r = t.createGain();
435
476
  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);
436
477
  } catch {
437
478
  }
438
479
  }
439
- function Dt(t) {
480
+ function en(t) {
440
481
  if (!(t != null && t.metadata)) return;
441
482
  const i = t.metadata, r = i.pageName ?? i.displayName ?? i.username ?? i.name;
442
483
  return typeof r == "string" && r ? r : void 0;
443
484
  }
444
- function ht(t) {
485
+ function Wt(t) {
445
486
  return t === "facebook" ? "Facebook Messenger" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo OA" : t === "livechat" ? "Live Chat" : "Channel";
446
487
  }
447
- function Ye(t) {
488
+ function yt(t) {
448
489
  return t === "facebook" ? "Facebook" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo" : t === "livechat" ? "Live Chat" : String(t ?? "");
449
490
  }
450
- const Pt = (t) => {
491
+ const tn = (t) => {
451
492
  var r;
452
493
  const i = {
453
494
  "application/pdf": "PDF",
@@ -458,85 +499,122 @@ const Pt = (t) => {
458
499
  };
459
500
  return t ? i[t] ?? ((r = t.split("/")[1]) == null ? void 0 : r.toUpperCase()) ?? "Tệp" : "Tệp đính kèm";
460
501
  };
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;
502
+ function bt({ status: t }) {
503
+ return t === "read" ? /* @__PURE__ */ e(ht, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(ht, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(lt, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
463
504
  }
464
- const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: C, disableAttachments: m, disableNotificationSound: O, hideKeyboardHint: f, locale: S = "vi", extensions: W, onNewMessage: I, onConversationSelect: H }, R) {
465
- var l, g, b, M, Z;
466
- const E = ee(new Mt(i, r)), [j, A] = y([]), [F, K] = y([]), [ne, U] = y(), [w, _] = y(), k = ee(void 0), [L, se] = y(""), [z, D] = y({ provider: "all", unreadOnly: !1 }), [le, v] = y(!1), Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!0), [B, P] = y(""), [q, ie] = y(() => !!(W != null && W.length)), [re, V] = y(280), [ye, ke] = y(!1), [be, fe] = y(0), G = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", de = Ee(() => new Map(F.map((c) => [c.id, c])), [F]), me = ee(null), [we, Oe] = y(0), Se = We(async (c, u) => {
467
- c.contactId && await E.current.patchContact(c.contactId, u), A((T) => T.map(($) => $.id === c.id ? { ...$, contactExternalId: u ?? void 0 } : $)), _((T) => T && T.id === c.id ? { ...T, contactExternalId: u ?? void 0 } : T), fe((T) => T + 1);
468
- }, []), Ce = We(() => {
469
- fe((c) => c + 1);
470
- }, []), Ie = Ee(() => {
471
- const c = new Set(F.map((u) => u.provider));
472
- return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) => c.has(u));
473
- }, [F]), ue = Ee(() => {
474
- var u;
475
- const c = {};
476
- for (const T of j) {
477
- const $ = ((u = de.get(T.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
478
- c[$] = (c[$] ?? 0) + 1;
505
+ function rt(t) {
506
+ const i = t.trim().split(/\s+/).filter(Boolean);
507
+ return i.length <= 2 ? t.trim() : i.slice(-2).join(" ");
508
+ }
509
+ const Wn = Pe(function({ apiUrl: i, token: r, theme: o, height: h, defaultConversationId: S, disableAttachments: m, disableNotificationSound: M, hideKeyboardHint: w, locale: v = "vi", extensions: W, currentAgent: T, teamAgents: j, onNewMessage: $, onConversationSelect: C }, D) {
510
+ var k, A, K, U, re;
511
+ const I = J(new it(i, r)), [L, P] = y([]), [q, te] = y([]), [Q, B] = y(), [x, b] = y(), E = J(void 0), [V, ne] = y(""), [de, z] = y("all"), [oe, Z] = y(null), [O, ee] = y({ provider: "all", unreadOnly: !1 }), [se, c] = y(!1), H = J(null), N = J(null), [ae, ce] = y(null), [ye, F] = y(!0), [he, Se] = y(""), [Me, He] = y(() => !!(W != null && W.length)), [Ae, Ce] = y(280), [ve, Ie] = y(!1), [Ne, me] = y(0), _ = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", ue = $e(() => new Map(q.map((l) => [l.id, l])), [q]), ze = J(null), [Fe, je] = y(0), G = T ?? oe ?? null;
512
+ X(() => {
513
+ I.current = new it(i, r), T || I.current.getSessionMe().then((l) => {
514
+ l != null && l.agent && Z(l.agent);
515
+ }).catch(() => {
516
+ });
517
+ }, [i, r, T]);
518
+ const Ke = $e(() => {
519
+ var p;
520
+ const l = /* @__PURE__ */ new Map();
521
+ G != null && G.id && l.set(G.id, G);
522
+ for (const u of j ?? [])
523
+ u != null && u.id && !l.has(u.id) && l.set(u.id, u);
524
+ for (const u of L)
525
+ (p = u.assignedAgent) != null && p.id && !l.has(u.assignedAgent.id) && l.set(u.assignedAgent.id, u.assignedAgent);
526
+ return [...l.values()];
527
+ }, [G, j, L]), qe = we(async (l, p) => {
528
+ P((u) => u.map((R) => R.id === l.id ? { ...R, assignedAgent: p } : R)), b((u) => u && u.id === l.id ? { ...u, assignedAgent: p } : u), me((u) => u + 1);
529
+ try {
530
+ const u = await I.current.assignConversation(l.id, p);
531
+ P((R) => R.map((le) => le.id === l.id ? { ...le, ...u, assignedAgent: u.assignedAgent ?? p } : le)), b((R) => R && R.id === l.id ? { ...R, ...u, assignedAgent: u.assignedAgent ?? p } : R), me((R) => R + 1);
532
+ } catch {
479
533
  }
480
- return c;
481
- }, [j, de]);
482
- function Me(c) {
483
- const u = c.clientX, T = re;
484
- ke(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
485
- function $(xe) {
486
- const Re = Math.max(200, Math.min(480, T + (u - xe.clientX)));
487
- V(Re);
534
+ }, []), ke = we(async (l, p) => {
535
+ l.contactId && await I.current.patchContact(l.contactId, p), P((u) => u.map((R) => R.id === l.id ? { ...R, contactExternalId: p ?? void 0 } : R)), b((u) => u && u.id === l.id ? { ...u, contactExternalId: p ?? void 0 } : u), me((u) => u + 1);
536
+ }, []), fe = we(() => {
537
+ me((l) => l + 1);
538
+ }, []), Ve = $e(() => {
539
+ const l = new Set(q.map((p) => p.provider));
540
+ return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((p) => l.has(p));
541
+ }, [q]), Ge = $e(() => {
542
+ var p;
543
+ const l = {};
544
+ for (const u of L) {
545
+ const R = ((p = ue.get(u.connectionId)) == null ? void 0 : p.provider) ?? "unknown";
546
+ l[R] = (l[R] ?? 0) + 1;
488
547
  }
489
- function ce() {
490
- ke(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", $), document.removeEventListener("mouseup", ce);
548
+ return l;
549
+ }, [L, ue]);
550
+ function Ze(l) {
551
+ const p = l.clientX, u = Ae;
552
+ Ie(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
553
+ function R(We) {
554
+ const Ee = Math.max(200, Math.min(480, u + (p - We.clientX)));
555
+ Ce(Ee);
491
556
  }
492
- document.addEventListener("mousemove", $), document.addEventListener("mouseup", ce);
557
+ function le() {
558
+ Ie(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", R), document.removeEventListener("mouseup", le);
559
+ }
560
+ document.addEventListener("mousemove", R), document.addEventListener("mouseup", le);
493
561
  }
494
- const oe = We(async (c) => {
562
+ const pe = we(async (l) => {
495
563
  try {
496
- const u = await E.current.listConversations(c);
497
- A((T) => c ? [...T, ...u.items] : u.items), U(u.nextCursor), !c && u.items.length && _((T) => T ?? (C ? u.items.find(($) => $.id === C) ?? u.items[0] : u.items[0])), P("");
498
- } catch (u) {
499
- P(u instanceof Error ? u.message : "Không tải được hội thoại");
564
+ const p = await I.current.listConversations(l);
565
+ P((u) => l ? [...u, ...p.items] : p.items), B(p.nextCursor), !l && p.items.length && b((u) => u ?? (S ? p.items.find((R) => R.id === S) ?? p.items[0] : p.items[0])), Se("");
566
+ } catch (p) {
567
+ Se(p instanceof Error ? p.message : "Không tải được hội thoại");
500
568
  } finally {
501
- h(!1);
569
+ F(!1);
502
570
  }
503
- }, [C]);
504
- Y(() => (E.current.listConnections().then(K).catch(() => {
505
- }), oe(), E.current.connectSSE((u, T) => {
506
- if (u === "message.new" || u === "conversation.updated") {
507
- if (oe(), u === "message.new") {
508
- const $ = typeof T == "object" && T ? T : {}, ce = $.conversationId ? String($.conversationId) : "", xe = $.messageId ? String($.messageId) : "";
509
- if (($.direction ? String($.direction) : "") === "inbound" && !O && Ut(), ce && ce === k.current && xe && me.current) {
510
- const ft = me.current;
511
- E.current.getMessage(xe).then((gt) => {
512
- ft(gt);
571
+ }, [S]);
572
+ X(() => (I.current.listConnections().then(te).catch(() => {
573
+ }), pe(), I.current.connectSSE((p, u) => {
574
+ if (p === "message.new" || p === "conversation.updated") {
575
+ if (pe(), p === "message.new") {
576
+ const R = typeof u == "object" && u ? u : {}, le = R.conversationId ? String(R.conversationId) : "", We = R.messageId ? String(R.messageId) : "";
577
+ if ((R.direction ? String(R.direction) : "") === "inbound" && !M && Qt(), le && le === E.current && We && ze.current) {
578
+ const Xe = ze.current;
579
+ I.current.getMessage(We).then((Ye) => {
580
+ Xe(Ye);
513
581
  }).catch(() => {
514
582
  });
515
583
  }
516
- I == null || I(ce || k.current || "");
584
+ $ == null || $(le || E.current || "");
517
585
  }
518
- } else u === "message.status_updated" && Oe(($) => $ + 1);
519
- })), [oe, I]), Y(() => {
520
- k.current = w == null ? void 0 : w.id;
521
- }, [w]), Y(() => {
522
- w != null && w.unreadCount && E.current.markRead(w.id).then(() => oe()).catch(() => {
586
+ } else p === "message.status_updated" && je((R) => R + 1);
587
+ })), [pe, $]), X(() => {
588
+ E.current = x == null ? void 0 : x.id;
589
+ }, [x]), X(() => {
590
+ x != null && x.unreadCount && I.current.markRead(x.id).then(() => pe()).catch(() => {
523
591
  });
524
- }, [w == null ? void 0 : w.id]), Y(() => {
525
- if (!le) return;
526
- function c(u) {
527
- var T, $;
528
- (T = Q.current) != null && T.contains(u.target) || ($ = N.current) != null && $.contains(u.target) || v(!1);
592
+ }, [x == null ? void 0 : x.id]), X(() => {
593
+ if (!se) return;
594
+ function l(p) {
595
+ var u, R;
596
+ (u = H.current) != null && u.contains(p.target) || (R = N.current) != null && R.contains(p.target) || c(!1);
529
597
  }
530
- return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
531
- }, [le]);
532
- const ze = Ee(() => {
533
- const c = L.toLowerCase().trim();
534
- return j.filter((u) => {
535
- var Re;
536
- const T = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), $ = ((Re = de.get(u.connectionId)) == null ? void 0 : Re.provider) ?? "unknown", ce = z.provider === "all" || $ === z.provider, xe = !z.unreadOnly || (u.unreadCount ?? 0) > 0;
537
- return ce && xe && (!c || T.includes(c));
598
+ return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
599
+ }, [se]);
600
+ const be = $e(() => {
601
+ const l = G ? L.filter((u) => {
602
+ var R;
603
+ return ((R = u.assignedAgent) == null ? void 0 : R.id) === G.id;
604
+ }).length : 0, p = L.filter((u) => !u.assignedAgent).length;
605
+ return { all: L.length, mine: l, unassigned: p };
606
+ }, [L, G]), Re = $e(() => {
607
+ const l = V.toLowerCase().trim();
608
+ return L.filter((p) => {
609
+ var Ee, Xe, Ye;
610
+ if (de === "mine") {
611
+ if (!G || ((Ee = p.assignedAgent) == null ? void 0 : Ee.id) !== G.id) return !1;
612
+ } else if (de === "unassigned" && p.assignedAgent)
613
+ return !1;
614
+ const u = `${p.contactName ?? ""} ${p.subject ?? ""} ${p.providerConversationKey} ${((Xe = p.assignedAgent) == null ? void 0 : Xe.name) ?? ""}`.toLowerCase(), R = ((Ye = ue.get(p.connectionId)) == null ? void 0 : Ye.provider) ?? "unknown", le = O.provider === "all" || R === O.provider, We = !O.unreadOnly || (p.unreadCount ?? 0) > 0;
615
+ return le && We && (!l || u.includes(l));
538
616
  });
539
- }, [j, de, z, L]), Te = z.provider !== "all" || z.unreadOnly, ae = S === "en" ? {
617
+ }, [L, ue, O, V, de, G]), Te = O.provider !== "all" || O.unreadOnly, a = v === "en" ? {
540
618
  today: "TODAY",
541
619
  loadOlder: "↑ Load older messages",
542
620
  loading: "Loading messages…",
@@ -557,383 +635,764 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
557
635
  send: "Gửi",
558
636
  all: "Tất cả"
559
637
  };
560
- yt(R, () => ({
561
- openConversation: (c) => {
562
- const u = j.find((T) => T.id === c);
563
- u && _(u);
638
+ Bt(D, () => ({
639
+ openConversation: (l) => {
640
+ const p = L.find((u) => u.id === l);
641
+ p && b(p);
564
642
  },
565
- refresh: () => void oe()
566
- }), [j, oe]);
567
- const He = {
568
- ...p.frame,
569
- height: s ?? 620,
570
- ...s ? { maxHeight: "none" } : {},
643
+ refresh: () => void pe()
644
+ }), [L, pe]);
645
+ const g = {
646
+ ...f.frame,
647
+ height: h ?? 620,
648
+ ...h ? { maxHeight: "none" } : {},
571
649
  fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif",
572
650
  borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px",
573
- gridTemplateColumns: q ? `minmax(260px, 300px) minmax(0, 1fr) ${re}px` : "minmax(260px, 300px) minmax(0, 1fr)",
574
- transition: ye ? "none" : "grid-template-columns 220ms ease"
651
+ gridTemplateColumns: Me ? `minmax(260px, 300px) minmax(0, 1fr) ${Ae}px` : "minmax(260px, 300px) minmax(0, 1fr)",
652
+ transition: ve ? "none" : "grid-template-columns 220ms ease"
575
653
  };
576
- return he ? /* @__PURE__ */ n("div", { style: { ...p.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
577
- /* @__PURE__ */ e(Fe, {}),
654
+ return ye ? /* @__PURE__ */ n("div", { style: { ...f.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
655
+ /* @__PURE__ */ e(ot, {}),
578
656
  " Đang tải hộp thư…"
579
- ] }) : B && !j.length ? /* @__PURE__ */ n("div", { style: { ...p.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
580
- /* @__PURE__ */ e(St, { size: 16, strokeWidth: 2 }),
657
+ ] }) : he && !L.length ? /* @__PURE__ */ n("div", { style: { ...f.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
658
+ /* @__PURE__ */ e(Et, { size: 16, strokeWidth: 2 }),
581
659
  " ",
582
- B,
583
- /* @__PURE__ */ e("button", { style: p.retry, onClick: () => {
584
- h(!0), oe();
660
+ he,
661
+ /* @__PURE__ */ e("button", { style: f.retry, onClick: () => {
662
+ F(!0), pe();
585
663
  }, children: "Thử lại" })
586
- ] }) : /* @__PURE__ */ e(qe.Provider, { value: i, children: /* @__PURE__ */ e(st.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
587
- const c = window.scrollY;
664
+ ] }) : /* @__PURE__ */ e(st.Provider, { value: i, children: /* @__PURE__ */ e(Tt.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: g, onFocusCapture: () => {
665
+ const l = window.scrollY;
588
666
  requestAnimationFrame(() => {
589
- window.scrollY !== c && window.scrollTo({ top: c, behavior: "instant" });
667
+ window.scrollY !== l && window.scrollTo({ top: l, behavior: "instant" });
590
668
  });
591
669
  }, children: [
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: (l = o == null ? void 0 : o.branding) != null && l.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((g = o == null ? void 0 : o.branding) == null ? void 0 : g.mark) ?? "C" }),
670
+ /* @__PURE__ */ n("aside", { style: f.sidebar, children: [
671
+ /* @__PURE__ */ n("div", { style: f.brand, children: [
672
+ /* @__PURE__ */ e("div", { style: { ...f.brandMark, background: _, overflow: "hidden", padding: 0 }, children: (k = o == null ? void 0 : o.branding) != null && k.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((A = o == null ? void 0 : o.branding) == null ? void 0 : A.mark) ?? "C" }),
595
673
  /* @__PURE__ */ n("div", { children: [
596
- /* @__PURE__ */ e("strong", { children: ((b = o == null ? void 0 : o.branding) == null ? void 0 : b.name) ?? "Hộp thư" }),
597
- !((M = o == null ? void 0 : o.branding) != null && M.name) && /* @__PURE__ */ e("span", { style: p.eyebrow, children: "CHANNELHUB" })
674
+ /* @__PURE__ */ e("strong", { children: ((K = o == null ? void 0 : o.branding) == null ? void 0 : K.name) ?? "Hộp thư" }),
675
+ !((U = o == null ? void 0 : o.branding) != null && U.name) && /* @__PURE__ */ e("span", { style: f.eyebrow, children: "CHANNELHUB" })
598
676
  ] }),
599
- /* @__PURE__ */ e(Ht, { "aria-label": "Tùy chọn", style: p.iconButton, children: /* @__PURE__ */ e(at, { size: 16, strokeWidth: 2 }) })
677
+ /* @__PURE__ */ e(Xt, { "aria-label": "Tùy chọn", style: f.iconButton, children: /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }) })
600
678
  ] }),
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: (c) => se(c.target.value), placeholder: ae.searchPlaceholder }),
604
- L && /* @__PURE__ */ e("button", { style: p.clear, onClick: () => se(""), "aria-label": "Xóa tìm kiếm", children: "×" })
679
+ /* @__PURE__ */ n("div", { style: f.search, children: [
680
+ /* @__PURE__ */ e(ut, { size: 16, strokeWidth: 2 }),
681
+ /* @__PURE__ */ e(Yt, { "aria-label": a.searchPlaceholder, value: V, onChange: (l) => ne(l.target.value), placeholder: a.searchPlaceholder }),
682
+ V && /* @__PURE__ */ e("button", { style: f.clear, onClick: () => ne(""), "aria-label": "Xóa tìm kiếm", children: "×" })
605
683
  ] }),
684
+ /* @__PURE__ */ e(
685
+ "div",
686
+ {
687
+ role: "tablist",
688
+ "aria-label": "Lọc theo người phụ trách",
689
+ style: {
690
+ display: "grid",
691
+ gridTemplateColumns: "repeat(3, 1fr)",
692
+ gap: 2,
693
+ margin: "0 14px 10px",
694
+ padding: 3,
695
+ borderRadius: 9,
696
+ border: `1px solid ${d.line}`,
697
+ background: d.surface
698
+ },
699
+ children: [
700
+ { key: "all", label: v === "en" ? "All" : "Tất cả", count: be.all },
701
+ { key: "mine", label: v === "en" ? "Mine" : "Của tôi", count: be.mine },
702
+ { key: "unassigned", label: v === "en" ? "Unassigned" : "Chưa nhận", count: be.unassigned }
703
+ ].map((l) => {
704
+ const p = de === l.key;
705
+ return /* @__PURE__ */ n(
706
+ "button",
707
+ {
708
+ type: "button",
709
+ role: "tab",
710
+ "aria-selected": p,
711
+ onClick: () => z(l.key),
712
+ style: {
713
+ border: 0,
714
+ borderRadius: 6,
715
+ padding: "5px 4px",
716
+ fontSize: 11,
717
+ fontWeight: p ? 700 : 500,
718
+ background: p ? d.white : "transparent",
719
+ color: p ? _ : d.muted,
720
+ boxShadow: p ? "0 1px 3px rgba(23,32,51,.08)" : "none",
721
+ cursor: "pointer",
722
+ whiteSpace: "nowrap",
723
+ overflow: "hidden",
724
+ textOverflow: "ellipsis",
725
+ transition: "all 120ms ease"
726
+ },
727
+ children: [
728
+ l.label,
729
+ " ",
730
+ /* @__PURE__ */ n("span", { style: { opacity: 0.75 }, children: [
731
+ "(",
732
+ l.count,
733
+ ")"
734
+ ] })
735
+ ]
736
+ },
737
+ l.key
738
+ );
739
+ })
740
+ }
741
+ ),
606
742
  Te && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
607
- z.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
608
- /* @__PURE__ */ e($e, { provider: z.provider }),
609
- Ye(z.provider),
610
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(je, { size: 10 }) })
743
+ O.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: _, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
744
+ /* @__PURE__ */ e(De, { provider: O.provider }),
745
+ yt(O.provider),
746
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: _, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => ee((l) => ({ ...l, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(Ue, { size: 10 }) })
611
747
  ] }),
612
- z.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
613
- ae.unreadOnly,
614
- /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(je, { size: 10 }) })
748
+ O.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: _, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
749
+ a.unreadOnly,
750
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: _, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => ee((l) => ({ ...l, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(Ue, { size: 10 }) })
615
751
  ] }),
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ả" })
752
+ /* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: d.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => ee({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
617
753
  ] }),
618
- /* @__PURE__ */ n("div", { style: p.listHeader, children: [
754
+ /* @__PURE__ */ n("div", { style: f.listHeader, children: [
619
755
  /* @__PURE__ */ n("span", { children: [
620
- ze.length,
756
+ Re.length,
621
757
  " hội thoại"
622
758
  ] }),
623
759
  /* @__PURE__ */ e(
624
760
  "button",
625
761
  {
626
- ref: Q,
627
- style: { ...p.iconButton, background: Te ? `${G}14` : "transparent", color: Te ? G : d.muted },
762
+ ref: H,
763
+ style: { ...f.iconButton, background: Te ? `${_}14` : "transparent", color: Te ? _ : d.muted },
628
764
  "aria-label": "Bộ lọc",
629
765
  onClick: () => {
630
- var c;
631
- if (!le) {
632
- const u = (c = Q.current) == null ? void 0 : c.getBoundingClientRect();
633
- u && J({ top: u.bottom + 6, left: u.left });
766
+ var l;
767
+ if (!se) {
768
+ const p = (l = H.current) == null ? void 0 : l.getBoundingClientRect();
769
+ p && ce({ top: p.bottom + 6, left: p.left });
634
770
  }
635
- v((u) => !u);
771
+ c((p) => !p);
636
772
  },
637
- children: /* @__PURE__ */ e(Wt, { size: 15, strokeWidth: 2 })
773
+ children: /* @__PURE__ */ e(Kt, { size: 15, strokeWidth: 2 })
638
774
  }
639
775
  )
640
776
  ] }),
641
- le && x && it(
777
+ se && ae && St(
642
778
  /* @__PURE__ */ n(
643
779
  "div",
644
780
  {
645
781
  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 },
782
+ style: { position: "fixed", top: ae.top, left: ae.left, zIndex: 9999, background: d.white, border: `1px solid ${d.line}`, borderRadius: 10, padding: "12px 14px", boxShadow: "0 8px 24px rgba(23,32,51,.14)", minWidth: 210, fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif", fontSize: 13 },
647
783
  children: [
648
784
  /* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
649
- ["all", ...Ie].map((c) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.provider === c ? `${G}0f` : "transparent" }, children: [
650
- /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider === c, onChange: () => D((u) => ({ ...u, provider: c })), style: { accentColor: G } }),
651
- c === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
652
- ae.all,
785
+ ["all", ...Ve].map((l) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: O.provider === l ? `${_}0f` : "transparent" }, children: [
786
+ /* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: O.provider === l, onChange: () => ee((p) => ({ ...p, provider: l })), style: { accentColor: _ } }),
787
+ l === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
788
+ a.all,
653
789
  " (",
654
- j.length,
790
+ L.length,
655
791
  ")"
656
792
  ] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: d.ink }, children: [
657
- /* @__PURE__ */ e($e, { provider: c }),
658
- Ye(c),
793
+ /* @__PURE__ */ e(De, { provider: l }),
794
+ yt(l),
659
795
  " ",
660
796
  /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
661
797
  "(",
662
- ue[c] ?? 0,
798
+ Ge[l] ?? 0,
663
799
  ")"
664
800
  ] })
665
801
  ] })
666
- ] }, c)),
802
+ ] }, l)),
667
803
  /* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${d.line}`, margin: "8px 0 6px" } }),
668
- /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.unreadOnly ? `${G}0f` : "transparent" }, children: [
669
- /* @__PURE__ */ e("input", { type: "checkbox", checked: z.unreadOnly, onChange: (c) => D((u) => ({ ...u, unreadOnly: c.target.checked })), style: { accentColor: G } }),
670
- /* @__PURE__ */ e("span", { style: { color: d.ink }, children: ae.unreadOnly })
804
+ /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: O.unreadOnly ? `${_}0f` : "transparent" }, children: [
805
+ /* @__PURE__ */ e("input", { type: "checkbox", checked: O.unreadOnly, onChange: (l) => ee((p) => ({ ...p, unreadOnly: l.target.checked })), style: { accentColor: _ } }),
806
+ /* @__PURE__ */ e("span", { style: { color: d.ink }, children: a.unreadOnly })
671
807
  ] })
672
808
  ]
673
809
  }
674
810
  ),
675
811
  document.body
676
812
  ),
677
- /* @__PURE__ */ n(ct, { style: p.conversationList, children: [
678
- ze.map((c) => {
679
- var u;
680
- return /* @__PURE__ */ e(Nt, { conversation: c, provider: (u = de.get(c.connectionId)) == null ? void 0 : u.provider, selected: (w == null ? void 0 : w.id) === c.id, primary: G, onSelect: () => {
681
- _(c), H == null || H(c.id), E.current.markRead(c.id).then(() => oe()).catch(() => {
813
+ /* @__PURE__ */ n(Rt, { style: f.conversationList, children: [
814
+ Re.map((l) => {
815
+ var p;
816
+ return /* @__PURE__ */ e(nn, { conversation: l, provider: (p = ue.get(l.connectionId)) == null ? void 0 : p.provider, selected: (x == null ? void 0 : x.id) === l.id, primary: _, currentAgent: G, onSelect: () => {
817
+ b(l), C == null || C(l.id), I.current.markRead(l.id).then(() => pe()).catch(() => {
682
818
  });
683
- } }, c.id);
819
+ } }, l.id);
684
820
  }),
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 }) }),
821
+ !Re.length && /* @__PURE__ */ n("div", { style: f.emptySmall, children: [
822
+ /* @__PURE__ */ e("div", { style: f.emptyIcon, children: /* @__PURE__ */ e(ut, { size: 16, strokeWidth: 2 }) }),
687
823
  /* @__PURE__ */ e("strong", { children: "Không tìm thấy" }),
688
824
  /* @__PURE__ */ e("span", { children: "Thử từ khóa hoặc bộ lọc khác." })
689
825
  ] }),
690
- ne && /* @__PURE__ */ e("button", { style: p.loadMore, onClick: () => void oe(ne), children: "Xem thêm hội thoại" })
826
+ Q && /* @__PURE__ */ e("button", { style: f.loadMore, onClick: () => void pe(Q), children: "Xem thêm hội thoại" })
691
827
  ] })
692
828
  ] }),
693
- /* @__PURE__ */ e("main", { style: p.main, children: w ? /* @__PURE__ */ e(
694
- Ft,
829
+ /* @__PURE__ */ e("main", { style: f.main, children: x ? /* @__PURE__ */ e(
830
+ rn,
695
831
  {
696
- conversation: w,
697
- provider: (Z = de.get(w.connectionId)) == null ? void 0 : Z.provider,
698
- connection: de.get(w.connectionId),
699
- client: E.current,
700
- primary: G,
701
- error: B,
702
- onRegisterAppend: (c) => {
703
- me.current = c;
832
+ conversation: x,
833
+ provider: (re = ue.get(x.connectionId)) == null ? void 0 : re.provider,
834
+ connection: ue.get(x.connectionId),
835
+ client: I.current,
836
+ primary: _,
837
+ error: he,
838
+ onRegisterAppend: (l) => {
839
+ ze.current = l;
704
840
  },
705
- refreshKey: we,
706
- infoOpen: q,
707
- onToggleInfo: () => ie((c) => !c),
708
- t: ae,
841
+ refreshKey: Fe,
842
+ infoOpen: Me,
843
+ onToggleInfo: () => He((l) => !l),
844
+ t: a,
709
845
  disableAttachments: m,
710
- hideKeyboardHint: f,
846
+ hideKeyboardHint: w,
711
847
  extensions: W,
712
- onLinkContact: (c) => Se(w, c),
713
- onRefreshContactInfo: Ce
848
+ currentAgent: G,
849
+ teamAgents: Ke,
850
+ onAssignAgent: (l) => qe(x, l),
851
+ onLinkContact: (l) => ke(x, l),
852
+ onRefreshContactInfo: fe
714
853
  },
715
- w.id
716
- ) : /* @__PURE__ */ e(Gt, {}) }),
717
- q && w && /* @__PURE__ */ e(
718
- qt,
854
+ x.id
855
+ ) : /* @__PURE__ */ e(dn, {}) }),
856
+ Me && x && /* @__PURE__ */ e(
857
+ an,
719
858
  {
720
- conversation: w,
721
- connection: de.get(w.connectionId),
722
- primary: G,
723
- onClose: () => ie(!1),
724
- client: E.current,
725
- onStartResize: Me,
859
+ conversation: x,
860
+ connection: ue.get(x.connectionId),
861
+ primary: _,
862
+ onClose: () => He(!1),
863
+ client: I.current,
864
+ onStartResize: Ze,
726
865
  extensions: W,
727
- extRefreshKey: be,
728
- onLinkContact: (c) => Se(w, c),
729
- onRefreshContactInfo: Ce
866
+ extRefreshKey: Ne,
867
+ onLinkContact: (l) => ke(x, l),
868
+ onRefreshContactInfo: fe
730
869
  }
731
870
  )
732
871
  ] }) }) });
733
872
  });
734
- function Nt({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
735
- const [C, m] = y(!1), O = t.contactName ?? t.subject ?? t.providerConversationKey, f = t.unreadCount ?? 0, S = t.lastMessageText ?? "", W = t.lastMessageDirection === "outbound" ? "Bạn: " : "", I = S.length > 60 ? S.slice(0, 60) + "…" : S, H = S ? W + I : "";
736
- let R = "transparent";
737
- r ? R = "#eef2ff" : C ? R = "#f7f9fc" : f > 0 && (R = "#f0f4ff");
738
- const E = {
739
- ...p.row,
740
- background: R,
741
- ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : f > 0 && !C ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
873
+ function nn({ conversation: t, provider: i, selected: r, primary: o, currentAgent: h, onSelect: S }) {
874
+ const [m, M] = y(!1), w = t.contactName ?? t.subject ?? t.providerConversationKey, v = t.unreadCount ?? 0, W = t.lastMessageText ?? "", T = t.lastMessageDirection === "outbound" ? "Bạn: " : "", j = W.length > 60 ? W.slice(0, 60) + "…" : W, $ = W ? T + j : "", C = t.assignedAgent ?? null, D = !!(C && h && C.id === h.id);
875
+ let I = "transparent";
876
+ r ? I = "#eef2ff" : m ? I = "#f7f9fc" : v > 0 && (I = "#f0f4ff");
877
+ const L = {
878
+ ...f.row,
879
+ background: I,
880
+ ...r ? { boxShadow: `inset 3px 0 0 ${o}` } : v > 0 && !m ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
742
881
  };
743
882
  return /* @__PURE__ */ n(
744
883
  "button",
745
884
  {
746
- onClick: s,
747
- style: E,
748
- onMouseEnter: () => m(!0),
749
- onMouseLeave: () => m(!1),
885
+ onClick: S,
886
+ style: L,
887
+ onMouseEnter: () => M(!0),
888
+ onMouseLeave: () => M(!1),
750
889
  children: [
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 }),
890
+ /* @__PURE__ */ e($t, { name: w, color: o, image: t.contactPictureUrl, provider: i }),
891
+ /* @__PURE__ */ n("span", { style: f.rowBody, children: [
892
+ /* @__PURE__ */ n("span", { style: f.rowTop, children: [
893
+ /* @__PURE__ */ e("strong", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: v > 0 ? 700 : 500 }, children: w }),
755
894
  /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, flexShrink: 0 }, children: [
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 })
895
+ /* @__PURE__ */ e("time", { style: { color: d.muted, fontSize: 11, whiteSpace: "nowrap" }, children: at(t.lastMessageAt) }),
896
+ v > 0 && /* @__PURE__ */ e("span", { "aria-label": `${v} tin nhắn chưa đọc`, style: f.unreadBadge, children: v > 99 ? "99+" : v })
758
897
  ] })
759
898
  ] }),
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" }) }) })
899
+ /* @__PURE__ */ n("span", { style: { ...f.rowBottom, justifyContent: "space-between", alignItems: "center", gap: 6, color: v > 0 && !r ? "#4a5568" : d.muted }, children: [
900
+ /* @__PURE__ */ e("span", { style: { flex: 1, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }, children: $ || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" }) }),
901
+ C ? /* @__PURE__ */ n(
902
+ "span",
903
+ {
904
+ title: `Phụ trách: ${C.name}${C.title ? ` (${C.title})` : ""}`,
905
+ style: {
906
+ display: "inline-flex",
907
+ alignItems: "center",
908
+ gap: 4,
909
+ padding: "1px 6px 1px 2px",
910
+ borderRadius: 999,
911
+ fontSize: 10,
912
+ fontWeight: 600,
913
+ flexShrink: 0,
914
+ background: D ? `${o}18` : "#f1f5f9",
915
+ color: D ? o : "#475569",
916
+ border: D ? `1px solid ${o}33` : "1px solid #e2e8f0"
917
+ },
918
+ children: [
919
+ /* @__PURE__ */ e(
920
+ "span",
921
+ {
922
+ style: {
923
+ width: 14,
924
+ height: 14,
925
+ borderRadius: "50%",
926
+ background: D ? o : "#64748b",
927
+ color: "#fff",
928
+ fontSize: 8,
929
+ fontWeight: 700,
930
+ display: "inline-grid",
931
+ placeItems: "center",
932
+ overflow: "hidden",
933
+ flexShrink: 0
934
+ },
935
+ children: C.avatarUrl ? /* @__PURE__ */ e("img", { src: C.avatarUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : Le(C.name)
936
+ }
937
+ ),
938
+ /* @__PURE__ */ e("span", { style: { maxWidth: 68, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: rt(C.name) })
939
+ ]
940
+ }
941
+ ) : v > 0 ? /* @__PURE__ */ e(
942
+ "span",
943
+ {
944
+ style: {
945
+ display: "inline-flex",
946
+ alignItems: "center",
947
+ padding: "1px 6px",
948
+ borderRadius: 999,
949
+ fontSize: 9.5,
950
+ fontWeight: 600,
951
+ flexShrink: 0,
952
+ background: "#fef3c7",
953
+ color: "#b45309"
954
+ },
955
+ children: "Chưa nhận"
956
+ }
957
+ ) : null
958
+ ] })
761
959
  ] })
762
960
  ]
763
961
  }
764
962
  );
765
963
  }
766
- function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s, error: C, onRegisterAppend: m, refreshKey: O, infoOpen: f, onToggleInfo: S, t: W, disableAttachments: I, hideKeyboardHint: H, extensions: R, onLinkContact: E, onRefreshContactInfo: j }) {
767
- var He;
768
- const [A, F] = y([]), [K, ne] = y(), [U, w] = y(""), [_, k] = y(!0), [L, se] = y(!1), [z, D] = y(""), le = ee(null), v = t.contactName ?? t.subject ?? t.providerConversationKey, Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!1), [B, P] = y(!1), [q, ie] = y(!1), [re, V] = y(0), ye = ee(null), ke = ee(null), be = ee(null), [fe, G] = y(!1), [de, me] = y(""), [we, Oe] = y([]), Se = ee(null), Ce = ee(null);
769
- Y(() => () => {
770
- x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl);
771
- }, [x == null ? void 0 : x.objectUrl]), Y(() => {
772
- if (!q) return;
773
- function l(g) {
774
- var b, M;
775
- (b = ke.current) != null && b.contains(g.target) || (M = ye.current) != null && M.contains(g.target) || ie(!1);
964
+ function rn({ conversation: t, provider: i, connection: r, client: o, primary: h, error: S, onRegisterAppend: m, refreshKey: M, infoOpen: w, onToggleInfo: v, t: W, disableAttachments: T, hideKeyboardHint: j, extensions: $, currentAgent: C, teamAgents: D, onAssignAgent: I, onLinkContact: L, onRefreshContactInfo: P }) {
965
+ var Re, Te;
966
+ const [q, te] = y([]), [Q, B] = y(), [x, b] = y(""), [E, V] = y(!0), [ne, de] = y(!1), [z, oe] = y(""), Z = J(null), O = t.contactName ?? t.subject ?? t.providerConversationKey, ee = J(null), se = J(null), [c, H] = y(null), [N, ae] = y(!1), [ce, ye] = y(!1), [F, he] = y(!1), [Se, Me] = y(0), He = J(null), Ae = J(null), Ce = J(null), [ve, Ie] = y(!1), [Ne, me] = y(""), [_, ue] = y([]), ze = J(null), Fe = J(null), [je, G] = y(!1), Ke = J(null), qe = J(null);
967
+ X(() => {
968
+ if (!je) return;
969
+ function a(g) {
970
+ var k, A;
971
+ (k = Ke.current) != null && k.contains(g.target) || (A = qe.current) != null && A.contains(g.target) || G(!1);
776
972
  }
777
- return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
778
- }, [q]), Y(() => {
779
- o.listCannedResponses().then(Oe).catch(() => {
973
+ return document.addEventListener("mousedown", a), () => document.removeEventListener("mousedown", a);
974
+ }, [je]), X(() => () => {
975
+ c != null && c.objectUrl && URL.revokeObjectURL(c.objectUrl);
976
+ }, [c == null ? void 0 : c.objectUrl]), X(() => {
977
+ if (!F) return;
978
+ function a(g) {
979
+ var k, A;
980
+ (k = Ae.current) != null && k.contains(g.target) || (A = He.current) != null && A.contains(g.target) || he(!1);
981
+ }
982
+ return document.addEventListener("mousedown", a), () => document.removeEventListener("mousedown", a);
983
+ }, [F]), X(() => {
984
+ o.listCannedResponses().then(ue).catch(() => {
780
985
  });
781
- }, [o]), Y(() => {
782
- if (!fe) return;
783
- function l(g) {
784
- var b, M;
785
- (b = Ce.current) != null && b.contains(g.target) || (M = Se.current) != null && M.contains(g.target) || G(!1);
986
+ }, [o]), X(() => {
987
+ if (!ve) return;
988
+ function a(g) {
989
+ var k, A;
990
+ (k = Fe.current) != null && k.contains(g.target) || (A = ze.current) != null && A.contains(g.target) || Ie(!1);
786
991
  }
787
- return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
788
- }, [fe]);
789
- const Ie = ee(!0), ue = We(async (l, g) => {
790
- g || (Ie.current = !l);
992
+ return document.addEventListener("mousedown", a), () => document.removeEventListener("mousedown", a);
993
+ }, [ve]);
994
+ const ke = J(!0), fe = we(async (a, g) => {
995
+ g || (ke.current = !a);
791
996
  try {
792
- const b = await o.listMessages(t.id, l);
793
- F((M) => l ? [...b.items, ...M] : b.items), ne(b.nextCursor);
794
- } catch (b) {
795
- D(b instanceof Error ? b.message : "Không tải được tin nhắn");
997
+ const k = await o.listMessages(t.id, a);
998
+ te((A) => a ? [...k.items, ...A] : k.items), B(k.nextCursor);
999
+ } catch (k) {
1000
+ oe(k instanceof Error ? k.message : "Không tải được tin nhắn");
796
1001
  } finally {
797
- g || k(!1);
1002
+ g || V(!1);
798
1003
  }
799
1004
  }, [o, t.id]);
800
- Y(() => {
801
- k(!0), ue();
802
- }, [ue]), Y(() => {
803
- O && ue(void 0, !0);
804
- }, [O]), Y(() => {
805
- Ie.current && requestAnimationFrame(() => {
806
- const l = le.current;
807
- l && (l.scrollTop = l.scrollHeight);
1005
+ X(() => {
1006
+ V(!0), fe();
1007
+ }, [fe]), X(() => {
1008
+ M && fe(void 0, !0);
1009
+ }, [M]), X(() => {
1010
+ ke.current && requestAnimationFrame(() => {
1011
+ const a = Z.current;
1012
+ a && (a.scrollTop = a.scrollHeight);
808
1013
  });
809
- }, [A]), Y(() => (m == null || m((l) => {
810
- Ie.current = !0, F((g) => g.some((b) => b.id === l.id) ? g : [...g, l]);
1014
+ }, [q]), X(() => (m == null || m((a) => {
1015
+ ke.current = !0, te((g) => g.some((k) => k.id === a.id) ? g : [...g, a]);
811
1016
  }), () => {
812
1017
  m == null || m(null);
813
1018
  }), [m]);
814
- async function Me(l) {
815
- var M;
816
- const g = (M = l.target.files) == null ? void 0 : M[0];
1019
+ async function Ve(a) {
1020
+ var A;
1021
+ const g = (A = a.target.files) == null ? void 0 : A[0];
817
1022
  if (!g) return;
818
- l.target.value = "";
819
- const b = URL.createObjectURL(g);
820
- J({ file: g, uploading: !0, objectUrl: b });
1023
+ a.target.value = "";
1024
+ const k = URL.createObjectURL(g);
1025
+ H({ file: g, uploading: !0, objectUrl: k });
821
1026
  try {
822
- const Z = await o.uploadAttachment(g);
823
- J({ file: g, uploading: !1, url: Z.url, mimeType: Z.mimeType, attachmentType: Z.attachmentType, objectUrl: b });
1027
+ const K = await o.uploadAttachment(g);
1028
+ H({ file: g, uploading: !1, url: K.url, mimeType: K.mimeType, attachmentType: K.attachmentType, objectUrl: k });
824
1029
  } catch {
825
- URL.revokeObjectURL(b), J(null), D("Không tải lên được tệp đính kèm");
1030
+ URL.revokeObjectURL(k), H(null), oe("Không tải lên được tệp đính kèm");
826
1031
  }
827
1032
  }
828
- async function oe(l) {
829
- l.preventDefault();
830
- const g = U.trim(), b = x != null && x.url ? [{ url: x.url, mimeType: x.mimeType ?? "application/octet-stream", type: x.attachmentType }] : [];
831
- if (!(!g && !b.length || L)) {
832
- se(!0), D("");
833
- try {
834
- await o.sendMessage(t.id, g || void 0, b.length ? b : void 0), x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), w(""), J(null), await ue();
835
- } catch (M) {
836
- D(M instanceof Error ? M.message : "Không gửi được tin nhắn");
837
- } finally {
838
- se(!1);
1033
+ async function Ge(a) {
1034
+ a.preventDefault();
1035
+ const g = x.trim(), k = c != null && c.url ? [{ url: c.url, mimeType: c.mimeType ?? "application/octet-stream", type: c.attachmentType }] : [];
1036
+ if (!g && !k.length || ne) return;
1037
+ de(!0), oe(""), !t.assignedAgent && C && I(C);
1038
+ const A = `optimistic-${Date.now()}`;
1039
+ C && (ke.current = !0, te((K) => [
1040
+ ...K,
1041
+ {
1042
+ id: A,
1043
+ direction: "outbound",
1044
+ status: "sending",
1045
+ text: g || void 0,
1046
+ attachments: k.length ? k : void 0,
1047
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
1048
+ senderAgent: C
839
1049
  }
1050
+ ]));
1051
+ try {
1052
+ await o.sendMessage(t.id, g || void 0, k.length ? k : void 0), c != null && c.objectUrl && URL.revokeObjectURL(c.objectUrl), b(""), H(null), await fe(), C && te((K) => {
1053
+ var l, p;
1054
+ const U = K.filter((u) => u.id !== A), re = U.length - 1;
1055
+ return re >= 0 && ((l = U[re]) == null ? void 0 : l.direction) === "outbound" && !((p = U[re]) != null && p.senderAgent) ? U.map((u, R) => R === re ? { ...u, senderAgent: C } : u) : U;
1056
+ });
1057
+ } catch (K) {
1058
+ te((U) => U.filter((re) => re.id !== A)), oe(K instanceof Error ? K.message : "Không gửi được tin nhắn");
1059
+ } finally {
1060
+ de(!1);
840
1061
  }
841
1062
  }
842
- function ze(l) {
843
- const g = be.current;
1063
+ function Ze(a) {
1064
+ const g = Ce.current;
844
1065
  if (!g) {
845
- w((c) => c + l), ie(!1);
1066
+ b((U) => U + a), he(!1);
846
1067
  return;
847
1068
  }
848
- const b = g.selectionStart ?? U.length, M = g.selectionEnd ?? U.length, Z = U.slice(0, b) + l + U.slice(M);
849
- w(Z), ie(!1), requestAnimationFrame(() => {
850
- g.focus(), g.selectionStart = g.selectionEnd = b + l.length;
1069
+ const k = g.selectionStart ?? x.length, A = g.selectionEnd ?? x.length, K = x.slice(0, k) + a + x.slice(A);
1070
+ b(K), he(!1), requestAnimationFrame(() => {
1071
+ g.focus(), g.selectionStart = g.selectionEnd = k + a.length;
851
1072
  });
852
1073
  }
853
- function Te(l) {
854
- w(l), G(!1), me(""), requestAnimationFrame(() => {
855
- const g = be.current;
856
- g && (g.focus(), g.selectionStart = g.selectionEnd = l.length);
1074
+ function pe(a) {
1075
+ b(a), Ie(!1), me(""), requestAnimationFrame(() => {
1076
+ const g = Ce.current;
1077
+ g && (g.focus(), g.selectionStart = g.selectionEnd = a.length);
857
1078
  });
858
1079
  }
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) })
1080
+ const be = !ne && (x.trim().length > 0 || (c == null ? void 0 : c.url) != null && !c.uploading);
1081
+ return /* @__PURE__ */ n("section", { style: f.chat, children: [
1082
+ /* @__PURE__ */ n("header", { style: f.chatHeader, children: [
1083
+ /* @__PURE__ */ e($t, { name: O, color: h, image: t.contactPictureUrl, provider: i }),
1084
+ /* @__PURE__ */ n("div", { style: f.contact, children: [
1085
+ /* @__PURE__ */ e("strong", { style: f.contactName, children: O }),
1086
+ /* @__PURE__ */ e("span", { style: f.contactMeta, children: en(r) ?? Wt(i) })
866
1087
  ] }),
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 }) }),
1088
+ /* @__PURE__ */ n("div", { style: { ...f.headerActions, alignItems: "center", gap: 6 }, children: [
1089
+ /* @__PURE__ */ n("div", { ref: Ke, style: { position: "relative", display: "inline-flex", alignItems: "center", gap: 4 }, children: [
1090
+ !t.assignedAgent && C ? /* @__PURE__ */ n("div", { style: { display: "inline-flex", alignItems: "center", borderRadius: 999, border: `1px solid ${h}40`, background: `${h}0d`, overflow: "hidden" }, children: [
1091
+ /* @__PURE__ */ n(
1092
+ "button",
1093
+ {
1094
+ type: "button",
1095
+ onClick: () => void I(C),
1096
+ style: {
1097
+ border: 0,
1098
+ background: "transparent",
1099
+ color: h,
1100
+ padding: "4px 9px",
1101
+ fontSize: 11.5,
1102
+ fontWeight: 600,
1103
+ cursor: "pointer",
1104
+ display: "inline-flex",
1105
+ alignItems: "center",
1106
+ gap: 4,
1107
+ whiteSpace: "nowrap"
1108
+ },
1109
+ children: [
1110
+ /* @__PURE__ */ e(ft, { size: 12, strokeWidth: 2.2 }),
1111
+ /* @__PURE__ */ e("span", { children: "+ Nhận phụ trách" })
1112
+ ]
1113
+ }
1114
+ ),
1115
+ ((D == null ? void 0 : D.length) ?? 0) > 1 && /* @__PURE__ */ e(
1116
+ "button",
1117
+ {
1118
+ type: "button",
1119
+ "aria-label": "Chọn nhân viên phụ trách",
1120
+ onClick: () => G((a) => !a),
1121
+ style: {
1122
+ border: 0,
1123
+ borderLeft: `1px solid ${h}30`,
1124
+ background: "transparent",
1125
+ color: h,
1126
+ padding: "4px 6px",
1127
+ cursor: "pointer",
1128
+ display: "inline-flex",
1129
+ alignItems: "center"
1130
+ },
1131
+ children: /* @__PURE__ */ e(nt, { size: 12, strokeWidth: 2.2 })
1132
+ }
1133
+ )
1134
+ ] }) : /* @__PURE__ */ n(
1135
+ "button",
1136
+ {
1137
+ type: "button",
1138
+ onClick: () => G((a) => !a),
1139
+ style: {
1140
+ display: "inline-flex",
1141
+ alignItems: "center",
1142
+ gap: 6,
1143
+ padding: "3px 9px 3px 4px",
1144
+ borderRadius: 999,
1145
+ border: `1px solid ${d.line}`,
1146
+ background: d.surface,
1147
+ color: d.ink,
1148
+ fontSize: 11.5,
1149
+ fontWeight: 600,
1150
+ cursor: "pointer",
1151
+ whiteSpace: "nowrap"
1152
+ },
1153
+ children: [
1154
+ t.assignedAgent ? /* @__PURE__ */ n(ie, { children: [
1155
+ /* @__PURE__ */ e(
1156
+ "span",
1157
+ {
1158
+ style: {
1159
+ width: 18,
1160
+ height: 18,
1161
+ borderRadius: "50%",
1162
+ background: h,
1163
+ color: "#fff",
1164
+ fontSize: 9,
1165
+ fontWeight: 700,
1166
+ display: "inline-grid",
1167
+ placeItems: "center",
1168
+ overflow: "hidden",
1169
+ flexShrink: 0
1170
+ },
1171
+ children: t.assignedAgent.avatarUrl ? /* @__PURE__ */ e("img", { src: t.assignedAgent.avatarUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : Le(t.assignedAgent.name)
1172
+ }
1173
+ ),
1174
+ /* @__PURE__ */ e("span", { style: { color: d.muted, fontWeight: 500 }, children: "Phụ trách:" }),
1175
+ /* @__PURE__ */ e("span", { style: { maxWidth: 110, overflow: "hidden", textOverflow: "ellipsis" }, children: rt(t.assignedAgent.name) })
1176
+ ] }) : /* @__PURE__ */ n(ie, { children: [
1177
+ /* @__PURE__ */ e(Vt, { size: 13, color: d.muted }),
1178
+ /* @__PURE__ */ e("span", { style: { color: d.muted }, children: "Chưa phân công" })
1179
+ ] }),
1180
+ /* @__PURE__ */ e(nt, { size: 12, color: d.muted })
1181
+ ]
1182
+ }
1183
+ ),
1184
+ je && /* @__PURE__ */ n(
1185
+ "div",
1186
+ {
1187
+ ref: qe,
1188
+ style: {
1189
+ position: "absolute",
1190
+ top: "calc(100% + 6px)",
1191
+ right: 0,
1192
+ zIndex: 200,
1193
+ minWidth: 230,
1194
+ background: d.white,
1195
+ border: `1px solid ${d.line}`,
1196
+ borderRadius: 11,
1197
+ boxShadow: "0 10px 28px rgba(23,32,51,.15)",
1198
+ padding: 6,
1199
+ fontSize: 12
1200
+ },
1201
+ children: [
1202
+ /* @__PURE__ */ e("div", { style: { padding: "4px 8px 6px", fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 0.8, textTransform: "uppercase" }, children: "Người phụ trách hội thoại" }),
1203
+ C && ((Re = t.assignedAgent) == null ? void 0 : Re.id) !== C.id && /* @__PURE__ */ n(
1204
+ "button",
1205
+ {
1206
+ type: "button",
1207
+ onClick: () => {
1208
+ G(!1), I(C);
1209
+ },
1210
+ style: {
1211
+ display: "flex",
1212
+ alignItems: "center",
1213
+ gap: 8,
1214
+ width: "100%",
1215
+ border: 0,
1216
+ borderRadius: 7,
1217
+ background: `${h}10`,
1218
+ color: h,
1219
+ padding: "6px 8px",
1220
+ marginBottom: 4,
1221
+ fontWeight: 600,
1222
+ fontSize: 12,
1223
+ cursor: "pointer",
1224
+ textAlign: "left"
1225
+ },
1226
+ children: [
1227
+ /* @__PURE__ */ e(ft, { size: 13 }),
1228
+ /* @__PURE__ */ n("span", { children: [
1229
+ "Nhận phụ trách cho tôi (",
1230
+ rt(C.name),
1231
+ ")"
1232
+ ] })
1233
+ ]
1234
+ }
1235
+ ),
1236
+ /* @__PURE__ */ e("div", { style: { maxHeight: 200, overflowY: "auto" }, children: (D ?? []).map((a) => {
1237
+ var k;
1238
+ const g = ((k = t.assignedAgent) == null ? void 0 : k.id) === a.id;
1239
+ return /* @__PURE__ */ n(
1240
+ "button",
1241
+ {
1242
+ type: "button",
1243
+ onClick: () => {
1244
+ G(!1), I(a);
1245
+ },
1246
+ style: {
1247
+ display: "flex",
1248
+ alignItems: "center",
1249
+ justifyContent: "space-between",
1250
+ gap: 8,
1251
+ width: "100%",
1252
+ border: 0,
1253
+ borderRadius: 7,
1254
+ background: g ? "#f1f5f9" : "transparent",
1255
+ color: d.ink,
1256
+ padding: "6px 8px",
1257
+ cursor: "pointer",
1258
+ textAlign: "left"
1259
+ },
1260
+ children: [
1261
+ /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }, children: [
1262
+ /* @__PURE__ */ e(
1263
+ "span",
1264
+ {
1265
+ style: {
1266
+ width: 22,
1267
+ height: 22,
1268
+ borderRadius: "50%",
1269
+ background: `${h}18`,
1270
+ color: h,
1271
+ fontSize: 10,
1272
+ fontWeight: 700,
1273
+ display: "inline-grid",
1274
+ placeItems: "center",
1275
+ overflow: "hidden",
1276
+ flexShrink: 0
1277
+ },
1278
+ children: a.avatarUrl ? /* @__PURE__ */ e("img", { src: a.avatarUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : Le(a.name)
1279
+ }
1280
+ ),
1281
+ /* @__PURE__ */ n("span", { style: { minWidth: 0 }, children: [
1282
+ /* @__PURE__ */ e("span", { style: { display: "block", fontWeight: 600, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }, children: a.name }),
1283
+ a.title && /* @__PURE__ */ e("span", { style: { display: "block", fontSize: 10.5, color: d.muted }, children: a.title })
1284
+ ] })
1285
+ ] }),
1286
+ g && /* @__PURE__ */ e(lt, { size: 13, color: h, strokeWidth: 2.5 })
1287
+ ]
1288
+ },
1289
+ a.id
1290
+ );
1291
+ }) }),
1292
+ t.assignedAgent && /* @__PURE__ */ n(ie, { children: [
1293
+ /* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${d.line}`, margin: "5px 0" } }),
1294
+ /* @__PURE__ */ n(
1295
+ "button",
1296
+ {
1297
+ type: "button",
1298
+ onClick: () => {
1299
+ G(!1), I(null);
1300
+ },
1301
+ style: {
1302
+ display: "flex",
1303
+ alignItems: "center",
1304
+ gap: 6,
1305
+ width: "100%",
1306
+ border: 0,
1307
+ borderRadius: 7,
1308
+ background: "transparent",
1309
+ color: "#b42318",
1310
+ padding: "6px 8px",
1311
+ fontSize: 11.5,
1312
+ fontWeight: 500,
1313
+ cursor: "pointer",
1314
+ textAlign: "left"
1315
+ },
1316
+ children: [
1317
+ /* @__PURE__ */ e(Ue, { size: 13 }),
1318
+ /* @__PURE__ */ e("span", { children: "Bỏ phân công (Chưa có người nhận)" })
1319
+ ]
1320
+ }
1321
+ )
1322
+ ] })
1323
+ ]
1324
+ }
1325
+ )
1326
+ ] }),
1327
+ /* @__PURE__ */ e("button", { style: f.iconButton, "aria-label": "Thêm tùy chọn", children: /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }) }),
869
1328
  /* @__PURE__ */ e(
870
1329
  "button",
871
1330
  {
872
1331
  style: {
873
- ...p.iconButton,
874
- background: f ? `${s}14` : "transparent",
875
- color: f ? s : d.muted
1332
+ ...f.iconButton,
1333
+ background: w ? `${h}14` : "transparent",
1334
+ color: w ? h : d.muted
876
1335
  },
877
1336
  "aria-label": "Thông tin liên hệ",
878
- onClick: S,
879
- children: /* @__PURE__ */ e(zt, { size: 16, strokeWidth: 2 })
1337
+ onClick: v,
1338
+ children: /* @__PURE__ */ e(Dt, { size: 16, strokeWidth: 2 })
880
1339
  }
881
1340
  )
882
1341
  ] })
883
1342
  ] }),
884
- /* @__PURE__ */ n(ct, { ref: le, style: p.messageArea, children: [
885
- /* @__PURE__ */ e("div", { style: p.day, children: W.today }),
886
- K && /* @__PURE__ */ e("button", { onClick: () => void ue(K), style: p.historyButton, children: W.loadOlder }),
887
- _ && /* @__PURE__ */ n("div", { style: p.messageHint, children: [
888
- /* @__PURE__ */ e(Fe, {}),
1343
+ /* @__PURE__ */ n(Rt, { ref: Z, style: f.messageArea, children: [
1344
+ /* @__PURE__ */ e("div", { style: f.day, children: W.today }),
1345
+ Q && /* @__PURE__ */ e("button", { onClick: () => void fe(Q), style: f.historyButton, children: W.loadOlder }),
1346
+ E && /* @__PURE__ */ n("div", { style: f.messageHint, children: [
1347
+ /* @__PURE__ */ e(ot, {}),
889
1348
  " ",
890
1349
  W.loading
891
1350
  ] }),
892
- !_ && !A.length && /* @__PURE__ */ e("div", { style: p.messageHint, children: W.noMessages }),
893
- A.map((l, g) => {
894
- const b = (R == null ? void 0 : R.flatMap((u) => u.messageEnrichments ?? [])) ?? [], M = l.direction === "inbound" && b.length > 0 && g >= A.length - 15, Z = M ? Ae(t, {
1351
+ !E && !q.length && /* @__PURE__ */ e("div", { style: f.messageHint, children: W.noMessages }),
1352
+ q.map((a, g) => {
1353
+ const k = ($ == null ? void 0 : $.flatMap((re) => re.messageEnrichments ?? [])) ?? [], A = a.direction === "inbound" && k.length > 0 && g >= q.length - 15, K = A ? Je(t, {
895
1354
  provider: i,
896
- recentMessages: A.slice(-10),
897
- linkContact: E,
898
- refreshContactInfo: j,
899
- sendMessage: async (u, T) => {
900
- await o.sendMessage(t.id, u, T), await ue(void 0, !0);
1355
+ recentMessages: q.slice(-10),
1356
+ linkContact: L,
1357
+ refreshContactInfo: P,
1358
+ sendMessage: async (re, l) => {
1359
+ await o.sendMessage(t.id, re, l), await fe(void 0, !0);
901
1360
  }
902
- }) : null, c = M && Z ? b.map((u, T) => {
903
- var ce;
904
- const $ = (ce = l.text) == null ? void 0 : ce.match(u.pattern);
905
- return $ ? /* @__PURE__ */ e(Ot, { children: u.render($, Z, l) }, `${l.id}-${T}`) : null;
1361
+ }) : null, U = A && K ? k.map((re, l) => {
1362
+ var u;
1363
+ const p = (u = a.text) == null ? void 0 : u.match(re.pattern);
1364
+ return p ? /* @__PURE__ */ e(_t, { children: re.render(p, K, a) }, `${a.id}-${l}`) : null;
906
1365
  }).filter(Boolean) : [];
907
1366
  return /* @__PURE__ */ n("div", { children: [
908
- /* @__PURE__ */ e(Kt, { message: l, primary: s }),
909
- c.length > 0 && /* @__PURE__ */ e("div", { style: { maxWidth: "min(70%, 480px)", marginTop: -4, marginBottom: 10, display: "flex", flexDirection: "column", gap: 6 }, children: c })
910
- ] }, l.id);
1367
+ /* @__PURE__ */ e(on, { message: a, primary: h }),
1368
+ U.length > 0 && /* @__PURE__ */ e("div", { style: { maxWidth: "min(70%, 480px)", marginTop: -4, marginBottom: 10, display: "flex", flexDirection: "column", gap: 6 }, children: U })
1369
+ ] }, a.id);
911
1370
  })
912
1371
  ] }),
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((l) => /* @__PURE__ */ e(
1372
+ /* @__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((a) => /* @__PURE__ */ e(
914
1373
  "button",
915
1374
  {
916
1375
  type: "button",
917
- onClick: () => w(l),
1376
+ onClick: () => b(a),
918
1377
  style: {
919
1378
  fontSize: 11,
920
1379
  padding: "3px 10px",
921
1380
  borderRadius: 999,
922
- background: `${s}0f`,
923
- color: s,
924
- border: `1px solid ${s}33`,
1381
+ background: `${h}0f`,
1382
+ color: h,
1383
+ border: `1px solid ${h}33`,
925
1384
  cursor: "pointer",
926
1385
  whiteSpace: "nowrap"
927
1386
  },
928
- children: l
1387
+ children: a
929
1388
  },
930
- l
1389
+ a
931
1390
  )) }),
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(
1391
+ /* @__PURE__ */ n("form", { onSubmit: Ge, style: { flex: "0 0 auto", padding: "8px 14px 12px", borderTop: `1px solid ${d.line}`, background: d.white, position: "relative" }, children: [
1392
+ F && /* @__PURE__ */ n(
934
1393
  "div",
935
1394
  {
936
- ref: ye,
1395
+ ref: He,
937
1396
  style: {
938
1397
  position: "absolute",
939
1398
  bottom: "calc(100% + 6px)",
@@ -948,11 +1407,11 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
948
1407
  fontFamily: "inherit"
949
1408
  },
950
1409
  children: [
951
- /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Je.map((l, g) => /* @__PURE__ */ e(
1410
+ /* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: gt.map((a, g) => /* @__PURE__ */ e(
952
1411
  "button",
953
1412
  {
954
1413
  type: "button",
955
- onClick: () => V(g),
1414
+ onClick: () => Me(g),
956
1415
  style: {
957
1416
  flex: 1,
958
1417
  border: 0,
@@ -961,19 +1420,19 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
961
1420
  fontSize: 16,
962
1421
  cursor: "pointer",
963
1422
  lineHeight: 1,
964
- borderBottom: re === g ? `2px solid ${s}` : "2px solid transparent",
965
- opacity: re === g ? 1 : 0.5,
1423
+ borderBottom: Se === g ? `2px solid ${h}` : "2px solid transparent",
1424
+ opacity: Se === g ? 1 : 0.5,
966
1425
  transition: "opacity 100ms ease"
967
1426
  },
968
- children: l.icon
1427
+ children: a.icon
969
1428
  },
970
1429
  g
971
1430
  )) }),
972
- /* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (He = Je[re]) == null ? void 0 : He.emojis.map((l, g) => /* @__PURE__ */ e(
1431
+ /* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (Te = gt[Se]) == null ? void 0 : Te.emojis.map((a, g) => /* @__PURE__ */ e(
973
1432
  "button",
974
1433
  {
975
1434
  type: "button",
976
- onClick: () => ze(l),
1435
+ onClick: () => Ze(a),
977
1436
  style: {
978
1437
  border: 0,
979
1438
  background: "transparent",
@@ -984,23 +1443,23 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
984
1443
  lineHeight: 1,
985
1444
  transition: "background 80ms ease"
986
1445
  },
987
- onMouseEnter: (b) => {
988
- b.target.style.background = "#f3f4f6";
1446
+ onMouseEnter: (k) => {
1447
+ k.target.style.background = "#f3f4f6";
989
1448
  },
990
- onMouseLeave: (b) => {
991
- b.target.style.background = "transparent";
1449
+ onMouseLeave: (k) => {
1450
+ k.target.style.background = "transparent";
992
1451
  },
993
- children: l
1452
+ children: a
994
1453
  },
995
1454
  g
996
1455
  )) })
997
1456
  ]
998
1457
  }
999
1458
  ),
1000
- fe && /* @__PURE__ */ n(
1459
+ ve && /* @__PURE__ */ n(
1001
1460
  "div",
1002
1461
  {
1003
- ref: Se,
1462
+ ref: ze,
1004
1463
  style: {
1005
1464
  position: "absolute",
1006
1465
  bottom: "calc(100% + 6px)",
@@ -1021,90 +1480,90 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1021
1480
  autoFocus: !0,
1022
1481
  type: "text",
1023
1482
  placeholder: "Tìm template…",
1024
- value: de,
1025
- onChange: (l) => me(l.target.value),
1483
+ value: Ne,
1484
+ onChange: (a) => me(a.target.value),
1026
1485
  style: { width: "100%", boxSizing: "border-box", border: `1px solid ${d.line}`, borderRadius: 7, padding: "5px 8px", fontSize: 12, outline: "none", fontFamily: "inherit", color: d.ink }
1027
1486
  }
1028
1487
  ) }),
1029
1488
  /* @__PURE__ */ e("div", { style: { maxHeight: 220, overflowY: "auto" }, children: (() => {
1030
- const l = de.trim().toLowerCase(), g = l ? we.filter((b) => b.title.toLowerCase().includes(l) || b.content.toLowerCase().includes(l) || (b.shortcut ?? "").toLowerCase().includes(l)) : we;
1031
- return g.length ? g.map((b) => /* @__PURE__ */ n(
1489
+ const a = Ne.trim().toLowerCase(), g = a ? _.filter((k) => k.title.toLowerCase().includes(a) || k.content.toLowerCase().includes(a) || (k.shortcut ?? "").toLowerCase().includes(a)) : _;
1490
+ return g.length ? g.map((k) => /* @__PURE__ */ n(
1032
1491
  "button",
1033
1492
  {
1034
1493
  type: "button",
1035
- onClick: () => Te(b.content),
1494
+ onClick: () => pe(k.content),
1036
1495
  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";
1496
+ onMouseEnter: (A) => {
1497
+ A.currentTarget.style.background = "#f7f9fc";
1039
1498
  },
1040
- onMouseLeave: (M) => {
1041
- M.currentTarget.style.background = "transparent";
1499
+ onMouseLeave: (A) => {
1500
+ A.currentTarget.style.background = "transparent";
1042
1501
  },
1043
1502
  children: [
1044
1503
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 2 }, children: [
1045
- /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: d.ink }, children: b.title }),
1046
- b.shortcut && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: s, background: `${s}18`, borderRadius: 4, padding: "1px 5px" }, children: b.shortcut })
1504
+ /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 600, color: d.ink }, children: k.title }),
1505
+ k.shortcut && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: h, background: `${h}18`, borderRadius: 4, padding: "1px 5px" }, children: k.shortcut })
1047
1506
  ] }),
1048
- /* @__PURE__ */ e("div", { style: { fontSize: 11, color: d.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: b.content })
1507
+ /* @__PURE__ */ e("div", { style: { fontSize: 11, color: d.muted, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: k.content })
1049
1508
  ]
1050
1509
  },
1051
- b.id
1052
- )) : /* @__PURE__ */ e("div", { style: { padding: "24px 16px", textAlign: "center", color: d.muted, fontSize: 12 }, children: we.length === 0 ? "Chưa có template nào" : "Không tìm thấy" });
1510
+ k.id
1511
+ )) : /* @__PURE__ */ e("div", { style: { padding: "24px 16px", textAlign: "center", color: d.muted, fontSize: 12 }, children: _.length === 0 ? "Chưa có template nào" : "Không tìm thấy" });
1053
1512
  })() })
1054
1513
  ]
1055
1514
  }
1056
1515
  ),
1057
1516
  /* @__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, {}),
1517
+ c && /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "8px 12px", borderBottom: `1px solid ${d.line}`, fontSize: 12 }, children: [
1518
+ c.uploading ? /* @__PURE__ */ n(ie, { children: [
1519
+ /* @__PURE__ */ e(ot, {}),
1061
1520
  /* @__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: [
1521
+ ] }) : c.attachmentType === "image" && c.objectUrl ? /* @__PURE__ */ e("img", { src: c.objectUrl, alt: "", style: { height: 48, width: 48, objectFit: "cover", borderRadius: 6 } }) : /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
1063
1522
  "📎 ",
1064
- x.file.name,
1523
+ c.file.name,
1065
1524
  " (",
1066
- Math.round(x.file.size / 1024),
1525
+ Math.round(c.file.size / 1024),
1067
1526
  " KB)"
1068
1527
  ] }),
1069
- !x.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1070
- x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), J(null);
1528
+ !c.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
1529
+ c != null && c.objectUrl && URL.revokeObjectURL(c.objectUrl), H(null);
1071
1530
  }, style: { marginLeft: "auto", border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 16 }, "aria-label": "Xóa tệp đính kèm", children: "✕" })
1072
1531
  ] }),
1073
1532
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 2, padding: "4px 8px", borderBottom: "1px solid #f3f4f6" }, children: [
1074
1533
  /* @__PURE__ */ e(
1075
1534
  "button",
1076
1535
  {
1077
- ref: ke,
1536
+ ref: Ae,
1078
1537
  type: "button",
1079
1538
  title: "Chèn emoji",
1080
- onClick: () => ie((l) => !l),
1081
- style: { ...p.toolbarBtn, background: q ? `${s}18` : "transparent", color: q ? s : "#9ca3af" },
1082
- children: /* @__PURE__ */ e($t, { size: 13, strokeWidth: 2 })
1539
+ onClick: () => he((a) => !a),
1540
+ style: { ...f.toolbarBtn, background: F ? `${h}18` : "transparent", color: F ? h : "#9ca3af" },
1541
+ children: /* @__PURE__ */ e(qt, { size: 13, strokeWidth: 2 })
1083
1542
  }
1084
1543
  ),
1085
- !I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: p.toolbarBtn, onClick: () => {
1086
- var l;
1087
- return (l = Q.current) == null ? void 0 : l.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: () => {
1090
- var l;
1091
- return (l = N.current) == null ? void 0 : l.click();
1092
- }, children: /* @__PURE__ */ e(Tt, { size: 13, strokeWidth: 2 }) }),
1093
- !I && /* @__PURE__ */ n(te, { children: [
1094
- /* @__PURE__ */ e("input", { ref: Q, type: "file", style: { display: "none" }, onChange: Me, accept: "image/*,video/mp4" }),
1095
- /* @__PURE__ */ e("input", { ref: N, type: "file", style: { display: "none" }, onChange: Me, accept: ".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" })
1544
+ !T && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: f.toolbarBtn, onClick: () => {
1545
+ var a;
1546
+ return (a = ee.current) == null ? void 0 : a.click();
1547
+ }, children: /* @__PURE__ */ e(Ot, { size: 13, strokeWidth: 2 }) }),
1548
+ !T && /* @__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: () => {
1549
+ var a;
1550
+ return (a = se.current) == null ? void 0 : a.click();
1551
+ }, children: /* @__PURE__ */ e(Pt, { size: 13, strokeWidth: 2 }) }),
1552
+ !T && /* @__PURE__ */ n(ie, { children: [
1553
+ /* @__PURE__ */ e("input", { ref: ee, type: "file", style: { display: "none" }, onChange: Ve, accept: "image/*,video/mp4" }),
1554
+ /* @__PURE__ */ e("input", { ref: se, type: "file", style: { display: "none" }, onChange: Ve, accept: ".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" })
1096
1555
  ] }),
1097
1556
  /* @__PURE__ */ e(
1098
1557
  "button",
1099
1558
  {
1100
- ref: Ce,
1559
+ ref: Fe,
1101
1560
  type: "button",
1102
1561
  title: "Template nhanh",
1103
1562
  onClick: () => {
1104
- G((l) => !l), me("");
1563
+ Ie((a) => !a), me("");
1105
1564
  },
1106
- style: { ...p.toolbarBtn, background: fe ? `${s}18` : "transparent", color: fe ? s : "#9ca3af" },
1107
- children: /* @__PURE__ */ e(Lt, { size: 13, strokeWidth: 2 })
1565
+ style: { ...f.toolbarBtn, background: ve ? `${h}18` : "transparent", color: ve ? h : "#9ca3af" },
1566
+ children: /* @__PURE__ */ e(Gt, { size: 13, strokeWidth: 2 })
1108
1567
  }
1109
1568
  ),
1110
1569
  /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 2px" } }),
@@ -1113,8 +1572,8 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1113
1572
  {
1114
1573
  type: "button",
1115
1574
  title: "In đậm",
1116
- onClick: () => h((l) => !l),
1117
- style: { ...p.toolbarBtn, fontWeight: 700, fontSize: 12, background: he ? `${s}18` : "transparent", color: he ? s : "#9ca3af", border: he ? `1px solid ${s}33` : "1px solid transparent" },
1575
+ onClick: () => ae((a) => !a),
1576
+ style: { ...f.toolbarBtn, fontWeight: 700, fontSize: 12, background: N ? `${h}18` : "transparent", color: N ? h : "#9ca3af", border: N ? `1px solid ${h}33` : "1px solid transparent" },
1118
1577
  children: "B"
1119
1578
  }
1120
1579
  ),
@@ -1123,71 +1582,71 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1123
1582
  {
1124
1583
  type: "button",
1125
1584
  title: "Nghiêng",
1126
- onClick: () => P((l) => !l),
1127
- style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background: B ? `${s}18` : "transparent", color: B ? s : "#9ca3af", border: B ? `1px solid ${s}33` : "1px solid transparent" },
1585
+ onClick: () => ye((a) => !a),
1586
+ style: { ...f.toolbarBtn, fontStyle: "italic", fontSize: 12, background: ce ? `${h}18` : "transparent", color: ce ? h : "#9ca3af", border: ce ? `1px solid ${h}33` : "1px solid transparent" },
1128
1587
  children: "I"
1129
1588
  }
1130
1589
  ),
1131
- !!(R != null && R.some((l) => {
1590
+ !!($ != null && $.some((a) => {
1132
1591
  var g;
1133
- return (((g = l.toolbarActions) == null ? void 0 : g.length) ?? 0) > 0;
1592
+ return (((g = a.toolbarActions) == null ? void 0 : g.length) ?? 0) > 0;
1134
1593
  })) && /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 4px" } }),
1135
- R == null ? void 0 : R.flatMap((l) => l.toolbarActions ?? []).map((l, g) => /* @__PURE__ */ n(
1594
+ $ == null ? void 0 : $.flatMap((a) => a.toolbarActions ?? []).map((a, g) => /* @__PURE__ */ n(
1136
1595
  "button",
1137
1596
  {
1138
1597
  type: "button",
1139
- title: l.tooltip,
1140
- style: l.label ? {
1598
+ title: a.tooltip,
1599
+ style: a.label ? {
1141
1600
  display: "inline-flex",
1142
1601
  alignItems: "center",
1143
1602
  gap: 5,
1144
1603
  padding: "3px 9px",
1145
1604
  borderRadius: 999,
1146
- border: `1px solid ${s}33`,
1147
- background: `${s}0f`,
1148
- color: s,
1605
+ border: `1px solid ${h}33`,
1606
+ background: `${h}0f`,
1607
+ color: h,
1149
1608
  fontSize: 11.5,
1150
1609
  fontWeight: 600,
1151
1610
  cursor: "pointer",
1152
1611
  lineHeight: 1.2,
1153
1612
  whiteSpace: "nowrap"
1154
- } : p.toolbarBtn,
1613
+ } : f.toolbarBtn,
1155
1614
  onClick: () => {
1156
- const b = (Z) => {
1157
- w((c) => c && !c.endsWith(" ") && !c.endsWith(`
1158
- `) ? `${c} ${Z}` : `${c}${Z}`), requestAnimationFrame(() => {
1159
- var c;
1160
- return (c = be.current) == null ? void 0 : c.focus();
1615
+ const k = (K) => {
1616
+ b((U) => U && !U.endsWith(" ") && !U.endsWith(`
1617
+ `) ? `${U} ${K}` : `${U}${K}`), requestAnimationFrame(() => {
1618
+ var U;
1619
+ return (U = Ce.current) == null ? void 0 : U.focus();
1161
1620
  });
1162
- }, M = Ae(t, {
1621
+ }, A = Je(t, {
1163
1622
  provider: i,
1164
- recentMessages: A.slice(-10),
1165
- linkContact: E,
1166
- refreshContactInfo: j,
1167
- sendMessage: async (Z, c) => {
1168
- await o.sendMessage(t.id, Z, c), await ue(void 0, !0);
1623
+ recentMessages: q.slice(-10),
1624
+ linkContact: L,
1625
+ refreshContactInfo: P,
1626
+ sendMessage: async (K, U) => {
1627
+ await o.sendMessage(t.id, K, U), await fe(void 0, !0);
1169
1628
  }
1170
1629
  });
1171
- l.onClick({ ...M, insertText: b });
1630
+ a.onClick({ ...A, insertText: k });
1172
1631
  },
1173
1632
  children: [
1174
- l.icon,
1175
- l.label && /* @__PURE__ */ e("span", { children: l.label })
1633
+ a.icon,
1634
+ a.label && /* @__PURE__ */ e("span", { children: a.label })
1176
1635
  ]
1177
1636
  },
1178
1637
  g
1179
1638
  ))
1180
1639
  ] }),
1181
1640
  /* @__PURE__ */ e(
1182
- jt,
1641
+ Jt,
1183
1642
  {
1184
- ref: be,
1643
+ ref: Ce,
1185
1644
  "aria-label": "Soạn tin nhắn",
1186
1645
  rows: 2,
1187
- value: U,
1188
- onChange: (l) => w(l.target.value),
1189
- onKeyDown: (l) => {
1190
- l.key === "Enter" && !l.shiftKey && (l.preventDefault(), oe(l));
1646
+ value: x,
1647
+ onChange: (a) => b(a.target.value),
1648
+ onKeyDown: (a) => {
1649
+ a.key === "Enter" && !a.shiftKey && (a.preventDefault(), Ge(a));
1191
1650
  },
1192
1651
  placeholder: W.sendPlaceholder,
1193
1652
  style: {
@@ -1206,26 +1665,26 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1206
1665
  font: "inherit",
1207
1666
  fontSize: 13,
1208
1667
  lineHeight: 1.45,
1209
- fontStyle: B ? "italic" : "normal",
1210
- fontWeight: he ? 700 : 400
1668
+ fontStyle: ce ? "italic" : "normal",
1669
+ fontWeight: N ? 700 : 400
1211
1670
  }
1212
1671
  }
1213
1672
  ),
1214
1673
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 8px 6px 12px" }, children: [
1215
1674
  /* @__PURE__ */ n("span", { style: {
1216
1675
  fontSize: 11,
1217
- color: U.length > 1e3 ? "#ef4444" : U.length > 900 ? "#f59e0b" : "#9ca3af",
1218
- fontWeight: U.length > 1e3 ? 600 : 400
1676
+ color: x.length > 1e3 ? "#ef4444" : x.length > 900 ? "#f59e0b" : "#9ca3af",
1677
+ fontWeight: x.length > 1e3 ? 600 : 400
1219
1678
  }, children: [
1220
- U.length,
1679
+ x.length,
1221
1680
  "/1000"
1222
1681
  ] }),
1223
1682
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
1224
- !H && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1683
+ !j && /* @__PURE__ */ e("span", { style: { fontSize: 10, color: "#9ca3af" }, children: "↵ Gửi · ⇧↵ Xuống dòng" }),
1225
1684
  /* @__PURE__ */ n(
1226
1685
  "button",
1227
1686
  {
1228
- disabled: !ae,
1687
+ disabled: !be,
1229
1688
  "aria-label": "Gửi tin nhắn",
1230
1689
  style: {
1231
1690
  display: "flex",
@@ -1236,14 +1695,14 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1236
1695
  borderRadius: 999,
1237
1696
  fontSize: 12,
1238
1697
  fontWeight: 600,
1239
- background: ae ? `linear-gradient(135deg,${s},#0ea5e9)` : "#e5e7eb",
1240
- color: ae ? "#fff" : "#9ca3af",
1241
- cursor: ae ? "pointer" : "not-allowed",
1242
- boxShadow: ae ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1698
+ background: be ? `linear-gradient(135deg,${h},#0ea5e9)` : "#e5e7eb",
1699
+ color: be ? "#fff" : "#9ca3af",
1700
+ cursor: be ? "pointer" : "not-allowed",
1701
+ boxShadow: be ? "0 2px 8px rgba(37,99,235,0.25)" : "none",
1243
1702
  transition: "all 150ms ease"
1244
1703
  },
1245
1704
  children: [
1246
- L ? /* @__PURE__ */ e(lt, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(Bt, { size: 12, strokeWidth: 2 }),
1705
+ ne ? /* @__PURE__ */ e(zt, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(Ft, { size: 12, strokeWidth: 2 }),
1247
1706
  W.send
1248
1707
  ]
1249
1708
  }
@@ -1252,185 +1711,217 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
1252
1711
  ] })
1253
1712
  ] })
1254
1713
  ] }),
1255
- (z || C) && /* @__PURE__ */ e("div", { role: "alert", style: p.error, children: z || C })
1714
+ (z || S) && /* @__PURE__ */ e("div", { role: "alert", style: f.error, children: z || S })
1256
1715
  ] });
1257
1716
  }
1258
- function Kt({ message: t, primary: i }) {
1259
- var K, ne, U, w, _;
1260
- const r = Ne(qe), o = Ne(st), s = (k) => k.startsWith("/v1/media/proxy") ? `${r}${k}&tok=${encodeURIComponent(o)}` : k, C = t.direction === "outbound", m = ((K = t.attachments) == null ? void 0 : K.filter((k) => k.type === "image")) ?? [], O = ((ne = t.attachments) == null ? void 0 : ne.filter((k) => k.type === "sticker")) ?? [], f = ((U = t.attachments) == null ? void 0 : U.filter((k) => k.type === "video")) ?? [], S = ((w = t.attachments) == null ? void 0 : w.filter((k) => k.type === "audio")) ?? [], W = ((_ = t.attachments) == null ? void 0 : _.filter((k) => k.type === "file")) ?? [], [I, H] = y(null), R = C ? "flex-end" : "flex-start", E = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
1261
- Ke(t.occurredAt, !0),
1262
- C && /* @__PURE__ */ n(te, { children: [
1263
- " ",
1264
- /* @__PURE__ */ e(_e, { status: t.status })
1717
+ function on({ message: t, primary: i }) {
1718
+ var q, te, Q, B, x;
1719
+ const r = tt(st), o = tt(Tt), h = (b) => b.startsWith("/v1/media/proxy") ? `${r}${b}&tok=${encodeURIComponent(o)}` : b, S = t.direction === "outbound", m = ((q = t.attachments) == null ? void 0 : q.filter((b) => b.type === "image")) ?? [], M = ((te = t.attachments) == null ? void 0 : te.filter((b) => b.type === "sticker")) ?? [], w = ((Q = t.attachments) == null ? void 0 : Q.filter((b) => b.type === "video")) ?? [], v = ((B = t.attachments) == null ? void 0 : B.filter((b) => b.type === "audio")) ?? [], W = ((x = t.attachments) == null ? void 0 : x.filter((b) => b.type === "file")) ?? [], [T, j] = y(null), $ = S ? "flex-end" : "flex-start", C = S ? t.senderAgent ?? null : null, D = /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: S ? "flex-end" : "flex-start", gap: 5, marginTop: 4, fontSize: 10, opacity: 0.78, letterSpacing: 0.2, userSelect: "none" }, children: [
1720
+ C && /* @__PURE__ */ n(
1721
+ "span",
1722
+ {
1723
+ title: C.title ? `${C.name} (${C.title})` : C.name,
1724
+ style: { display: "inline-flex", alignItems: "center", gap: 3.5, fontWeight: 600 },
1725
+ children: [
1726
+ /* @__PURE__ */ e(
1727
+ "span",
1728
+ {
1729
+ style: {
1730
+ width: 14,
1731
+ height: 14,
1732
+ borderRadius: "50%",
1733
+ background: "rgba(255,255,255,0.22)",
1734
+ color: "#fff",
1735
+ fontSize: 8,
1736
+ fontWeight: 700,
1737
+ display: "inline-grid",
1738
+ placeItems: "center",
1739
+ overflow: "hidden",
1740
+ flexShrink: 0
1741
+ },
1742
+ children: C.avatarUrl ? /* @__PURE__ */ e("img", { src: C.avatarUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : Le(C.name)
1743
+ }
1744
+ ),
1745
+ /* @__PURE__ */ e("span", { children: C.name }),
1746
+ /* @__PURE__ */ e("span", { style: { opacity: 0.6 }, children: "•" })
1747
+ ]
1748
+ }
1749
+ ),
1750
+ /* @__PURE__ */ n("time", { children: [
1751
+ at(t.occurredAt, !0),
1752
+ S && /* @__PURE__ */ n(ie, { children: [
1753
+ " ",
1754
+ /* @__PURE__ */ e(bt, { status: t.status })
1755
+ ] })
1265
1756
  ] })
1266
- ] }), j = /* @__PURE__ */ e("div", { style: { position: "absolute", bottom: 6, right: 8 }, children: /* @__PURE__ */ n("time", { style: { fontSize: 10, color: "#fff", textShadow: "0 1px 3px rgba(0,0,0,.5)", letterSpacing: 0.2, userSelect: "none" }, children: [
1267
- Ke(t.occurredAt, !0),
1268
- C && /* @__PURE__ */ n(te, { children: [
1757
+ ] }), I = /* @__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: [
1758
+ at(t.occurredAt, !0),
1759
+ S && /* @__PURE__ */ n(ie, { children: [
1269
1760
  " ",
1270
- /* @__PURE__ */ e(_e, { status: t.status })
1761
+ /* @__PURE__ */ e(bt, { status: t.status })
1271
1762
  ] })
1272
- ] }) }), A = C ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, F = !t.text && S.length === 0 && W.length === 0;
1273
- return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent: R, flexDirection: "column", alignItems: R }, children: [
1274
- O.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1275
- /* @__PURE__ */ e("img", { src: s(k.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1276
- F && m.length === 0 && f.length === 0 && L === O.length - 1 && j
1277
- ] }, `s${L}`)),
1278
- m.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => H({ url: s(k.url), kind: "image" }), children: [
1279
- /* @__PURE__ */ e("img", { src: s(k.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1280
- F && L === m.length - 1 && f.length === 0 && j
1281
- ] }, L)),
1282
- f.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => H({ url: s(k.url), kind: "video" }), children: [
1283
- /* @__PURE__ */ e("video", { src: s(k.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1284
- /* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,0,0,.25)" }, children: /* @__PURE__ */ e("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,.9)", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(Rt, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
1285
- F && L === f.length - 1 && j
1286
- ] }, L)),
1287
- (S.length > 0 || W.length > 0 || t.text || !m.length && !f.length && !O.length && !t.text) && /* @__PURE__ */ n("div", { style: A, children: [
1288
- S.map((k, L) => /* @__PURE__ */ e("audio", { src: s(k.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, L)),
1289
- W.map((k, L) => /* @__PURE__ */ n("a", { href: s(k.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: C ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
1763
+ ] }) }), L = S ? { ...f.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : f.bubbleIn, P = !t.text && v.length === 0 && W.length === 0;
1764
+ return /* @__PURE__ */ n("div", { style: { ...f.messageLine, justifyContent: $, flexDirection: "column", alignItems: $ }, children: [
1765
+ M.map((b, E) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
1766
+ /* @__PURE__ */ e("img", { src: h(b.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
1767
+ P && m.length === 0 && w.length === 0 && E === M.length - 1 && I
1768
+ ] }, `s${E}`)),
1769
+ m.map((b, E) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => j({ url: h(b.url), kind: "image" }), children: [
1770
+ /* @__PURE__ */ e("img", { src: h(b.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
1771
+ P && E === m.length - 1 && w.length === 0 && I
1772
+ ] }, E)),
1773
+ w.map((b, E) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => j({ url: h(b.url), kind: "video" }), children: [
1774
+ /* @__PURE__ */ e("video", { src: h(b.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
1775
+ /* @__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(Nt, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
1776
+ P && E === w.length - 1 && I
1777
+ ] }, E)),
1778
+ (v.length > 0 || W.length > 0 || t.text || !m.length && !w.length && !M.length && !t.text) && /* @__PURE__ */ n("div", { style: L, children: [
1779
+ v.map((b, E) => /* @__PURE__ */ e("audio", { src: h(b.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, E)),
1780
+ W.map((b, E) => /* @__PURE__ */ n("a", { href: h(b.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: S ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
1290
1781
  "📎 ",
1291
- Pt(k.mimeType)
1292
- ] }, L)),
1782
+ tn(b.mimeType)
1783
+ ] }, E)),
1293
1784
  t.text && /* @__PURE__ */ e("p", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: t.text }),
1294
- !S.length && !W.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1295
- E
1785
+ !v.length && !W.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
1786
+ D
1296
1787
  ] }),
1297
- I && it(
1298
- /* @__PURE__ */ n("div", { onClick: () => H(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
1299
- I.kind === "image" ? /* @__PURE__ */ e("img", { src: I.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (k) => k.stopPropagation() }) : /* @__PURE__ */ e("video", { src: I.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (k) => k.stopPropagation() }),
1300
- /* @__PURE__ */ e("button", { onClick: () => H(null), style: { position: "absolute", top: 16, right: 16, background: "rgba(255,255,255,.15)", border: "none", borderRadius: "50%", width: 36, height: 36, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ e(je, { size: 18 }) })
1788
+ T && St(
1789
+ /* @__PURE__ */ n("div", { onClick: () => j(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
1790
+ T.kind === "image" ? /* @__PURE__ */ e("img", { src: T.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (b) => b.stopPropagation() }) : /* @__PURE__ */ e("video", { src: T.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (b) => b.stopPropagation() }),
1791
+ /* @__PURE__ */ e("button", { onClick: () => j(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(Ue, { size: 18 }) })
1301
1792
  ] }),
1302
1793
  document.body
1303
1794
  )
1304
1795
  ] });
1305
1796
  }
1306
- function qt({
1797
+ function an({
1307
1798
  conversation: t,
1308
1799
  connection: i,
1309
1800
  primary: r,
1310
1801
  onClose: o,
1311
- client: s,
1312
- onStartResize: C,
1802
+ client: h,
1803
+ onStartResize: S,
1313
1804
  extensions: m,
1314
- extRefreshKey: O,
1315
- onLinkContact: f,
1316
- onRefreshContactInfo: S
1805
+ extRefreshKey: M,
1806
+ onLinkContact: w,
1807
+ onRefreshContactInfo: v
1317
1808
  }) {
1318
- const W = t.contactName ?? t.subject ?? t.providerConversationKey, I = i == null ? void 0 : i.provider, H = !!(m != null && m.some((v) => v.contactInfoRows)), [R, E] = y({ channel: !0, stats: !1, extra: !0 }), j = (v) => E((Q) => ({ ...Q, [v]: !Q[v] })), [A, F] = y(""), [K, ne] = y(!1), [U, w] = y(!1), [_, k] = y(""), [L, se] = y([]), [z, D] = y(!1);
1319
- Y(() => {
1320
- F(""), w(!1), k(""), s.getNote(t.id).then((v) => {
1321
- v && F(v.content);
1809
+ const W = t.contactName ?? t.subject ?? t.providerConversationKey, T = i == null ? void 0 : i.provider, j = !!(m != null && m.some((z) => z.contactInfoRows)), [$, C] = y({ channel: !0, stats: !1, extra: !0 }), D = (z) => C((oe) => ({ ...oe, [z]: !oe[z] })), [I, L] = y(""), [P, q] = y(!1), [te, Q] = y(!1), [B, x] = y(""), [b, E] = y([]), [V, ne] = y(!1);
1810
+ X(() => {
1811
+ L(""), Q(!1), x(""), h.getNote(t.id).then((z) => {
1812
+ z && L(z.content);
1322
1813
  }).catch(() => {
1323
1814
  });
1324
- }, [t.id, s]), Y(() => {
1325
- if (!H || !m) return;
1326
- let v = !1;
1327
- const Q = Ae(t, {
1328
- provider: I,
1329
- linkContact: f,
1330
- refreshContactInfo: S,
1331
- sendMessage: async (N, x) => {
1332
- await s.sendMessage(t.id, N, x);
1815
+ }, [t.id, h]), X(() => {
1816
+ if (!j || !m) return;
1817
+ let z = !1;
1818
+ const oe = Je(t, {
1819
+ provider: T,
1820
+ linkContact: w,
1821
+ refreshContactInfo: v,
1822
+ sendMessage: async (Z, O) => {
1823
+ await h.sendMessage(t.id, Z, O);
1333
1824
  }
1334
1825
  });
1335
- return D(!0), Promise.allSettled(
1336
- m.filter((N) => N.contactInfoRows).map((N) => N.contactInfoRows(Q))
1337
- ).then((N) => {
1338
- if (v) return;
1339
- const x = N.filter((J) => J.status === "fulfilled").flatMap((J) => J.value);
1340
- se(x), D(!1);
1826
+ return ne(!0), Promise.allSettled(
1827
+ m.filter((Z) => Z.contactInfoRows).map((Z) => Z.contactInfoRows(oe))
1828
+ ).then((Z) => {
1829
+ if (z) return;
1830
+ const O = Z.filter((ee) => ee.status === "fulfilled").flatMap((ee) => ee.value);
1831
+ E(O), ne(!1);
1341
1832
  }), () => {
1342
- v = !0;
1833
+ z = !0;
1343
1834
  };
1344
- }, [t.id, t.contactExternalId, m, O, H, I, f, S, s]);
1345
- async function le() {
1346
- if (!(!A.trim() || K)) {
1347
- ne(!0), k("");
1835
+ }, [t.id, t.contactExternalId, m, M, j, T, w, v, h]);
1836
+ async function de() {
1837
+ if (!(!I.trim() || P)) {
1838
+ q(!0), x("");
1348
1839
  try {
1349
- await s.upsertNote(t.id, A.trim()), w(!0), setTimeout(() => w(!1), 2e3);
1840
+ await h.upsertNote(t.id, I.trim()), Q(!0), setTimeout(() => Q(!1), 2e3);
1350
1841
  } catch {
1351
- k("Lưu thất bại");
1842
+ x("Lưu thất bại");
1352
1843
  } finally {
1353
- ne(!1);
1844
+ q(!1);
1354
1845
  }
1355
1846
  }
1356
1847
  }
1357
- return /* @__PURE__ */ n("aside", { style: { ...p.infoPanel, position: "relative" }, children: [
1848
+ return /* @__PURE__ */ n("aside", { style: { ...f.infoPanel, position: "relative" }, children: [
1358
1849
  /* @__PURE__ */ e(
1359
1850
  "div",
1360
1851
  {
1361
- onMouseDown: C,
1852
+ onMouseDown: S,
1362
1853
  style: { position: "absolute", left: 0, top: 0, bottom: 0, width: 4, cursor: "col-resize", zIndex: 1 },
1363
- onMouseEnter: (v) => {
1364
- v.currentTarget.style.background = "rgba(0,0,0,0.07)";
1854
+ onMouseEnter: (z) => {
1855
+ z.currentTarget.style.background = "rgba(0,0,0,0.07)";
1365
1856
  },
1366
- onMouseLeave: (v) => {
1367
- v.currentTarget.style.background = "";
1857
+ onMouseLeave: (z) => {
1858
+ z.currentTarget.style.background = "";
1368
1859
  }
1369
1860
  }
1370
1861
  ),
1371
- /* @__PURE__ */ n("div", { style: p.infoPanelHeader, children: [
1862
+ /* @__PURE__ */ n("div", { style: f.infoPanelHeader, children: [
1372
1863
  /* @__PURE__ */ e("span", { style: { fontWeight: 600, fontSize: 13, color: d.ink }, children: "Thông tin liên hệ" }),
1373
- /* @__PURE__ */ e("button", { style: p.iconButton, onClick: o, "aria-label": "Đóng", children: /* @__PURE__ */ e(je, { size: 16, strokeWidth: 2 }) })
1864
+ /* @__PURE__ */ e("button", { style: f.iconButton, onClick: o, "aria-label": "Đóng", children: /* @__PURE__ */ e(Ue, { size: 16, strokeWidth: 2 }) })
1374
1865
  ] }),
1375
1866
  /* @__PURE__ */ n("div", { style: { overflowY: "auto", flex: 1 }, children: [
1376
- /* @__PURE__ */ n("div", { style: p.infoPanelIdentity, children: [
1377
- /* @__PURE__ */ n("span", { style: { ...p.avatarWrap, width: 48, height: 48 }, children: [
1867
+ /* @__PURE__ */ n("div", { style: f.infoPanelIdentity, children: [
1868
+ /* @__PURE__ */ n("span", { style: { ...f.avatarWrap, width: 48, height: 48 }, children: [
1378
1869
  /* @__PURE__ */ e(
1379
1870
  dt,
1380
1871
  {
1381
1872
  src: t.contactPictureUrl,
1382
- fallback: ut(W),
1383
- style: { ...p.avatar, width: 48, height: 48, fontSize: 16 }
1873
+ fallback: Le(W),
1874
+ style: { ...f.avatar, width: 48, height: 48, fontSize: 16 }
1384
1875
  }
1385
1876
  ),
1386
- /* @__PURE__ */ e("span", { style: { ...p.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e($e, { provider: I }) })
1877
+ /* @__PURE__ */ e("span", { style: { ...f.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e(De, { provider: T }) })
1387
1878
  ] }),
1388
1879
  /* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: W }),
1389
1880
  /* @__PURE__ */ e("span", { style: { fontSize: 11, color: d.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
1390
1881
  ] }),
1391
- /* @__PURE__ */ n(Ue, { label: "KÊNH", sectionKey: "channel", expanded: R.channel, onToggle: () => j("channel"), children: [
1392
- /* @__PURE__ */ e(pe, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
1393
- /* @__PURE__ */ e($e, { provider: I }),
1394
- /* @__PURE__ */ e("span", { children: ht(I) })
1882
+ /* @__PURE__ */ n(_e, { label: "KÊNH", sectionKey: "channel", expanded: $.channel, onToggle: () => D("channel"), children: [
1883
+ /* @__PURE__ */ e(ge, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
1884
+ /* @__PURE__ */ e(De, { provider: T }),
1885
+ /* @__PURE__ */ e("span", { children: Wt(T) })
1395
1886
  ] }) }),
1396
- /* @__PURE__ */ n(pe, { label: "ID hội thoại", children: [
1887
+ /* @__PURE__ */ n(ge, { label: "ID hội thoại", children: [
1397
1888
  /* @__PURE__ */ n("span", { style: { fontFamily: "monospace", fontSize: 11 }, children: [
1398
1889
  t.id.slice(0, 8),
1399
1890
  "…"
1400
1891
  ] }),
1401
- /* @__PURE__ */ e(Vt, { value: t.id })
1892
+ /* @__PURE__ */ e(ln, { value: t.id })
1402
1893
  ] })
1403
1894
  ] }),
1404
- /* @__PURE__ */ n(Ue, { label: "THỐNG KÊ", sectionKey: "stats", expanded: R.stats, onToggle: () => j("stats"), children: [
1405
- /* @__PURE__ */ e(pe, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
1406
- (t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(pe, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
1895
+ /* @__PURE__ */ n(_e, { label: "THỐNG KÊ", sectionKey: "stats", expanded: $.stats, onToggle: () => D("stats"), children: [
1896
+ /* @__PURE__ */ e(ge, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
1897
+ (t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(ge, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
1407
1898
  /* @__PURE__ */ e(
1408
- pe,
1899
+ ge,
1409
1900
  {
1410
1901
  label: "Gần nhất",
1411
1902
  value: t.lastMessageAt ? new Date(t.lastMessageAt).toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit", year: "numeric" }) : "—"
1412
1903
  }
1413
1904
  ),
1414
- /* @__PURE__ */ e(pe, { label: "Lần đầu", value: "—" })
1905
+ /* @__PURE__ */ e(ge, { label: "Lần đầu", value: "—" })
1415
1906
  ] }),
1416
- /* @__PURE__ */ n(Ue, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: R.extra, onToggle: () => j("extra"), children: [
1417
- !H && /* @__PURE__ */ n(te, { children: [
1418
- /* @__PURE__ */ e(pe, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
1419
- /* @__PURE__ */ e(pe, { label: "Email", value: "— chưa có", valueMuted: !0 }),
1420
- /* @__PURE__ */ e(pe, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
1907
+ /* @__PURE__ */ n(_e, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: $.extra, onToggle: () => D("extra"), children: [
1908
+ !j && /* @__PURE__ */ n(ie, { children: [
1909
+ /* @__PURE__ */ e(ge, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
1910
+ /* @__PURE__ */ e(ge, { label: "Email", value: "— chưa có", valueMuted: !0 }),
1911
+ /* @__PURE__ */ e(ge, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
1421
1912
  ] }),
1422
- z && L.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
1423
- L.map((v) => /* @__PURE__ */ e(pe, { label: v.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
1424
- v.onClick ? /* @__PURE__ */ e(
1913
+ V && b.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
1914
+ b.map((z) => /* @__PURE__ */ e(ge, { label: z.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
1915
+ z.onClick ? /* @__PURE__ */ e(
1425
1916
  "button",
1426
1917
  {
1427
1918
  type: "button",
1428
- onClick: v.onClick,
1919
+ onClick: z.onClick,
1429
1920
  style: { border: 0, background: "none", padding: 0, color: r, fontSize: 12, fontWeight: 600, cursor: "pointer", textDecoration: "underline" },
1430
- children: v.value
1921
+ children: z.value
1431
1922
  }
1432
- ) : v.href ? /* @__PURE__ */ e("a", { href: v.href, target: "_blank", rel: "noopener noreferrer", style: { color: r, fontSize: 12, fontWeight: 600 }, children: v.value }) : /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 500, color: d.ink }, children: v.value }),
1433
- v.badge && /* @__PURE__ */ e(
1923
+ ) : z.href ? /* @__PURE__ */ e("a", { href: z.href, target: "_blank", rel: "noopener noreferrer", style: { color: r, fontSize: 12, fontWeight: 600 }, children: z.value }) : /* @__PURE__ */ e("span", { style: { fontSize: 12, fontWeight: 500, color: d.ink }, children: z.value }),
1924
+ z.badge && /* @__PURE__ */ e(
1434
1925
  "span",
1435
1926
  {
1436
1927
  style: {
@@ -1438,49 +1929,49 @@ function qt({
1438
1929
  fontWeight: 700,
1439
1930
  padding: "1px 7px",
1440
1931
  borderRadius: 999,
1441
- color: v.badge.color ?? r,
1442
- background: v.badge.bg ?? `${r}14`
1932
+ color: z.badge.color ?? r,
1933
+ background: z.badge.bg ?? `${r}14`
1443
1934
  },
1444
- children: v.badge.text
1935
+ children: z.badge.text
1445
1936
  }
1446
1937
  )
1447
- ] }) }, v.label))
1938
+ ] }) }, z.label))
1448
1939
  ] }),
1449
1940
  /* @__PURE__ */ n("div", { style: { padding: "12px 16px", display: "flex", flexDirection: "column", gap: 8 }, children: [
1450
- !(m != null && m.length) && /* @__PURE__ */ e("button", { style: { ...p.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1451
- m == null ? void 0 : m.flatMap((v) => v.sidebarActions ?? []).map((v, Q) => {
1452
- const N = v.variant === "primary";
1941
+ !(m != null && m.length) && /* @__PURE__ */ e("button", { style: { ...f.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
1942
+ m == null ? void 0 : m.flatMap((z) => z.sidebarActions ?? []).map((z, oe) => {
1943
+ const Z = z.variant === "primary";
1453
1944
  return /* @__PURE__ */ n(
1454
1945
  "button",
1455
1946
  {
1456
1947
  style: {
1457
- ...p.ghostButton,
1458
- background: N ? r : "#fff",
1459
- color: N ? "#fff" : d.ink,
1460
- borderColor: N ? r : d.line,
1461
- fontWeight: N ? 700 : 600,
1948
+ ...f.ghostButton,
1949
+ background: Z ? r : "#fff",
1950
+ color: Z ? "#fff" : d.ink,
1951
+ borderColor: Z ? r : d.line,
1952
+ fontWeight: Z ? 700 : 600,
1462
1953
  display: "flex",
1463
1954
  alignItems: "center",
1464
1955
  justifyContent: "center",
1465
1956
  gap: 6
1466
1957
  },
1467
1958
  onClick: () => {
1468
- const x = Ae(t, {
1469
- provider: I,
1470
- linkContact: f,
1471
- refreshContactInfo: S,
1472
- sendMessage: async (J, he) => {
1473
- await s.sendMessage(t.id, J, he);
1959
+ const O = Je(t, {
1960
+ provider: T,
1961
+ linkContact: w,
1962
+ refreshContactInfo: v,
1963
+ sendMessage: async (ee, se) => {
1964
+ await h.sendMessage(t.id, ee, se);
1474
1965
  }
1475
1966
  });
1476
- v.onClick(x);
1967
+ z.onClick(O);
1477
1968
  },
1478
1969
  children: [
1479
- v.icon,
1480
- v.label
1970
+ z.icon,
1971
+ z.label
1481
1972
  ]
1482
1973
  },
1483
- Q
1974
+ oe
1484
1975
  );
1485
1976
  }),
1486
1977
  /* @__PURE__ */ n("div", { style: { border: `1px solid ${d.line}`, borderRadius: 10, background: "#fff", overflow: "hidden" }, children: [
@@ -1488,28 +1979,28 @@ function qt({
1488
1979
  /* @__PURE__ */ e(
1489
1980
  "textarea",
1490
1981
  {
1491
- value: A,
1492
- onChange: (v) => F(v.target.value),
1982
+ value: I,
1983
+ onChange: (z) => L(z.target.value),
1493
1984
  placeholder: "Nhập ghi chú...",
1494
1985
  rows: 3,
1495
1986
  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 }
1496
1987
  }
1497
1988
  ),
1498
1989
  /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 10px 6px" }, children: [
1499
- U ? /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, fontSize: 11, color: "#16a34a" }, children: [
1500
- /* @__PURE__ */ e(ot, { size: 11, strokeWidth: 2.5 }),
1990
+ te ? /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, fontSize: 11, color: "#16a34a" }, children: [
1991
+ /* @__PURE__ */ e(lt, { size: 11, strokeWidth: 2.5 }),
1501
1992
  " Đã lưu"
1502
- ] }) : _ ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: _ }) : /* @__PURE__ */ e("span", {}),
1993
+ ] }) : B ? /* @__PURE__ */ e("span", { style: { fontSize: 11, color: "#ef4444" }, children: B }) : /* @__PURE__ */ e("span", {}),
1503
1994
  /* @__PURE__ */ e(
1504
1995
  "button",
1505
1996
  {
1506
1997
  type: "button",
1507
1998
  onClick: () => {
1508
- le();
1999
+ de();
1509
2000
  },
1510
- disabled: !A.trim() || K,
1511
- style: { padding: "4px 12px", border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: A.trim() && !K ? "linear-gradient(135deg,#f59e0b,#fbbf24)" : "#e5e7eb", color: A.trim() && !K ? "#fff" : "#9ca3af", cursor: A.trim() && !K ? "pointer" : "not-allowed" },
1512
- children: K ? "Đang lưu…" : "Lưu ghi chú"
2001
+ disabled: !I.trim() || P,
2002
+ style: { padding: "4px 12px", border: 0, borderRadius: 7, fontSize: 12, fontWeight: 600, background: I.trim() && !P ? "linear-gradient(135deg,#f59e0b,#fbbf24)" : "#e5e7eb", color: I.trim() && !P ? "#fff" : "#9ca3af", cursor: I.trim() && !P ? "pointer" : "not-allowed" },
2003
+ children: P ? "Đang lưu…" : "Lưu ghi chú"
1513
2004
  }
1514
2005
  )
1515
2006
  ] })
@@ -1518,30 +2009,30 @@ function qt({
1518
2009
  ] })
1519
2010
  ] });
1520
2011
  }
1521
- function Ue({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s }) {
1522
- const C = !!s, m = o ?? !0;
2012
+ function _e({ label: t, children: i, sectionKey: r, expanded: o, onToggle: h }) {
2013
+ const S = !!h, m = o ?? !0;
1523
2014
  return /* @__PURE__ */ n("div", { style: { borderTop: `1px solid ${d.line}` }, children: [
1524
2015
  /* @__PURE__ */ n(
1525
2016
  "div",
1526
2017
  {
1527
- style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: d.muted, textTransform: "uppercase", cursor: C ? "pointer" : "default" },
1528
- onClick: s,
2018
+ style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: d.muted, textTransform: "uppercase", cursor: S ? "pointer" : "default" },
2019
+ onClick: h,
1529
2020
  children: [
1530
2021
  /* @__PURE__ */ e("span", { children: t }),
1531
- C && (m ? /* @__PURE__ */ e(kt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(wt, { size: 12, strokeWidth: 2 }))
2022
+ S && (m ? /* @__PURE__ */ e(nt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(jt, { size: 12, strokeWidth: 2 }))
1532
2023
  ]
1533
2024
  }
1534
2025
  ),
1535
2026
  m && i
1536
2027
  ] });
1537
2028
  }
1538
- function pe({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
2029
+ function ge({ label: t, value: i, children: r, valueColor: o, valueMuted: h }) {
1539
2030
  return /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", padding: "5px 16px", fontSize: 12, gap: 10 }, children: [
1540
2031
  /* @__PURE__ */ e("span", { style: { color: d.muted, flexShrink: 0, lineHeight: 1.4 }, children: t }),
1541
- /* @__PURE__ */ e("span", { style: { color: o ?? (s ? d.muted : d.ink), textAlign: "right", minWidth: 0, display: "flex", alignItems: "center", justifyContent: "flex-end", flexWrap: "wrap", gap: 4, lineHeight: 1.4 }, children: r ?? i })
2032
+ /* @__PURE__ */ e("span", { style: { color: o ?? (h ? d.muted : d.ink), textAlign: "right", minWidth: 0, display: "flex", alignItems: "center", justifyContent: "flex-end", flexWrap: "wrap", gap: 4, lineHeight: 1.4 }, children: r ?? i })
1542
2033
  ] });
1543
2034
  }
1544
- function Vt({ value: t }) {
2035
+ function ln({ value: t }) {
1545
2036
  const [i, r] = y(!1);
1546
2037
  return /* @__PURE__ */ e(
1547
2038
  "button",
@@ -1558,41 +2049,41 @@ function Vt({ value: t }) {
1558
2049
  }
1559
2050
  );
1560
2051
  }
1561
- function Gt() {
1562
- return /* @__PURE__ */ n("div", { style: p.empty, children: [
1563
- /* @__PURE__ */ e("div", { style: p.emptyHero, children: /* @__PURE__ */ e(It, { size: 16, strokeWidth: 2 }) }),
2052
+ function dn() {
2053
+ return /* @__PURE__ */ n("div", { style: f.empty, children: [
2054
+ /* @__PURE__ */ e("div", { style: f.emptyHero, children: /* @__PURE__ */ e(Ut, { size: 16, strokeWidth: 2 }) }),
1564
2055
  /* @__PURE__ */ e("h2", { children: "Chọn một hội thoại" }),
1565
2056
  /* @__PURE__ */ e("p", { children: "Chọn hội thoại bên trái để xem và trả lời tin nhắn." })
1566
2057
  ] });
1567
2058
  }
1568
- function pt({ name: t, color: i, image: r, provider: o }) {
1569
- return /* @__PURE__ */ n("span", { style: p.avatarWrap, children: [
1570
- /* @__PURE__ */ e(Xt, { name: t, color: i, image: r }),
1571
- o && /* @__PURE__ */ e("span", { style: p.providerBadge, children: /* @__PURE__ */ e($e, { provider: o }) })
2059
+ function $t({ name: t, color: i, image: r, provider: o }) {
2060
+ return /* @__PURE__ */ n("span", { style: f.avatarWrap, children: [
2061
+ /* @__PURE__ */ e(sn, { name: t, color: i, image: r }),
2062
+ o && /* @__PURE__ */ e("span", { style: f.providerBadge, children: /* @__PURE__ */ e(De, { provider: o }) })
1572
2063
  ] });
1573
2064
  }
1574
- function Xt({ name: t, color: i, image: r }) {
1575
- return /* @__PURE__ */ e(dt, { src: r, fallback: ut(t), style: { ...p.avatar, background: `${i}18`, color: i } });
2065
+ function sn({ name: t, color: i, image: r }) {
2066
+ return /* @__PURE__ */ e(dt, { src: r, fallback: Le(t), style: { ...f.avatar, background: `${i}18`, color: i } });
1576
2067
  }
1577
- function Fe() {
1578
- return /* @__PURE__ */ e(lt, { size: 14, style: p.spinner, "aria-hidden": "true" });
2068
+ function ot() {
2069
+ return /* @__PURE__ */ e(zt, { size: 14, style: f.spinner, "aria-hidden": "true" });
1579
2070
  }
1580
- function ut(t) {
2071
+ function Le(t) {
1581
2072
  return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
1582
2073
  }
1583
- const Jt = { livechat: "web" };
1584
- function $e({ provider: t }) {
1585
- const i = Ne(qe), r = 14;
2074
+ const cn = { livechat: "web" };
2075
+ function De({ provider: t }) {
2076
+ const i = tt(st), r = 14;
1586
2077
  if (!t) return null;
1587
- const o = Jt[t] ?? t;
2078
+ const o = cn[t] ?? t;
1588
2079
  return /* @__PURE__ */ e("img", { src: `${i}/static/logos/${o}.avif`, alt: t, width: r, height: r, style: { borderRadius: "50%", objectFit: "cover", display: "block" } });
1589
2080
  }
1590
- function Ke(t, i = !1) {
2081
+ function at(t, i = !1) {
1591
2082
  if (!t) return "";
1592
2083
  const r = new Date(t);
1593
2084
  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" });
1594
2085
  }
1595
- const p = {
2086
+ const f = {
1596
2087
  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)" },
1597
2088
  sidebar: { display: "flex", flexDirection: "column", minWidth: 0, minHeight: 0, borderRight: `1px solid ${d.line}`, background: d.white },
1598
2089
  brand: { display: "flex", alignItems: "center", gap: 10, padding: "20px 18px 16px" },
@@ -1639,14 +2130,14 @@ const p = {
1639
2130
  infoPanelHeader: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 16px 12px", borderBottom: `1px solid ${d.line}`, flex: "0 0 auto" },
1640
2131
  infoPanelIdentity: { display: "flex", flexDirection: "column", alignItems: "center", padding: "20px 16px 16px", gap: 4 },
1641
2132
  ghostButton: { width: "100%", padding: "8px 12px", border: `1px solid ${d.line}`, borderRadius: 8, background: "transparent", fontSize: 12, cursor: "pointer", textAlign: "center" }
1642
- }, Yt = {
2133
+ }, hn = {
1643
2134
  facebook: "#dbeafe",
1644
2135
  zalo: "#e0f2fe",
1645
2136
  instagram: "#fce7f3",
1646
2137
  telegram: "#cffafe",
1647
2138
  livechat: "#ede9fe",
1648
2139
  whatsapp: "#dcfce7"
1649
- }, _t = {
2140
+ }, pn = {
1650
2141
  facebook: "facebook",
1651
2142
  instagram: "instagram",
1652
2143
  telegram: "telegram",
@@ -1654,8 +2145,8 @@ const p = {
1654
2145
  livechat: "web",
1655
2146
  whatsapp: "web"
1656
2147
  };
1657
- function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1658
- const o = Yt[t] ?? "#f1f5f9", s = _t[t], C = i.replace(/\/$/, "");
2148
+ function xe({ provider: t, apiUrl: i, size: r = 40 }) {
2149
+ const o = hn[t] ?? "#f1f5f9", h = pn[t], S = i.replace(/\/$/, "");
1659
2150
  return /* @__PURE__ */ e(
1660
2151
  "div",
1661
2152
  {
@@ -1670,10 +2161,10 @@ function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1670
2161
  flexShrink: 0,
1671
2162
  overflow: "hidden"
1672
2163
  },
1673
- children: s ? /* @__PURE__ */ e(
2164
+ children: h ? /* @__PURE__ */ e(
1674
2165
  "img",
1675
2166
  {
1676
- src: `${C}/static/logos/${s}.avif`,
2167
+ src: `${S}/static/logos/${h}.avif`,
1677
2168
  alt: t,
1678
2169
  width: Math.round(r * 0.65),
1679
2170
  height: Math.round(r * 0.65),
@@ -1683,14 +2174,14 @@ function ge({ provider: t, apiUrl: i, size: r = 40 }) {
1683
2174
  }
1684
2175
  );
1685
2176
  }
1686
- const Be = {
2177
+ const Oe = {
1687
2178
  facebook: "Facebook",
1688
2179
  zalo: "Zalo OA",
1689
2180
  instagram: "Instagram",
1690
2181
  telegram: "Telegram",
1691
2182
  livechat: "Live Chat",
1692
2183
  whatsapp: "WhatsApp"
1693
- }, Zt = {
2184
+ }, un = {
1694
2185
  facebook: "#dbeafe",
1695
2186
  zalo: "#e0f2fe",
1696
2187
  instagram: "#fce7f3",
@@ -1698,15 +2189,15 @@ const Be = {
1698
2189
  livechat: "#ede9fe",
1699
2190
  whatsapp: "#dcfce7"
1700
2191
  };
1701
- function Ve(t) {
2192
+ function ct(t) {
1702
2193
  const i = t.metadata;
1703
2194
  return String(i.displayName ?? i.pageName ?? i.username ?? i.name ?? t.externalAccountId);
1704
2195
  }
1705
- function Qt(t) {
1706
- const i = Be[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
2196
+ function fn(t) {
2197
+ const i = Oe[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
1707
2198
  return r ? `${i} · ${r}` : i;
1708
2199
  }
1709
- const a = {
2200
+ const s = {
1710
2201
  root: {
1711
2202
  background: "#fff",
1712
2203
  borderRadius: 16,
@@ -1981,272 +2472,272 @@ const a = {
1981
2472
  fontFamily: "inherit"
1982
2473
  }
1983
2474
  };
1984
- function Ze() {
2475
+ function mt() {
1985
2476
  return /* @__PURE__ */ e("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ e("path", { d: "M7 1v12M1 7h12", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) });
1986
2477
  }
1987
- function ve() {
2478
+ function Be() {
1988
2479
  return /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ e("path", { d: "M10 3L5 8l5 5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) });
1989
2480
  }
1990
- function Qe() {
2481
+ function xt() {
1991
2482
  return /* @__PURE__ */ n("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: [
1992
2483
  /* @__PURE__ */ e("rect", { x: "4", y: "4", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.3" }),
1993
2484
  /* @__PURE__ */ e("path", { d: "M2.5 8H2a1 1 0 01-1-1V2a1 1 0 011-1h5a1 1 0 011 1v.5", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
1994
2485
  ] });
1995
2486
  }
1996
- function et() {
2487
+ function vt() {
1997
2488
  return /* @__PURE__ */ e("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: /* @__PURE__ */ e("path", { d: "M2 6l3 3 5-5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
1998
2489
  }
1999
- function en() {
2490
+ function gn() {
2000
2491
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0 }, children: [
2001
2492
  /* @__PURE__ */ e("circle", { cx: "5", cy: "6", r: "3.5", stroke: "#ca8a04", strokeWidth: "1.4" }),
2002
2493
  /* @__PURE__ */ e("path", { d: "M8 7.5l4.5 4.5M10.5 10l1.5 1.5", stroke: "#ca8a04", strokeWidth: "1.4", strokeLinecap: "round" })
2003
2494
  ] });
2004
2495
  }
2005
- function tn() {
2496
+ function yn() {
2006
2497
  return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0, marginTop: 1 }, children: [
2007
2498
  /* @__PURE__ */ e("circle", { cx: "7", cy: "7", r: "6", stroke: "currentColor", strokeWidth: "1.5" }),
2008
2499
  /* @__PURE__ */ e("path", { d: "M7 6v5M7 4.5v.01", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
2009
2500
  ] });
2010
2501
  }
2011
- let tt = !1;
2012
- function nn() {
2013
- if (tt || typeof document > "u") return;
2014
- tt = !0;
2502
+ let kt = !1;
2503
+ function bn() {
2504
+ if (kt || typeof document > "u") return;
2505
+ kt = !0;
2015
2506
  const t = document.createElement("style");
2016
2507
  t.textContent = "@keyframes ch-spin{to{transform:rotate(360deg)}}", document.head.appendChild(t);
2017
2508
  }
2018
- function un({ apiUrl: t, token: i, onConnectionChange: r }) {
2019
- const o = t.replace(/\/$/, ""), [s, C] = y([]), [m, O] = y(!0), [f, S] = y({ name: "list" }), [W, I] = y(null), [H, R] = y(!1), [E, j] = y(""), [A, F] = y(""), [K, ne] = y(""), [U, w] = y(""), [_, k] = y(!1), [L, se] = y(!1), z = ee(null);
2020
- nn();
2021
- const D = We(async () => {
2509
+ function $n({ apiUrl: t, token: i, onConnectionChange: r }) {
2510
+ const o = t.replace(/\/$/, ""), [h, S] = y([]), [m, M] = y(!0), [w, v] = y({ name: "list" }), [W, T] = y(null), [j, $] = y(!1), [C, D] = y(""), [I, L] = y(""), [P, q] = y(""), [te, Q] = y(""), [B, x] = y(!1), [b, E] = y(!1), V = J(null);
2511
+ bn();
2512
+ const ne = we(async () => {
2022
2513
  try {
2023
- const h = await fetch(`${o}/v1/connections`, {
2514
+ const c = await fetch(`${o}/v1/connections`, {
2024
2515
  headers: { authorization: `Bearer ${i}` }
2025
2516
  });
2026
- if (!h.ok) throw new Error("Không tải được kênh");
2027
- const B = await h.json();
2028
- C(B), r == null || r(B);
2029
- } catch (h) {
2030
- I(h instanceof Error ? h.message : "Lỗi tải dữ liệu");
2517
+ if (!c.ok) throw new Error("Không tải được kênh");
2518
+ const H = await c.json();
2519
+ S(H), r == null || r(H);
2520
+ } catch (c) {
2521
+ T(c instanceof Error ? c.message : "Lỗi tải dữ liệu");
2031
2522
  } finally {
2032
- O(!1);
2523
+ M(!1);
2033
2524
  }
2034
2525
  }, [o, i, r]);
2035
- Y(() => {
2036
- D();
2037
- }, [D]), Y(() => {
2526
+ X(() => {
2527
+ ne();
2528
+ }, [ne]), X(() => {
2038
2529
  if (!W) return;
2039
- const h = setTimeout(() => I(null), 5e3);
2040
- return () => clearTimeout(h);
2041
- }, [W]), Y(() => () => {
2042
- z.current && window.removeEventListener("message", z.current);
2530
+ const c = setTimeout(() => T(null), 5e3);
2531
+ return () => clearTimeout(c);
2532
+ }, [W]), X(() => () => {
2533
+ V.current && window.removeEventListener("message", V.current);
2043
2534
  }, []);
2044
- async function le(h, B) {
2045
- if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${B}"?
2535
+ async function de(c, H) {
2536
+ if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${H}"?
2046
2537
 
2047
2538
  Hành động này không thể hoàn tác.`))
2048
2539
  try {
2049
- if (!(await fetch(`${o}/v1/connections/${h}`, {
2540
+ if (!(await fetch(`${o}/v1/connections/${c}`, {
2050
2541
  method: "DELETE",
2051
2542
  headers: { authorization: `Bearer ${i}` }
2052
2543
  })).ok) throw new Error("Không thể ngắt kết nối");
2053
- await D();
2054
- } catch (P) {
2055
- I(P instanceof Error ? P.message : "Lỗi ngắt kết nối");
2544
+ await ne();
2545
+ } catch (N) {
2546
+ T(N instanceof Error ? N.message : "Lỗi ngắt kết nối");
2056
2547
  }
2057
2548
  }
2058
- async function v() {
2059
- if (!E.trim()) {
2060
- I("Vui lòng nhập Bot Token");
2549
+ async function z() {
2550
+ if (!C.trim()) {
2551
+ T("Vui lòng nhập Bot Token");
2061
2552
  return;
2062
2553
  }
2063
- if (!/^\d+:[A-Za-z0-9_-]+$/.test(E.trim())) {
2064
- I("Token không đúng định dạng");
2554
+ if (!/^\d+:[A-Za-z0-9_-]+$/.test(C.trim())) {
2555
+ T("Token không đúng định dạng");
2065
2556
  return;
2066
2557
  }
2067
- R(!0), I(null);
2558
+ $(!0), T(null);
2068
2559
  try {
2069
- const h = await fetch(`${o}/v1/connect/telegram/start`, {
2560
+ const c = await fetch(`${o}/v1/connect/telegram/start`, {
2070
2561
  method: "POST",
2071
2562
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2072
- body: JSON.stringify({ botToken: E.trim(), displayName: A.trim() || void 0 })
2073
- }), B = await h.json();
2074
- if (!h.ok || !B.connectionId) throw new Error(B.message ?? "Không thể kết nối Telegram");
2075
- j(""), F(""), await D(), S({ name: "list" });
2076
- } catch (h) {
2077
- I(h instanceof Error ? h.message : "Lỗi kết nối");
2563
+ body: JSON.stringify({ botToken: C.trim(), displayName: I.trim() || void 0 })
2564
+ }), H = await c.json();
2565
+ if (!c.ok || !H.connectionId) throw new Error(H.message ?? "Không thể kết nối Telegram");
2566
+ D(""), L(""), await ne(), v({ name: "list" });
2567
+ } catch (c) {
2568
+ T(c instanceof Error ? c.message : "Lỗi kết nối");
2078
2569
  } finally {
2079
- R(!1);
2570
+ $(!1);
2080
2571
  }
2081
2572
  }
2082
- async function Q() {
2083
- if (!K.trim()) {
2084
- I("Vui lòng nhập tên widget");
2573
+ async function oe() {
2574
+ if (!P.trim()) {
2575
+ T("Vui lòng nhập tên widget");
2085
2576
  return;
2086
2577
  }
2087
- R(!0), I(null);
2578
+ $(!0), T(null);
2088
2579
  try {
2089
- const h = U.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean), B = await fetch(`${o}/v1/connect/livechat/start`, {
2580
+ const c = te.split(/[\n,]+/).map((ae) => ae.trim()).filter(Boolean), H = await fetch(`${o}/v1/connect/livechat/start`, {
2090
2581
  method: "POST",
2091
2582
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2092
- body: JSON.stringify({ displayName: K.trim(), allowedDomains: h.length ? h : void 0 })
2093
- }), P = await B.json();
2094
- if (!B.ok || !P.connectionId || !P.embedScript) throw new Error(P.message ?? "Không thể tạo widget");
2095
- ne(""), w(""), await D(), S({
2583
+ body: JSON.stringify({ displayName: P.trim(), allowedDomains: c.length ? c : void 0 })
2584
+ }), N = await H.json();
2585
+ if (!H.ok || !N.connectionId || !N.embedScript) throw new Error(N.message ?? "Không thể tạo widget");
2586
+ q(""), Q(""), await ne(), v({
2096
2587
  name: "livechat-result",
2097
- connectionId: P.connectionId,
2098
- embedScript: P.embedScript,
2099
- identitySecret: P.identitySecret ?? "",
2100
- allowedDomains: P.allowedDomains ?? []
2588
+ connectionId: N.connectionId,
2589
+ embedScript: N.embedScript,
2590
+ identitySecret: N.identitySecret ?? "",
2591
+ allowedDomains: N.allowedDomains ?? []
2101
2592
  });
2102
- } catch (h) {
2103
- I(h instanceof Error ? h.message : "Lỗi tạo widget");
2593
+ } catch (c) {
2594
+ T(c instanceof Error ? c.message : "Lỗi tạo widget");
2104
2595
  } finally {
2105
- R(!1);
2596
+ $(!1);
2106
2597
  }
2107
2598
  }
2108
- async function N(h) {
2109
- I(null);
2599
+ async function Z(c) {
2600
+ T(null);
2110
2601
  try {
2111
- const B = `${o}/static/oauth-popup.html`, P = await fetch(`${o}/v1/connect/${h}/start`, {
2602
+ const H = `${o}/static/oauth-popup.html`, N = await fetch(`${o}/v1/connect/${c}/start`, {
2112
2603
  method: "POST",
2113
2604
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2114
- body: JSON.stringify({ callbackUrl: B })
2115
- }), q = await P.json();
2116
- if (!P.ok || !q.authorizationUrl) throw new Error(q.message ?? "Không thể bắt đầu kết nối");
2117
- const ie = window.open(q.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
2118
- S({ name: "oauth-waiting", provider: h, popup: ie }), z.current && window.removeEventListener("message", z.current);
2119
- const re = (V) => {
2120
- if (V.data) {
2121
- if (V.data.type === "channelhub:oauth-select") {
2122
- S({
2605
+ body: JSON.stringify({ callbackUrl: H })
2606
+ }), ae = await N.json();
2607
+ if (!N.ok || !ae.authorizationUrl) throw new Error(ae.message ?? "Không thể bắt đầu kết nối");
2608
+ const ce = window.open(ae.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
2609
+ v({ name: "oauth-waiting", provider: c, popup: ce }), V.current && window.removeEventListener("message", V.current);
2610
+ const ye = (F) => {
2611
+ if (F.data) {
2612
+ if (F.data.type === "channelhub:oauth-select") {
2613
+ v({
2123
2614
  name: "oauth-select",
2124
- provider: V.data.provider,
2125
- sessionId: String(V.data.sessionId ?? ""),
2126
- pages: V.data.pages ?? [],
2127
- popup: ie
2615
+ provider: F.data.provider,
2616
+ sessionId: String(F.data.sessionId ?? ""),
2617
+ pages: F.data.pages ?? [],
2618
+ popup: ce
2128
2619
  });
2129
2620
  return;
2130
2621
  }
2131
- V.data.type === "channelhub:oauth" && (window.removeEventListener("message", re), z.current = null, V.data.status === "active" ? (D(), S({ name: "list" })) : (I("Kết nối thất bại: " + String(V.data.error ?? "Không xác định")), S({ name: "list" })));
2622
+ F.data.type === "channelhub:oauth" && (window.removeEventListener("message", ye), V.current = null, F.data.status === "active" ? (ne(), v({ name: "list" })) : (T("Kết nối thất bại: " + String(F.data.error ?? "Không xác định")), v({ name: "list" })));
2132
2623
  }
2133
2624
  };
2134
- z.current = re, window.addEventListener("message", re);
2135
- } catch (B) {
2136
- I(B instanceof Error ? B.message : "Lỗi kết nối"), S({ name: "list" });
2625
+ V.current = ye, window.addEventListener("message", ye);
2626
+ } catch (H) {
2627
+ T(H instanceof Error ? H.message : "Lỗi kết nối"), v({ name: "list" });
2137
2628
  }
2138
2629
  }
2139
- function x(h, B) {
2140
- navigator.clipboard.writeText(h).then(() => {
2141
- B === "script" ? (k(!0), setTimeout(() => k(!1), 2e3)) : (se(!0), setTimeout(() => se(!1), 2e3));
2630
+ function O(c, H) {
2631
+ navigator.clipboard.writeText(c).then(() => {
2632
+ H === "script" ? (x(!0), setTimeout(() => x(!1), 2e3)) : (E(!0), setTimeout(() => E(!1), 2e3));
2142
2633
  });
2143
2634
  }
2144
- function J() {
2145
- const h = f.name === "oauth-waiting" || f.name === "oauth-select" ? f.popup : null;
2146
- if (h)
2635
+ function ee() {
2636
+ const c = w.name === "oauth-waiting" || w.name === "oauth-select" ? w.popup : null;
2637
+ if (c)
2147
2638
  try {
2148
- h.close();
2639
+ c.close();
2149
2640
  } catch {
2150
2641
  }
2151
- z.current && (window.removeEventListener("message", z.current), z.current = null), S({ name: "add" });
2642
+ V.current && (window.removeEventListener("message", V.current), V.current = null), v({ name: "add" });
2152
2643
  }
2153
- async function he(h) {
2154
- if (f.name !== "oauth-select") return;
2155
- const { provider: B, sessionId: P, popup: q } = f;
2156
- R(!0), I(null);
2157
- const ie = {
2644
+ async function se(c) {
2645
+ if (w.name !== "oauth-select") return;
2646
+ const { provider: H, sessionId: N, popup: ae } = w;
2647
+ $(!0), T(null);
2648
+ const ce = {
2158
2649
  facebook: `${o}/v1/connect/facebook/select-page`,
2159
2650
  instagram: `${o}/v1/connect/instagram/select-account`,
2160
2651
  zalo: `${o}/v1/connect/zalo/select-oa`
2161
- }, re = {
2652
+ }, ye = {
2162
2653
  facebook: "pageId",
2163
2654
  instagram: "accountId",
2164
2655
  zalo: "oaId"
2165
2656
  };
2166
2657
  try {
2167
- const V = await fetch(ie[B] ?? `${o}/v1/connect/${B}/select-page`, {
2658
+ const F = await fetch(ce[H] ?? `${o}/v1/connect/${H}/select-page`, {
2168
2659
  method: "POST",
2169
2660
  headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
2170
- body: JSON.stringify({ sessionId: P, [re[B] ?? "pageId"]: h })
2171
- }), ye = await V.json();
2172
- if (!V.ok || !ye.connectionId) throw new Error(ye.message ?? "Không thể kết nối");
2173
- if (q)
2661
+ body: JSON.stringify({ sessionId: N, [ye[H] ?? "pageId"]: c })
2662
+ }), he = await F.json();
2663
+ if (!F.ok || !he.connectionId) throw new Error(he.message ?? "Không thể kết nối");
2664
+ if (ae)
2174
2665
  try {
2175
- q.postMessage({ type: "channelhub:close-popup" }, "*");
2666
+ ae.postMessage({ type: "channelhub:close-popup" }, "*");
2176
2667
  } catch {
2177
2668
  }
2178
- z.current && (window.removeEventListener("message", z.current), z.current = null), await D(), S({ name: "list" });
2179
- } catch (V) {
2180
- I(V instanceof Error ? V.message : "Lỗi kết nối");
2669
+ V.current && (window.removeEventListener("message", V.current), V.current = null), await ne(), v({ name: "list" });
2670
+ } catch (F) {
2671
+ T(F instanceof Error ? F.message : "Lỗi kết nối");
2181
2672
  } finally {
2182
- R(!1);
2673
+ $(!1);
2183
2674
  }
2184
2675
  }
2185
- return /* @__PURE__ */ n("div", { style: a.root, children: [
2186
- W && /* @__PURE__ */ e("div", { style: a.errorBanner, children: W }),
2187
- f.name === "list" && /* @__PURE__ */ n(te, { children: [
2188
- /* @__PURE__ */ n("div", { style: a.header, children: [
2189
- /* @__PURE__ */ e("div", { style: a.headerLeft, children: /* @__PURE__ */ n("div", { children: [
2190
- /* @__PURE__ */ e("div", { style: a.title, children: "Kênh kết nối" }),
2191
- /* @__PURE__ */ e("div", { style: a.subtitle, children: m ? "Đang tải…" : `${s.filter((h) => h.status === "active").length} kênh đang hoạt động` })
2676
+ return /* @__PURE__ */ n("div", { style: s.root, children: [
2677
+ W && /* @__PURE__ */ e("div", { style: s.errorBanner, children: W }),
2678
+ w.name === "list" && /* @__PURE__ */ n(ie, { children: [
2679
+ /* @__PURE__ */ n("div", { style: s.header, children: [
2680
+ /* @__PURE__ */ e("div", { style: s.headerLeft, children: /* @__PURE__ */ n("div", { children: [
2681
+ /* @__PURE__ */ e("div", { style: s.title, children: "Kênh kết nối" }),
2682
+ /* @__PURE__ */ e("div", { style: s.subtitle, children: m ? "Đang tải…" : `${h.filter((c) => c.status === "active").length} kênh đang hoạt động` })
2192
2683
  ] }) }),
2193
- /* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => S({ name: "add" }), children: [
2194
- /* @__PURE__ */ e(Ze, {}),
2684
+ /* @__PURE__ */ n("button", { style: s.addBtn, onClick: () => v({ name: "add" }), children: [
2685
+ /* @__PURE__ */ e(mt, {}),
2195
2686
  /* @__PURE__ */ e("span", { children: "Thêm kênh" })
2196
2687
  ] })
2197
2688
  ] }),
2198
- /* @__PURE__ */ e("div", { style: a.divider }),
2199
- /* @__PURE__ */ e("div", { style: a.body, children: !m && s.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
2200
- /* @__PURE__ */ e("div", { style: { width: 64, height: 64, borderRadius: 16, background: "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 40 }) }),
2201
- /* @__PURE__ */ e("div", { style: a.emptyTitle, children: "Chưa có kênh nào được kết nối" }),
2202
- /* @__PURE__ */ e("div", { style: a.emptyDesc, children: "Kết nối Facebook, Zalo OA, Telegram hoặc Live Chat để bắt đầu nhận tin nhắn từ khách hàng." }),
2203
- /* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => S({ name: "add" }), children: [
2204
- /* @__PURE__ */ e(Ze, {}),
2689
+ /* @__PURE__ */ e("div", { style: s.divider }),
2690
+ /* @__PURE__ */ e("div", { style: s.body, children: !m && h.length === 0 ? /* @__PURE__ */ n("div", { style: s.empty, children: [
2691
+ /* @__PURE__ */ e("div", { style: { width: 64, height: 64, borderRadius: 16, background: "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(xe, { provider: "livechat", apiUrl: o, size: 40 }) }),
2692
+ /* @__PURE__ */ e("div", { style: s.emptyTitle, children: "Chưa có kênh nào được kết nối" }),
2693
+ /* @__PURE__ */ e("div", { style: s.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." }),
2694
+ /* @__PURE__ */ n("button", { style: s.emptyCta, onClick: () => v({ name: "add" }), children: [
2695
+ /* @__PURE__ */ e(mt, {}),
2205
2696
  "Kết nối kênh đầu tiên"
2206
2697
  ] })
2207
- ] }) : /* @__PURE__ */ e("div", { children: s.map((h) => /* @__PURE__ */ e(
2208
- an,
2698
+ ] }) : /* @__PURE__ */ e("div", { children: h.map((c) => /* @__PURE__ */ e(
2699
+ vn,
2209
2700
  {
2210
- conn: h,
2701
+ conn: c,
2211
2702
  apiUrl: o,
2212
- onDisconnect: () => void le(h.id, Ve(h))
2703
+ onDisconnect: () => void de(c.id, ct(c))
2213
2704
  },
2214
- h.id
2705
+ c.id
2215
2706
  )) }) })
2216
2707
  ] }),
2217
- f.name === "add" && /* @__PURE__ */ n(te, { children: [
2218
- /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2219
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2708
+ w.name === "add" && /* @__PURE__ */ n(ie, { children: [
2709
+ /* @__PURE__ */ e("div", { style: s.header, children: /* @__PURE__ */ n("div", { style: s.headerLeft, children: [
2710
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: () => v({ name: "list" }), children: /* @__PURE__ */ e(Be, {}) }),
2220
2711
  /* @__PURE__ */ n("div", { children: [
2221
- /* @__PURE__ */ e("div", { style: a.title, children: "Thêm kênh mới" }),
2222
- /* @__PURE__ */ e("div", { style: a.subtitle, children: "Chọn nền tảng bạn muốn kết nối" })
2712
+ /* @__PURE__ */ e("div", { style: s.title, children: "Thêm kênh mới" }),
2713
+ /* @__PURE__ */ e("div", { style: s.subtitle, children: "Chọn nền tảng bạn muốn kết nối" })
2223
2714
  ] })
2224
2715
  ] }) }),
2225
- /* @__PURE__ */ e("div", { style: a.divider }),
2226
- /* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: ln.map((h) => /* @__PURE__ */ e(
2227
- dn,
2716
+ /* @__PURE__ */ e("div", { style: s.divider }),
2717
+ /* @__PURE__ */ e("div", { style: s.body, children: /* @__PURE__ */ e("div", { style: s.providerGrid, children: kn.map((c) => /* @__PURE__ */ e(
2718
+ wn,
2228
2719
  {
2229
- provider: h,
2720
+ provider: c,
2230
2721
  apiUrl: o,
2231
2722
  onClick: () => {
2232
- h.type === "oauth" ? N(h.id) : h.id === "telegram" ? S({ name: "connect-telegram" }) : S({ name: "connect-livechat" });
2723
+ c.type === "oauth" ? Z(c.id) : c.id === "telegram" ? v({ name: "connect-telegram" }) : v({ name: "connect-livechat" });
2233
2724
  }
2234
2725
  },
2235
- h.id
2726
+ c.id
2236
2727
  )) }) })
2237
2728
  ] }),
2238
- f.name === "connect-telegram" && /* @__PURE__ */ n(te, { children: [
2239
- /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2240
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2241
- /* @__PURE__ */ e(ge, { provider: "telegram", apiUrl: o, size: 44 }),
2729
+ w.name === "connect-telegram" && /* @__PURE__ */ n(ie, { children: [
2730
+ /* @__PURE__ */ n("div", { style: s.connectHeader, children: [
2731
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: () => v({ name: "add" }), children: /* @__PURE__ */ e(Be, {}) }),
2732
+ /* @__PURE__ */ e(xe, { provider: "telegram", apiUrl: o, size: 44 }),
2242
2733
  /* @__PURE__ */ n("div", { children: [
2243
- /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Kết nối Telegram Bot" }),
2244
- /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhập Bot Token để bắt đầu nhận tin nhắn" })
2734
+ /* @__PURE__ */ e("div", { style: s.connectTitle, children: "Kết nối Telegram Bot" }),
2735
+ /* @__PURE__ */ e("div", { style: s.connectDesc, children: "Nhập Bot Token để bắt đầu nhận tin nhắn" })
2245
2736
  ] })
2246
2737
  ] }),
2247
- /* @__PURE__ */ n("div", { style: a.form, children: [
2248
- /* @__PURE__ */ n("div", { style: a.infoBox, children: [
2249
- /* @__PURE__ */ e(tn, {}),
2738
+ /* @__PURE__ */ n("div", { style: s.form, children: [
2739
+ /* @__PURE__ */ n("div", { style: s.infoBox, children: [
2740
+ /* @__PURE__ */ e(yn, {}),
2250
2741
  /* @__PURE__ */ n("div", { children: [
2251
2742
  "Tạo bot mới bằng cách nhắn tin cho ",
2252
2743
  /* @__PURE__ */ e("strong", { children: "@BotFather" }),
@@ -2255,113 +2746,113 @@ Hành động này không thể hoàn tác.`))
2255
2746
  " rồi sao chép token được cấp."
2256
2747
  ] })
2257
2748
  ] }),
2258
- /* @__PURE__ */ n("div", { style: a.field, children: [
2259
- /* @__PURE__ */ n("label", { style: a.label, children: [
2749
+ /* @__PURE__ */ n("div", { style: s.field, children: [
2750
+ /* @__PURE__ */ n("label", { style: s.label, children: [
2260
2751
  "Bot Token ",
2261
- /* @__PURE__ */ e("span", { style: a.labelHint, children: "bắt buộc" })
2752
+ /* @__PURE__ */ e("span", { style: s.labelHint, children: "bắt buộc" })
2262
2753
  ] }),
2263
2754
  /* @__PURE__ */ e(
2264
2755
  "input",
2265
2756
  {
2266
- style: a.input,
2757
+ style: s.input,
2267
2758
  type: "text",
2268
- value: E,
2269
- onChange: (h) => j(h.target.value),
2759
+ value: C,
2760
+ onChange: (c) => D(c.target.value),
2270
2761
  placeholder: "1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxx",
2271
2762
  autoComplete: "off",
2272
2763
  spellCheck: !1
2273
2764
  }
2274
2765
  ),
2275
- /* @__PURE__ */ n("div", { style: a.inputHint, children: [
2766
+ /* @__PURE__ */ n("div", { style: s.inputHint, children: [
2276
2767
  "Định dạng: ",
2277
2768
  /* @__PURE__ */ e("code", { children: "số:ký_tự" }),
2278
2769
  ", ví dụ: ",
2279
2770
  /* @__PURE__ */ e("code", { children: "1234567890:AAExxxxxxxx" })
2280
2771
  ] })
2281
2772
  ] }),
2282
- /* @__PURE__ */ n("div", { style: a.field, children: [
2283
- /* @__PURE__ */ n("label", { style: a.label, children: [
2773
+ /* @__PURE__ */ n("div", { style: s.field, children: [
2774
+ /* @__PURE__ */ n("label", { style: s.label, children: [
2284
2775
  "Tên hiển thị ",
2285
- /* @__PURE__ */ e("span", { style: a.labelHint, children: "tùy chọn" })
2776
+ /* @__PURE__ */ e("span", { style: s.labelHint, children: "tùy chọn" })
2286
2777
  ] }),
2287
2778
  /* @__PURE__ */ e(
2288
2779
  "input",
2289
2780
  {
2290
- style: a.input,
2781
+ style: s.input,
2291
2782
  type: "text",
2292
- value: A,
2293
- onChange: (h) => F(h.target.value),
2783
+ value: I,
2784
+ onChange: (c) => L(c.target.value),
2294
2785
  placeholder: "VD: Bot hỗ trợ cửa hàng"
2295
2786
  }
2296
2787
  )
2297
2788
  ] }),
2298
- /* @__PURE__ */ n("div", { style: a.formActions, children: [
2299
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2300
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void v(), children: H ? "Đang kết nối…" : "Kết nối Telegram" })
2789
+ /* @__PURE__ */ n("div", { style: s.formActions, children: [
2790
+ /* @__PURE__ */ e("button", { style: s.btnSecondary, onClick: () => v({ name: "add" }), children: "Hủy" }),
2791
+ /* @__PURE__ */ e("button", { style: s.btnPrimary, disabled: j, onClick: () => void z(), children: j ? "Đang kết nối…" : "Kết nối Telegram" })
2301
2792
  ] })
2302
2793
  ] })
2303
2794
  ] }),
2304
- f.name === "connect-livechat" && /* @__PURE__ */ n(te, { children: [
2305
- /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2306
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "add" }), children: /* @__PURE__ */ e(ve, {}) }),
2307
- /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2795
+ w.name === "connect-livechat" && /* @__PURE__ */ n(ie, { children: [
2796
+ /* @__PURE__ */ n("div", { style: s.connectHeader, children: [
2797
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: () => v({ name: "add" }), children: /* @__PURE__ */ e(Be, {}) }),
2798
+ /* @__PURE__ */ e(xe, { provider: "livechat", apiUrl: o, size: 44 }),
2308
2799
  /* @__PURE__ */ n("div", { children: [
2309
- /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Tạo Live Chat Widget" }),
2310
- /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhúng vào website để nhận tin nhắn từ khách hàng" })
2800
+ /* @__PURE__ */ e("div", { style: s.connectTitle, children: "Tạo Live Chat Widget" }),
2801
+ /* @__PURE__ */ e("div", { style: s.connectDesc, children: "Nhúng vào website để nhận tin nhắn từ khách hàng" })
2311
2802
  ] })
2312
2803
  ] }),
2313
- /* @__PURE__ */ n("div", { style: a.form, children: [
2314
- /* @__PURE__ */ n("div", { style: a.field, children: [
2315
- /* @__PURE__ */ n("label", { style: a.label, children: [
2804
+ /* @__PURE__ */ n("div", { style: s.form, children: [
2805
+ /* @__PURE__ */ n("div", { style: s.field, children: [
2806
+ /* @__PURE__ */ n("label", { style: s.label, children: [
2316
2807
  "Tên widget ",
2317
- /* @__PURE__ */ e("span", { style: a.labelHint, children: "bắt buộc" })
2808
+ /* @__PURE__ */ e("span", { style: s.labelHint, children: "bắt buộc" })
2318
2809
  ] }),
2319
2810
  /* @__PURE__ */ e(
2320
2811
  "input",
2321
2812
  {
2322
- style: a.input,
2813
+ style: s.input,
2323
2814
  type: "text",
2324
- value: K,
2325
- onChange: (h) => ne(h.target.value),
2815
+ value: P,
2816
+ onChange: (c) => q(c.target.value),
2326
2817
  placeholder: "VD: Hỗ trợ website hanashop.vn"
2327
2818
  }
2328
2819
  )
2329
2820
  ] }),
2330
- /* @__PURE__ */ n("div", { style: a.field, children: [
2331
- /* @__PURE__ */ n("label", { style: a.label, children: [
2821
+ /* @__PURE__ */ n("div", { style: s.field, children: [
2822
+ /* @__PURE__ */ n("label", { style: s.label, children: [
2332
2823
  "Tên miền được phép ",
2333
- /* @__PURE__ */ e("span", { style: a.labelHint, children: "tùy chọn" })
2824
+ /* @__PURE__ */ e("span", { style: s.labelHint, children: "tùy chọn" })
2334
2825
  ] }),
2335
2826
  /* @__PURE__ */ e(
2336
2827
  "textarea",
2337
2828
  {
2338
- style: { ...a.input, resize: "vertical", minHeight: 80, lineHeight: 1.5 },
2339
- value: U,
2340
- onChange: (h) => w(h.target.value),
2829
+ style: { ...s.input, resize: "vertical", minHeight: 80, lineHeight: 1.5 },
2830
+ value: te,
2831
+ onChange: (c) => Q(c.target.value),
2341
2832
  placeholder: `https://myshop.com
2342
2833
  https://www.myshop.com`,
2343
2834
  spellCheck: !1
2344
2835
  }
2345
2836
  ),
2346
- /* @__PURE__ */ e("div", { style: a.inputHint, children: "Mỗi domain một dòng. Để trống để cho phép tất cả." })
2837
+ /* @__PURE__ */ e("div", { style: s.inputHint, children: "Mỗi domain một dòng. Để trống để cho phép tất cả." })
2347
2838
  ] }),
2348
- /* @__PURE__ */ n("div", { style: a.formActions, children: [
2349
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "add" }), children: "Hủy" }),
2350
- /* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void Q(), children: H ? "Đang tạo…" : "Tạo widget" })
2839
+ /* @__PURE__ */ n("div", { style: s.formActions, children: [
2840
+ /* @__PURE__ */ e("button", { style: s.btnSecondary, onClick: () => v({ name: "add" }), children: "Hủy" }),
2841
+ /* @__PURE__ */ e("button", { style: s.btnPrimary, disabled: j, onClick: () => void oe(), children: j ? "Đang tạo…" : "Tạo widget" })
2351
2842
  ] })
2352
2843
  ] })
2353
2844
  ] }),
2354
- f.name === "livechat-result" && /* @__PURE__ */ n(te, { children: [
2355
- /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2356
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => S({ name: "list" }), children: /* @__PURE__ */ e(ve, {}) }),
2357
- /* @__PURE__ */ e(ge, { provider: "livechat", apiUrl: o, size: 44 }),
2845
+ w.name === "livechat-result" && /* @__PURE__ */ n(ie, { children: [
2846
+ /* @__PURE__ */ n("div", { style: s.connectHeader, children: [
2847
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: () => v({ name: "list" }), children: /* @__PURE__ */ e(Be, {}) }),
2848
+ /* @__PURE__ */ e(xe, { provider: "livechat", apiUrl: o, size: 44 }),
2358
2849
  /* @__PURE__ */ n("div", { children: [
2359
- /* @__PURE__ */ e("div", { style: a.connectTitle, children: "Widget đã được tạo!" }),
2360
- /* @__PURE__ */ e("div", { style: a.connectDesc, children: "Sao chép mã nhúng và dán vào website của bạn" })
2850
+ /* @__PURE__ */ e("div", { style: s.connectTitle, children: "Widget đã được tạo!" }),
2851
+ /* @__PURE__ */ e("div", { style: s.connectDesc, children: "Sao chép mã nhúng và dán vào website của bạn" })
2361
2852
  ] })
2362
2853
  ] }),
2363
- /* @__PURE__ */ n("div", { style: a.form, children: [
2364
- /* @__PURE__ */ n("div", { style: a.resultBanner, children: [
2854
+ /* @__PURE__ */ n("div", { style: s.form, children: [
2855
+ /* @__PURE__ */ n("div", { style: s.resultBanner, children: [
2365
2856
  /* @__PURE__ */ e("span", { style: { fontSize: 16, flexShrink: 0 }, children: "✅" }),
2366
2857
  /* @__PURE__ */ n("div", { children: [
2367
2858
  /* @__PURE__ */ e("strong", { children: "Tạo thành công!" }),
@@ -2371,58 +2862,58 @@ https://www.myshop.com`,
2371
2862
  ] })
2372
2863
  ] }),
2373
2864
  /* @__PURE__ */ n("div", { children: [
2374
- /* @__PURE__ */ e("div", { style: a.codeLabel, children: "Mã nhúng" }),
2375
- /* @__PURE__ */ n("div", { style: a.codeBlock, children: [
2376
- /* @__PURE__ */ e("pre", { style: a.codePre, children: f.embedScript }),
2377
- /* @__PURE__ */ e("button", { style: { ...a.copyBtn, ..._ ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => x(f.embedScript, "script"), children: _ ? /* @__PURE__ */ n(te, { children: [
2378
- /* @__PURE__ */ e(et, {}),
2865
+ /* @__PURE__ */ e("div", { style: s.codeLabel, children: "Mã nhúng" }),
2866
+ /* @__PURE__ */ n("div", { style: s.codeBlock, children: [
2867
+ /* @__PURE__ */ e("pre", { style: s.codePre, children: w.embedScript }),
2868
+ /* @__PURE__ */ e("button", { style: { ...s.copyBtn, ...B ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => O(w.embedScript, "script"), children: B ? /* @__PURE__ */ n(ie, { children: [
2869
+ /* @__PURE__ */ e(vt, {}),
2379
2870
  " Đã sao chép"
2380
- ] }) : /* @__PURE__ */ n(te, { children: [
2381
- /* @__PURE__ */ e(Qe, {}),
2871
+ ] }) : /* @__PURE__ */ n(ie, { children: [
2872
+ /* @__PURE__ */ e(xt, {}),
2382
2873
  " Sao chép"
2383
2874
  ] }) })
2384
2875
  ] })
2385
2876
  ] }),
2386
- f.identitySecret && /* @__PURE__ */ n("div", { children: [
2387
- /* @__PURE__ */ n("div", { style: a.codeLabel, children: [
2877
+ w.identitySecret && /* @__PURE__ */ n("div", { children: [
2878
+ /* @__PURE__ */ n("div", { style: s.codeLabel, children: [
2388
2879
  "Identity Secret ",
2389
- /* @__PURE__ */ e("span", { style: { ...a.labelHint, color: "#dc2626", fontWeight: 600 }, children: "Lưu ngay — chỉ hiển thị một lần" })
2880
+ /* @__PURE__ */ e("span", { style: { ...s.labelHint, color: "#dc2626", fontWeight: 600 }, children: "Lưu ngay — chỉ hiển thị một lần" })
2390
2881
  ] }),
2391
- /* @__PURE__ */ n("div", { style: a.secretRow, children: [
2392
- /* @__PURE__ */ e(en, {}),
2393
- /* @__PURE__ */ e("span", { style: a.secretLabel, children: "Secret:" }),
2394
- /* @__PURE__ */ e("span", { style: a.secretValue, children: f.identitySecret }),
2882
+ /* @__PURE__ */ n("div", { style: s.secretRow, children: [
2883
+ /* @__PURE__ */ e(gn, {}),
2884
+ /* @__PURE__ */ e("span", { style: s.secretLabel, children: "Secret:" }),
2885
+ /* @__PURE__ */ e("span", { style: s.secretValue, children: w.identitySecret }),
2395
2886
  /* @__PURE__ */ e(
2396
2887
  "button",
2397
2888
  {
2398
- onClick: () => x(f.identitySecret, "secret"),
2399
- style: { border: "none", background: "transparent", cursor: "pointer", color: L ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2400
- children: L ? /* @__PURE__ */ e(et, {}) : /* @__PURE__ */ e(Qe, {})
2889
+ onClick: () => O(w.identitySecret, "secret"),
2890
+ style: { border: "none", background: "transparent", cursor: "pointer", color: b ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
2891
+ children: b ? /* @__PURE__ */ e(vt, {}) : /* @__PURE__ */ e(xt, {})
2401
2892
  }
2402
2893
  )
2403
2894
  ] }),
2404
- /* @__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." })
2895
+ /* @__PURE__ */ e("div", { style: { ...s.inputHint, marginTop: 6 }, children: "Dùng secret này để xác thực danh tính người dùng (HMAC). Giữ bí mật — không chia sẻ nơi công khai." })
2405
2896
  ] }),
2406
- /* @__PURE__ */ n("div", { style: a.formActions, children: [
2407
- /* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => S({ name: "list" }), children: "Về danh sách" }),
2408
- /* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => S({ name: "add" }), children: "Thêm kênh khác" })
2897
+ /* @__PURE__ */ n("div", { style: s.formActions, children: [
2898
+ /* @__PURE__ */ e("button", { style: s.btnSecondary, onClick: () => v({ name: "list" }), children: "Về danh sách" }),
2899
+ /* @__PURE__ */ e("button", { style: s.btnPrimary, onClick: () => v({ name: "add" }), children: "Thêm kênh khác" })
2409
2900
  ] })
2410
2901
  ] })
2411
2902
  ] }),
2412
- f.name === "oauth-waiting" && /* @__PURE__ */ n(te, { children: [
2413
- /* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
2414
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2903
+ w.name === "oauth-waiting" && /* @__PURE__ */ n(ie, { children: [
2904
+ /* @__PURE__ */ e("div", { style: s.header, children: /* @__PURE__ */ n("div", { style: s.headerLeft, children: [
2905
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: ee, children: /* @__PURE__ */ e(Be, {}) }),
2415
2906
  /* @__PURE__ */ n("div", { children: [
2416
- /* @__PURE__ */ n("div", { style: a.title, children: [
2907
+ /* @__PURE__ */ n("div", { style: s.title, children: [
2417
2908
  "Đang xác thực ",
2418
- Be[f.provider]
2909
+ Oe[w.provider]
2419
2910
  ] }),
2420
- /* @__PURE__ */ e("div", { style: a.subtitle, children: "Vui lòng hoàn thành trong cửa sổ bật lên" })
2911
+ /* @__PURE__ */ e("div", { style: s.subtitle, children: "Vui lòng hoàn thành trong cửa sổ bật lên" })
2421
2912
  ] })
2422
2913
  ] }) }),
2423
- /* @__PURE__ */ n("div", { style: a.oauthWaiting, children: [
2914
+ /* @__PURE__ */ n("div", { style: s.oauthWaiting, children: [
2424
2915
  /* @__PURE__ */ n("div", { style: { position: "relative", width: 72, height: 72 }, children: [
2425
- /* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: Zt[f.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 48 }) }),
2916
+ /* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: un[w.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(xe, { provider: w.provider, apiUrl: o, size: 48 }) }),
2426
2917
  /* @__PURE__ */ n(
2427
2918
  "svg",
2428
2919
  {
@@ -2449,40 +2940,40 @@ https://www.myshop.com`,
2449
2940
  }
2450
2941
  )
2451
2942
  ] }),
2452
- /* @__PURE__ */ n("div", { style: a.oauthTitle, children: [
2943
+ /* @__PURE__ */ n("div", { style: s.oauthTitle, children: [
2453
2944
  "Đang chờ xác thực với ",
2454
- Be[f.provider]
2945
+ Oe[w.provider]
2455
2946
  ] }),
2456
- /* @__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." }),
2947
+ /* @__PURE__ */ e("div", { style: s.oauthDesc, children: "Một cửa sổ đăng nhập đã được mở. Vui lòng đăng nhập và cấp quyền truy cập để hoàn tất kết nối." }),
2457
2948
  /* @__PURE__ */ n("div", { style: { display: "flex", flexDirection: "column", gap: 8, alignItems: "flex-start", width: "100%", maxWidth: 280 }, children: [
2458
- /* @__PURE__ */ e(De, { done: !0, label: `Đã mở cửa sổ ${Be[f.provider]}` }),
2459
- /* @__PURE__ */ e(De, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2460
- /* @__PURE__ */ e(De, { label: "Lưu kết nối & quay về" })
2949
+ /* @__PURE__ */ e(Qe, { done: !0, label: `Đã mở cửa sổ ${Oe[w.provider]}` }),
2950
+ /* @__PURE__ */ e(Qe, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
2951
+ /* @__PURE__ */ e(Qe, { label: "Lưu kết nối & quay về" })
2461
2952
  ] }),
2462
- /* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: J, children: "Hủy và quay lại" })
2953
+ /* @__PURE__ */ e("button", { style: s.oauthCancel, onClick: ee, children: "Hủy và quay lại" })
2463
2954
  ] })
2464
2955
  ] }),
2465
- f.name === "oauth-select" && /* @__PURE__ */ n(te, { children: [
2466
- /* @__PURE__ */ n("div", { style: a.connectHeader, children: [
2467
- /* @__PURE__ */ e("button", { style: a.backBtn, onClick: J, children: /* @__PURE__ */ e(ve, {}) }),
2468
- /* @__PURE__ */ e(ge, { provider: f.provider, apiUrl: o, size: 44 }),
2956
+ w.name === "oauth-select" && /* @__PURE__ */ n(ie, { children: [
2957
+ /* @__PURE__ */ n("div", { style: s.connectHeader, children: [
2958
+ /* @__PURE__ */ e("button", { style: s.backBtn, onClick: ee, children: /* @__PURE__ */ e(Be, {}) }),
2959
+ /* @__PURE__ */ e(xe, { provider: w.provider, apiUrl: o, size: 44 }),
2469
2960
  /* @__PURE__ */ n("div", { children: [
2470
- /* @__PURE__ */ n("div", { style: a.connectTitle, children: [
2961
+ /* @__PURE__ */ n("div", { style: s.connectTitle, children: [
2471
2962
  "Chọn ",
2472
- f.provider === "instagram" ? "tài khoản" : "trang"
2963
+ w.provider === "instagram" ? "tài khoản" : "trang"
2473
2964
  ] }),
2474
- /* @__PURE__ */ n("div", { style: a.connectDesc, children: [
2965
+ /* @__PURE__ */ n("div", { style: s.connectDesc, children: [
2475
2966
  "Chọn ",
2476
- Be[f.provider],
2967
+ Oe[w.provider],
2477
2968
  " bạn muốn kết nối với ChannelHub"
2478
2969
  ] })
2479
2970
  ] })
2480
2971
  ] }),
2481
- /* @__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(
2972
+ /* @__PURE__ */ e("div", { style: s.body, children: w.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: w.pages.map((c) => /* @__PURE__ */ n(
2482
2973
  "button",
2483
2974
  {
2484
- disabled: H,
2485
- onClick: () => void he(h.id),
2975
+ disabled: j,
2976
+ onClick: () => void se(c.id),
2486
2977
  style: {
2487
2978
  display: "flex",
2488
2979
  alignItems: "center",
@@ -2491,26 +2982,26 @@ https://www.myshop.com`,
2491
2982
  borderRadius: 12,
2492
2983
  border: "1.5px solid #e2e8f0",
2493
2984
  background: "#fff",
2494
- cursor: H ? "not-allowed" : "pointer",
2495
- opacity: H ? 0.6 : 1,
2985
+ cursor: j ? "not-allowed" : "pointer",
2986
+ opacity: j ? 0.6 : 1,
2496
2987
  textAlign: "left",
2497
2988
  fontFamily: "inherit",
2498
2989
  transition: "border-color .15s, background .15s"
2499
2990
  },
2500
2991
  children: [
2501
2992
  /* @__PURE__ */ n("div", { children: [
2502
- /* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: h.name }),
2503
- /* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: h.id })
2993
+ /* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: c.name }),
2994
+ /* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: c.id })
2504
2995
  ] }),
2505
- /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: H ? "Đang kết nối…" : "Chọn →" })
2996
+ /* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: j ? "Đang kết nối…" : "Chọn →" })
2506
2997
  ]
2507
2998
  },
2508
- h.id
2999
+ c.id
2509
3000
  )) }) })
2510
3001
  ] })
2511
3002
  ] });
2512
3003
  }
2513
- function rn(t) {
3004
+ function mn(t) {
2514
3005
  const i = t.metadata;
2515
3006
  if (typeof i.pictureUrl == "string") return i.pictureUrl;
2516
3007
  if (t.provider === "facebook")
@@ -2521,38 +3012,38 @@ function rn(t) {
2521
3012
  }
2522
3013
  return null;
2523
3014
  }
2524
- function on({ conn: t, apiUrl: i, size: r = 40 }) {
2525
- const [o, s] = y(!1), C = rn(t), m = Math.round(r * 0.28);
2526
- return C && !o ? /* @__PURE__ */ e(
3015
+ function xn({ conn: t, apiUrl: i, size: r = 40 }) {
3016
+ const [o, h] = y(!1), S = mn(t), m = Math.round(r * 0.28);
3017
+ return S && !o ? /* @__PURE__ */ e(
2527
3018
  "img",
2528
3019
  {
2529
- src: C,
2530
- alt: Ve(t),
3020
+ src: S,
3021
+ alt: ct(t),
2531
3022
  referrerPolicy: "no-referrer",
2532
- onError: () => s(!0),
3023
+ onError: () => h(!0),
2533
3024
  style: { width: r, height: r, borderRadius: m, objectFit: "cover", flexShrink: 0, display: "block" }
2534
3025
  }
2535
- ) : /* @__PURE__ */ e(ge, { provider: t.provider, apiUrl: i, size: r });
3026
+ ) : /* @__PURE__ */ e(xe, { provider: t.provider, apiUrl: i, size: r });
2536
3027
  }
2537
- function an({ conn: t, apiUrl: i, onDisconnect: r }) {
2538
- const [o, s] = y(!1);
2539
- return /* @__PURE__ */ n("div", { style: a.channelItem, children: [
2540
- /* @__PURE__ */ e(on, { conn: t, apiUrl: i, size: 40 }),
2541
- /* @__PURE__ */ n("div", { style: a.channelInfo, children: [
2542
- /* @__PURE__ */ e("div", { style: a.channelName, children: Ve(t) }),
2543
- /* @__PURE__ */ e("div", { style: a.channelMeta, children: Qt(t) })
3028
+ function vn({ conn: t, apiUrl: i, onDisconnect: r }) {
3029
+ const [o, h] = y(!1);
3030
+ return /* @__PURE__ */ n("div", { style: s.channelItem, children: [
3031
+ /* @__PURE__ */ e(xn, { conn: t, apiUrl: i, size: 40 }),
3032
+ /* @__PURE__ */ n("div", { style: s.channelInfo, children: [
3033
+ /* @__PURE__ */ e("div", { style: s.channelName, children: ct(t) }),
3034
+ /* @__PURE__ */ e("div", { style: s.channelMeta, children: fn(t) })
2544
3035
  ] }),
2545
- /* @__PURE__ */ n("div", { style: a.channelActions, children: [
2546
- /* @__PURE__ */ e("span", { style: t.status === "active" ? a.badgeActive : a.badgeInactive, children: t.status === "active" ? "Hoạt động" : t.status }),
3036
+ /* @__PURE__ */ n("div", { style: s.channelActions, children: [
3037
+ /* @__PURE__ */ e("span", { style: t.status === "active" ? s.badgeActive : s.badgeInactive, children: t.status === "active" ? "Hoạt động" : t.status }),
2547
3038
  /* @__PURE__ */ e(
2548
3039
  "button",
2549
3040
  {
2550
3041
  style: {
2551
- ...a.disconnectBtn,
3042
+ ...s.disconnectBtn,
2552
3043
  ...o ? { background: "#fef2f2", borderColor: "#fca5a5", color: "#dc2626" } : {}
2553
3044
  },
2554
- onMouseEnter: () => s(!0),
2555
- onMouseLeave: () => s(!1),
3045
+ onMouseEnter: () => h(!0),
3046
+ onMouseLeave: () => h(!1),
2556
3047
  onClick: r,
2557
3048
  children: "Ngắt kết nối"
2558
3049
  }
@@ -2560,36 +3051,36 @@ function an({ conn: t, apiUrl: i, onDisconnect: r }) {
2560
3051
  ] })
2561
3052
  ] });
2562
3053
  }
2563
- const ln = [
3054
+ const kn = [
2564
3055
  { id: "facebook", name: "Facebook", desc: "Fanpage & Messenger", type: "oauth" },
2565
3056
  { id: "zalo", name: "Zalo OA", desc: "Official Account", type: "oauth" },
2566
3057
  { id: "instagram", name: "Instagram", desc: "DM & Comments", type: "oauth" },
2567
3058
  { id: "telegram", name: "Telegram", desc: "Bot token", type: "token" },
2568
3059
  { id: "livechat", name: "Live Chat", desc: "Website widget", type: "livechat" }
2569
3060
  ];
2570
- function dn({ provider: t, apiUrl: i, onClick: r }) {
2571
- const [o, s] = y(!1);
3061
+ function wn({ provider: t, apiUrl: i, onClick: r }) {
3062
+ const [o, h] = y(!1);
2572
3063
  return /* @__PURE__ */ n(
2573
3064
  "div",
2574
3065
  {
2575
3066
  style: {
2576
- ...a.providerCard,
3067
+ ...s.providerCard,
2577
3068
  ...o ? { background: "#fff", borderColor: "#e2e8f0", boxShadow: "0 2px 8px rgba(0,0,0,.07)", transform: "translateY(-1px)" } : {}
2578
3069
  },
2579
3070
  onClick: r,
2580
- onMouseEnter: () => s(!0),
2581
- onMouseLeave: () => s(!1),
3071
+ onMouseEnter: () => h(!0),
3072
+ onMouseLeave: () => h(!1),
2582
3073
  children: [
2583
- /* @__PURE__ */ e(ge, { provider: t.id, apiUrl: i, size: 44 }),
3074
+ /* @__PURE__ */ e(xe, { provider: t.id, apiUrl: i, size: 44 }),
2584
3075
  /* @__PURE__ */ n("div", { children: [
2585
- /* @__PURE__ */ e("div", { style: a.providerName, children: t.name }),
2586
- /* @__PURE__ */ e("div", { style: a.providerDesc, children: t.desc })
3076
+ /* @__PURE__ */ e("div", { style: s.providerName, children: t.name }),
3077
+ /* @__PURE__ */ e("div", { style: s.providerDesc, children: t.desc })
2587
3078
  ] })
2588
3079
  ]
2589
3080
  }
2590
3081
  );
2591
3082
  }
2592
- function De({ done: t, active: i, label: r }) {
3083
+ function Qe({ done: t, active: i, label: r }) {
2593
3084
  return /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 10, fontSize: 13, color: t ? "#059669" : i ? "#0f172a" : "#94a3b8" }, children: [
2594
3085
  /* @__PURE__ */ e("div", { style: {
2595
3086
  width: 10,
@@ -2602,9 +3093,264 @@ function De({ done: t, active: i, label: r }) {
2602
3093
  r
2603
3094
  ] });
2604
3095
  }
2605
- console.log("[ChannelHub] widget v0.1.7 loaded");
3096
+ function Sn(t) {
3097
+ return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
3098
+ }
3099
+ function Cn(t) {
3100
+ if (!t) return "";
3101
+ const i = new Date(t);
3102
+ return i.toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? i.toLocaleTimeString("vi-VN", { hour: "2-digit", minute: "2-digit" }) : i.toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit" });
3103
+ }
3104
+ function Bn({
3105
+ apiUrl: t,
3106
+ token: i,
3107
+ theme: r,
3108
+ locale: o = "vi",
3109
+ icon: h,
3110
+ onConversationSelect: S
3111
+ }) {
3112
+ const m = (r == null ? void 0 : r.primaryColor) ?? "#2563eb", M = typeof h == "function" ? h({ size: 20, color: "currentColor" }) : h ?? /* @__PURE__ */ e(pt, { size: 20, strokeWidth: 1.8 }), w = J(new it(t, i)), [v, W] = y(!1), [T, j] = y([]), $ = J(null), C = J(null), D = T.filter((B) => (B.unreadCount ?? 0) > 0), I = D.reduce((B, x) => B + (x.unreadCount ?? 0), 0), L = we(async () => {
3113
+ try {
3114
+ const B = await w.current.listConversations();
3115
+ j(B.items);
3116
+ } catch {
3117
+ }
3118
+ }, []);
3119
+ X(() => (L(), w.current.connectSSE((x) => {
3120
+ (x === "message.new" || x === "conversation.updated") && L();
3121
+ })), [L]), X(() => {
3122
+ if (!v) return;
3123
+ const B = (x) => {
3124
+ var b, E;
3125
+ (b = $.current) != null && b.contains(x.target) || (E = C.current) != null && E.contains(x.target) || W(!1);
3126
+ };
3127
+ return document.addEventListener("mousedown", B), () => document.removeEventListener("mousedown", B);
3128
+ }, [v]);
3129
+ const P = async (B) => {
3130
+ if (W(!1), S == null || S(B.id, B), (B.unreadCount ?? 0) > 0)
3131
+ try {
3132
+ await w.current.markRead(B.id), j(
3133
+ (x) => x.map((b) => b.id === B.id ? { ...b, unreadCount: 0 } : b)
3134
+ );
3135
+ } catch {
3136
+ }
3137
+ }, q = o === "en" ? `${I} unread message${I !== 1 ? "s" : ""}` : `${I} tin nhắn chưa đọc`, te = o === "en" ? "No unread messages" : "Không có tin nhắn mới", Q = o === "en" ? "Messages" : "Tin nhắn";
3138
+ return /* @__PURE__ */ n("div", { style: { position: "relative", display: "inline-block", fontFamily: (r == null ? void 0 : r.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif" }, children: [
3139
+ /* @__PURE__ */ n(
3140
+ "button",
3141
+ {
3142
+ ref: $,
3143
+ "aria-label": q,
3144
+ "aria-haspopup": "true",
3145
+ "aria-expanded": v,
3146
+ onClick: () => W((B) => !B),
3147
+ style: {
3148
+ position: "relative",
3149
+ display: "inline-grid",
3150
+ placeItems: "center",
3151
+ width: 40,
3152
+ height: 40,
3153
+ border: 0,
3154
+ borderRadius: "50%",
3155
+ background: v ? `${m}18` : "transparent",
3156
+ color: v ? m : "#6b7280",
3157
+ cursor: "pointer",
3158
+ transition: "background 150ms ease, color 150ms ease"
3159
+ },
3160
+ children: [
3161
+ M,
3162
+ I > 0 && /* @__PURE__ */ e(
3163
+ "span",
3164
+ {
3165
+ "aria-hidden": "true",
3166
+ style: {
3167
+ position: "absolute",
3168
+ top: 4,
3169
+ right: 4,
3170
+ minWidth: 16,
3171
+ height: 16,
3172
+ borderRadius: 999,
3173
+ background: "#ef4444",
3174
+ color: "#fff",
3175
+ fontSize: 10,
3176
+ fontWeight: 800,
3177
+ lineHeight: "16px",
3178
+ textAlign: "center",
3179
+ padding: "0 4px",
3180
+ border: "2px solid #fff",
3181
+ boxSizing: "border-box"
3182
+ },
3183
+ children: I > 99 ? "99+" : I
3184
+ }
3185
+ )
3186
+ ]
3187
+ }
3188
+ ),
3189
+ v && /* @__PURE__ */ n(
3190
+ "div",
3191
+ {
3192
+ ref: C,
3193
+ role: "dialog",
3194
+ "aria-label": Q,
3195
+ style: {
3196
+ position: "absolute",
3197
+ top: "calc(100% + 8px)",
3198
+ right: 0,
3199
+ zIndex: 9999,
3200
+ width: 360,
3201
+ maxHeight: 480,
3202
+ background: "#fff",
3203
+ border: "1px solid #e7ebf2",
3204
+ borderRadius: 14,
3205
+ boxShadow: "0 12px 40px rgba(23,32,51,.14)",
3206
+ overflow: "hidden",
3207
+ display: "flex",
3208
+ flexDirection: "column"
3209
+ },
3210
+ children: [
3211
+ /* @__PURE__ */ n("div", { style: {
3212
+ display: "flex",
3213
+ alignItems: "center",
3214
+ justifyContent: "space-between",
3215
+ padding: "14px 16px 10px",
3216
+ borderBottom: "1px solid #e7ebf2"
3217
+ }, children: [
3218
+ /* @__PURE__ */ e("span", { style: { fontSize: 16, fontWeight: 700, color: "#172033" }, children: Q }),
3219
+ I > 0 && /* @__PURE__ */ n("span", { style: {
3220
+ fontSize: 11,
3221
+ fontWeight: 600,
3222
+ background: `${m}14`,
3223
+ color: m,
3224
+ borderRadius: 999,
3225
+ padding: "2px 8px"
3226
+ }, children: [
3227
+ I,
3228
+ " ",
3229
+ o === "en" ? "unread" : "chưa đọc"
3230
+ ] })
3231
+ ] }),
3232
+ /* @__PURE__ */ e("div", { style: { overflowY: "auto", flex: 1 }, children: D.length === 0 ? /* @__PURE__ */ n("div", { style: {
3233
+ display: "flex",
3234
+ flexDirection: "column",
3235
+ alignItems: "center",
3236
+ gap: 8,
3237
+ padding: "40px 24px",
3238
+ color: "#9aa5b5"
3239
+ }, children: [
3240
+ /* @__PURE__ */ e(pt, { size: 28, strokeWidth: 1.5 }),
3241
+ /* @__PURE__ */ e("span", { style: { fontSize: 13 }, children: te })
3242
+ ] }) : D.map((B) => /* @__PURE__ */ e(
3243
+ In,
3244
+ {
3245
+ conversation: B,
3246
+ primary: m,
3247
+ apiUrl: t,
3248
+ onSelect: P
3249
+ },
3250
+ B.id
3251
+ )) })
3252
+ ]
3253
+ }
3254
+ )
3255
+ ] });
3256
+ }
3257
+ function In({
3258
+ conversation: t,
3259
+ primary: i,
3260
+ apiUrl: r,
3261
+ onSelect: o
3262
+ }) {
3263
+ const [h, S] = y(!1), m = t.contactName ?? t.providerConversationKey, M = t.unreadCount ?? 0;
3264
+ return /* @__PURE__ */ n(
3265
+ "button",
3266
+ {
3267
+ onClick: () => o(t),
3268
+ onMouseEnter: () => S(!0),
3269
+ onMouseLeave: () => S(!1),
3270
+ style: {
3271
+ display: "flex",
3272
+ width: "100%",
3273
+ gap: 12,
3274
+ padding: "10px 16px",
3275
+ border: 0,
3276
+ borderBottom: "1px solid #f1f5f9",
3277
+ background: h ? "#f7f9fc" : M > 0 ? "#f0f4ff" : "#fff",
3278
+ textAlign: "left",
3279
+ cursor: "pointer",
3280
+ transition: "background 100ms ease",
3281
+ alignItems: "center"
3282
+ },
3283
+ children: [
3284
+ /* @__PURE__ */ n("span", { style: { position: "relative", flex: "0 0 auto", width: 42, height: 42 }, children: [
3285
+ /* @__PURE__ */ e(
3286
+ dt,
3287
+ {
3288
+ src: t.contactPictureUrl,
3289
+ fallback: Sn(m),
3290
+ style: {
3291
+ width: 42,
3292
+ height: 42,
3293
+ borderRadius: "50%",
3294
+ objectFit: "cover",
3295
+ display: "grid",
3296
+ placeItems: "center",
3297
+ fontSize: 13,
3298
+ fontWeight: 800,
3299
+ background: `${i}18`,
3300
+ color: i
3301
+ }
3302
+ }
3303
+ ),
3304
+ void 0
3305
+ ] }),
3306
+ /* @__PURE__ */ n("span", { style: { flex: 1, minWidth: 0 }, children: [
3307
+ /* @__PURE__ */ n("span", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 6 }, children: [
3308
+ /* @__PURE__ */ e("span", { style: {
3309
+ fontSize: 13,
3310
+ fontWeight: M > 0 ? 700 : 500,
3311
+ color: "#172033",
3312
+ overflow: "hidden",
3313
+ textOverflow: "ellipsis",
3314
+ whiteSpace: "nowrap"
3315
+ }, children: m }),
3316
+ /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, flexShrink: 0 }, children: [
3317
+ /* @__PURE__ */ e("time", { style: { fontSize: 11, color: "#9aa5b5", whiteSpace: "nowrap" }, children: Cn(t.lastMessageAt) }),
3318
+ M > 0 && /* @__PURE__ */ e("span", { style: {
3319
+ display: "inline-grid",
3320
+ placeItems: "center",
3321
+ minWidth: 18,
3322
+ height: 18,
3323
+ borderRadius: 999,
3324
+ background: "#ef4444",
3325
+ color: "#fff",
3326
+ fontSize: 10,
3327
+ fontWeight: 800,
3328
+ padding: "0 4px"
3329
+ }, children: M > 99 ? "99+" : M })
3330
+ ] })
3331
+ ] }),
3332
+ /* @__PURE__ */ n("span", { style: {
3333
+ display: "block",
3334
+ marginTop: 2,
3335
+ fontSize: 12,
3336
+ color: M > 0 ? "#374151" : "#9aa5b5",
3337
+ fontWeight: M > 0 ? 500 : 400,
3338
+ overflow: "hidden",
3339
+ textOverflow: "ellipsis",
3340
+ whiteSpace: "nowrap"
3341
+ }, children: [
3342
+ t.lastMessageDirection === "outbound" && /* @__PURE__ */ e("span", { style: { color: "#9aa5b5" }, children: "Bạn: " }),
3343
+ t.lastMessageText || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" })
3344
+ ] })
3345
+ ] })
3346
+ ]
3347
+ }
3348
+ );
3349
+ }
3350
+ console.log("[ChannelHub] widget v0.1.9 loaded");
2606
3351
  export {
2607
- un as ChannelHubChannels,
2608
- Mt as ChannelHubClient,
2609
- pn as ChannelHubInbox
3352
+ $n as ChannelHubChannels,
3353
+ it as ChannelHubClient,
3354
+ Wn as ChannelHubInbox,
3355
+ Bn as ChannelHubNotificationBell
2610
3356
  };