@channelhub/widget 0.0.0-stage → 0.1.4

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