@channelhub/widget 0.0.0-stage → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +36 -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 +114 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2376 -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 +1133 -0
- package/src/LiveChatWidget.tsx +441 -0
- package/src/api.ts +100 -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 +7 -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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ChannelConnection {
|
|
2
|
+
id: string;
|
|
3
|
+
provider: string;
|
|
4
|
+
type: string;
|
|
5
|
+
externalAccountId: string;
|
|
6
|
+
status: string;
|
|
7
|
+
metadata: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface ChannelHubChannelsProps {
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
token: string;
|
|
12
|
+
onConnectionChange?: (connections: ChannelConnection[]) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function ChannelHubChannels({ apiUrl, token, onConnectionChange }: ChannelHubChannelsProps): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=ChannelHubChannels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelHubChannels.d.ts","sourceRoot":"","sources":["../src/ChannelHubChannels.tsx"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAC;CACjE;AA4QD,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,EAAE,uBAAuB,+BAqiBhG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelHubInbox.d.ts","sourceRoot":"","sources":["../src/ChannelHubInbox.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAwE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgF3I,eAAO,MAAM,eAAe,+GA8M1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface LiveChatWidgetProps {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
widgetId: string;
|
|
4
|
+
primaryColor?: string;
|
|
5
|
+
greeting?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
identifier?: string;
|
|
8
|
+
hmac?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function LiveChatWidget({ apiUrl, widgetId, primaryColor, greeting, title, identifier, hmac }: LiveChatWidgetProps): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=LiveChatWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveChatWidget.d.ts","sourceRoot":"","sources":["../src/LiveChatWidget.tsx"],"names":[],"mappings":"AAEA,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAuCD,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAwB,EAAE,QAAwD,EAAE,KAA4B,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,mBAAmB,+BAmO3M"}
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Connection, Conversation, Message, MessageAttachment, Page } from './types.js';
|
|
2
|
+
export declare class ChannelHubClient {
|
|
3
|
+
private readonly apiUrl;
|
|
4
|
+
private readonly token;
|
|
5
|
+
constructor(apiUrl: string, token: string);
|
|
6
|
+
private request;
|
|
7
|
+
listConnections(): Promise<Connection[]>;
|
|
8
|
+
listConversations(cursor?: string): Promise<Page<Conversation>>;
|
|
9
|
+
listMessages(conversationId: string, cursor?: string): Promise<Page<Message>>;
|
|
10
|
+
getMessage(messageId: string): Promise<Message>;
|
|
11
|
+
sendMessage(conversationId: string, text?: string, attachments?: MessageAttachment[]): Promise<unknown>;
|
|
12
|
+
markRead(conversationId: string): Promise<void>;
|
|
13
|
+
listCannedResponses(search?: string): Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
content: string;
|
|
17
|
+
shortcut: string | null;
|
|
18
|
+
}[]>;
|
|
19
|
+
getNote(conversationId: string): Promise<{
|
|
20
|
+
id: string;
|
|
21
|
+
content: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
} | null>;
|
|
24
|
+
upsertNote(conversationId: string, content: string): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
content: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
}>;
|
|
29
|
+
uploadAttachment(file: File): Promise<{
|
|
30
|
+
url: string;
|
|
31
|
+
mimeType: string;
|
|
32
|
+
attachmentType: string;
|
|
33
|
+
}>;
|
|
34
|
+
connectSSE(onEvent: (type: string, data: unknown) => void): () => void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE7F,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAU,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAtC,MAAM,EAAE,MAAM,EAAmB,KAAK,EAAE,MAAM;YAE7D,OAAO;IAerB,eAAe,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAExC,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAI/D,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAI7E,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/C,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAQjG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,EAAE,CAAC;IAKxH,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAInG,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAO1G,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IAUtG,UAAU,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI;CAuBvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderLogo.d.ts","sourceRoot":"","sources":["../../src/channels/ProviderLogo.tsx"],"names":[],"mappings":"AAAA,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAoBD,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAS,EAAE,EAAE,iBAAiB,+BAkC9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../../src/components/ui/avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,wBAAgB,MAAM,CAAC,EAAE,GAAG,EAAE,GAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAAE,+BAAsQ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from 'react';
|
|
2
|
+
export declare function Button({ variant, style, ...props }: ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
3
|
+
variant?: 'default' | 'ghost' | 'outline';
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/components/ui/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAClD,wBAAgB,MAAM,CAAC,EAAE,OAAiB,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;CAAE,+BAErJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/components/ui/input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACjD,wBAAgB,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,+BAAsJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export declare const ScrollArea: import("react").ForwardRefExoticComponent<{
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
style?: React.CSSProperties;
|
|
5
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
6
|
+
//# sourceMappingURL=scroll-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-area.d.ts","sourceRoot":"","sources":["../../../src/components/ui/scroll-area.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,eAAO,MAAM,UAAU;cAA0C,SAAS;YAAU,KAAK,CAAC,aAAa;kDAEtG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/components/ui/textarea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AACpD,eAAO,MAAM,QAAQ,6IAIpB,CAAC"}
|
|
Binary file
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),Ae=require("react-dom");/**
|
|
2
|
+
* @license lucide-react v0.468.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Xe=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Oe=(...t)=>t.filter((n,i,r)=>!!n&&n.trim()!==""&&r.indexOf(n)===i).join(" ").trim();/**
|
|
7
|
+
* @license lucide-react v0.468.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/var Ze={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
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
|
+
*/const _e=s.forwardRef(({color:t="currentColor",size:n=24,strokeWidth:i=2,absoluteStrokeWidth:r,className:d="",children:y,iconNode:v,...W},f)=>s.createElement("svg",{ref:f,...Ze,width:n,height:n,stroke:t,strokeWidth:r?Number(i)*24/Number(n):i,className:Oe("lucide",d),...W},[...v.map(([m,S])=>s.createElement(m,S)),...Array.isArray(y)?y:[y]]));/**
|
|
17
|
+
* @license lucide-react v0.468.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const U=(t,n)=>{const i=s.forwardRef(({className:r,...d},y)=>s.createElement(_e,{ref:y,iconNode:n,className:Oe(`lucide-${Xe(t)}`,r),...d}));return i.displayName=`${t}`,i};/**
|
|
22
|
+
* @license lucide-react v0.468.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const Te=U("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]);/**
|
|
27
|
+
* @license lucide-react v0.468.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const Fe=U("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
|
|
32
|
+
* @license lucide-react v0.468.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const Qe=U("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
|
|
37
|
+
* @license lucide-react v0.468.0 - ISC
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the ISC license.
|
|
40
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/const et=U("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
|
|
42
|
+
* @license lucide-react v0.468.0 - ISC
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the ISC license.
|
|
45
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
+
*/const tt=U("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
|
|
47
|
+
* @license lucide-react v0.468.0 - ISC
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the ISC license.
|
|
50
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/const Ue=U("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
|
|
52
|
+
* @license lucide-react v0.468.0 - ISC
|
|
53
|
+
*
|
|
54
|
+
* This source code is licensed under the ISC license.
|
|
55
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
+
*/const nt=U("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);/**
|
|
57
|
+
* @license lucide-react v0.468.0 - ISC
|
|
58
|
+
*
|
|
59
|
+
* This source code is licensed under the ISC license.
|
|
60
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
+
*/const it=U("Inbox",[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{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",key:"oot6mr"}]]);/**
|
|
62
|
+
* @license lucide-react v0.468.0 - ISC
|
|
63
|
+
*
|
|
64
|
+
* This source code is licensed under the ISC license.
|
|
65
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
+
*/const rt=U("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);/**
|
|
67
|
+
* @license lucide-react v0.468.0 - ISC
|
|
68
|
+
*
|
|
69
|
+
* This source code is licensed under the ISC license.
|
|
70
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
+
*/const De=U("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
72
|
+
* @license lucide-react v0.468.0 - ISC
|
|
73
|
+
*
|
|
74
|
+
* This source code is licensed under the ISC license.
|
|
75
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
+
*/const ot=U("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{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",key:"1pkts6"}]]);/**
|
|
77
|
+
* @license lucide-react v0.468.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const st=U("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
|
|
82
|
+
* @license lucide-react v0.468.0 - ISC
|
|
83
|
+
*
|
|
84
|
+
* This source code is licensed under the ISC license.
|
|
85
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
+
*/const Re=U("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
|
|
87
|
+
* @license lucide-react v0.468.0 - ISC
|
|
88
|
+
*
|
|
89
|
+
* This source code is licensed under the ISC license.
|
|
90
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
+
*/const at=U("Send",[["path",{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",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
|
|
92
|
+
* @license lucide-react v0.468.0 - ISC
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the ISC license.
|
|
95
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/const lt=U("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]);/**
|
|
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
|
+
*/const dt=U("Smile",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]]);/**
|
|
102
|
+
* @license lucide-react v0.468.0 - ISC
|
|
103
|
+
*
|
|
104
|
+
* This source code is licensed under the ISC license.
|
|
105
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
+
*/const ve=U("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);/**
|
|
107
|
+
* @license lucide-react v0.468.0 - ISC
|
|
108
|
+
*
|
|
109
|
+
* This source code is licensed under the ISC license.
|
|
110
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
+
*/const ct=U("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);class Pe{constructor(n,i){this.apiUrl=n,this.token=i}async request(n,i,r){const d={authorization:`Bearer ${this.token}`,...r?{}:{"content-type":"application/json"},...i==null?void 0:i.headers},y=await fetch(`${this.apiUrl}${n}`,{...i,headers:d}),v=await y.json().catch(()=>null);if(!y.ok)throw new Error((v==null?void 0:v.message)??`Request failed (${y.status})`);return v}listConnections(){return this.request("/v1/connections")}listConversations(n){return this.request(`/v1/conversations${n?`?cursor=${encodeURIComponent(n)}`:""}`)}listMessages(n,i){return this.request(`/v1/conversations/${encodeURIComponent(n)}/messages${i?`?cursor=${encodeURIComponent(i)}`:""}`)}getMessage(n){return this.request(`/v1/messages/${encodeURIComponent(n)}`)}sendMessage(n,i,r){return this.request(`/v1/conversations/${encodeURIComponent(n)}/messages`,{method:"POST",headers:{"idempotency-key":crypto.randomUUID()},body:JSON.stringify({text:i,attachments:r})})}async markRead(n){const i=await fetch(`${this.apiUrl}/v1/conversations/${encodeURIComponent(n)}/mark-read`,{method:"POST",headers:{authorization:`Bearer ${this.token}`}});if(!i.ok&&i.status!==204)throw new Error(`markRead failed (${i.status})`)}listCannedResponses(n){const i=n!=null&&n.trim()?`?search=${encodeURIComponent(n)}`:"";return this.request(`/v1/canned-responses${i}`)}getNote(n){return this.request(`/v1/conversations/${encodeURIComponent(n)}/note`)}upsertNote(n,i){return this.request(`/v1/conversations/${encodeURIComponent(n)}/note`,{method:"PUT",body:JSON.stringify({content:i})})}async uploadAttachment(n){const i=new FormData;return i.append("file",n),this.request("/v1/attachments",{method:"POST",body:i},!0)}connectSSE(n){const i=`${this.apiUrl}/v1/events?token=${encodeURIComponent(this.token)}`;let r,d,y=!1;const v=()=>{r=new EventSource(i),r.addEventListener("message.new",W=>{n("message.new",JSON.parse(W.data))}),r.addEventListener("conversation.updated",W=>{n("conversation.updated",JSON.parse(W.data))}),r.onerror=()=>{r.close(),y||(d=setTimeout(v,5e3))}};return v(),()=>{y=!0,clearTimeout(d),r==null||r.close()}}}function Ne({src:t,alt:n="",fallback:i,style:r}){return t?e.jsx("img",{src:t,alt:n,style:{width:38,height:38,borderRadius:"50%",objectFit:"cover",...r}}):e.jsx("span",{style:{display:"grid",placeItems:"center",width:38,height:38,borderRadius:"50%",...r},children:i})}function pt({variant:t="ghost",style:n,...i}){return e.jsx("button",{...i,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",...n}})}function ht({style:t,...n}){return e.jsx("input",{...n,style:{width:"100%",minWidth:0,border:0,outline:0,background:"transparent",font:"inherit",...t}})}const Ke=s.forwardRef(({children:t,style:n},i)=>e.jsx("div",{ref:i,style:{minHeight:0,overflowY:"auto",overscrollBehavior:"contain",...n},children:t})),ut=s.forwardRef(function({style:n,...i},r){return e.jsx("textarea",{ref:r,...i,style:{display:"block",width:"100%",minWidth:0,boxSizing:"border-box",resize:"vertical",border:0,outline:0,background:"transparent",font:"inherit",...n}})}),l={ink:"#172033",muted:"#718096",line:"#e7ebf2",surface:"#f7f9fc",white:"#fff"},Be=[{icon:"😊",emojis:["😀","😁","😂","🤣","😊","😇","🙂","😉","😍","🥰","😘","😋","😎","🤩","😏","😒","😔","😢","😭","😤","😠","🤯","😱","🥳","😴","🤔","🤗","🫡","😮","🤧","🥺","😶","🫠","🤭","🤫"]},{icon:"👋",emojis:["👍","👎","👏","🙏","🤝","✌️","🤞","🫡","💪","🤜","👊","✊","🖐","👌","🤌","🤏","☝️","👆","👇","👉","👈","🤙","💅","🫶","❤️","🧡","💛","💚","💙","💜","🖤","💔","❣️","💕","💯"]},{icon:"🐱",emojis:["🐶","🐱","🐭","🐹","🐰","🦊","🐻","🐼","🐨","🐯","🦁","🐮","🐷","🐸","🐵","🙈","🐔","🐧","🐦","🦆","🦅","🦉","🦋","🐝","🐛","🐢","🦎","🐬","🦈","🐳","🐙","🦑"]},{icon:"🍕",emojis:["🍎","🍊","🍋","🍇","🍓","🍒","🥝","🥑","🍔","🍕","🌮","🍜","🍣","🍦","🎂","🍰","🧁","☕","🧋","🥤","🍺","🥂","🍾","🧃","🧊"]},{icon:"⚽",emojis:["⚽","🏀","🏈","⚾","🎾","🏐","🏓","🎮","🎲","🎯","🎳","🏆","🥇","🎖","🎁","🎉","🎊","🎈","🎭","🎨","🎬","🎵","🎸","🎹","🎺","🪗","🎻"]},{icon:"🌍",emojis:["🌍","🌈","⭐","🌙","☀️","⛅","🌊","🔥","💧","🌿","🌸","🌺","🌻","🍀","🌴","🏔","🏖","🏕","🌃","🏙","🌅","🌄","🌠","🌌","🌋","🏝"]}],Ie=s.createContext(""),qe=s.createContext("");function ft(){try{const t=new AudioContext,n=t.createOscillator(),i=t.createGain();n.connect(i),i.connect(t.destination),n.type="sine",n.frequency.setValueAtTime(880,t.currentTime),n.frequency.exponentialRampToValueAtTime(660,t.currentTime+.12),i.gain.setValueAtTime(.25,t.currentTime),i.gain.exponentialRampToValueAtTime(.001,t.currentTime+.35),n.start(t.currentTime),n.stop(t.currentTime+.35)}catch{}}function xt(t){if(!(t!=null&&t.metadata))return;const n=t.metadata,i=n.pageName??n.displayName??n.username??n.name;return typeof i=="string"&&i?i:void 0}function Ve(t){return t==="facebook"?"Facebook Messenger":t==="instagram"?"Instagram":t==="telegram"?"Telegram":t==="zalo"?"Zalo OA":"Channel"}function We(t){return t==="facebook"?"Facebook":t==="instagram"?"Instagram":t==="telegram"?"Telegram":t==="zalo"?"Zalo":String(t??"")}const gt=t=>{var i;const n={"application/pdf":"PDF","video/mp4":"Video MP4","audio/mpeg":"Audio MP3","audio/ogg":"Audio OGG","application/octet-stream":"Tệp đính kèm"};return t?n[t]??((i=t.split("/")[1])==null?void 0:i.toUpperCase())??"Tệp":"Tệp đính kèm"};function $e({status:t}){return t==="read"?e.jsx(Te,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle"}}):t==="delivered"?e.jsx(Te,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle",opacity:.5}}):t==="sent"?e.jsx(Fe,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle"}}):null}const yt=s.forwardRef(function({apiUrl:n,token:i,theme:r,height:d,defaultConversationId:y,disableAttachments:v,disableNotificationSound:W,hideKeyboardHint:f,locale:m="vi",onNewMessage:S,onConversationSelect:k},z){var ne,ue,fe,me,be;const C=s.useRef(new Pe(n,i)),[L,P]=s.useState([]),[K,T]=s.useState([]),[O,F]=s.useState(),[w,q]=s.useState(),Y=s.useRef(void 0),[b,$]=s.useState(""),[A,M]=s.useState({provider:"all",unreadOnly:!1}),[N,re]=s.useState(!1),j=s.useRef(null),J=s.useRef(null),[X,oe]=s.useState(null),[Z,se]=s.useState(!0),[c,I]=s.useState(""),[R,V]=s.useState(!1),H=(r==null?void 0:r.primaryColor)??"#2563eb",D=s.useMemo(()=>new Map(K.map(p=>[p.id,p])),[K]),E=s.useRef(null),[_,de]=s.useState(0),ye=s.useMemo(()=>{const p=new Set(K.map(x=>x.provider));return["facebook","instagram","telegram","zalo"].filter(x=>p.has(x))},[K]),ce=s.useMemo(()=>{var x;const p={};for(const a of L){const h=((x=D.get(a.connectionId))==null?void 0:x.provider)??"unknown";p[h]=(p[h]??0)+1}return p},[L,D]),G=s.useCallback(async p=>{try{const x=await C.current.listConversations(p);P(a=>p?[...a,...x.items]:x.items),F(x.nextCursor),!p&&x.items.length&&q(a=>a??(y?x.items.find(h=>h.id===y)??x.items[0]:x.items[0])),I("")}catch(x){I(x instanceof Error?x.message:"Không tải được hội thoại")}finally{se(!1)}},[y]);s.useEffect(()=>(C.current.listConnections().then(T).catch(()=>{}),G(),C.current.connectSSE((x,a)=>{if(x==="message.new"||x==="conversation.updated"){if(G(),x==="message.new"){const h=typeof a=="object"&&a?a:{},g=h.conversationId?String(h.conversationId):"",B=h.messageId?String(h.messageId):"";if((h.direction?String(h.direction):"")==="inbound"&&!W&&ft(),g&&g===Y.current&&B&&E.current){const je=E.current;C.current.getMessage(B).then(Je=>{je(Je)}).catch(()=>{})}S==null||S(g||Y.current||"")}}else x==="message.status_updated"&&de(h=>h+1)})),[G,S]),s.useEffect(()=>{Y.current=w==null?void 0:w.id},[w]),s.useEffect(()=>{w!=null&&w.unreadCount&&C.current.markRead(w.id).then(()=>G()).catch(()=>{})},[w==null?void 0:w.id]),s.useEffect(()=>{if(!N)return;function p(x){var a,h;(a=j.current)!=null&&a.contains(x.target)||(h=J.current)!=null&&h.contains(x.target)||re(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[N]);const pe=s.useMemo(()=>{const p=b.toLowerCase().trim();return L.filter(x=>{var ee;const a=`${x.contactName??""} ${x.subject??""} ${x.providerConversationKey}`.toLowerCase(),h=((ee=D.get(x.connectionId))==null?void 0:ee.provider)??"unknown",g=A.provider==="all"||h===A.provider,B=!A.unreadOnly||(x.unreadCount??0)>0;return g&&B&&(!p||a.includes(p))})},[L,D,A,b]),ae=A.provider!=="all"||A.unreadOnly,Q=m==="en"?{today:"TODAY",loadOlder:"↑ Load older messages",loading:"Loading messages…",noMessages:"No messages in this conversation.",searchPlaceholder:"Search conversations…",unreadOnly:"Unread only",sendPlaceholder:"Write a message…",send:"Send",all:"All"}:{today:"HÔM NAY",loadOlder:"↑ Tải tin cũ hơn",loading:"Đang tải tin nhắn…",noMessages:"Chưa có tin nhắn trong hội thoại này.",searchPlaceholder:"Tìm kiếm hội thoại…",unreadOnly:"Chưa đọc",sendPlaceholder:"Viết tin nhắn…",send:"Gửi",all:"Tất cả"};s.useImperativeHandle(z,()=>({openConversation:p=>{const x=L.find(a=>a.id===p);x&&q(x)},refresh:()=>void G()}),[L,G]);const he={...u.frame,height:d??620,...d?{maxHeight:"none"}:{},fontFamily:(r==null?void 0:r.fontFamily)??"Inter, ui-sans-serif, system-ui, sans-serif",borderRadius:(r==null?void 0:r.borderRadius)??"16px",gridTemplateColumns:R?"minmax(260px, 300px) minmax(0, 1fr) 260px":"minmax(260px, 300px) minmax(0, 1fr)",transition:"grid-template-columns 220ms ease"};return Z?e.jsxs("div",{style:{...u.state,borderRadius:(r==null?void 0:r.borderRadius)??"16px"},children:[e.jsx(Se,{})," Đang tải hộp thư…"]}):c&&!L.length?e.jsxs("div",{style:{...u.state,color:"#b42318",borderRadius:(r==null?void 0:r.borderRadius)??"16px"},children:[e.jsx(tt,{size:16,strokeWidth:2})," ",c,e.jsx("button",{style:u.retry,onClick:()=>{se(!0),G()},children:"Thử lại"})]}):e.jsx(Ie.Provider,{value:n,children:e.jsx(qe.Provider,{value:i,children:e.jsxs("div",{style:he,onFocusCapture:()=>{const p=window.scrollY;requestAnimationFrame(()=>{window.scrollY!==p&&window.scrollTo({top:p,behavior:"instant"})})},children:[e.jsxs("aside",{style:u.sidebar,children:[e.jsxs("div",{style:u.brand,children:[e.jsx("div",{style:{...u.brandMark,background:H,overflow:"hidden",padding:0},children:(ne=r==null?void 0:r.branding)!=null&&ne.logoUrl?e.jsx("img",{src:r.branding.logoUrl,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):((ue=r==null?void 0:r.branding)==null?void 0:ue.mark)??"C"}),e.jsxs("div",{children:[e.jsx("strong",{children:((fe=r==null?void 0:r.branding)==null?void 0:fe.name)??"Hộp thư"}),!((me=r==null?void 0:r.branding)!=null&&me.name)&&e.jsx("span",{style:u.eyebrow,children:"CHANNELHUB"})]}),e.jsx(pt,{"aria-label":"Tùy chọn",style:u.iconButton,children:e.jsx(Ue,{size:16,strokeWidth:2})})]}),e.jsxs("div",{style:u.search,children:[e.jsx(Re,{size:16,strokeWidth:2}),e.jsx(ht,{"aria-label":Q.searchPlaceholder,value:b,onChange:p=>$(p.target.value),placeholder:Q.searchPlaceholder}),b&&e.jsx("button",{style:u.clear,onClick:()=>$(""),"aria-label":"Xóa tìm kiếm",children:"×"})]}),ae&&e.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap",padding:"0 14px 8px"},children:[A.provider!=="all"&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",color:H,borderRadius:6,fontSize:11,padding:"2px 8px",fontWeight:500},children:[e.jsx(ge,{provider:A.provider}),We(A.provider),e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:H,padding:0,lineHeight:1,display:"flex"},onClick:()=>M(p=>({...p,provider:"all"})),"aria-label":"Xóa filter kênh",children:e.jsx(ve,{size:10})})]}),A.unreadOnly&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",color:H,borderRadius:6,fontSize:11,padding:"2px 8px",fontWeight:500},children:[Q.unreadOnly,e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:H,padding:0,lineHeight:1,display:"flex"},onClick:()=>M(p=>({...p,unreadOnly:!1})),"aria-label":"Xóa filter chưa đọc",children:e.jsx(ve,{size:10})})]}),e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:l.muted,fontSize:11,padding:"2px 4px"},onClick:()=>M({provider:"all",unreadOnly:!1}),children:"Xóa tất cả"})]}),e.jsxs("div",{style:u.listHeader,children:[e.jsxs("span",{children:[pe.length," hội thoại"]}),e.jsx("button",{ref:j,style:{...u.iconButton,background:ae?`${H}14`:"transparent",color:ae?H:l.muted},"aria-label":"Bộ lọc",onClick:()=>{var p;if(!N){const x=(p=j.current)==null?void 0:p.getBoundingClientRect();x&&oe({top:x.bottom+6,left:x.left})}re(x=>!x)},children:e.jsx(lt,{size:15,strokeWidth:2})})]}),N&&X&&Ae.createPortal(e.jsxs("div",{ref:J,style:{position:"fixed",top:X.top,left:X.left,zIndex:9999,background:l.white,border:`1px solid ${l.line}`,borderRadius:10,padding:"12px 14px",boxShadow:"0 8px 24px rgba(23,32,51,.14)",minWidth:210,fontFamily:(r==null?void 0:r.fontFamily)??"Inter, ui-sans-serif, system-ui, sans-serif",fontSize:13},children:[e.jsx("div",{style:{fontSize:10,fontWeight:700,color:l.muted,letterSpacing:1,textTransform:"uppercase",marginBottom:8},children:"Kênh"}),["all",...ye].map(p=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 6px",cursor:"pointer",borderRadius:6,background:A.provider===p?`${H}0f`:"transparent"},children:[e.jsx("input",{type:"radio",name:"provider-filter",checked:A.provider===p,onChange:()=>M(x=>({...x,provider:p})),style:{accentColor:H}}),p==="all"?e.jsxs("span",{style:{color:l.ink},children:[Q.all," (",L.length,")"]}):e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,color:l.ink},children:[e.jsx(ge,{provider:p}),We(p)," ",e.jsxs("span",{style:{color:l.muted},children:["(",ce[p]??0,")"]})]})]},p)),e.jsx("div",{style:{borderTop:`1px solid ${l.line}`,margin:"8px 0 6px"}}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 6px",cursor:"pointer",borderRadius:6,background:A.unreadOnly?`${H}0f`:"transparent"},children:[e.jsx("input",{type:"checkbox",checked:A.unreadOnly,onChange:p=>M(x=>({...x,unreadOnly:p.target.checked})),style:{accentColor:H}}),e.jsx("span",{style:{color:l.ink},children:Q.unreadOnly})]})]}),document.body),e.jsxs(Ke,{style:u.conversationList,children:[pe.map(p=>{var x;return e.jsx(mt,{conversation:p,provider:(x=D.get(p.connectionId))==null?void 0:x.provider,selected:(w==null?void 0:w.id)===p.id,primary:H,onSelect:()=>{q(p),k==null||k(p.id),C.current.markRead(p.id).then(()=>G()).catch(()=>{})}},p.id)}),!pe.length&&e.jsxs("div",{style:u.emptySmall,children:[e.jsx("div",{style:u.emptyIcon,children:e.jsx(Re,{size:16,strokeWidth:2})}),e.jsx("strong",{children:"Không tìm thấy"}),e.jsx("span",{children:"Thử từ khóa hoặc bộ lọc khác."})]}),O&&e.jsx("button",{style:u.loadMore,onClick:()=>void G(O),children:"Xem thêm hội thoại"})]})]}),e.jsx("main",{style:u.main,children:w?e.jsx(bt,{conversation:w,provider:(be=D.get(w.connectionId))==null?void 0:be.provider,connection:D.get(w.connectionId),client:C.current,primary:H,error:c,onRegisterAppend:p=>{E.current=p},refreshKey:_,infoOpen:R,onToggleInfo:()=>V(p=>!p),t:Q,disableAttachments:v,hideKeyboardHint:f},w.id):e.jsx(wt,{})}),R&&w&&e.jsx(jt,{conversation:w,connection:D.get(w.connectionId),primary:H,onClose:()=>V(!1),client:C.current})]})})})});function mt({conversation:t,provider:n,selected:i,primary:r,onSelect:d}){const[y,v]=s.useState(!1),W=t.contactName??t.subject??t.providerConversationKey,f=t.unreadCount??0,m=t.lastMessageText??"",S=t.lastMessageDirection==="outbound"?"Bạn: ":"",k=m.length>60?m.slice(0,60)+"…":m,z=m?S+k:"";let C="transparent";i?C="#eef2ff":y?C="#f7f9fc":f>0&&(C="#f0f4ff");const L={...u.row,background:C,...i?{boxShadow:`inset 3px 0 0 ${r}`}:f>0&&!y?{boxShadow:`inset 3px 0 0 ${r}`}:{}};return e.jsxs("button",{onClick:d,style:L,onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),children:[e.jsx(Ge,{name:W,color:r,image:t.contactPictureUrl,provider:n}),e.jsxs("span",{style:u.rowBody,children:[e.jsxs("span",{style:u.rowTop,children:[e.jsx("strong",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:f>0?700:500},children:W}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[e.jsx("time",{style:{color:l.muted,fontSize:11,whiteSpace:"nowrap"},children:Ce(t.lastMessageAt)}),f>0&&e.jsx("span",{"aria-label":`${f} tin nhắn chưa đọc`,style:u.unreadBadge,children:f>99?"99+":f})]})]}),e.jsx("span",{style:{...u.rowBottom,color:f>0&&!i?"#4a5568":l.muted},children:e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:z||e.jsx("span",{style:{opacity:.5},children:"Chưa có tin nhắn"})})})]})]})}function bt({conversation:t,provider:n,connection:i,client:r,primary:d,error:y,onRegisterAppend:v,refreshKey:W,infoOpen:f,onToggleInfo:m,t:S,disableAttachments:k,hideKeyboardHint:z}){var x;const[C,L]=s.useState([]),[P,K]=s.useState(),[T,O]=s.useState(""),[F,w]=s.useState(!0),[q,Y]=s.useState(!1),[b,$]=s.useState(""),A=s.useRef(null),M=t.contactName??t.subject??t.providerConversationKey,N=s.useRef(null),re=s.useRef(null),[j,J]=s.useState(null),[X,oe]=s.useState(!1),[Z,se]=s.useState(!1),[c,I]=s.useState(!1),[R,V]=s.useState(0),H=s.useRef(null),D=s.useRef(null),E=s.useRef(null),[_,de]=s.useState(!1),[ye,ce]=s.useState(""),[G,pe]=s.useState([]),ae=s.useRef(null),Q=s.useRef(null);s.useEffect(()=>()=>{j!=null&&j.objectUrl&&URL.revokeObjectURL(j.objectUrl)},[j==null?void 0:j.objectUrl]),s.useEffect(()=>{if(!c)return;function a(h){var g,B;(g=D.current)!=null&&g.contains(h.target)||(B=H.current)!=null&&B.contains(h.target)||I(!1)}return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[c]),s.useEffect(()=>{r.listCannedResponses().then(pe).catch(()=>{})},[r]),s.useEffect(()=>{if(!_)return;function a(h){var g,B;(g=Q.current)!=null&&g.contains(h.target)||(B=ae.current)!=null&&B.contains(h.target)||de(!1)}return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[_]);const he=s.useRef(!0),ne=s.useCallback(async(a,h)=>{h||(he.current=!a);try{const g=await r.listMessages(t.id,a);L(B=>a?[...g.items,...B]:g.items),K(g.nextCursor)}catch(g){$(g instanceof Error?g.message:"Không tải được tin nhắn")}finally{h||w(!1)}},[r,t.id]);s.useEffect(()=>{w(!0),ne()},[ne]),s.useEffect(()=>{W&&ne(void 0,!0)},[W]),s.useEffect(()=>{he.current&&requestAnimationFrame(()=>{const a=A.current;a&&(a.scrollTop=a.scrollHeight)})},[C]),s.useEffect(()=>(v==null||v(a=>{he.current=!0,L(h=>h.some(g=>g.id===a.id)?h:[...h,a])}),()=>{v==null||v(null)}),[v]);async function ue(a){var B;const h=(B=a.target.files)==null?void 0:B[0];if(!h)return;a.target.value="";const g=URL.createObjectURL(h);J({file:h,uploading:!0,objectUrl:g});try{const ee=await r.uploadAttachment(h);J({file:h,uploading:!1,url:ee.url,mimeType:ee.mimeType,attachmentType:ee.attachmentType,objectUrl:g})}catch{URL.revokeObjectURL(g),J(null),$("Không tải lên được tệp đính kèm")}}async function fe(a){a.preventDefault();const h=T.trim(),g=j!=null&&j.url?[{url:j.url,mimeType:j.mimeType??"application/octet-stream",type:j.attachmentType}]:[];if(!(!h&&!g.length||q)){Y(!0),$("");try{await r.sendMessage(t.id,h||void 0,g.length?g:void 0),j!=null&&j.objectUrl&&URL.revokeObjectURL(j.objectUrl),O(""),J(null),await ne()}catch(B){$(B instanceof Error?B.message:"Không gửi được tin nhắn")}finally{Y(!1)}}}function me(a){const h=E.current;if(!h){O(je=>je+a),I(!1);return}const g=h.selectionStart??T.length,B=h.selectionEnd??T.length,ee=T.slice(0,g)+a+T.slice(B);O(ee),I(!1),requestAnimationFrame(()=>{h.focus(),h.selectionStart=h.selectionEnd=g+a.length})}function be(a){O(a),de(!1),ce(""),requestAnimationFrame(()=>{const h=E.current;h&&(h.focus(),h.selectionStart=h.selectionEnd=a.length)})}const p=!q&&(T.trim().length>0||(j==null?void 0:j.url)!=null&&!j.uploading);return e.jsxs("section",{style:u.chat,children:[e.jsxs("header",{style:u.chatHeader,children:[e.jsx(Ge,{name:M,color:d,image:t.contactPictureUrl,provider:n}),e.jsxs("div",{style:u.contact,children:[e.jsx("strong",{style:u.contactName,children:M}),e.jsx("span",{style:u.contactMeta,children:xt(i)??Ve(n)})]}),e.jsxs("div",{style:u.headerActions,children:[e.jsx("button",{style:u.iconButton,"aria-label":"Thêm tùy chọn",children:e.jsx(Ue,{size:16,strokeWidth:2})}),e.jsx("button",{style:{...u.iconButton,background:f?`${d}14`:"transparent",color:f?d:l.muted},"aria-label":"Thông tin liên hệ",onClick:m,children:e.jsx(rt,{size:16,strokeWidth:2})})]})]}),e.jsxs(Ke,{ref:A,style:u.messageArea,children:[e.jsx("div",{style:u.day,children:S.today}),P&&e.jsx("button",{onClick:()=>void ne(P),style:u.historyButton,children:S.loadOlder}),F&&e.jsxs("div",{style:u.messageHint,children:[e.jsx(Se,{})," ",S.loading]}),!F&&!C.length&&e.jsx("div",{style:u.messageHint,children:S.noMessages}),C.map(a=>e.jsx(vt,{message:a,primary:d},a.id))]}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",padding:"6px 14px 2px",borderTop:`1px solid ${l.line}`},children:["Cảm ơn bạn đã liên hệ 🙏","Mình sẽ kiểm tra ngay","Vui lòng chờ 1-2 phút"].map(a=>e.jsx("button",{type:"button",onClick:()=>O(a),style:{fontSize:11,padding:"3px 10px",borderRadius:999,background:`${d}0f`,color:d,border:`1px solid ${d}33`,cursor:"pointer",whiteSpace:"nowrap"},children:a},a))}),e.jsxs("form",{onSubmit:fe,style:{flex:"0 0 auto",padding:"8px 14px 12px",borderTop:`1px solid ${l.line}`,background:l.white,position:"relative"},children:[c&&e.jsxs("div",{ref:H,style:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,background:l.white,border:`1px solid ${l.line}`,borderRadius:12,boxShadow:"0 8px 24px rgba(23,32,51,.14)",width:280,overflow:"hidden",fontFamily:"inherit"},children:[e.jsx("div",{style:{display:"flex",borderBottom:`1px solid ${l.line}`,background:"#f9fafb"},children:Be.map((a,h)=>e.jsx("button",{type:"button",onClick:()=>V(h),style:{flex:1,border:0,background:"transparent",padding:"7px 2px",fontSize:16,cursor:"pointer",lineHeight:1,borderBottom:R===h?`2px solid ${d}`:"2px solid transparent",opacity:R===h?1:.5,transition:"opacity 100ms ease"},children:a.icon},h))}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(8, 1fr)",gap:2,padding:8,maxHeight:180,overflowY:"auto"},children:(x=Be[R])==null?void 0:x.emojis.map((a,h)=>e.jsx("button",{type:"button",onClick:()=>me(a),style:{border:0,background:"transparent",padding:"5px 2px",fontSize:18,cursor:"pointer",borderRadius:6,lineHeight:1,transition:"background 80ms ease"},onMouseEnter:g=>{g.target.style.background="#f3f4f6"},onMouseLeave:g=>{g.target.style.background="transparent"},children:a},h))})]}),_&&e.jsxs("div",{ref:ae,style:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,background:l.white,border:`1px solid ${l.line}`,borderRadius:12,boxShadow:"0 8px 24px rgba(23,32,51,.14)",width:300,overflow:"hidden",fontFamily:"inherit"},children:[e.jsx("div",{style:{padding:"8px 10px",borderBottom:`1px solid ${l.line}`},children:e.jsx("input",{autoFocus:!0,type:"text",placeholder:"Tìm template…",value:ye,onChange:a=>ce(a.target.value),style:{width:"100%",boxSizing:"border-box",border:`1px solid ${l.line}`,borderRadius:7,padding:"5px 8px",fontSize:12,outline:"none",fontFamily:"inherit",color:l.ink}})}),e.jsx("div",{style:{maxHeight:220,overflowY:"auto"},children:(()=>{const a=ye.trim().toLowerCase(),h=a?G.filter(g=>g.title.toLowerCase().includes(a)||g.content.toLowerCase().includes(a)||(g.shortcut??"").toLowerCase().includes(a)):G;return h.length?h.map(g=>e.jsxs("button",{type:"button",onClick:()=>be(g.content),style:{display:"block",width:"100%",textAlign:"left",border:0,borderBottom:`1px solid ${l.line}`,background:"transparent",padding:"9px 12px",cursor:"pointer",fontFamily:"inherit"},onMouseEnter:B=>{B.currentTarget.style.background="#f7f9fc"},onMouseLeave:B=>{B.currentTarget.style.background="transparent"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:2},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600,color:l.ink},children:g.title}),g.shortcut&&e.jsx("span",{style:{fontSize:10,color:d,background:`${d}18`,borderRadius:4,padding:"1px 5px"},children:g.shortcut})]}),e.jsx("div",{style:{fontSize:11,color:l.muted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g.content})]},g.id)):e.jsx("div",{style:{padding:"24px 16px",textAlign:"center",color:l.muted,fontSize:12},children:G.length===0?"Chưa có template nào":"Không tìm thấy"})})()})]}),e.jsxs("div",{style:{border:`1.5px solid ${l.line}`,borderRadius:12,background:l.white,overflow:"hidden"},children:[j&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:`1px solid ${l.line}`,fontSize:12},children:[j.uploading?e.jsxs(e.Fragment,{children:[e.jsx(Se,{}),e.jsx("span",{style:{color:l.muted},children:"Đang tải lên…"})]}):j.attachmentType==="image"&&j.objectUrl?e.jsx("img",{src:j.objectUrl,alt:"",style:{height:48,width:48,objectFit:"cover",borderRadius:6}}):e.jsxs("span",{style:{color:l.muted},children:["📎 ",j.file.name," (",Math.round(j.file.size/1024)," KB)"]}),!j.uploading&&e.jsx("button",{type:"button",onClick:()=>{j!=null&&j.objectUrl&&URL.revokeObjectURL(j.objectUrl),J(null)},style:{marginLeft:"auto",border:0,background:"none",color:l.muted,cursor:"pointer",fontSize:16},"aria-label":"Xóa tệp đính kèm",children:"✕"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,padding:"4px 8px",borderBottom:"1px solid #f3f4f6"},children:[e.jsx("button",{ref:D,type:"button",title:"Chèn emoji",onClick:()=>I(a=>!a),style:{...u.toolbarBtn,background:c?`${d}18`:"transparent",color:c?d:"#9ca3af"},children:e.jsx(dt,{size:13,strokeWidth:2})}),!k&&e.jsx("button",{type:"button",title:"Gửi ảnh / video","aria-label":"Gửi ảnh hoặc video",style:u.toolbarBtn,onClick:()=>{var a;return(a=N.current)==null?void 0:a.click()},children:e.jsx(nt,{size:13,strokeWidth:2})}),!k&&e.jsx("button",{type:"button",title:"Gửi tệp đính kèm","aria-label":"Gửi tệp đính kèm",style:u.toolbarBtn,onClick:()=>{var a;return(a=re.current)==null?void 0:a.click()},children:e.jsx(ot,{size:13,strokeWidth:2})}),!k&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:N,type:"file",style:{display:"none"},onChange:ue,accept:"image/*,video/mp4"}),e.jsx("input",{ref:re,type:"file",style:{display:"none"},onChange:ue,accept:".pdf,audio/mpeg,audio/ogg,application/octet-stream,application/zip,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"})]}),e.jsx("button",{ref:Q,type:"button",title:"Template nhanh",onClick:()=>{de(a=>!a),ce("")},style:{...u.toolbarBtn,background:_?`${d}18`:"transparent",color:_?d:"#9ca3af"},children:e.jsx(ct,{size:13,strokeWidth:2})}),e.jsx("span",{style:{width:1,height:14,background:"#e5e7eb",margin:"0 2px"}}),e.jsx("button",{type:"button",title:"In đậm",onClick:()=>oe(a=>!a),style:{...u.toolbarBtn,fontWeight:700,fontSize:12,background:X?`${d}18`:"transparent",color:X?d:"#9ca3af",border:X?`1px solid ${d}33`:"1px solid transparent"},children:"B"}),e.jsx("button",{type:"button",title:"Nghiêng",onClick:()=>se(a=>!a),style:{...u.toolbarBtn,fontStyle:"italic",fontSize:12,background:Z?`${d}18`:"transparent",color:Z?d:"#9ca3af",border:Z?`1px solid ${d}33`:"1px solid transparent"},children:"I"})]}),e.jsx(ut,{ref:E,"aria-label":"Soạn tin nhắn",rows:2,value:T,onChange:a=>O(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),fe(a))},placeholder:S.sendPlaceholder,style:{display:"block",width:"100%",minWidth:0,boxSizing:"border-box",minHeight:52,maxHeight:120,resize:"none",border:0,outline:0,background:"transparent",color:l.ink,padding:"8px 12px 4px",font:"inherit",fontSize:13,lineHeight:1.45,fontStyle:Z?"italic":"normal",fontWeight:X?700:400}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 8px 6px 12px"},children:[e.jsxs("span",{style:{fontSize:11,color:T.length>1e3?"#ef4444":T.length>900?"#f59e0b":"#9ca3af",fontWeight:T.length>1e3?600:400},children:[T.length,"/1000"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[!z&&e.jsx("span",{style:{fontSize:10,color:"#9ca3af"},children:"↵ Gửi · ⇧↵ Xuống dòng"}),e.jsxs("button",{disabled:!p,"aria-label":"Gửi tin nhắn",style:{display:"flex",alignItems:"center",gap:5,padding:"5px 12px",border:0,borderRadius:999,fontSize:12,fontWeight:600,background:p?`linear-gradient(135deg,${d},#0ea5e9)`:"#e5e7eb",color:p?"#fff":"#9ca3af",cursor:p?"pointer":"not-allowed",boxShadow:p?"0 2px 8px rgba(37,99,235,0.25)":"none",transition:"all 150ms ease"},children:[q?e.jsx(De,{size:12,style:{animation:"channelhub-spin .7s linear infinite"}}):e.jsx(at,{size:12,strokeWidth:2}),S.send]})]})]})]})]}),(b||y)&&e.jsx("div",{role:"alert",style:u.error,children:b||y})]})}function vt({message:t,primary:n}){var O,F,w,q,Y;const i=s.useContext(Ie),r=s.useContext(qe),d=b=>b.startsWith("/v1/media/proxy")?`${i}${b}&tok=${encodeURIComponent(r)}`:b,y=t.direction==="outbound",v=((O=t.attachments)==null?void 0:O.filter(b=>b.type==="image"))??[],W=((F=t.attachments)==null?void 0:F.filter(b=>b.type==="sticker"))??[],f=((w=t.attachments)==null?void 0:w.filter(b=>b.type==="video"))??[],m=((q=t.attachments)==null?void 0:q.filter(b=>b.type==="audio"))??[],S=((Y=t.attachments)==null?void 0:Y.filter(b=>b.type==="file"))??[],[k,z]=s.useState(null),C=y?"flex-end":"flex-start",L=e.jsxs("time",{style:{display:"block",marginTop:4,fontSize:10,opacity:.65,textAlign:"right",letterSpacing:.2,userSelect:"none"},children:[Ce(t.occurredAt,!0),y&&e.jsxs(e.Fragment,{children:[" ",e.jsx($e,{status:t.status})]})]}),P=e.jsx("div",{style:{position:"absolute",bottom:6,right:8},children:e.jsxs("time",{style:{fontSize:10,color:"#fff",textShadow:"0 1px 3px rgba(0,0,0,.5)",letterSpacing:.2,userSelect:"none"},children:[Ce(t.occurredAt,!0),y&&e.jsxs(e.Fragment,{children:[" ",e.jsx($e,{status:t.status})]})]})}),K=y?{...u.bubbleOut,background:n,color:"#fff",border:"1px solid transparent"}:u.bubbleIn,T=!t.text&&m.length===0&&S.length===0;return e.jsxs("div",{style:{...u.messageLine,justifyContent:C,flexDirection:"column",alignItems:C},children:[W.map((b,$)=>e.jsxs("div",{style:{position:"relative",marginBottom:2},children:[e.jsx("img",{src:d(b.url),alt:"sticker",style:{display:"block",maxWidth:128,maxHeight:128,objectFit:"contain"}}),T&&v.length===0&&f.length===0&&$===W.length-1&&P]},`s${$}`)),v.map((b,$)=>e.jsxs("div",{style:{position:"relative",marginBottom:2,cursor:"zoom-in"},onClick:()=>z({url:d(b.url),kind:"image"}),children:[e.jsx("img",{src:d(b.url),alt:"",style:{display:"block",maxWidth:260,maxHeight:260,borderRadius:12,objectFit:"cover"}}),T&&$===v.length-1&&f.length===0&&P]},$)),f.map((b,$)=>e.jsxs("div",{style:{position:"relative",marginBottom:2,cursor:"pointer"},onClick:()=>z({url:d(b.url),kind:"video"}),children:[e.jsx("video",{src:d(b.url),style:{display:"block",maxWidth:260,maxHeight:200,borderRadius:12,objectFit:"cover"}}),e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:12,background:"rgba(0,0,0,.25)"},children:e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",background:"rgba(255,255,255,.9)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(st,{size:16,fill:"#172033",color:"#172033",style:{marginLeft:2}})})}),T&&$===f.length-1&&P]},$)),(m.length>0||S.length>0||t.text||!v.length&&!f.length&&!W.length&&!t.text)&&e.jsxs("div",{style:K,children:[m.map((b,$)=>e.jsx("audio",{src:d(b.url),controls:!0,style:{display:"block",width:"100%",marginBottom:4}},$)),S.map((b,$)=>e.jsxs("a",{href:d(b.url),target:"_blank",rel:"noreferrer",style:{display:"block",fontSize:12,color:y?"#fff":"#2563eb",textDecoration:"underline",marginBottom:4},children:["📎 ",gt(b.mimeType)]},$)),t.text&&e.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t.text}),!m.length&&!S.length&&!t.text&&e.jsx("p",{style:{margin:0,opacity:.5},children:"[attachment]"}),L]}),k&&Ae.createPortal(e.jsxs("div",{onClick:()=>z(null),style:{position:"fixed",inset:0,zIndex:1e4,background:"rgba(0,0,0,.88)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},children:[k.kind==="image"?e.jsx("img",{src:k.url,alt:"",style:{maxWidth:"90vw",maxHeight:"90vh",borderRadius:8,objectFit:"contain",boxShadow:"0 8px 40px rgba(0,0,0,.5)"},onClick:b=>b.stopPropagation()}):e.jsx("video",{src:k.url,controls:!0,autoPlay:!0,style:{maxWidth:"90vw",maxHeight:"90vh",borderRadius:8,boxShadow:"0 8px 40px rgba(0,0,0,.5)"},onClick:b=>b.stopPropagation()}),e.jsx("button",{onClick:()=>z(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:e.jsx(ve,{size:18})})]}),document.body)]})}function jt({conversation:t,connection:n,primary:i,onClose:r,client:d}){const y=t.contactName??t.subject??t.providerConversationKey,v=n==null?void 0:n.provider,[W,f]=s.useState({channel:!0,stats:!1,extra:!1}),m=F=>f(w=>({...w,[F]:!w[F]})),[S,k]=s.useState(""),[z,C]=s.useState(!1),[L,P]=s.useState(!1),[K,T]=s.useState("");s.useEffect(()=>{k(""),P(!1),T(""),d.getNote(t.id).then(F=>{F&&k(F.content)}).catch(()=>{})},[t.id,d]);async function O(){if(!(!S.trim()||z)){C(!0),T("");try{await d.upsertNote(t.id,S.trim()),P(!0),setTimeout(()=>P(!1),2e3)}catch{T("Lưu thất bại")}finally{C(!1)}}}return e.jsxs("aside",{style:u.infoPanel,children:[e.jsxs("div",{style:u.infoPanelHeader,children:[e.jsx("span",{style:{fontWeight:600,fontSize:13,color:l.ink},children:"Thông tin liên hệ"}),e.jsx("button",{style:u.iconButton,onClick:r,"aria-label":"Đóng",children:e.jsx(ve,{size:16,strokeWidth:2})})]}),e.jsxs("div",{style:{overflowY:"auto",flex:1},children:[e.jsxs("div",{style:u.infoPanelIdentity,children:[e.jsxs("span",{style:{...u.avatarWrap,width:48,height:48},children:[e.jsx(Ne,{src:t.contactPictureUrl,fallback:Ye(y),style:{...u.avatar,width:48,height:48,fontSize:16}}),e.jsx("span",{style:{...u.providerBadge,width:20,height:20},children:e.jsx(ge,{provider:v})})]}),e.jsx("strong",{style:{marginTop:10,fontSize:15,color:l.ink,textAlign:"center"},children:y}),e.jsx("span",{style:{fontSize:11,color:l.muted,fontFamily:"monospace",textAlign:"center"},children:t.providerConversationKey})]}),e.jsxs(ke,{label:"KÊNH",sectionKey:"channel",expanded:W.channel,onToggle:()=>m("channel"),children:[e.jsx(te,{label:"Nền tảng",children:e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[e.jsx(ge,{provider:v}),e.jsx("span",{children:Ve(v)})]})}),e.jsxs(te,{label:"ID hội thoại",children:[e.jsxs("span",{style:{fontFamily:"monospace",fontSize:11},children:[t.id.slice(0,8),"…"]}),e.jsx(kt,{value:t.id})]})]}),e.jsxs(ke,{label:"THỐNG KÊ",sectionKey:"stats",expanded:W.stats,onToggle:()=>m("stats"),children:[e.jsx(te,{label:"Tin nhắn",value:String(t.messageCount??0)}),(t.unreadCount??0)>0&&e.jsx(te,{label:"Chưa đọc",value:String(t.unreadCount),valueColor:"#ef4444"}),e.jsx(te,{label:"Gần nhất",value:t.lastMessageAt?new Date(t.lastMessageAt).toLocaleDateString("vi-VN",{day:"2-digit",month:"2-digit",year:"numeric"}):"—"}),e.jsx(te,{label:"Lần đầu",value:"—"})]}),e.jsxs(ke,{label:"THÔNG TIN BỔ SUNG",sectionKey:"extra",expanded:W.extra,onToggle:()=>m("extra"),children:[e.jsx(te,{label:"Điện thoại",value:"— chưa có",valueMuted:!0}),e.jsx(te,{label:"Email",value:"— chưa có",valueMuted:!0}),e.jsx(te,{label:"Nhãn",value:"— chưa có",valueMuted:!0})]}),e.jsxs("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:8},children:[e.jsx("button",{style:{...u.ghostButton,color:i,borderColor:`${i}33`},children:"Xem lịch sử"}),e.jsxs("div",{style:{border:"1.5px solid #fde68a",borderRadius:10,background:"#fffbeb",overflow:"hidden"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid #fde68a",fontSize:11,fontWeight:600,color:"#92400e"},children:"🔒 Ghi chú nội bộ"}),e.jsx("textarea",{value:S,onChange:F=>k(F.target.value),placeholder:"Nhập ghi chú...",rows:3,style:{display:"block",width:"100%",boxSizing:"border-box",border:0,outline:0,background:"transparent",resize:"none",padding:"8px 10px",font:"inherit",fontSize:12,color:l.ink,lineHeight:1.5}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 10px 6px"},children:[L?e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:11,color:"#16a34a"},children:[e.jsx(Fe,{size:11,strokeWidth:2.5})," Đã lưu"]}):K?e.jsx("span",{style:{fontSize:11,color:"#ef4444"},children:K}):e.jsx("span",{}),e.jsx("button",{type:"button",onClick:()=>{O()},disabled:!S.trim()||z,style:{padding:"4px 12px",border:0,borderRadius:7,fontSize:12,fontWeight:600,background:S.trim()&&!z?"linear-gradient(135deg,#f59e0b,#fbbf24)":"#e5e7eb",color:S.trim()&&!z?"#fff":"#9ca3af",cursor:S.trim()&&!z?"pointer":"not-allowed"},children:z?"Đang lưu…":"Lưu ghi chú"})]})]})]})]})]})}function ke({label:t,children:n,sectionKey:i,expanded:r,onToggle:d}){const y=!!d,v=r??!0;return e.jsxs("div",{style:{borderTop:`1px solid ${l.line}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px 6px",fontSize:10,fontWeight:700,letterSpacing:1,color:l.muted,textTransform:"uppercase",cursor:y?"pointer":"default"},onClick:d,children:[e.jsx("span",{children:t}),y&&(v?e.jsx(Qe,{size:12,strokeWidth:2}):e.jsx(et,{size:12,strokeWidth:2}))]}),v&&n]})}function te({label:t,value:n,children:i,valueColor:r,valueMuted:d}){return e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"3px 16px",fontSize:12,gap:8},children:[e.jsx("span",{style:{color:l.muted,flexShrink:0},children:t}),e.jsx("span",{style:{color:r??(d?l.muted:l.ink),textAlign:"right",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"flex",alignItems:"center",gap:4},children:i??n})]})}function kt({value:t}){const[n,i]=s.useState(!1);return e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:l.muted,padding:2,lineHeight:1},title:"Sao chép",onClick:()=>{navigator.clipboard.writeText(t).then(()=>{i(!0),setTimeout(()=>i(!1),1500)})},"aria-label":"Sao chép ID",children:n?"✓":"⎘"})}function wt(){return e.jsxs("div",{style:u.empty,children:[e.jsx("div",{style:u.emptyHero,children:e.jsx(it,{size:16,strokeWidth:2})}),e.jsx("h2",{children:"Chọn một hội thoại"}),e.jsx("p",{children:"Chọn hội thoại bên trái để xem và trả lời tin nhắn."})]})}function Ge({name:t,color:n,image:i,provider:r}){return e.jsxs("span",{style:u.avatarWrap,children:[e.jsx(St,{name:t,color:n,image:i}),r&&e.jsx("span",{style:u.providerBadge,children:e.jsx(ge,{provider:r})})]})}function St({name:t,color:n,image:i}){return e.jsx(Ne,{src:i,fallback:Ye(t),style:{...u.avatar,background:`${n}18`,color:n}})}function Se(){return e.jsx(De,{size:14,style:u.spinner,"aria-hidden":"true"})}function Ye(t){return t.split(/\s+/).filter(Boolean).slice(-2).map(n=>n[0]).join("").toUpperCase()||"?"}const Ct={livechat:"web"};function ge({provider:t}){const n=s.useContext(Ie),i=14;if(!t)return null;const r=Ct[t]??t;return e.jsx("img",{src:`${n}/static/logos/${r}.avif`,alt:t,width:i,height:i,style:{borderRadius:"50%",objectFit:"cover",display:"block"}})}function Ce(t,n=!1){if(!t)return"";const i=new Date(t);return i.toDateString()===new Date().toDateString()?i.toLocaleTimeString("vi-VN",{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString("vi-VN",{day:"2-digit",month:"2-digit"})}const u={frame:{display:"grid",gridTemplateRows:"minmax(0, 1fr)",height:620,maxHeight:"calc(100dvh - 220px)",minHeight:0,overflow:"hidden",border:`1px solid ${l.line}`,background:l.white,color:l.ink,boxShadow:"0 18px 50px rgba(31,45,72,.10)"},sidebar:{display:"flex",flexDirection:"column",minWidth:0,minHeight:0,borderRight:`1px solid ${l.line}`,background:l.white},brand:{display:"flex",alignItems:"center",gap:10,padding:"20px 18px 16px"},brandMark:{display:"grid",placeItems:"center",width:32,height:32,borderRadius:10,color:"#fff",fontWeight:800},eyebrow:{display:"block",marginTop:2,fontSize:9,letterSpacing:1.3,color:l.muted},iconButton:{display:"inline-grid",placeItems:"center",width:32,height:32,marginLeft:"auto",border:0,borderRadius:8,background:"transparent",color:l.muted,cursor:"pointer"},search:{display:"flex",alignItems:"center",gap:8,margin:"0 14px 12px",padding:"9px 10px",border:`1px solid ${l.line}`,borderRadius:9,color:l.muted,background:l.surface},clear:{border:0,background:"none",color:l.muted,cursor:"pointer",fontSize:18},listHeader:{display:"flex",alignItems:"center",padding:"10px 18px",borderTop:`1px solid ${l.line}`,borderBottom:`1px solid ${l.line}`,color:l.muted,fontSize:11,fontWeight:700,letterSpacing:.4,textTransform:"uppercase"},conversationList:{overflowY:"auto",flex:1,minHeight:0},row:{display:"flex",width:"100%",gap:11,padding:"10px 14px",border:0,borderBottom:`1px solid ${l.line}`,background:"transparent",textAlign:"left",cursor:"pointer",transition:"background 120ms ease"},avatarWrap:{position:"relative",flex:"0 0 auto",width:38,height:38},avatar:{flex:"0 0 auto",width:38,height:38,display:"grid",placeItems:"center",borderRadius:"50%",objectFit:"cover",fontSize:12,fontWeight:800},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"},rowBody:{minWidth:0,flex:1},rowTop:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,fontSize:13},rowBottom:{display:"flex",marginTop:4,fontSize:11,minWidth:0,overflow:"hidden",lineHeight:1.4},unreadBadge:{display:"inline-grid",placeItems:"center",minWidth:18,height:18,borderRadius:999,background:"#ef4444",color:"#fff",fontSize:10,fontWeight:800,padding:"0 5px"},loadMore:{width:"100%",border:0,background:"transparent",color:"#4c72ca",padding:14,cursor:"pointer",fontSize:12},emptySmall:{display:"grid",justifyItems:"center",gap:7,padding:"56px 24px",color:l.muted,fontSize:12,textAlign:"center"},emptyIcon:{display:"grid",placeItems:"center",width:40,height:40,borderRadius:12,background:l.surface},main:{minWidth:0,minHeight:0,overflow:"hidden",background:l.surface},chat:{display:"flex",flexDirection:"column",height:"100%",minWidth:0,minHeight:0},chatHeader:{flex:"0 0 auto",display:"flex",alignItems:"center",gap:10,padding:"0 16px 0 18px",height:56,borderBottom:`1px solid ${l.line}`,background:l.white},contact:{display:"grid",gap:3,minWidth:0,flex:1},contactName:{fontSize:14,fontWeight:600,color:l.ink,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},contactMeta:{display:"flex",alignItems:"center",gap:5,fontSize:11,color:l.muted},headerActions:{display:"flex",gap:2,marginLeft:"auto"},messageArea:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",padding:"20px clamp(16px,5vw,56px)",background:"linear-gradient(180deg,#f9fbfe 0%,#f4f7fb 100%)"},day:{margin:"0 auto 18px",color:"#a1acbb",fontSize:10,letterSpacing:1.2,fontWeight:700,textAlign:"center"},historyButton:{display:"block",margin:"0 auto 18px",border:`1px solid ${l.line}`,borderRadius:20,padding:"6px 12px",background:l.white,color:l.muted,cursor:"pointer",fontSize:11},messageHint:{display:"flex",justifyContent:"center",alignItems:"center",gap:8,padding:40,color:l.muted,fontSize:12},messageLine:{display:"flex",marginBottom:10},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},bubbleIn:{maxWidth:"min(70%,480px)",padding:"9px 13px",borderRadius:"14px 14px 14px 3px",border:`1px solid ${l.line}`,background:l.surface,boxShadow:"0 2px 5px rgba(30,43,65,.03)",fontSize:14,lineHeight:1.55},error:{padding:"8px 18px",background:"#fff2f0",color:"#b42318",fontSize:12},empty:{display:"grid",placeItems:"center",alignContent:"center",height:"100%",padding:30,textAlign:"center",color:l.muted},emptyHero:{display:"grid",placeItems:"center",width:64,height:64,marginBottom:16,borderRadius:20,background:"#eaf0ff",color:"#5277d7"},state:{display:"flex",alignItems:"center",justifyContent:"center",gap:10,minHeight:180,border:`1px solid ${l.line}`,background:l.white,color:l.muted,fontSize:13},retry:{border:0,borderRadius:7,padding:"7px 10px",background:"#eff4ff",color:"#315dbb",cursor:"pointer"},spinner:{display:"inline-block",width:14,height:14,border:"2px solid #dbe3f3",borderTopColor:"#5277d7",borderRadius:"50%",animation:"channelhub-spin .7s linear infinite"},toolbarBtn:{display:"inline-grid",placeItems:"center",width:26,height:26,border:"1px solid transparent",borderRadius:6,background:"transparent",color:"#9ca3af",cursor:"pointer",padding:0,lineHeight:1},infoPanel:{display:"flex",flexDirection:"column",borderLeft:`1px solid ${l.line}`,background:l.white,minHeight:0,overflow:"hidden"},infoPanelHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 16px 12px",borderBottom:`1px solid ${l.line}`,flex:"0 0 auto"},infoPanelIdentity:{display:"flex",flexDirection:"column",alignItems:"center",padding:"20px 16px 16px",gap:4},ghostButton:{width:"100%",padding:"8px 12px",border:`1px solid ${l.line}`,borderRadius:8,background:"transparent",fontSize:12,cursor:"pointer",textAlign:"center"}},It={facebook:"#dbeafe",zalo:"#e0f2fe",instagram:"#fce7f3",telegram:"#cffafe",livechat:"#ede9fe",whatsapp:"#dcfce7"},zt={facebook:"facebook",instagram:"instagram",telegram:"telegram",zalo:"zalo",livechat:"web",whatsapp:"web"};function ie({provider:t,apiUrl:n,size:i=40}){const r=It[t]??"#f1f5f9",d=zt[t],y=n.replace(/\/$/,"");return e.jsx("div",{style:{width:i,height:i,borderRadius:Math.round(i*.28),background:r,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,overflow:"hidden"},children:d?e.jsx("img",{src:`${y}/static/logos/${d}.avif`,alt:t,width:Math.round(i*.65),height:Math.round(i*.65),style:{objectFit:"contain",display:"block"}}):e.jsx("span",{style:{fontSize:Math.round(i*.45),fontWeight:700,color:"#64748b",textTransform:"uppercase"},children:t.slice(0,1)})})}const xe={facebook:"Facebook",zalo:"Zalo OA",instagram:"Instagram",telegram:"Telegram",livechat:"Live Chat",whatsapp:"WhatsApp"},Tt={facebook:"#dbeafe",zalo:"#e0f2fe",instagram:"#fce7f3",telegram:"#cffafe",livechat:"#ede9fe",whatsapp:"#dcfce7"};function ze(t){const n=t.metadata;return String(n.displayName??n.pageName??n.username??n.name??t.externalAccountId)}function Rt(t){const n=xe[t.provider]??t.provider,i=String(t.metadata.username??t.metadata.pageName??"");return i?`${n} · ${i}`:n}const o={root:{background:"#fff",borderRadius:16,boxShadow:"0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06)",overflow:"hidden",minWidth:320,width:"100%",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif",fontSize:14,color:"#0f172a"},header:{padding:"20px 24px 0",display:"flex",alignItems:"center",justifyContent:"space-between"},headerLeft:{display:"flex",alignItems:"center",gap:10},title:{fontSize:16,fontWeight:700,color:"#0f172a",lineHeight:1.3},subtitle:{fontSize:12,color:"#94a3b8",marginTop:1},divider:{height:1,background:"#f1f5f9",margin:"16px 0 0"},body:{padding:"16px 24px 24px"},backBtn:{width:32,height:32,borderRadius:8,border:"1px solid #e2e8f0",background:"#fff",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",color:"#475569",flexShrink:0},addBtn:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:8,border:"none",background:"#2563eb",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",flexShrink:0},errorBanner:{margin:"12px 24px 0",padding:"10px 14px",borderRadius:10,background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",fontSize:13},channelItem:{display:"flex",alignItems:"center",gap:12,padding:"12px 14px",borderRadius:12,border:"1px solid #f1f5f9",background:"#fafafa",marginBottom:8},channelInfo:{flex:1,minWidth:0},channelName:{fontSize:14,fontWeight:600,color:"#0f172a",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},channelMeta:{fontSize:12,color:"#94a3b8",marginTop:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},channelActions:{display:"flex",alignItems:"center",gap:8,flexShrink:0},badgeActive:{fontSize:11,fontWeight:600,padding:"2px 8px",borderRadius:999,background:"#d1fae5",color:"#059669"},badgeInactive:{fontSize:11,fontWeight:600,padding:"2px 8px",borderRadius:999,background:"#f1f5f9",color:"#94a3b8"},disconnectBtn:{fontSize:12,fontWeight:500,padding:"5px 10px",borderRadius:7,border:"1px solid #e2e8f0",background:"#fff",color:"#64748b",cursor:"pointer"},providerGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(130px, 1fr))",gap:10},providerCard:{display:"flex",flexDirection:"column",alignItems:"center",gap:8,padding:"16px 12px 14px",borderRadius:12,borderWidth:"1.5px",borderStyle:"solid",borderColor:"#f1f5f9",background:"#fafafa",cursor:"pointer",textAlign:"center",boxShadow:"none",transform:"none"},providerName:{fontSize:13,fontWeight:600,color:"#0f172a",lineHeight:1.2},providerDesc:{fontSize:11,color:"#94a3b8",lineHeight:1.4},connectHeader:{display:"flex",alignItems:"center",gap:12,padding:"20px 24px 16px",borderBottom:"1px solid #f1f5f9"},connectTitle:{fontSize:15,fontWeight:700,color:"#0f172a"},connectDesc:{fontSize:12,color:"#94a3b8",marginTop:2,lineHeight:1.5},form:{padding:"20px 24px 24px",display:"flex",flexDirection:"column",gap:16},field:{display:"flex",flexDirection:"column",gap:6},label:{fontSize:13,fontWeight:600,color:"#374151"},labelHint:{fontSize:11,fontWeight:400,color:"#94a3b8",marginLeft:4},input:{padding:"9px 12px",borderRadius:8,border:"1.5px solid #e2e8f0",fontSize:13,color:"#0f172a",background:"#fff",outline:"none",fontFamily:"inherit",width:"100%",boxSizing:"border-box"},inputHint:{fontSize:11,color:"#94a3b8",lineHeight:1.5},infoBox:{display:"flex",gap:8,padding:"10px 12px",borderRadius:8,background:"#eff6ff",border:"1px solid #bfdbfe",color:"#1e40af",fontSize:13,lineHeight:1.5},formActions:{display:"flex",gap:8,flexWrap:"wrap"},btnPrimary:{flex:1,minWidth:120,padding:"10px 16px",borderRadius:9,border:"none",background:"#2563eb",color:"#fff",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:"inherit"},btnSecondary:{padding:"10px 16px",borderRadius:9,border:"1.5px solid #e2e8f0",background:"#fff",color:"#64748b",fontSize:14,fontWeight:500,cursor:"pointer",fontFamily:"inherit"},resultBanner:{display:"flex",alignItems:"flex-start",gap:10,padding:"12px 14px",borderRadius:10,background:"#f0fdf4",border:"1px solid #bbf7d0",fontSize:13,color:"#166534",lineHeight:1.5},codeLabel:{fontSize:11,fontWeight:600,color:"#64748b",textTransform:"uppercase",letterSpacing:".05em",marginBottom:6},codeBlock:{background:"#0f172a",borderRadius:10,padding:"14px 16px",position:"relative",overflowX:"auto"},codePre:{fontFamily:"'JetBrains Mono', 'Fira Code', 'Courier New', monospace",fontSize:11.5,lineHeight:1.6,color:"#e2e8f0",whiteSpace:"pre-wrap",wordBreak:"break-all",margin:0},copyBtn:{position:"absolute",top:10,right:10,display:"flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:6,border:"1px solid #334155",background:"#1e293b",color:"#94a3b8",fontSize:11,fontWeight:500,cursor:"pointer",fontFamily:"inherit"},secretRow:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderRadius:8,background:"#fefce8",border:"1px solid #fef08a"},secretLabel:{fontSize:12,fontWeight:600,color:"#854d0e",whiteSpace:"nowrap"},secretValue:{fontFamily:"'JetBrains Mono', monospace",fontSize:12,color:"#0f172a",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},oauthWaiting:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"40px 24px 48px",gap:16,textAlign:"center"},oauthTitle:{fontSize:16,fontWeight:700,color:"#0f172a"},oauthDesc:{fontSize:13,color:"#64748b",lineHeight:1.6,maxWidth:300},oauthCancel:{marginTop:8,padding:"10px 20px",borderRadius:9,border:"1.5px solid #e2e8f0",background:"#fff",color:"#64748b",fontSize:14,fontWeight:500,cursor:"pointer",fontFamily:"inherit"},empty:{display:"flex",flexDirection:"column",alignItems:"center",padding:"40px 24px 48px",gap:12,textAlign:"center"},emptyTitle:{fontSize:15,fontWeight:700,color:"#0f172a"},emptyDesc:{fontSize:13,color:"#94a3b8",lineHeight:1.6,maxWidth:280},emptyCta:{marginTop:4,display:"flex",alignItems:"center",gap:6,padding:"10px 20px",borderRadius:9,border:"none",background:"#2563eb",color:"#fff",fontSize:14,fontWeight:600,cursor:"pointer",fontFamily:"inherit"}};function Le(){return e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M7 1v12M1 7h12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}function le(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e.jsx("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round"})})}function He(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[e.jsx("rect",{x:"4",y:"4",width:"7",height:"7",rx:"1.5",stroke:"currentColor",strokeWidth:"1.3"}),e.jsx("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"})]})}function Ee(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Bt(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{flexShrink:0},children:[e.jsx("circle",{cx:"5",cy:"6",r:"3.5",stroke:"#ca8a04",strokeWidth:"1.4"}),e.jsx("path",{d:"M8 7.5l4.5 4.5M10.5 10l1.5 1.5",stroke:"#ca8a04",strokeWidth:"1.4",strokeLinecap:"round"})]})}function Wt(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{flexShrink:0,marginTop:1},children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M7 6v5M7 4.5v.01",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}let Me=!1;function $t(){if(Me||typeof document>"u")return;Me=!0;const t=document.createElement("style");t.textContent="@keyframes ch-spin{to{transform:rotate(360deg)}}",document.head.appendChild(t)}function Lt({apiUrl:t,token:n,onConnectionChange:i}){const r=t.replace(/\/$/,""),[d,y]=s.useState([]),[v,W]=s.useState(!0),[f,m]=s.useState({name:"list"}),[S,k]=s.useState(null),[z,C]=s.useState(!1),[L,P]=s.useState(""),[K,T]=s.useState(""),[O,F]=s.useState(""),[w,q]=s.useState(""),[Y,b]=s.useState(!1),[$,A]=s.useState(!1),M=s.useRef(null);$t();const N=s.useCallback(async()=>{try{const c=await fetch(`${r}/v1/connections`,{headers:{authorization:`Bearer ${n}`}});if(!c.ok)throw new Error("Không tải được kênh");const I=await c.json();y(I),i==null||i(I)}catch(c){k(c instanceof Error?c.message:"Lỗi tải dữ liệu")}finally{W(!1)}},[r,n,i]);s.useEffect(()=>{N()},[N]),s.useEffect(()=>{if(!S)return;const c=setTimeout(()=>k(null),5e3);return()=>clearTimeout(c)},[S]),s.useEffect(()=>()=>{M.current&&window.removeEventListener("message",M.current)},[]);async function re(c,I){if(confirm(`Bạn chắc chắn muốn ngắt kết nối "${I}"?
|
|
112
|
+
|
|
113
|
+
Hành động này không thể hoàn tác.`))try{if(!(await fetch(`${r}/v1/connections/${c}`,{method:"DELETE",headers:{authorization:`Bearer ${n}`}})).ok)throw new Error("Không thể ngắt kết nối");await N()}catch(R){k(R instanceof Error?R.message:"Lỗi ngắt kết nối")}}async function j(){if(!L.trim()){k("Vui lòng nhập Bot Token");return}if(!/^\d+:[A-Za-z0-9_-]+$/.test(L.trim())){k("Token không đúng định dạng");return}C(!0),k(null);try{const c=await fetch(`${r}/v1/connect/telegram/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({botToken:L.trim(),displayName:K.trim()||void 0})}),I=await c.json();if(!c.ok||!I.connectionId)throw new Error(I.message??"Không thể kết nối Telegram");P(""),T(""),await N(),m({name:"list"})}catch(c){k(c instanceof Error?c.message:"Lỗi kết nối")}finally{C(!1)}}async function J(){if(!O.trim()){k("Vui lòng nhập tên widget");return}C(!0),k(null);try{const c=w.split(/[\n,]+/).map(V=>V.trim()).filter(Boolean),I=await fetch(`${r}/v1/connect/livechat/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({displayName:O.trim(),allowedDomains:c.length?c:void 0})}),R=await I.json();if(!I.ok||!R.connectionId||!R.embedScript)throw new Error(R.message??"Không thể tạo widget");F(""),q(""),await N(),m({name:"livechat-result",connectionId:R.connectionId,embedScript:R.embedScript,identitySecret:R.identitySecret??"",allowedDomains:R.allowedDomains??[]})}catch(c){k(c instanceof Error?c.message:"Lỗi tạo widget")}finally{C(!1)}}async function X(c){k(null);try{const I=`${r}/static/oauth-popup.html`,R=await fetch(`${r}/v1/connect/${c}/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({callbackUrl:I})}),V=await R.json();if(!R.ok||!V.authorizationUrl)throw new Error(V.message??"Không thể bắt đầu kết nối");const H=window.open(V.authorizationUrl,"channelhub-oauth","width=600,height=700,scrollbars=yes,resizable=yes");m({name:"oauth-waiting",provider:c,popup:H}),M.current&&window.removeEventListener("message",M.current);const D=E=>{if(E.data){if(E.data.type==="channelhub:oauth-select"){m({name:"oauth-select",provider:E.data.provider,sessionId:String(E.data.sessionId??""),pages:E.data.pages??[],popup:H});return}E.data.type==="channelhub:oauth"&&(window.removeEventListener("message",D),M.current=null,E.data.status==="active"?(N(),m({name:"list"})):(k("Kết nối thất bại: "+String(E.data.error??"Không xác định")),m({name:"list"})))}};M.current=D,window.addEventListener("message",D)}catch(I){k(I instanceof Error?I.message:"Lỗi kết nối"),m({name:"list"})}}function oe(c,I){navigator.clipboard.writeText(c).then(()=>{I==="script"?(b(!0),setTimeout(()=>b(!1),2e3)):(A(!0),setTimeout(()=>A(!1),2e3))})}function Z(){const c=f.name==="oauth-waiting"||f.name==="oauth-select"?f.popup:null;if(c)try{c.close()}catch{}M.current&&(window.removeEventListener("message",M.current),M.current=null),m({name:"add"})}async function se(c){if(f.name!=="oauth-select")return;const{provider:I,sessionId:R,popup:V}=f;C(!0),k(null);const H={facebook:`${r}/v1/connect/facebook/select-page`,instagram:`${r}/v1/connect/instagram/select-account`,zalo:`${r}/v1/connect/zalo/select-oa`},D={facebook:"pageId",instagram:"accountId",zalo:"oaId"};try{const E=await fetch(H[I]??`${r}/v1/connect/${I}/select-page`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({sessionId:R,[D[I]??"pageId"]:c})}),_=await E.json();if(!E.ok||!_.connectionId)throw new Error(_.message??"Không thể kết nối");if(V)try{V.postMessage({type:"channelhub:close-popup"},"*")}catch{}M.current&&(window.removeEventListener("message",M.current),M.current=null),await N(),m({name:"list"})}catch(E){k(E instanceof Error?E.message:"Lỗi kết nối")}finally{C(!1)}}return e.jsxs("div",{style:o.root,children:[S&&e.jsx("div",{style:o.errorBanner,children:S}),f.name==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.header,children:[e.jsx("div",{style:o.headerLeft,children:e.jsxs("div",{children:[e.jsx("div",{style:o.title,children:"Kênh kết nối"}),e.jsx("div",{style:o.subtitle,children:v?"Đang tải…":`${d.filter(c=>c.status==="active").length} kênh đang hoạt động`})]})}),e.jsxs("button",{style:o.addBtn,onClick:()=>m({name:"add"}),children:[e.jsx(Le,{}),e.jsx("span",{children:"Thêm kênh"})]})]}),e.jsx("div",{style:o.divider}),e.jsx("div",{style:o.body,children:!v&&d.length===0?e.jsxs("div",{style:o.empty,children:[e.jsx("div",{style:{width:64,height:64,borderRadius:16,background:"#f1f5f9",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ie,{provider:"livechat",apiUrl:r,size:40})}),e.jsx("div",{style:o.emptyTitle,children:"Chưa có kênh nào được kết nối"}),e.jsx("div",{style:o.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."}),e.jsxs("button",{style:o.emptyCta,onClick:()=>m({name:"add"}),children:[e.jsx(Le,{}),"Kết nối kênh đầu tiên"]})]}):e.jsx("div",{children:d.map(c=>e.jsx(Mt,{conn:c,apiUrl:r,onDisconnect:()=>void re(c.id,ze(c))},c.id))})})]}),f.name==="add"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:o.header,children:e.jsxs("div",{style:o.headerLeft,children:[e.jsx("button",{style:o.backBtn,onClick:()=>m({name:"list"}),children:e.jsx(le,{})}),e.jsxs("div",{children:[e.jsx("div",{style:o.title,children:"Thêm kênh mới"}),e.jsx("div",{style:o.subtitle,children:"Chọn nền tảng bạn muốn kết nối"})]})]})}),e.jsx("div",{style:o.divider}),e.jsx("div",{style:o.body,children:e.jsx("div",{style:o.providerGrid,children:At.map(c=>e.jsx(Ot,{provider:c,apiUrl:r,onClick:()=>{c.type==="oauth"?X(c.id):c.id==="telegram"?m({name:"connect-telegram"}):m({name:"connect-livechat"})}},c.id))})})]}),f.name==="connect-telegram"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>m({name:"add"}),children:e.jsx(le,{})}),e.jsx(ie,{provider:"telegram",apiUrl:r,size:44}),e.jsxs("div",{children:[e.jsx("div",{style:o.connectTitle,children:"Kết nối Telegram Bot"}),e.jsx("div",{style:o.connectDesc,children:"Nhập Bot Token để bắt đầu nhận tin nhắn"})]})]}),e.jsxs("div",{style:o.form,children:[e.jsxs("div",{style:o.infoBox,children:[e.jsx(Wt,{}),e.jsxs("div",{children:["Tạo bot mới bằng cách nhắn tin cho ",e.jsx("strong",{children:"@BotFather"})," trên Telegram, dùng lệnh ",e.jsx("strong",{children:"/newbot"})," rồi sao chép token được cấp."]})]}),e.jsxs("div",{style:o.field,children:[e.jsxs("label",{style:o.label,children:["Bot Token ",e.jsx("span",{style:o.labelHint,children:"bắt buộc"})]}),e.jsx("input",{style:o.input,type:"text",value:L,onChange:c=>P(c.target.value),placeholder:"1234567890:AAExxxxxxxxxxxxxxxxxxxxxxxx",autoComplete:"off",spellCheck:!1}),e.jsxs("div",{style:o.inputHint,children:["Định dạng: ",e.jsx("code",{children:"số:ký_tự"}),", ví dụ: ",e.jsx("code",{children:"1234567890:AAExxxxxxxx"})]})]}),e.jsxs("div",{style:o.field,children:[e.jsxs("label",{style:o.label,children:["Tên hiển thị ",e.jsx("span",{style:o.labelHint,children:"tùy chọn"})]}),e.jsx("input",{style:o.input,type:"text",value:K,onChange:c=>T(c.target.value),placeholder:"VD: Bot hỗ trợ cửa hàng"})]}),e.jsxs("div",{style:o.formActions,children:[e.jsx("button",{style:o.btnSecondary,onClick:()=>m({name:"add"}),children:"Hủy"}),e.jsx("button",{style:o.btnPrimary,disabled:z,onClick:()=>void j(),children:z?"Đang kết nối…":"Kết nối Telegram"})]})]})]}),f.name==="connect-livechat"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>m({name:"add"}),children:e.jsx(le,{})}),e.jsx(ie,{provider:"livechat",apiUrl:r,size:44}),e.jsxs("div",{children:[e.jsx("div",{style:o.connectTitle,children:"Tạo Live Chat Widget"}),e.jsx("div",{style:o.connectDesc,children:"Nhúng vào website để nhận tin nhắn từ khách hàng"})]})]}),e.jsxs("div",{style:o.form,children:[e.jsxs("div",{style:o.field,children:[e.jsxs("label",{style:o.label,children:["Tên widget ",e.jsx("span",{style:o.labelHint,children:"bắt buộc"})]}),e.jsx("input",{style:o.input,type:"text",value:O,onChange:c=>F(c.target.value),placeholder:"VD: Hỗ trợ website hanashop.vn"})]}),e.jsxs("div",{style:o.field,children:[e.jsxs("label",{style:o.label,children:["Tên miền được phép ",e.jsx("span",{style:o.labelHint,children:"tùy chọn"})]}),e.jsx("textarea",{style:{...o.input,resize:"vertical",minHeight:80,lineHeight:1.5},value:w,onChange:c=>q(c.target.value),placeholder:`https://myshop.com
|
|
114
|
+
https://www.myshop.com`,spellCheck:!1}),e.jsx("div",{style:o.inputHint,children:"Mỗi domain một dòng. Để trống để cho phép tất cả."})]}),e.jsxs("div",{style:o.formActions,children:[e.jsx("button",{style:o.btnSecondary,onClick:()=>m({name:"add"}),children:"Hủy"}),e.jsx("button",{style:o.btnPrimary,disabled:z,onClick:()=>void J(),children:z?"Đang tạo…":"Tạo widget"})]})]})]}),f.name==="livechat-result"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>m({name:"list"}),children:e.jsx(le,{})}),e.jsx(ie,{provider:"livechat",apiUrl:r,size:44}),e.jsxs("div",{children:[e.jsx("div",{style:o.connectTitle,children:"Widget đã được tạo!"}),e.jsx("div",{style:o.connectDesc,children:"Sao chép mã nhúng và dán vào website của bạn"})]})]}),e.jsxs("div",{style:o.form,children:[e.jsxs("div",{style:o.resultBanner,children:[e.jsx("span",{style:{fontSize:16,flexShrink:0},children:"✅"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Tạo thành công!"})," Dán đoạn script dưới đây vào thẻ ",e.jsx("code",{style:{background:"#dcfce7",padding:"1px 4px",borderRadius:4},children:"</body>"})," của website."]})]}),e.jsxs("div",{children:[e.jsx("div",{style:o.codeLabel,children:"Mã nhúng"}),e.jsxs("div",{style:o.codeBlock,children:[e.jsx("pre",{style:o.codePre,children:f.embedScript}),e.jsx("button",{style:{...o.copyBtn,...Y?{background:"#166534",borderColor:"#166534",color:"#bbf7d0"}:{}},onClick:()=>oe(f.embedScript,"script"),children:Y?e.jsxs(e.Fragment,{children:[e.jsx(Ee,{})," Đã sao chép"]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{})," Sao chép"]})})]})]}),f.identitySecret&&e.jsxs("div",{children:[e.jsxs("div",{style:o.codeLabel,children:["Identity Secret ",e.jsx("span",{style:{...o.labelHint,color:"#dc2626",fontWeight:600},children:"Lưu ngay — chỉ hiển thị một lần"})]}),e.jsxs("div",{style:o.secretRow,children:[e.jsx(Bt,{}),e.jsx("span",{style:o.secretLabel,children:"Secret:"}),e.jsx("span",{style:o.secretValue,children:f.identitySecret}),e.jsx("button",{onClick:()=>oe(f.identitySecret,"secret"),style:{border:"none",background:"transparent",cursor:"pointer",color:$?"#059669":"#ca8a04",padding:2,display:"flex",alignItems:"center"},children:$?e.jsx(Ee,{}):e.jsx(He,{})})]}),e.jsx("div",{style:{...o.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."})]}),e.jsxs("div",{style:o.formActions,children:[e.jsx("button",{style:o.btnSecondary,onClick:()=>m({name:"list"}),children:"Về danh sách"}),e.jsx("button",{style:o.btnPrimary,onClick:()=>m({name:"add"}),children:"Thêm kênh khác"})]})]})]}),f.name==="oauth-waiting"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:o.header,children:e.jsxs("div",{style:o.headerLeft,children:[e.jsx("button",{style:o.backBtn,onClick:Z,children:e.jsx(le,{})}),e.jsxs("div",{children:[e.jsxs("div",{style:o.title,children:["Đang xác thực ",xe[f.provider]]}),e.jsx("div",{style:o.subtitle,children:"Vui lòng hoàn thành trong cửa sổ bật lên"})]})]})}),e.jsxs("div",{style:o.oauthWaiting,children:[e.jsxs("div",{style:{position:"relative",width:72,height:72},children:[e.jsx("div",{style:{width:72,height:72,borderRadius:20,background:Tt[f.provider]??"#f1f5f9",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ie,{provider:f.provider,apiUrl:r,size:48})}),e.jsxs("svg",{width:92,height:92,viewBox:"0 0 92 92",fill:"none",style:{position:"absolute",top:-10,left:-10,animation:"ch-spin 1.2s linear infinite"},children:[e.jsx("circle",{cx:"46",cy:"46",r:"42",stroke:"#e2e8f0",strokeWidth:"3.5"}),e.jsx("circle",{cx:"46",cy:"46",r:"42",stroke:"#2563eb",strokeWidth:"3.5",strokeLinecap:"round",strokeDasharray:"66 198"})]})]}),e.jsxs("div",{style:o.oauthTitle,children:["Đang chờ xác thực với ",xe[f.provider]]}),e.jsx("div",{style:o.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."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,alignItems:"flex-start",width:"100%",maxWidth:280},children:[e.jsx(we,{done:!0,label:`Đã mở cửa sổ ${xe[f.provider]}`}),e.jsx(we,{active:!0,label:"Đang chờ bạn đăng nhập & cấp quyền"}),e.jsx(we,{label:"Lưu kết nối & quay về"})]}),e.jsx("button",{style:o.oauthCancel,onClick:Z,children:"Hủy và quay lại"})]})]}),f.name==="oauth-select"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:Z,children:e.jsx(le,{})}),e.jsx(ie,{provider:f.provider,apiUrl:r,size:44}),e.jsxs("div",{children:[e.jsxs("div",{style:o.connectTitle,children:["Chọn ",f.provider==="instagram"?"tài khoản":"trang"]}),e.jsxs("div",{style:o.connectDesc,children:["Chọn ",xe[f.provider]," bạn muốn kết nối với ChannelHub"]})]})]}),e.jsx("div",{style:o.body,children:f.pages.length===0?e.jsx("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."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:f.pages.map(c=>e.jsxs("button",{disabled:z,onClick:()=>void se(c.id),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:12,border:"1.5px solid #e2e8f0",background:"#fff",cursor:z?"not-allowed":"pointer",opacity:z?.6:1,textAlign:"left",fontFamily:"inherit",transition:"border-color .15s, background .15s"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#0f172a"},children:c.name}),e.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontFamily:"monospace",marginTop:2},children:c.id})]}),e.jsx("span",{style:{fontSize:13,color:"#2563eb",fontWeight:500},children:z?"Đang kết nối…":"Chọn →"})]},c.id))})})]})]})}function Ht(t){const n=t.metadata;if(typeof n.pictureUrl=="string")return n.pictureUrl;if(t.provider==="facebook")return`https://graph.facebook.com/${t.externalAccountId}/picture?type=square`;if(t.provider==="instagram"){const i=typeof n.pageId=="string"?n.pageId:null;if(i)return`https://graph.facebook.com/${i}/picture?type=square`}return null}function Et({conn:t,apiUrl:n,size:i=40}){const[r,d]=s.useState(!1),y=Ht(t),v=Math.round(i*.28);return y&&!r?e.jsx("img",{src:y,alt:ze(t),referrerPolicy:"no-referrer",onError:()=>d(!0),style:{width:i,height:i,borderRadius:v,objectFit:"cover",flexShrink:0,display:"block"}}):e.jsx(ie,{provider:t.provider,apiUrl:n,size:i})}function Mt({conn:t,apiUrl:n,onDisconnect:i}){const[r,d]=s.useState(!1);return e.jsxs("div",{style:o.channelItem,children:[e.jsx(Et,{conn:t,apiUrl:n,size:40}),e.jsxs("div",{style:o.channelInfo,children:[e.jsx("div",{style:o.channelName,children:ze(t)}),e.jsx("div",{style:o.channelMeta,children:Rt(t)})]}),e.jsxs("div",{style:o.channelActions,children:[e.jsx("span",{style:t.status==="active"?o.badgeActive:o.badgeInactive,children:t.status==="active"?"Hoạt động":t.status}),e.jsx("button",{style:{...o.disconnectBtn,...r?{background:"#fef2f2",borderColor:"#fca5a5",color:"#dc2626"}:{}},onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onClick:i,children:"Ngắt kết nối"})]})]})}const At=[{id:"facebook",name:"Facebook",desc:"Fanpage & Messenger",type:"oauth"},{id:"zalo",name:"Zalo OA",desc:"Official Account",type:"oauth"},{id:"instagram",name:"Instagram",desc:"DM & Comments",type:"oauth"},{id:"telegram",name:"Telegram",desc:"Bot token",type:"token"},{id:"livechat",name:"Live Chat",desc:"Website widget",type:"livechat"}];function Ot({provider:t,apiUrl:n,onClick:i}){const[r,d]=s.useState(!1);return e.jsxs("div",{style:{...o.providerCard,...r?{background:"#fff",borderColor:"#e2e8f0",boxShadow:"0 2px 8px rgba(0,0,0,.07)",transform:"translateY(-1px)"}:{}},onClick:i,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsx(ie,{provider:t.id,apiUrl:n,size:44}),e.jsxs("div",{children:[e.jsx("div",{style:o.providerName,children:t.name}),e.jsx("div",{style:o.providerDesc,children:t.desc})]})]})}function we({done:t,active:n,label:i}){const r=t?"#059669":n?"#2563eb":"#cbd5e1";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,fontSize:13,color:t?"#059669":n?"#0f172a":"#94a3b8"},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:r,flexShrink:0,...n?{boxShadow:"0 0 0 3px rgba(37,99,235,.2)"}:{}}}),i]})}console.log("[ChannelHub] widget v0.1.4 loaded");exports.ChannelHubChannels=Lt;exports.ChannelHubClient=Pe;exports.ChannelHubInbox=yt;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ChannelHubInbox } from './ChannelHubInbox.js';
|
|
2
|
+
export { ChannelHubChannels } from './ChannelHubChannels.js';
|
|
3
|
+
export { ChannelHubClient } from './api.js';
|
|
4
|
+
export type { WidgetProps, WidgetTheme, Conversation, Message, ChannelHubInboxHandle } from './types.js';
|
|
5
|
+
export type { ChannelHubChannelsProps, ChannelConnection } from './ChannelHubChannels.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACzG,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
|