@channelhub/widget 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChannelHubChannels.d.ts +15 -0
- package/dist/ChannelHubChannels.d.ts.map +1 -0
- package/dist/ChannelHubInbox.d.ts +3 -0
- package/dist/ChannelHubInbox.d.ts.map +1 -0
- package/dist/LiveChatWidget.d.ts +12 -0
- package/dist/LiveChatWidget.d.ts.map +1 -0
- package/dist/api.d.ts +20 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/channels/ProviderLogo.d.ts +8 -0
- package/dist/channels/ProviderLogo.d.ts.map +1 -0
- package/dist/components/ui/avatar.d.ts +8 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/button.d.ts +5 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/index.d.ts +6 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +6 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/textarea.d.ts +3 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/facebook_icon.avif +0 -0
- package/dist/index.cjs +99 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1975 -0
- package/dist/instagram_icon.avif +0 -0
- package/dist/livechat-standalone.d.ts +23 -0
- package/dist/livechat-standalone.d.ts.map +1 -0
- package/dist/standalone.d.ts +22 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/telegram_icon.avif +0 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web.avif +0 -0
- package/dist/zalo_icon.avif +0 -0
- package/package.json +45 -3
- package/public/facebook_icon.avif +0 -0
- package/public/instagram_icon.avif +0 -0
- package/public/telegram_icon.avif +0 -0
- package/public/web.avif +0 -0
- package/public/zalo_icon.avif +0 -0
- package/src/ChannelHubChannels.tsx +941 -0
- package/src/ChannelHubInbox.tsx +769 -0
- package/src/LiveChatWidget.tsx +380 -0
- package/src/api.ts +84 -0
- package/src/assets/facebook_icon.avif +0 -0
- package/src/assets/instagram_icon.avif +0 -0
- package/src/assets/telegram_icon.avif +0 -0
- package/src/assets/web.avif +0 -0
- package/src/assets/zalo_icon.avif +0 -0
- package/src/assets.d.ts +4 -0
- package/src/channels/ProviderLogo.tsx +59 -0
- package/src/components/ui/avatar.tsx +2 -0
- package/src/components/ui/button.tsx +4 -0
- package/src/components/ui/index.ts +5 -0
- package/src/components/ui/input.tsx +2 -0
- package/src/components/ui/scroll-area.tsx +5 -0
- package/src/components/ui/textarea.tsx +2 -0
- package/src/index.ts +8 -0
- package/src/livechat-standalone.tsx +75 -0
- package/src/standalone.tsx +68 -0
- package/src/types.ts +65 -0
- package/tsconfig.json +14 -0
- package/vite.config.ts +76 -0
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1975 @@
|
|
|
1
|
+
import { jsx as e, jsxs as n, Fragment as K } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as fe, createElement as ve, createContext as Ee, useRef as Q, useState as k, useMemo as pe, useCallback as Ce, useEffect as q, useImperativeHandle as nt, useContext as ke } from "react";
|
|
3
|
+
import { createPortal as Pe } from "react-dom";
|
|
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 it = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), Fe = (...t) => t.filter((i, r, o) => !!i && i.trim() !== "" && o.indexOf(i) === r).join(" ").trim();
|
|
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 rt = {
|
|
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 ot = fe(
|
|
35
|
+
({
|
|
36
|
+
color: t = "currentColor",
|
|
37
|
+
size: i = 24,
|
|
38
|
+
strokeWidth: r = 2,
|
|
39
|
+
absoluteStrokeWidth: o,
|
|
40
|
+
className: p = "",
|
|
41
|
+
children: f,
|
|
42
|
+
iconNode: b,
|
|
43
|
+
...B
|
|
44
|
+
}, h) => ve(
|
|
45
|
+
"svg",
|
|
46
|
+
{
|
|
47
|
+
ref: h,
|
|
48
|
+
...rt,
|
|
49
|
+
width: i,
|
|
50
|
+
height: i,
|
|
51
|
+
stroke: t,
|
|
52
|
+
strokeWidth: o ? Number(r) * 24 / Number(i) : r,
|
|
53
|
+
className: Fe("lucide", p),
|
|
54
|
+
...B
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
...b.map(([y, C]) => ve(y, C)),
|
|
58
|
+
...Array.isArray(f) ? f : [f]
|
|
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 D = (t, i) => {
|
|
69
|
+
const r = fe(
|
|
70
|
+
({ className: o, ...p }, f) => ve(ot, {
|
|
71
|
+
ref: f,
|
|
72
|
+
iconNode: i,
|
|
73
|
+
className: Fe(`lucide-${it(t)}`, o),
|
|
74
|
+
...p
|
|
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 He = D("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 at = D("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 lt = D("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 dt = D("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 ct = D("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 Ne = D("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 st = D("Inbox", [
|
|
143
|
+
["polyline", { points: "22 12 16 12 14 15 10 15 8 12 2 12", key: "o97t9d" }],
|
|
144
|
+
[
|
|
145
|
+
"path",
|
|
146
|
+
{
|
|
147
|
+
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",
|
|
148
|
+
key: "oot6mr"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
]);
|
|
152
|
+
/**
|
|
153
|
+
* @license lucide-react v0.468.0 - ISC
|
|
154
|
+
*
|
|
155
|
+
* This source code is licensed under the ISC license.
|
|
156
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
157
|
+
*/
|
|
158
|
+
const ht = D("Info", [
|
|
159
|
+
["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
|
|
160
|
+
["path", { d: "M12 16v-4", key: "1dtifu" }],
|
|
161
|
+
["path", { d: "M12 8h.01", key: "e9boi3" }]
|
|
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 pt = D("LoaderCircle", [
|
|
170
|
+
["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]
|
|
171
|
+
]);
|
|
172
|
+
/**
|
|
173
|
+
* @license lucide-react v0.468.0 - ISC
|
|
174
|
+
*
|
|
175
|
+
* This source code is licensed under the ISC license.
|
|
176
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
177
|
+
*/
|
|
178
|
+
const ut = D("Paperclip", [
|
|
179
|
+
["path", { d: "M13.234 20.252 21 12.3", key: "1cbrk9" }],
|
|
180
|
+
[
|
|
181
|
+
"path",
|
|
182
|
+
{
|
|
183
|
+
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",
|
|
184
|
+
key: "1pkts6"
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
]);
|
|
188
|
+
/**
|
|
189
|
+
* @license lucide-react v0.468.0 - ISC
|
|
190
|
+
*
|
|
191
|
+
* This source code is licensed under the ISC license.
|
|
192
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
193
|
+
*/
|
|
194
|
+
const ft = D("Play", [
|
|
195
|
+
["polygon", { points: "6 3 20 12 6 21 6 3", key: "1oa8hb" }]
|
|
196
|
+
]);
|
|
197
|
+
/**
|
|
198
|
+
* @license lucide-react v0.468.0 - ISC
|
|
199
|
+
*
|
|
200
|
+
* This source code is licensed under the ISC license.
|
|
201
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
202
|
+
*/
|
|
203
|
+
const $e = D("Search", [
|
|
204
|
+
["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }],
|
|
205
|
+
["path", { d: "m21 21-4.3-4.3", key: "1qie3q" }]
|
|
206
|
+
]);
|
|
207
|
+
/**
|
|
208
|
+
* @license lucide-react v0.468.0 - ISC
|
|
209
|
+
*
|
|
210
|
+
* This source code is licensed under the ISC license.
|
|
211
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
212
|
+
*/
|
|
213
|
+
const gt = D("Send", [
|
|
214
|
+
[
|
|
215
|
+
"path",
|
|
216
|
+
{
|
|
217
|
+
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",
|
|
218
|
+
key: "1ffxy3"
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
["path", { d: "m21.854 2.147-10.94 10.939", key: "12cjpa" }]
|
|
222
|
+
]);
|
|
223
|
+
/**
|
|
224
|
+
* @license lucide-react v0.468.0 - ISC
|
|
225
|
+
*
|
|
226
|
+
* This source code is licensed under the ISC license.
|
|
227
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
228
|
+
*/
|
|
229
|
+
const yt = D("SlidersHorizontal", [
|
|
230
|
+
["line", { x1: "21", x2: "14", y1: "4", y2: "4", key: "obuewd" }],
|
|
231
|
+
["line", { x1: "10", x2: "3", y1: "4", y2: "4", key: "1q6298" }],
|
|
232
|
+
["line", { x1: "21", x2: "12", y1: "12", y2: "12", key: "1iu8h1" }],
|
|
233
|
+
["line", { x1: "8", x2: "3", y1: "12", y2: "12", key: "ntss68" }],
|
|
234
|
+
["line", { x1: "21", x2: "16", y1: "20", y2: "20", key: "14d8ph" }],
|
|
235
|
+
["line", { x1: "12", x2: "3", y1: "20", y2: "20", key: "m0wm8r" }],
|
|
236
|
+
["line", { x1: "14", x2: "14", y1: "2", y2: "6", key: "14e1ph" }],
|
|
237
|
+
["line", { x1: "8", x2: "8", y1: "10", y2: "14", key: "1i6ji0" }],
|
|
238
|
+
["line", { x1: "16", x2: "16", y1: "18", y2: "22", key: "1lctlv" }]
|
|
239
|
+
]);
|
|
240
|
+
/**
|
|
241
|
+
* @license lucide-react v0.468.0 - ISC
|
|
242
|
+
*
|
|
243
|
+
* This source code is licensed under the ISC license.
|
|
244
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
245
|
+
*/
|
|
246
|
+
const ue = D("X", [
|
|
247
|
+
["path", { d: "M18 6 6 18", key: "1bl5f8" }],
|
|
248
|
+
["path", { d: "m6 6 12 12", key: "d8bk6v" }]
|
|
249
|
+
]);
|
|
250
|
+
class mt {
|
|
251
|
+
constructor(i, r) {
|
|
252
|
+
this.apiUrl = i, this.token = r;
|
|
253
|
+
}
|
|
254
|
+
async request(i, r, o) {
|
|
255
|
+
const p = {
|
|
256
|
+
authorization: `Bearer ${this.token}`,
|
|
257
|
+
...o ? {} : { "content-type": "application/json" },
|
|
258
|
+
...r == null ? void 0 : r.headers
|
|
259
|
+
}, f = await fetch(`${this.apiUrl}${i}`, {
|
|
260
|
+
...r,
|
|
261
|
+
headers: p
|
|
262
|
+
}), b = await f.json().catch(() => null);
|
|
263
|
+
if (!f.ok) throw new Error((b == null ? void 0 : b.message) ?? `Request failed (${f.status})`);
|
|
264
|
+
return b;
|
|
265
|
+
}
|
|
266
|
+
listConnections() {
|
|
267
|
+
return this.request("/v1/connections");
|
|
268
|
+
}
|
|
269
|
+
listConversations(i) {
|
|
270
|
+
return this.request(`/v1/conversations${i ? `?cursor=${encodeURIComponent(i)}` : ""}`);
|
|
271
|
+
}
|
|
272
|
+
listMessages(i, r) {
|
|
273
|
+
return this.request(`/v1/conversations/${encodeURIComponent(i)}/messages${r ? `?cursor=${encodeURIComponent(r)}` : ""}`);
|
|
274
|
+
}
|
|
275
|
+
getMessage(i) {
|
|
276
|
+
return this.request(`/v1/messages/${encodeURIComponent(i)}`);
|
|
277
|
+
}
|
|
278
|
+
sendMessage(i, r, o) {
|
|
279
|
+
return this.request(`/v1/conversations/${encodeURIComponent(i)}/messages`, {
|
|
280
|
+
method: "POST",
|
|
281
|
+
headers: { "idempotency-key": crypto.randomUUID() },
|
|
282
|
+
body: JSON.stringify({ text: r, attachments: o })
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
async markRead(i) {
|
|
286
|
+
const r = await fetch(`${this.apiUrl}/v1/conversations/${encodeURIComponent(i)}/mark-read`, {
|
|
287
|
+
method: "POST",
|
|
288
|
+
headers: { authorization: `Bearer ${this.token}` }
|
|
289
|
+
});
|
|
290
|
+
if (!r.ok && r.status !== 204) throw new Error(`markRead failed (${r.status})`);
|
|
291
|
+
}
|
|
292
|
+
async uploadAttachment(i) {
|
|
293
|
+
const r = new FormData();
|
|
294
|
+
return r.append("file", i), this.request(
|
|
295
|
+
"/v1/attachments",
|
|
296
|
+
{ method: "POST", body: r },
|
|
297
|
+
!0
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
connectSSE(i) {
|
|
301
|
+
const r = `${this.apiUrl}/v1/events?token=${encodeURIComponent(this.token)}`;
|
|
302
|
+
let o, p, f = !1;
|
|
303
|
+
const b = () => {
|
|
304
|
+
o = new EventSource(r), o.addEventListener("message.new", (B) => {
|
|
305
|
+
i("message.new", JSON.parse(B.data));
|
|
306
|
+
}), o.addEventListener("conversation.updated", (B) => {
|
|
307
|
+
i("conversation.updated", JSON.parse(B.data));
|
|
308
|
+
}), o.onerror = () => {
|
|
309
|
+
o.close(), f || (p = setTimeout(b, 5e3));
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
return b(), () => {
|
|
313
|
+
f = !0, clearTimeout(p), o == null || o.close();
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function Ke({ src: t, alt: i = "", fallback: r, style: o }) {
|
|
318
|
+
return t ? /* @__PURE__ */ e("img", { src: t, alt: i, style: { width: 38, height: 38, borderRadius: "50%", objectFit: "cover", ...o } }) : /* @__PURE__ */ e("span", { style: { display: "grid", placeItems: "center", width: 38, height: 38, borderRadius: "50%", ...o }, children: r });
|
|
319
|
+
}
|
|
320
|
+
function bt({ variant: t = "ghost", style: i, ...r }) {
|
|
321
|
+
return /* @__PURE__ */ e("button", { ...r, style: { display: "inline-flex", alignItems: "center", justifyContent: "center", border: t === "outline" ? "1px solid #e7ebf2" : 0, borderRadius: 8, cursor: "pointer", font: "inherit", background: t === "default" ? "#2563eb" : "transparent", ...i } });
|
|
322
|
+
}
|
|
323
|
+
function xt({ style: t, ...i }) {
|
|
324
|
+
return /* @__PURE__ */ e("input", { ...i, style: { width: "100%", minWidth: 0, border: 0, outline: 0, background: "transparent", font: "inherit", ...t } });
|
|
325
|
+
}
|
|
326
|
+
const qe = fe(
|
|
327
|
+
({ children: t, style: i }, r) => /* @__PURE__ */ e("div", { ref: r, style: { minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", ...i }, children: t })
|
|
328
|
+
);
|
|
329
|
+
function vt({ style: t, ...i }) {
|
|
330
|
+
return /* @__PURE__ */ e("textarea", { ...i, style: { display: "block", width: "100%", minWidth: 0, boxSizing: "border-box", resize: "vertical", border: 0, outline: 0, background: "transparent", font: "inherit", ...t } });
|
|
331
|
+
}
|
|
332
|
+
const d = { ink: "#172033", muted: "#718096", line: "#e7ebf2", surface: "#f7f9fc", white: "#fff" }, Ie = Ee(""), Ve = Ee("");
|
|
333
|
+
function kt() {
|
|
334
|
+
try {
|
|
335
|
+
const t = new AudioContext(), i = t.createOscillator(), r = t.createGain();
|
|
336
|
+
i.connect(r), r.connect(t.destination), i.type = "sine", i.frequency.setValueAtTime(880, t.currentTime), i.frequency.exponentialRampToValueAtTime(660, t.currentTime + 0.12), r.gain.setValueAtTime(0.25, t.currentTime), r.gain.exponentialRampToValueAtTime(1e-3, t.currentTime + 0.35), i.start(t.currentTime), i.stop(t.currentTime + 0.35);
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function wt(t) {
|
|
341
|
+
if (!(t != null && t.metadata)) return;
|
|
342
|
+
const i = t.metadata, r = i.pageName ?? i.displayName ?? i.username ?? i.name;
|
|
343
|
+
return typeof r == "string" && r ? r : void 0;
|
|
344
|
+
}
|
|
345
|
+
function Ge(t) {
|
|
346
|
+
return t === "facebook" ? "Facebook Messenger" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo OA" : "Channel";
|
|
347
|
+
}
|
|
348
|
+
function je(t) {
|
|
349
|
+
return t === "facebook" ? "Facebook" : t === "instagram" ? "Instagram" : t === "telegram" ? "Telegram" : t === "zalo" ? "Zalo" : String(t ?? "");
|
|
350
|
+
}
|
|
351
|
+
const St = (t) => {
|
|
352
|
+
var r;
|
|
353
|
+
const i = {
|
|
354
|
+
"application/pdf": "PDF",
|
|
355
|
+
"video/mp4": "Video MP4",
|
|
356
|
+
"audio/mpeg": "Audio MP3",
|
|
357
|
+
"audio/ogg": "Audio OGG",
|
|
358
|
+
"application/octet-stream": "Tệp đính kèm"
|
|
359
|
+
};
|
|
360
|
+
return t ? i[t] ?? ((r = t.split("/")[1]) == null ? void 0 : r.toUpperCase()) ?? "Tệp" : "Tệp đính kèm";
|
|
361
|
+
};
|
|
362
|
+
function Me({ status: t }) {
|
|
363
|
+
return t === "read" ? /* @__PURE__ */ e(He, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(He, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(at, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
|
|
364
|
+
}
|
|
365
|
+
const Gt = fe(function({ apiUrl: i, token: r, theme: o, height: p, defaultConversationId: f, disableAttachments: b, disableNotificationSound: B, hideKeyboardHint: h, locale: y = "vi", onNewMessage: C, onConversationSelect: S }, H) {
|
|
366
|
+
var Te, Be, Re, We, Le;
|
|
367
|
+
const I = Q(new mt(i, r)), [W, V] = k([]), [G, E] = k([]), [P, J] = k(), [w, F] = k(), N = Q(void 0), [g, z] = k(""), [L, R] = k({ provider: "all", unreadOnly: !1 }), [O, x] = k(!1), X = Q(null), ee = Q(null), [Y, re] = k(null), [te, ne] = k(!0), [l, m] = k(""), [v, $] = k(!1), T = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", U = pe(() => new Map(G.map((s) => [s.id, s])), [G]), j = Q(null), [se, Je] = k(0), _e = pe(() => {
|
|
368
|
+
const s = new Set(G.map((u) => u.provider));
|
|
369
|
+
return ["facebook", "instagram", "telegram", "zalo"].filter((u) => s.has(u));
|
|
370
|
+
}, [G]), Ze = pe(() => {
|
|
371
|
+
var u;
|
|
372
|
+
const s = {};
|
|
373
|
+
for (const A of W) {
|
|
374
|
+
const M = ((u = U.get(A.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
|
|
375
|
+
s[M] = (s[M] ?? 0) + 1;
|
|
376
|
+
}
|
|
377
|
+
return s;
|
|
378
|
+
}, [W, U]), _ = Ce(async (s) => {
|
|
379
|
+
try {
|
|
380
|
+
const u = await I.current.listConversations(s);
|
|
381
|
+
V((A) => s ? [...A, ...u.items] : u.items), J(u.nextCursor), !s && u.items.length && F((A) => A ?? (f ? u.items.find((M) => M.id === f) ?? u.items[0] : u.items[0])), m("");
|
|
382
|
+
} catch (u) {
|
|
383
|
+
m(u instanceof Error ? u.message : "Không tải được hội thoại");
|
|
384
|
+
} finally {
|
|
385
|
+
ne(!1);
|
|
386
|
+
}
|
|
387
|
+
}, [f]);
|
|
388
|
+
q(() => (I.current.listConnections().then(E).catch(() => {
|
|
389
|
+
}), _(), I.current.connectSSE((u, A) => {
|
|
390
|
+
if (u === "message.new" || u === "conversation.updated") {
|
|
391
|
+
if (_(), u === "message.new") {
|
|
392
|
+
const M = typeof A == "object" && A ? A : {}, le = M.conversationId ? String(M.conversationId) : "", he = M.messageId ? String(M.messageId) : "";
|
|
393
|
+
if ((M.direction ? String(M.direction) : "") === "inbound" && !B && kt(), le && le === N.current && he && j.current) {
|
|
394
|
+
const et = j.current;
|
|
395
|
+
I.current.getMessage(he).then((tt) => {
|
|
396
|
+
et(tt);
|
|
397
|
+
}).catch(() => {
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
C == null || C(le || N.current || "");
|
|
401
|
+
}
|
|
402
|
+
} else u === "message.status_updated" && Je((M) => M + 1);
|
|
403
|
+
})), [_, C]), q(() => {
|
|
404
|
+
N.current = w == null ? void 0 : w.id;
|
|
405
|
+
}, [w]), q(() => {
|
|
406
|
+
w != null && w.unreadCount && I.current.markRead(w.id).then(() => _()).catch(() => {
|
|
407
|
+
});
|
|
408
|
+
}, [w == null ? void 0 : w.id]), q(() => {
|
|
409
|
+
if (!O) return;
|
|
410
|
+
function s(u) {
|
|
411
|
+
var A, M;
|
|
412
|
+
(A = X.current) != null && A.contains(u.target) || (M = ee.current) != null && M.contains(u.target) || x(!1);
|
|
413
|
+
}
|
|
414
|
+
return document.addEventListener("mousedown", s), () => document.removeEventListener("mousedown", s);
|
|
415
|
+
}, [O]);
|
|
416
|
+
const ge = pe(() => {
|
|
417
|
+
const s = g.toLowerCase().trim();
|
|
418
|
+
return W.filter((u) => {
|
|
419
|
+
var me;
|
|
420
|
+
const A = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), M = ((me = U.get(u.connectionId)) == null ? void 0 : me.provider) ?? "unknown", le = L.provider === "all" || M === L.provider, he = !L.unreadOnly || (u.unreadCount ?? 0) > 0;
|
|
421
|
+
return le && he && (!s || A.includes(s));
|
|
422
|
+
});
|
|
423
|
+
}, [W, U, L, g]), ye = L.provider !== "all" || L.unreadOnly, oe = y === "en" ? {
|
|
424
|
+
today: "TODAY",
|
|
425
|
+
loadOlder: "↑ Load older messages",
|
|
426
|
+
loading: "Loading messages…",
|
|
427
|
+
noMessages: "No messages in this conversation.",
|
|
428
|
+
searchPlaceholder: "Search conversations…",
|
|
429
|
+
unreadOnly: "Unread only",
|
|
430
|
+
sendPlaceholder: "Write a message…",
|
|
431
|
+
send: "Send",
|
|
432
|
+
all: "All"
|
|
433
|
+
} : {
|
|
434
|
+
today: "HÔM NAY",
|
|
435
|
+
loadOlder: "↑ Tải tin cũ hơn",
|
|
436
|
+
loading: "Đang tải tin nhắn…",
|
|
437
|
+
noMessages: "Chưa có tin nhắn trong hội thoại này.",
|
|
438
|
+
searchPlaceholder: "Tìm kiếm hội thoại…",
|
|
439
|
+
unreadOnly: "Chưa đọc",
|
|
440
|
+
sendPlaceholder: "Viết tin nhắn…",
|
|
441
|
+
send: "Gửi",
|
|
442
|
+
all: "Tất cả"
|
|
443
|
+
};
|
|
444
|
+
nt(H, () => ({
|
|
445
|
+
openConversation: (s) => {
|
|
446
|
+
const u = W.find((A) => A.id === s);
|
|
447
|
+
u && F(u);
|
|
448
|
+
},
|
|
449
|
+
refresh: () => void _()
|
|
450
|
+
}), [W, _]);
|
|
451
|
+
const Qe = {
|
|
452
|
+
...c.frame,
|
|
453
|
+
height: p ?? 620,
|
|
454
|
+
...p ? { maxHeight: "none" } : {},
|
|
455
|
+
fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif",
|
|
456
|
+
borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px",
|
|
457
|
+
gridTemplateColumns: v ? "minmax(260px, 300px) minmax(0, 1fr) 260px" : "minmax(260px, 300px) minmax(0, 1fr)",
|
|
458
|
+
transition: "grid-template-columns 220ms ease"
|
|
459
|
+
};
|
|
460
|
+
return te ? /* @__PURE__ */ n("div", { style: { ...c.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
|
|
461
|
+
/* @__PURE__ */ e(we, {}),
|
|
462
|
+
" Đang tải hộp thư…"
|
|
463
|
+
] }) : l && !W.length ? /* @__PURE__ */ n("div", { style: { ...c.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
|
|
464
|
+
/* @__PURE__ */ e(ct, { size: 16, strokeWidth: 2 }),
|
|
465
|
+
" ",
|
|
466
|
+
l,
|
|
467
|
+
/* @__PURE__ */ e("button", { style: c.retry, onClick: () => {
|
|
468
|
+
ne(!0), _();
|
|
469
|
+
}, children: "Thử lại" })
|
|
470
|
+
] }) : /* @__PURE__ */ e(Ie.Provider, { value: i, children: /* @__PURE__ */ e(Ve.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: Qe, onFocusCapture: () => {
|
|
471
|
+
const s = window.scrollY;
|
|
472
|
+
requestAnimationFrame(() => {
|
|
473
|
+
window.scrollY !== s && window.scrollTo({ top: s, behavior: "instant" });
|
|
474
|
+
});
|
|
475
|
+
}, children: [
|
|
476
|
+
/* @__PURE__ */ n("aside", { style: c.sidebar, children: [
|
|
477
|
+
/* @__PURE__ */ n("div", { style: c.brand, children: [
|
|
478
|
+
/* @__PURE__ */ e("div", { style: { ...c.brandMark, background: T, overflow: "hidden", padding: 0 }, children: (Te = o == null ? void 0 : o.branding) != null && Te.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((Be = o == null ? void 0 : o.branding) == null ? void 0 : Be.mark) ?? "C" }),
|
|
479
|
+
/* @__PURE__ */ n("div", { children: [
|
|
480
|
+
/* @__PURE__ */ e("strong", { children: ((Re = o == null ? void 0 : o.branding) == null ? void 0 : Re.name) ?? "Hộp thư" }),
|
|
481
|
+
!((We = o == null ? void 0 : o.branding) != null && We.name) && /* @__PURE__ */ e("span", { style: c.eyebrow, children: "CHANNELHUB" })
|
|
482
|
+
] }),
|
|
483
|
+
/* @__PURE__ */ e(bt, { "aria-label": "Tùy chọn", style: c.iconButton, children: /* @__PURE__ */ e(Ne, { size: 16, strokeWidth: 2 }) })
|
|
484
|
+
] }),
|
|
485
|
+
/* @__PURE__ */ n("div", { style: c.search, children: [
|
|
486
|
+
/* @__PURE__ */ e($e, { size: 16, strokeWidth: 2 }),
|
|
487
|
+
/* @__PURE__ */ e(xt, { "aria-label": oe.searchPlaceholder, value: g, onChange: (s) => z(s.target.value), placeholder: oe.searchPlaceholder }),
|
|
488
|
+
g && /* @__PURE__ */ e("button", { style: c.clear, onClick: () => z(""), "aria-label": "Xóa tìm kiếm", children: "×" })
|
|
489
|
+
] }),
|
|
490
|
+
ye && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
|
|
491
|
+
L.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: T, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
|
|
492
|
+
/* @__PURE__ */ e(ce, { provider: L.provider }),
|
|
493
|
+
je(L.provider),
|
|
494
|
+
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: T, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => R((s) => ({ ...s, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(ue, { size: 10 }) })
|
|
495
|
+
] }),
|
|
496
|
+
L.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: T, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
|
|
497
|
+
oe.unreadOnly,
|
|
498
|
+
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: T, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => R((s) => ({ ...s, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(ue, { size: 10 }) })
|
|
499
|
+
] }),
|
|
500
|
+
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: d.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => R({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
|
|
501
|
+
] }),
|
|
502
|
+
/* @__PURE__ */ n("div", { style: c.listHeader, children: [
|
|
503
|
+
/* @__PURE__ */ n("span", { children: [
|
|
504
|
+
ge.length,
|
|
505
|
+
" hội thoại"
|
|
506
|
+
] }),
|
|
507
|
+
/* @__PURE__ */ e(
|
|
508
|
+
"button",
|
|
509
|
+
{
|
|
510
|
+
ref: X,
|
|
511
|
+
style: { ...c.iconButton, background: ye ? `${T}14` : "transparent", color: ye ? T : d.muted },
|
|
512
|
+
"aria-label": "Bộ lọc",
|
|
513
|
+
onClick: () => {
|
|
514
|
+
var s;
|
|
515
|
+
if (!O) {
|
|
516
|
+
const u = (s = X.current) == null ? void 0 : s.getBoundingClientRect();
|
|
517
|
+
u && re({ top: u.bottom + 6, left: u.left });
|
|
518
|
+
}
|
|
519
|
+
x((u) => !u);
|
|
520
|
+
},
|
|
521
|
+
children: /* @__PURE__ */ e(yt, { size: 15, strokeWidth: 2 })
|
|
522
|
+
}
|
|
523
|
+
)
|
|
524
|
+
] }),
|
|
525
|
+
O && Y && Pe(
|
|
526
|
+
/* @__PURE__ */ n(
|
|
527
|
+
"div",
|
|
528
|
+
{
|
|
529
|
+
ref: ee,
|
|
530
|
+
style: { position: "fixed", top: Y.top, left: Y.left, zIndex: 9999, background: d.white, border: `1px solid ${d.line}`, borderRadius: 10, padding: "12px 14px", boxShadow: "0 8px 24px rgba(23,32,51,.14)", minWidth: 210, fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif", fontSize: 13 },
|
|
531
|
+
children: [
|
|
532
|
+
/* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
|
|
533
|
+
["all", ..._e].map((s) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: L.provider === s ? `${T}0f` : "transparent" }, children: [
|
|
534
|
+
/* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: L.provider === s, onChange: () => R((u) => ({ ...u, provider: s })), style: { accentColor: T } }),
|
|
535
|
+
s === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
|
|
536
|
+
oe.all,
|
|
537
|
+
" (",
|
|
538
|
+
W.length,
|
|
539
|
+
")"
|
|
540
|
+
] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: d.ink }, children: [
|
|
541
|
+
/* @__PURE__ */ e(ce, { provider: s }),
|
|
542
|
+
je(s),
|
|
543
|
+
" ",
|
|
544
|
+
/* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
|
|
545
|
+
"(",
|
|
546
|
+
Ze[s] ?? 0,
|
|
547
|
+
")"
|
|
548
|
+
] })
|
|
549
|
+
] })
|
|
550
|
+
] }, s)),
|
|
551
|
+
/* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${d.line}`, margin: "8px 0 6px" } }),
|
|
552
|
+
/* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: L.unreadOnly ? `${T}0f` : "transparent" }, children: [
|
|
553
|
+
/* @__PURE__ */ e("input", { type: "checkbox", checked: L.unreadOnly, onChange: (s) => R((u) => ({ ...u, unreadOnly: s.target.checked })), style: { accentColor: T } }),
|
|
554
|
+
/* @__PURE__ */ e("span", { style: { color: d.ink }, children: oe.unreadOnly })
|
|
555
|
+
] })
|
|
556
|
+
]
|
|
557
|
+
}
|
|
558
|
+
),
|
|
559
|
+
document.body
|
|
560
|
+
),
|
|
561
|
+
/* @__PURE__ */ n(qe, { style: c.conversationList, children: [
|
|
562
|
+
ge.map((s) => {
|
|
563
|
+
var u;
|
|
564
|
+
return /* @__PURE__ */ e(Ct, { conversation: s, provider: (u = U.get(s.connectionId)) == null ? void 0 : u.provider, selected: (w == null ? void 0 : w.id) === s.id, primary: T, onSelect: () => {
|
|
565
|
+
F(s), S == null || S(s.id), I.current.markRead(s.id).then(() => _()).catch(() => {
|
|
566
|
+
});
|
|
567
|
+
} }, s.id);
|
|
568
|
+
}),
|
|
569
|
+
!ge.length && /* @__PURE__ */ n("div", { style: c.emptySmall, children: [
|
|
570
|
+
/* @__PURE__ */ e("div", { style: c.emptyIcon, children: /* @__PURE__ */ e($e, { size: 16, strokeWidth: 2 }) }),
|
|
571
|
+
/* @__PURE__ */ e("strong", { children: "Không tìm thấy" }),
|
|
572
|
+
/* @__PURE__ */ e("span", { children: "Thử từ khóa hoặc bộ lọc khác." })
|
|
573
|
+
] }),
|
|
574
|
+
P && /* @__PURE__ */ e("button", { style: c.loadMore, onClick: () => void _(P), children: "Xem thêm hội thoại" })
|
|
575
|
+
] })
|
|
576
|
+
] }),
|
|
577
|
+
/* @__PURE__ */ e("main", { style: c.main, children: w ? /* @__PURE__ */ e(
|
|
578
|
+
It,
|
|
579
|
+
{
|
|
580
|
+
conversation: w,
|
|
581
|
+
provider: (Le = U.get(w.connectionId)) == null ? void 0 : Le.provider,
|
|
582
|
+
connection: U.get(w.connectionId),
|
|
583
|
+
client: I.current,
|
|
584
|
+
primary: T,
|
|
585
|
+
error: l,
|
|
586
|
+
onRegisterAppend: (s) => {
|
|
587
|
+
j.current = s;
|
|
588
|
+
},
|
|
589
|
+
refreshKey: se,
|
|
590
|
+
infoOpen: v,
|
|
591
|
+
onToggleInfo: () => $((s) => !s),
|
|
592
|
+
t: oe,
|
|
593
|
+
disableAttachments: b,
|
|
594
|
+
hideKeyboardHint: h
|
|
595
|
+
},
|
|
596
|
+
w.id
|
|
597
|
+
) : /* @__PURE__ */ e(Rt, {}) }),
|
|
598
|
+
v && w && /* @__PURE__ */ e(
|
|
599
|
+
Tt,
|
|
600
|
+
{
|
|
601
|
+
conversation: w,
|
|
602
|
+
connection: U.get(w.connectionId),
|
|
603
|
+
primary: T,
|
|
604
|
+
onClose: () => $(!1)
|
|
605
|
+
}
|
|
606
|
+
)
|
|
607
|
+
] }) }) });
|
|
608
|
+
});
|
|
609
|
+
function Ct({ conversation: t, provider: i, selected: r, primary: o, onSelect: p }) {
|
|
610
|
+
const [f, b] = k(!1), B = t.contactName ?? t.subject ?? t.providerConversationKey, h = t.unreadCount ?? 0, y = t.lastMessageText ?? "", C = t.lastMessageDirection === "outbound" ? "Bạn: " : "", S = y.length > 60 ? y.slice(0, 60) + "…" : y, H = y ? C + S : "";
|
|
611
|
+
let I = "transparent";
|
|
612
|
+
r ? I = "#eef2ff" : f ? I = "#f7f9fc" : h > 0 && (I = "#f0f4ff");
|
|
613
|
+
const W = {
|
|
614
|
+
...c.row,
|
|
615
|
+
background: I,
|
|
616
|
+
...r ? { boxShadow: `inset 3px 0 0 ${o}` } : h > 0 && !f ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
|
|
617
|
+
};
|
|
618
|
+
return /* @__PURE__ */ n(
|
|
619
|
+
"button",
|
|
620
|
+
{
|
|
621
|
+
onClick: p,
|
|
622
|
+
style: W,
|
|
623
|
+
onMouseEnter: () => b(!0),
|
|
624
|
+
onMouseLeave: () => b(!1),
|
|
625
|
+
children: [
|
|
626
|
+
/* @__PURE__ */ e(Xe, { name: B, color: o, image: t.contactPictureUrl, provider: i }),
|
|
627
|
+
/* @__PURE__ */ n("span", { style: c.rowBody, children: [
|
|
628
|
+
/* @__PURE__ */ n("span", { style: c.rowTop, children: [
|
|
629
|
+
/* @__PURE__ */ e("strong", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontWeight: h > 0 ? 700 : 500 }, children: B }),
|
|
630
|
+
/* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 4, flexShrink: 0 }, children: [
|
|
631
|
+
/* @__PURE__ */ e("time", { style: { color: d.muted, fontSize: 11, whiteSpace: "nowrap" }, children: Se(t.lastMessageAt) }),
|
|
632
|
+
h > 0 && /* @__PURE__ */ e("span", { "aria-label": `${h} tin nhắn chưa đọc`, style: c.unreadBadge, children: h > 99 ? "99+" : h })
|
|
633
|
+
] })
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ e("span", { style: { ...c.rowBottom, color: h > 0 && !r ? "#4a5568" : d.muted }, children: /* @__PURE__ */ e("span", { style: { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", maxWidth: "100%" }, children: H || /* @__PURE__ */ e("span", { style: { opacity: 0.5 }, children: "Chưa có tin nhắn" }) }) })
|
|
636
|
+
] })
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
function It({ conversation: t, provider: i, connection: r, client: o, primary: p, error: f, onRegisterAppend: b, refreshKey: B, infoOpen: h, onToggleInfo: y, t: C, disableAttachments: S, hideKeyboardHint: H }) {
|
|
642
|
+
const [I, W] = k([]), [V, G] = k(), [E, P] = k(""), [J, w] = k(!0), [F, N] = k(!1), [g, z] = k(""), L = Q(null), R = t.contactName ?? t.subject ?? t.providerConversationKey, O = Q(null), [x, X] = k(null);
|
|
643
|
+
q(() => () => {
|
|
644
|
+
x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl);
|
|
645
|
+
}, [x == null ? void 0 : x.objectUrl]);
|
|
646
|
+
const ee = Q(!0), Y = Ce(async (l, m) => {
|
|
647
|
+
m || (ee.current = !l);
|
|
648
|
+
try {
|
|
649
|
+
const v = await o.listMessages(t.id, l);
|
|
650
|
+
W(($) => l ? [...v.items, ...$] : v.items), G(v.nextCursor);
|
|
651
|
+
} catch (v) {
|
|
652
|
+
z(v instanceof Error ? v.message : "Không tải được tin nhắn");
|
|
653
|
+
} finally {
|
|
654
|
+
m || w(!1);
|
|
655
|
+
}
|
|
656
|
+
}, [o, t.id]);
|
|
657
|
+
q(() => {
|
|
658
|
+
w(!0), Y();
|
|
659
|
+
}, [Y]), q(() => {
|
|
660
|
+
B && Y(void 0, !0);
|
|
661
|
+
}, [B]), q(() => {
|
|
662
|
+
ee.current && requestAnimationFrame(() => {
|
|
663
|
+
const l = L.current;
|
|
664
|
+
l && (l.scrollTop = l.scrollHeight);
|
|
665
|
+
});
|
|
666
|
+
}, [I]), q(() => (b == null || b((l) => {
|
|
667
|
+
ee.current = !0, W((m) => m.some((v) => v.id === l.id) ? m : [...m, l]);
|
|
668
|
+
}), () => {
|
|
669
|
+
b == null || b(null);
|
|
670
|
+
}), [b]);
|
|
671
|
+
async function re(l) {
|
|
672
|
+
var $;
|
|
673
|
+
const m = ($ = l.target.files) == null ? void 0 : $[0];
|
|
674
|
+
if (!m) return;
|
|
675
|
+
l.target.value = "";
|
|
676
|
+
const v = URL.createObjectURL(m);
|
|
677
|
+
X({ file: m, uploading: !0, objectUrl: v });
|
|
678
|
+
try {
|
|
679
|
+
const T = await o.uploadAttachment(m);
|
|
680
|
+
X({ file: m, uploading: !1, url: T.url, mimeType: T.mimeType, attachmentType: T.attachmentType, objectUrl: v });
|
|
681
|
+
} catch {
|
|
682
|
+
URL.revokeObjectURL(v), X(null), z("Không tải lên được tệp đính kèm");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
async function te(l) {
|
|
686
|
+
l.preventDefault();
|
|
687
|
+
const m = E.trim(), v = x != null && x.url ? [{ url: x.url, mimeType: x.mimeType ?? "application/octet-stream", type: x.attachmentType }] : [];
|
|
688
|
+
if (!(!m && !v.length || F)) {
|
|
689
|
+
N(!0), z("");
|
|
690
|
+
try {
|
|
691
|
+
await o.sendMessage(t.id, m || void 0, v.length ? v : void 0), x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), P(""), X(null), await Y();
|
|
692
|
+
} catch ($) {
|
|
693
|
+
z($ instanceof Error ? $.message : "Không gửi được tin nhắn");
|
|
694
|
+
} finally {
|
|
695
|
+
N(!1);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const ne = !F && (E.trim().length > 0 || (x == null ? void 0 : x.url) != null && !x.uploading);
|
|
700
|
+
return /* @__PURE__ */ n("section", { style: c.chat, children: [
|
|
701
|
+
/* @__PURE__ */ n("header", { style: c.chatHeader, children: [
|
|
702
|
+
/* @__PURE__ */ e(Xe, { name: R, color: p, image: t.contactPictureUrl, provider: i }),
|
|
703
|
+
/* @__PURE__ */ n("div", { style: c.contact, children: [
|
|
704
|
+
/* @__PURE__ */ e("strong", { style: c.contactName, children: R }),
|
|
705
|
+
/* @__PURE__ */ e("span", { style: c.contactMeta, children: wt(r) ?? Ge(i) })
|
|
706
|
+
] }),
|
|
707
|
+
/* @__PURE__ */ n("div", { style: c.headerActions, children: [
|
|
708
|
+
/* @__PURE__ */ e("button", { style: c.iconButton, "aria-label": "Thêm tùy chọn", children: /* @__PURE__ */ e(Ne, { size: 16, strokeWidth: 2 }) }),
|
|
709
|
+
/* @__PURE__ */ e(
|
|
710
|
+
"button",
|
|
711
|
+
{
|
|
712
|
+
style: {
|
|
713
|
+
...c.iconButton,
|
|
714
|
+
background: h ? `${p}14` : "transparent",
|
|
715
|
+
color: h ? p : d.muted
|
|
716
|
+
},
|
|
717
|
+
"aria-label": "Thông tin liên hệ",
|
|
718
|
+
onClick: y,
|
|
719
|
+
children: /* @__PURE__ */ e(ht, { size: 16, strokeWidth: 2 })
|
|
720
|
+
}
|
|
721
|
+
)
|
|
722
|
+
] })
|
|
723
|
+
] }),
|
|
724
|
+
/* @__PURE__ */ n(qe, { ref: L, style: c.messageArea, children: [
|
|
725
|
+
/* @__PURE__ */ e("div", { style: c.day, children: C.today }),
|
|
726
|
+
V && /* @__PURE__ */ e("button", { onClick: () => void Y(V), style: c.historyButton, children: C.loadOlder }),
|
|
727
|
+
J && /* @__PURE__ */ n("div", { style: c.messageHint, children: [
|
|
728
|
+
/* @__PURE__ */ e(we, {}),
|
|
729
|
+
" ",
|
|
730
|
+
C.loading
|
|
731
|
+
] }),
|
|
732
|
+
!J && !I.length && /* @__PURE__ */ e("div", { style: c.messageHint, children: C.noMessages }),
|
|
733
|
+
I.map((l) => /* @__PURE__ */ e(zt, { message: l, primary: p }, l.id))
|
|
734
|
+
] }),
|
|
735
|
+
/* @__PURE__ */ n("form", { onSubmit: te, style: c.composer, children: [
|
|
736
|
+
/* @__PURE__ */ n("div", { style: c.composerBox, children: [
|
|
737
|
+
x && /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "8px 12px", borderBottom: `1px solid ${d.line}`, fontSize: 12 }, children: [
|
|
738
|
+
x.uploading ? /* @__PURE__ */ n(K, { children: [
|
|
739
|
+
/* @__PURE__ */ e(we, {}),
|
|
740
|
+
/* @__PURE__ */ e("span", { style: { color: d.muted }, children: "Đang tải lên…" })
|
|
741
|
+
] }) : x.attachmentType === "image" && x.objectUrl ? /* @__PURE__ */ e("img", { src: x.objectUrl, alt: "", style: { height: 48, width: 48, objectFit: "cover", borderRadius: 6 } }) : /* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
|
|
742
|
+
"📎 ",
|
|
743
|
+
x.file.name,
|
|
744
|
+
" (",
|
|
745
|
+
Math.round(x.file.size / 1024),
|
|
746
|
+
" KB)"
|
|
747
|
+
] }),
|
|
748
|
+
!x.uploading && /* @__PURE__ */ e("button", { type: "button", onClick: () => {
|
|
749
|
+
x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), X(null);
|
|
750
|
+
}, style: { marginLeft: "auto", border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 16 }, "aria-label": "Xóa tệp đính kèm", children: "✕" })
|
|
751
|
+
] }),
|
|
752
|
+
/* @__PURE__ */ e(vt, { "aria-label": "Soạn tin nhắn", rows: 1, value: E, onChange: (l) => P(l.target.value), onKeyDown: (l) => {
|
|
753
|
+
l.key === "Enter" && !l.shiftKey && (l.preventDefault(), te(l));
|
|
754
|
+
}, placeholder: C.sendPlaceholder, style: c.textarea }),
|
|
755
|
+
/* @__PURE__ */ n("div", { style: c.composerTools, children: [
|
|
756
|
+
!H && /* @__PURE__ */ e("span", { children: "↵ Gửi · ⇧↵ Xuống dòng" }),
|
|
757
|
+
!S && /* @__PURE__ */ e("button", { type: "button", style: c.iconButton, "aria-label": "Đính kèm tệp", onClick: () => {
|
|
758
|
+
var l;
|
|
759
|
+
return (l = O.current) == null ? void 0 : l.click();
|
|
760
|
+
}, children: /* @__PURE__ */ e(ut, { size: 16, strokeWidth: 2 }) }),
|
|
761
|
+
!S && /* @__PURE__ */ e("input", { ref: O, type: "file", style: { display: "none" }, onChange: re, accept: "image/jpeg,image/png,image/gif,image/webp,application/pdf,video/mp4,audio/mpeg,audio/ogg" })
|
|
762
|
+
] })
|
|
763
|
+
] }),
|
|
764
|
+
/* @__PURE__ */ e("button", { disabled: !ne, "aria-label": "Gửi tin nhắn", style: { ...c.send, background: p, opacity: ne ? 1 : 0.5, cursor: ne ? "pointer" : "not-allowed" }, children: /* @__PURE__ */ e(gt, { size: 16, strokeWidth: 2 }) })
|
|
765
|
+
] }),
|
|
766
|
+
(g || f) && /* @__PURE__ */ e("div", { role: "alert", style: c.error, children: g || f })
|
|
767
|
+
] });
|
|
768
|
+
}
|
|
769
|
+
function zt({ message: t, primary: i }) {
|
|
770
|
+
var P, J, w, F, N;
|
|
771
|
+
const r = ke(Ie), o = ke(Ve), p = (g) => g.startsWith("/v1/media/proxy") ? `${r}${g}&tok=${encodeURIComponent(o)}` : g, f = t.direction === "outbound", b = ((P = t.attachments) == null ? void 0 : P.filter((g) => g.type === "image")) ?? [], B = ((J = t.attachments) == null ? void 0 : J.filter((g) => g.type === "sticker")) ?? [], h = ((w = t.attachments) == null ? void 0 : w.filter((g) => g.type === "video")) ?? [], y = ((F = t.attachments) == null ? void 0 : F.filter((g) => g.type === "audio")) ?? [], C = ((N = t.attachments) == null ? void 0 : N.filter((g) => g.type === "file")) ?? [], [S, H] = k(null), I = f ? "flex-end" : "flex-start", W = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
|
|
772
|
+
Se(t.occurredAt, !0),
|
|
773
|
+
f && /* @__PURE__ */ n(K, { children: [
|
|
774
|
+
" ",
|
|
775
|
+
/* @__PURE__ */ e(Me, { status: t.status })
|
|
776
|
+
] })
|
|
777
|
+
] }), V = /* @__PURE__ */ e("div", { style: { position: "absolute", bottom: 6, right: 8 }, children: /* @__PURE__ */ n("time", { style: { fontSize: 10, color: "#fff", textShadow: "0 1px 3px rgba(0,0,0,.5)", letterSpacing: 0.2, userSelect: "none" }, children: [
|
|
778
|
+
Se(t.occurredAt, !0),
|
|
779
|
+
f && /* @__PURE__ */ n(K, { children: [
|
|
780
|
+
" ",
|
|
781
|
+
/* @__PURE__ */ e(Me, { status: t.status })
|
|
782
|
+
] })
|
|
783
|
+
] }) }), G = f ? { ...c.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : c.bubbleIn, E = !t.text && y.length === 0 && C.length === 0;
|
|
784
|
+
return /* @__PURE__ */ n("div", { style: { ...c.messageLine, justifyContent: I, flexDirection: "column", alignItems: I }, children: [
|
|
785
|
+
B.map((g, z) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
|
|
786
|
+
/* @__PURE__ */ e("img", { src: p(g.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
|
|
787
|
+
E && b.length === 0 && h.length === 0 && z === B.length - 1 && V
|
|
788
|
+
] }, `s${z}`)),
|
|
789
|
+
b.map((g, z) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "zoom-in" }, onClick: () => H({ url: p(g.url), kind: "image" }), children: [
|
|
790
|
+
/* @__PURE__ */ e("img", { src: p(g.url), alt: "", style: { display: "block", maxWidth: 260, maxHeight: 260, borderRadius: 12, objectFit: "cover" } }),
|
|
791
|
+
E && z === b.length - 1 && h.length === 0 && V
|
|
792
|
+
] }, z)),
|
|
793
|
+
h.map((g, z) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2, cursor: "pointer" }, onClick: () => H({ url: p(g.url), kind: "video" }), children: [
|
|
794
|
+
/* @__PURE__ */ e("video", { src: p(g.url), style: { display: "block", maxWidth: 260, maxHeight: 200, borderRadius: 12, objectFit: "cover" } }),
|
|
795
|
+
/* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,0,0,.25)" }, children: /* @__PURE__ */ e("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,.9)", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ft, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
|
|
796
|
+
E && z === h.length - 1 && V
|
|
797
|
+
] }, z)),
|
|
798
|
+
(y.length > 0 || C.length > 0 || t.text || !b.length && !h.length && !B.length && !t.text) && /* @__PURE__ */ n("div", { style: G, children: [
|
|
799
|
+
y.map((g, z) => /* @__PURE__ */ e("audio", { src: p(g.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, z)),
|
|
800
|
+
C.map((g, z) => /* @__PURE__ */ n("a", { href: p(g.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: f ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
|
|
801
|
+
"📎 ",
|
|
802
|
+
St(g.mimeType)
|
|
803
|
+
] }, z)),
|
|
804
|
+
t.text && /* @__PURE__ */ e("p", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: t.text }),
|
|
805
|
+
!y.length && !C.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
|
|
806
|
+
W
|
|
807
|
+
] }),
|
|
808
|
+
S && Pe(
|
|
809
|
+
/* @__PURE__ */ n("div", { onClick: () => H(null), style: { position: "fixed", inset: 0, zIndex: 1e4, background: "rgba(0,0,0,.88)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: [
|
|
810
|
+
S.kind === "image" ? /* @__PURE__ */ e("img", { src: S.url, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, objectFit: "contain", boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (g) => g.stopPropagation() }) : /* @__PURE__ */ e("video", { src: S.url, controls: !0, autoPlay: !0, style: { maxWidth: "90vw", maxHeight: "90vh", borderRadius: 8, boxShadow: "0 8px 40px rgba(0,0,0,.5)" }, onClick: (g) => g.stopPropagation() }),
|
|
811
|
+
/* @__PURE__ */ e("button", { onClick: () => H(null), style: { position: "absolute", top: 16, right: 16, background: "rgba(255,255,255,.15)", border: "none", borderRadius: "50%", width: 36, height: 36, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", color: "#fff" }, children: /* @__PURE__ */ e(ue, { size: 18 }) })
|
|
812
|
+
] }),
|
|
813
|
+
document.body
|
|
814
|
+
)
|
|
815
|
+
] });
|
|
816
|
+
}
|
|
817
|
+
function Tt({
|
|
818
|
+
conversation: t,
|
|
819
|
+
connection: i,
|
|
820
|
+
primary: r,
|
|
821
|
+
onClose: o
|
|
822
|
+
}) {
|
|
823
|
+
const p = t.contactName ?? t.subject ?? t.providerConversationKey, f = i == null ? void 0 : i.provider, [b, B] = k({ channel: !0, stats: !1, extra: !1 }), h = (y) => B((C) => ({ ...C, [y]: !C[y] }));
|
|
824
|
+
return /* @__PURE__ */ n("aside", { style: c.infoPanel, children: [
|
|
825
|
+
/* @__PURE__ */ n("div", { style: c.infoPanelHeader, children: [
|
|
826
|
+
/* @__PURE__ */ e("span", { style: { fontWeight: 600, fontSize: 13, color: d.ink }, children: "Thông tin liên hệ" }),
|
|
827
|
+
/* @__PURE__ */ e("button", { style: c.iconButton, onClick: o, "aria-label": "Đóng", children: /* @__PURE__ */ e(ue, { size: 16, strokeWidth: 2 }) })
|
|
828
|
+
] }),
|
|
829
|
+
/* @__PURE__ */ n("div", { style: { overflowY: "auto", flex: 1 }, children: [
|
|
830
|
+
/* @__PURE__ */ n("div", { style: c.infoPanelIdentity, children: [
|
|
831
|
+
/* @__PURE__ */ n("span", { style: { ...c.avatarWrap, width: 48, height: 48 }, children: [
|
|
832
|
+
/* @__PURE__ */ e(
|
|
833
|
+
Ke,
|
|
834
|
+
{
|
|
835
|
+
src: t.contactPictureUrl,
|
|
836
|
+
fallback: Ye(p),
|
|
837
|
+
style: { ...c.avatar, width: 48, height: 48, fontSize: 16 }
|
|
838
|
+
}
|
|
839
|
+
),
|
|
840
|
+
/* @__PURE__ */ e("span", { style: { ...c.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e(ce, { provider: f }) })
|
|
841
|
+
] }),
|
|
842
|
+
/* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: p }),
|
|
843
|
+
/* @__PURE__ */ e("span", { style: { fontSize: 11, color: d.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
|
|
844
|
+
] }),
|
|
845
|
+
/* @__PURE__ */ n(be, { label: "KÊNH", sectionKey: "channel", expanded: b.channel, onToggle: () => h("channel"), children: [
|
|
846
|
+
/* @__PURE__ */ e(Z, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
|
|
847
|
+
/* @__PURE__ */ e(ce, { provider: f }),
|
|
848
|
+
/* @__PURE__ */ e("span", { children: Ge(f) })
|
|
849
|
+
] }) }),
|
|
850
|
+
/* @__PURE__ */ n(Z, { label: "ID hội thoại", children: [
|
|
851
|
+
/* @__PURE__ */ n("span", { style: { fontFamily: "monospace", fontSize: 11 }, children: [
|
|
852
|
+
t.id.slice(0, 8),
|
|
853
|
+
"…"
|
|
854
|
+
] }),
|
|
855
|
+
/* @__PURE__ */ e(Bt, { value: t.id })
|
|
856
|
+
] })
|
|
857
|
+
] }),
|
|
858
|
+
/* @__PURE__ */ n(be, { label: "THỐNG KÊ", sectionKey: "stats", expanded: b.stats, onToggle: () => h("stats"), children: [
|
|
859
|
+
/* @__PURE__ */ e(Z, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
|
|
860
|
+
(t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(Z, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
|
|
861
|
+
/* @__PURE__ */ e(
|
|
862
|
+
Z,
|
|
863
|
+
{
|
|
864
|
+
label: "Gần nhất",
|
|
865
|
+
value: t.lastMessageAt ? new Date(t.lastMessageAt).toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit", year: "numeric" }) : "—"
|
|
866
|
+
}
|
|
867
|
+
),
|
|
868
|
+
/* @__PURE__ */ e(Z, { label: "Lần đầu", value: "—" })
|
|
869
|
+
] }),
|
|
870
|
+
/* @__PURE__ */ n(be, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: b.extra, onToggle: () => h("extra"), children: [
|
|
871
|
+
/* @__PURE__ */ e(Z, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
|
|
872
|
+
/* @__PURE__ */ e(Z, { label: "Email", value: "— chưa có", valueMuted: !0 }),
|
|
873
|
+
/* @__PURE__ */ e(Z, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
|
|
874
|
+
] }),
|
|
875
|
+
/* @__PURE__ */ n("div", { style: { padding: "12px 16px", display: "flex", flexDirection: "column", gap: 8 }, children: [
|
|
876
|
+
/* @__PURE__ */ e("button", { style: { ...c.ghostButton, color: r, borderColor: `${r}33` }, children: "Xem lịch sử" }),
|
|
877
|
+
/* @__PURE__ */ e("button", { style: { ...c.ghostButton, color: r, borderColor: `${r}33` }, children: "Thêm ghi chú" })
|
|
878
|
+
] })
|
|
879
|
+
] })
|
|
880
|
+
] });
|
|
881
|
+
}
|
|
882
|
+
function be({ label: t, children: i, sectionKey: r, expanded: o, onToggle: p }) {
|
|
883
|
+
const f = !!p, b = o ?? !0;
|
|
884
|
+
return /* @__PURE__ */ n("div", { style: { borderTop: `1px solid ${d.line}` }, children: [
|
|
885
|
+
/* @__PURE__ */ n(
|
|
886
|
+
"div",
|
|
887
|
+
{
|
|
888
|
+
style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 16px 6px", fontSize: 10, fontWeight: 700, letterSpacing: 1, color: d.muted, textTransform: "uppercase", cursor: f ? "pointer" : "default" },
|
|
889
|
+
onClick: p,
|
|
890
|
+
children: [
|
|
891
|
+
/* @__PURE__ */ e("span", { children: t }),
|
|
892
|
+
f && (b ? /* @__PURE__ */ e(lt, { size: 12, strokeWidth: 2 }) : /* @__PURE__ */ e(dt, { size: 12, strokeWidth: 2 }))
|
|
893
|
+
]
|
|
894
|
+
}
|
|
895
|
+
),
|
|
896
|
+
b && i
|
|
897
|
+
] });
|
|
898
|
+
}
|
|
899
|
+
function Z({ label: t, value: i, children: r, valueColor: o, valueMuted: p }) {
|
|
900
|
+
return /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: "3px 16px", fontSize: 12, gap: 8 }, children: [
|
|
901
|
+
/* @__PURE__ */ e("span", { style: { color: d.muted, flexShrink: 0 }, children: t }),
|
|
902
|
+
/* @__PURE__ */ e("span", { style: { color: o ?? (p ? d.muted : d.ink), textAlign: "right", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", display: "flex", alignItems: "center", gap: 4 }, children: r ?? i })
|
|
903
|
+
] });
|
|
904
|
+
}
|
|
905
|
+
function Bt({ value: t }) {
|
|
906
|
+
const [i, r] = k(!1);
|
|
907
|
+
return /* @__PURE__ */ e(
|
|
908
|
+
"button",
|
|
909
|
+
{
|
|
910
|
+
style: { border: 0, background: "none", cursor: "pointer", color: d.muted, padding: 2, lineHeight: 1 },
|
|
911
|
+
title: "Sao chép",
|
|
912
|
+
onClick: () => {
|
|
913
|
+
navigator.clipboard.writeText(t).then(() => {
|
|
914
|
+
r(!0), setTimeout(() => r(!1), 1500);
|
|
915
|
+
});
|
|
916
|
+
},
|
|
917
|
+
"aria-label": "Sao chép ID",
|
|
918
|
+
children: i ? "✓" : "⎘"
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
function Rt() {
|
|
923
|
+
return /* @__PURE__ */ n("div", { style: c.empty, children: [
|
|
924
|
+
/* @__PURE__ */ e("div", { style: c.emptyHero, children: /* @__PURE__ */ e(st, { size: 16, strokeWidth: 2 }) }),
|
|
925
|
+
/* @__PURE__ */ e("h2", { children: "Chọn một hội thoại" }),
|
|
926
|
+
/* @__PURE__ */ e("p", { children: "Chọn hội thoại bên trái để xem và trả lời tin nhắn." })
|
|
927
|
+
] });
|
|
928
|
+
}
|
|
929
|
+
function Xe({ name: t, color: i, image: r, provider: o }) {
|
|
930
|
+
return /* @__PURE__ */ n("span", { style: c.avatarWrap, children: [
|
|
931
|
+
/* @__PURE__ */ e(Wt, { name: t, color: i, image: r }),
|
|
932
|
+
o && /* @__PURE__ */ e("span", { style: c.providerBadge, children: /* @__PURE__ */ e(ce, { provider: o }) })
|
|
933
|
+
] });
|
|
934
|
+
}
|
|
935
|
+
function Wt({ name: t, color: i, image: r }) {
|
|
936
|
+
return /* @__PURE__ */ e(Ke, { src: r, fallback: Ye(t), style: { ...c.avatar, background: `${i}18`, color: i } });
|
|
937
|
+
}
|
|
938
|
+
function we() {
|
|
939
|
+
return /* @__PURE__ */ e(pt, { size: 14, style: c.spinner, "aria-hidden": "true" });
|
|
940
|
+
}
|
|
941
|
+
function Ye(t) {
|
|
942
|
+
return t.split(/\s+/).filter(Boolean).slice(-2).map((i) => i[0]).join("").toUpperCase() || "?";
|
|
943
|
+
}
|
|
944
|
+
const Lt = { livechat: "web" };
|
|
945
|
+
function ce({ provider: t }) {
|
|
946
|
+
const i = ke(Ie), r = 14;
|
|
947
|
+
if (!t) return null;
|
|
948
|
+
const o = Lt[t] ?? t;
|
|
949
|
+
return /* @__PURE__ */ e("img", { src: `${i}/static/logos/${o}.avif`, alt: t, width: r, height: r, style: { borderRadius: "50%", objectFit: "cover", display: "block" } });
|
|
950
|
+
}
|
|
951
|
+
function Se(t, i = !1) {
|
|
952
|
+
if (!t) return "";
|
|
953
|
+
const r = new Date(t);
|
|
954
|
+
return r.toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? r.toLocaleTimeString("vi-VN", { hour: "2-digit", minute: "2-digit" }) : r.toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit" });
|
|
955
|
+
}
|
|
956
|
+
const c = {
|
|
957
|
+
frame: { display: "grid", gridTemplateRows: "minmax(0, 1fr)", height: 620, maxHeight: "calc(100dvh - 220px)", minHeight: 0, overflow: "hidden", border: `1px solid ${d.line}`, background: d.white, color: d.ink, boxShadow: "0 18px 50px rgba(31,45,72,.10)" },
|
|
958
|
+
sidebar: { display: "flex", flexDirection: "column", minWidth: 0, minHeight: 0, borderRight: `1px solid ${d.line}`, background: d.white },
|
|
959
|
+
brand: { display: "flex", alignItems: "center", gap: 10, padding: "20px 18px 16px" },
|
|
960
|
+
brandMark: { display: "grid", placeItems: "center", width: 32, height: 32, borderRadius: 10, color: "#fff", fontWeight: 800 },
|
|
961
|
+
eyebrow: { display: "block", marginTop: 2, fontSize: 9, letterSpacing: 1.3, color: d.muted },
|
|
962
|
+
iconButton: { display: "inline-grid", placeItems: "center", width: 32, height: 32, marginLeft: "auto", border: 0, borderRadius: 8, background: "transparent", color: d.muted, cursor: "pointer" },
|
|
963
|
+
search: { display: "flex", alignItems: "center", gap: 8, margin: "0 14px 12px", padding: "9px 10px", border: `1px solid ${d.line}`, borderRadius: 9, color: d.muted, background: d.surface },
|
|
964
|
+
clear: { border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 18 },
|
|
965
|
+
listHeader: { display: "flex", alignItems: "center", padding: "10px 18px", borderTop: `1px solid ${d.line}`, borderBottom: `1px solid ${d.line}`, color: d.muted, fontSize: 11, fontWeight: 700, letterSpacing: 0.4, textTransform: "uppercase" },
|
|
966
|
+
conversationList: { overflowY: "auto", flex: 1, minHeight: 0 },
|
|
967
|
+
row: { display: "flex", width: "100%", gap: 11, padding: "10px 14px", border: 0, borderBottom: `1px solid ${d.line}`, background: "transparent", textAlign: "left", cursor: "pointer", transition: "background 120ms ease" },
|
|
968
|
+
avatarWrap: { position: "relative", flex: "0 0 auto", width: 38, height: 38 },
|
|
969
|
+
avatar: { flex: "0 0 auto", width: 38, height: 38, display: "grid", placeItems: "center", borderRadius: "50%", objectFit: "cover", fontSize: 12, fontWeight: 800 },
|
|
970
|
+
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" },
|
|
971
|
+
rowBody: { minWidth: 0, flex: 1 },
|
|
972
|
+
rowTop: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8, fontSize: 13 },
|
|
973
|
+
rowBottom: { display: "flex", marginTop: 4, fontSize: 11, minWidth: 0, overflow: "hidden", lineHeight: 1.4 },
|
|
974
|
+
unreadBadge: { display: "inline-grid", placeItems: "center", minWidth: 18, height: 18, borderRadius: 999, background: "#ef4444", color: "#fff", fontSize: 10, fontWeight: 800, padding: "0 5px" },
|
|
975
|
+
loadMore: { width: "100%", border: 0, background: "transparent", color: "#4c72ca", padding: 14, cursor: "pointer", fontSize: 12 },
|
|
976
|
+
emptySmall: { display: "grid", justifyItems: "center", gap: 7, padding: "56px 24px", color: d.muted, fontSize: 12, textAlign: "center" },
|
|
977
|
+
emptyIcon: { display: "grid", placeItems: "center", width: 40, height: 40, borderRadius: 12, background: d.surface },
|
|
978
|
+
main: { minWidth: 0, minHeight: 0, overflow: "hidden", background: d.surface },
|
|
979
|
+
chat: { display: "flex", flexDirection: "column", height: "100%", minWidth: 0, minHeight: 0 },
|
|
980
|
+
chatHeader: { flex: "0 0 auto", display: "flex", alignItems: "center", gap: 10, padding: "0 16px 0 18px", height: 56, borderBottom: `1px solid ${d.line}`, background: d.white },
|
|
981
|
+
contact: { display: "grid", gap: 3, minWidth: 0, flex: 1 },
|
|
982
|
+
contactName: { fontSize: 14, fontWeight: 600, color: d.ink, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" },
|
|
983
|
+
contactMeta: { display: "flex", alignItems: "center", gap: 5, fontSize: 11, color: d.muted },
|
|
984
|
+
headerActions: { display: "flex", gap: 2, marginLeft: "auto" },
|
|
985
|
+
messageArea: { flex: 1, minHeight: 0, overflowY: "auto", overscrollBehavior: "contain", padding: "20px clamp(16px,5vw,56px)", background: "linear-gradient(180deg,#f9fbfe 0%,#f4f7fb 100%)" },
|
|
986
|
+
day: { margin: "0 auto 18px", color: "#a1acbb", fontSize: 10, letterSpacing: 1.2, fontWeight: 700, textAlign: "center" },
|
|
987
|
+
historyButton: { display: "block", margin: "0 auto 18px", border: `1px solid ${d.line}`, borderRadius: 20, padding: "6px 12px", background: d.white, color: d.muted, cursor: "pointer", fontSize: 11 },
|
|
988
|
+
messageHint: { display: "flex", justifyContent: "center", alignItems: "center", gap: 8, padding: 40, color: d.muted, fontSize: 12 },
|
|
989
|
+
messageLine: { display: "flex", marginBottom: 10 },
|
|
990
|
+
bubbleOut: { maxWidth: "min(70%,480px)", padding: "9px 13px", borderRadius: "14px 14px 3px 14px", boxShadow: "0 2px 5px rgba(30,43,65,.03)", fontSize: 14, lineHeight: 1.55 },
|
|
991
|
+
bubbleIn: { maxWidth: "min(70%,480px)", padding: "9px 13px", borderRadius: "14px 14px 14px 3px", border: `1px solid ${d.line}`, background: d.surface, boxShadow: "0 2px 5px rgba(30,43,65,.03)", fontSize: 14, lineHeight: 1.55 },
|
|
992
|
+
composer: { flex: "0 0 auto", display: "flex", alignItems: "flex-end", gap: 10, padding: "10px 14px 12px", borderTop: `1px solid ${d.line}`, background: d.white },
|
|
993
|
+
textarea: { display: "block", width: "100%", minWidth: 0, boxSizing: "border-box", minHeight: 44, maxHeight: 120, resize: "vertical", border: 0, outline: 0, background: "transparent", color: d.ink, padding: "10px 12px 4px", font: "inherit", fontSize: 13, lineHeight: 1.45 },
|
|
994
|
+
composerBox: { flex: 1, minWidth: 0, border: `1px solid ${d.line}`, borderRadius: 10, background: d.surface, overflow: "hidden" },
|
|
995
|
+
send: { display: "grid", placeItems: "center", width: 38, height: 38, border: 0, borderRadius: "50%", color: "#fff", flexShrink: 0 },
|
|
996
|
+
error: { padding: "8px 18px", background: "#fff2f0", color: "#b42318", fontSize: 12 },
|
|
997
|
+
empty: { display: "grid", placeItems: "center", alignContent: "center", height: "100%", padding: 30, textAlign: "center", color: d.muted },
|
|
998
|
+
emptyHero: { display: "grid", placeItems: "center", width: 64, height: 64, marginBottom: 16, borderRadius: 20, background: "#eaf0ff", color: "#5277d7" },
|
|
999
|
+
state: { display: "flex", alignItems: "center", justifyContent: "center", gap: 10, minHeight: 180, border: `1px solid ${d.line}`, background: d.white, color: d.muted, fontSize: 13 },
|
|
1000
|
+
retry: { border: 0, borderRadius: 7, padding: "7px 10px", background: "#eff4ff", color: "#315dbb", cursor: "pointer" },
|
|
1001
|
+
spinner: { display: "inline-block", width: 14, height: 14, border: "2px solid #dbe3f3", borderTopColor: "#5277d7", borderRadius: "50%", animation: "channelhub-spin .7s linear infinite" },
|
|
1002
|
+
composerTools: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: "4px 8px 4px 12px", color: "#a0aabd", fontSize: 12 },
|
|
1003
|
+
infoPanel: { display: "flex", flexDirection: "column", borderLeft: `1px solid ${d.line}`, background: d.white, minHeight: 0, overflow: "hidden" },
|
|
1004
|
+
infoPanelHeader: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "16px 16px 12px", borderBottom: `1px solid ${d.line}`, flex: "0 0 auto" },
|
|
1005
|
+
infoPanelIdentity: { display: "flex", flexDirection: "column", alignItems: "center", padding: "20px 16px 16px", gap: 4 },
|
|
1006
|
+
ghostButton: { width: "100%", padding: "8px 12px", border: `1px solid ${d.line}`, borderRadius: 8, background: "transparent", fontSize: 12, cursor: "pointer", textAlign: "center" }
|
|
1007
|
+
}, Ht = {
|
|
1008
|
+
facebook: "#dbeafe",
|
|
1009
|
+
zalo: "#e0f2fe",
|
|
1010
|
+
instagram: "#fce7f3",
|
|
1011
|
+
telegram: "#cffafe",
|
|
1012
|
+
livechat: "#ede9fe",
|
|
1013
|
+
whatsapp: "#dcfce7"
|
|
1014
|
+
}, $t = {
|
|
1015
|
+
facebook: "facebook",
|
|
1016
|
+
instagram: "instagram",
|
|
1017
|
+
telegram: "telegram",
|
|
1018
|
+
zalo: "zalo",
|
|
1019
|
+
livechat: "web",
|
|
1020
|
+
whatsapp: "web"
|
|
1021
|
+
};
|
|
1022
|
+
function ie({ provider: t, apiUrl: i, size: r = 40 }) {
|
|
1023
|
+
const o = Ht[t] ?? "#f1f5f9", p = $t[t], f = i.replace(/\/$/, "");
|
|
1024
|
+
return /* @__PURE__ */ e(
|
|
1025
|
+
"div",
|
|
1026
|
+
{
|
|
1027
|
+
style: {
|
|
1028
|
+
width: r,
|
|
1029
|
+
height: r,
|
|
1030
|
+
borderRadius: Math.round(r * 0.28),
|
|
1031
|
+
background: o,
|
|
1032
|
+
display: "flex",
|
|
1033
|
+
alignItems: "center",
|
|
1034
|
+
justifyContent: "center",
|
|
1035
|
+
flexShrink: 0,
|
|
1036
|
+
overflow: "hidden"
|
|
1037
|
+
},
|
|
1038
|
+
children: p ? /* @__PURE__ */ e(
|
|
1039
|
+
"img",
|
|
1040
|
+
{
|
|
1041
|
+
src: `${f}/static/logos/${p}.avif`,
|
|
1042
|
+
alt: t,
|
|
1043
|
+
width: Math.round(r * 0.65),
|
|
1044
|
+
height: Math.round(r * 0.65),
|
|
1045
|
+
style: { objectFit: "contain", display: "block" }
|
|
1046
|
+
}
|
|
1047
|
+
) : /* @__PURE__ */ e("span", { style: { fontSize: Math.round(r * 0.45), fontWeight: 700, color: "#64748b", textTransform: "uppercase" }, children: t.slice(0, 1) })
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
const de = {
|
|
1052
|
+
facebook: "Facebook",
|
|
1053
|
+
zalo: "Zalo OA",
|
|
1054
|
+
instagram: "Instagram",
|
|
1055
|
+
telegram: "Telegram",
|
|
1056
|
+
livechat: "Live Chat",
|
|
1057
|
+
whatsapp: "WhatsApp"
|
|
1058
|
+
}, jt = {
|
|
1059
|
+
facebook: "#dbeafe",
|
|
1060
|
+
zalo: "#e0f2fe",
|
|
1061
|
+
instagram: "#fce7f3",
|
|
1062
|
+
telegram: "#cffafe",
|
|
1063
|
+
livechat: "#ede9fe",
|
|
1064
|
+
whatsapp: "#dcfce7"
|
|
1065
|
+
};
|
|
1066
|
+
function ze(t) {
|
|
1067
|
+
const i = t.metadata;
|
|
1068
|
+
return String(i.displayName ?? i.pageName ?? i.username ?? i.name ?? t.externalAccountId);
|
|
1069
|
+
}
|
|
1070
|
+
function Mt(t) {
|
|
1071
|
+
const i = de[t.provider] ?? t.provider, r = String(t.metadata.username ?? t.metadata.pageName ?? "");
|
|
1072
|
+
return r ? `${i} · ${r}` : i;
|
|
1073
|
+
}
|
|
1074
|
+
const a = {
|
|
1075
|
+
root: {
|
|
1076
|
+
background: "#fff",
|
|
1077
|
+
borderRadius: 16,
|
|
1078
|
+
boxShadow: "0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06)",
|
|
1079
|
+
overflow: "hidden",
|
|
1080
|
+
minWidth: 320,
|
|
1081
|
+
width: "100%",
|
|
1082
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",
|
|
1083
|
+
fontSize: 14,
|
|
1084
|
+
color: "#0f172a"
|
|
1085
|
+
},
|
|
1086
|
+
header: {
|
|
1087
|
+
padding: "20px 24px 0",
|
|
1088
|
+
display: "flex",
|
|
1089
|
+
alignItems: "center",
|
|
1090
|
+
justifyContent: "space-between"
|
|
1091
|
+
},
|
|
1092
|
+
headerLeft: { display: "flex", alignItems: "center", gap: 10 },
|
|
1093
|
+
title: { fontSize: 16, fontWeight: 700, color: "#0f172a", lineHeight: 1.3 },
|
|
1094
|
+
subtitle: { fontSize: 12, color: "#94a3b8", marginTop: 1 },
|
|
1095
|
+
divider: { height: 1, background: "#f1f5f9", margin: "16px 0 0" },
|
|
1096
|
+
body: { padding: "16px 24px 24px" },
|
|
1097
|
+
backBtn: {
|
|
1098
|
+
width: 32,
|
|
1099
|
+
height: 32,
|
|
1100
|
+
borderRadius: 8,
|
|
1101
|
+
border: "1px solid #e2e8f0",
|
|
1102
|
+
background: "#fff",
|
|
1103
|
+
display: "flex",
|
|
1104
|
+
alignItems: "center",
|
|
1105
|
+
justifyContent: "center",
|
|
1106
|
+
cursor: "pointer",
|
|
1107
|
+
color: "#475569",
|
|
1108
|
+
flexShrink: 0
|
|
1109
|
+
},
|
|
1110
|
+
addBtn: {
|
|
1111
|
+
display: "flex",
|
|
1112
|
+
alignItems: "center",
|
|
1113
|
+
gap: 6,
|
|
1114
|
+
padding: "8px 14px",
|
|
1115
|
+
borderRadius: 8,
|
|
1116
|
+
border: "none",
|
|
1117
|
+
background: "#2563eb",
|
|
1118
|
+
color: "#fff",
|
|
1119
|
+
fontSize: 13,
|
|
1120
|
+
fontWeight: 600,
|
|
1121
|
+
cursor: "pointer",
|
|
1122
|
+
whiteSpace: "nowrap",
|
|
1123
|
+
flexShrink: 0
|
|
1124
|
+
},
|
|
1125
|
+
errorBanner: {
|
|
1126
|
+
margin: "12px 24px 0",
|
|
1127
|
+
padding: "10px 14px",
|
|
1128
|
+
borderRadius: 10,
|
|
1129
|
+
background: "#fef2f2",
|
|
1130
|
+
border: "1px solid #fecaca",
|
|
1131
|
+
color: "#dc2626",
|
|
1132
|
+
fontSize: 13
|
|
1133
|
+
},
|
|
1134
|
+
channelItem: {
|
|
1135
|
+
display: "flex",
|
|
1136
|
+
alignItems: "center",
|
|
1137
|
+
gap: 12,
|
|
1138
|
+
padding: "12px 14px",
|
|
1139
|
+
borderRadius: 12,
|
|
1140
|
+
border: "1px solid #f1f5f9",
|
|
1141
|
+
background: "#fafafa",
|
|
1142
|
+
marginBottom: 8
|
|
1143
|
+
},
|
|
1144
|
+
channelInfo: { flex: 1, minWidth: 0 },
|
|
1145
|
+
channelName: { fontSize: 14, fontWeight: 600, color: "#0f172a", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
1146
|
+
channelMeta: { fontSize: 12, color: "#94a3b8", marginTop: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
|
|
1147
|
+
channelActions: { display: "flex", alignItems: "center", gap: 8, flexShrink: 0 },
|
|
1148
|
+
badgeActive: { fontSize: 11, fontWeight: 600, padding: "2px 8px", borderRadius: 999, background: "#d1fae5", color: "#059669" },
|
|
1149
|
+
badgeInactive: { fontSize: 11, fontWeight: 600, padding: "2px 8px", borderRadius: 999, background: "#f1f5f9", color: "#94a3b8" },
|
|
1150
|
+
disconnectBtn: {
|
|
1151
|
+
fontSize: 12,
|
|
1152
|
+
fontWeight: 500,
|
|
1153
|
+
padding: "5px 10px",
|
|
1154
|
+
borderRadius: 7,
|
|
1155
|
+
border: "1px solid #e2e8f0",
|
|
1156
|
+
background: "#fff",
|
|
1157
|
+
color: "#64748b",
|
|
1158
|
+
cursor: "pointer"
|
|
1159
|
+
},
|
|
1160
|
+
providerGrid: { display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(130px, 1fr))", gap: 10 },
|
|
1161
|
+
providerCard: {
|
|
1162
|
+
display: "flex",
|
|
1163
|
+
flexDirection: "column",
|
|
1164
|
+
alignItems: "center",
|
|
1165
|
+
gap: 8,
|
|
1166
|
+
padding: "16px 12px 14px",
|
|
1167
|
+
borderRadius: 12,
|
|
1168
|
+
borderWidth: "1.5px",
|
|
1169
|
+
borderStyle: "solid",
|
|
1170
|
+
borderColor: "#f1f5f9",
|
|
1171
|
+
background: "#fafafa",
|
|
1172
|
+
cursor: "pointer",
|
|
1173
|
+
textAlign: "center",
|
|
1174
|
+
boxShadow: "none",
|
|
1175
|
+
transform: "none"
|
|
1176
|
+
},
|
|
1177
|
+
providerName: { fontSize: 13, fontWeight: 600, color: "#0f172a", lineHeight: 1.2 },
|
|
1178
|
+
providerDesc: { fontSize: 11, color: "#94a3b8", lineHeight: 1.4 },
|
|
1179
|
+
connectHeader: {
|
|
1180
|
+
display: "flex",
|
|
1181
|
+
alignItems: "center",
|
|
1182
|
+
gap: 12,
|
|
1183
|
+
padding: "20px 24px 16px",
|
|
1184
|
+
borderBottom: "1px solid #f1f5f9"
|
|
1185
|
+
},
|
|
1186
|
+
connectTitle: { fontSize: 15, fontWeight: 700, color: "#0f172a" },
|
|
1187
|
+
connectDesc: { fontSize: 12, color: "#94a3b8", marginTop: 2, lineHeight: 1.5 },
|
|
1188
|
+
form: { padding: "20px 24px 24px", display: "flex", flexDirection: "column", gap: 16 },
|
|
1189
|
+
field: { display: "flex", flexDirection: "column", gap: 6 },
|
|
1190
|
+
label: { fontSize: 13, fontWeight: 600, color: "#374151" },
|
|
1191
|
+
labelHint: { fontSize: 11, fontWeight: 400, color: "#94a3b8", marginLeft: 4 },
|
|
1192
|
+
input: {
|
|
1193
|
+
padding: "9px 12px",
|
|
1194
|
+
borderRadius: 8,
|
|
1195
|
+
border: "1.5px solid #e2e8f0",
|
|
1196
|
+
fontSize: 13,
|
|
1197
|
+
color: "#0f172a",
|
|
1198
|
+
background: "#fff",
|
|
1199
|
+
outline: "none",
|
|
1200
|
+
fontFamily: "inherit",
|
|
1201
|
+
width: "100%",
|
|
1202
|
+
boxSizing: "border-box"
|
|
1203
|
+
},
|
|
1204
|
+
inputHint: { fontSize: 11, color: "#94a3b8", lineHeight: 1.5 },
|
|
1205
|
+
infoBox: {
|
|
1206
|
+
display: "flex",
|
|
1207
|
+
gap: 8,
|
|
1208
|
+
padding: "10px 12px",
|
|
1209
|
+
borderRadius: 8,
|
|
1210
|
+
background: "#eff6ff",
|
|
1211
|
+
border: "1px solid #bfdbfe",
|
|
1212
|
+
color: "#1e40af",
|
|
1213
|
+
fontSize: 13,
|
|
1214
|
+
lineHeight: 1.5
|
|
1215
|
+
},
|
|
1216
|
+
formActions: { display: "flex", gap: 8, flexWrap: "wrap" },
|
|
1217
|
+
btnPrimary: {
|
|
1218
|
+
flex: 1,
|
|
1219
|
+
minWidth: 120,
|
|
1220
|
+
padding: "10px 16px",
|
|
1221
|
+
borderRadius: 9,
|
|
1222
|
+
border: "none",
|
|
1223
|
+
background: "#2563eb",
|
|
1224
|
+
color: "#fff",
|
|
1225
|
+
fontSize: 14,
|
|
1226
|
+
fontWeight: 600,
|
|
1227
|
+
cursor: "pointer",
|
|
1228
|
+
fontFamily: "inherit"
|
|
1229
|
+
},
|
|
1230
|
+
btnSecondary: {
|
|
1231
|
+
padding: "10px 16px",
|
|
1232
|
+
borderRadius: 9,
|
|
1233
|
+
border: "1.5px solid #e2e8f0",
|
|
1234
|
+
background: "#fff",
|
|
1235
|
+
color: "#64748b",
|
|
1236
|
+
fontSize: 14,
|
|
1237
|
+
fontWeight: 500,
|
|
1238
|
+
cursor: "pointer",
|
|
1239
|
+
fontFamily: "inherit"
|
|
1240
|
+
},
|
|
1241
|
+
resultBanner: {
|
|
1242
|
+
display: "flex",
|
|
1243
|
+
alignItems: "flex-start",
|
|
1244
|
+
gap: 10,
|
|
1245
|
+
padding: "12px 14px",
|
|
1246
|
+
borderRadius: 10,
|
|
1247
|
+
background: "#f0fdf4",
|
|
1248
|
+
border: "1px solid #bbf7d0",
|
|
1249
|
+
fontSize: 13,
|
|
1250
|
+
color: "#166534",
|
|
1251
|
+
lineHeight: 1.5
|
|
1252
|
+
},
|
|
1253
|
+
codeLabel: { fontSize: 11, fontWeight: 600, color: "#64748b", textTransform: "uppercase", letterSpacing: ".05em", marginBottom: 6 },
|
|
1254
|
+
codeBlock: { background: "#0f172a", borderRadius: 10, padding: "14px 16px", position: "relative", overflowX: "auto" },
|
|
1255
|
+
codePre: {
|
|
1256
|
+
fontFamily: "'JetBrains Mono', 'Fira Code', 'Courier New', monospace",
|
|
1257
|
+
fontSize: 11.5,
|
|
1258
|
+
lineHeight: 1.6,
|
|
1259
|
+
color: "#e2e8f0",
|
|
1260
|
+
whiteSpace: "pre-wrap",
|
|
1261
|
+
wordBreak: "break-all",
|
|
1262
|
+
margin: 0
|
|
1263
|
+
},
|
|
1264
|
+
copyBtn: {
|
|
1265
|
+
position: "absolute",
|
|
1266
|
+
top: 10,
|
|
1267
|
+
right: 10,
|
|
1268
|
+
display: "flex",
|
|
1269
|
+
alignItems: "center",
|
|
1270
|
+
gap: 4,
|
|
1271
|
+
padding: "4px 10px",
|
|
1272
|
+
borderRadius: 6,
|
|
1273
|
+
border: "1px solid #334155",
|
|
1274
|
+
background: "#1e293b",
|
|
1275
|
+
color: "#94a3b8",
|
|
1276
|
+
fontSize: 11,
|
|
1277
|
+
fontWeight: 500,
|
|
1278
|
+
cursor: "pointer",
|
|
1279
|
+
fontFamily: "inherit"
|
|
1280
|
+
},
|
|
1281
|
+
secretRow: {
|
|
1282
|
+
display: "flex",
|
|
1283
|
+
alignItems: "center",
|
|
1284
|
+
gap: 8,
|
|
1285
|
+
padding: "10px 12px",
|
|
1286
|
+
borderRadius: 8,
|
|
1287
|
+
background: "#fefce8",
|
|
1288
|
+
border: "1px solid #fef08a"
|
|
1289
|
+
},
|
|
1290
|
+
secretLabel: { fontSize: 12, fontWeight: 600, color: "#854d0e", whiteSpace: "nowrap" },
|
|
1291
|
+
secretValue: {
|
|
1292
|
+
fontFamily: "'JetBrains Mono', monospace",
|
|
1293
|
+
fontSize: 12,
|
|
1294
|
+
color: "#0f172a",
|
|
1295
|
+
flex: 1,
|
|
1296
|
+
overflow: "hidden",
|
|
1297
|
+
textOverflow: "ellipsis",
|
|
1298
|
+
whiteSpace: "nowrap"
|
|
1299
|
+
},
|
|
1300
|
+
oauthWaiting: {
|
|
1301
|
+
display: "flex",
|
|
1302
|
+
flexDirection: "column",
|
|
1303
|
+
alignItems: "center",
|
|
1304
|
+
justifyContent: "center",
|
|
1305
|
+
padding: "40px 24px 48px",
|
|
1306
|
+
gap: 16,
|
|
1307
|
+
textAlign: "center"
|
|
1308
|
+
},
|
|
1309
|
+
oauthTitle: { fontSize: 16, fontWeight: 700, color: "#0f172a" },
|
|
1310
|
+
oauthDesc: { fontSize: 13, color: "#64748b", lineHeight: 1.6, maxWidth: 300 },
|
|
1311
|
+
oauthCancel: {
|
|
1312
|
+
marginTop: 8,
|
|
1313
|
+
padding: "10px 20px",
|
|
1314
|
+
borderRadius: 9,
|
|
1315
|
+
border: "1.5px solid #e2e8f0",
|
|
1316
|
+
background: "#fff",
|
|
1317
|
+
color: "#64748b",
|
|
1318
|
+
fontSize: 14,
|
|
1319
|
+
fontWeight: 500,
|
|
1320
|
+
cursor: "pointer",
|
|
1321
|
+
fontFamily: "inherit"
|
|
1322
|
+
},
|
|
1323
|
+
empty: {
|
|
1324
|
+
display: "flex",
|
|
1325
|
+
flexDirection: "column",
|
|
1326
|
+
alignItems: "center",
|
|
1327
|
+
padding: "40px 24px 48px",
|
|
1328
|
+
gap: 12,
|
|
1329
|
+
textAlign: "center"
|
|
1330
|
+
},
|
|
1331
|
+
emptyTitle: { fontSize: 15, fontWeight: 700, color: "#0f172a" },
|
|
1332
|
+
emptyDesc: { fontSize: 13, color: "#94a3b8", lineHeight: 1.6, maxWidth: 280 },
|
|
1333
|
+
emptyCta: {
|
|
1334
|
+
marginTop: 4,
|
|
1335
|
+
display: "flex",
|
|
1336
|
+
alignItems: "center",
|
|
1337
|
+
gap: 6,
|
|
1338
|
+
padding: "10px 20px",
|
|
1339
|
+
borderRadius: 9,
|
|
1340
|
+
border: "none",
|
|
1341
|
+
background: "#2563eb",
|
|
1342
|
+
color: "#fff",
|
|
1343
|
+
fontSize: 14,
|
|
1344
|
+
fontWeight: 600,
|
|
1345
|
+
cursor: "pointer",
|
|
1346
|
+
fontFamily: "inherit"
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
function Ae() {
|
|
1350
|
+
return /* @__PURE__ */ e("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ e("path", { d: "M7 1v12M1 7h12", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) });
|
|
1351
|
+
}
|
|
1352
|
+
function ae() {
|
|
1353
|
+
return /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ e("path", { d: "M10 3L5 8l5 5", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
1354
|
+
}
|
|
1355
|
+
function Oe() {
|
|
1356
|
+
return /* @__PURE__ */ n("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: [
|
|
1357
|
+
/* @__PURE__ */ e("rect", { x: "4", y: "4", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
1358
|
+
/* @__PURE__ */ e("path", { d: "M2.5 8H2a1 1 0 01-1-1V2a1 1 0 011-1h5a1 1 0 011 1v.5", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
|
|
1359
|
+
] });
|
|
1360
|
+
}
|
|
1361
|
+
function De() {
|
|
1362
|
+
return /* @__PURE__ */ e("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", children: /* @__PURE__ */ e("path", { d: "M2 6l3 3 5-5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
1363
|
+
}
|
|
1364
|
+
function At() {
|
|
1365
|
+
return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0 }, children: [
|
|
1366
|
+
/* @__PURE__ */ e("circle", { cx: "5", cy: "6", r: "3.5", stroke: "#ca8a04", strokeWidth: "1.4" }),
|
|
1367
|
+
/* @__PURE__ */ e("path", { d: "M8 7.5l4.5 4.5M10.5 10l1.5 1.5", stroke: "#ca8a04", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1368
|
+
] });
|
|
1369
|
+
}
|
|
1370
|
+
function Ot() {
|
|
1371
|
+
return /* @__PURE__ */ n("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", style: { flexShrink: 0, marginTop: 1 }, children: [
|
|
1372
|
+
/* @__PURE__ */ e("circle", { cx: "7", cy: "7", r: "6", stroke: "currentColor", strokeWidth: "1.5" }),
|
|
1373
|
+
/* @__PURE__ */ e("path", { d: "M7 6v5M7 4.5v.01", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
|
|
1374
|
+
] });
|
|
1375
|
+
}
|
|
1376
|
+
let Ue = !1;
|
|
1377
|
+
function Dt() {
|
|
1378
|
+
if (Ue || typeof document > "u") return;
|
|
1379
|
+
Ue = !0;
|
|
1380
|
+
const t = document.createElement("style");
|
|
1381
|
+
t.textContent = "@keyframes ch-spin{to{transform:rotate(360deg)}}", document.head.appendChild(t);
|
|
1382
|
+
}
|
|
1383
|
+
function Xt({ apiUrl: t, token: i, onConnectionChange: r }) {
|
|
1384
|
+
const o = t.replace(/\/$/, ""), [p, f] = k([]), [b, B] = k(!0), [h, y] = k({ name: "list" }), [C, S] = k(null), [H, I] = k(!1), [W, V] = k(""), [G, E] = k(""), [P, J] = k(""), [w, F] = k(""), [N, g] = k(!1), [z, L] = k(!1), R = Q(null);
|
|
1385
|
+
Dt();
|
|
1386
|
+
const O = Ce(async () => {
|
|
1387
|
+
try {
|
|
1388
|
+
const l = await fetch(`${o}/v1/connections`, {
|
|
1389
|
+
headers: { authorization: `Bearer ${i}` }
|
|
1390
|
+
});
|
|
1391
|
+
if (!l.ok) throw new Error("Không tải được kênh");
|
|
1392
|
+
const m = await l.json();
|
|
1393
|
+
f(m), r == null || r(m);
|
|
1394
|
+
} catch (l) {
|
|
1395
|
+
S(l instanceof Error ? l.message : "Lỗi tải dữ liệu");
|
|
1396
|
+
} finally {
|
|
1397
|
+
B(!1);
|
|
1398
|
+
}
|
|
1399
|
+
}, [o, i, r]);
|
|
1400
|
+
q(() => {
|
|
1401
|
+
O();
|
|
1402
|
+
}, [O]), q(() => {
|
|
1403
|
+
if (!C) return;
|
|
1404
|
+
const l = setTimeout(() => S(null), 5e3);
|
|
1405
|
+
return () => clearTimeout(l);
|
|
1406
|
+
}, [C]), q(() => () => {
|
|
1407
|
+
R.current && window.removeEventListener("message", R.current);
|
|
1408
|
+
}, []);
|
|
1409
|
+
async function x(l, m) {
|
|
1410
|
+
if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${m}"?
|
|
1411
|
+
|
|
1412
|
+
Hành động này không thể hoàn tác.`))
|
|
1413
|
+
try {
|
|
1414
|
+
if (!(await fetch(`${o}/v1/connections/${l}`, {
|
|
1415
|
+
method: "DELETE",
|
|
1416
|
+
headers: { authorization: `Bearer ${i}` }
|
|
1417
|
+
})).ok) throw new Error("Không thể ngắt kết nối");
|
|
1418
|
+
await O();
|
|
1419
|
+
} catch (v) {
|
|
1420
|
+
S(v instanceof Error ? v.message : "Lỗi ngắt kết nối");
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
async function X() {
|
|
1424
|
+
if (!W.trim()) {
|
|
1425
|
+
S("Vui lòng nhập Bot Token");
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1428
|
+
if (!/^\d+:[A-Za-z0-9_-]+$/.test(W.trim())) {
|
|
1429
|
+
S("Token không đúng định dạng");
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
I(!0), S(null);
|
|
1433
|
+
try {
|
|
1434
|
+
const l = await fetch(`${o}/v1/connect/telegram/start`, {
|
|
1435
|
+
method: "POST",
|
|
1436
|
+
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
1437
|
+
body: JSON.stringify({ botToken: W.trim(), displayName: G.trim() || void 0 })
|
|
1438
|
+
}), m = await l.json();
|
|
1439
|
+
if (!l.ok || !m.connectionId) throw new Error(m.message ?? "Không thể kết nối Telegram");
|
|
1440
|
+
V(""), E(""), await O(), y({ name: "list" });
|
|
1441
|
+
} catch (l) {
|
|
1442
|
+
S(l instanceof Error ? l.message : "Lỗi kết nối");
|
|
1443
|
+
} finally {
|
|
1444
|
+
I(!1);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
async function ee() {
|
|
1448
|
+
if (!P.trim()) {
|
|
1449
|
+
S("Vui lòng nhập tên widget");
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
I(!0), S(null);
|
|
1453
|
+
try {
|
|
1454
|
+
const l = w.split(/[\n,]+/).map(($) => $.trim()).filter(Boolean), m = await fetch(`${o}/v1/connect/livechat/start`, {
|
|
1455
|
+
method: "POST",
|
|
1456
|
+
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
1457
|
+
body: JSON.stringify({ displayName: P.trim(), allowedDomains: l.length ? l : void 0 })
|
|
1458
|
+
}), v = await m.json();
|
|
1459
|
+
if (!m.ok || !v.connectionId || !v.embedScript) throw new Error(v.message ?? "Không thể tạo widget");
|
|
1460
|
+
J(""), F(""), await O(), y({
|
|
1461
|
+
name: "livechat-result",
|
|
1462
|
+
connectionId: v.connectionId,
|
|
1463
|
+
embedScript: v.embedScript,
|
|
1464
|
+
identitySecret: v.identitySecret ?? "",
|
|
1465
|
+
allowedDomains: v.allowedDomains ?? []
|
|
1466
|
+
});
|
|
1467
|
+
} catch (l) {
|
|
1468
|
+
S(l instanceof Error ? l.message : "Lỗi tạo widget");
|
|
1469
|
+
} finally {
|
|
1470
|
+
I(!1);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
async function Y(l) {
|
|
1474
|
+
S(null);
|
|
1475
|
+
try {
|
|
1476
|
+
const m = `${o}/static/oauth-popup.html`, v = await fetch(`${o}/v1/connect/${l}/start`, {
|
|
1477
|
+
method: "POST",
|
|
1478
|
+
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
1479
|
+
body: JSON.stringify({ callbackUrl: m })
|
|
1480
|
+
}), $ = await v.json();
|
|
1481
|
+
if (!v.ok || !$.authorizationUrl) throw new Error($.message ?? "Không thể bắt đầu kết nối");
|
|
1482
|
+
const T = window.open($.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
|
|
1483
|
+
y({ name: "oauth-waiting", provider: l, popup: T }), R.current && window.removeEventListener("message", R.current);
|
|
1484
|
+
const U = (j) => {
|
|
1485
|
+
if (j.data) {
|
|
1486
|
+
if (j.data.type === "channelhub:oauth-select") {
|
|
1487
|
+
y({
|
|
1488
|
+
name: "oauth-select",
|
|
1489
|
+
provider: j.data.provider,
|
|
1490
|
+
sessionId: String(j.data.sessionId ?? ""),
|
|
1491
|
+
pages: j.data.pages ?? [],
|
|
1492
|
+
popup: T
|
|
1493
|
+
});
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1496
|
+
j.data.type === "channelhub:oauth" && (window.removeEventListener("message", U), R.current = null, j.data.status === "active" ? (O(), y({ name: "list" })) : (S("Kết nối thất bại: " + String(j.data.error ?? "Không xác định")), y({ name: "list" })));
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
R.current = U, window.addEventListener("message", U);
|
|
1500
|
+
} catch (m) {
|
|
1501
|
+
S(m instanceof Error ? m.message : "Lỗi kết nối"), y({ name: "list" });
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
function re(l, m) {
|
|
1505
|
+
navigator.clipboard.writeText(l).then(() => {
|
|
1506
|
+
m === "script" ? (g(!0), setTimeout(() => g(!1), 2e3)) : (L(!0), setTimeout(() => L(!1), 2e3));
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
function te() {
|
|
1510
|
+
const l = h.name === "oauth-waiting" || h.name === "oauth-select" ? h.popup : null;
|
|
1511
|
+
if (l)
|
|
1512
|
+
try {
|
|
1513
|
+
l.close();
|
|
1514
|
+
} catch {
|
|
1515
|
+
}
|
|
1516
|
+
R.current && (window.removeEventListener("message", R.current), R.current = null), y({ name: "add" });
|
|
1517
|
+
}
|
|
1518
|
+
async function ne(l) {
|
|
1519
|
+
if (h.name !== "oauth-select") return;
|
|
1520
|
+
const { provider: m, sessionId: v, popup: $ } = h;
|
|
1521
|
+
I(!0), S(null);
|
|
1522
|
+
const T = {
|
|
1523
|
+
facebook: `${o}/v1/connect/facebook/select-page`,
|
|
1524
|
+
instagram: `${o}/v1/connect/instagram/select-account`,
|
|
1525
|
+
zalo: `${o}/v1/connect/zalo/select-oa`
|
|
1526
|
+
}, U = {
|
|
1527
|
+
facebook: "pageId",
|
|
1528
|
+
instagram: "accountId",
|
|
1529
|
+
zalo: "oaId"
|
|
1530
|
+
};
|
|
1531
|
+
try {
|
|
1532
|
+
const j = await fetch(T[m] ?? `${o}/v1/connect/${m}/select-page`, {
|
|
1533
|
+
method: "POST",
|
|
1534
|
+
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
1535
|
+
body: JSON.stringify({ sessionId: v, [U[m] ?? "pageId"]: l })
|
|
1536
|
+
}), se = await j.json();
|
|
1537
|
+
if (!j.ok || !se.connectionId) throw new Error(se.message ?? "Không thể kết nối");
|
|
1538
|
+
if ($)
|
|
1539
|
+
try {
|
|
1540
|
+
$.postMessage({ type: "channelhub:close-popup" }, "*");
|
|
1541
|
+
} catch {
|
|
1542
|
+
}
|
|
1543
|
+
R.current && (window.removeEventListener("message", R.current), R.current = null), await O(), y({ name: "list" });
|
|
1544
|
+
} catch (j) {
|
|
1545
|
+
S(j instanceof Error ? j.message : "Lỗi kết nối");
|
|
1546
|
+
} finally {
|
|
1547
|
+
I(!1);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return /* @__PURE__ */ n("div", { style: a.root, children: [
|
|
1551
|
+
C && /* @__PURE__ */ e("div", { style: a.errorBanner, children: C }),
|
|
1552
|
+
h.name === "list" && /* @__PURE__ */ n(K, { children: [
|
|
1553
|
+
/* @__PURE__ */ n("div", { style: a.header, children: [
|
|
1554
|
+
/* @__PURE__ */ e("div", { style: a.headerLeft, children: /* @__PURE__ */ n("div", { children: [
|
|
1555
|
+
/* @__PURE__ */ e("div", { style: a.title, children: "Kênh kết nối" }),
|
|
1556
|
+
/* @__PURE__ */ e("div", { style: a.subtitle, children: b ? "Đang tải…" : `${p.filter((l) => l.status === "active").length} kênh đang hoạt động` })
|
|
1557
|
+
] }) }),
|
|
1558
|
+
/* @__PURE__ */ n("button", { style: a.addBtn, onClick: () => y({ name: "add" }), children: [
|
|
1559
|
+
/* @__PURE__ */ e(Ae, {}),
|
|
1560
|
+
/* @__PURE__ */ e("span", { children: "Thêm kênh" })
|
|
1561
|
+
] })
|
|
1562
|
+
] }),
|
|
1563
|
+
/* @__PURE__ */ e("div", { style: a.divider }),
|
|
1564
|
+
/* @__PURE__ */ e("div", { style: a.body, children: !b && p.length === 0 ? /* @__PURE__ */ n("div", { style: a.empty, children: [
|
|
1565
|
+
/* @__PURE__ */ e("div", { style: { width: 64, height: 64, borderRadius: 16, background: "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ie, { provider: "livechat", apiUrl: o, size: 40 }) }),
|
|
1566
|
+
/* @__PURE__ */ e("div", { style: a.emptyTitle, children: "Chưa có kênh nào được kết nối" }),
|
|
1567
|
+
/* @__PURE__ */ e("div", { style: a.emptyDesc, children: "Kết nối Facebook, Zalo OA, Telegram hoặc Live Chat để bắt đầu nhận tin nhắn từ khách hàng." }),
|
|
1568
|
+
/* @__PURE__ */ n("button", { style: a.emptyCta, onClick: () => y({ name: "add" }), children: [
|
|
1569
|
+
/* @__PURE__ */ e(Ae, {}),
|
|
1570
|
+
"Kết nối kênh đầu tiên"
|
|
1571
|
+
] })
|
|
1572
|
+
] }) : /* @__PURE__ */ e("div", { children: p.map((l) => /* @__PURE__ */ e(
|
|
1573
|
+
Pt,
|
|
1574
|
+
{
|
|
1575
|
+
conn: l,
|
|
1576
|
+
apiUrl: o,
|
|
1577
|
+
onDisconnect: () => void x(l.id, ze(l))
|
|
1578
|
+
},
|
|
1579
|
+
l.id
|
|
1580
|
+
)) }) })
|
|
1581
|
+
] }),
|
|
1582
|
+
h.name === "add" && /* @__PURE__ */ n(K, { children: [
|
|
1583
|
+
/* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
|
|
1584
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => y({ name: "list" }), children: /* @__PURE__ */ e(ae, {}) }),
|
|
1585
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1586
|
+
/* @__PURE__ */ e("div", { style: a.title, children: "Thêm kênh mới" }),
|
|
1587
|
+
/* @__PURE__ */ e("div", { style: a.subtitle, children: "Chọn nền tảng bạn muốn kết nối" })
|
|
1588
|
+
] })
|
|
1589
|
+
] }) }),
|
|
1590
|
+
/* @__PURE__ */ e("div", { style: a.divider }),
|
|
1591
|
+
/* @__PURE__ */ e("div", { style: a.body, children: /* @__PURE__ */ e("div", { style: a.providerGrid, children: Ft.map((l) => /* @__PURE__ */ e(
|
|
1592
|
+
Nt,
|
|
1593
|
+
{
|
|
1594
|
+
provider: l,
|
|
1595
|
+
apiUrl: o,
|
|
1596
|
+
onClick: () => {
|
|
1597
|
+
l.type === "oauth" ? Y(l.id) : l.id === "telegram" ? y({ name: "connect-telegram" }) : y({ name: "connect-livechat" });
|
|
1598
|
+
}
|
|
1599
|
+
},
|
|
1600
|
+
l.id
|
|
1601
|
+
)) }) })
|
|
1602
|
+
] }),
|
|
1603
|
+
h.name === "connect-telegram" && /* @__PURE__ */ n(K, { children: [
|
|
1604
|
+
/* @__PURE__ */ n("div", { style: a.connectHeader, children: [
|
|
1605
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => y({ name: "add" }), children: /* @__PURE__ */ e(ae, {}) }),
|
|
1606
|
+
/* @__PURE__ */ e(ie, { provider: "telegram", apiUrl: o, size: 44 }),
|
|
1607
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1608
|
+
/* @__PURE__ */ e("div", { style: a.connectTitle, children: "Kết nối Telegram Bot" }),
|
|
1609
|
+
/* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhập Bot Token để bắt đầu nhận tin nhắn" })
|
|
1610
|
+
] })
|
|
1611
|
+
] }),
|
|
1612
|
+
/* @__PURE__ */ n("div", { style: a.form, children: [
|
|
1613
|
+
/* @__PURE__ */ n("div", { style: a.infoBox, children: [
|
|
1614
|
+
/* @__PURE__ */ e(Ot, {}),
|
|
1615
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1616
|
+
"Tạo bot mới bằng cách nhắn tin cho ",
|
|
1617
|
+
/* @__PURE__ */ e("strong", { children: "@BotFather" }),
|
|
1618
|
+
" trên Telegram, dùng lệnh ",
|
|
1619
|
+
/* @__PURE__ */ e("strong", { children: "/newbot" }),
|
|
1620
|
+
" rồi sao chép token được cấp."
|
|
1621
|
+
] })
|
|
1622
|
+
] }),
|
|
1623
|
+
/* @__PURE__ */ n("div", { style: a.field, children: [
|
|
1624
|
+
/* @__PURE__ */ n("label", { style: a.label, children: [
|
|
1625
|
+
"Bot Token ",
|
|
1626
|
+
/* @__PURE__ */ e("span", { style: a.labelHint, children: "bắt buộc" })
|
|
1627
|
+
] }),
|
|
1628
|
+
/* @__PURE__ */ e(
|
|
1629
|
+
"input",
|
|
1630
|
+
{
|
|
1631
|
+
style: a.input,
|
|
1632
|
+
type: "text",
|
|
1633
|
+
value: W,
|
|
1634
|
+
onChange: (l) => V(l.target.value),
|
|
1635
|
+
placeholder: "1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxx",
|
|
1636
|
+
autoComplete: "off",
|
|
1637
|
+
spellCheck: !1
|
|
1638
|
+
}
|
|
1639
|
+
),
|
|
1640
|
+
/* @__PURE__ */ n("div", { style: a.inputHint, children: [
|
|
1641
|
+
"Định dạng: ",
|
|
1642
|
+
/* @__PURE__ */ e("code", { children: "số:ký_tự" }),
|
|
1643
|
+
", ví dụ: ",
|
|
1644
|
+
/* @__PURE__ */ e("code", { children: "1234567890:AAExxxxxxxx" })
|
|
1645
|
+
] })
|
|
1646
|
+
] }),
|
|
1647
|
+
/* @__PURE__ */ n("div", { style: a.field, children: [
|
|
1648
|
+
/* @__PURE__ */ n("label", { style: a.label, children: [
|
|
1649
|
+
"Tên hiển thị ",
|
|
1650
|
+
/* @__PURE__ */ e("span", { style: a.labelHint, children: "tùy chọn" })
|
|
1651
|
+
] }),
|
|
1652
|
+
/* @__PURE__ */ e(
|
|
1653
|
+
"input",
|
|
1654
|
+
{
|
|
1655
|
+
style: a.input,
|
|
1656
|
+
type: "text",
|
|
1657
|
+
value: G,
|
|
1658
|
+
onChange: (l) => E(l.target.value),
|
|
1659
|
+
placeholder: "VD: Bot hỗ trợ cửa hàng"
|
|
1660
|
+
}
|
|
1661
|
+
)
|
|
1662
|
+
] }),
|
|
1663
|
+
/* @__PURE__ */ n("div", { style: a.formActions, children: [
|
|
1664
|
+
/* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => y({ name: "add" }), children: "Hủy" }),
|
|
1665
|
+
/* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void X(), children: H ? "Đang kết nối…" : "Kết nối Telegram" })
|
|
1666
|
+
] })
|
|
1667
|
+
] })
|
|
1668
|
+
] }),
|
|
1669
|
+
h.name === "connect-livechat" && /* @__PURE__ */ n(K, { children: [
|
|
1670
|
+
/* @__PURE__ */ n("div", { style: a.connectHeader, children: [
|
|
1671
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => y({ name: "add" }), children: /* @__PURE__ */ e(ae, {}) }),
|
|
1672
|
+
/* @__PURE__ */ e(ie, { provider: "livechat", apiUrl: o, size: 44 }),
|
|
1673
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1674
|
+
/* @__PURE__ */ e("div", { style: a.connectTitle, children: "Tạo Live Chat Widget" }),
|
|
1675
|
+
/* @__PURE__ */ e("div", { style: a.connectDesc, children: "Nhúng vào website để nhận tin nhắn từ khách hàng" })
|
|
1676
|
+
] })
|
|
1677
|
+
] }),
|
|
1678
|
+
/* @__PURE__ */ n("div", { style: a.form, children: [
|
|
1679
|
+
/* @__PURE__ */ n("div", { style: a.field, children: [
|
|
1680
|
+
/* @__PURE__ */ n("label", { style: a.label, children: [
|
|
1681
|
+
"Tên widget ",
|
|
1682
|
+
/* @__PURE__ */ e("span", { style: a.labelHint, children: "bắt buộc" })
|
|
1683
|
+
] }),
|
|
1684
|
+
/* @__PURE__ */ e(
|
|
1685
|
+
"input",
|
|
1686
|
+
{
|
|
1687
|
+
style: a.input,
|
|
1688
|
+
type: "text",
|
|
1689
|
+
value: P,
|
|
1690
|
+
onChange: (l) => J(l.target.value),
|
|
1691
|
+
placeholder: "VD: Hỗ trợ website hanashop.vn"
|
|
1692
|
+
}
|
|
1693
|
+
)
|
|
1694
|
+
] }),
|
|
1695
|
+
/* @__PURE__ */ n("div", { style: a.field, children: [
|
|
1696
|
+
/* @__PURE__ */ n("label", { style: a.label, children: [
|
|
1697
|
+
"Tên miền được phép ",
|
|
1698
|
+
/* @__PURE__ */ e("span", { style: a.labelHint, children: "tùy chọn" })
|
|
1699
|
+
] }),
|
|
1700
|
+
/* @__PURE__ */ e(
|
|
1701
|
+
"textarea",
|
|
1702
|
+
{
|
|
1703
|
+
style: { ...a.input, resize: "vertical", minHeight: 80, lineHeight: 1.5 },
|
|
1704
|
+
value: w,
|
|
1705
|
+
onChange: (l) => F(l.target.value),
|
|
1706
|
+
placeholder: `https://myshop.com
|
|
1707
|
+
https://www.myshop.com`,
|
|
1708
|
+
spellCheck: !1
|
|
1709
|
+
}
|
|
1710
|
+
),
|
|
1711
|
+
/* @__PURE__ */ e("div", { style: a.inputHint, children: "Mỗi domain một dòng. Để trống để cho phép tất cả." })
|
|
1712
|
+
] }),
|
|
1713
|
+
/* @__PURE__ */ n("div", { style: a.formActions, children: [
|
|
1714
|
+
/* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => y({ name: "add" }), children: "Hủy" }),
|
|
1715
|
+
/* @__PURE__ */ e("button", { style: a.btnPrimary, disabled: H, onClick: () => void ee(), children: H ? "Đang tạo…" : "Tạo widget" })
|
|
1716
|
+
] })
|
|
1717
|
+
] })
|
|
1718
|
+
] }),
|
|
1719
|
+
h.name === "livechat-result" && /* @__PURE__ */ n(K, { children: [
|
|
1720
|
+
/* @__PURE__ */ n("div", { style: a.connectHeader, children: [
|
|
1721
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: () => y({ name: "list" }), children: /* @__PURE__ */ e(ae, {}) }),
|
|
1722
|
+
/* @__PURE__ */ e(ie, { provider: "livechat", apiUrl: o, size: 44 }),
|
|
1723
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1724
|
+
/* @__PURE__ */ e("div", { style: a.connectTitle, children: "Widget đã được tạo!" }),
|
|
1725
|
+
/* @__PURE__ */ e("div", { style: a.connectDesc, children: "Sao chép mã nhúng và dán vào website của bạn" })
|
|
1726
|
+
] })
|
|
1727
|
+
] }),
|
|
1728
|
+
/* @__PURE__ */ n("div", { style: a.form, children: [
|
|
1729
|
+
/* @__PURE__ */ n("div", { style: a.resultBanner, children: [
|
|
1730
|
+
/* @__PURE__ */ e("span", { style: { fontSize: 16, flexShrink: 0 }, children: "✅" }),
|
|
1731
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1732
|
+
/* @__PURE__ */ e("strong", { children: "Tạo thành công!" }),
|
|
1733
|
+
" Dán đoạn script dưới đây vào thẻ ",
|
|
1734
|
+
/* @__PURE__ */ e("code", { style: { background: "#dcfce7", padding: "1px 4px", borderRadius: 4 }, children: "</body>" }),
|
|
1735
|
+
" của website."
|
|
1736
|
+
] })
|
|
1737
|
+
] }),
|
|
1738
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1739
|
+
/* @__PURE__ */ e("div", { style: a.codeLabel, children: "Mã nhúng" }),
|
|
1740
|
+
/* @__PURE__ */ n("div", { style: a.codeBlock, children: [
|
|
1741
|
+
/* @__PURE__ */ e("pre", { style: a.codePre, children: h.embedScript }),
|
|
1742
|
+
/* @__PURE__ */ e("button", { style: { ...a.copyBtn, ...N ? { background: "#166534", borderColor: "#166534", color: "#bbf7d0" } : {} }, onClick: () => re(h.embedScript, "script"), children: N ? /* @__PURE__ */ n(K, { children: [
|
|
1743
|
+
/* @__PURE__ */ e(De, {}),
|
|
1744
|
+
" Đã sao chép"
|
|
1745
|
+
] }) : /* @__PURE__ */ n(K, { children: [
|
|
1746
|
+
/* @__PURE__ */ e(Oe, {}),
|
|
1747
|
+
" Sao chép"
|
|
1748
|
+
] }) })
|
|
1749
|
+
] })
|
|
1750
|
+
] }),
|
|
1751
|
+
h.identitySecret && /* @__PURE__ */ n("div", { children: [
|
|
1752
|
+
/* @__PURE__ */ n("div", { style: a.codeLabel, children: [
|
|
1753
|
+
"Identity Secret ",
|
|
1754
|
+
/* @__PURE__ */ e("span", { style: { ...a.labelHint, color: "#dc2626", fontWeight: 600 }, children: "Lưu ngay — chỉ hiển thị một lần" })
|
|
1755
|
+
] }),
|
|
1756
|
+
/* @__PURE__ */ n("div", { style: a.secretRow, children: [
|
|
1757
|
+
/* @__PURE__ */ e(At, {}),
|
|
1758
|
+
/* @__PURE__ */ e("span", { style: a.secretLabel, children: "Secret:" }),
|
|
1759
|
+
/* @__PURE__ */ e("span", { style: a.secretValue, children: h.identitySecret }),
|
|
1760
|
+
/* @__PURE__ */ e(
|
|
1761
|
+
"button",
|
|
1762
|
+
{
|
|
1763
|
+
onClick: () => re(h.identitySecret, "secret"),
|
|
1764
|
+
style: { border: "none", background: "transparent", cursor: "pointer", color: z ? "#059669" : "#ca8a04", padding: 2, display: "flex", alignItems: "center" },
|
|
1765
|
+
children: z ? /* @__PURE__ */ e(De, {}) : /* @__PURE__ */ e(Oe, {})
|
|
1766
|
+
}
|
|
1767
|
+
)
|
|
1768
|
+
] }),
|
|
1769
|
+
/* @__PURE__ */ e("div", { style: { ...a.inputHint, marginTop: 6 }, children: "Dùng secret này để xác thực danh tính người dùng (HMAC). Giữ bí mật — không chia sẻ nơi công khai." })
|
|
1770
|
+
] }),
|
|
1771
|
+
/* @__PURE__ */ n("div", { style: a.formActions, children: [
|
|
1772
|
+
/* @__PURE__ */ e("button", { style: a.btnSecondary, onClick: () => y({ name: "list" }), children: "Về danh sách" }),
|
|
1773
|
+
/* @__PURE__ */ e("button", { style: a.btnPrimary, onClick: () => y({ name: "add" }), children: "Thêm kênh khác" })
|
|
1774
|
+
] })
|
|
1775
|
+
] })
|
|
1776
|
+
] }),
|
|
1777
|
+
h.name === "oauth-waiting" && /* @__PURE__ */ n(K, { children: [
|
|
1778
|
+
/* @__PURE__ */ e("div", { style: a.header, children: /* @__PURE__ */ n("div", { style: a.headerLeft, children: [
|
|
1779
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: te, children: /* @__PURE__ */ e(ae, {}) }),
|
|
1780
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1781
|
+
/* @__PURE__ */ n("div", { style: a.title, children: [
|
|
1782
|
+
"Đang xác thực ",
|
|
1783
|
+
de[h.provider]
|
|
1784
|
+
] }),
|
|
1785
|
+
/* @__PURE__ */ e("div", { style: a.subtitle, children: "Vui lòng hoàn thành trong cửa sổ bật lên" })
|
|
1786
|
+
] })
|
|
1787
|
+
] }) }),
|
|
1788
|
+
/* @__PURE__ */ n("div", { style: a.oauthWaiting, children: [
|
|
1789
|
+
/* @__PURE__ */ n("div", { style: { position: "relative", width: 72, height: 72 }, children: [
|
|
1790
|
+
/* @__PURE__ */ e("div", { style: { width: 72, height: 72, borderRadius: 20, background: jt[h.provider] ?? "#f1f5f9", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ie, { provider: h.provider, apiUrl: o, size: 48 }) }),
|
|
1791
|
+
/* @__PURE__ */ n(
|
|
1792
|
+
"svg",
|
|
1793
|
+
{
|
|
1794
|
+
width: 92,
|
|
1795
|
+
height: 92,
|
|
1796
|
+
viewBox: "0 0 92 92",
|
|
1797
|
+
fill: "none",
|
|
1798
|
+
style: { position: "absolute", top: -10, left: -10, animation: "ch-spin 1.2s linear infinite" },
|
|
1799
|
+
children: [
|
|
1800
|
+
/* @__PURE__ */ e("circle", { cx: "46", cy: "46", r: "42", stroke: "#e2e8f0", strokeWidth: "3.5" }),
|
|
1801
|
+
/* @__PURE__ */ e(
|
|
1802
|
+
"circle",
|
|
1803
|
+
{
|
|
1804
|
+
cx: "46",
|
|
1805
|
+
cy: "46",
|
|
1806
|
+
r: "42",
|
|
1807
|
+
stroke: "#2563eb",
|
|
1808
|
+
strokeWidth: "3.5",
|
|
1809
|
+
strokeLinecap: "round",
|
|
1810
|
+
strokeDasharray: "66 198"
|
|
1811
|
+
}
|
|
1812
|
+
)
|
|
1813
|
+
]
|
|
1814
|
+
}
|
|
1815
|
+
)
|
|
1816
|
+
] }),
|
|
1817
|
+
/* @__PURE__ */ n("div", { style: a.oauthTitle, children: [
|
|
1818
|
+
"Đang chờ xác thực với ",
|
|
1819
|
+
de[h.provider]
|
|
1820
|
+
] }),
|
|
1821
|
+
/* @__PURE__ */ e("div", { style: a.oauthDesc, children: "Một cửa sổ đăng nhập đã được mở. Vui lòng đăng nhập và cấp quyền truy cập để hoàn tất kết nối." }),
|
|
1822
|
+
/* @__PURE__ */ n("div", { style: { display: "flex", flexDirection: "column", gap: 8, alignItems: "flex-start", width: "100%", maxWidth: 280 }, children: [
|
|
1823
|
+
/* @__PURE__ */ e(xe, { done: !0, label: `Đã mở cửa sổ ${de[h.provider]}` }),
|
|
1824
|
+
/* @__PURE__ */ e(xe, { active: !0, label: "Đang chờ bạn đăng nhập & cấp quyền" }),
|
|
1825
|
+
/* @__PURE__ */ e(xe, { label: "Lưu kết nối & quay về" })
|
|
1826
|
+
] }),
|
|
1827
|
+
/* @__PURE__ */ e("button", { style: a.oauthCancel, onClick: te, children: "Hủy và quay lại" })
|
|
1828
|
+
] })
|
|
1829
|
+
] }),
|
|
1830
|
+
h.name === "oauth-select" && /* @__PURE__ */ n(K, { children: [
|
|
1831
|
+
/* @__PURE__ */ n("div", { style: a.connectHeader, children: [
|
|
1832
|
+
/* @__PURE__ */ e("button", { style: a.backBtn, onClick: te, children: /* @__PURE__ */ e(ae, {}) }),
|
|
1833
|
+
/* @__PURE__ */ e(ie, { provider: h.provider, apiUrl: o, size: 44 }),
|
|
1834
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1835
|
+
/* @__PURE__ */ n("div", { style: a.connectTitle, children: [
|
|
1836
|
+
"Chọn ",
|
|
1837
|
+
h.provider === "instagram" ? "tài khoản" : "trang"
|
|
1838
|
+
] }),
|
|
1839
|
+
/* @__PURE__ */ n("div", { style: a.connectDesc, children: [
|
|
1840
|
+
"Chọn ",
|
|
1841
|
+
de[h.provider],
|
|
1842
|
+
" bạn muốn kết nối với ChannelHub"
|
|
1843
|
+
] })
|
|
1844
|
+
] })
|
|
1845
|
+
] }),
|
|
1846
|
+
/* @__PURE__ */ e("div", { style: a.body, children: h.pages.length === 0 ? /* @__PURE__ */ e("div", { style: { textAlign: "center", color: "#94a3b8", fontSize: 13, padding: "24px 0" }, children: "Không tìm thấy trang/tài khoản nào. Hãy thử lại." }) : /* @__PURE__ */ e("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: h.pages.map((l) => /* @__PURE__ */ n(
|
|
1847
|
+
"button",
|
|
1848
|
+
{
|
|
1849
|
+
disabled: H,
|
|
1850
|
+
onClick: () => void ne(l.id),
|
|
1851
|
+
style: {
|
|
1852
|
+
display: "flex",
|
|
1853
|
+
alignItems: "center",
|
|
1854
|
+
justifyContent: "space-between",
|
|
1855
|
+
padding: "12px 16px",
|
|
1856
|
+
borderRadius: 12,
|
|
1857
|
+
border: "1.5px solid #e2e8f0",
|
|
1858
|
+
background: "#fff",
|
|
1859
|
+
cursor: H ? "not-allowed" : "pointer",
|
|
1860
|
+
opacity: H ? 0.6 : 1,
|
|
1861
|
+
textAlign: "left",
|
|
1862
|
+
fontFamily: "inherit",
|
|
1863
|
+
transition: "border-color .15s, background .15s"
|
|
1864
|
+
},
|
|
1865
|
+
children: [
|
|
1866
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1867
|
+
/* @__PURE__ */ e("div", { style: { fontSize: 14, fontWeight: 600, color: "#0f172a" }, children: l.name }),
|
|
1868
|
+
/* @__PURE__ */ e("div", { style: { fontSize: 11, color: "#94a3b8", fontFamily: "monospace", marginTop: 2 }, children: l.id })
|
|
1869
|
+
] }),
|
|
1870
|
+
/* @__PURE__ */ e("span", { style: { fontSize: 13, color: "#2563eb", fontWeight: 500 }, children: H ? "Đang kết nối…" : "Chọn →" })
|
|
1871
|
+
]
|
|
1872
|
+
},
|
|
1873
|
+
l.id
|
|
1874
|
+
)) }) })
|
|
1875
|
+
] })
|
|
1876
|
+
] });
|
|
1877
|
+
}
|
|
1878
|
+
function Ut(t) {
|
|
1879
|
+
const i = t.metadata;
|
|
1880
|
+
if (typeof i.pictureUrl == "string") return i.pictureUrl;
|
|
1881
|
+
if (t.provider === "facebook")
|
|
1882
|
+
return `https://graph.facebook.com/${t.externalAccountId}/picture?type=square`;
|
|
1883
|
+
if (t.provider === "instagram") {
|
|
1884
|
+
const r = typeof i.pageId == "string" ? i.pageId : null;
|
|
1885
|
+
if (r) return `https://graph.facebook.com/${r}/picture?type=square`;
|
|
1886
|
+
}
|
|
1887
|
+
return null;
|
|
1888
|
+
}
|
|
1889
|
+
function Et({ conn: t, apiUrl: i, size: r = 40 }) {
|
|
1890
|
+
const [o, p] = k(!1), f = Ut(t), b = Math.round(r * 0.28);
|
|
1891
|
+
return f && !o ? /* @__PURE__ */ e(
|
|
1892
|
+
"img",
|
|
1893
|
+
{
|
|
1894
|
+
src: f,
|
|
1895
|
+
alt: ze(t),
|
|
1896
|
+
referrerPolicy: "no-referrer",
|
|
1897
|
+
onError: () => p(!0),
|
|
1898
|
+
style: { width: r, height: r, borderRadius: b, objectFit: "cover", flexShrink: 0, display: "block" }
|
|
1899
|
+
}
|
|
1900
|
+
) : /* @__PURE__ */ e(ie, { provider: t.provider, apiUrl: i, size: r });
|
|
1901
|
+
}
|
|
1902
|
+
function Pt({ conn: t, apiUrl: i, onDisconnect: r }) {
|
|
1903
|
+
const [o, p] = k(!1);
|
|
1904
|
+
return /* @__PURE__ */ n("div", { style: a.channelItem, children: [
|
|
1905
|
+
/* @__PURE__ */ e(Et, { conn: t, apiUrl: i, size: 40 }),
|
|
1906
|
+
/* @__PURE__ */ n("div", { style: a.channelInfo, children: [
|
|
1907
|
+
/* @__PURE__ */ e("div", { style: a.channelName, children: ze(t) }),
|
|
1908
|
+
/* @__PURE__ */ e("div", { style: a.channelMeta, children: Mt(t) })
|
|
1909
|
+
] }),
|
|
1910
|
+
/* @__PURE__ */ n("div", { style: a.channelActions, children: [
|
|
1911
|
+
/* @__PURE__ */ e("span", { style: t.status === "active" ? a.badgeActive : a.badgeInactive, children: t.status === "active" ? "Hoạt động" : t.status }),
|
|
1912
|
+
/* @__PURE__ */ e(
|
|
1913
|
+
"button",
|
|
1914
|
+
{
|
|
1915
|
+
style: {
|
|
1916
|
+
...a.disconnectBtn,
|
|
1917
|
+
...o ? { background: "#fef2f2", borderColor: "#fca5a5", color: "#dc2626" } : {}
|
|
1918
|
+
},
|
|
1919
|
+
onMouseEnter: () => p(!0),
|
|
1920
|
+
onMouseLeave: () => p(!1),
|
|
1921
|
+
onClick: r,
|
|
1922
|
+
children: "Ngắt kết nối"
|
|
1923
|
+
}
|
|
1924
|
+
)
|
|
1925
|
+
] })
|
|
1926
|
+
] });
|
|
1927
|
+
}
|
|
1928
|
+
const Ft = [
|
|
1929
|
+
{ id: "facebook", name: "Facebook", desc: "Fanpage & Messenger", type: "oauth" },
|
|
1930
|
+
{ id: "zalo", name: "Zalo OA", desc: "Official Account", type: "oauth" },
|
|
1931
|
+
{ id: "instagram", name: "Instagram", desc: "DM & Comments", type: "oauth" },
|
|
1932
|
+
{ id: "telegram", name: "Telegram", desc: "Bot token", type: "token" },
|
|
1933
|
+
{ id: "livechat", name: "Live Chat", desc: "Website widget", type: "livechat" }
|
|
1934
|
+
];
|
|
1935
|
+
function Nt({ provider: t, apiUrl: i, onClick: r }) {
|
|
1936
|
+
const [o, p] = k(!1);
|
|
1937
|
+
return /* @__PURE__ */ n(
|
|
1938
|
+
"div",
|
|
1939
|
+
{
|
|
1940
|
+
style: {
|
|
1941
|
+
...a.providerCard,
|
|
1942
|
+
...o ? { background: "#fff", borderColor: "#e2e8f0", boxShadow: "0 2px 8px rgba(0,0,0,.07)", transform: "translateY(-1px)" } : {}
|
|
1943
|
+
},
|
|
1944
|
+
onClick: r,
|
|
1945
|
+
onMouseEnter: () => p(!0),
|
|
1946
|
+
onMouseLeave: () => p(!1),
|
|
1947
|
+
children: [
|
|
1948
|
+
/* @__PURE__ */ e(ie, { provider: t.id, apiUrl: i, size: 44 }),
|
|
1949
|
+
/* @__PURE__ */ n("div", { children: [
|
|
1950
|
+
/* @__PURE__ */ e("div", { style: a.providerName, children: t.name }),
|
|
1951
|
+
/* @__PURE__ */ e("div", { style: a.providerDesc, children: t.desc })
|
|
1952
|
+
] })
|
|
1953
|
+
]
|
|
1954
|
+
}
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1957
|
+
function xe({ done: t, active: i, label: r }) {
|
|
1958
|
+
return /* @__PURE__ */ n("div", { style: { display: "flex", alignItems: "center", gap: 10, fontSize: 13, color: t ? "#059669" : i ? "#0f172a" : "#94a3b8" }, children: [
|
|
1959
|
+
/* @__PURE__ */ e("div", { style: {
|
|
1960
|
+
width: 10,
|
|
1961
|
+
height: 10,
|
|
1962
|
+
borderRadius: "50%",
|
|
1963
|
+
background: t ? "#059669" : i ? "#2563eb" : "#cbd5e1",
|
|
1964
|
+
flexShrink: 0,
|
|
1965
|
+
...i ? { boxShadow: "0 0 0 3px rgba(37,99,235,.2)" } : {}
|
|
1966
|
+
} }),
|
|
1967
|
+
r
|
|
1968
|
+
] });
|
|
1969
|
+
}
|
|
1970
|
+
console.log("[ChannelHub] widget v0.1.3 loaded");
|
|
1971
|
+
export {
|
|
1972
|
+
Xt as ChannelHubChannels,
|
|
1973
|
+
mt as ChannelHubClient,
|
|
1974
|
+
Gt as ChannelHubInbox
|
|
1975
|
+
};
|