@chatdakenh/widget 0.1.0 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # @chatdakenh/widget
2
+
3
+ Embeddable chat widget for websites and applications. Lightweight, real-time messaging powered by Preact and Socket.IO.
4
+
5
+ ## Features
6
+
7
+ - Single `<script>` tag integration — no extra CSS needed
8
+ - Real-time messaging via Socket.IO
9
+ - File uploads & image previews
10
+ - Emoji picker
11
+ - Typing indicators
12
+ - Business hours & timezone support
13
+ - Configurable position & theme
14
+ - Compact sidebar launcher variant
15
+ - Failed message retry
16
+ - ~86KB minified bundle
17
+
18
+ ## Installation
19
+
20
+ ### CDN (Recommended)
21
+
22
+ ```html
23
+ <script
24
+ src="https://unpkg.com/@chatdakenh/widget/dist/widget.js"
25
+ data-widget-id="YOUR_WIDGET_ID"
26
+ data-api-url="https://api.chatdakenh.vn/api/v1"
27
+ data-ws-url="wss://ws.chatdakenh.vn"
28
+ async
29
+ ></script>
30
+ ```
31
+
32
+ ### npm
33
+
34
+ ```bash
35
+ npm install @chatdakenh/widget
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Script Tag (Auto-init)
41
+
42
+ Add the script tag to your HTML. The widget auto-discovers `data-widget-id` and initializes itself:
43
+
44
+ ```html
45
+ <script
46
+ src="https://unpkg.com/@chatdakenh/widget/dist/widget.js"
47
+ data-widget-id="widget_abc123"
48
+ data-api-url="https://api.chatdakenh.vn/api/v1"
49
+ data-ws-url="wss://ws.chatdakenh.vn"
50
+ async
51
+ ></script>
52
+ ```
53
+
54
+ #### Data Attributes
55
+
56
+ | Attribute | Required | Description |
57
+ |---|---|---|
58
+ | `data-widget-id` | Yes | Your widget identifier |
59
+ | `data-api-url` | No | API endpoint URL |
60
+ | `data-ws-url` | No | WebSocket endpoint URL |
61
+
62
+ ### JavaScript SDK (Manual init)
63
+
64
+ ```javascript
65
+ window.ChatDaKenh.init({
66
+ widgetId: 'widget_abc123',
67
+ apiUrl: 'https://api.chatdakenh.vn/api/v1',
68
+ wsUrl: 'wss://ws.chatdakenh.vn'
69
+ })
70
+
71
+ // Destroy widget
72
+ window.ChatDaKenh.destroy()
73
+
74
+ // Check version
75
+ console.log(window.ChatDaKenh.version)
76
+ ```
77
+
78
+ ## Widget Configuration
79
+
80
+ Widget settings are managed server-side and fetched during initialization:
81
+
82
+ | Setting | Type | Description |
83
+ |---|---|---|
84
+ | `theme` | `'light' \| 'dark' \| 'auto'` | Color theme |
85
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | Widget position on screen |
86
+ | `autoOpen` | `boolean` | Auto-open chat after 2 seconds |
87
+ | `welcomeMessage` | `string` | Initial greeting message |
88
+ | `offlineMessage` | `string` | Message shown outside business hours |
89
+ | `placeholderText` | `string` | Input textarea placeholder |
90
+ | `widget_bubble_type` | `string` | Set to `'compact'` for vertical sidebar launcher |
91
+ | `enable_business_hours` | `boolean` | Enable business hours checking |
92
+ | `business_hours` | `BusinessHour[]` | Schedule per day of week |
93
+ | `timezone` | `string` | IANA timezone (e.g., `'Asia/Ho_Chi_Minh'`) or UTC offset (e.g., `'UTC+7'`) |
94
+
95
+ ## Development
96
+
97
+ ### Prerequisites
98
+
99
+ - Node.js >= 18
100
+ - npm
101
+
102
+ ### Setup
103
+
104
+ ```bash
105
+ git clone https://github.com/dinhsan2000/chatdakenh-widget.git
106
+ cd chatdakenh-widget
107
+ npm install
108
+ ```
109
+
110
+ ### Environment Variables
111
+
112
+ Copy `.env.example` to `.env` and configure:
113
+
114
+ ```env
115
+ VITE_API_URL=http://localhost:3000/api/v1
116
+ VITE_WS_URL=http://localhost:3002
117
+ ```
118
+
119
+ ### Commands
120
+
121
+ ```bash
122
+ # Start dev server
123
+ npm run dev
124
+
125
+ # Build for production
126
+ npm run build
127
+
128
+ # Build and serve locally for testing
129
+ npm test
130
+
131
+ # Preview production build
132
+ npm run preview
133
+ ```
134
+
135
+ ### Project Structure
136
+
137
+ ```
138
+ src/
139
+ ├── main.tsx # Entry point, auto-init & SDK API
140
+ ├── Widget.tsx # Main widget component
141
+ ├── api.ts # HTTP client for REST endpoints
142
+ ├── socket.ts # Socket.IO service wrapper
143
+ ├── storage.ts # localStorage/sessionStorage manager
144
+ ├── types.ts # TypeScript interfaces
145
+ ├── constants.ts # Storage keys & socket event names
146
+ ├── EmojiPicker.tsx # Emoji picker component
147
+ ├── styles.css # All widget styles
148
+ └── env.d.ts # Vite environment type definitions
149
+ ```
150
+
151
+ ### Build Output
152
+
153
+ The build produces a single IIFE bundle at `dist/widget.js`:
154
+
155
+ - CSS is automatically injected into `<head>` at runtime (no separate CSS file)
156
+ - All dependencies bundled inline
157
+ - Console logs stripped in production
158
+ - Minified with Terser
159
+
160
+ ### Testing on a Website
161
+
162
+ Open `test.html` in a browser after building. It simulates embedding the widget on a customer website.
163
+
164
+ ## Publishing
165
+
166
+ Publishing to npm is automated via GitHub Actions. To release a new version:
167
+
168
+ 1. Update `version` in `package.json`
169
+ 2. Commit and push
170
+ 3. Create a new **Release** on GitHub with a matching tag (e.g., `v0.1.0`)
171
+ 4. The workflow builds and publishes to npm automatically
172
+
173
+ ### Required GitHub Configuration
174
+
175
+ | Type | Name | Description |
176
+ |---|---|---|
177
+ | Secret | `NPM_TOKEN` | npm access token (Granular, with 2FA bypass) |
178
+ | Variable | `VITE_API_URL` | Production API URL |
179
+ | Variable | `VITE_WS_URL` | Production WebSocket URL |
180
+
181
+ ## License
182
+
183
+ UNLICENSED — All rights reserved.
package/dist/widget.js CHANGED
@@ -1 +1 @@
1
- (function(){var s=document.createElement('style');s.setAttribute('data-cdk-widget','');s.textContent=".cdk-widget,.cdk-widget *{box-sizing:border-box;margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;line-height:1.5}.cdk-widget{position:fixed;z-index:2147483647;color-scheme:light;--cdk-brand: #0b63f6;--cdk-brand-hover: #0852d6;--cdk-brand-soft: #dbeafe;--cdk-brand-contrast: #ffffff}.cdk-bottom-right{bottom:20px;right:20px}.cdk-bottom-left{bottom:20px;left:20px}.cdk-top-right{top:20px;right:20px}.cdk-top-left{top:20px;left:20px}.cdk-panel{position:absolute;bottom:72px;right:0;width:380px;max-width:calc(100vw - 32px);height:560px;max-height:calc(100vh - 120px);background:#fff;border-radius:16px;box-shadow:0 20px 60px #00000026,0 8px 20px #0000001a;display:flex;flex-direction:column;overflow:hidden;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .25s ease,transform .25s ease}.cdk-bottom-left .cdk-panel{right:auto;left:0}.cdk-top-right .cdk-panel,.cdk-top-left .cdk-panel{bottom:auto;top:72px;transform:translateY(-16px) scale(.95)}.cdk-panel-open{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cdk-widget-compact.cdk-bottom-right .cdk-panel,.cdk-widget-compact.cdk-bottom-left .cdk-panel{bottom:58px}.cdk-widget-compact.cdk-top-right .cdk-panel,.cdk-widget-compact.cdk-top-left .cdk-panel{top:86px}.cdk-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;background:linear-gradient(135deg,#0f6bff,#0b63f6 55%,#0852d6);color:#fff;flex-shrink:0}.cdk-header-info{flex:1;min-width:0}.cdk-header-avatar{width:40px;height:40px;margin-right:12px;object-fit:contain}.cdk-header-title{font-size:16px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.cdk-header-subtitle{font-size:12px;opacity:.85;margin-top:2px;transition:opacity .2s ease}.cdk-subtitle-typing{font-style:italic;opacity:1;animation:cdk-typingPulse 1.5s ease-in-out infinite}@keyframes cdk-typingPulse{0%,to{opacity:.7}50%{opacity:1}}.cdk-header-close{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;border-radius:8px;background:#fff3;color:#fff;cursor:pointer;transition:background .2s;flex-shrink:0;margin-left:12px}.cdk-header-close:hover{background:#ffffff59}.cdk-widget-compact .cdk-header{padding:12px 14px}.cdk-widget-compact .cdk-header-avatar{width:36px;height:36px;margin-right:11px}.cdk-widget-compact .cdk-header-title{font-size:14px;line-height:1.2}.cdk-widget-compact .cdk-header-subtitle{font-size:12px;margin-top:1px;line-height:1.2}.cdk-widget-compact .cdk-header-close{width:30px;height:30px;margin-left:10px;border-radius:8px}.cdk-widget-compact .cdk-header-close svg{width:17px;height:17px}.cdk-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:8px;background:#f8f9fb}.cdk-messages::-webkit-scrollbar{width:4px}.cdk-messages::-webkit-scrollbar-thumb{background:#d1d5db;border-radius:4px}.cdk-msg{display:flex;flex-direction:column;max-width:80%;animation:cdk-fadeIn .2s ease}@keyframes cdk-fadeIn{0%{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}.cdk-msg-visitor{align-self:flex-end;align-items:flex-end}.cdk-msg-agent{align-self:flex-start;align-items:flex-start}.cdk-msg-bubble{padding:10px 14px;border-radius:16px;font-size:14px;word-break:break-word;white-space:pre-wrap}.cdk-msg-bubble-visitor{background:var(--cdk-brand);color:#fff;border:1px solid rgba(255,255,255,.18);border-bottom-right-radius:4px}.cdk-msg-bubble-agent{background:#fff;color:#1f2937;border:1px solid #e5e7eb;border-bottom-left-radius:4px}.cdk-msg-time{font-size:11px;color:#9ca3af;margin-top:4px;padding:0 4px}.cdk-msg-attachments{margin-bottom:4px}.cdk-attachment-img-link{display:block}.cdk-attachment-img{max-width:100%;max-height:200px;border-radius:8px;object-fit:cover;cursor:pointer;transition:opacity .2s}.cdk-attachment-img:hover{opacity:.85}.cdk-attachment-file{display:flex;align-items:center;gap:6px;padding:8px 12px;background:#0000000f;border-radius:8px;text-decoration:none;color:inherit;font-size:13px;transition:background .2s}.cdk-attachment-file:hover{background:#0000001a}.cdk-msg-bubble-visitor .cdk-attachment-file{background:#ffffff26;color:#fff}.cdk-msg-bubble-visitor .cdk-attachment-file:hover{background:#ffffff40}.cdk-attachment-icon{font-size:16px;flex-shrink:0}.cdk-attachment-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cdk-attachment-size{font-size:11px;opacity:.7;flex-shrink:0}.cdk-typing{display:flex;align-items:center;gap:4px;padding:12px 18px}.cdk-dot{width:7px;height:7px;background:#9ca3af;border-radius:50%;animation:cdk-bounce 1.4s infinite ease-in-out both}.cdk-dot:nth-child(1){animation-delay:-.32s}.cdk-dot:nth-child(2){animation-delay:-.16s}@keyframes cdk-bounce{0%,80%,to{transform:scale(.6);opacity:.4}40%{transform:scale(1);opacity:1}}.cdk-input-wrapper{display:flex;flex-direction:column;position:relative;background:#fff;border-top:1px solid #e5e7eb}.cdk-action-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;background:transparent;color:#6b7280;border-radius:8px;cursor:pointer;transition:background .2s,color .2s;flex-shrink:0}.cdk-action-btn:hover{background:#f3f4f6;color:#1f2937}.cdk-input-area{display:flex;align-items:flex-end;gap:6px;padding:8px 12px;background:#fff}.cdk-emoji-picker{position:absolute;bottom:100%;left:12px;width:300px;max-width:calc(100% - 24px);background:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 10px 25px #0000001a;padding:10px;z-index:10;margin-bottom:8px}.cdk-emoji-grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px;max-height:200px;overflow-y:auto}.cdk-emoji-grid::-webkit-scrollbar{width:4px}.cdk-emoji-grid::-webkit-scrollbar-thumb{background:#d1d5db;border-radius:4px}.cdk-emoji-btn{background:transparent;border:none;font-size:20px;cursor:pointer;width:100%;aspect-ratio:1;border-radius:6px;display:flex;align-items:center;justify-content:center}.cdk-emoji-btn:hover{background:#f3f4f6}.cdk-input-box{flex:1;display:flex;align-items:flex-end;background:#f9fafb;border:1px solid #e5e7eb;border-radius:10px;padding:2px 3px;transition:border-color .2s,background .2s;gap:1px}.cdk-input-box:focus-within{border-color:var(--cdk-brand);background:#fff}.cdk-input{flex:1;border:none;background:transparent;padding:4px 8px;font-size:14px;resize:none;outline:none;max-height:88px;min-height:30px;color:#1f2937;font-family:inherit;line-height:1.35}.cdk-input::placeholder{color:#9ca3af}.cdk-send-btn{display:flex;align-items:center;justify-content:center;width:36px;height:36px;border:none;border-radius:10px;background:var(--cdk-brand);color:#fff;cursor:pointer;flex-shrink:0;transition:opacity .2s,transform .15s}.cdk-send-btn:hover:not(:disabled){background:var(--cdk-brand-hover);opacity:1;transform:scale(1.03)}.cdk-send-btn:disabled{opacity:.4;cursor:not-allowed}.cdk-footer{text-align:center;padding:8px;font-size:11px;color:#9ca3af;background:#fff;border-top:1px solid #f3f4f6}.cdk-footer a{color:var(--cdk-brand);text-decoration:none;font-weight:500}.cdk-footer a:hover{text-decoration:underline}.cdk-toggle{display:flex;align-items:center;justify-content:center;width:58px;height:58px;border:none;border-radius:99px;color:#fff;cursor:pointer;background:#0b63f6;box-shadow:0 12px 26px #0b63f652,0 4px 10px #02061726;transition:transform .2s,box-shadow .2s;position:relative}.cdk-toggle:hover{transform:translateY(-1px);box-shadow:0 16px 30px #0b63f65c,0 5px 12px #02061729}.cdk-toggle:active{transform:scale(.98)}.cdk-toggle-logo{width:38px;height:38px;display:block;object-fit:contain;object-position:center;filter:drop-shadow(0 1px 2px rgba(255,255,255,.18))}.cdk-toggle[aria-label=\"Toggle chat\"]>svg{color:#fff}.cdk-toggle-compact{height:136px;border-radius:13px 0 0 13px;border:none;flex-direction:column;padding:12px 0;width:40px;position:absolute;right:-20px;bottom:0;transform:none;background:#0b63f6;box-shadow:-10px 12px 24px #0b63f647}.cdk-toggle-compact:hover{transform:none;box-shadow:-12px 14px 28px #0b63f657}.cdk-toggle-compact:active{transform:none}.cdk-toggle-compact.cdk-compact-left{border-radius:0 13px 13px 0;left:-20px;right:auto;box-shadow:10px 12px 24px #0b63f647}.cdk-toggle-compact.cdk-compact-left:hover{transform:none;box-shadow:12px 14px 28px #0b63f657}.cdk-toggle-compact.cdk-compact-left:active{transform:none}.cdk-compact-inner{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;width:100%;height:100%;padding:6px 0;position:relative;z-index:1}.cdk-compact-logo{width:24px;height:24px;display:block;object-fit:contain;object-position:center;position:static;transform:none;padding:0;background:transparent;border:none;border-radius:0;box-shadow:none;opacity:.95;transform:translateY(-1px)}.cdk-compact-title{writing-mode:vertical-rl;font-weight:700;font-size:12px;letter-spacing:.3px;text-transform:none;white-space:nowrap;color:#fff;text-shadow:0 1px 2px rgba(2,6,23,.2);transform:rotate(180deg);margin:0;line-height:1;transform-origin:center}.cdk-toggle-compact:not(.cdk-compact-left) .cdk-compact-title{transform:none}.cdk-compact-icon{display:flex;align-items:center;justify-content:center}.cdk-toggle-compact .cdk-badge{top:-4px;bottom:auto;right:auto;left:-8px}.cdk-compact-left .cdk-badge{left:auto;right:-8px}.cdk-badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;background:#ef4444;border-radius:10px;font-size:11px;font-weight:700;color:#fff;display:flex;align-items:center;justify-content:center;padding:0 5px;border:2px solid white;animation:cdk-popIn .3s ease}@keyframes cdk-popIn{0%{transform:scale(0)}to{transform:scale(1)}}@media(max-width:480px){.cdk-panel{width:calc(100vw - 16px);height:calc(100vh - 100px);border-radius:12px;right:-12px}.cdk-widget{bottom:12px!important;right:12px!important}}.cdk-toast{position:absolute;bottom:62px;left:12px;right:12px;display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-radius:10px;font-size:13px;z-index:10;animation:cdk-toastSlideIn .3s ease}.cdk-toast-error{background:#fef2f2;color:#b91c1c;border:1px solid #fecaca}.cdk-toast-close{background:none;border:none;color:#b91c1c;cursor:pointer;font-size:14px;padding:0 0 0 8px;opacity:.6}.cdk-toast-close:hover{opacity:1}@keyframes cdk-toastSlideIn{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.cdk-msg-failed{opacity:.85}.cdk-msg-bubble-failed{background:#fef2f2!important;color:#b91c1c!important;border:1px dashed #fca5a5!important}.cdk-msg-meta{display:flex;align-items:center;margin-top:4px;padding:0 4px}.cdk-msg-error{display:flex;align-items:center;gap:8px}.cdk-msg-error-text{font-size:11px;color:#dc2626}.cdk-msg-retry-btn{background:none;border:1px solid #dc2626;color:#dc2626;border-radius:4px;font-size:11px;padding:2px 8px;cursor:pointer;transition:all .2s}.cdk-msg-retry-btn:hover{background:#dc2626;color:#fff}.cdk-msg-delete-btn{background:none;border:none;color:#9ca3af;cursor:pointer;font-size:12px;padding:2px 4px}.cdk-msg-delete-btn:hover{color:#dc2626}\n";document.head.appendChild(s)})();var ChatDaKenh=function(){"use strict";var t,e,n,s,i,r,o,a,c,h,l,u={},d=[],p=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_=Array.isArray;function f(t,e){for(var n in e)t[n]=e[n];return t}function g(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function m(t,s,i,r,o){var a={type:t,props:s,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==o?++n:o,__i:-1,__u:0};return null==o&&null!=e.vnode&&e.vnode(a),a}function y(t){return t.children}function v(t,e){this.props=t,this.context=e}function b(t,e){if(null==e)return t.__?b(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if(null!=(n=t.__k[e])&&null!=n.__e)return n.__e;return"function"==typeof t.type?b(t):null}function w(t){if(t.__P&&t.__d){var n=t.__v,s=n.__e,i=[],r=[],o=f({},n);o.__v=n.__v+1,e.vnode&&e.vnode(o),R(t.__P,o,n,t.__n,t.__P.namespaceURI,32&n.__u?[s]:null,i,null==s?b(n):s,!!(32&n.__u),r),o.__v=n.__v,o.__.__k[o.__i]=o,B(i,o,r),n.__e=n.__=null,o.__e!=s&&k(o)}}function k(t){if(null!=(t=t.__)&&null!=t.__c)return t.__e=t.__c.base=null,t.__k.some(function(e){if(null!=e&&null!=e.__e)return t.__e=t.__c.base=e.__e}),k(t)}function T(t){(!t.__d&&(t.__d=!0)&&s.push(t)&&!C.__r++||i!=e.debounceRendering)&&((i=e.debounceRendering)||r)(C)}function C(){for(var t,e=1;s.length;)s.length>e&&s.sort(o),t=s.shift(),e=s.length,w(t);C.__r=0}function S(t,e,n,s,i,r,o,a,c,h,l){var p,f,g,v,w,k,T,C=s&&s.__k||d,S=e.length;for(c=function(t,e,n,s,i){var r,o,a,c,h,l=n.length,u=l,d=0;for(t.__k=new Array(i),r=0;r<i;r++)null!=(o=e[r])&&"boolean"!=typeof o&&"function"!=typeof o?("string"==typeof o||"number"==typeof o||"bigint"==typeof o||o.constructor==String?o=t.__k[r]=m(null,o,null,null,null):_(o)?o=t.__k[r]=m(y,{children:o},null,null,null):void 0===o.constructor&&o.__b>0?o=t.__k[r]=m(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):t.__k[r]=o,c=r+d,o.__=t,o.__b=t.__b+1,a=null,-1!=(h=o.__i=A(o,n,c,u))&&(u--,(a=n[h])&&(a.__u|=2)),null==a||null==a.__v?(-1==h&&(i>l?d--:i<l&&d++),"function"!=typeof o.type&&(o.__u|=4)):h!=c&&(h==c-1?d--:h==c+1?d++:(h>c?d--:d++,o.__u|=4))):t.__k[r]=null;if(u)for(r=0;r<l;r++)null!=(a=n[r])&&!(2&a.__u)&&(a.__e==s&&(s=b(a)),P(a,a));return s}(n,e,C,c,S),p=0;p<S;p++)null!=(g=n.__k[p])&&(f=-1!=g.__i&&C[g.__i]||u,g.__i=p,k=R(t,g,f,i,r,o,a,c,h,l),v=g.__e,g.ref&&f.ref!=g.ref&&(f.ref&&L(f.ref,null,g),l.push(g.ref,g.__c||v,g)),null==w&&null!=v&&(w=v),(T=!!(4&g.__u))||f.__k===g.__k?c=E(g,c,t,T):"function"==typeof g.type&&void 0!==k?c=k:v&&(c=v.nextSibling),g.__u&=-7);return n.__e=w,c}function E(t,e,n,s){var i,r;if("function"==typeof t.type){for(i=t.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=t,e=E(i[r],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=b(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do{e=e&&e.nextSibling}while(null!=e&&8==e.nodeType);return e}function A(t,e,n,s){var i,r,o,a=t.key,c=t.type,h=e[n],l=null!=h&&!(2&h.__u);if(null===h&&null==a||l&&a==h.key&&c==h.type)return n;if(s>(l?1:0))for(i=n-1,r=n+1;i>=0||r<e.length;)if(null!=(h=e[o=i>=0?i--:r++])&&!(2&h.__u)&&a==h.key&&c==h.type)return o;return-1}function O(t,e,n){"-"==e[0]?t.setProperty(e,null==n?"":n):t[e]=null==n?"":"number"!=typeof n||p.test(e)?n:n+"px"}function x(t,e,n,s,i){var r,o;t:if("style"==e)if("string"==typeof n)t.style.cssText=n;else{if("string"==typeof s&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||O(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||O(t.style,e,n[e])}else if("o"==e[0]&&"n"==e[1])r=e!=(e=e.replace(a,"$1")),o=e.toLowerCase(),e=o in t||"onFocusOut"==e||"onFocusIn"==e?o.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?s?n.u=s.u:(n.u=c,t.addEventListener(e,r?l:h,r)):t.removeEventListener(e,r?l:h,r);else{if("http://www.w3.org/2000/svg"==i)e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=e&&"height"!=e&&"href"!=e&&"list"!=e&&"form"!=e&&"tabIndex"!=e&&"download"!=e&&"rowSpan"!=e&&"colSpan"!=e&&"role"!=e&&"popover"!=e&&e in t)try{t[e]=null==n?"":n;break t}catch(u){}"function"==typeof n||(null==n||!1===n&&"-"!=e[4]?t.removeAttribute(e):t.setAttribute(e,"popover"==e&&1==n?"":n))}}function N(t){return function(n){if(this.l){var s=this.l[n.type+t];if(null==n.t)n.t=c++;else if(n.t<s.u)return;return s(e.event?e.event(n):n)}}}function R(n,s,i,r,o,a,c,h,l,p){var m,w,k,T,C,E,A,O,N,R,B,L,P,j,M,q=s.type;if(void 0!==s.constructor)return null;128&i.__u&&(l=!!(32&i.__u),a=[h=s.__e=i.__e]),(m=e.__b)&&m(s);t:if("function"==typeof q)try{if(O=s.props,N="prototype"in q&&q.prototype.render,R=(m=q.contextType)&&r[m.__c],B=m?R?R.props.value:m.__:r,i.__c?A=(w=s.__c=i.__c).__=w.__E:(N?s.__c=w=new q(O,B):(s.__c=w=new v(O,B),w.constructor=q,w.render=U),R&&R.sub(w),w.state||(w.state={}),w.__n=r,k=w.__d=!0,w.__h=[],w._sb=[]),N&&null==w.__s&&(w.__s=w.state),N&&null!=q.getDerivedStateFromProps&&(w.__s==w.state&&(w.__s=f({},w.__s)),f(w.__s,q.getDerivedStateFromProps(O,w.__s))),T=w.props,C=w.state,w.__v=s,k)N&&null==q.getDerivedStateFromProps&&null!=w.componentWillMount&&w.componentWillMount(),N&&null!=w.componentDidMount&&w.__h.push(w.componentDidMount);else{if(N&&null==q.getDerivedStateFromProps&&O!==T&&null!=w.componentWillReceiveProps&&w.componentWillReceiveProps(O,B),s.__v==i.__v||!w.__e&&null!=w.shouldComponentUpdate&&!1===w.shouldComponentUpdate(O,w.__s,B)){s.__v!=i.__v&&(w.props=O,w.state=w.__s,w.__d=!1),s.__e=i.__e,s.__k=i.__k,s.__k.some(function(t){t&&(t.__=s)}),d.push.apply(w.__h,w._sb),w._sb=[],w.__h.length&&c.push(w);break t}null!=w.componentWillUpdate&&w.componentWillUpdate(O,w.__s,B),N&&null!=w.componentDidUpdate&&w.__h.push(function(){w.componentDidUpdate(T,C,E)})}if(w.context=B,w.props=O,w.__P=n,w.__e=!1,L=e.__r,P=0,N)w.state=w.__s,w.__d=!1,L&&L(s),m=w.render(w.props,w.state,w.context),d.push.apply(w.__h,w._sb),w._sb=[];else do{w.__d=!1,L&&L(s),m=w.render(w.props,w.state,w.context),w.state=w.__s}while(w.__d&&++P<25);w.state=w.__s,null!=w.getChildContext&&(r=f(f({},r),w.getChildContext())),N&&!k&&null!=w.getSnapshotBeforeUpdate&&(E=w.getSnapshotBeforeUpdate(T,C)),j=null!=m&&m.type===y&&null==m.key?D(m.props.children):m,h=S(n,_(j)?j:[j],s,i,r,o,a,c,h,l,p),w.base=s.__e,s.__u&=-161,w.__h.length&&c.push(w),A&&(w.__E=w.__=null)}catch(F){if(s.__v=null,l||null!=a)if(F.then){for(s.__u|=l?160:128;h&&8==h.nodeType&&h.nextSibling;)h=h.nextSibling;a[a.indexOf(h)]=null,s.__e=h}else{for(M=a.length;M--;)g(a[M]);I(s)}else s.__e=i.__e,s.__k=i.__k,F.then||I(s);e.__e(F,s,i)}else null==a&&s.__v==i.__v?(s.__k=i.__k,s.__e=i.__e):h=s.__e=function(n,s,i,r,o,a,c,h,l){var d,p,f,m,y,v,w,k=i.props||u,T=s.props,C=s.type;if("svg"==C?o="http://www.w3.org/2000/svg":"math"==C?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),null!=a)for(d=0;d<a.length;d++)if((y=a[d])&&"setAttribute"in y==!!C&&(C?y.localName==C:3==y.nodeType)){n=y,a[d]=null;break}if(null==n){if(null==C)return document.createTextNode(T);n=document.createElementNS(o,C,T.is&&T),h&&(e.__m&&e.__m(s,a),h=!1),a=null}if(null==C)k===T||h&&n.data==T||(n.data=T);else{if(a=a&&t.call(n.childNodes),!h&&null!=a)for(k={},d=0;d<n.attributes.length;d++)k[(y=n.attributes[d]).name]=y.value;for(d in k)y=k[d],"dangerouslySetInnerHTML"==d?f=y:"children"==d||d in T||"value"==d&&"defaultValue"in T||"checked"==d&&"defaultChecked"in T||x(n,d,null,y,o);for(d in T)y=T[d],"children"==d?m=y:"dangerouslySetInnerHTML"==d?p=y:"value"==d?v=y:"checked"==d?w=y:h&&"function"!=typeof y||k[d]===y||x(n,d,y,k[d],o);if(p)h||f&&(p.__html==f.__html||p.__html==n.innerHTML)||(n.innerHTML=p.__html),s.__k=[];else if(f&&(n.innerHTML=""),S("template"==s.type?n.content:n,_(m)?m:[m],s,i,r,"foreignObject"==C?"http://www.w3.org/1999/xhtml":o,a,c,a?a[0]:i.__k&&b(i,0),h,l),null!=a)for(d=a.length;d--;)g(a[d]);h||(d="value","progress"==C&&null==v?n.removeAttribute("value"):null!=v&&(v!==n[d]||"progress"==C&&!v||"option"==C&&v!=k[d])&&x(n,d,v,k[d],o),d="checked",null!=w&&w!=n[d]&&x(n,d,w,k[d],o))}return n}(i.__e,s,i,r,o,a,c,l,p);return(m=e.diffed)&&m(s),128&s.__u?void 0:h}function I(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(I))}function B(t,n,s){for(var i=0;i<s.length;i++)L(s[i],s[++i],s[++i]);e.__c&&e.__c(n,t),t.some(function(n){try{t=n.__h,n.__h=[],t.some(function(t){t.call(n)})}catch(s){e.__e(s,n.__v)}})}function D(t){return"object"!=typeof t||null==t||t.__b>0?t:_(t)?t.map(D):f({},t)}function L(t,n,s){try{if("function"==typeof t){var i="function"==typeof t.__u;i&&t.__u(),i&&null==n||(t.__u=t(n))}else t.current=n}catch(r){e.__e(r,s)}}function P(t,n,s){var i,r;if(e.unmount&&e.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||L(i,null,n)),null!=(i=t.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(o){e.__e(o,n)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&P(i[r],n,s||"function"!=typeof t.type);s||g(t.__e),t.__c=t.__=t.__e=void 0}function U(t,e,n){return this.constructor(t,n)}function j(n,s,i){var r,o,a;s==document&&(s=document.documentElement),e.__&&e.__(n,s),r=!1?null:s.__k,o=[],a=[],R(s,n=s.__k=function(e,n,s){var i,r,o,a={};for(o in n)"key"==o?i=n[o]:"ref"==o?r=n[o]:a[o]=n[o];if(arguments.length>2&&(a.children=arguments.length>3?t.call(arguments,2):s),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===a[o]&&(a[o]=e.defaultProps[o]);return m(e,a,i,r,null)}(y,null,[n]),r||u,u,s.namespaceURI,r?null:s.firstChild?t.call(s.childNodes):null,o,r?r.__e:s.firstChild,false,a),B(o,n,a)}t=d.slice,e={__e:function(t,e,n,s){for(var i,r,o;e=e.__;)if((i=e.__c)&&!i.__)try{if((r=i.constructor)&&null!=r.getDerivedStateFromError&&(i.setState(r.getDerivedStateFromError(t)),o=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(t,s||{}),o=i.__d),o)return i.__E=i}catch(a){t=a}throw t}},n=0,v.prototype.setState=function(t,e){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=f({},this.state),"function"==typeof t&&(t=t(f({},n),this.props)),t&&f(n,t),null!=t&&this.__v&&(e&&this._sb.push(e),T(this))},v.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),T(this))},v.prototype.render=y,s=[],r="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,o=function(t,e){return t.__v.__b-e.__v.__b},C.__r=0,a=/(PointerCapture)$|Capture$/i,c=0,h=N(!1),l=N(!0);var M=0;function q(t,n,s,i,r,o){n||(n={});var a,c,h=n;if("ref"in h)for(c in h={},n)"ref"==c?a=n[c]:h[c]=n[c];var l={type:t,props:h,key:s,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--M,__i:-1,__u:0,__source:r,__self:o};if("function"==typeof t&&(a=t.defaultProps))for(c in a)void 0===h[c]&&(h[c]=a[c]);return e.vnode&&e.vnode(l),l}var F,$,H,V,z=0,W=[],K=e,Y=K.__b,J=K.__r,X=K.diffed,Q=K.__c,Z=K.unmount,G=K.__;function tt(t,e){K.__h&&K.__h($,t,z||e),z=0;var n=$.__H||($.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function et(t){return z=1,function(t,e){var n=tt(F++,2);if(n.t=t,!n.__c&&(n.__=[dt(void 0,e),function(t){var e=n.__N?n.__N[0]:n.__[0],s=n.t(e,t);e!==s&&(n.__N=[s,n.__[1]],n.__c.setState({}))}],n.__c=$,!$.__f)){var s=function(t,e,s){if(!n.__c.__H)return!0;var r=n.__c.__H.__.filter(function(t){return t.__c});if(r.every(function(t){return!t.__N}))return!i||i.call(this,t,e,s);var o=n.__c.props!==t;return r.some(function(t){if(t.__N){var e=t.__[0];t.__=t.__N,t.__N=void 0,e!==t.__[0]&&(o=!0)}}),i&&i.call(this,t,e,s)||o};$.__f=!0;var i=$.shouldComponentUpdate,r=$.componentWillUpdate;$.componentWillUpdate=function(t,e,n){if(this.__e){var o=i;i=void 0,s(t,e,n),i=o}r&&r.call(this,t,e,n)},$.shouldComponentUpdate=s}return n.__N||n.__}(dt,t)}function nt(t,e){var n=tt(F++,3);!K.__s&&ut(n.__H,e)&&(n.__=t,n.u=e,$.__H.__h.push(n))}function st(t){return z=5,it(function(){return{current:t}},[])}function it(t,e){var n=tt(F++,7);return ut(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function rt(t,e){return z=8,it(function(){return t},e)}function ot(){for(var t;t=W.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(ht),e.__h.some(lt),e.__h=[]}catch(n){e.__h=[],K.__e(n,t.__v)}}}K.__b=function(t){$=null,Y&&Y(t)},K.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),G&&G(t,e)},K.__r=function(t){J&&J(t),F=0;var e=($=t.__c).__H;e&&(H===$?(e.__h=[],$.__h=[],e.__.some(function(t){t.__N&&(t.__=t.__N),t.u=t.__N=void 0})):(e.__h.some(ht),e.__h.some(lt),e.__h=[],F=0)),H=$},K.diffed=function(t){X&&X(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(1!==W.push(e)&&V===K.requestAnimationFrame||((V=K.requestAnimationFrame)||ct)(ot)),e.__H.__.some(function(t){t.u&&(t.__H=t.u),t.u=void 0})),H=$=null},K.__c=function(t,e){e.some(function(t){try{t.__h.some(ht),t.__h=t.__h.filter(function(t){return!t.__||lt(t)})}catch(n){e.some(function(t){t.__h&&(t.__h=[])}),e=[],K.__e(n,t.__v)}}),Q&&Q(t,e)},K.unmount=function(t){Z&&Z(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.some(function(t){try{ht(t)}catch(n){e=n}}),n.__H=void 0,e&&K.__e(e,n.__v))};var at="function"==typeof requestAnimationFrame;function ct(t){var e,n=function(){clearTimeout(s),at&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);at&&(e=requestAnimationFrame(n))}function ht(t){var e=$,n=t.__c;"function"==typeof n&&(t.__c=void 0,n()),$=e}function lt(t){var e=$;t.__c=t.__(),$=e}function ut(t,e){return!t||t.length!==e.length||e.some(function(e,n){return e!==t[n]})}function dt(t,e){return"function"==typeof e?e(t):e}const pt={VISITOR_ID:"cdk_visitor_id",CONVERSATION_ID:"cdk_conversation_id",SESSION_TOKEN:"cdk_session_token",COMPANY_ID:"cdk_company_id"},_t="widget:message",ft="widget:agent_typing",gt="widget:session_expired",mt="receive_message",yt="join_receive_message";const vt=new class{get(t){try{return localStorage.getItem(t)??sessionStorage.getItem(t)??null}catch{return null}}set(t,e){try{localStorage.setItem(t,e)}catch{try{sessionStorage.setItem(t,e)}catch{}}}remove(t){try{localStorage.removeItem(t),sessionStorage.removeItem(t)}catch{}}getVisitorId(){return this.get(pt.VISITOR_ID)}setVisitorId(t){this.set(pt.VISITOR_ID,t)}getConversationId(){return this.get(pt.CONVERSATION_ID)}setConversationId(t){this.set(pt.CONVERSATION_ID,t)}getSessionToken(){return this.get(pt.SESSION_TOKEN)}setSessionToken(t){this.set(pt.SESSION_TOKEN,t)}getCompanyId(){return this.get(pt.COMPANY_ID)}setCompanyId(t){this.set(pt.COMPANY_ID,t)}clearAll(){Object.values(pt).forEach(t=>this.remove(t))}};const bt=new class{constructor(){this.baseUrl=""}configure(t){this.baseUrl=t.replace(/\/$/,"")+"/widgets"}async request(t,e={}){const n=vt.getSessionToken(),s=vt.getCompanyId(),i=await fetch(`${this.baseUrl}${t}`,{...e,headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},...s?{"x-tenant-id":s}:{},...e.headers}});if(!i.ok)throw new Error(`API Error: ${i.status} ${i.statusText}`);return i.json()}async initialize(t){const e=await this.request("/initialize",{method:"POST",body:JSON.stringify(t)});if(!e.success)throw new Error("Failed to initialize widget");const n=e.data,s={...n.widget_config.settings};return delete s.primaryColor,delete s.widget_bubble_launcher_title,{...n,widget_config:{...n.widget_config,settings:s}}}async sendMessage(t){const e=await this.request("/send-message",{method:"POST",body:JSON.stringify(t)});if(!e.success)throw new Error(e.message||"Failed to send message");return e}async getMessages(t,e){const n=await this.request(`/${t}/get-messages/${e}`);if(!n.success)throw new Error("Failed to fetch messages");return n.data}async uploadFile(t){const e=vt.getSessionToken(),n=vt.getCompanyId(),s=new FormData;s.append("file",t);const i=await fetch(`${this.baseUrl}/upload`,{method:"POST",headers:{...e?{Authorization:`Bearer ${e}`}:{},...n?{"x-tenant-id":n}:{}},body:s});if(!i.ok){const t=await i.json().catch(()=>({}));throw new Error(t.message||`Upload failed: ${i.status}`)}const r=await i.json();if(!r.success)throw new Error(r.message||"Upload failed");return r.data}},wt=Object.create(null);wt.open="0",wt.close="1",wt.ping="2",wt.pong="3",wt.message="4",wt.upgrade="5",wt.noop="6";const kt=Object.create(null);Object.keys(wt).forEach(t=>{kt[wt[t]]=t});const Tt={type:"error",data:"parser error"},Ct="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),St="function"==typeof ArrayBuffer,Et=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,At=({type:t,data:e},n,s)=>Ct&&e instanceof Blob?n?s(e):Ot(e,s):St&&(e instanceof ArrayBuffer||Et(e))?n?s(e):Ot(new Blob([e]),s):s(wt[t]+(e||"")),Ot=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function xt(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let Nt;const Rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",It="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let en=0;en<64;en++)It[Rt.charCodeAt(en)]=en;const Bt="function"==typeof ArrayBuffer,Dt=(t,e)=>{if("string"!=typeof t)return{type:"message",data:Pt(t,e)};const n=t.charAt(0);if("b"===n)return{type:"message",data:Lt(t.substring(1),e)};return kt[n]?t.length>1?{type:kt[n],data:t.substring(1)}:{type:kt[n]}:Tt},Lt=(t,e)=>{if(Bt){const n=(t=>{let e,n,s,i,r,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),l=new Uint8Array(h);for(e=0;e<a;e+=4)n=It[t.charCodeAt(e)],s=It[t.charCodeAt(e+1)],i=It[t.charCodeAt(e+2)],r=It[t.charCodeAt(e+3)],l[c++]=n<<2|s>>4,l[c++]=(15&s)<<4|i>>2,l[c++]=(3&i)<<6|63&r;return h})(t);return Pt(n,e)}return{base64:!0,data:t}},Pt=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,Ut=String.fromCharCode(30);function jt(){return new TransformStream({transform(t,e){!function(t,e){Ct&&t.data instanceof Blob?t.data.arrayBuffer().then(xt).then(e):St&&(t.data instanceof ArrayBuffer||Et(t.data))?e(xt(t.data)):At(t,!1,t=>{Nt||(Nt=new TextEncoder),e(Nt.encode(t))})}(t,n=>{const s=n.length;let i;if(s<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,s);else if(s<65536){i=new Uint8Array(3);const t=new DataView(i.buffer);t.setUint8(0,126),t.setUint16(1,s)}else{i=new Uint8Array(9);const t=new DataView(i.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(s))}t.data&&"string"!=typeof t.data&&(i[0]|=128),e.enqueue(i),e.enqueue(n)})}})}let Mt;function qt(t){return t.reduce((t,e)=>t+e.length,0)}function Ft(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let s=0;for(let i=0;i<e;i++)n[i]=t[0][s++],s===t[0].length&&(t.shift(),s=0);return t.length&&s<t[0].length&&(t[0]=t[0].slice(s)),n}function $t(t){if(t)return function(t){for(var e in $t.prototype)t[e]=$t.prototype[e];return t}(t)}$t.prototype.on=$t.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},$t.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},$t.prototype.off=$t.prototype.removeListener=$t.prototype.removeAllListeners=$t.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<s.length;i++)if((n=s[i])===e||n.fn===e){s.splice(i,1);break}return 0===s.length&&delete this._callbacks["$"+t],this},$t.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if(n){s=0;for(var i=(n=n.slice(0)).length;s<i;++s)n[s].apply(this,e)}return this},$t.prototype.emitReserved=$t.prototype.emit,$t.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},$t.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Ht="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),Vt="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function zt(t,...e){return e.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{})}const Wt=Vt.setTimeout,Kt=Vt.clearTimeout;function Yt(t,e){e.useNativeTimers?(t.setTimeoutFn=Wt.bind(Vt),t.clearTimeoutFn=Kt.bind(Vt)):(t.setTimeoutFn=Vt.setTimeout.bind(Vt),t.clearTimeoutFn=Vt.clearTimeout.bind(Vt))}function Jt(t){return"string"==typeof t?function(t){let e=0,n=0;for(let s=0,i=t.length;s<i;s++)e=t.charCodeAt(s),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(s++,n+=4);return n}(t):Math.ceil(1.33*(t.byteLength||t.size))}function Xt(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Qt extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class Zt extends $t{constructor(t){super(),this.writable=!1,Yt(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new Qt(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=Dt(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class Gt extends Zt{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",function(){--t||e()})),this.writable||(t++,this.once("drain",function(){--t||e()}))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(Ut),s=[];for(let i=0;i<n.length;i++){const t=Dt(n[i],e);if(s.push(t),"error"===t.type)break}return s})(t,this.socket.binaryType).forEach(t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)}),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,s=new Array(n);let i=0;t.forEach((t,r)=>{At(t,!1,t=>{s[r]=t,++i===n&&e(s.join(Ut))})})})(t,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=Xt()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let te=!1;try{te="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(tn){}const ee=te;function ne(){}class se extends Gt{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",(t,e)=>{this.onError("xhr post error",t,e)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(t,e)=>{this.onError("xhr poll error",t,e)}),this.pollXhr=t}}class ie extends $t{constructor(t,e,n){super(),this.createRequest=t,Yt(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=zt(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(s){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(s){}try{n.setRequestHeader("Accept","*/*")}catch(s){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn(()=>{this._onError("number"==typeof n.status?n.status:0)},0))},n.send(this._data)}catch(s){return void this.setTimeoutFn(()=>{this._onError(s)},0)}"undefined"!=typeof document&&(this._index=ie.requestsCount++,ie.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=ne,t)try{this._xhr.abort()}catch(e){}"undefined"!=typeof document&&delete ie.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}if(ie.requestsCount=0,ie.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",re);else if("function"==typeof addEventListener){addEventListener("onpagehide"in Vt?"pagehide":"unload",re,!1)}function re(){for(let t in ie.requests)ie.requests.hasOwnProperty(t)&&ie.requests[t].abort()}const oe=function(){const t=ae({xdomain:!1});return t&&null!==t.responseType}();function ae(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||ee))return new XMLHttpRequest}catch(n){}if(!e)try{return new(Vt[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(n){}}const ce="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class he extends Zt{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=ce?{}:zt(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(tn){return this.emitReserved("error",tn)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;At(n,this.supportsBinary,t=>{try{this.doWrite(n,t)}catch(e){}s&&Ht(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=Xt()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const le=Vt.WebSocket||Vt.MozWebSocket;const ue={websocket:class extends he{createSocket(t,e,n){return ce?new le(t,e,n):e?new le(t,e):new le(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends Zt{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(tn){return this.emitReserved("error",tn)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const e=function(t,e){Mt||(Mt=new TextDecoder);const n=[];let s=0,i=-1,r=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===s){if(qt(n)<1)break;const t=Ft(n,1);r=!(128&~t[0]),i=127&t[0],s=i<126?3:126===i?1:2}else if(1===s){if(qt(n)<2)break;const t=Ft(n,2);i=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),s=3}else if(2===s){if(qt(n)<8)break;const t=Ft(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),r=e.getUint32(0);if(r>Math.pow(2,21)-1){a.enqueue(Tt);break}i=r*Math.pow(2,32)+e.getUint32(4),s=3}else{if(qt(n)<i)break;const t=Ft(n,i);a.enqueue(Dt(r?t:Mt.decode(t),e)),s=0}if(0===i||i>t){a.enqueue(Tt);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),s=jt();s.readable.pipeTo(t.writable),this._writer=s.writable.getWriter();const i=()=>{n.read().then(({done:t,value:e})=>{t||(this.onPacket(e),i())}).catch(t=>{})};i();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;this._writer.write(n).then(()=>{s&&Ht(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends se{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=oe&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new ie(ae,this.uri(),t)}}},de=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,pe=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function _e(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),s=t.indexOf("]");-1!=n&&-1!=s&&(t=t.substring(0,n)+t.substring(n,s).replace(/:/g,";")+t.substring(s,t.length));let i=de.exec(t||""),r={},o=14;for(;o--;)r[pe[o]]=i[o]||"";return-1!=n&&-1!=s&&(r.source=e,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,e){const n=/\/{2,9}/g,s=e.replace(n,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||s.splice(0,1);"/"==e.slice(-1)&&s.splice(s.length-1,1);return s}(0,r.path),r.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,s){e&&(n[e]=s)}),n}(0,r.query),r}const fe="function"==typeof addEventListener&&"function"==typeof removeEventListener,ge=[];fe&&addEventListener("offline",()=>{ge.forEach(t=>t())},!1);class me extends $t{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=_e(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=_e(e.host).host);Yt(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach(t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let s=0,i=n.length;s<i;s++){let t=n[s].split("=");e[decodeURIComponent(t[0])]=decodeURIComponent(t[1])}return e}(this.opts.query)),fe&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},ge.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);const t=this.opts.rememberUpgrade&&me.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",me.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const n=this.writeBuffer[e].data;if(n&&(t+=Jt(n)),e>0&&t>this._maxPayload)return this.writeBuffer.slice(0,e);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Ht(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,s){if("function"==typeof e&&(s=e,e=void 0),"function"==typeof n&&(s=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const i={type:t,data:e,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():t()}):this.upgrading?n():t()),this}_onError(t){if(me.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),fe&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=ge.indexOf(this._offlineEventListener);-1!==t&&ge.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}me.protocol=4;class ye extends me{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;me.priorWebsocketSuccess=!1;const s=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;me.priorWebsocketSuccess="websocket"===e.name,this.transport.pause(()=>{n||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())})}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}}))};function i(){n||(n=!0,h(),e.close(),e=null)}const r=t=>{const n=new Error("probe error: "+t);n.transport=e.name,i(),this.emitReserved("upgradeError",n)};function o(){r("transport closed")}function a(){r("socket closed")}function c(t){e&&t.name!==e.name&&i()}const h=()=>{e.removeListener("open",s),e.removeListener("error",r),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",s),e.once("error",r),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn(()=>{n||e.open()},200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}let ve=class extends ye{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map(t=>ue[t]).filter(t=>!!t)),super(t,n)}};const be="function"==typeof ArrayBuffer,we=Object.prototype.toString,ke="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===we.call(Blob),Te="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===we.call(File);function Ce(t){return be&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||ke&&t instanceof Blob||Te&&t instanceof File}function Se(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(Se(t[e]))return!0;return!1}if(Ce(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Se(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&Se(t[n]))return!0;return!1}function Ee(t){const e=[],n=t.data,s=t;return s.data=Ae(n,e),s.attachments=e.length,{packet:s,buffers:e}}function Ae(t,e){if(!t)return t;if(Ce(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let s=0;s<t.length;s++)n[s]=Ae(t[s],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=Ae(t[s],e));return n}return t}function Oe(t,e){return t.data=xe(t.data,e),delete t.attachments,t}function xe(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=xe(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=xe(t[n],e));return t}const Ne=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Re,Ie;(Ie=Re||(Re={}))[Ie.CONNECT=0]="CONNECT",Ie[Ie.DISCONNECT=1]="DISCONNECT",Ie[Ie.EVENT=2]="EVENT",Ie[Ie.ACK=3]="ACK",Ie[Ie.CONNECT_ERROR=4]="CONNECT_ERROR",Ie[Ie.BINARY_EVENT=5]="BINARY_EVENT",Ie[Ie.BINARY_ACK=6]="BINARY_ACK";class Be extends $t{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===Re.BINARY_EVENT;n||e.type===Re.BINARY_ACK?(e.type=n?Re.EVENT:Re.ACK,this.reconstructor=new De(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!Ce(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===Re[n.type])throw new Error("unknown packet type "+n.type);if(n.type===Re.BINARY_EVENT||n.type===Re.BINARY_ACK){const s=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const i=t.substring(s,e);if(i!=Number(i)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===t.charAt(e+1)){const s=e+1;for(;++e;){if(","===t.charAt(e))break;if(e===t.length)break}n.nsp=t.substring(s,e)}else n.nsp="/";const s=t.charAt(e+1);if(""!==s&&Number(s)==s){const s=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(s,e+1))}if(t.charAt(++e)){const s=this.tryParse(t.substr(e));if(!Be.isPayloadValid(n.type,s))throw new Error("invalid payload");n.data=s}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(e){return!1}}static isPayloadValid(t,e){switch(t){case Re.CONNECT:return Le(e);case Re.DISCONNECT:return void 0===e;case Re.CONNECT_ERROR:return"string"==typeof e||Le(e);case Re.EVENT:case Re.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===Ne.indexOf(e[0]));case Re.ACK:case Re.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class De{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=Oe(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function Le(t){return"[object Object]"===Object.prototype.toString.call(t)}const Pe=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Be,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Re.EVENT&&t.type!==Re.ACK||!Se(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Re.EVENT?Re.BINARY_EVENT:Re.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==Re.BINARY_EVENT&&t.type!==Re.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=Ee(t),n=this.encodeAsString(e.packet),s=e.buffers;return s.unshift(n),s}},get PacketType(){return Re}},Symbol.toStringTag,{value:"Module"}));function Ue(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const je=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Me extends $t{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Ue(t,"open",this.onopen.bind(this)),Ue(t,"packet",this.onpacket.bind(this)),Ue(t,"error",this.onerror.bind(this)),Ue(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,s,i;if(je.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const r={type:Re.EVENT,data:e,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),r.id=t}const o=null===(s=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===s?void 0:s.writable,a=this.connected&&!(null===(i=this.io.engine)||void 0===i?void 0:i._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,e){var n;const s=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===s)return void(this.acks[t]=e);const i=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))},s),r=(...t)=>{this.io.clearTimeoutFn(i),e.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...e){return new Promise((n,s)=>{const i=(t,e)=>t?s(t):n(e);i.withError=!0,e.push(i),this.emit(t,...e)})}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((t,...s)=>{this._queue[0];return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...s)),n.pending=!1,this._drainQueue()}),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Re.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(e=>String(e.id)===t)){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Re.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Re.EVENT:case Re.BINARY_EVENT:this.onevent(t);break;case Re.ACK:case Re.BINARY_ACK:this.onack(t);break;case Re.DISCONNECT:this.ondisconnect();break;case Re.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...s){n||(n=!0,e.packet({type:Re.ACK,id:t,data:s}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Re.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function qe(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}qe.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},qe.prototype.reset=function(){this.attempts=0},qe.prototype.setMin=function(t){this.ms=t},qe.prototype.setMax=function(t){this.max=t},qe.prototype.setJitter=function(t){this.jitter=t};class Fe extends $t{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,Yt(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new qe({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const s=e.parser||Pe;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new ve(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const s=Ue(e,"open",function(){n.onopen(),t&&t()}),i=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},r=Ue(e,"error",i);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn(()=>{s(),i(new Error("timeout")),e.close()},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(s),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ue(t,"ping",this.onping.bind(this)),Ue(t,"data",this.ondata.bind(this)),Ue(t,"error",this.onerror.bind(this)),Ue(t,"close",this.onclose.bind(this)),Ue(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(e){this.onclose("parse error",e)}}ondecoded(t){Ht(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new Me(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const n of e){if(this.nsps[n].active)return}this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open(e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()}))},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const $e={};function He(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let s=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),s=_e(t)),s.port||(/^(http|ws)$/.test(s.protocol)?s.port="80":/^(http|ws)s$/.test(s.protocol)&&(s.port="443")),s.path=s.path||"/";const i=-1!==s.host.indexOf(":")?"["+s.host+"]":s.host;return s.id=s.protocol+"://"+i+":"+s.port+e,s.href=s.protocol+"://"+i+(n&&n.port===s.port?"":":"+s.port),s}(t,(e=e||{}).path||"/socket.io"),s=n.source,i=n.id,r=n.path,o=$e[i]&&r in $e[i].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new Fe(s,e):($e[i]||($e[i]=new Fe(s,e)),a=$e[i]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(He,{Manager:Fe,Socket:Me,io:He,connect:He});const Ve=new class{constructor(){this.socket=null,this.wsUrl="",this.pendingJoinConversationId=null,this.handlers={message:new Set,typing:new Set,disconnect:new Set}}configure(t){this.wsUrl=t}connect(){var t;if(null==(t=this.socket)?void 0:t.connected)return void this._joinStoredConversation();const e=vt.getSessionToken();e&&(this.socket=He(this.wsUrl,{transports:["websocket","polling"],timeout:2e4,reconnection:!0,reconnectionDelay:2e3,reconnectionDelayMax:1e4,reconnectionAttempts:10,auth:{token:e,type:"widget"}}),this.socket.on("connect",()=>{this._joinStoredConversation()}),this.socket.on("disconnect",t=>{this.handlers.disconnect.forEach(e=>e(t))}),this.socket.on("reconnect",()=>{this._joinStoredConversation()}),this.socket.on("joined_conversation",t=>{}),this.socket.on(mt,t=>{this._handleIncomingMessage(t)}),this.socket.on(_t,t=>{this._handleIncomingMessage(t)}),this.socket.on(ft,t=>{this.handlers.typing.forEach(e=>e(t))}),this.socket.on("typing",t=>{this.handlers.typing.forEach(e=>e({isTyping:(null==t?void 0:t.isTyping)??!1}))}),this.socket.on(gt,()=>{this.disconnect(),vt.clearAll()}),this.socket.on("error",t=>{}),this.socket.on("connect_error",t=>{}))}_joinStoredConversation(){const t=this.pendingJoinConversationId||vt.getConversationId();t&&this.joinConversation(t)}_handleIncomingMessage(t){var e;const n=null==(e=null==t?void 0:t.data)?void 0:e.messages;if(n&&"outgoing"===n.message_type){const t={id:n.id,content:n.content,content_type:n.content_type,sender_type:"user",message_type:n.message_type,attachments:n.attachments,sent_at:n.sent_at,quote_id:n.quote_id};this.handlers.message.forEach(e=>e(t))}}joinConversation(t){var e;this.pendingJoinConversationId=t,(null==(e=this.socket)?void 0:e.connected)&&this.socket.emit(yt,t)}leaveConversation(t){var e;(null==(e=this.socket)?void 0:e.connected)&&this.socket.emit("leave_receive_message",t)}emitTyping(t,e){var n;null==(n=this.socket)||n.emit("typing",{conversationId:t,isTyping:e})}disconnect(){this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null)}get connected(){var t;return(null==(t=this.socket)?void 0:t.connected)??!1}onMessage(t){return this.handlers.message.add(t),()=>{this.handlers.message.delete(t)}}onTyping(t){return this.handlers.typing.add(t),()=>{this.handlers.typing.delete(t)}}onDisconnect(t){return this.handlers.disconnect.add(t),()=>{this.handlers.disconnect.delete(t)}}},ze=["😀","😃","😄","😁","😅","😂","🤣","😊","😇","🙂","😉","😌","😍","🥰","😘","😗","😙","😚","😋","😛","😝","😜","🤪","🤨","🧐","🤓","😎","🤩","🥳","😏","😒","😞","😔","😟","😕","🙁","☹️","😣","😖","😫","😩","🥺","😢","😭","😤","😠","😡","🤬","🤯","😳","👍","👎","👏","🙌","👐","🤲","🤝","🙏","❤️","💔"],We=({onSelect:t})=>q("div",{class:"cdk-emoji-picker",children:q("div",{class:"cdk-emoji-grid",children:ze.map(e=>q("button",{type:"button",class:"cdk-emoji-btn",onClick:n=>{n.preventDefault(),t(e)},children:e},e))})}),Ke=({widgetId:t,apiUrl:e,wsUrl:n})=>{var s;const[i,r]=et(!1),[o,a]=et(!1),[c,h]=et(null),[l,u]=et([]),[d,p]=et(""),[_,f]=et(!1),[g,m]=et(!1),[y,v]=et(0),[b,w]=et(!1),[k,T]=et(null),[C,S]=et(new Set),E=st(null),A=st(null),O=st(null),x=st(!1),N=st(null),R=st(null),I=null==c?void 0:c.settings,B="compact"===(null==(s=null==c?void 0:c.settings)?void 0:s.widget_bubble_type),D="/logo.svg",L=rt(t=>{const e=(t||"").trim().toLowerCase();return{mon:"monday",tue:"tuesday",tues:"tuesday",wed:"wednesday",thu:"thursday",thur:"thursday",thurs:"thursday",fri:"friday",sat:"saturday",sun:"sunday","thứ 2":"monday","thu 2":"monday","thứ 3":"tuesday","thu 3":"tuesday","thứ 4":"wednesday","thu 4":"wednesday","thứ 5":"thursday","thu 5":"thursday","thứ 6":"friday","thu 6":"friday","thứ 7":"saturday","thu 7":"saturday","chủ nhật":"sunday","chu nhat":"sunday"}[e]||e},[]);nt(()=>{if(x.current||!t)return;x.current=!0,bt.configure(e),Ve.configure(n);return(async()=>{var e;try{let n=vt.getVisitorId();n||(n=`visitor_${Math.random().toString(36).substring(2,15)}${Date.now().toString(36)}`,vt.setVisitorId(n));const s=await bt.initialize({widget_id:t,visitor_id:n,page_info:{url:window.location.href,title:document.title,referrer:document.referrer},browser_info:{userAgent:navigator.userAgent,language:navigator.language||"en",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,screen:`${screen.width}x${screen.height}`}});vt.setSessionToken(s.session_token),vt.setCompanyId(s.company_id),vt.setConversationId(s.conversation_id),h(s.widget_config),a(!0),(null==(e=s.widget_config.settings)?void 0:e.autoOpen)&&setTimeout(()=>r(!0),2e3),Ve.connect();try{const e=await bt.getMessages(t,s.conversation_id);u(e)}catch{}}catch(tn){}})(),()=>{Ve.disconnect()}},[t,e,n]),nt(()=>{if(!o)return;const t=Ve.onMessage(t=>{u(e=>[...e,t]),i||v(t=>t+1),m(!1),R.current&&(window.clearTimeout(R.current),R.current=null)}),e=Ve.onTyping(t=>{(null==t?void 0:t.isWidget)||(m(t.isTyping),R.current&&(window.clearTimeout(R.current),R.current=null),t.isTyping&&(R.current=window.setTimeout(()=>{m(!1),R.current=null},3e3)))});return()=>{t(),e()}},[o,i]),nt(()=>{var t;null==(t=A.current)||t.scrollIntoView({behavior:"smooth"})},[l,g]),nt(()=>{i&&setTimeout(()=>{var t;return null==(t=O.current)?void 0:t.focus()},300)},[i]);const P=rt(async()=>{var e,n,s;const i=d.trim();if(!i||_)return;f(!0),p("");const r=vt.getConversationId();r&&(N.current&&(clearTimeout(N.current),N.current=null),Ve.emitTyping(r,!1));const o=`temp_${Date.now()}`,a={id:o,content:i,sender_type:"contact",message_type:"incoming",sent_at:(new Date).toISOString()};u(t=>[...t,a]);if((()=>{if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return!1;const t=(()=>{const t=null==I?void 0:I.timezone;if(!t)return new Date;try{const e=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"long"}).formatToParts(new Date),n=t=>{var n;return(null==(n=e.find(e=>e.type===t))?void 0:n.value)||""};return{day:n("weekday"),hours:parseInt(n("hour")),minutes:parseInt(n("minute"))}}catch{const t=new Date;return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][t.getDay()],hours:t.getHours(),minutes:t.getMinutes()}}})(),e="object"==typeof t&&"day"in t?L(t.day):"",n=I.business_hours.find(t=>L(t.day)===e);if(!n||!n.enabled)return!0;const s=60*("object"==typeof t&&"hours"in t?t.hours:0)+("object"==typeof t&&"minutes"in t?t.minutes:0),[i,r]=n.startTime.split(":").map(Number),[o,a]=n.endTime.split(":").map(Number);return s<60*i+(r||0)||s>60*o+(a||0)})()){const t={id:`offline_${Date.now()}`,content:(null==I?void 0:I.offlineMessage)||"We're currently offline. Leave a message and we'll get back to you!",sender_type:"user",message_type:"outgoing",sent_at:(new Date).toISOString()};return u(e=>[...e,t]),void f(!1)}try{const r=vt.getConversationId()||"",c=vt.getVisitorId()||"",h=await bt.sendMessage({conversation_id:r,widget_id:t,visitor_id:c,sender_name:c,message:i,message_type:"text"}),l=(null==(e=h.data)?void 0:e.conversation_id)||(null==(s=null==(n=h.data)?void 0:n.conversation)?void 0:s.id);l&&(vt.setConversationId(l),Ve.joinConversation(l)),u(t=>t.map(t=>{var e,n,s,r;return t.id===o?{id:(null==(e=h.data)?void 0:e.id)||o,content:(null==(n=h.data)?void 0:n.content)||i,sender_type:"contact",message_type:"incoming",attachments:null==(s=h.data)?void 0:s.attachments,sent_at:(null==(r=h.data)?void 0:r.sent_at)||a.sent_at}:t}))}catch(tn){S(t=>new Set(t).add(o)),U("Gửi tin nhắn thất bại. Nhấn ⚠️ để thử lại.")}finally{f(!1),setTimeout(()=>{O.current&&O.current.focus()},0)}},[d,_,t,I]),U=rt(t=>{T(t),E.current&&clearTimeout(E.current),E.current=window.setTimeout(()=>{T(null),E.current=null},4e3)},[]),j=rt(async e=>{var n,s,i;const r=l.find(t=>t.id===e);if(r){S(t=>{const n=new Set(t);return n.delete(e),n});try{const o=vt.getConversationId()||"",a=vt.getVisitorId()||"",c=await bt.sendMessage({conversation_id:o,widget_id:t,visitor_id:a,sender_name:a,message:r.content,message_type:r.content_type||"text"}),h=(null==(n=c.data)?void 0:n.conversation_id)||(null==(i=null==(s=c.data)?void 0:s.conversation)?void 0:i.id);h&&(vt.setConversationId(h),Ve.joinConversation(h)),u(t=>t.map(t=>{var n,s,i,o;return t.id===e?{id:(null==(n=c.data)?void 0:n.id)||e,content:(null==(s=c.data)?void 0:s.content)||r.content,sender_type:"contact",message_type:"incoming",attachments:null==(i=c.data)?void 0:i.attachments,sent_at:(null==(o=c.data)?void 0:o.sent_at)||r.sent_at}:t}))}catch(tn){S(t=>new Set(t).add(e)),U("Thử lại thất bại. Kiểm tra kết nối mạng.")}}},[l,t,U]),M=rt(t=>{if(O.current){const e=O.current.selectionStart,n=O.current.selectionEnd,s=d,i=s.substring(0,e)+t+s.substring(n);p(i),setTimeout(()=>{if(O.current){O.current.focus();const n=e+t.length;O.current.setSelectionRange(n,n)}},0)}else p(e=>e+t)},[d]),F=rt(async e=>{var n,s,i;const r=e.target;if(!r.files||0===r.files.length)return;const o=r.files[0];if(r.value="",o.size>10485760)return void alert(`File too large (${(o.size/1024/1024).toFixed(1)}MB). Max allowed: 10MB.`);const a=`upload_${Date.now()}`,c=o.type.startsWith("image/"),h={id:a,content:c?"":`📎 Uploading ${o.name}...`,sender_type:"contact",message_type:"incoming",sent_at:(new Date).toISOString()};u(t=>[...t,h]);try{const e=await bt.uploadFile(o),r=vt.getConversationId()||"",l=vt.getVisitorId()||"",d=await bt.sendMessage({conversation_id:r,widget_id:t,visitor_id:l,sender_name:l,message:c?"":`📎 ${o.name}`,message_type:c?"image":"file",attachments:[e.url]}),p=(null==(n=d.data)?void 0:n.conversation_id)||(null==(i=null==(s=d.data)?void 0:s.conversation)?void 0:i.id);p&&(vt.setConversationId(p),Ve.joinConversation(p)),u(t=>t.map(t=>{var n,s,i;return t.id===a?{id:(null==(n=d.data)?void 0:n.id)||a,content:(null==(s=d.data)?void 0:s.content)||(c?"":`📎 ${o.name}`),sender_type:"contact",message_type:"incoming",attachments:[{id:a,name:o.name,size:o.size,type:o.type,url:e.url}],sent_at:(null==(i=d.data)?void 0:i.sent_at)||h.sent_at}:t}))}catch(tn){u(t=>t.filter(t=>t.id!==a)),alert(`Upload failed: ${tn.message}`)}finally{setTimeout(()=>{O.current&&O.current.focus()},0)}},[t]),$=rt(()=>{const t=null==I?void 0:I.timezone;if(!t)return new Date;try{const e=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"long"}).formatToParts(new Date),n=t=>{var n;return(null==(n=e.find(e=>e.type===t))?void 0:n.value)||""};return{day:n("weekday"),hours:parseInt(n("hour")),minutes:parseInt(n("minute"))}}catch{const e=t.match(/UTC([+-])(\d{1,2})/i);if(e){const t="+"===e[1]?1:-1,n=parseInt(e[2]),s=new Date((new Date).getTime()+t*n*60*60*1e3);return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][s.getUTCDay()],hours:s.getUTCHours(),minutes:s.getUTCMinutes()}}const n=new Date;return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][n.getDay()],hours:n.getHours(),minutes:n.getMinutes()}}},[null==I?void 0:I.timezone]),H=it(()=>{if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return!0;const t=$(),e="object"==typeof t&&"day"in t?L(t.day):"",n=I.business_hours.find(t=>L(t.day)===e);if(!n||!n.enabled)return!1;const s=60*("object"==typeof t&&"hours"in t?t.hours:0)+("object"==typeof t&&"minutes"in t?t.minutes:0),[i,r]=n.startTime.split(":").map(Number),[o,a]=n.endTime.split(":").map(Number);return s>=60*i+(r||0)&&s<=60*o+(a||0)},[I,$,L]),V=it(()=>{var t;if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return null;const e=$(),n="object"==typeof e&&"day"in e?L(e.day):"",s=I.business_hours.find(t=>L(t.day)===n&&t.enabled),i=I.timezone||"";let r="";if(i)try{r=(null==(t=new Intl.DateTimeFormat("en-US",{timeZone:i,timeZoneName:"shortOffset"}).formatToParts(new Date).find(t=>"timeZoneName"===t.type))?void 0:t.value)||i}catch{r=i}return s?`Service hours: ${s.startTime}–${s.endTime}${r?` (${r})`:""}`:"Closed today"+(r?` (${r})`:"")},[I,$,L]),z=(null==I?void 0:I.position)||"bottom-right",W=t=>{try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}};return o?q("div",{class:`cdk-widget cdk-${z} ${B?"cdk-widget-compact":""}`,children:[q("div",{class:"cdk-panel "+(i?"cdk-panel-open":""),children:[q("div",{class:"cdk-header",children:[(null==c?void 0:c.website_url)&&q("img",{src:`https://www.google.com/s2/favicons?domain=${c.website_url}&sz=64`,alt:"Avatar",class:"cdk-header-avatar",onError:t=>t.currentTarget.style.display="none"}),q("div",{class:"cdk-header-info",children:[q("div",{class:"cdk-header-title",children:(null==c?void 0:c.name)||"Chat"}),q("div",{class:"cdk-header-subtitle "+(g?"cdk-subtitle-typing":""),children:g?"Agent is typing...":V||(null==I?void 0:I.subtitle)||"We typically reply within minutes"})]}),q("button",{class:"cdk-header-close",onClick:()=>r(!1),"aria-label":"Close",children:q("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:q("path",{d:"M12 16.5a1 1 0 0 1-.7-.29l-6-6A1 1 0 0 1 6.7 8.79L12 14.09l5.3-5.3a1 1 0 1 1 1.41 1.42l-6 6A1 1 0 0 1 12 16.5z"})})})]}),q("div",{class:"cdk-messages",children:[0===l.length&&(H?null==I?void 0:I.welcomeMessage:(null==I?void 0:I.offlineMessage)||"We're currently offline. Leave a message and we'll get back to you!")&&q("div",{class:"cdk-msg cdk-msg-agent",children:q("div",{class:"cdk-msg-bubble cdk-msg-bubble-agent",children:H?null==I?void 0:I.welcomeMessage:(null==I?void 0:I.offlineMessage)||"We're currently offline. Leave a message and we'll get back to you!"})}),l.map(t=>{const e=C.has(t.id);return q("div",{class:`cdk-msg ${"contact"===t.sender_type?"cdk-msg-visitor":"cdk-msg-agent"} ${e?"cdk-msg-failed":""}`,children:[q("div",{class:`cdk-msg-bubble ${"contact"===t.sender_type?"cdk-msg-bubble-visitor":"cdk-msg-bubble-agent"} ${e?"cdk-msg-bubble-failed":""}`,children:[t.attachments&&t.attachments.length>0&&q("div",{class:"cdk-msg-attachments",children:t.attachments.map(t=>{var e;return q("a",(null==(e=t.type)?void 0:e.startsWith("image/"))||/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url||t.name)?{href:t.url,target:"_blank",rel:"noopener noreferrer",class:"cdk-attachment-img-link",children:q("img",{src:t.url,alt:t.name,class:"cdk-attachment-img",loading:"lazy"})}:{href:t.url,target:"_blank",rel:"noopener noreferrer",class:"cdk-attachment-file",children:[q("span",{class:"cdk-attachment-icon",children:"📎"}),q("span",{class:"cdk-attachment-name",children:t.name}),t.size&&q("span",{class:"cdk-attachment-size",children:["(",(t.size/1024).toFixed(0),"KB)"]})]})})}),t.content&&q("span",{children:t.content})]}),q("div",{class:"cdk-msg-meta",children:q("div",e?{class:"cdk-msg-error",children:[q("span",{class:"cdk-msg-error-text",children:"Gửi thất bại"}),q("button",{class:"cdk-msg-retry-btn",onClick:()=>j(t.id),title:"Thử lại",children:"⟳ Thử lại"}),q("button",{class:"cdk-msg-delete-btn",onClick:()=>{u(e=>e.filter(e=>e.id!==t.id)),S(e=>{const n=new Set(e);return n.delete(t.id),n})},title:"Xoá",children:"✕"})]}:{class:"cdk-msg-time",children:W(t.sent_at)})})]},t.id)}),g&&q("div",{class:"cdk-msg cdk-msg-agent",children:q("div",{class:"cdk-msg-bubble cdk-msg-bubble-agent cdk-typing",children:[q("span",{class:"cdk-dot"}),q("span",{class:"cdk-dot"}),q("span",{class:"cdk-dot"})]})}),q("div",{ref:A})]}),k&&q("div",{class:"cdk-toast cdk-toast-error",children:[q("span",{children:["⚠️ ",k]}),q("button",{class:"cdk-toast-close",onClick:()=>T(null),children:"✕"})]}),q("div",{class:"cdk-input-wrapper",children:[b&&q(We,{onSelect:M}),q("div",{class:"cdk-input-area",children:[q("div",{class:"cdk-input-box",children:[q("textarea",{ref:O,class:"cdk-input",placeholder:(null==I?void 0:I.placeholderText)||"Type a message...",value:d,onInput:t=>{p(t.target.value);const e=vt.getConversationId();e&&(N.current?clearTimeout(N.current):Ve.emitTyping(e,!0),N.current=window.setTimeout(()=>{Ve.emitTyping(e,!1),N.current=null},2500))},onKeyDown:t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),P())},rows:1,disabled:_}),q("button",{type:"button",class:"cdk-action-btn",onClick:()=>w(!b),title:"Add emoji",children:q("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[q("circle",{cx:"12",cy:"12",r:"10"}),q("path",{d:"M8 14s1.5 2 4 2 4-2 4-2"}),q("line",{x1:"9",y1:"9",x2:"9.01",y2:"9"}),q("line",{x1:"15",y1:"9",x2:"15.01",y2:"9"})]})}),q("label",{class:"cdk-action-btn",title:"Attach file",children:[q("input",{type:"file",style:{display:"none"},onChange:F}),q("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:q("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})]})]}),q("button",{class:"cdk-send-btn",onClick:P,disabled:!d.trim()||_,"aria-label":"Send",children:q("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:q("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]})]}),!(i&&B)&&q("button",{class:`cdk-toggle ${!i&&B?"cdk-toggle-compact":""} ${!i&&B&&z.includes("left")?"cdk-compact-left":""}`,onClick:()=>{r(t=>!t),i||(v(0),w(!1))},"aria-label":"Toggle chat",children:[!B&&i?q("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.25","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:q("path",{d:"M6 10l6 6 6-6"})}):B?q("div",{class:"cdk-compact-inner",children:[q("img",{src:D,alt:"","aria-hidden":"true",class:"cdk-compact-logo"}),q("span",{class:"cdk-compact-title",children:"Chat with us"})]}):q("img",{src:D,alt:"","aria-hidden":"true",class:"cdk-toggle-logo"}),y>0&&!i&&q("span",{class:"cdk-badge",children:y>9?"9+":y})]})]}):null},Ye=new Map,Je="https://api.chatdakenh.vn/api/v1",Xe="https://ws.chatdakenh.vn";function Qe(t){const{widgetId:e,apiUrl:n=Je,wsUrl:s=Xe}=t;if(Ye.has(e))return;const i=document.createElement("div");i.id=`cdk-widget-${e}`,i.setAttribute("data-cdk-widget","true"),document.body.appendChild(i),j(q(Ke,{widgetId:e,apiUrl:n,wsUrl:s}),i),Ye.set(e,{container:i,unmount:()=>{j(null,i),i.remove()}})}function Ze(){document.querySelectorAll("script[data-widget-id]").forEach(t=>{const e=t.getAttribute("data-widget-id"),n=t.getAttribute("data-api-url")||Je,s=t.getAttribute("data-ws-url")||Xe;e&&Qe({widgetId:e,apiUrl:n,wsUrl:s})})}const Ge={init:Qe,destroy:function(t){if(t){const e=Ye.get(t);e&&(e.unmount(),Ye.delete(t))}else Ye.forEach(t=>t.unmount()),Ye.clear()},version:"1.0.0"};return"undefined"!=typeof window&&(window.ChatDaKenh=Ge,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Ze):Ze()),Ge}();
1
+ (function(){var s=document.createElement('style');s.setAttribute('data-cdk-widget','');s.textContent=".cdk-widget,.cdk-widget *{box-sizing:border-box;margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;line-height:1.5}.cdk-widget{position:fixed;z-index:2147483647;color-scheme:light;--cdk-brand: #0b63f6;--cdk-brand-hover: #0852d6;--cdk-brand-soft: #dbeafe;--cdk-brand-contrast: #ffffff}.cdk-bottom-right{bottom:20px;right:20px}.cdk-bottom-left{bottom:20px;left:20px}.cdk-top-right{top:20px;right:20px}.cdk-top-left{top:20px;left:20px}.cdk-panel{position:absolute;bottom:72px;right:0;width:380px;max-width:calc(100vw - 32px);height:560px;max-height:calc(100vh - 120px);background:#fff;border-radius:16px;box-shadow:0 20px 60px #00000026,0 8px 20px #0000001a;display:flex;flex-direction:column;overflow:hidden;opacity:0;transform:translateY(16px) scale(.95);pointer-events:none;transition:opacity .25s ease,transform .25s ease}.cdk-bottom-left .cdk-panel{right:auto;left:0}.cdk-top-right .cdk-panel,.cdk-top-left .cdk-panel{bottom:auto;top:72px;transform:translateY(-16px) scale(.95)}.cdk-panel-open{opacity:1;transform:translateY(0) scale(1);pointer-events:auto}.cdk-widget-compact.cdk-bottom-right .cdk-panel,.cdk-widget-compact.cdk-bottom-left .cdk-panel{bottom:58px}.cdk-widget-compact.cdk-top-right .cdk-panel,.cdk-widget-compact.cdk-top-left .cdk-panel{top:86px}.cdk-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;background:linear-gradient(135deg,#0f6bff,#0b63f6 55%,#0852d6);color:#fff;flex-shrink:0}.cdk-header-info{flex:1;min-width:0}.cdk-header-avatar{width:40px;height:40px;margin-right:12px;object-fit:contain}.cdk-header-title{font-size:16px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.cdk-header-subtitle{font-size:12px;opacity:.85;margin-top:2px;transition:opacity .2s ease}.cdk-subtitle-typing{font-style:italic;opacity:1;animation:cdk-typingPulse 1.5s ease-in-out infinite}@keyframes cdk-typingPulse{0%,to{opacity:.7}50%{opacity:1}}.cdk-header-close{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:none;border-radius:8px;background:#fff3;color:#fff;cursor:pointer;transition:background .2s;flex-shrink:0;margin-left:12px}.cdk-header-close:hover{background:#ffffff59}.cdk-widget-compact .cdk-header{padding:12px 14px}.cdk-widget-compact .cdk-header-avatar{width:36px;height:36px;margin-right:11px}.cdk-widget-compact .cdk-header-title{font-size:14px;line-height:1.2}.cdk-widget-compact .cdk-header-subtitle{font-size:12px;margin-top:1px;line-height:1.2}.cdk-widget-compact .cdk-header-close{width:30px;height:30px;margin-left:10px;border-radius:8px}.cdk-widget-compact .cdk-header-close svg{width:17px;height:17px}.cdk-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:8px;background:#f8f9fb}.cdk-messages::-webkit-scrollbar{width:4px}.cdk-messages::-webkit-scrollbar-thumb{background:#d1d5db;border-radius:4px}.cdk-msg{display:flex;flex-direction:column;max-width:80%;animation:cdk-fadeIn .2s ease}@keyframes cdk-fadeIn{0%{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}.cdk-msg-visitor{align-self:flex-end;align-items:flex-end}.cdk-msg-agent{align-self:flex-start;align-items:flex-start}.cdk-msg-bubble{padding:10px 14px;border-radius:16px;font-size:14px;word-break:break-word;white-space:pre-wrap}.cdk-msg-bubble-visitor{background:var(--cdk-brand);color:#fff;border:1px solid rgba(255,255,255,.18);border-bottom-right-radius:4px}.cdk-msg-bubble-agent{background:#fff;color:#1f2937;border:1px solid #e5e7eb;border-bottom-left-radius:4px}.cdk-msg-time{font-size:11px;color:#9ca3af;margin-top:4px;padding:0 4px}.cdk-msg-attachments{margin-bottom:4px}.cdk-attachment-img-link{display:block}.cdk-attachment-img{max-width:100%;max-height:200px;border-radius:8px;object-fit:cover;cursor:pointer;transition:opacity .2s}.cdk-attachment-img:hover{opacity:.85}.cdk-attachment-file{display:flex;align-items:center;gap:6px;padding:8px 12px;background:#0000000f;border-radius:8px;text-decoration:none;color:inherit;font-size:13px;transition:background .2s}.cdk-attachment-file:hover{background:#0000001a}.cdk-msg-bubble-visitor .cdk-attachment-file{background:#ffffff26;color:#fff}.cdk-msg-bubble-visitor .cdk-attachment-file:hover{background:#ffffff40}.cdk-attachment-icon{font-size:16px;flex-shrink:0}.cdk-attachment-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cdk-attachment-size{font-size:11px;opacity:.7;flex-shrink:0}.cdk-typing{display:flex;align-items:center;gap:4px;padding:12px 18px}.cdk-dot{width:7px;height:7px;background:#9ca3af;border-radius:50%;animation:cdk-bounce 1.4s infinite ease-in-out both}.cdk-dot:nth-child(1){animation-delay:-.32s}.cdk-dot:nth-child(2){animation-delay:-.16s}@keyframes cdk-bounce{0%,80%,to{transform:scale(.6);opacity:.4}40%{transform:scale(1);opacity:1}}.cdk-input-wrapper{display:flex;flex-direction:column;position:relative;background:#fff;border-top:1px solid #e5e7eb}.cdk-action-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;background:transparent;color:#6b7280;border-radius:8px;cursor:pointer;transition:background .2s,color .2s;flex-shrink:0}.cdk-action-btn:hover{background:#f3f4f6;color:#1f2937}.cdk-input-area{display:flex;align-items:flex-end;gap:6px;padding:8px 12px;background:#fff}.cdk-emoji-picker{position:absolute;bottom:100%;left:12px;width:300px;max-width:calc(100% - 24px);background:#fff;border:1px solid #e5e7eb;border-radius:12px;box-shadow:0 10px 25px #0000001a;padding:10px;z-index:10;margin-bottom:8px}.cdk-emoji-grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px;max-height:200px;overflow-y:auto}.cdk-emoji-grid::-webkit-scrollbar{width:4px}.cdk-emoji-grid::-webkit-scrollbar-thumb{background:#d1d5db;border-radius:4px}.cdk-emoji-btn{background:transparent;border:none;font-size:20px;cursor:pointer;width:100%;aspect-ratio:1;border-radius:6px;display:flex;align-items:center;justify-content:center}.cdk-emoji-btn:hover{background:#f3f4f6}.cdk-input-box{flex:1;display:flex;align-items:flex-end;background:#f9fafb;border:1px solid #e5e7eb;border-radius:10px;padding:2px 3px;transition:border-color .2s,background .2s;gap:1px}.cdk-input-box:focus-within{border-color:var(--cdk-brand);background:#fff}.cdk-input{flex:1;border:none;background:transparent;padding:4px 8px;font-size:14px;resize:none;outline:none;max-height:88px;min-height:30px;color:#1f2937;font-family:inherit;line-height:1.35}.cdk-input::placeholder{color:#9ca3af}.cdk-send-btn{display:flex;align-items:center;justify-content:center;width:36px;height:36px;border:none;border-radius:10px;background:var(--cdk-brand);color:#fff;cursor:pointer;flex-shrink:0;transition:opacity .2s,transform .15s}.cdk-send-btn:hover:not(:disabled){background:var(--cdk-brand-hover);opacity:1;transform:scale(1.03)}.cdk-send-btn:disabled{opacity:.4;cursor:not-allowed}.cdk-footer{text-align:center;padding:8px;font-size:11px;color:#9ca3af;background:#fff;border-top:1px solid #f3f4f6}.cdk-footer a{color:var(--cdk-brand);text-decoration:none;font-weight:500}.cdk-footer a:hover{text-decoration:underline}.cdk-toggle{display:flex;align-items:center;justify-content:center;width:58px;height:58px;border:none;border-radius:99px;color:#fff;cursor:pointer;background:#0b63f6;box-shadow:0 12px 26px #0b63f652,0 4px 10px #02061726;transition:transform .2s,box-shadow .2s;position:relative}.cdk-toggle:hover{transform:translateY(-1px);box-shadow:0 16px 30px #0b63f65c,0 5px 12px #02061729}.cdk-toggle:active{transform:scale(.98)}.cdk-toggle-logo{width:38px;height:38px;display:block;object-fit:contain;object-position:center;filter:drop-shadow(0 1px 2px rgba(255,255,255,.18))}.cdk-toggle[aria-label=\"Toggle chat\"]>svg{color:#fff}.cdk-toggle-compact{height:136px;border-radius:13px 0 0 13px;border:none;flex-direction:column;padding:12px 0;width:40px;position:absolute;right:-20px;bottom:0;transform:none;background:#0b63f6;box-shadow:-10px 12px 24px #0b63f647}.cdk-toggle-compact:hover{transform:none;box-shadow:-12px 14px 28px #0b63f657}.cdk-toggle-compact:active{transform:none}.cdk-toggle-compact.cdk-compact-left{border-radius:0 13px 13px 0;left:-20px;right:auto;box-shadow:10px 12px 24px #0b63f647}.cdk-toggle-compact.cdk-compact-left:hover{transform:none;box-shadow:12px 14px 28px #0b63f657}.cdk-toggle-compact.cdk-compact-left:active{transform:none}.cdk-compact-inner{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;width:100%;height:100%;padding:6px 0;position:relative;z-index:1}.cdk-compact-logo{width:24px;height:24px;display:block;object-fit:contain;object-position:center;position:static;transform:none;padding:0;background:transparent;border:none;border-radius:0;box-shadow:none;opacity:.95;transform:translateY(-1px)}.cdk-compact-title{writing-mode:vertical-rl;font-weight:700;font-size:12px;letter-spacing:.3px;text-transform:none;white-space:nowrap;color:#fff;text-shadow:0 1px 2px rgba(2,6,23,.2);transform:rotate(180deg);margin:0;line-height:1;transform-origin:center}.cdk-toggle-compact:not(.cdk-compact-left) .cdk-compact-title{transform:none}.cdk-compact-icon{display:flex;align-items:center;justify-content:center}.cdk-toggle-compact .cdk-badge{top:-4px;bottom:auto;right:auto;left:-8px}.cdk-compact-left .cdk-badge{left:auto;right:-8px}.cdk-badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;background:#ef4444;border-radius:10px;font-size:11px;font-weight:700;color:#fff;display:flex;align-items:center;justify-content:center;padding:0 5px;border:2px solid white;animation:cdk-popIn .3s ease}@keyframes cdk-popIn{0%{transform:scale(0)}to{transform:scale(1)}}@media(max-width:480px){.cdk-panel{width:calc(100vw - 16px);height:calc(100vh - 100px);border-radius:12px;right:-12px}.cdk-widget{bottom:12px!important;right:12px!important}}.cdk-toast{position:absolute;bottom:62px;left:12px;right:12px;display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-radius:10px;font-size:13px;z-index:10;animation:cdk-toastSlideIn .3s ease}.cdk-toast-error{background:#fef2f2;color:#b91c1c;border:1px solid #fecaca}.cdk-toast-close{background:none;border:none;color:#b91c1c;cursor:pointer;font-size:14px;padding:0 0 0 8px;opacity:.6}.cdk-toast-close:hover{opacity:1}@keyframes cdk-toastSlideIn{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.cdk-msg-failed{opacity:.85}.cdk-msg-bubble-failed{background:#fef2f2!important;color:#b91c1c!important;border:1px dashed #fca5a5!important}.cdk-msg-meta{display:flex;align-items:center;margin-top:4px;padding:0 4px}.cdk-msg-error{display:flex;align-items:center;gap:8px}.cdk-msg-error-text{font-size:11px;color:#dc2626}.cdk-msg-retry-btn{background:none;border:1px solid #dc2626;color:#dc2626;border-radius:4px;font-size:11px;padding:2px 8px;cursor:pointer;transition:all .2s}.cdk-msg-retry-btn:hover{background:#dc2626;color:#fff}.cdk-msg-delete-btn{background:none;border:none;color:#9ca3af;cursor:pointer;font-size:12px;padding:2px 4px}.cdk-msg-delete-btn:hover{color:#dc2626}\n";document.head.appendChild(s)})();var ChatDaKenh=function(){"use strict";var t,e,n,s,i,r,o,a,c,l,h,u={},d=[],p=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_=Array.isArray;function f(t,e){for(var n in e)t[n]=e[n];return t}function g(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function y(t,s,i,r,o){var a={type:t,props:s,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==o?++n:o,__i:-1,__u:0};return null==o&&null!=e.vnode&&e.vnode(a),a}function m(t){return t.children}function v(t,e){this.props=t,this.context=e}function b(t,e){if(null==e)return t.__?b(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if(null!=(n=t.__k[e])&&null!=n.__e)return n.__e;return"function"==typeof t.type?b(t):null}function w(t){if(t.__P&&t.__d){var n=t.__v,s=n.__e,i=[],r=[],o=f({},n);o.__v=n.__v+1,e.vnode&&e.vnode(o),R(t.__P,o,n,t.__n,t.__P.namespaceURI,32&n.__u?[s]:null,i,null==s?b(n):s,!!(32&n.__u),r),o.__v=n.__v,o.__.__k[o.__i]=o,B(i,o,r),n.__e=n.__=null,o.__e!=s&&k(o)}}function k(t){if(null!=(t=t.__)&&null!=t.__c)return t.__e=t.__c.base=null,t.__k.some(function(e){if(null!=e&&null!=e.__e)return t.__e=t.__c.base=e.__e}),k(t)}function C(t){(!t.__d&&(t.__d=!0)&&s.push(t)&&!T.__r++||i!=e.debounceRendering)&&((i=e.debounceRendering)||r)(T)}function T(){for(var t,e=1;s.length;)s.length>e&&s.sort(o),t=s.shift(),e=s.length,w(t);T.__r=0}function S(t,e,n,s,i,r,o,a,c,l,h){var p,f,g,v,w,k,C,T=s&&s.__k||d,S=e.length;for(c=function(t,e,n,s,i){var r,o,a,c,l,h=n.length,u=h,d=0;for(t.__k=new Array(i),r=0;r<i;r++)null!=(o=e[r])&&"boolean"!=typeof o&&"function"!=typeof o?("string"==typeof o||"number"==typeof o||"bigint"==typeof o||o.constructor==String?o=t.__k[r]=y(null,o,null,null,null):_(o)?o=t.__k[r]=y(m,{children:o},null,null,null):void 0===o.constructor&&o.__b>0?o=t.__k[r]=y(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):t.__k[r]=o,c=r+d,o.__=t,o.__b=t.__b+1,a=null,-1!=(l=o.__i=A(o,n,c,u))&&(u--,(a=n[l])&&(a.__u|=2)),null==a||null==a.__v?(-1==l&&(i>h?d--:i<h&&d++),"function"!=typeof o.type&&(o.__u|=4)):l!=c&&(l==c-1?d--:l==c+1?d++:(l>c?d--:d++,o.__u|=4))):t.__k[r]=null;if(u)for(r=0;r<h;r++)null!=(a=n[r])&&!(2&a.__u)&&(a.__e==s&&(s=b(a)),F(a,a));return s}(n,e,T,c,S),p=0;p<S;p++)null!=(g=n.__k[p])&&(f=-1!=g.__i&&T[g.__i]||u,g.__i=p,k=R(t,g,f,i,r,o,a,c,l,h),v=g.__e,g.ref&&f.ref!=g.ref&&(f.ref&&L(f.ref,null,g),h.push(g.ref,g.__c||v,g)),null==w&&null!=v&&(w=v),(C=!!(4&g.__u))||f.__k===g.__k?c=E(g,c,t,C):"function"==typeof g.type&&void 0!==k?c=k:v&&(c=v.nextSibling),g.__u&=-7);return n.__e=w,c}function E(t,e,n,s){var i,r;if("function"==typeof t.type){for(i=t.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=t,e=E(i[r],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=b(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do{e=e&&e.nextSibling}while(null!=e&&8==e.nodeType);return e}function A(t,e,n,s){var i,r,o,a=t.key,c=t.type,l=e[n],h=null!=l&&!(2&l.__u);if(null===l&&null==a||h&&a==l.key&&c==l.type)return n;if(s>(h?1:0))for(i=n-1,r=n+1;i>=0||r<e.length;)if(null!=(l=e[o=i>=0?i--:r++])&&!(2&l.__u)&&a==l.key&&c==l.type)return o;return-1}function O(t,e,n){"-"==e[0]?t.setProperty(e,null==n?"":n):t[e]=null==n?"":"number"!=typeof n||p.test(e)?n:n+"px"}function x(t,e,n,s,i){var r,o;t:if("style"==e)if("string"==typeof n)t.style.cssText=n;else{if("string"==typeof s&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||O(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||O(t.style,e,n[e])}else if("o"==e[0]&&"n"==e[1])r=e!=(e=e.replace(a,"$1")),o=e.toLowerCase(),e=o in t||"onFocusOut"==e||"onFocusIn"==e?o.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?s?n.u=s.u:(n.u=c,t.addEventListener(e,r?h:l,r)):t.removeEventListener(e,r?h:l,r);else{if("http://www.w3.org/2000/svg"==i)e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=e&&"height"!=e&&"href"!=e&&"list"!=e&&"form"!=e&&"tabIndex"!=e&&"download"!=e&&"rowSpan"!=e&&"colSpan"!=e&&"role"!=e&&"popover"!=e&&e in t)try{t[e]=null==n?"":n;break t}catch(u){}"function"==typeof n||(null==n||!1===n&&"-"!=e[4]?t.removeAttribute(e):t.setAttribute(e,"popover"==e&&1==n?"":n))}}function N(t){return function(n){if(this.l){var s=this.l[n.type+t];if(null==n.t)n.t=c++;else if(n.t<s.u)return;return s(e.event?e.event(n):n)}}}function R(n,s,i,r,o,a,c,l,h,p){var y,w,k,C,T,E,A,O,N,R,B,L,F,U,j,P=s.type;if(void 0!==s.constructor)return null;128&i.__u&&(h=!!(32&i.__u),a=[l=s.__e=i.__e]),(y=e.__b)&&y(s);t:if("function"==typeof P)try{if(O=s.props,N="prototype"in P&&P.prototype.render,R=(y=P.contextType)&&r[y.__c],B=y?R?R.props.value:y.__:r,i.__c?A=(w=s.__c=i.__c).__=w.__E:(N?s.__c=w=new P(O,B):(s.__c=w=new v(O,B),w.constructor=P,w.render=M),R&&R.sub(w),w.state||(w.state={}),w.__n=r,k=w.__d=!0,w.__h=[],w._sb=[]),N&&null==w.__s&&(w.__s=w.state),N&&null!=P.getDerivedStateFromProps&&(w.__s==w.state&&(w.__s=f({},w.__s)),f(w.__s,P.getDerivedStateFromProps(O,w.__s))),C=w.props,T=w.state,w.__v=s,k)N&&null==P.getDerivedStateFromProps&&null!=w.componentWillMount&&w.componentWillMount(),N&&null!=w.componentDidMount&&w.__h.push(w.componentDidMount);else{if(N&&null==P.getDerivedStateFromProps&&O!==C&&null!=w.componentWillReceiveProps&&w.componentWillReceiveProps(O,B),s.__v==i.__v||!w.__e&&null!=w.shouldComponentUpdate&&!1===w.shouldComponentUpdate(O,w.__s,B)){s.__v!=i.__v&&(w.props=O,w.state=w.__s,w.__d=!1),s.__e=i.__e,s.__k=i.__k,s.__k.some(function(t){t&&(t.__=s)}),d.push.apply(w.__h,w._sb),w._sb=[],w.__h.length&&c.push(w);break t}null!=w.componentWillUpdate&&w.componentWillUpdate(O,w.__s,B),N&&null!=w.componentDidUpdate&&w.__h.push(function(){w.componentDidUpdate(C,T,E)})}if(w.context=B,w.props=O,w.__P=n,w.__e=!1,L=e.__r,F=0,N)w.state=w.__s,w.__d=!1,L&&L(s),y=w.render(w.props,w.state,w.context),d.push.apply(w.__h,w._sb),w._sb=[];else do{w.__d=!1,L&&L(s),y=w.render(w.props,w.state,w.context),w.state=w.__s}while(w.__d&&++F<25);w.state=w.__s,null!=w.getChildContext&&(r=f(f({},r),w.getChildContext())),N&&!k&&null!=w.getSnapshotBeforeUpdate&&(E=w.getSnapshotBeforeUpdate(C,T)),U=null!=y&&y.type===m&&null==y.key?D(y.props.children):y,l=S(n,_(U)?U:[U],s,i,r,o,a,c,l,h,p),w.base=s.__e,s.__u&=-161,w.__h.length&&c.push(w),A&&(w.__E=w.__=null)}catch(q){if(s.__v=null,h||null!=a)if(q.then){for(s.__u|=h?160:128;l&&8==l.nodeType&&l.nextSibling;)l=l.nextSibling;a[a.indexOf(l)]=null,s.__e=l}else{for(j=a.length;j--;)g(a[j]);I(s)}else s.__e=i.__e,s.__k=i.__k,q.then||I(s);e.__e(q,s,i)}else null==a&&s.__v==i.__v?(s.__k=i.__k,s.__e=i.__e):l=s.__e=function(n,s,i,r,o,a,c,l,h){var d,p,f,y,m,v,w,k=i.props||u,C=s.props,T=s.type;if("svg"==T?o="http://www.w3.org/2000/svg":"math"==T?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),null!=a)for(d=0;d<a.length;d++)if((m=a[d])&&"setAttribute"in m==!!T&&(T?m.localName==T:3==m.nodeType)){n=m,a[d]=null;break}if(null==n){if(null==T)return document.createTextNode(C);n=document.createElementNS(o,T,C.is&&C),l&&(e.__m&&e.__m(s,a),l=!1),a=null}if(null==T)k===C||l&&n.data==C||(n.data=C);else{if(a=a&&t.call(n.childNodes),!l&&null!=a)for(k={},d=0;d<n.attributes.length;d++)k[(m=n.attributes[d]).name]=m.value;for(d in k)m=k[d],"dangerouslySetInnerHTML"==d?f=m:"children"==d||d in C||"value"==d&&"defaultValue"in C||"checked"==d&&"defaultChecked"in C||x(n,d,null,m,o);for(d in C)m=C[d],"children"==d?y=m:"dangerouslySetInnerHTML"==d?p=m:"value"==d?v=m:"checked"==d?w=m:l&&"function"!=typeof m||k[d]===m||x(n,d,m,k[d],o);if(p)l||f&&(p.__html==f.__html||p.__html==n.innerHTML)||(n.innerHTML=p.__html),s.__k=[];else if(f&&(n.innerHTML=""),S("template"==s.type?n.content:n,_(y)?y:[y],s,i,r,"foreignObject"==T?"http://www.w3.org/1999/xhtml":o,a,c,a?a[0]:i.__k&&b(i,0),l,h),null!=a)for(d=a.length;d--;)g(a[d]);l||(d="value","progress"==T&&null==v?n.removeAttribute("value"):null!=v&&(v!==n[d]||"progress"==T&&!v||"option"==T&&v!=k[d])&&x(n,d,v,k[d],o),d="checked",null!=w&&w!=n[d]&&x(n,d,w,k[d],o))}return n}(i.__e,s,i,r,o,a,c,h,p);return(y=e.diffed)&&y(s),128&s.__u?void 0:l}function I(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(I))}function B(t,n,s){for(var i=0;i<s.length;i++)L(s[i],s[++i],s[++i]);e.__c&&e.__c(n,t),t.some(function(n){try{t=n.__h,n.__h=[],t.some(function(t){t.call(n)})}catch(s){e.__e(s,n.__v)}})}function D(t){return"object"!=typeof t||null==t||t.__b>0?t:_(t)?t.map(D):f({},t)}function L(t,n,s){try{if("function"==typeof t){var i="function"==typeof t.__u;i&&t.__u(),i&&null==n||(t.__u=t(n))}else t.current=n}catch(r){e.__e(r,s)}}function F(t,n,s){var i,r;if(e.unmount&&e.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||L(i,null,n)),null!=(i=t.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(o){e.__e(o,n)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&F(i[r],n,s||"function"!=typeof t.type);s||g(t.__e),t.__c=t.__=t.__e=void 0}function M(t,e,n){return this.constructor(t,n)}function U(n,s,i){var r,o,a;s==document&&(s=document.documentElement),e.__&&e.__(n,s),r=!1?null:s.__k,o=[],a=[],R(s,n=s.__k=function(e,n,s){var i,r,o,a={};for(o in n)"key"==o?i=n[o]:"ref"==o?r=n[o]:a[o]=n[o];if(arguments.length>2&&(a.children=arguments.length>3?t.call(arguments,2):s),"function"==typeof e&&null!=e.defaultProps)for(o in e.defaultProps)void 0===a[o]&&(a[o]=e.defaultProps[o]);return y(e,a,i,r,null)}(m,null,[n]),r||u,u,s.namespaceURI,r?null:s.firstChild?t.call(s.childNodes):null,o,r?r.__e:s.firstChild,false,a),B(o,n,a)}t=d.slice,e={__e:function(t,e,n,s){for(var i,r,o;e=e.__;)if((i=e.__c)&&!i.__)try{if((r=i.constructor)&&null!=r.getDerivedStateFromError&&(i.setState(r.getDerivedStateFromError(t)),o=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(t,s||{}),o=i.__d),o)return i.__E=i}catch(a){t=a}throw t}},n=0,v.prototype.setState=function(t,e){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=f({},this.state),"function"==typeof t&&(t=t(f({},n),this.props)),t&&f(n,t),null!=t&&this.__v&&(e&&this._sb.push(e),C(this))},v.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),C(this))},v.prototype.render=m,s=[],r="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,o=function(t,e){return t.__v.__b-e.__v.__b},T.__r=0,a=/(PointerCapture)$|Capture$/i,c=0,l=N(!1),h=N(!0);var j=0;function P(t,n,s,i,r,o){n||(n={});var a,c,l=n;if("ref"in l)for(c in l={},n)"ref"==c?a=n[c]:l[c]=n[c];var h={type:t,props:l,key:s,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--j,__i:-1,__u:0,__source:r,__self:o};if("function"==typeof t&&(a=t.defaultProps))for(c in a)void 0===l[c]&&(l[c]=a[c]);return e.vnode&&e.vnode(h),h}var q,$,H,z,V=0,W=[],K=e,J=K.__b,Y=K.__r,X=K.diffed,Q=K.__c,G=K.unmount,Z=K.__;function tt(t,e){K.__h&&K.__h($,t,V||e),V=0;var n=$.__H||($.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function et(t){return V=1,function(t,e){var n=tt(q++,2);if(n.t=t,!n.__c&&(n.__=[dt(void 0,e),function(t){var e=n.__N?n.__N[0]:n.__[0],s=n.t(e,t);e!==s&&(n.__N=[s,n.__[1]],n.__c.setState({}))}],n.__c=$,!$.__f)){var s=function(t,e,s){if(!n.__c.__H)return!0;var r=n.__c.__H.__.filter(function(t){return t.__c});if(r.every(function(t){return!t.__N}))return!i||i.call(this,t,e,s);var o=n.__c.props!==t;return r.some(function(t){if(t.__N){var e=t.__[0];t.__=t.__N,t.__N=void 0,e!==t.__[0]&&(o=!0)}}),i&&i.call(this,t,e,s)||o};$.__f=!0;var i=$.shouldComponentUpdate,r=$.componentWillUpdate;$.componentWillUpdate=function(t,e,n){if(this.__e){var o=i;i=void 0,s(t,e,n),i=o}r&&r.call(this,t,e,n)},$.shouldComponentUpdate=s}return n.__N||n.__}(dt,t)}function nt(t,e){var n=tt(q++,3);!K.__s&&ut(n.__H,e)&&(n.__=t,n.u=e,$.__H.__h.push(n))}function st(t){return V=5,it(function(){return{current:t}},[])}function it(t,e){var n=tt(q++,7);return ut(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function rt(t,e){return V=8,it(function(){return t},e)}function ot(){for(var t;t=W.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(lt),e.__h.some(ht),e.__h=[]}catch(n){e.__h=[],K.__e(n,t.__v)}}}K.__b=function(t){$=null,J&&J(t)},K.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Z&&Z(t,e)},K.__r=function(t){Y&&Y(t),q=0;var e=($=t.__c).__H;e&&(H===$?(e.__h=[],$.__h=[],e.__.some(function(t){t.__N&&(t.__=t.__N),t.u=t.__N=void 0})):(e.__h.some(lt),e.__h.some(ht),e.__h=[],q=0)),H=$},K.diffed=function(t){X&&X(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(1!==W.push(e)&&z===K.requestAnimationFrame||((z=K.requestAnimationFrame)||ct)(ot)),e.__H.__.some(function(t){t.u&&(t.__H=t.u),t.u=void 0})),H=$=null},K.__c=function(t,e){e.some(function(t){try{t.__h.some(lt),t.__h=t.__h.filter(function(t){return!t.__||ht(t)})}catch(n){e.some(function(t){t.__h&&(t.__h=[])}),e=[],K.__e(n,t.__v)}}),Q&&Q(t,e)},K.unmount=function(t){G&&G(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.some(function(t){try{lt(t)}catch(n){e=n}}),n.__H=void 0,e&&K.__e(e,n.__v))};var at="function"==typeof requestAnimationFrame;function ct(t){var e,n=function(){clearTimeout(s),at&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);at&&(e=requestAnimationFrame(n))}function lt(t){var e=$,n=t.__c;"function"==typeof n&&(t.__c=void 0,n()),$=e}function ht(t){var e=$;t.__c=t.__(),$=e}function ut(t,e){return!t||t.length!==e.length||e.some(function(e,n){return e!==t[n]})}function dt(t,e){return"function"==typeof e?e(t):e}const pt={defaultTitle:"Chat",defaultSubtitle:"We typically reply within minutes",agentTyping:"Agent is typing...",closedToday:"Closed today",serviceHours:"Service hours:",offlineMessage:"We're currently offline. Leave a message and we'll get back to you!",defaultPlaceholder:"Type a message...",close:"Close",send:"Send",toggleChat:"Toggle chat",addEmoji:"Add emoji",attachFile:"Attach file",chatWithUs:"Chat with us",sendFailed:"Send failed",sendFailedToast:"Failed to send message. Tap to retry.",retryFailed:"Retry failed. Check your connection.",retry:"Retry",delete:"Delete",fileTooLarge:"File too large ({{size}}MB). Max allowed: 10MB.",uploading:"Uploading {{name}}...",uploadFailed:"Upload failed: {{error}}"},_t={en:pt,vi:{defaultTitle:"Chat",defaultSubtitle:"Chúng tôi thường phản hồi trong vài phút",agentTyping:"Nhân viên đang nhập...",closedToday:"Hôm nay nghỉ",serviceHours:"Giờ làm việc:",offlineMessage:"Chúng tôi hiện không trực tuyến. Hãy để lại tin nhắn, chúng tôi sẽ phản hồi sớm nhất!",defaultPlaceholder:"Nhập tin nhắn...",close:"Đóng",send:"Gửi",toggleChat:"Mở/đóng chat",addEmoji:"Thêm emoji",attachFile:"Đính kèm file",chatWithUs:"Chat với chúng tôi",sendFailed:"Gửi thất bại",sendFailedToast:"Gửi tin nhắn thất bại. Nhấn để thử lại.",retryFailed:"Thử lại thất bại. Kiểm tra kết nối mạng.",retry:"Thử lại",delete:"Xoá",fileTooLarge:"File quá lớn ({{size}}MB). Tối đa: 10MB.",uploading:"Đang tải {{name}}...",uploadFailed:"Tải lên thất bại: {{error}}"}};let ft=pt;function gt(t,e){let n=ft[t]||pt[t];if(e)for(const[s,i]of Object.entries(e))n=n.replace(`{{${s}}}`,i);return n}const yt={VISITOR_ID:"cdk_visitor_id",CONVERSATION_ID:"cdk_conversation_id",SESSION_TOKEN:"cdk_session_token",TENANT_ID:"cdk_tenant_id"},mt="widget:message",vt="widget:agent_typing",bt="widget:session_expired",wt="receive_message",kt="join_receive_message";const Ct=new class{get(t){try{return localStorage.getItem(t)??sessionStorage.getItem(t)??null}catch{return null}}set(t,e){try{localStorage.setItem(t,e)}catch{try{sessionStorage.setItem(t,e)}catch{}}}remove(t){try{localStorage.removeItem(t),sessionStorage.removeItem(t)}catch{}}getVisitorId(){return this.get(yt.VISITOR_ID)}setVisitorId(t){this.set(yt.VISITOR_ID,t)}getConversationId(){return this.get(yt.CONVERSATION_ID)}setConversationId(t){this.set(yt.CONVERSATION_ID,t)}getSessionToken(){return this.get(yt.SESSION_TOKEN)}setSessionToken(t){this.set(yt.SESSION_TOKEN,t)}getTenantId(){return this.get(yt.TENANT_ID)}setTenantId(t){this.set(yt.TENANT_ID,t)}clearAll(){Object.values(yt).forEach(t=>this.remove(t))}};const Tt=new class{constructor(){this.baseUrl=""}configure(t){this.baseUrl=t.replace(/\/$/,"")+"/widgets"}async request(t,e={}){const n=Ct.getSessionToken(),s=Ct.getTenantId(),i=await fetch(`${this.baseUrl}${t}`,{...e,headers:{"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},...s?{"x-tenant-id":s}:{},...e.headers}});if(!i.ok)throw new Error(`API Error: ${i.status} ${i.statusText}`);return i.json()}async initialize(t){const e=await this.request("/initialize",{method:"POST",body:JSON.stringify(t)});if(!e.success)throw new Error("Failed to initialize widget");const n=e.data,s={...n.widget_config.settings};return delete s.primaryColor,delete s.widget_bubble_launcher_title,{...n,widget_config:{...n.widget_config,settings:s}}}async sendMessage(t){const e=await this.request("/send-message",{method:"POST",body:JSON.stringify(t)});if(!e.success)throw new Error(e.message||"Failed to send message");return e}async getMessages(t,e){const n=await this.request(`/${t}/get-messages/${e}`);if(!n.success)throw new Error("Failed to fetch messages");return n.data}async uploadFile(t){const e=Ct.getSessionToken(),n=Ct.getTenantId(),s=new FormData;s.append("file",t);const i=await fetch(`${this.baseUrl}/upload`,{method:"POST",headers:{...e?{Authorization:`Bearer ${e}`}:{},...n?{"x-tenant-id":n}:{}},body:s});if(!i.ok){const t=await i.json().catch(()=>({}));throw new Error(t.message||`Upload failed: ${i.status}`)}const r=await i.json();if(!r.success)throw new Error(r.message||"Upload failed");return r.data}},St=Object.create(null);St.open="0",St.close="1",St.ping="2",St.pong="3",St.message="4",St.upgrade="5",St.noop="6";const Et=Object.create(null);Object.keys(St).forEach(t=>{Et[St[t]]=t});const At={type:"error",data:"parser error"},Ot="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),xt="function"==typeof ArrayBuffer,Nt=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,Rt=({type:t,data:e},n,s)=>Ot&&e instanceof Blob?n?s(e):It(e,s):xt&&(e instanceof ArrayBuffer||Nt(e))?n?s(e):It(new Blob([e]),s):s(St[t]+(e||"")),It=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function Bt(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let Dt;const Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ft="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let on=0;on<64;on++)Ft[Lt.charCodeAt(on)]=on;const Mt="function"==typeof ArrayBuffer,Ut=(t,e)=>{if("string"!=typeof t)return{type:"message",data:Pt(t,e)};const n=t.charAt(0);if("b"===n)return{type:"message",data:jt(t.substring(1),e)};return Et[n]?t.length>1?{type:Et[n],data:t.substring(1)}:{type:Et[n]}:At},jt=(t,e)=>{if(Mt){const n=(t=>{let e,n,s,i,r,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const l=new ArrayBuffer(o),h=new Uint8Array(l);for(e=0;e<a;e+=4)n=Ft[t.charCodeAt(e)],s=Ft[t.charCodeAt(e+1)],i=Ft[t.charCodeAt(e+2)],r=Ft[t.charCodeAt(e+3)],h[c++]=n<<2|s>>4,h[c++]=(15&s)<<4|i>>2,h[c++]=(3&i)<<6|63&r;return l})(t);return Pt(n,e)}return{base64:!0,data:t}},Pt=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,qt=String.fromCharCode(30);function $t(){return new TransformStream({transform(t,e){!function(t,e){Ot&&t.data instanceof Blob?t.data.arrayBuffer().then(Bt).then(e):xt&&(t.data instanceof ArrayBuffer||Nt(t.data))?e(Bt(t.data)):Rt(t,!1,t=>{Dt||(Dt=new TextEncoder),e(Dt.encode(t))})}(t,n=>{const s=n.length;let i;if(s<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,s);else if(s<65536){i=new Uint8Array(3);const t=new DataView(i.buffer);t.setUint8(0,126),t.setUint16(1,s)}else{i=new Uint8Array(9);const t=new DataView(i.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(s))}t.data&&"string"!=typeof t.data&&(i[0]|=128),e.enqueue(i),e.enqueue(n)})}})}let Ht;function zt(t){return t.reduce((t,e)=>t+e.length,0)}function Vt(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let s=0;for(let i=0;i<e;i++)n[i]=t[0][s++],s===t[0].length&&(t.shift(),s=0);return t.length&&s<t[0].length&&(t[0]=t[0].slice(s)),n}function Wt(t){if(t)return function(t){for(var e in Wt.prototype)t[e]=Wt.prototype[e];return t}(t)}Wt.prototype.on=Wt.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},Wt.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},Wt.prototype.off=Wt.prototype.removeListener=Wt.prototype.removeAllListeners=Wt.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<s.length;i++)if((n=s[i])===e||n.fn===e){s.splice(i,1);break}return 0===s.length&&delete this._callbacks["$"+t],this},Wt.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if(n){s=0;for(var i=(n=n.slice(0)).length;s<i;++s)n[s].apply(this,e)}return this},Wt.prototype.emitReserved=Wt.prototype.emit,Wt.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},Wt.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Kt="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),Jt="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function Yt(t,...e){return e.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{})}const Xt=Jt.setTimeout,Qt=Jt.clearTimeout;function Gt(t,e){e.useNativeTimers?(t.setTimeoutFn=Xt.bind(Jt),t.clearTimeoutFn=Qt.bind(Jt)):(t.setTimeoutFn=Jt.setTimeout.bind(Jt),t.clearTimeoutFn=Jt.clearTimeout.bind(Jt))}function Zt(t){return"string"==typeof t?function(t){let e=0,n=0;for(let s=0,i=t.length;s<i;s++)e=t.charCodeAt(s),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(s++,n+=4);return n}(t):Math.ceil(1.33*(t.byteLength||t.size))}function te(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class ee extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class ne extends Wt{constructor(t){super(),this.writable=!1,Gt(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new ee(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=Ut(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class se extends ne{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",function(){--t||e()})),this.writable||(t++,this.once("drain",function(){--t||e()}))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(qt),s=[];for(let i=0;i<n.length;i++){const t=Ut(n[i],e);if(s.push(t),"error"===t.type)break}return s})(t,this.socket.binaryType).forEach(t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)}),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,s=new Array(n);let i=0;t.forEach((t,r)=>{Rt(t,!1,t=>{s[r]=t,++i===n&&e(s.join(qt))})})})(t,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=te()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let ie=!1;try{ie="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(rn){}const re=ie;function oe(){}class ae extends se{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",(t,e)=>{this.onError("xhr post error",t,e)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(t,e)=>{this.onError("xhr poll error",t,e)}),this.pollXhr=t}}class ce extends Wt{constructor(t,e,n){super(),this.createRequest=t,Gt(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=Yt(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(s){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(s){}try{n.setRequestHeader("Accept","*/*")}catch(s){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn(()=>{this._onError("number"==typeof n.status?n.status:0)},0))},n.send(this._data)}catch(s){return void this.setTimeoutFn(()=>{this._onError(s)},0)}"undefined"!=typeof document&&(this._index=ce.requestsCount++,ce.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=oe,t)try{this._xhr.abort()}catch(e){}"undefined"!=typeof document&&delete ce.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}if(ce.requestsCount=0,ce.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",le);else if("function"==typeof addEventListener){addEventListener("onpagehide"in Jt?"pagehide":"unload",le,!1)}function le(){for(let t in ce.requests)ce.requests.hasOwnProperty(t)&&ce.requests[t].abort()}const he=function(){const t=ue({xdomain:!1});return t&&null!==t.responseType}();function ue(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||re))return new XMLHttpRequest}catch(n){}if(!e)try{return new(Jt[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(n){}}const de="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class pe extends ne{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=de?{}:Yt(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(rn){return this.emitReserved("error",rn)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;Rt(n,this.supportsBinary,t=>{try{this.doWrite(n,t)}catch(e){}s&&Kt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=te()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const _e=Jt.WebSocket||Jt.MozWebSocket;const fe={websocket:class extends pe{createSocket(t,e,n){return de?new _e(t,e,n):e?new _e(t,e):new _e(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends ne{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(rn){return this.emitReserved("error",rn)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const e=function(t,e){Ht||(Ht=new TextDecoder);const n=[];let s=0,i=-1,r=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===s){if(zt(n)<1)break;const t=Vt(n,1);r=!(128&~t[0]),i=127&t[0],s=i<126?3:126===i?1:2}else if(1===s){if(zt(n)<2)break;const t=Vt(n,2);i=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),s=3}else if(2===s){if(zt(n)<8)break;const t=Vt(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),r=e.getUint32(0);if(r>Math.pow(2,21)-1){a.enqueue(At);break}i=r*Math.pow(2,32)+e.getUint32(4),s=3}else{if(zt(n)<i)break;const t=Vt(n,i);a.enqueue(Ut(r?t:Ht.decode(t),e)),s=0}if(0===i||i>t){a.enqueue(At);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),s=$t();s.readable.pipeTo(t.writable),this._writer=s.writable.getWriter();const i=()=>{n.read().then(({done:t,value:e})=>{t||(this.onPacket(e),i())}).catch(t=>{})};i();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;this._writer.write(n).then(()=>{s&&Kt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends ae{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=he&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new ce(ue,this.uri(),t)}}},ge=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ye=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function me(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),s=t.indexOf("]");-1!=n&&-1!=s&&(t=t.substring(0,n)+t.substring(n,s).replace(/:/g,";")+t.substring(s,t.length));let i=ge.exec(t||""),r={},o=14;for(;o--;)r[ye[o]]=i[o]||"";return-1!=n&&-1!=s&&(r.source=e,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,e){const n=/\/{2,9}/g,s=e.replace(n,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||s.splice(0,1);"/"==e.slice(-1)&&s.splice(s.length-1,1);return s}(0,r.path),r.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,s){e&&(n[e]=s)}),n}(0,r.query),r}const ve="function"==typeof addEventListener&&"function"==typeof removeEventListener,be=[];ve&&addEventListener("offline",()=>{be.forEach(t=>t())},!1);class we extends Wt{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=me(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=me(e.host).host);Gt(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach(t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let s=0,i=n.length;s<i;s++){let t=n[s].split("=");e[decodeURIComponent(t[0])]=decodeURIComponent(t[1])}return e}(this.opts.query)),ve&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},be.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);const t=this.opts.rememberUpgrade&&we.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",we.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const n=this.writeBuffer[e].data;if(n&&(t+=Zt(n)),e>0&&t>this._maxPayload)return this.writeBuffer.slice(0,e);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Kt(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,s){if("function"==typeof e&&(s=e,e=void 0),"function"==typeof n&&(s=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const i={type:t,data:e,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():t()}):this.upgrading?n():t()),this}_onError(t){if(we.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ve&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=be.indexOf(this._offlineEventListener);-1!==t&&be.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}we.protocol=4;class ke extends we{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;we.priorWebsocketSuccess=!1;const s=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;we.priorWebsocketSuccess="websocket"===e.name,this.transport.pause(()=>{n||"closed"!==this.readyState&&(l(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())})}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}}))};function i(){n||(n=!0,l(),e.close(),e=null)}const r=t=>{const n=new Error("probe error: "+t);n.transport=e.name,i(),this.emitReserved("upgradeError",n)};function o(){r("transport closed")}function a(){r("socket closed")}function c(t){e&&t.name!==e.name&&i()}const l=()=>{e.removeListener("open",s),e.removeListener("error",r),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",s),e.once("error",r),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn(()=>{n||e.open()},200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}let Ce=class extends ke{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map(t=>fe[t]).filter(t=>!!t)),super(t,n)}};const Te="function"==typeof ArrayBuffer,Se=Object.prototype.toString,Ee="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Se.call(Blob),Ae="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===Se.call(File);function Oe(t){return Te&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||Ee&&t instanceof Blob||Ae&&t instanceof File}function xe(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(xe(t[e]))return!0;return!1}if(Oe(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return xe(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&xe(t[n]))return!0;return!1}function Ne(t){const e=[],n=t.data,s=t;return s.data=Re(n,e),s.attachments=e.length,{packet:s,buffers:e}}function Re(t,e){if(!t)return t;if(Oe(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let s=0;s<t.length;s++)n[s]=Re(t[s],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=Re(t[s],e));return n}return t}function Ie(t,e){return t.data=Be(t.data,e),delete t.attachments,t}function Be(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=Be(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=Be(t[n],e));return t}const De=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Le,Fe;(Fe=Le||(Le={}))[Fe.CONNECT=0]="CONNECT",Fe[Fe.DISCONNECT=1]="DISCONNECT",Fe[Fe.EVENT=2]="EVENT",Fe[Fe.ACK=3]="ACK",Fe[Fe.CONNECT_ERROR=4]="CONNECT_ERROR",Fe[Fe.BINARY_EVENT=5]="BINARY_EVENT",Fe[Fe.BINARY_ACK=6]="BINARY_ACK";class Me extends Wt{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===Le.BINARY_EVENT;n||e.type===Le.BINARY_ACK?(e.type=n?Le.EVENT:Le.ACK,this.reconstructor=new Ue(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!Oe(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===Le[n.type])throw new Error("unknown packet type "+n.type);if(n.type===Le.BINARY_EVENT||n.type===Le.BINARY_ACK){const s=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const i=t.substring(s,e);if(i!=Number(i)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(i)}if("/"===t.charAt(e+1)){const s=e+1;for(;++e;){if(","===t.charAt(e))break;if(e===t.length)break}n.nsp=t.substring(s,e)}else n.nsp="/";const s=t.charAt(e+1);if(""!==s&&Number(s)==s){const s=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(s,e+1))}if(t.charAt(++e)){const s=this.tryParse(t.substr(e));if(!Me.isPayloadValid(n.type,s))throw new Error("invalid payload");n.data=s}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(e){return!1}}static isPayloadValid(t,e){switch(t){case Le.CONNECT:return je(e);case Le.DISCONNECT:return void 0===e;case Le.CONNECT_ERROR:return"string"==typeof e||je(e);case Le.EVENT:case Le.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===De.indexOf(e[0]));case Le.ACK:case Le.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Ue{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=Ie(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function je(t){return"[object Object]"===Object.prototype.toString.call(t)}const Pe=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Me,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Le.EVENT&&t.type!==Le.ACK||!xe(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Le.EVENT?Le.BINARY_EVENT:Le.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==Le.BINARY_EVENT&&t.type!==Le.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=Ne(t),n=this.encodeAsString(e.packet),s=e.buffers;return s.unshift(n),s}},get PacketType(){return Le}},Symbol.toStringTag,{value:"Module"}));function qe(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const $e=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class He extends Wt{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[qe(t,"open",this.onopen.bind(this)),qe(t,"packet",this.onpacket.bind(this)),qe(t,"error",this.onerror.bind(this)),qe(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,s,i;if($e.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const r={type:Le.EVENT,data:e,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),r.id=t}const o=null===(s=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===s?void 0:s.writable,a=this.connected&&!(null===(i=this.io.engine)||void 0===i?void 0:i._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,e){var n;const s=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===s)return void(this.acks[t]=e);const i=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))},s),r=(...t)=>{this.io.clearTimeoutFn(i),e.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...e){return new Promise((n,s)=>{const i=(t,e)=>t?s(t):n(e);i.withError=!0,e.push(i),this.emit(t,...e)})}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((t,...s)=>{this._queue[0];return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...s)),n.pending=!1,this._drainQueue()}),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Le.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(e=>String(e.id)===t)){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Le.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Le.EVENT:case Le.BINARY_EVENT:this.onevent(t);break;case Le.ACK:case Le.BINARY_ACK:this.onack(t);break;case Le.DISCONNECT:this.ondisconnect();break;case Le.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...s){n||(n=!0,e.packet({type:Le.ACK,id:t,data:s}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Le.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function ze(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}ze.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},ze.prototype.reset=function(){this.attempts=0},ze.prototype.setMin=function(t){this.ms=t},ze.prototype.setMax=function(t){this.max=t},ze.prototype.setJitter=function(t){this.jitter=t};class Ve extends Wt{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,Gt(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new ze({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const s=e.parser||Pe;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new Ce(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const s=qe(e,"open",function(){n.onopen(),t&&t()}),i=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},r=qe(e,"error",i);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn(()=>{s(),i(new Error("timeout")),e.close()},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(s),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(qe(t,"ping",this.onping.bind(this)),qe(t,"data",this.ondata.bind(this)),qe(t,"error",this.onerror.bind(this)),qe(t,"close",this.onclose.bind(this)),qe(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(e){this.onclose("parse error",e)}}ondecoded(t){Kt(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new He(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const n of e){if(this.nsps[n].active)return}this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open(e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()}))},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const We={};function Ke(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let s=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),s=me(t)),s.port||(/^(http|ws)$/.test(s.protocol)?s.port="80":/^(http|ws)s$/.test(s.protocol)&&(s.port="443")),s.path=s.path||"/";const i=-1!==s.host.indexOf(":")?"["+s.host+"]":s.host;return s.id=s.protocol+"://"+i+":"+s.port+e,s.href=s.protocol+"://"+i+(n&&n.port===s.port?"":":"+s.port),s}(t,(e=e||{}).path||"/socket.io"),s=n.source,i=n.id,r=n.path,o=We[i]&&r in We[i].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new Ve(s,e):(We[i]||(We[i]=new Ve(s,e)),a=We[i]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(Ke,{Manager:Ve,Socket:He,io:Ke,connect:Ke});const Je=new class{constructor(){this.socket=null,this.wsUrl="",this.pendingJoinConversationId=null,this.handlers={message:new Set,typing:new Set,disconnect:new Set}}configure(t){this.wsUrl=t}connect(){var t;if(null==(t=this.socket)?void 0:t.connected)return void this._joinStoredConversation();const e=Ct.getSessionToken();e&&(this.socket=Ke(this.wsUrl,{transports:["websocket","polling"],timeout:2e4,reconnection:!0,reconnectionDelay:2e3,reconnectionDelayMax:1e4,reconnectionAttempts:10,auth:{token:e,type:"widget"}}),this.socket.on("connect",()=>{this._joinStoredConversation()}),this.socket.on("disconnect",t=>{this.handlers.disconnect.forEach(e=>e(t))}),this.socket.on("reconnect",()=>{this._joinStoredConversation()}),this.socket.on(wt,t=>{this._handleIncomingMessage(t)}),this.socket.on(mt,t=>{this._handleIncomingMessage(t)}),this.socket.on(vt,t=>{this.handlers.typing.forEach(e=>e(t))}),this.socket.on("typing",t=>{this.handlers.typing.forEach(e=>e({isTyping:(null==t?void 0:t.isTyping)??!1}))}),this.socket.on(bt,()=>{this.disconnect(),Ct.clearAll()}))}_joinStoredConversation(){const t=this.pendingJoinConversationId||Ct.getConversationId();t&&this.joinConversation(t)}_handleIncomingMessage(t){var e;const n=null==(e=null==t?void 0:t.data)?void 0:e.messages;if(n&&"outgoing"===n.message_type){const t={id:n.id,content:n.content,content_type:n.content_type,sender_type:"user",message_type:n.message_type,attachments:n.attachments,sent_at:n.sent_at,quote_id:n.quote_id};this.handlers.message.forEach(e=>e(t))}}joinConversation(t){var e;this.pendingJoinConversationId=t,(null==(e=this.socket)?void 0:e.connected)&&this.socket.emit(kt,t)}leaveConversation(t){var e;(null==(e=this.socket)?void 0:e.connected)&&this.socket.emit("leave_receive_message",t)}emitTyping(t,e){var n;null==(n=this.socket)||n.emit("typing",{conversationId:t,isTyping:e})}disconnect(){this.socket&&(this.socket.removeAllListeners(),this.socket.disconnect(),this.socket=null)}get connected(){var t;return(null==(t=this.socket)?void 0:t.connected)??!1}onMessage(t){return this.handlers.message.add(t),()=>{this.handlers.message.delete(t)}}onTyping(t){return this.handlers.typing.add(t),()=>{this.handlers.typing.delete(t)}}onDisconnect(t){return this.handlers.disconnect.add(t),()=>{this.handlers.disconnect.delete(t)}}},Ye=["😀","😃","😄","😁","😅","😂","🤣","😊","😇","🙂","😉","😌","😍","🥰","😘","😗","😙","😚","😋","😛","😝","😜","🤪","🤨","🧐","🤓","😎","🤩","🥳","😏","😒","😞","😔","😟","😕","🙁","☹️","😣","😖","😫","😩","🥺","😢","😭","😤","😠","😡","🤬","🤯","😳","👍","👎","👏","🙌","👐","🤲","🤝","🙏","❤️","💔"],Xe=({onSelect:t})=>P("div",{class:"cdk-emoji-picker",children:P("div",{class:"cdk-emoji-grid",children:Ye.map(e=>P("button",{type:"button",class:"cdk-emoji-btn",onClick:n=>{n.preventDefault(),t(e)},children:e},e))})}),Qe=({widgetId:t,apiUrl:e,wsUrl:n})=>{var s;const[i,r]=et(!1),[o,a]=et(!1),[c,l]=et(null),[h,u]=et([]),[d,p]=et(""),[_,f]=et(!1),[g,y]=et(!1),[m,v]=et(0),[b,w]=et(!1),[k,C]=et(null),[T,S]=et(new Set),E=st(null),A=st(null),O=st(null),x=st(!1),N=st(null),R=st(null),I=null==c?void 0:c.settings,B="compact"===(null==(s=null==c?void 0:c.settings)?void 0:s.widget_bubble_type),D="data:image/svg+xml,%3csvg%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20x='0px'%20y='0px'%20width='100%25'%20viewBox='0%200%20500%20500'%20enable-background='new%200%200%20500%20500'%20xml:space='preserve'%3e%3cpath%20fill='%239BBDFF'%20opacity='1.000000'%20stroke='none'%20d='%20M140.252762,54.245255%20C161.199081,40.689423%20183.823654,31.758812%20207.401901,25.441967%20C218.162231,22.559170%20229.443436,21.474543%20240.552277,20.085209%20C249.344025,18.985662%20258.256256,17.894676%20267.074524,18.157549%20C286.327698,18.731489%20305.418152,20.832294%20324.238861,25.508360%20C342.365295,30.011917%20359.974152,35.993649%20376.050507,45.254520%20C390.599274,53.635445%20404.269012,63.634136%20417.842194,73.580231%20C425.236206,78.998398%20431.905945,85.508339%20438.407745,92.019745%20C453.031647,106.665215%20464.399719,123.674751%20471.380707,143.132553%20C474.512604,151.862045%20475.486511,161.423309%20476.933563,170.686203%20C479.086426,184.467300%20476.760651,197.912125%20473.042145,211.196777%20C469.138641,225.142105%20462.030579,237.334549%20452.987610,248.498154%20C451.031036,250.913574%20449.011749,253.278244%20447.222992,255.424408%20C452.578979,262.901031%20458.419708,269.942169%20463.016998,277.718384%20C470.989227,291.203278%20475.878845,305.659546%20477.228210,321.619019%20C479.005951,342.644440%20473.921509,361.978516%20464.654266,380.186249%20C459.562073,390.191101%20452.179291,399.112488%20445.241089,408.066589%20C440.601715,414.053833%20435.103363,419.418091%20429.681763,424.748230%20C416.609558,437.599976%20402.080109,448.743652%20385.938477,457.294098%20C371.010132,465.201843%20355.611420,472.498718%20339.783081,478.338623%20C328.065460,482.661804%20315.348694,484.320099%20303.036499,486.977600%20C287.606628,490.308044%20271.887787,490.742279%20256.265381,489.821228%20C242.122437,488.987457%20227.914429,487.443146%20214.011795,484.772064%20C192.990158,480.733246%20173.204575,472.657898%20154.339157,462.634796%20C137.535614,453.707153%20121.945580,443.004517%20107.576645,430.333160%20C92.684273,417.200195%2079.884979,402.420380%2068.669403,386.181244%20C53.099525,363.637512%2042.290356,338.815369%2035.383755,312.427704%20C32.518871,301.481964%2031.045507,290.045258%2030.174398,278.736725%20C29.106480,264.873260%2028.579288,250.874588%2029.233473,237.001099%20C29.774836,225.520233%2031.840506,214.026443%2034.178226,202.734497%20C37.918365,184.668381%2044.283577,167.369522%2052.657726,150.958160%20C61.209385,134.198929%2070.957283,118.114639%2083.548431,103.955528%20C88.771812,98.081696%2093.625313,91.827011%2099.264633,86.385597%20C111.716057,74.371162%20125.021523,63.355614%20140.252762,54.245255%20M108.120209,148.666534%20C104.447884,154.809601%20100.510056,160.811142%2097.147957,167.119553%20C80.106979,199.093979%2073.178864,233.161484%2075.861305,269.322540%20C77.930298,297.213928%2085.955261,323.176819%2099.716423,347.430084%20C117.004189,377.898743%20141.297302,401.322479%20171.721924,418.448242%20C213.823135,442.146759%20258.649567,449.251038%20305.811920,438.849579%20C349.532410,429.207184%20386.088409,407.243866%20414.248810,372.145020%20C425.279663,358.396271%20432.706299,342.711517%20430.605408,324.703369%20C427.819458,300.823303%20413.933746,284.421753%20392.071655,275.197144%20C371.312012,266.437622%20352.093231,271.254883%20334.967804,284.643890%20C327.676544,290.344360%20321.794983,297.812286%20314.961823,304.141266%20C296.444458,321.292358%20274.844513,328.971405%20249.755310,323.359222%20C214.214554,315.409180%20191.208771,282.394226%20196.043884,245.608185%20C199.801422,217.020401%20215.618057,196.903122%20243.128448,187.776154%20C269.608887,178.990906%20293.779999,184.648239%20314.353760,203.723877%20C320.200836,209.145187%20325.443268,215.245255%20330.727783,221.241318%20C342.579987,234.689407%20357.343689,240.364700%20375.198914,239.298920%20C415.211884,236.910507%20441.233917,197.116104%20427.265320,159.530792%20C420.437622,141.159485%20408.230408,126.889565%20393.728912,114.287544%20C342.808899,70.037331%20284.217865,55.052128%20218.855057,71.201500%20C172.727554,82.598366%20136.025131,109.127724%20108.120209,148.666534%20M235.598419,290.227814%20C237.346329,289.684235%20239.420258,289.567719%20240.786758,288.524506%20C247.355972,283.509674%20254.340652,285.013580%20261.608154,286.313660%20C275.517670,288.801910%20288.528015,285.788727%20300.120270,277.859833%20C318.746368,265.119873%20319.992035,242.878952%20303.485718,228.103714%20C287.071564,213.410950%20253.270721,212.606583%20235.945602,226.738678%20C223.729797,236.703125%20219.690872,250.082748%20225.986404,262.513824%20C228.339157,267.159485%20231.950302,271.310974%20235.584763,275.117737%20C238.336823,278.000244%20238.381363,280.308899%20235.750916,282.707642%20C233.435349,284.819214%20230.718979,286.491028%20228.181503,288.359650%20C226.971115,289.250977%20225.765106,290.148254%20224.557114,291.042816%20C224.742432,291.423157%20224.927750,291.803497%20225.113068,292.183807%20C228.350769,291.614594%20231.588455,291.045349%20235.598419,290.227814%20z'/%3e%3cpath%20fill='%230155FF'%20opacity='1.000000'%20stroke='none'%20d='%20M108.322021,148.367065%20C136.025131,109.127724%20172.727554,82.598366%20218.855057,71.201500%20C284.217865,55.052128%20342.808899,70.037331%20393.728912,114.287544%20C408.230408,126.889565%20420.437622,141.159485%20427.265320,159.530792%20C441.233917,197.116104%20415.211884,236.910507%20375.198914,239.298920%20C357.343689,240.364700%20342.579987,234.689407%20330.727783,221.241318%20C325.443268,215.245255%20320.200836,209.145187%20314.353760,203.723877%20C293.779999,184.648239%20269.608887,178.990906%20243.128448,187.776154%20C215.618057,196.903122%20199.801422,217.020401%20196.043884,245.608185%20C191.208771,282.394226%20214.214554,315.409180%20249.755310,323.359222%20C274.844513,328.971405%20296.444458,321.292358%20314.961823,304.141266%20C321.794983,297.812286%20327.676544,290.344360%20334.967804,284.643890%20C352.093231,271.254883%20371.312012,266.437622%20392.071655,275.197144%20C413.933746,284.421753%20427.819458,300.823303%20430.605408,324.703369%20C432.706299,342.711517%20425.279663,358.396271%20414.248810,372.145020%20C386.088409,407.243866%20349.532410,429.207184%20305.811920,438.849579%20C258.649567,449.251038%20213.823135,442.146759%20171.721924,418.448242%20C141.297302,401.322479%20117.004189,377.898743%2099.716423,347.430084%20C85.955261,323.176819%2077.930298,297.213928%2075.861305,269.322540%20C73.178864,233.161484%2080.106979,199.093979%2097.147957,167.119553%20C100.510056,160.811142%20104.447884,154.809601%20108.322021,148.367065%20M124.732277,348.758545%20C137.075897,367.711823%20152.421600,383.870148%20171.464478,396.022980%20C216.863174,424.995544%20265.766296,431.981781%20317.353333,416.653839%20C328.825653,413.245056%20339.519928,406.953430%20350.211639,401.306030%20C354.789398,398.888062%20355.795074,393.890808%20353.986969,390.580719%20C351.664520,386.329071%20346.933105,384.648438%20341.863373,386.510406%20C338.743591,387.656189%20335.718903,389.076111%20332.698029,390.473511%20C313.928802,399.155762%20294.305084,404.978973%20273.621399,405.807190%20C233.120285,407.428894%20197.177872,395.239075%20166.501266,368.445831%20C119.026039,326.980469%20102.398308,258.873688%20125.774902,200.401932%20C129.581100,190.881516%20135.008072,181.997131%20139.853516,172.908127%20C143.407333,166.241943%20141.580566,160.515106%20134.994873,158.541763%20C130.428177,157.173386%20125.811470,159.657990%20121.864021,166.289673%20C106.951569,191.342392%2098.216049,218.374680%2097.119453,247.585983%20C95.757301,283.871216%20104.612198,317.514099%20124.732277,348.758545%20M231.371399,150.805130%20C223.340347,153.234314%20215.590225,156.229111%20209.735519,162.594116%20C206.951294,165.621002%20206.433975,169.058380%20208.892334,172.605530%20C211.312332,176.097321%20214.422379,177.869446%20218.716782,176.167175%20C221.494781,175.065994%20224.297882,173.993149%20226.971573,172.669037%20C258.672729,156.969666%20298.586456,161.985825%20325.048859,185.445374%20C332.877136,192.385330%20340.022064,200.109787%20347.323059,207.627243%20C355.346741,215.888763%20364.878937,220.104919%20376.462219,218.946335%20C385.279724,218.064377%20393.504395,215.629944%20399.346313,208.332779%20C402.498993,204.394745%20402.417938,199.530991%20399.436829,195.925613%20C396.607666,192.504013%20391.521362,191.729782%20387.168457,194.133835%20C386.009613,194.773865%20384.983093,195.649841%20383.876251,196.388168%20C375.607117,201.904083%20366.485657,201.373352%20359.141144,194.697296%20C356.446014,192.247452%20354.091125,189.406265%20351.703400,186.638062%20C339.709167,172.732666%20326.008118,161.082138%20308.883057,153.885254%20C283.708405,143.305466%20258.067749,143.584015%20231.371399,150.805130%20M154.652512,133.691925%20C147.558197,132.693588%20142.721359,135.941010%20141.486389,142.531601%20C140.414276,148.253052%20143.815903,153.179947%20149.896072,154.712143%20C155.230484,156.056396%20160.184494,153.312469%20162.133408,147.934067%20C164.276215,142.020569%20161.953751,137.177597%20154.652512,133.691925%20z'/%3e%3cpath%20fill='%23FEFFFF'%20opacity='1.000000'%20stroke='none'%20d='%20M235.212280,290.351990%20C231.588455,291.045349%20228.350769,291.614594%20225.113068,292.183807%20C224.927750,291.803497%20224.742432,291.423157%20224.557114,291.042816%20C225.765106,290.148254%20226.971115,289.250977%20228.181503,288.359650%20C230.718979,286.491028%20233.435349,284.819214%20235.750916,282.707642%20C238.381363,280.308899%20238.336823,278.000244%20235.584763,275.117737%20C231.950302,271.310974%20228.339157,267.159485%20225.986404,262.513824%20C219.690872,250.082748%20223.729797,236.703125%20235.945602,226.738678%20C253.270721,212.606583%20287.071564,213.410950%20303.485718,228.103714%20C319.992035,242.878952%20318.746368,265.119873%20300.120270,277.859833%20C288.528015,285.788727%20275.517670,288.801910%20261.608154,286.313660%20C254.340652,285.013580%20247.355972,283.509674%20240.786758,288.524506%20C239.420258,289.567719%20237.346329,289.684235%20235.212280,290.351990%20z'/%3e%3cpath%20fill='%2399BCFF'%20opacity='1.000000'%20stroke='none'%20d='%20M124.528618,348.458801%20C104.612198,317.514099%2095.757301,283.871216%2097.119453,247.585983%20C98.216049,218.374680%20106.951569,191.342392%20121.864021,166.289673%20C125.811470,159.657990%20130.428177,157.173386%20134.994873,158.541763%20C141.580566,160.515106%20143.407333,166.241943%20139.853516,172.908127%20C135.008072,181.997131%20129.581100,190.881516%20125.774902,200.401932%20C102.398308,258.873688%20119.026039,326.980469%20166.501266,368.445831%20C197.177872,395.239075%20233.120285,407.428894%20273.621399,405.807190%20C294.305084,404.978973%20313.928802,399.155762%20332.698029,390.473511%20C335.718903,389.076111%20338.743591,387.656189%20341.863373,386.510406%20C346.933105,384.648438%20351.664520,386.329071%20353.986969,390.580719%20C355.795074,393.890808%20354.789398,398.888062%20350.211639,401.306030%20C339.519928,406.953430%20328.825653,413.245056%20317.353333,416.653839%20C265.766296,431.981781%20216.863174,424.995544%20171.464478,396.022980%20C152.421600,383.870148%20137.075897,367.711823%20124.528618,348.458801%20z'/%3e%3cpath%20fill='%2399BCFF'%20opacity='1.000000'%20stroke='none'%20d='%20M231.751648,150.669800%20C258.067749,143.584015%20283.708405,143.305466%20308.883057,153.885254%20C326.008118,161.082138%20339.709167,172.732666%20351.703400,186.638062%20C354.091125,189.406265%20356.446014,192.247452%20359.141144,194.697296%20C366.485657,201.373352%20375.607117,201.904083%20383.876251,196.388168%20C384.983093,195.649841%20386.009613,194.773865%20387.168457,194.133835%20C391.521362,191.729782%20396.607666,192.504013%20399.436829,195.925613%20C402.417938,199.530991%20402.498993,204.394745%20399.346313,208.332779%20C393.504395,215.629944%20385.279724,218.064377%20376.462219,218.946335%20C364.878937,220.104919%20355.346741,215.888763%20347.323059,207.627243%20C340.022064,200.109787%20332.877136,192.385330%20325.048859,185.445374%20C298.586456,161.985825%20258.672729,156.969666%20226.971573,172.669037%20C224.297882,173.993149%20221.494781,175.065994%20218.716782,176.167175%20C214.422379,177.869446%20211.312332,176.097321%20208.892334,172.605530%20C206.433975,169.058380%20206.951294,165.621002%20209.735519,162.594116%20C215.590225,156.229111%20223.340347,153.234314%20231.751648,150.669800%20z'/%3e%3cpath%20fill='%2397BBFF'%20opacity='1.000000'%20stroke='none'%20d='%20M155.025177,133.790253%20C161.953751,137.177597%20164.276215,142.020569%20162.133408,147.934067%20C160.184494,153.312469%20155.230484,156.056396%20149.896072,154.712143%20C143.815903,153.179947%20140.414276,148.253052%20141.486389,142.531601%20C142.721359,135.941010%20147.558197,132.693588%20155.025177,133.790253%20z'/%3e%3c/svg%3e",L=rt(t=>{const e=(t||"").trim().toLowerCase();return{mon:"monday",tue:"tuesday",tues:"tuesday",wed:"wednesday",thu:"thursday",thur:"thursday",thurs:"thursday",fri:"friday",sat:"saturday",sun:"sunday","thứ 2":"monday","thu 2":"monday","thứ 3":"tuesday","thu 3":"tuesday","thứ 4":"wednesday","thu 4":"wednesday","thứ 5":"thursday","thu 5":"thursday","thứ 6":"friday","thu 6":"friday","thứ 7":"saturday","thu 7":"saturday","chủ nhật":"sunday","chu nhat":"sunday"}[e]||e},[]);nt(()=>{if(x.current||!t)return;x.current=!0,Tt.configure(e),Je.configure(n);return(async()=>{var e;try{let n=Ct.getVisitorId();n||(n=`visitor_${Math.random().toString(36).substring(2,15)}${Date.now().toString(36)}`,Ct.setVisitorId(n));const s=await Tt.initialize({widget_id:t,visitor_id:n,page_info:{url:window.location.href,title:document.title,referrer:document.referrer},browser_info:{userAgent:navigator.userAgent,language:navigator.language||"en",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,screen:`${screen.width}x${screen.height}`}});Ct.setSessionToken(s.session_token),Ct.setTenantId(s.tenant_id),Ct.setConversationId(s.conversation_id),l(s.widget_config),a(!0),(null==(e=s.widget_config.settings)?void 0:e.autoOpen)&&setTimeout(()=>r(!0),2e3),Je.connect();try{const e=await Tt.getMessages(t,s.conversation_id);u(e)}catch{}}catch{}})(),()=>{Je.disconnect()}},[t,e,n]),nt(()=>{if(!o)return;const t=Je.onMessage(t=>{u(e=>[...e,t]),i||v(t=>t+1),y(!1),R.current&&(window.clearTimeout(R.current),R.current=null)}),e=Je.onTyping(t=>{(null==t?void 0:t.isWidget)||(y(t.isTyping),R.current&&(window.clearTimeout(R.current),R.current=null),t.isTyping&&(R.current=window.setTimeout(()=>{y(!1),R.current=null},3e3)))});return()=>{t(),e()}},[o,i]),nt(()=>{var t;null==(t=A.current)||t.scrollIntoView({behavior:"smooth"})},[h,g]),nt(()=>{i&&setTimeout(()=>{var t;return null==(t=O.current)?void 0:t.focus()},300)},[i]);const F=rt(async()=>{var e,n,s;const i=d.trim();if(!i||_)return;f(!0),p("");const r=Ct.getConversationId();r&&(N.current&&(clearTimeout(N.current),N.current=null),Je.emitTyping(r,!1));const o=`temp_${Date.now()}`,a={id:o,content:i,sender_type:"contact",message_type:"incoming",sent_at:(new Date).toISOString()};u(t=>[...t,a]);if((()=>{if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return!1;const t=(()=>{const t=null==I?void 0:I.timezone;if(!t)return new Date;try{const e=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"long"}).formatToParts(new Date),n=t=>{var n;return(null==(n=e.find(e=>e.type===t))?void 0:n.value)||""};return{day:n("weekday"),hours:parseInt(n("hour")),minutes:parseInt(n("minute"))}}catch{const t=new Date;return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][t.getDay()],hours:t.getHours(),minutes:t.getMinutes()}}})(),e="object"==typeof t&&"day"in t?L(t.day):"",n=I.business_hours.find(t=>L(t.day)===e);if(!n||!n.enabled)return!0;const s=60*("object"==typeof t&&"hours"in t?t.hours:0)+("object"==typeof t&&"minutes"in t?t.minutes:0),[i,r]=n.startTime.split(":").map(Number),[o,a]=n.endTime.split(":").map(Number);return s<60*i+(r||0)||s>60*o+(a||0)})()){const t={id:`offline_${Date.now()}`,content:(null==I?void 0:I.offlineMessage)||gt("offlineMessage"),sender_type:"user",message_type:"outgoing",sent_at:(new Date).toISOString()};return u(e=>[...e,t]),void f(!1)}try{const r=Ct.getConversationId()||"",c=Ct.getVisitorId()||"",l=await Tt.sendMessage({conversation_id:r,widget_id:t,visitor_id:c,sender_name:c,message:i,message_type:"text"}),h=(null==(e=l.data)?void 0:e.conversation_id)||(null==(s=null==(n=l.data)?void 0:n.conversation)?void 0:s.id);h&&(Ct.setConversationId(h),Je.joinConversation(h)),u(t=>t.map(t=>{var e,n,s,r;return t.id===o?{id:(null==(e=l.data)?void 0:e.id)||o,content:(null==(n=l.data)?void 0:n.content)||i,sender_type:"contact",message_type:"incoming",attachments:null==(s=l.data)?void 0:s.attachments,sent_at:(null==(r=l.data)?void 0:r.sent_at)||a.sent_at}:t}))}catch{S(t=>new Set(t).add(o)),M(gt("sendFailedToast"))}finally{f(!1),setTimeout(()=>{O.current&&O.current.focus()},0)}},[d,_,t,I]),M=rt(t=>{C(t),E.current&&clearTimeout(E.current),E.current=window.setTimeout(()=>{C(null),E.current=null},4e3)},[]),U=rt(async e=>{var n,s,i;const r=h.find(t=>t.id===e);if(r){S(t=>{const n=new Set(t);return n.delete(e),n});try{const o=Ct.getConversationId()||"",a=Ct.getVisitorId()||"",c=await Tt.sendMessage({conversation_id:o,widget_id:t,visitor_id:a,sender_name:a,message:r.content,message_type:r.content_type||"text"}),l=(null==(n=c.data)?void 0:n.conversation_id)||(null==(i=null==(s=c.data)?void 0:s.conversation)?void 0:i.id);l&&(Ct.setConversationId(l),Je.joinConversation(l)),u(t=>t.map(t=>{var n,s,i,o;return t.id===e?{id:(null==(n=c.data)?void 0:n.id)||e,content:(null==(s=c.data)?void 0:s.content)||r.content,sender_type:"contact",message_type:"incoming",attachments:null==(i=c.data)?void 0:i.attachments,sent_at:(null==(o=c.data)?void 0:o.sent_at)||r.sent_at}:t}))}catch{S(t=>new Set(t).add(e)),M(gt("retryFailed"))}}},[h,t,M]),j=rt(t=>{if(O.current){const e=O.current.selectionStart,n=O.current.selectionEnd,s=d,i=s.substring(0,e)+t+s.substring(n);p(i),setTimeout(()=>{if(O.current){O.current.focus();const n=e+t.length;O.current.setSelectionRange(n,n)}},0)}else p(e=>e+t)},[d]),q=rt(async e=>{var n,s,i;const r=e.target;if(!r.files||0===r.files.length)return;const o=r.files[0];if(r.value="",o.size>10485760)return void alert(gt("fileTooLarge",{size:(o.size/1024/1024).toFixed(1)}));const a=`upload_${Date.now()}`,c=o.type.startsWith("image/"),l={id:a,content:c?"":`📎 ${gt("uploading",{name:o.name})}`,sender_type:"contact",message_type:"incoming",sent_at:(new Date).toISOString()};u(t=>[...t,l]);try{const e=await Tt.uploadFile(o),r=Ct.getConversationId()||"",h=Ct.getVisitorId()||"",d=await Tt.sendMessage({conversation_id:r,widget_id:t,visitor_id:h,sender_name:h,message:c?"":`📎 ${o.name}`,message_type:c?"image":"file",attachments:[e.url]}),p=(null==(n=d.data)?void 0:n.conversation_id)||(null==(i=null==(s=d.data)?void 0:s.conversation)?void 0:i.id);p&&(Ct.setConversationId(p),Je.joinConversation(p)),u(t=>t.map(t=>{var n,s,i;return t.id===a?{id:(null==(n=d.data)?void 0:n.id)||a,content:(null==(s=d.data)?void 0:s.content)||(c?"":`📎 ${o.name}`),sender_type:"contact",message_type:"incoming",attachments:[{id:a,name:o.name,size:o.size,type:o.type,url:e.url}],sent_at:(null==(i=d.data)?void 0:i.sent_at)||l.sent_at}:t}))}catch(rn){u(t=>t.filter(t=>t.id!==a)),alert(gt("uploadFailed",{error:rn.message}))}finally{setTimeout(()=>{O.current&&O.current.focus()},0)}},[t]),$=rt(()=>{const t=null==I?void 0:I.timezone;if(!t)return new Date;try{const e=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,weekday:"long"}).formatToParts(new Date),n=t=>{var n;return(null==(n=e.find(e=>e.type===t))?void 0:n.value)||""};return{day:n("weekday"),hours:parseInt(n("hour")),minutes:parseInt(n("minute"))}}catch{const e=t.match(/UTC([+-])(\d{1,2})/i);if(e){const t="+"===e[1]?1:-1,n=parseInt(e[2]),s=new Date((new Date).getTime()+t*n*60*60*1e3);return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][s.getUTCDay()],hours:s.getUTCHours(),minutes:s.getUTCMinutes()}}const n=new Date;return{day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][n.getDay()],hours:n.getHours(),minutes:n.getMinutes()}}},[null==I?void 0:I.timezone]),H=it(()=>{if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return!0;const t=$(),e="object"==typeof t&&"day"in t?L(t.day):"",n=I.business_hours.find(t=>L(t.day)===e);if(!n||!n.enabled)return!1;const s=60*("object"==typeof t&&"hours"in t?t.hours:0)+("object"==typeof t&&"minutes"in t?t.minutes:0),[i,r]=n.startTime.split(":").map(Number),[o,a]=n.endTime.split(":").map(Number);return s>=60*i+(r||0)&&s<=60*o+(a||0)},[I,$,L]),z=it(()=>{var t;if(!(null==I?void 0:I.enable_business_hours)||!(null==I?void 0:I.business_hours))return null;const e=$(),n="object"==typeof e&&"day"in e?L(e.day):"",s=I.business_hours.find(t=>L(t.day)===n&&t.enabled),i=I.timezone||"";let r="";if(i)try{r=(null==(t=new Intl.DateTimeFormat("en-US",{timeZone:i,timeZoneName:"shortOffset"}).formatToParts(new Date).find(t=>"timeZoneName"===t.type))?void 0:t.value)||i}catch{r=i}return s?`${gt("serviceHours")} ${s.startTime}–${s.endTime}${r?` (${r})`:""}`:`${gt("closedToday")}${r?` (${r})`:""}`},[I,$,L]),V=(null==I?void 0:I.position)||"bottom-right",W=t=>{try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}};return o?P("div",{class:`cdk-widget cdk-${V} ${B?"cdk-widget-compact":""}`,children:[P("div",{class:"cdk-panel "+(i?"cdk-panel-open":""),children:[P("div",{class:"cdk-header",children:[(null==c?void 0:c.website_url)&&P("img",{src:`https://www.google.com/s2/favicons?domain=${c.website_url}&sz=64`,alt:"Avatar",class:"cdk-header-avatar",onError:t=>t.currentTarget.style.display="none"}),P("div",{class:"cdk-header-info",children:[P("div",{class:"cdk-header-title",children:(null==c?void 0:c.name)||gt("defaultTitle")}),P("div",{class:"cdk-header-subtitle "+(g?"cdk-subtitle-typing":""),children:g?gt("agentTyping"):z||(null==I?void 0:I.subtitle)||gt("defaultSubtitle")})]}),P("button",{class:"cdk-header-close",onClick:()=>r(!1),"aria-label":gt("close"),children:P("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor",children:P("path",{d:"M12 16.5a1 1 0 0 1-.7-.29l-6-6A1 1 0 0 1 6.7 8.79L12 14.09l5.3-5.3a1 1 0 1 1 1.41 1.42l-6 6A1 1 0 0 1 12 16.5z"})})})]}),P("div",{class:"cdk-messages",children:[0===h.length&&(H?null==I?void 0:I.welcomeMessage:(null==I?void 0:I.offlineMessage)||gt("offlineMessage"))&&P("div",{class:"cdk-msg cdk-msg-agent",children:P("div",{class:"cdk-msg-bubble cdk-msg-bubble-agent",children:H?null==I?void 0:I.welcomeMessage:(null==I?void 0:I.offlineMessage)||gt("offlineMessage")})}),h.map(t=>{const e=T.has(t.id);return P("div",{class:`cdk-msg ${"contact"===t.sender_type?"cdk-msg-visitor":"cdk-msg-agent"} ${e?"cdk-msg-failed":""}`,children:[P("div",{class:`cdk-msg-bubble ${"contact"===t.sender_type?"cdk-msg-bubble-visitor":"cdk-msg-bubble-agent"} ${e?"cdk-msg-bubble-failed":""}`,children:[t.attachments&&t.attachments.length>0&&P("div",{class:"cdk-msg-attachments",children:t.attachments.map(t=>{var e;return P("a",(null==(e=t.type)?void 0:e.startsWith("image/"))||/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url||t.name)?{href:t.url,target:"_blank",rel:"noopener noreferrer",class:"cdk-attachment-img-link",children:P("img",{src:t.url,alt:t.name,class:"cdk-attachment-img",loading:"lazy"})}:{href:t.url,target:"_blank",rel:"noopener noreferrer",class:"cdk-attachment-file",children:[P("span",{class:"cdk-attachment-icon",children:"📎"}),P("span",{class:"cdk-attachment-name",children:t.name}),t.size&&P("span",{class:"cdk-attachment-size",children:["(",(t.size/1024).toFixed(0),"KB)"]})]})})}),t.content&&P("span",{children:t.content})]}),P("div",{class:"cdk-msg-meta",children:P("div",e?{class:"cdk-msg-error",children:[P("span",{class:"cdk-msg-error-text",children:gt("sendFailed")}),P("button",{class:"cdk-msg-retry-btn",onClick:()=>U(t.id),title:gt("retry"),children:["⟳ ",gt("retry")]}),P("button",{class:"cdk-msg-delete-btn",onClick:()=>{u(e=>e.filter(e=>e.id!==t.id)),S(e=>{const n=new Set(e);return n.delete(t.id),n})},title:gt("delete"),children:"✕"})]}:{class:"cdk-msg-time",children:W(t.sent_at)})})]},t.id)}),g&&P("div",{class:"cdk-msg cdk-msg-agent",children:P("div",{class:"cdk-msg-bubble cdk-msg-bubble-agent cdk-typing",children:[P("span",{class:"cdk-dot"}),P("span",{class:"cdk-dot"}),P("span",{class:"cdk-dot"})]})}),P("div",{ref:A})]}),k&&P("div",{class:"cdk-toast cdk-toast-error",children:[P("span",{children:["⚠️ ",k]}),P("button",{class:"cdk-toast-close",onClick:()=>C(null),children:"✕"})]}),P("div",{class:"cdk-input-wrapper",children:[b&&P(Xe,{onSelect:j}),P("div",{class:"cdk-input-area",children:[P("div",{class:"cdk-input-box",children:[P("textarea",{ref:O,class:"cdk-input",placeholder:(null==I?void 0:I.placeholderText)||gt("defaultPlaceholder"),value:d,onInput:t=>{p(t.target.value);const e=Ct.getConversationId();e&&(N.current?clearTimeout(N.current):Je.emitTyping(e,!0),N.current=window.setTimeout(()=>{Je.emitTyping(e,!1),N.current=null},2500))},onKeyDown:t=>{"Enter"!==t.key||t.shiftKey||(t.preventDefault(),F())},rows:1,disabled:_}),P("button",{type:"button",class:"cdk-action-btn",onClick:()=>w(!b),title:gt("addEmoji"),children:P("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[P("circle",{cx:"12",cy:"12",r:"10"}),P("path",{d:"M8 14s1.5 2 4 2 4-2 4-2"}),P("line",{x1:"9",y1:"9",x2:"9.01",y2:"9"}),P("line",{x1:"15",y1:"9",x2:"15.01",y2:"9"})]})}),P("label",{class:"cdk-action-btn",title:gt("attachFile"),children:[P("input",{type:"file",style:{display:"none"},onChange:q}),P("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:P("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})]})]}),P("button",{class:"cdk-send-btn",onClick:F,disabled:!d.trim()||_,"aria-label":gt("send"),children:P("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:P("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]})]})]}),!(i&&B)&&P("button",{class:`cdk-toggle ${!i&&B?"cdk-toggle-compact":""} ${!i&&B&&V.includes("left")?"cdk-compact-left":""}`,onClick:()=>{r(t=>!t),i||(v(0),w(!1))},"aria-label":gt("toggleChat"),children:[!B&&i?P("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.25","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:P("path",{d:"M6 10l6 6 6-6"})}):B?P("div",{class:"cdk-compact-inner",children:[P("img",{src:D,alt:"","aria-hidden":"true",class:"cdk-compact-logo"}),P("span",{class:"cdk-compact-title",children:gt("chatWithUs")})]}):P("img",{src:D,alt:"","aria-hidden":"true",class:"cdk-toggle-logo"}),m>0&&!i&&P("span",{class:"cdk-badge",children:m>9?"9+":m})]})]}):null},Ge=new Map,Ze="https://api.chatdakenh.vn/api/v1",tn="https://ws.chatdakenh.vn";function en(t){const{widgetId:e,apiUrl:n=Ze,wsUrl:s=tn,lang:i}=t;if(i&&function(t){ft=_t[t]||pt}(i),Ge.has(e))return;const r=document.createElement("div");r.id=`cdk-widget-${e}`,r.setAttribute("data-cdk-widget","true"),document.body.appendChild(r),U(P(Qe,{widgetId:e,apiUrl:n,wsUrl:s}),r),Ge.set(e,{container:r,unmount:()=>{U(null,r),r.remove()}})}function nn(){document.querySelectorAll("script[data-widget-id]").forEach(t=>{const e=t.getAttribute("data-widget-id"),n=t.getAttribute("data-api-url")||Ze,s=t.getAttribute("data-ws-url")||tn,i=t.getAttribute("data-lang")||void 0;e&&en({widgetId:e,apiUrl:n,wsUrl:s,lang:i})})}const sn={init:en,destroy:function(t){if(t){const e=Ge.get(t);e&&(e.unmount(),Ge.delete(t))}else Ge.forEach(t=>t.unmount()),Ge.clear()},version:"1.0.0"};return"undefined"!=typeof window&&(window.ChatDaKenh=sn,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",nn):nn()),sn}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatdakenh/widget",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "ChatDaKenh embeddable chat widget for websites and applications.",
5
5
  "author": "ChatDaKenh Team <support@chatdakenh.vn>",
6
6
  "license": "UNLICENSED",