@channelhub/widget 0.1.3 → 0.1.5

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