@channelhub/widget 0.0.0-stage → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/ChannelHubChannels.d.ts +15 -0
  2. package/dist/ChannelHubChannels.d.ts.map +1 -0
  3. package/dist/ChannelHubInbox.d.ts +3 -0
  4. package/dist/ChannelHubInbox.d.ts.map +1 -0
  5. package/dist/LiveChatWidget.d.ts +12 -0
  6. package/dist/LiveChatWidget.d.ts.map +1 -0
  7. package/dist/api.d.ts +20 -0
  8. package/dist/api.d.ts.map +1 -0
  9. package/dist/channels/ProviderLogo.d.ts +8 -0
  10. package/dist/channels/ProviderLogo.d.ts.map +1 -0
  11. package/dist/components/ui/avatar.d.ts +8 -0
  12. package/dist/components/ui/avatar.d.ts.map +1 -0
  13. package/dist/components/ui/button.d.ts +5 -0
  14. package/dist/components/ui/button.d.ts.map +1 -0
  15. package/dist/components/ui/index.d.ts +6 -0
  16. package/dist/components/ui/index.d.ts.map +1 -0
  17. package/dist/components/ui/input.d.ts +3 -0
  18. package/dist/components/ui/input.d.ts.map +1 -0
  19. package/dist/components/ui/scroll-area.d.ts +6 -0
  20. package/dist/components/ui/scroll-area.d.ts.map +1 -0
  21. package/dist/components/ui/textarea.d.ts +3 -0
  22. package/dist/components/ui/textarea.d.ts.map +1 -0
  23. package/dist/facebook_icon.avif +0 -0
  24. package/dist/index.cjs +99 -0
  25. package/dist/index.d.ts +6 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +1975 -0
  28. package/dist/instagram_icon.avif +0 -0
  29. package/dist/livechat-standalone.d.ts +23 -0
  30. package/dist/livechat-standalone.d.ts.map +1 -0
  31. package/dist/standalone.d.ts +22 -0
  32. package/dist/standalone.d.ts.map +1 -0
  33. package/dist/telegram_icon.avif +0 -0
  34. package/dist/types.d.ts +66 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/web.avif +0 -0
  37. package/dist/zalo_icon.avif +0 -0
  38. package/package.json +45 -3
  39. package/public/facebook_icon.avif +0 -0
  40. package/public/instagram_icon.avif +0 -0
  41. package/public/telegram_icon.avif +0 -0
  42. package/public/web.avif +0 -0
  43. package/public/zalo_icon.avif +0 -0
  44. package/src/ChannelHubChannels.tsx +941 -0
  45. package/src/ChannelHubInbox.tsx +769 -0
  46. package/src/LiveChatWidget.tsx +380 -0
  47. package/src/api.ts +84 -0
  48. package/src/assets/facebook_icon.avif +0 -0
  49. package/src/assets/instagram_icon.avif +0 -0
  50. package/src/assets/telegram_icon.avif +0 -0
  51. package/src/assets/web.avif +0 -0
  52. package/src/assets/zalo_icon.avif +0 -0
  53. package/src/assets.d.ts +4 -0
  54. package/src/channels/ProviderLogo.tsx +59 -0
  55. package/src/components/ui/avatar.tsx +2 -0
  56. package/src/components/ui/button.tsx +4 -0
  57. package/src/components/ui/index.ts +5 -0
  58. package/src/components/ui/input.tsx +2 -0
  59. package/src/components/ui/scroll-area.tsx +5 -0
  60. package/src/components/ui/textarea.tsx +2 -0
  61. package/src/index.ts +8 -0
  62. package/src/livechat-standalone.tsx +75 -0
  63. package/src/standalone.tsx +68 -0
  64. package/src/types.ts +65 -0
  65. package/tsconfig.json +14 -0
  66. package/vite.config.ts +76 -0
  67. package/README.md +0 -3
@@ -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,3 @@
1
+ import type { ChannelHubInboxHandle, WidgetProps } from './types.js';
2
+ export declare const ChannelHubInbox: import("react").ForwardRefExoticComponent<WidgetProps & import("react").RefAttributes<ChannelHubInboxHandle>>;
3
+ //# sourceMappingURL=ChannelHubInbox.d.ts.map
@@ -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;AAsE3I,eAAO,MAAM,eAAe,+GA6M1B,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;AAgCD,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAwB,EAAE,QAAwD,EAAE,KAA4B,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,mBAAmB,+BA6K3M"}
package/dist/api.d.ts ADDED
@@ -0,0 +1,20 @@
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
+ uploadAttachment(file: File): Promise<{
14
+ url: string;
15
+ mimeType: string;
16
+ attachmentType: string;
17
+ }>;
18
+ connectSSE(onEvent: (type: string, data: unknown) => void): () => void;
19
+ }
20
+ //# 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;IAQ/C,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,8 @@
1
+ interface ProviderLogoProps {
2
+ provider: string;
3
+ apiUrl: string;
4
+ size?: number;
5
+ }
6
+ export declare function ProviderLogo({ provider, apiUrl, size }: ProviderLogoProps): import("react").JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=ProviderLogo.d.ts.map
@@ -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,8 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare function Avatar({ src, alt, fallback, style }: {
3
+ src?: string;
4
+ alt?: string;
5
+ fallback: ReactNode;
6
+ style?: React.CSSProperties;
7
+ }): import("react").JSX.Element;
8
+ //# sourceMappingURL=avatar.d.ts.map
@@ -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,6 @@
1
+ export { Avatar } from './avatar.js';
2
+ export { Button } from './button.js';
3
+ export { Input } from './input.js';
4
+ export { ScrollArea } from './scroll-area.js';
5
+ export { Textarea } from './textarea.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ import type { InputHTMLAttributes } from 'react';
2
+ export declare function Input({ style, ...props }: InputHTMLAttributes<HTMLInputElement>): import("react").JSX.Element;
3
+ //# sourceMappingURL=input.d.ts.map
@@ -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,3 @@
1
+ import type { TextareaHTMLAttributes } from 'react';
2
+ export declare function Textarea({ style, ...props }: TextareaHTMLAttributes<HTMLTextAreaElement>): import("react").JSX.Element;
3
+ //# sourceMappingURL=textarea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../../src/components/ui/textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AACpD,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,+BAAwN"}
Binary file
package/dist/index.cjs ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),We=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 Ge=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),He=(...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 Xe={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 Ye=a.forwardRef(({color:t="currentColor",size:n=24,strokeWidth:i=2,absoluteStrokeWidth:r,className:p="",children:f,iconNode:m,...z},h)=>a.createElement("svg",{ref:h,...Xe,width:n,height:n,stroke:t,strokeWidth:r?Number(i)*24/Number(n):i,className:He("lucide",p),...z},[...m.map(([g,w])=>a.createElement(g,w)),...Array.isArray(f)?f:[f]]));/**
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 A=(t,n)=>{const i=a.forwardRef(({className:r,...p},f)=>a.createElement(Ye,{ref:f,iconNode:n,className:He(`lucide-${Ge(t)}`,r),...p}));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 we=A("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 Je=A("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 _e=A("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 Ze=A("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 Qe=A("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 Le=A("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 et=A("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"}]]);/**
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 tt=A("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);/**
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 nt=A("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
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 it=A("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"}]]);/**
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 rt=A("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
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 Se=A("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
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 ot=A("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"}]]);/**
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 st=A("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"}]]);/**
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 le=A("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);class $e{constructor(n,i){this.apiUrl=n,this.token=i}async request(n,i,r){const p={authorization:`Bearer ${this.token}`,...r?{}:{"content-type":"application/json"},...i==null?void 0:i.headers},f=await fetch(`${this.apiUrl}${n}`,{...i,headers:p}),m=await f.json().catch(()=>null);if(!f.ok)throw new Error((m==null?void 0:m.message)??`Request failed (${f.status})`);return m}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})`)}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,p,f=!1;const m=()=>{r=new EventSource(i),r.addEventListener("message.new",z=>{n("message.new",JSON.parse(z.data))}),r.addEventListener("conversation.updated",z=>{n("conversation.updated",JSON.parse(z.data))}),r.onerror=()=>{r.close(),f||(p=setTimeout(m,5e3))}};return m(),()=>{f=!0,clearTimeout(p),r==null||r.close()}}}function Me({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 at({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 lt({style:t,...n}){return e.jsx("input",{...n,style:{width:"100%",minWidth:0,border:0,outline:0,background:"transparent",font:"inherit",...t}})}const Ee=a.forwardRef(({children:t,style:n},i)=>e.jsx("div",{ref:i,style:{minHeight:0,overflowY:"auto",overscrollBehavior:"contain",...n},children:t}));function dt({style:t,...n}){return e.jsx("textarea",{...n,style:{display:"block",width:"100%",minWidth:0,boxSizing:"border-box",resize:"vertical",border:0,outline:0,background:"transparent",font:"inherit",...t}})}const l={ink:"#172033",muted:"#718096",line:"#e7ebf2",surface:"#f7f9fc",white:"#fff"},ge=a.createContext(""),Ae=a.createContext("");function ct(){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 ht(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 Oe(t){return t==="facebook"?"Facebook Messenger":t==="instagram"?"Instagram":t==="telegram"?"Telegram":t==="zalo"?"Zalo OA":"Channel"}function Ce(t){return t==="facebook"?"Facebook":t==="instagram"?"Instagram":t==="telegram"?"Telegram":t==="zalo"?"Zalo":String(t??"")}const pt=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 Ie({status:t}){return t==="read"?e.jsx(we,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle"}}):t==="delivered"?e.jsx(we,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle",opacity:.5}}):t==="sent"?e.jsx(Je,{size:11,strokeWidth:2,style:{display:"inline",verticalAlign:"middle"}}):null}const ut=a.forwardRef(function({apiUrl:n,token:i,theme:r,height:p,defaultConversationId:f,disableAttachments:m,disableNotificationSound:z,hideKeyboardHint:h,locale:g="vi",onNewMessage:w,onConversationSelect:k},W){var me,be,ve,je,ke;const S=a.useRef(new $e(n,i)),[R,N]=a.useState([]),[K,D]=a.useState([]),[U,G]=a.useState(),[j,F]=a.useState(),P=a.useRef(void 0),[x,C]=a.useState(""),[B,T]=a.useState({provider:"all",unreadOnly:!1}),[E,b]=a.useState(!1),q=a.useRef(null),J=a.useRef(null),[V,ee]=a.useState(null),[_,Z]=a.useState(!0),[s,y]=a.useState(""),[v,H]=a.useState(!1),I=(r==null?void 0:r.primaryColor)??"#2563eb",O=a.useMemo(()=>new Map(K.map(c=>[c.id,c])),[K]),L=a.useRef(null),[se,Fe]=a.useState(0),Pe=a.useMemo(()=>{const c=new Set(K.map(u=>u.provider));return["facebook","instagram","telegram","zalo"].filter(u=>c.has(u))},[K]),Ne=a.useMemo(()=>{var u;const c={};for(const M of R){const $=((u=O.get(M.connectionId))==null?void 0:u.provider)??"unknown";c[$]=(c[$]??0)+1}return c},[R,O]),X=a.useCallback(async c=>{try{const u=await S.current.listConversations(c);N(M=>c?[...M,...u.items]:u.items),G(u.nextCursor),!c&&u.items.length&&F(M=>M??(f?u.items.find($=>$.id===f)??u.items[0]:u.items[0])),y("")}catch(u){y(u instanceof Error?u.message:"Không tải được hội thoại")}finally{Z(!1)}},[f]);a.useEffect(()=>(S.current.listConnections().then(D).catch(()=>{}),X(),S.current.connectSSE((u,M)=>{if(u==="message.new"||u==="conversation.updated"){if(X(),u==="message.new"){const $=typeof M=="object"&&M?M:{},ie=$.conversationId?String($.conversationId):"",ae=$.messageId?String($.messageId):"";if(($.direction?String($.direction):"")==="inbound"&&!z&&ct(),ie&&ie===P.current&&ae&&L.current){const qe=L.current;S.current.getMessage(ae).then(Ve=>{qe(Ve)}).catch(()=>{})}w==null||w(ie||P.current||"")}}else u==="message.status_updated"&&Fe($=>$+1)})),[X,w]),a.useEffect(()=>{P.current=j==null?void 0:j.id},[j]),a.useEffect(()=>{j!=null&&j.unreadCount&&S.current.markRead(j.id).then(()=>X()).catch(()=>{})},[j==null?void 0:j.id]),a.useEffect(()=>{if(!E)return;function c(u){var M,$;(M=q.current)!=null&&M.contains(u.target)||($=J.current)!=null&&$.contains(u.target)||b(!1)}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[E]);const de=a.useMemo(()=>{const c=x.toLowerCase().trim();return R.filter(u=>{var he;const M=`${u.contactName??""} ${u.subject??""} ${u.providerConversationKey}`.toLowerCase(),$=((he=O.get(u.connectionId))==null?void 0:he.provider)??"unknown",ie=B.provider==="all"||$===B.provider,ae=!B.unreadOnly||(u.unreadCount??0)>0;return ie&&ae&&(!c||M.includes(c))})},[R,O,B,x]),ce=B.provider!=="all"||B.unreadOnly,te=g==="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ả"};a.useImperativeHandle(W,()=>({openConversation:c=>{const u=R.find(M=>M.id===c);u&&F(u)},refresh:()=>void X()}),[R,X]);const Ke={...d.frame,height:p??620,...p?{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:v?"minmax(260px, 300px) minmax(0, 1fr) 260px":"minmax(260px, 300px) minmax(0, 1fr)",transition:"grid-template-columns 220ms ease"};return _?e.jsxs("div",{style:{...d.state,borderRadius:(r==null?void 0:r.borderRadius)??"16px"},children:[e.jsx(fe,{})," Đang tải hộp thư…"]}):s&&!R.length?e.jsxs("div",{style:{...d.state,color:"#b42318",borderRadius:(r==null?void 0:r.borderRadius)??"16px"},children:[e.jsx(Qe,{size:16,strokeWidth:2})," ",s,e.jsx("button",{style:d.retry,onClick:()=>{Z(!0),X()},children:"Thử lại"})]}):e.jsx(ge.Provider,{value:n,children:e.jsx(Ae.Provider,{value:i,children:e.jsxs("div",{style:Ke,onFocusCapture:()=>{const c=window.scrollY;requestAnimationFrame(()=>{window.scrollY!==c&&window.scrollTo({top:c,behavior:"instant"})})},children:[e.jsxs("aside",{style:d.sidebar,children:[e.jsxs("div",{style:d.brand,children:[e.jsx("div",{style:{...d.brandMark,background:I,overflow:"hidden",padding:0},children:(me=r==null?void 0:r.branding)!=null&&me.logoUrl?e.jsx("img",{src:r.branding.logoUrl,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):((be=r==null?void 0:r.branding)==null?void 0:be.mark)??"C"}),e.jsxs("div",{children:[e.jsx("strong",{children:((ve=r==null?void 0:r.branding)==null?void 0:ve.name)??"Hộp thư"}),!((je=r==null?void 0:r.branding)!=null&&je.name)&&e.jsx("span",{style:d.eyebrow,children:"CHANNELHUB"})]}),e.jsx(at,{"aria-label":"Tùy chọn",style:d.iconButton,children:e.jsx(Le,{size:16,strokeWidth:2})})]}),e.jsxs("div",{style:d.search,children:[e.jsx(Se,{size:16,strokeWidth:2}),e.jsx(lt,{"aria-label":te.searchPlaceholder,value:x,onChange:c=>C(c.target.value),placeholder:te.searchPlaceholder}),x&&e.jsx("button",{style:d.clear,onClick:()=>C(""),"aria-label":"Xóa tìm kiếm",children:"×"})]}),ce&&e.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap",padding:"0 14px 8px"},children:[B.provider!=="all"&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",color:I,borderRadius:6,fontSize:11,padding:"2px 8px",fontWeight:500},children:[e.jsx(oe,{provider:B.provider}),Ce(B.provider),e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:I,padding:0,lineHeight:1,display:"flex"},onClick:()=>T(c=>({...c,provider:"all"})),"aria-label":"Xóa filter kênh",children:e.jsx(le,{size:10})})]}),B.unreadOnly&&e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",color:I,borderRadius:6,fontSize:11,padding:"2px 8px",fontWeight:500},children:[te.unreadOnly,e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:I,padding:0,lineHeight:1,display:"flex"},onClick:()=>T(c=>({...c,unreadOnly:!1})),"aria-label":"Xóa filter chưa đọc",children:e.jsx(le,{size:10})})]}),e.jsx("button",{style:{border:0,background:"none",cursor:"pointer",color:l.muted,fontSize:11,padding:"2px 4px"},onClick:()=>T({provider:"all",unreadOnly:!1}),children:"Xóa tất cả"})]}),e.jsxs("div",{style:d.listHeader,children:[e.jsxs("span",{children:[de.length," hội thoại"]}),e.jsx("button",{ref:q,style:{...d.iconButton,background:ce?`${I}14`:"transparent",color:ce?I:l.muted},"aria-label":"Bộ lọc",onClick:()=>{var c;if(!E){const u=(c=q.current)==null?void 0:c.getBoundingClientRect();u&&ee({top:u.bottom+6,left:u.left})}b(u=>!u)},children:e.jsx(st,{size:15,strokeWidth:2})})]}),E&&V&&We.createPortal(e.jsxs("div",{ref:J,style:{position:"fixed",top:V.top,left:V.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",...Pe].map(c=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 6px",cursor:"pointer",borderRadius:6,background:B.provider===c?`${I}0f`:"transparent"},children:[e.jsx("input",{type:"radio",name:"provider-filter",checked:B.provider===c,onChange:()=>T(u=>({...u,provider:c})),style:{accentColor:I}}),c==="all"?e.jsxs("span",{style:{color:l.ink},children:[te.all," (",R.length,")"]}):e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,color:l.ink},children:[e.jsx(oe,{provider:c}),Ce(c)," ",e.jsxs("span",{style:{color:l.muted},children:["(",Ne[c]??0,")"]})]})]},c)),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:B.unreadOnly?`${I}0f`:"transparent"},children:[e.jsx("input",{type:"checkbox",checked:B.unreadOnly,onChange:c=>T(u=>({...u,unreadOnly:c.target.checked})),style:{accentColor:I}}),e.jsx("span",{style:{color:l.ink},children:te.unreadOnly})]})]}),document.body),e.jsxs(Ee,{style:d.conversationList,children:[de.map(c=>{var u;return e.jsx(ft,{conversation:c,provider:(u=O.get(c.connectionId))==null?void 0:u.provider,selected:(j==null?void 0:j.id)===c.id,primary:I,onSelect:()=>{F(c),k==null||k(c.id),S.current.markRead(c.id).then(()=>X()).catch(()=>{})}},c.id)}),!de.length&&e.jsxs("div",{style:d.emptySmall,children:[e.jsx("div",{style:d.emptyIcon,children:e.jsx(Se,{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."})]}),U&&e.jsx("button",{style:d.loadMore,onClick:()=>void X(U),children:"Xem thêm hội thoại"})]})]}),e.jsx("main",{style:d.main,children:j?e.jsx(xt,{conversation:j,provider:(ke=O.get(j.connectionId))==null?void 0:ke.provider,connection:O.get(j.connectionId),client:S.current,primary:I,error:s,onRegisterAppend:c=>{L.current=c},refreshKey:se,infoOpen:v,onToggleInfo:()=>H(c=>!c),t:te,disableAttachments:m,hideKeyboardHint:h},j.id):e.jsx(bt,{})}),v&&j&&e.jsx(yt,{conversation:j,connection:O.get(j.connectionId),primary:I,onClose:()=>H(!1)})]})})})});function ft({conversation:t,provider:n,selected:i,primary:r,onSelect:p}){const[f,m]=a.useState(!1),z=t.contactName??t.subject??t.providerConversationKey,h=t.unreadCount??0,g=t.lastMessageText??"",w=t.lastMessageDirection==="outbound"?"Bạn: ":"",k=g.length>60?g.slice(0,60)+"…":g,W=g?w+k:"";let S="transparent";i?S="#eef2ff":f?S="#f7f9fc":h>0&&(S="#f0f4ff");const R={...d.row,background:S,...i?{boxShadow:`inset 3px 0 0 ${r}`}:h>0&&!f?{boxShadow:`inset 3px 0 0 ${r}`}:{}};return e.jsxs("button",{onClick:p,style:R,onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),children:[e.jsx(De,{name:z,color:r,image:t.contactPictureUrl,provider:n}),e.jsxs("span",{style:d.rowBody,children:[e.jsxs("span",{style:d.rowTop,children:[e.jsx("strong",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:h>0?700:500},children:z}),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:xe(t.lastMessageAt)}),h>0&&e.jsx("span",{"aria-label":`${h} tin nhắn chưa đọc`,style:d.unreadBadge,children:h>99?"99+":h})]})]}),e.jsx("span",{style:{...d.rowBottom,color:h>0&&!i?"#4a5568":l.muted},children:e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:W||e.jsx("span",{style:{opacity:.5},children:"Chưa có tin nhắn"})})})]})]})}function xt({conversation:t,provider:n,connection:i,client:r,primary:p,error:f,onRegisterAppend:m,refreshKey:z,infoOpen:h,onToggleInfo:g,t:w,disableAttachments:k,hideKeyboardHint:W}){const[S,R]=a.useState([]),[N,K]=a.useState(),[D,U]=a.useState(""),[G,j]=a.useState(!0),[F,P]=a.useState(!1),[x,C]=a.useState(""),B=a.useRef(null),T=t.contactName??t.subject??t.providerConversationKey,E=a.useRef(null),[b,q]=a.useState(null);a.useEffect(()=>()=>{b!=null&&b.objectUrl&&URL.revokeObjectURL(b.objectUrl)},[b==null?void 0:b.objectUrl]);const J=a.useRef(!0),V=a.useCallback(async(s,y)=>{y||(J.current=!s);try{const v=await r.listMessages(t.id,s);R(H=>s?[...v.items,...H]:v.items),K(v.nextCursor)}catch(v){C(v instanceof Error?v.message:"Không tải được tin nhắn")}finally{y||j(!1)}},[r,t.id]);a.useEffect(()=>{j(!0),V()},[V]),a.useEffect(()=>{z&&V(void 0,!0)},[z]),a.useEffect(()=>{J.current&&requestAnimationFrame(()=>{const s=B.current;s&&(s.scrollTop=s.scrollHeight)})},[S]),a.useEffect(()=>(m==null||m(s=>{J.current=!0,R(y=>y.some(v=>v.id===s.id)?y:[...y,s])}),()=>{m==null||m(null)}),[m]);async function ee(s){var H;const y=(H=s.target.files)==null?void 0:H[0];if(!y)return;s.target.value="";const v=URL.createObjectURL(y);q({file:y,uploading:!0,objectUrl:v});try{const I=await r.uploadAttachment(y);q({file:y,uploading:!1,url:I.url,mimeType:I.mimeType,attachmentType:I.attachmentType,objectUrl:v})}catch{URL.revokeObjectURL(v),q(null),C("Không tải lên được tệp đính kèm")}}async function _(s){s.preventDefault();const y=D.trim(),v=b!=null&&b.url?[{url:b.url,mimeType:b.mimeType??"application/octet-stream",type:b.attachmentType}]:[];if(!(!y&&!v.length||F)){P(!0),C("");try{await r.sendMessage(t.id,y||void 0,v.length?v:void 0),b!=null&&b.objectUrl&&URL.revokeObjectURL(b.objectUrl),U(""),q(null),await V()}catch(H){C(H instanceof Error?H.message:"Không gửi được tin nhắn")}finally{P(!1)}}}const Z=!F&&(D.trim().length>0||(b==null?void 0:b.url)!=null&&!b.uploading);return e.jsxs("section",{style:d.chat,children:[e.jsxs("header",{style:d.chatHeader,children:[e.jsx(De,{name:T,color:p,image:t.contactPictureUrl,provider:n}),e.jsxs("div",{style:d.contact,children:[e.jsx("strong",{style:d.contactName,children:T}),e.jsx("span",{style:d.contactMeta,children:ht(i)??Oe(n)})]}),e.jsxs("div",{style:d.headerActions,children:[e.jsx("button",{style:d.iconButton,"aria-label":"Thêm tùy chọn",children:e.jsx(Le,{size:16,strokeWidth:2})}),e.jsx("button",{style:{...d.iconButton,background:h?`${p}14`:"transparent",color:h?p:l.muted},"aria-label":"Thông tin liên hệ",onClick:g,children:e.jsx(tt,{size:16,strokeWidth:2})})]})]}),e.jsxs(Ee,{ref:B,style:d.messageArea,children:[e.jsx("div",{style:d.day,children:w.today}),N&&e.jsx("button",{onClick:()=>void V(N),style:d.historyButton,children:w.loadOlder}),G&&e.jsxs("div",{style:d.messageHint,children:[e.jsx(fe,{})," ",w.loading]}),!G&&!S.length&&e.jsx("div",{style:d.messageHint,children:w.noMessages}),S.map(s=>e.jsx(gt,{message:s,primary:p},s.id))]}),e.jsxs("form",{onSubmit:_,style:d.composer,children:[e.jsxs("div",{style:d.composerBox,children:[b&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:`1px solid ${l.line}`,fontSize:12},children:[b.uploading?e.jsxs(e.Fragment,{children:[e.jsx(fe,{}),e.jsx("span",{style:{color:l.muted},children:"Đang tải lên…"})]}):b.attachmentType==="image"&&b.objectUrl?e.jsx("img",{src:b.objectUrl,alt:"",style:{height:48,width:48,objectFit:"cover",borderRadius:6}}):e.jsxs("span",{style:{color:l.muted},children:["📎 ",b.file.name," (",Math.round(b.file.size/1024)," KB)"]}),!b.uploading&&e.jsx("button",{type:"button",onClick:()=>{b!=null&&b.objectUrl&&URL.revokeObjectURL(b.objectUrl),q(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.jsx(dt,{"aria-label":"Soạn tin nhắn",rows:1,value:D,onChange:s=>U(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),_(s))},placeholder:w.sendPlaceholder,style:d.textarea}),e.jsxs("div",{style:d.composerTools,children:[!W&&e.jsx("span",{children:"↵ Gửi · ⇧↵ Xuống dòng"}),!k&&e.jsx("button",{type:"button",style:d.iconButton,"aria-label":"Đính kèm tệp",onClick:()=>{var s;return(s=E.current)==null?void 0:s.click()},children:e.jsx(it,{size:16,strokeWidth:2})}),!k&&e.jsx("input",{ref:E,type:"file",style:{display:"none"},onChange:ee,accept:"image/jpeg,image/png,image/gif,image/webp,application/pdf,video/mp4,audio/mpeg,audio/ogg"})]})]}),e.jsx("button",{disabled:!Z,"aria-label":"Gửi tin nhắn",style:{...d.send,background:p,opacity:Z?1:.5,cursor:Z?"pointer":"not-allowed"},children:e.jsx(ot,{size:16,strokeWidth:2})})]}),(x||f)&&e.jsx("div",{role:"alert",style:d.error,children:x||f})]})}function gt({message:t,primary:n}){var U,G,j,F,P;const i=a.useContext(ge),r=a.useContext(Ae),p=x=>x.startsWith("/v1/media/proxy")?`${i}${x}&tok=${encodeURIComponent(r)}`:x,f=t.direction==="outbound",m=((U=t.attachments)==null?void 0:U.filter(x=>x.type==="image"))??[],z=((G=t.attachments)==null?void 0:G.filter(x=>x.type==="sticker"))??[],h=((j=t.attachments)==null?void 0:j.filter(x=>x.type==="video"))??[],g=((F=t.attachments)==null?void 0:F.filter(x=>x.type==="audio"))??[],w=((P=t.attachments)==null?void 0:P.filter(x=>x.type==="file"))??[],[k,W]=a.useState(null),S=f?"flex-end":"flex-start",R=e.jsxs("time",{style:{display:"block",marginTop:4,fontSize:10,opacity:.65,textAlign:"right",letterSpacing:.2,userSelect:"none"},children:[xe(t.occurredAt,!0),f&&e.jsxs(e.Fragment,{children:[" ",e.jsx(Ie,{status:t.status})]})]}),N=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:[xe(t.occurredAt,!0),f&&e.jsxs(e.Fragment,{children:[" ",e.jsx(Ie,{status:t.status})]})]})}),K=f?{...d.bubbleOut,background:n,color:"#fff",border:"1px solid transparent"}:d.bubbleIn,D=!t.text&&g.length===0&&w.length===0;return e.jsxs("div",{style:{...d.messageLine,justifyContent:S,flexDirection:"column",alignItems:S},children:[z.map((x,C)=>e.jsxs("div",{style:{position:"relative",marginBottom:2},children:[e.jsx("img",{src:p(x.url),alt:"sticker",style:{display:"block",maxWidth:128,maxHeight:128,objectFit:"contain"}}),D&&m.length===0&&h.length===0&&C===z.length-1&&N]},`s${C}`)),m.map((x,C)=>e.jsxs("div",{style:{position:"relative",marginBottom:2,cursor:"zoom-in"},onClick:()=>W({url:p(x.url),kind:"image"}),children:[e.jsx("img",{src:p(x.url),alt:"",style:{display:"block",maxWidth:260,maxHeight:260,borderRadius:12,objectFit:"cover"}}),D&&C===m.length-1&&h.length===0&&N]},C)),h.map((x,C)=>e.jsxs("div",{style:{position:"relative",marginBottom:2,cursor:"pointer"},onClick:()=>W({url:p(x.url),kind:"video"}),children:[e.jsx("video",{src:p(x.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(rt,{size:16,fill:"#172033",color:"#172033",style:{marginLeft:2}})})}),D&&C===h.length-1&&N]},C)),(g.length>0||w.length>0||t.text||!m.length&&!h.length&&!z.length&&!t.text)&&e.jsxs("div",{style:K,children:[g.map((x,C)=>e.jsx("audio",{src:p(x.url),controls:!0,style:{display:"block",width:"100%",marginBottom:4}},C)),w.map((x,C)=>e.jsxs("a",{href:p(x.url),target:"_blank",rel:"noreferrer",style:{display:"block",fontSize:12,color:f?"#fff":"#2563eb",textDecoration:"underline",marginBottom:4},children:["📎 ",pt(x.mimeType)]},C)),t.text&&e.jsx("p",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:t.text}),!g.length&&!w.length&&!t.text&&e.jsx("p",{style:{margin:0,opacity:.5},children:"[attachment]"}),R]}),k&&We.createPortal(e.jsxs("div",{onClick:()=>W(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:x=>x.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:x=>x.stopPropagation()}),e.jsx("button",{onClick:()=>W(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(le,{size:18})})]}),document.body)]})}function yt({conversation:t,connection:n,primary:i,onClose:r}){const p=t.contactName??t.subject??t.providerConversationKey,f=n==null?void 0:n.provider,[m,z]=a.useState({channel:!0,stats:!1,extra:!1}),h=g=>z(w=>({...w,[g]:!w[g]}));return e.jsxs("aside",{style:d.infoPanel,children:[e.jsxs("div",{style:d.infoPanelHeader,children:[e.jsx("span",{style:{fontWeight:600,fontSize:13,color:l.ink},children:"Thông tin liên hệ"}),e.jsx("button",{style:d.iconButton,onClick:r,"aria-label":"Đóng",children:e.jsx(le,{size:16,strokeWidth:2})})]}),e.jsxs("div",{style:{overflowY:"auto",flex:1},children:[e.jsxs("div",{style:d.infoPanelIdentity,children:[e.jsxs("span",{style:{...d.avatarWrap,width:48,height:48},children:[e.jsx(Me,{src:t.contactPictureUrl,fallback:Ue(p),style:{...d.avatar,width:48,height:48,fontSize:16}}),e.jsx("span",{style:{...d.providerBadge,width:20,height:20},children:e.jsx(oe,{provider:f})})]}),e.jsx("strong",{style:{marginTop:10,fontSize:15,color:l.ink,textAlign:"center"},children:p}),e.jsx("span",{style:{fontSize:11,color:l.muted,fontFamily:"monospace",textAlign:"center"},children:t.providerConversationKey})]}),e.jsxs(pe,{label:"KÊNH",sectionKey:"channel",expanded:m.channel,onToggle:()=>h("channel"),children:[e.jsx(Y,{label:"Nền tảng",children:e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5},children:[e.jsx(oe,{provider:f}),e.jsx("span",{children:Oe(f)})]})}),e.jsxs(Y,{label:"ID hội thoại",children:[e.jsxs("span",{style:{fontFamily:"monospace",fontSize:11},children:[t.id.slice(0,8),"…"]}),e.jsx(mt,{value:t.id})]})]}),e.jsxs(pe,{label:"THỐNG KÊ",sectionKey:"stats",expanded:m.stats,onToggle:()=>h("stats"),children:[e.jsx(Y,{label:"Tin nhắn",value:String(t.messageCount??0)}),(t.unreadCount??0)>0&&e.jsx(Y,{label:"Chưa đọc",value:String(t.unreadCount),valueColor:"#ef4444"}),e.jsx(Y,{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(Y,{label:"Lần đầu",value:"—"})]}),e.jsxs(pe,{label:"THÔNG TIN BỔ SUNG",sectionKey:"extra",expanded:m.extra,onToggle:()=>h("extra"),children:[e.jsx(Y,{label:"Điện thoại",value:"— chưa có",valueMuted:!0}),e.jsx(Y,{label:"Email",value:"— chưa có",valueMuted:!0}),e.jsx(Y,{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:{...d.ghostButton,color:i,borderColor:`${i}33`},children:"Xem lịch sử"}),e.jsx("button",{style:{...d.ghostButton,color:i,borderColor:`${i}33`},children:"Thêm ghi chú"})]})]})]})}function pe({label:t,children:n,sectionKey:i,expanded:r,onToggle:p}){const f=!!p,m=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:f?"pointer":"default"},onClick:p,children:[e.jsx("span",{children:t}),f&&(m?e.jsx(_e,{size:12,strokeWidth:2}):e.jsx(Ze,{size:12,strokeWidth:2}))]}),m&&n]})}function Y({label:t,value:n,children:i,valueColor:r,valueMuted:p}){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??(p?l.muted:l.ink),textAlign:"right",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"flex",alignItems:"center",gap:4},children:i??n})]})}function mt({value:t}){const[n,i]=a.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 bt(){return e.jsxs("div",{style:d.empty,children:[e.jsx("div",{style:d.emptyHero,children:e.jsx(et,{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 De({name:t,color:n,image:i,provider:r}){return e.jsxs("span",{style:d.avatarWrap,children:[e.jsx(vt,{name:t,color:n,image:i}),r&&e.jsx("span",{style:d.providerBadge,children:e.jsx(oe,{provider:r})})]})}function vt({name:t,color:n,image:i}){return e.jsx(Me,{src:i,fallback:Ue(t),style:{...d.avatar,background:`${n}18`,color:n}})}function fe(){return e.jsx(nt,{size:14,style:d.spinner,"aria-hidden":"true"})}function Ue(t){return t.split(/\s+/).filter(Boolean).slice(-2).map(n=>n[0]).join("").toUpperCase()||"?"}const jt={livechat:"web"};function oe({provider:t}){const n=a.useContext(ge),i=14;if(!t)return null;const r=jt[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 xe(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 d={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},composer:{flex:"0 0 auto",display:"flex",alignItems:"flex-end",gap:10,padding:"10px 14px 12px",borderTop:`1px solid ${l.line}`,background:l.white},textarea:{display:"block",width:"100%",minWidth:0,boxSizing:"border-box",minHeight:44,maxHeight:120,resize:"vertical",border:0,outline:0,background:"transparent",color:l.ink,padding:"10px 12px 4px",font:"inherit",fontSize:13,lineHeight:1.45},composerBox:{flex:1,minWidth:0,border:`1px solid ${l.line}`,borderRadius:10,background:l.surface,overflow:"hidden"},send:{display:"grid",placeItems:"center",width:38,height:38,border:0,borderRadius:"50%",color:"#fff",flexShrink:0},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"},composerTools:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 8px 4px 12px",color:"#a0aabd",fontSize:12},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"}},kt={facebook:"#dbeafe",zalo:"#e0f2fe",instagram:"#fce7f3",telegram:"#cffafe",livechat:"#ede9fe",whatsapp:"#dcfce7"},wt={facebook:"facebook",instagram:"instagram",telegram:"telegram",zalo:"zalo",livechat:"web",whatsapp:"web"};function Q({provider:t,apiUrl:n,size:i=40}){const r=kt[t]??"#f1f5f9",p=wt[t],f=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:p?e.jsx("img",{src:`${f}/static/logos/${p}.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 re={facebook:"Facebook",zalo:"Zalo OA",instagram:"Instagram",telegram:"Telegram",livechat:"Live Chat",whatsapp:"WhatsApp"},St={facebook:"#dbeafe",zalo:"#e0f2fe",instagram:"#fce7f3",telegram:"#cffafe",livechat:"#ede9fe",whatsapp:"#dcfce7"};function ye(t){const n=t.metadata;return String(n.displayName??n.pageName??n.username??n.name??t.externalAccountId)}function Ct(t){const n=re[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 ze(){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 ne(){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 Te(){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 Re(){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 It(){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 zt(){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 Be=!1;function Tt(){if(Be||typeof document>"u")return;Be=!0;const t=document.createElement("style");t.textContent="@keyframes ch-spin{to{transform:rotate(360deg)}}",document.head.appendChild(t)}function Rt({apiUrl:t,token:n,onConnectionChange:i}){const r=t.replace(/\/$/,""),[p,f]=a.useState([]),[m,z]=a.useState(!0),[h,g]=a.useState({name:"list"}),[w,k]=a.useState(null),[W,S]=a.useState(!1),[R,N]=a.useState(""),[K,D]=a.useState(""),[U,G]=a.useState(""),[j,F]=a.useState(""),[P,x]=a.useState(!1),[C,B]=a.useState(!1),T=a.useRef(null);Tt();const E=a.useCallback(async()=>{try{const s=await fetch(`${r}/v1/connections`,{headers:{authorization:`Bearer ${n}`}});if(!s.ok)throw new Error("Không tải được kênh");const y=await s.json();f(y),i==null||i(y)}catch(s){k(s instanceof Error?s.message:"Lỗi tải dữ liệu")}finally{z(!1)}},[r,n,i]);a.useEffect(()=>{E()},[E]),a.useEffect(()=>{if(!w)return;const s=setTimeout(()=>k(null),5e3);return()=>clearTimeout(s)},[w]),a.useEffect(()=>()=>{T.current&&window.removeEventListener("message",T.current)},[]);async function b(s,y){if(confirm(`Bạn chắc chắn muốn ngắt kết nối "${y}"?
97
+
98
+ Hành động này không thể hoàn tác.`))try{if(!(await fetch(`${r}/v1/connections/${s}`,{method:"DELETE",headers:{authorization:`Bearer ${n}`}})).ok)throw new Error("Không thể ngắt kết nối");await E()}catch(v){k(v instanceof Error?v.message:"Lỗi ngắt kết nối")}}async function q(){if(!R.trim()){k("Vui lòng nhập Bot Token");return}if(!/^\d+:[A-Za-z0-9_-]+$/.test(R.trim())){k("Token không đúng định dạng");return}S(!0),k(null);try{const s=await fetch(`${r}/v1/connect/telegram/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({botToken:R.trim(),displayName:K.trim()||void 0})}),y=await s.json();if(!s.ok||!y.connectionId)throw new Error(y.message??"Không thể kết nối Telegram");N(""),D(""),await E(),g({name:"list"})}catch(s){k(s instanceof Error?s.message:"Lỗi kết nối")}finally{S(!1)}}async function J(){if(!U.trim()){k("Vui lòng nhập tên widget");return}S(!0),k(null);try{const s=j.split(/[\n,]+/).map(H=>H.trim()).filter(Boolean),y=await fetch(`${r}/v1/connect/livechat/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({displayName:U.trim(),allowedDomains:s.length?s:void 0})}),v=await y.json();if(!y.ok||!v.connectionId||!v.embedScript)throw new Error(v.message??"Không thể tạo widget");G(""),F(""),await E(),g({name:"livechat-result",connectionId:v.connectionId,embedScript:v.embedScript,identitySecret:v.identitySecret??"",allowedDomains:v.allowedDomains??[]})}catch(s){k(s instanceof Error?s.message:"Lỗi tạo widget")}finally{S(!1)}}async function V(s){k(null);try{const y=`${r}/static/oauth-popup.html`,v=await fetch(`${r}/v1/connect/${s}/start`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({callbackUrl:y})}),H=await v.json();if(!v.ok||!H.authorizationUrl)throw new Error(H.message??"Không thể bắt đầu kết nối");const I=window.open(H.authorizationUrl,"channelhub-oauth","width=600,height=700,scrollbars=yes,resizable=yes");g({name:"oauth-waiting",provider:s,popup:I}),T.current&&window.removeEventListener("message",T.current);const O=L=>{if(L.data){if(L.data.type==="channelhub:oauth-select"){g({name:"oauth-select",provider:L.data.provider,sessionId:String(L.data.sessionId??""),pages:L.data.pages??[],popup:I});return}L.data.type==="channelhub:oauth"&&(window.removeEventListener("message",O),T.current=null,L.data.status==="active"?(E(),g({name:"list"})):(k("Kết nối thất bại: "+String(L.data.error??"Không xác định")),g({name:"list"})))}};T.current=O,window.addEventListener("message",O)}catch(y){k(y instanceof Error?y.message:"Lỗi kết nối"),g({name:"list"})}}function ee(s,y){navigator.clipboard.writeText(s).then(()=>{y==="script"?(x(!0),setTimeout(()=>x(!1),2e3)):(B(!0),setTimeout(()=>B(!1),2e3))})}function _(){const s=h.name==="oauth-waiting"||h.name==="oauth-select"?h.popup:null;if(s)try{s.close()}catch{}T.current&&(window.removeEventListener("message",T.current),T.current=null),g({name:"add"})}async function Z(s){if(h.name!=="oauth-select")return;const{provider:y,sessionId:v,popup:H}=h;S(!0),k(null);const I={facebook:`${r}/v1/connect/facebook/select-page`,instagram:`${r}/v1/connect/instagram/select-account`,zalo:`${r}/v1/connect/zalo/select-oa`},O={facebook:"pageId",instagram:"accountId",zalo:"oaId"};try{const L=await fetch(I[y]??`${r}/v1/connect/${y}/select-page`,{method:"POST",headers:{authorization:`Bearer ${n}`,"content-type":"application/json"},body:JSON.stringify({sessionId:v,[O[y]??"pageId"]:s})}),se=await L.json();if(!L.ok||!se.connectionId)throw new Error(se.message??"Không thể kết nối");if(H)try{H.postMessage({type:"channelhub:close-popup"},"*")}catch{}T.current&&(window.removeEventListener("message",T.current),T.current=null),await E(),g({name:"list"})}catch(L){k(L instanceof Error?L.message:"Lỗi kết nối")}finally{S(!1)}}return e.jsxs("div",{style:o.root,children:[w&&e.jsx("div",{style:o.errorBanner,children:w}),h.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:m?"Đang tải…":`${p.filter(s=>s.status==="active").length} kênh đang hoạt động`})]})}),e.jsxs("button",{style:o.addBtn,onClick:()=>g({name:"add"}),children:[e.jsx(ze,{}),e.jsx("span",{children:"Thêm kênh"})]})]}),e.jsx("div",{style:o.divider}),e.jsx("div",{style:o.body,children:!m&&p.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(Q,{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:()=>g({name:"add"}),children:[e.jsx(ze,{}),"Kết nối kênh đầu tiên"]})]}):e.jsx("div",{children:p.map(s=>e.jsx(Ht,{conn:s,apiUrl:r,onDisconnect:()=>void b(s.id,ye(s))},s.id))})})]}),h.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:()=>g({name:"list"}),children:e.jsx(ne,{})}),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:Lt.map(s=>e.jsx($t,{provider:s,apiUrl:r,onClick:()=>{s.type==="oauth"?V(s.id):s.id==="telegram"?g({name:"connect-telegram"}):g({name:"connect-livechat"})}},s.id))})})]}),h.name==="connect-telegram"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>g({name:"add"}),children:e.jsx(ne,{})}),e.jsx(Q,{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(zt,{}),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:R,onChange:s=>N(s.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:s=>D(s.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:()=>g({name:"add"}),children:"Hủy"}),e.jsx("button",{style:o.btnPrimary,disabled:W,onClick:()=>void q(),children:W?"Đang kết nối…":"Kết nối Telegram"})]})]})]}),h.name==="connect-livechat"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>g({name:"add"}),children:e.jsx(ne,{})}),e.jsx(Q,{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:U,onChange:s=>G(s.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:j,onChange:s=>F(s.target.value),placeholder:`https://myshop.com
99
+ 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:()=>g({name:"add"}),children:"Hủy"}),e.jsx("button",{style:o.btnPrimary,disabled:W,onClick:()=>void J(),children:W?"Đang tạo…":"Tạo widget"})]})]})]}),h.name==="livechat-result"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:()=>g({name:"list"}),children:e.jsx(ne,{})}),e.jsx(Q,{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:h.embedScript}),e.jsx("button",{style:{...o.copyBtn,...P?{background:"#166534",borderColor:"#166534",color:"#bbf7d0"}:{}},onClick:()=>ee(h.embedScript,"script"),children:P?e.jsxs(e.Fragment,{children:[e.jsx(Re,{})," Đã sao chép"]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{})," Sao chép"]})})]})]}),h.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(It,{}),e.jsx("span",{style:o.secretLabel,children:"Secret:"}),e.jsx("span",{style:o.secretValue,children:h.identitySecret}),e.jsx("button",{onClick:()=>ee(h.identitySecret,"secret"),style:{border:"none",background:"transparent",cursor:"pointer",color:C?"#059669":"#ca8a04",padding:2,display:"flex",alignItems:"center"},children:C?e.jsx(Re,{}):e.jsx(Te,{})})]}),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:()=>g({name:"list"}),children:"Về danh sách"}),e.jsx("button",{style:o.btnPrimary,onClick:()=>g({name:"add"}),children:"Thêm kênh khác"})]})]})]}),h.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:_,children:e.jsx(ne,{})}),e.jsxs("div",{children:[e.jsxs("div",{style:o.title,children:["Đang xác thực ",re[h.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:St[h.provider]??"#f1f5f9",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Q,{provider:h.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 ",re[h.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(ue,{done:!0,label:`Đã mở cửa sổ ${re[h.provider]}`}),e.jsx(ue,{active:!0,label:"Đang chờ bạn đăng nhập & cấp quyền"}),e.jsx(ue,{label:"Lưu kết nối & quay về"})]}),e.jsx("button",{style:o.oauthCancel,onClick:_,children:"Hủy và quay lại"})]})]}),h.name==="oauth-select"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:o.connectHeader,children:[e.jsx("button",{style:o.backBtn,onClick:_,children:e.jsx(ne,{})}),e.jsx(Q,{provider:h.provider,apiUrl:r,size:44}),e.jsxs("div",{children:[e.jsxs("div",{style:o.connectTitle,children:["Chọn ",h.provider==="instagram"?"tài khoản":"trang"]}),e.jsxs("div",{style:o.connectDesc,children:["Chọn ",re[h.provider]," bạn muốn kết nối với ChannelHub"]})]})]}),e.jsx("div",{style:o.body,children:h.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:h.pages.map(s=>e.jsxs("button",{disabled:W,onClick:()=>void Z(s.id),style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:12,border:"1.5px solid #e2e8f0",background:"#fff",cursor:W?"not-allowed":"pointer",opacity:W?.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:s.name}),e.jsx("div",{style:{fontSize:11,color:"#94a3b8",fontFamily:"monospace",marginTop:2},children:s.id})]}),e.jsx("span",{style:{fontSize:13,color:"#2563eb",fontWeight:500},children:W?"Đang kết nối…":"Chọn →"})]},s.id))})})]})]})}function Bt(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 Wt({conn:t,apiUrl:n,size:i=40}){const[r,p]=a.useState(!1),f=Bt(t),m=Math.round(i*.28);return f&&!r?e.jsx("img",{src:f,alt:ye(t),referrerPolicy:"no-referrer",onError:()=>p(!0),style:{width:i,height:i,borderRadius:m,objectFit:"cover",flexShrink:0,display:"block"}}):e.jsx(Q,{provider:t.provider,apiUrl:n,size:i})}function Ht({conn:t,apiUrl:n,onDisconnect:i}){const[r,p]=a.useState(!1);return e.jsxs("div",{style:o.channelItem,children:[e.jsx(Wt,{conn:t,apiUrl:n,size:40}),e.jsxs("div",{style:o.channelInfo,children:[e.jsx("div",{style:o.channelName,children:ye(t)}),e.jsx("div",{style:o.channelMeta,children:Ct(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:()=>p(!0),onMouseLeave:()=>p(!1),onClick:i,children:"Ngắt kết nối"})]})]})}const Lt=[{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 $t({provider:t,apiUrl:n,onClick:i}){const[r,p]=a.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:()=>p(!0),onMouseLeave:()=>p(!1),children:[e.jsx(Q,{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 ue({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.3 loaded");exports.ChannelHubChannels=Rt;exports.ChannelHubClient=$e;exports.ChannelHubInbox=ut;
@@ -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"}