@subiz/widget-v4 4.0.53 → 4.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/cloudflare_worker.js +1 -1
  2. package/compiled_src/chatbox/Header.js +2 -0
  3. package/compiled_src/lib.js +9 -2
  4. package/compiled_src/notif/notif.js +7 -3
  5. package/compiled_src/store/store.js +7 -5
  6. package/compiled_src/util/campaign.js +7 -2
  7. package/dist/178.js +406 -0
  8. package/dist/17d938a5acb.178.js +1 -0
  9. package/dist/17d938a5acb.213.js +1 -0
  10. package/dist/17d938a5acb.362.js +1 -0
  11. package/dist/17d938a5acb.441.js +1 -0
  12. package/dist/17d938a5acb.605.js +1 -0
  13. package/dist/17d938a5acb.619.js +1 -0
  14. package/dist/17d938a5acb.678.js +1 -0
  15. package/dist/17d938a5acb.74.js +1 -0
  16. package/dist/17d938a5acb.782.js +1 -0
  17. package/dist/17d938a5acb.app.js +1 -0
  18. package/dist/17d938a5acb.index.html +37 -0
  19. package/dist/17d938a5acb.library.html +37 -0
  20. package/dist/17d938a5acb.library.js +1 -0
  21. package/dist/17d938a5acb.preview.html +759 -0
  22. package/dist/17d938a5acb.preview.js +1 -0
  23. package/dist/17d938a5acb.screenshoot.js +1 -0
  24. package/dist/213.js +3223 -0
  25. package/dist/362.js +107 -0
  26. package/dist/441.js +2706 -0
  27. package/dist/605.js +391 -0
  28. package/dist/619.js +777 -0
  29. package/dist/678.js +107 -0
  30. package/dist/74.js +4734 -0
  31. package/dist/782.js +107 -0
  32. package/dist/HASH +1 -1
  33. package/dist/assets/img/Facebook.64607ec.png +0 -0
  34. package/dist/assets/img/Zalo.6845707.png +0 -0
  35. package/dist/assets/img/award1a.1a58e10.png +0 -0
  36. package/dist/assets/img/award3a.3b74423.png +0 -0
  37. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  38. package/dist/assets/img/award5.39eb7ae.png +0 -0
  39. package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
  40. package/dist/assets/img/convos_empty.2353007.svg +72 -0
  41. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  42. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  43. package/dist/assets/img/done_gray.d7e8203.svg +4 -0
  44. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  45. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  46. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  47. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  48. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  49. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  50. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  51. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  52. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  53. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  54. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  55. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  56. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  57. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  58. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  59. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  60. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  61. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  62. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  63. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  64. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  65. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  66. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  67. package/dist/assets/img/empty.29bed2d.svg +23 -0
  68. package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
  69. package/dist/assets/img/external-link.90577cc.svg +1 -0
  70. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  71. package/dist/assets/img/image_default.be0698b.png +0 -0
  72. package/dist/assets/img/loading_static.8f403ae.svg +10 -0
  73. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  74. package/dist/assets/img/main-service2.9b99549.png +0 -0
  75. package/dist/assets/img/rating--average.1ea492c.svg +12 -0
  76. package/dist/assets/img/rating--great.e3d712e.svg +16 -0
  77. package/dist/assets/img/rating--poor.2938a25.svg +12 -0
  78. package/dist/assets/img/send.6db52a9.svg +3 -0
  79. package/dist/assets/img/subiz-mono.877e9f5.svg +3 -0
  80. package/dist/screenshoot.html +7 -0
  81. package/dist/screenshoot.js +5757 -0
  82. package/index.html +18 -2
  83. package/package.json +10 -9
  84. package/screenshoot.html +15 -0
  85. package/screenshoot.js +59 -0
  86. package/src/chatbox/Header.js +42 -34
  87. package/src/lib.js +8 -3
  88. package/src/notif/notif.js +37 -28
  89. package/src/plugin.js +11 -4
  90. package/src/store/store.js +9 -5
  91. package/src/util/campaign.js +16 -12
  92. package/take.js +36 -0
  93. package/webpack.dev.js +7 -0
  94. package/webpack.prod.js +12 -2
  95. package/webpack.screenshoot.js +20 -0
package/dist/74.js ADDED
@@ -0,0 +1,4734 @@
1
+ (self["webpackChunk_subiz_widget_v4"] = self["webpackChunk_subiz_widget_v4"] || []).push([[74],{
2
+
3
+ /***/ 1074:
4
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
5
+
6
+ "use strict";
7
+ // ESM COMPAT FLAG
8
+ __webpack_require__.r(__webpack_exports__);
9
+
10
+ // EXPORTS
11
+ __webpack_require__.d(__webpack_exports__, {
12
+ "default": () => (/* binding */ Main)
13
+ });
14
+
15
+ // EXTERNAL MODULE: ./src/util/index.js + 2 modules
16
+ var util = __webpack_require__(819);
17
+ // EXTERNAL MODULE: ./src/common.js
18
+ var common = __webpack_require__(2493);
19
+ // EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js
20
+ var preact_module = __webpack_require__(6400);
21
+ ;// CONCATENATED MODULE: ./src/chatbox/Emoji.js
22
+
23
+
24
+
25
+ class Emoji extends common/* Com */.M {
26
+ render() {
27
+ var emojiCode = this.props.emojiCode;
28
+ if (util/* default.size */.Z.size(emojiCode) < 3) return null;
29
+ var emojiText = emojiCode.replace(/:/g, '');
30
+ return (0,preact_module.h)("i", {
31
+ "data-tooltip": emojiCode,
32
+ class: `emoji emoji--${emojiText}`
33
+ });
34
+ }
35
+
36
+ }
37
+ ;// CONCATENATED MODULE: ./src/chatbox/ChatButton.js
38
+
39
+
40
+
41
+ var defaultBubble = __webpack_require__(6755);
42
+
43
+ let defaultAvatar = __webpack_require__(4761);
44
+
45
+
46
+
47
+ class ChatButton extends common/* Com */.M {
48
+ constructor(props) {
49
+ super(props);
50
+ this.setState({
51
+ opacity: 0,
52
+ previewEvent: {},
53
+ displayPreview: false
54
+ });
55
+ this.loadGreeting();
56
+ this.props.store.onUpdate(this, _ => this.forceUpdate());
57
+ this.props.store.onConvoEvent(this, ev => {
58
+ if (util/* default.get */.Z.get(ev, 'type') !== 'message_sent') return;
59
+ let bytype = util/* default.get */.Z.get(ev, 'by.type');
60
+ if (bytype !== 'system' && bytype !== 'agent') return;
61
+ let isquickreplies = false;
62
+ util/* default.map */.Z.map(util/* default.get */.Z.get(ev, 'data.message.attachments', []), att => {
63
+ if (!att) return;
64
+
65
+ if (att.type === 'quick_replies') {
66
+ isquickreplies = true;
67
+ }
68
+ });
69
+ if (isquickreplies) return;
70
+ this.setState({
71
+ displayPreview: true,
72
+ previewEvent: ev
73
+ });
74
+ });
75
+ }
76
+
77
+ fixMissingSetting(chatbox) {
78
+ chatbox = util/* default.cloneDeep */.Z.cloneDeep(chatbox);
79
+
80
+ if (util/* default.get */.Z.get(chatbox, 'desktop_button.background_image_url')) {
81
+ chatbox.desktop_button.background_image_url = this.props.store.replaceFileUrl(chatbox.desktop_button.background_image_url);
82
+ }
83
+
84
+ if (util/* default.get */.Z.get(chatbox, 'desktop_button.background_mask_url')) {
85
+ chatbox.desktop_button.background_mask_url = this.props.store.replaceFileUrl(chatbox.desktop_button.background_mask_url);
86
+ }
87
+
88
+ if (util/* default.get */.Z.get(chatbox, 'mobile_button.background_image_url')) {
89
+ chatbox.mobile_button.background_image_url = this.props.store.replaceFileUrl(chatbox.mobile_button.background_image_url);
90
+ }
91
+
92
+ if (util/* default.get */.Z.get(chatbox, 'mobile_button.background_mask_url')) {
93
+ chatbox.mobile_button.background_mask_url = this.props.store.replaceFileUrl(chatbox.mobile_button.background_mask_url);
94
+ }
95
+
96
+ return chatbox;
97
+ }
98
+
99
+ render() {
100
+ let accountSetting = this.props.plugin.chatbox;
101
+ let position = util/* default.get */.Z.get(accountSetting, 'desktop_button.position') || 'right';
102
+
103
+ if (this.props.store.isMobile()) {
104
+ position = util/* default.get */.Z.get(accountSetting, 'mobile_button.position') || position;
105
+ let hiddenButtonMobile = util/* default.get */.Z.get(accountSetting, 'mobile_button.hidden');
106
+ if (hiddenButtonMobile) return null;
107
+ }
108
+
109
+ let hiddenButtonDesktop = util/* default.get */.Z.get(accountSetting, 'desktop_button.hidden');
110
+ if (hiddenButtonDesktop) return null;
111
+ let cls = 'widget-layout widget-layout--' + position;
112
+ let opacity = this.state.opacity;
113
+
114
+ if (!this.props.isShow) {
115
+ cls += ' widget-layout--hidden';
116
+ opacity = 0;
117
+ }
118
+
119
+ return (0,preact_module.h)("div", {
120
+ class: cls,
121
+ style: 'opacity: ' + opacity + ' !important'
122
+ }, this.renderPreview(), this.renderButton());
123
+ }
124
+
125
+ ClearPreview() {
126
+ this.setState({
127
+ previewEvent: {}
128
+ });
129
+ }
130
+
131
+ ShowGreeting() {
132
+ let greeting = util/* default.get */.Z.get(this.props.plugin, 'chatbox.greeting', {});
133
+ let agentM = this.props.store.matchAgent('*');
134
+ let byid = greeting.agent_id;
135
+ if (!byid) byid = randomAgent(agentM).id;
136
+ let text = this.props.t.i18n(util/* default.get */.Z.get(greeting, 'greeting', {})) || greeting.message;
137
+ this.setState({
138
+ previewEvent: {
139
+ by: {
140
+ id: byid,
141
+ type: 'agent'
142
+ },
143
+ data: {
144
+ message: {
145
+ text,
146
+ format: 'plaintext'
147
+ }
148
+ }
149
+ },
150
+ displayPreview: true
151
+ });
152
+ }
153
+
154
+ HideGreeting() {
155
+ this.setState({
156
+ previewEvent: {}
157
+ });
158
+ }
159
+
160
+ loadGreeting() {
161
+ let accountSetting = this.props.plugin.chatbox;
162
+ if (new util/* default.Date */.Z.Date().getTime() - this.props.store.matchClosePreviewAt() < Ms30Mins) return;
163
+ let greeting = util/* default.get */.Z.get(accountSetting, 'greeting', {});
164
+
165
+ if (!greeting.message || !greeting.enabled) {
166
+ this.setState({
167
+ previewEvent: {}
168
+ });
169
+ return;
170
+ }
171
+
172
+ this.ShowGreeting();
173
+ }
174
+
175
+ onClick() {
176
+ let lastview = this.props.store.matchLastview();
177
+
178
+ if (util/* default.get */.Z.get(lastview, 'view')) {
179
+ if (lastview.view !== 'list' || util/* default.size */.Z.size(this.props.store.matchConvo('*')) > 0) {
180
+ return this.props.onClick && this.props.onClick(Object.assign({}, lastview.opts, {
181
+ view: lastview.view
182
+ }));
183
+ }
184
+ }
185
+
186
+ return this.onPreviewClick();
187
+ }
188
+
189
+ onPreviewClick(e) {
190
+ let cid = util/* default.convoOfEv */.Z.convoOfEv(this.state.previewEvent);
191
+
192
+ if (!cid) {
193
+ let convos = util/* default.map */.Z.map(this.props.store.matchConvo('*'));
194
+ let convo = util/* default.find */.Z.find(convos, convo => !util/* default.isConvoSeen */.Z.isConvoSeen(convo, this.props.store.matchUser().id));
195
+ if (!convo) convo = convos[0] || {};
196
+ cid = convo.id;
197
+ }
198
+
199
+ this.closePreview(e);
200
+ this.props.onClick && this.props.onClick({
201
+ view: 'chat',
202
+ cid
203
+ });
204
+ }
205
+
206
+ renderUnread() {
207
+ let unreadcount = this.props.store.matchUnread();
208
+ if (unreadcount === 0) return null;
209
+ return (0,preact_module.h)("div", {
210
+ class: "chat-button--unread"
211
+ }, unreadcount);
212
+ }
213
+
214
+ renderPreview() {
215
+ let account = this.props.store.matchAccount();
216
+ let accountSetting = this.props.plugin.chatbox;
217
+ let byid = util/* default.get */.Z.get(this.state.previewEvent, 'by.display_id', util/* default.get */.Z.get(this.state.previewEvent, 'by.id'));
218
+ let agent = util/* default.cloneDeep */.Z.cloneDeep(this.props.store.matchAgent(byid)) || {};
219
+ agent.fullname = agent.fullname || util/* default.get */.Z.get(account, 'name') || this.props.t('agent');
220
+ agent.avatar_url = agent.avatar_url || defaultAvatar;
221
+ let position = util/* default.get */.Z.get(accountSetting, 'desktop_button.position') || 'right';
222
+
223
+ if (this.props.store.isMobile()) {
224
+ position = util/* default.get */.Z.get(accountSetting, 'mobile_button.position') || position;
225
+ }
226
+
227
+ let cls = 'widget-preview widget-preview--' + position;
228
+ if (!this.state.displayPreview) cls += ' widget-preview--hidden';
229
+ var tags = this.renderMessagePreview(this.state.previewEvent, this.props.t('sent_you_a_message'));
230
+ if (util/* default.size */.Z.size(tags) === 0) cls += ' widget-preview--hidden';
231
+ return (0,preact_module.h)("div", {
232
+ class: cls
233
+ }, (0,preact_module.h)("div", {
234
+ class: "widget-preview--body"
235
+ }, (0,preact_module.h)("img", {
236
+ alt: "widget avatar",
237
+ class: "widget-preview--avatar",
238
+ src: this.props.store.replaceFileUrl(agent.avatar_url),
239
+ onError: ev => this.onProfileError(ev),
240
+ onload: _ => this.onProfileReady()
241
+ }), (0,preact_module.h)("div", {
242
+ class: "widget-preview--content",
243
+ onClick: e => this.onPreviewClick(e)
244
+ }, (0,preact_module.h)("div", {
245
+ class: "widget-preview--title"
246
+ }, agent.fullname), (0,preact_module.h)("p", {
247
+ class: "widget-preview--message"
248
+ }, tags)), (0,preact_module.h)("div", {
249
+ class: "widget-preview--btn-close",
250
+ onClick: e => this.closePreview(e)
251
+ })), (0,preact_module.h)("div", {
252
+ class: "widget-preview--action",
253
+ onClick: e => this.onPreviewClick(e)
254
+ }, (0,preact_module.h)("div", {
255
+ class: "widget-preview--action-text"
256
+ }, this.props.t('chat_now'))));
257
+ }
258
+
259
+ onProfileReady() {
260
+ if (this.state.buttonLoaded) this.setState({
261
+ opacity: 1
262
+ });
263
+ this.setState({
264
+ profileLoaded: true
265
+ });
266
+ }
267
+
268
+ onButtonReady() {
269
+ if (this.state.profileLoaded) this.setState({
270
+ opacity: 1
271
+ });
272
+ this.setState({
273
+ buttonLoaded: true
274
+ });
275
+ }
276
+
277
+ renderButton() {
278
+ let accountSetting = this.props.plugin.chatbox;
279
+ accountSetting = this.fixMissingSetting(accountSetting);
280
+ let imgsrc = util/* default.get */.Z.get(accountSetting, 'desktop_button.background_image_url') || util/* default.get */.Z.get(accountSetting, 'desktop_button.background_mask_url') || defaultBubble;
281
+ let background = util/* default.get */.Z.get(accountSetting, 'background') || DEF_BG;
282
+ let position = util/* default.get */.Z.get(accountSetting, 'desktop_button.position') || 'right';
283
+ let imgurl = util/* default.get */.Z.get(accountSetting, 'desktop_button.background_image_url');
284
+ let maskurl = util/* default.get */.Z.get(accountSetting, 'desktop_button.background_mask_url');
285
+
286
+ if (this.props.store.isMobile()) {
287
+ imgsrc = util/* default.get */.Z.get(accountSetting, 'mobile_button.background_image_url') || util/* default.get */.Z.get(accountSetting, 'mobile_button.background_mask_url') || imgsrc;
288
+ position = util/* default.get */.Z.get(accountSetting, 'mobile_button.position') || position;
289
+ let mobileimgurl = util/* default.get */.Z.get(accountSetting, 'mobile_button.background_image_url');
290
+ let mobilemaskurl = util/* default.get */.Z.get(accountSetting, 'mobile_button.background_mask_url');
291
+
292
+ if (mobileimgurl || mobilemaskurl) {
293
+ imgurl = mobileimgurl;
294
+ maskurl = mobilemaskurl;
295
+ }
296
+ }
297
+
298
+ let whitebgcls = 'chat-button--white-bg';
299
+ if (!imgurl && maskurl) whitebgcls += ' chat-button--white-bg--mask-only';
300
+ let imgcontainerstyle = '';
301
+ imgurl = this.props.store.replaceFileUrl(imgurl);
302
+ imgsrc = this.props.store.replaceFileUrl(imgsrc);
303
+ maskurl = this.props.store.replaceFileUrl(maskurl);
304
+
305
+ if (!imgurl && !maskurl) {
306
+ whitebgcls += ' chat-button--white-bg--mask-only';
307
+ imgcontainerstyle = `
308
+ -webkit-mask-image: url("${encodeURI(DEF_BG_URL)}") !important;
309
+ -o-mask-image: url("${encodeURI(DEF_BG_URL)}") !important;
310
+ -moz-mask-image: url("${encodeURI(DEF_BG_URL)}") !important;
311
+ mask-image: url("${encodeURI(DEF_BG_URL)}") !important;
312
+ height: 70px !important;
313
+ width: 70px !important;
314
+ background: ${background} !important;
315
+ `;
316
+ }
317
+
318
+ if (imgurl && maskurl) {
319
+ imgcontainerstyle = `
320
+ -webkit-mask-image: url("${encodeURI(maskurl)}") !important;
321
+ -o-mask-image: url("${encodeURI(maskurl)}") !important;
322
+ -moz-mask-image: url("${encodeURI(maskurl)}") !important;
323
+ mask-image: url("${encodeURI(maskurl)}") !important;
324
+ background-image: url("${encodeURI(imgurl)}") !important;
325
+ background-repeat: no-repeat !important;
326
+ `;
327
+ }
328
+
329
+ if (imgurl && !maskurl) {
330
+ imgcontainerstyle = `
331
+ background-image: url("${encodeURI(imgurl)}") !important;
332
+ background-repeat: no-repeat !important;
333
+ `;
334
+ }
335
+
336
+ if (!imgurl && maskurl) {
337
+ imgcontainerstyle = `
338
+ -webkit-mask-image: url("${encodeURI(maskurl)}") !important;
339
+ -o-mask-image: url("${encodeURI(maskurl)}") !important;
340
+ -moz-mask-image: url("${encodeURI(maskurl)}") !important;
341
+ mask-image: url("${encodeURI(maskurl)}") !important;
342
+ height: 70px !important;
343
+ width: 70px !important;
344
+ background: ${background} !important;
345
+ `;
346
+ }
347
+
348
+ let cls = 'chat-button chat-button--' + position;
349
+ return (0,preact_module.h)("div", {
350
+ class: cls,
351
+ onClick: e => this.onClick(e)
352
+ }, (0,preact_module.h)("div", {
353
+ class: whitebgcls
354
+ }), (0,preact_module.h)("div", {
355
+ class: "chat-button--img-container",
356
+ style: imgcontainerstyle
357
+ }, (0,preact_module.h)("img", {
358
+ width: "70",
359
+ height: "70",
360
+ alt: "chat button",
361
+ class: "chat-button--img",
362
+ onload: () => this.onButtonReady(),
363
+ src: imgsrc,
364
+ onError: (e, a) => this.onChatButtonError(e, a)
365
+ })), this.renderUnread());
366
+ }
367
+
368
+ onProfileError(ev) {
369
+ var $el = ev.target;
370
+ $el.src = defaultAvatar;
371
+ this.onProfileReady();
372
+ }
373
+
374
+ onChatButtonError(ev) {
375
+ if (this._onChatButtonErrorExecuted) return;
376
+ this._onChatButtonErrorExecuted = true;
377
+ var $el = ev.target;
378
+ $el.src = defaultBubble;
379
+ }
380
+
381
+ renderMessagePreview(ev, defmsg) {
382
+ defmsg = defmsg || 'Sent you a message';
383
+ let message = util/* default.get */.Z.get(ev, 'data.message.text');
384
+ var format = util/* default.get */.Z.get(ev, 'data.message.format');
385
+ if (format && format !== 'plaintext') message = defmsg;
386
+ if (!message && util/* default.size */.Z.size(util/* default.get */.Z.get(ev, 'data.message.attachments')) > 0) message = defmsg;
387
+ if (!message) return null;
388
+ let byType = util/* default.get */.Z.get(ev, 'by.type');
389
+ var tags = util/* default.extractText */.Z.extractText(message).map(tag => {
390
+ if (tag.type === 'emoji') return (0,preact_module.h)(Emoji, {
391
+ emojiCode: tag.text,
392
+ byType: byType
393
+ });
394
+ return tag.text;
395
+ });
396
+ return tags;
397
+ }
398
+
399
+ closePreview(e) {
400
+ if (e) {
401
+ e.preventDefault();
402
+ e.stopPropagation();
403
+ }
404
+
405
+ this.setState({
406
+ displayPreview: false
407
+ });
408
+ this.props.store.closePreview();
409
+ this.forceUpdate();
410
+ }
411
+
412
+ }
413
+
414
+ function randomAgent(agentM) {
415
+ var agents = util/* default.filter */.Z.filter(agentM, ag => ag.type === 'agent');
416
+ return agents[Math.floor(Math.random() * util/* default.size */.Z.size(agents))] || {};
417
+ }
418
+
419
+ const Ms30Mins = 30 * 60 * 1000;
420
+ const DEF_BG_URL = 'https://file-subiz.com/bubble_11.svg';
421
+ const DEF_BG = 'linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)';
422
+ ;// CONCATENATED MODULE: ./src/chatbox/PoweredBy.js
423
+ var logo = __webpack_require__(8430);
424
+
425
+
426
+
427
+ class PoweredBy extends common/* Com */.M {
428
+ constructor(props) {
429
+ super(props);
430
+ }
431
+
432
+ render() {
433
+ if (this.props.store.isMobile()) return null;
434
+ let user = this.props.store.matchUser();
435
+ var link = `https://subiz.com.vn/?utm_source=id-${user.account_id}&utm_medium=widget&utm_campaign=widget_referral`;
436
+ return (0,preact_module.h)("div", {
437
+ class: "poweredby"
438
+ }, (0,preact_module.h)("a", {
439
+ href: link,
440
+ class: "poweredby--text",
441
+ target: "_blank",
442
+ rel: "noreferrer"
443
+ }, (0,preact_module.h)("img", {
444
+ width: "14",
445
+ height: "10",
446
+ class: "poweredby--subiz-logo",
447
+ src: logo,
448
+ alt: "power by"
449
+ }), " Subiz"));
450
+ }
451
+
452
+ }
453
+ ;// CONCATENATED MODULE: ./src/chatbox/AgentsAvatar.js
454
+
455
+
456
+
457
+ class AgentsAvatar extends common/* Com */.M {
458
+ constructor(props) {
459
+ super(props);
460
+ }
461
+
462
+ render() {
463
+ let accountSetting = this.props.plugin.chatbox;
464
+ let agentM = this.props.store.matchAgent('*');
465
+ var agents = util/* default.map */.Z.map(this.props.agent_ids, id => agentM[id]);
466
+
467
+ if (this.props.agent_ids === undefined || util/* default.size */.Z.size(this.props.agent_ids) === 0) {
468
+ var agids = util/* default.get */.Z.get(accountSetting, 'header.agent_ids', []);
469
+ agids = util/* default.filter */.Z.filter(agids, id => !!agentM[id]);
470
+
471
+ if (agids.length !== 0) {
472
+ agents = util/* default.map */.Z.map(agids, id => agentM[id]);
473
+ } else {
474
+ agents = util/* default.filter */.Z.filter(agentM, agent => agent.type === 'agent');
475
+ }
476
+ }
477
+
478
+ agents = util/* default.filter */.Z.filter(agents, ag => !!ag);
479
+ let acc = this.props.store.matchAccount();
480
+ var tooltippos = this.props.tooltipPos || 'bottom';
481
+ var mode = this.props.mode || 'primary';
482
+
483
+ if (agents.length === 0) {
484
+ return (0,preact_module.h)("div", {
485
+ class: `group-avatar group-avatar--${mode}`
486
+ }, (0,preact_module.h)("div", {
487
+ class: "d-inline-block pos-relative",
488
+ "data-tooltip": acc.name,
489
+ "data-tooltip-position": tooltippos
490
+ }, (0,preact_module.h)("img", {
491
+ width: 35,
492
+ height: 35,
493
+ alt: "agent avatar left",
494
+ class: "avatar group-avatar--agent-left",
495
+ src: this.props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(9895)
496
+ })));
497
+ }
498
+
499
+ if (agents.length === 1) {
500
+ var agent = agents[0];
501
+ var groupClass = mode === 'primary' ? 'group-avatar--agent-middle' : 'group-avatar--agent-left';
502
+ return (0,preact_module.h)("div", {
503
+ class: `group-avatar group-avatar--${mode}`
504
+ }, (0,preact_module.h)("div", {
505
+ class: "d-inline-block pos-relative",
506
+ "data-tooltip": agent.fullname || acc.name,
507
+ "data-tooltip-position": tooltippos
508
+ }, (0,preact_module.h)("img", {
509
+ width: 35,
510
+ height: 35,
511
+ class: `avatar ${groupClass}`,
512
+ alt: "agent avatar",
513
+ src: this.props.store.replaceFileUrl(agent.avatar_url) || __webpack_require__(4761)
514
+ })));
515
+ }
516
+
517
+ if (agents.length === 2) {
518
+ let leftAgent = agents[0];
519
+ let rightAgent = agents[1];
520
+ return (0,preact_module.h)("div", {
521
+ class: `group-avatar group-avatar--${mode}`
522
+ }, (0,preact_module.h)("div", {
523
+ class: "d-inline-block pos-relative",
524
+ "data-tooltip": leftAgent.fullname || acc.name,
525
+ "data-tooltip-position": tooltippos
526
+ }, (0,preact_module.h)("img", {
527
+ width: 35,
528
+ height: 35,
529
+ alt: "agent avatar left",
530
+ class: "avatar group-avatar--agent-left",
531
+ src: this.props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(4761)
532
+ })), (0,preact_module.h)("div", {
533
+ class: "d-inline-block pos-relative",
534
+ "data-tooltip": rightAgent.fullname || acc.name,
535
+ "data-tooltip-position": tooltippos
536
+ }, (0,preact_module.h)("img", {
537
+ alt: "agent avatar right",
538
+ width: 35,
539
+ height: 35,
540
+ class: "avatar group-avatar--agent-right",
541
+ src: this.props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(4761)
542
+ })));
543
+ }
544
+
545
+ let leftAgent = agents[0];
546
+ let middleAgent = agents[1];
547
+ let rightAgent = agents[2];
548
+ return (0,preact_module.h)("div", {
549
+ class: `group-avatar group-avatar--${mode}`
550
+ }, (0,preact_module.h)("div", {
551
+ class: "d-inline-block pos-relative",
552
+ "data-tooltip": leftAgent.fullname || acc.name,
553
+ "data-tooltip-position": tooltippos
554
+ }, (0,preact_module.h)("img", {
555
+ width: 35,
556
+ height: 35,
557
+ alt: "agent avatar left",
558
+ class: "avatar group-avatar--agent-left",
559
+ src: this.props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(4761)
560
+ })), (0,preact_module.h)("div", {
561
+ class: "d-inline-block pos-relative",
562
+ "data-tooltip": middleAgent.fullname || acc.name,
563
+ "data-tooltip-position": tooltippos
564
+ }, (0,preact_module.h)("img", {
565
+ alt: "agent avatar middle",
566
+ width: 35,
567
+ height: 35,
568
+ class: "avatar group-avatar--agent-middle",
569
+ src: this.props.store.replaceFileUrl(middleAgent.avatar_url) || __webpack_require__(4761)
570
+ })), (0,preact_module.h)("div", {
571
+ class: "d-inline-block pos-relative",
572
+ "data-tooltip": rightAgent.fullname || acc.name,
573
+ "data-tooltip-position": tooltippos
574
+ }, (0,preact_module.h)("img", {
575
+ width: 35,
576
+ height: 35,
577
+ alt: "agent avatar right",
578
+ class: "avatar group-avatar--agent-right",
579
+ src: this.props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(4761)
580
+ })));
581
+ }
582
+
583
+ }
584
+ ;// CONCATENATED MODULE: ./src/chatbox/Header.js
585
+
586
+
587
+
588
+
589
+
590
+ class Header extends common/* Com */.M {
591
+ constructor(props) {
592
+ super(props);
593
+ }
594
+
595
+ render() {
596
+ let headerMode = 'collapsed';
597
+ let cls = 'widget-header';
598
+ let renderSocial = false;
599
+ let renderTeam = false;
600
+ let renderCollapsed = this.props.view !== 'list' && headerMode === 'collapsed';
601
+ let accSetting = this.props.plugin.chatbox || {};
602
+ let layout = util/* default.get */.Z.get(accSetting, 'header.layout');
603
+
604
+ if (renderCollapsed) {
605
+ cls += ' widget-header--collapsed';
606
+ } else {
607
+ cls += ' widget-header--convo-expanded';
608
+ renderSocial = layout === 'social';
609
+ renderTeam = !renderSocial;
610
+ }
611
+
612
+ return (0,preact_module.h)("div", {
613
+ class: cls
614
+ }, this.renderCollapsedHeader(renderCollapsed), this.renderSocial(renderSocial), this.renderTeam(renderTeam));
615
+ }
616
+
617
+ renderCollapsedHeader(show) {
618
+ let accSetting = this.props.plugin.chatbox || {};
619
+ let acc = this.props.store.matchAccount();
620
+ let state = acc.is_online ? this.props.t('agent_online') : this.props.t('agent_offline');
621
+ let tagline = util/* default.get */.Z.get(accSetting, `tagline`, {});
622
+ let desc = this.props.t.i18n(tagline) || accSetting.introduction || state;
623
+ let agentIdsJoined = util/* default.map */.Z.map(this.getAgentJoined(this.props.cid), agent => agent.id);
624
+ let cls = 'widget-header--inner widget-header--inner--collapsed';
625
+ if (!show) cls += ' widget-header--inner--hidden';
626
+ return (0,preact_module.h)("div", {
627
+ class: cls
628
+ }, this.renderBackButton(), (0,preact_module.h)(AgentsAvatar, {
629
+ plugin: this.props.plugin,
630
+ store: this.props.store,
631
+ mode: "secondary",
632
+ agent_ids: agentIdsJoined
633
+ }), (0,preact_module.h)("div", {
634
+ class: "widget-header--title-container"
635
+ }, (0,preact_module.h)("div", {
636
+ class: "widget-header--title"
637
+ }, this.getTitle()), (0,preact_module.h)("div", {
638
+ class: "widget-header--description",
639
+ title: desc
640
+ }, desc)), this.renderCloseButton());
641
+ }
642
+
643
+ renderSocial(show) {
644
+ let accSetting = this.props.plugin.chatbox || {};
645
+ let acc = this.props.store.matchAccount();
646
+ let links = util/* default.get */.Z.get(accSetting, 'header.links') || [];
647
+ let $links = util/* default.map */.Z.map(links, link => {
648
+ if (!link.url || !link.type || link.type === 'subiz') return null;
649
+
650
+ if (link.type === 'email') {
651
+ return (0,preact_module.h)("div", null, (0,preact_module.h)("a", {
652
+ href: `mailto:${link.url}`,
653
+ title: link.url
654
+ }, (0,preact_module.h)("i", {
655
+ class: `social__links-logo social__links-logo--${link.type}`
656
+ })));
657
+ }
658
+
659
+ return (0,preact_module.h)("div", null, (0,preact_module.h)("a", {
660
+ href: link.url,
661
+ target: "_blank",
662
+ title: link.url,
663
+ rel: "noreferrer"
664
+ }, (0,preact_module.h)("i", {
665
+ class: `social__links-logo social__links-logo--${link.type}`
666
+ })));
667
+ });
668
+ const DEFTEAMINTO = `Chúng tôi sẵn sàng trợ giúp :wave:.
669
+ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi của bạn`;
670
+ let tagline = util/* default.get */.Z.get(accSetting, `tagline`, {});
671
+ var teamintro = this.props.t.i18n(tagline) || accSetting.introduction || this.props.t('team_intro') || DEFTEAMINTO;
672
+ var tags = util/* default.extractText */.Z.extractText(teamintro).map(tag => {
673
+ if (tag.type === 'emoji') return (0,preact_module.h)(Emoji, {
674
+ emojiCode: tag.text
675
+ });
676
+ return tag.text;
677
+ });
678
+ let cls = 'widget-header--inner widget-header--inner--expanded';
679
+ if (!show) cls += ' widget-header--inner--hidden';
680
+ return (0,preact_module.h)("div", {
681
+ class: cls
682
+ }, (0,preact_module.h)("div", {
683
+ class: "widget-header-expand-container"
684
+ }, (0,preact_module.h)("div", {
685
+ class: "widget-header--top-wrapper"
686
+ }, (0,preact_module.h)("div", {
687
+ class: "widget-header--title"
688
+ }, this.getTitle()), this.renderCloseButton()), (0,preact_module.h)("div", {
689
+ class: "widget_header__body widget_header__body__social"
690
+ }, (0,preact_module.h)("img", {
691
+ alt: "logo",
692
+ class: "social__account_logo",
693
+ src: this.props.store.replaceFileUrl(util/* default.get */.Z.get(acc, 'logo_url'))
694
+ }), (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
695
+ class: "social__introduction"
696
+ }, tags), (0,preact_module.h)("div", {
697
+ class: "social__links"
698
+ }, $links)))));
699
+ }
700
+
701
+ renderTeam(show) {
702
+ let accSetting = this.props.plugin.chatbox || {};
703
+ const DEFTEAMINTO = `Chúng tôi sẵn sàng trợ giúp :wave:.
704
+ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi của bạn`;
705
+ let tagline = util/* default.get */.Z.get(accSetting, `tagline`, {});
706
+ var teamintro = this.props.t.i18n(tagline) || accSetting.introduction || this.props.t('team_intro') || DEFTEAMINTO;
707
+ var tags = util/* default.extractText */.Z.extractText(teamintro).map(tag => {
708
+ if (tag.type === 'emoji') return (0,preact_module.h)(Emoji, {
709
+ emojiCode: tag.text
710
+ });
711
+ return tag.text;
712
+ });
713
+ let cls = 'widget-header--inner widget-header--inner--expanded';
714
+ if (!show) cls += ' widget-header--inner--hidden';
715
+ return (0,preact_module.h)("div", {
716
+ class: cls
717
+ }, (0,preact_module.h)("div", {
718
+ class: "widget-header-expand-container"
719
+ }, (0,preact_module.h)("div", {
720
+ class: "widget-header--top-wrapper"
721
+ }, (0,preact_module.h)("div", {
722
+ class: "widget-header--title"
723
+ }, this.getTitle()), this.renderCloseButton()), (0,preact_module.h)("div", {
724
+ class: "widget_header__body"
725
+ }, (0,preact_module.h)("div", {
726
+ class: "widget-header--avatar-wrapper"
727
+ }, (0,preact_module.h)(AgentsAvatar, {
728
+ plugin: this.props.plugin,
729
+ store: this.props.store,
730
+ mode: "primary"
731
+ })), (0,preact_module.h)("div", {
732
+ class: "widget-header--title-container"
733
+ }, (0,preact_module.h)("div", {
734
+ class: "widget-header--description"
735
+ }, tags)))));
736
+ }
737
+
738
+ getTitle() {
739
+ let accSetting = this.props.plugin.chatbox || {};
740
+ let acc = this.props.store.matchAccount();
741
+ let agentsJoined = this.getAgentJoined(this.props.cid);
742
+ let caption = util/* default.get */.Z.get(this.props.plugin, 'chatbox.caption', {});
743
+ let title = this.props.t.i18n(caption) || accSetting.title;
744
+ return getJoinedNameMember(agentsJoined) || title || acc.name || this.props.t('widget_title');
745
+ }
746
+
747
+ renderBackButton() {
748
+ let allconvos = this.props.store.matchConvo('*');
749
+ if (util/* default.size */.Z.size(allconvos) === 0) return null;
750
+ var $unreadcount = null;
751
+ let user = this.props.store.matchUser();
752
+ let unreadcount = 0;
753
+ util/* default.map */.Z.map(allconvos, convo => {
754
+ if (convo.id == this.props.cid) return;
755
+ if (!util/* default.isConvoSeen */.Z.isConvoSeen(convo, user.id)) unreadcount++;
756
+ });
757
+
758
+ if (unreadcount !== 0) {
759
+ $unreadcount = (0,preact_module.h)("span", {
760
+ class: "widget-header--total-unread-convo"
761
+ }, unreadcount);
762
+ }
763
+
764
+ return (0,preact_module.h)("div", {
765
+ class: `widget-header--wrap-button-back ${unreadcount ? 'widget-header--has-convo-unred' : ''}`,
766
+ onClick: e => this.onBackClick(e)
767
+ }, (0,preact_module.h)("div", {
768
+ class: "widget-header--button-back",
769
+ "data-tooltip": this.props.t('menu_back')
770
+ }), $unreadcount);
771
+ }
772
+
773
+ renderCloseButton() {
774
+ let accSetting = this.props.plugin.chatbox || {};
775
+ if (accSetting.hide_close_button) return null;
776
+ return (0,preact_module.h)("div", {
777
+ class: "widget-header--button widget-header--button-close",
778
+ "data-tooltip": this.props.t('close'),
779
+ "data-tooltip-position": "bottom",
780
+ onClick: e => this.onCloseClick(e)
781
+ }, (0,preact_module.h)("span", {
782
+ class: "widget-header--button-close-icon"
783
+ }));
784
+ }
785
+
786
+ onBackClick(e) {
787
+ e.stopPropagation();
788
+ e.preventDefault();
789
+ this.props.onGotoList && this.props.onGotoList();
790
+ }
791
+
792
+ onCloseClick(e) {
793
+ e.stopPropagation();
794
+ e.preventDefault();
795
+ this.props.onClose && this.props.onClose();
796
+ }
797
+
798
+ getAgentJoined(cid) {
799
+ var convo = this.props.store.matchConvo(cid) || {};
800
+ let joined = util/* default.filter */.Z.filter(convo.members, mem => mem.type === 'agent' && mem.membership === 'active');
801
+ return joined;
802
+ }
803
+
804
+ }
805
+
806
+ let getJoinedNameMember = agents => util/* default.map */.Z.map(agents, agent => agent.name).join(', ');
807
+ ;// CONCATENATED MODULE: ./src/chatbox/MessageInput.js
808
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
809
+
810
+
811
+
812
+
813
+
814
+ class MessageInput extends common/* Com */.M {
815
+ constructor(props) {
816
+ super(props);
817
+
818
+ _defineProperty(this, "onEnter", util/* default.throttle */.Z.throttle(function () {
819
+ this.submitMessage();
820
+ }, 50));
821
+
822
+ this.refFileInput = (0,preact_module/* createRef */.Vf)();
823
+ this.refMessageInput = (0,preact_module/* createRef */.Vf)();
824
+ this.props.store.onUpdate(this, _ => this.forceUpdate());
825
+ this.props.store.onConvoEvent(this, ev => {
826
+ var evcid = util/* default.convoOfEv */.Z.convoOfEv(ev);
827
+ if (evcid !== this.props.cid) return;
828
+ this.forceUpdate();
829
+ });
830
+ this.focus();
831
+ this._forceUpdate = util/* default.throttle */.Z.throttle(() => {
832
+ this.forceUpdate();
833
+ }, 500);
834
+ this.resizeInput = util/* default.throttle */.Z.throttle(function () {
835
+ const input = this.refMessageInput.current;
836
+ input.style.setProperty('height', '1em', 'important');
837
+ const height = Math.min(200, input.scrollHeight);
838
+ input.style.setProperty('height', `${height}px`, 'important');
839
+ }, 5);
840
+ }
841
+
842
+ render() {
843
+ var buttons = (0,preact_module.h)("div", {
844
+ class: "d-flex flex-row align-self-end"
845
+ }, this.renderEmoji(), (0,preact_module.h)("div", {
846
+ "data-tooltip-poasition": "top-left",
847
+ class: "message-input--button message-input--attachment-button",
848
+ onClick: e => this.selectFile(e)
849
+ }));
850
+ var msg = util/* default.trim */.Z.trim(this.refMessageInput.current && this.refMessageInput.current.value);
851
+
852
+ if (msg.length > 0) {
853
+ buttons = (0,preact_module.h)("div", {
854
+ class: "d-flex flex-row align-self-end"
855
+ }, this.renderEmoji(), (0,preact_module.h)("div", {
856
+ "data-tooltip-position": "top-left",
857
+ class: "message-input--button message-input--send-button",
858
+ onClick: () => this.submitMessage()
859
+ }));
860
+ }
861
+
862
+ var containercls = '';
863
+ var disabled = this.hasUnfinishRequiredFormOrLock() || this.props.disabled;
864
+ if (disabled) containercls = 'message-input--disabled';
865
+ return (0,preact_module.h)("div", {
866
+ class: `message-input ${containercls}`,
867
+ onClick: e => {
868
+ this.refMessageInput.current && this.refMessageInput.current.focus();
869
+ }
870
+ }, (0,preact_module.h)("input", {
871
+ class: "d-none",
872
+ ref: this.refFileInput,
873
+ type: "file",
874
+ onChange: e => this.sendFile(e),
875
+ multiple: true
876
+ }), (0,preact_module.h)("textarea", {
877
+ disabled: disabled,
878
+ class: "message-input--input",
879
+ maxlength: "1024",
880
+ placeholder: this.props.t('message_input_help'),
881
+ ref: this.refMessageInput,
882
+ rows: "1",
883
+ onInput: e => this.onChange(e),
884
+ onPaste: e => this.pasteImage(e),
885
+ "data-emojiable": "true",
886
+ onKeydown: e => this.onKeydown(e)
887
+ }), buttons);
888
+ }
889
+
890
+ hasUnfinishRequiredFormOrLock() {
891
+ let convo = this.props.store.matchConvo(this.props.cid);
892
+ if (util/* default.get */.Z.get(convo, 'state') === 'ended') return false;
893
+ let events = this.props.store.listEvents(this.props.cid);
894
+ events = util/* default.orderBy */.Z.orderBy(events, 'created', 'desc').filter(ev => ev.type === 'message_sent');
895
+ let attachments = util/* default.get */.Z.get(events[0], 'data.message.attachments', []);
896
+ let lock = util/* default.find */.Z.find(attachments, att => util/* default.get */.Z.get(att, 'lock_input'));
897
+ if (lock) return true;
898
+ var last_agent_sent;
899
+
900
+ for (let ev of events) {
901
+ if (util/* default.get */.Z.get(ev, 'by.type') === 'user') continue;
902
+ last_agent_sent = ev;
903
+ break;
904
+ }
905
+
906
+ attachments = util/* default.get */.Z.get(last_agent_sent, 'data.message.attachments', []);
907
+ let pendingForms = util/* default.filter */.Z.filter(attachments, att => {
908
+ if (!att) return false;
909
+ if (att.type !== 'form' && att.type !== 'ask_info_form') return false;
910
+ var form = att.form;
911
+ if (!form) return false;
912
+ var state = util/* default.parseJSON */.Z.parseJSON(form.state) || {};
913
+ if (!state.require_finished && att.type !== 'ask_info_form') return false;
914
+ if (isSummited(att.form)) return false;
915
+ return true;
916
+ });
917
+ return util/* default.size */.Z.size(pendingForms) > 0;
918
+ }
919
+
920
+ renderEmojiPopup() {
921
+ if (!this.state.openEmoji) return null;
922
+ return (0,preact_module.h)("div", {
923
+ class: "emoji-picker",
924
+ "v-clickaway": e => this.setState({
925
+ openEmoji: false
926
+ })
927
+ }, (0,preact_module.h)("div", {
928
+ class: "emoji-picker-background-item"
929
+ }, (0,preact_module.h)("div", {
930
+ onClick: () => this.emojiPick(':like:'),
931
+ "data-tooltip": ":like:",
932
+ class: "emoji-picker--item emoji--like"
933
+ })), (0,preact_module.h)("div", {
934
+ class: "emoji-picker-background-item"
935
+ }, (0,preact_module.h)("div", {
936
+ onClick: () => this.emojiPick(':unlike:'),
937
+ "data-tooltip": ":unlike:",
938
+ class: "emoji-picker--item emoji--unlike"
939
+ })), (0,preact_module.h)("div", {
940
+ class: "emoji-picker-background-item"
941
+ }, (0,preact_module.h)("div", {
942
+ onClick: () => this.emojiPick(':angry:'),
943
+ "data-tooltip": ":angry:",
944
+ class: "emoji-picker--item emoji--angry"
945
+ })), (0,preact_module.h)("div", {
946
+ class: "emoji-picker-background-item"
947
+ }, (0,preact_module.h)("div", {
948
+ onClick: () => this.emojiPick(':confused:'),
949
+ "data-tooltip": ":confused:",
950
+ class: "emoji-picker--item emoji--confused"
951
+ })), (0,preact_module.h)("div", {
952
+ class: "emoji-picker-background-item"
953
+ }, (0,preact_module.h)("div", {
954
+ onClick: () => this.emojiPick(':crying:'),
955
+ "data-tooltip": ":crying:",
956
+ class: "emoji-picker--item emoji--crying"
957
+ })), (0,preact_module.h)("div", {
958
+ class: "emoji-picker-background-item"
959
+ }, (0,preact_module.h)("div", {
960
+ onClick: () => this.emojiPick(':grinning:'),
961
+ "data-tooltip": ":grinning:",
962
+ class: "emoji-picker--item emoji--grinning"
963
+ })), (0,preact_module.h)("div", {
964
+ class: "emoji-picker-background-item"
965
+ }, (0,preact_module.h)("div", {
966
+ onClick: () => this.emojiPick(':heart-eyes:'),
967
+ "data-tooltip": ":heart-eyes:",
968
+ class: "emoji-picker--item emoji--heart-eyes"
969
+ })), (0,preact_module.h)("div", {
970
+ class: "emoji-picker-background-item"
971
+ }, (0,preact_module.h)("div", {
972
+ onClick: () => this.emojiPick(':neutral:'),
973
+ "data-tooltip": ":neutral:",
974
+ class: "emoji-picker--item emoji--neutral"
975
+ })), (0,preact_module.h)("div", {
976
+ class: "emoji-picker-background-item"
977
+ }, (0,preact_module.h)("div", {
978
+ onClick: () => this.emojiPick(':sad:'),
979
+ "data-tooltip": ":sad:",
980
+ class: "emoji-picker--item emoji--sad"
981
+ })), (0,preact_module.h)("div", {
982
+ class: "emoji-picker-background-item"
983
+ }, (0,preact_module.h)("div", {
984
+ onClick: () => this.emojiPick(':sleepy:'),
985
+ "data-tooltip": ":sleepy:",
986
+ class: "emoji-picker--item emoji--sleepy"
987
+ })), (0,preact_module.h)("div", {
988
+ class: "emoji-picker-background-item"
989
+ }, (0,preact_module.h)("div", {
990
+ onClick: () => this.emojiPick(':smiling:'),
991
+ "data-tooltip": ":smiling:",
992
+ class: "emoji-picker--item emoji--smiling"
993
+ })), (0,preact_module.h)("div", {
994
+ class: "emoji-picker-background-item"
995
+ }, (0,preact_module.h)("div", {
996
+ onClick: () => this.emojiPick(':surprised:'),
997
+ "data-tooltip": ":surprised:",
998
+ class: "emoji-picker--item emoji--surprised"
999
+ })), (0,preact_module.h)("div", {
1000
+ class: "emoji-picker-background-item"
1001
+ }, (0,preact_module.h)("div", {
1002
+ onClick: () => this.emojiPick(':tired:'),
1003
+ "data-tooltip": ":tired:",
1004
+ class: "emoji-picker--item emoji--tired"
1005
+ })), (0,preact_module.h)("div", {
1006
+ class: "emoji-picker-background-item"
1007
+ }, (0,preact_module.h)("div", {
1008
+ onClick: () => this.emojiPick(':tongue-out:'),
1009
+ "data-tooltip": ":tongue-out:",
1010
+ class: "emoji-picker--item emoji--tongue-out"
1011
+ })), (0,preact_module.h)("div", {
1012
+ class: "emoji-picker-background-item"
1013
+ }, (0,preact_module.h)("div", {
1014
+ onClick: () => this.emojiPick(':wink:'),
1015
+ "data-tooltip": ":wink:",
1016
+ class: "emoji-picker--item emoji--wink"
1017
+ })));
1018
+ }
1019
+
1020
+ focus() {
1021
+ if (this.props.disabled) return;
1022
+ this.refMessageInput.current && this.refMessageInput.current.focus();
1023
+ setTimeout(() => {
1024
+ this.refMessageInput.current && this.refMessageInput.current.focus();
1025
+ });
1026
+ setTimeout(() => {
1027
+ this.refMessageInput.current && this.refMessageInput.current.focus();
1028
+ }, 100);
1029
+ }
1030
+
1031
+ renderEmoji() {
1032
+ return (0,preact_module.h)("div", null, this.renderEmojiPopup(), (0,preact_module.h)("div", {
1033
+ class: "message-input--button message-input--emoji-button",
1034
+ onClick: e => this.toggleEmoji(e)
1035
+ }));
1036
+ }
1037
+
1038
+ toggleEmoji(e) {
1039
+ e.stopPropagation();
1040
+ this.focus();
1041
+ if (this.props.disabled) return;
1042
+ this.setState({
1043
+ openEmoji: !this.state.openEmoji
1044
+ });
1045
+ }
1046
+
1047
+ emojiPick(code) {
1048
+ const input = this.refMessageInput.current;
1049
+ const position = input.selectionStart;
1050
+ const message = this.refMessageInput.current.value;
1051
+ this.setState({
1052
+ openEmoji: false
1053
+ });
1054
+ this.refMessageInput.current.value = [message.slice(0, position), code, message.slice(position)].join('');
1055
+ this.resizeInput();
1056
+ input.focus();
1057
+ }
1058
+
1059
+ onKeydown(e) {
1060
+ if (e.keyCode === 13 && e.shiftKey === false) {
1061
+ this.onEnter();
1062
+ return e.preventDefault();
1063
+ }
1064
+
1065
+ this._forceUpdate();
1066
+
1067
+ this.sendTyping();
1068
+ }
1069
+
1070
+ onChange() {
1071
+ this.resizeInput();
1072
+ }
1073
+
1074
+ selectFile() {
1075
+ if (this.props.disabled) return;
1076
+ this.refFileInput.current.click();
1077
+ }
1078
+
1079
+ sendFile() {
1080
+ let $input = this.refFileInput.current;
1081
+
1082
+ this._sendFile($input.files);
1083
+
1084
+ $input.value = '';
1085
+ }
1086
+
1087
+ _sendFile(files) {
1088
+ if (util/* default.size */.Z.size(files) === 0) return;
1089
+ if (this.props.disabled) return;
1090
+ let attachments = util/* default.map */.Z.map(files, file => {
1091
+ return {
1092
+ type: 'file',
1093
+ mimetype: file.type,
1094
+ name: file.name,
1095
+ _file: file,
1096
+ size: file.size
1097
+ };
1098
+ });
1099
+ this.props.onSend && this.props.onSend({
1100
+ attachments
1101
+ });
1102
+ }
1103
+
1104
+ async submitMessage(msg) {
1105
+ msg = msg || util/* default.trim */.Z.trim(this.refMessageInput.current.value) || '';
1106
+ if (!msg) return;
1107
+ if (this.props.disabled) return;
1108
+ this.refMessageInput.current.value = '';
1109
+ this.resizeInput();
1110
+ this.setState({
1111
+ openEmoji: false
1112
+ });
1113
+ this.props.onSend && this.props.onSend({
1114
+ text: msg,
1115
+ format: 'plaintext'
1116
+ });
1117
+ }
1118
+
1119
+ sendTyping() {
1120
+ if (!this.props.cid) return;
1121
+ return this.props.store.typing(this.props.cid);
1122
+ }
1123
+
1124
+ pasteImage(event) {
1125
+ if (!window.File || !window.FileReader || !window.FileList || !window.Blob) return;
1126
+ let now = new util/* default.Date */.Z.Date();
1127
+ let year = now.getFullYear();
1128
+ let month = now.getMonth() + 1;
1129
+ let date = now.getDate();
1130
+ let hour = now.getHours();
1131
+ let min = now.getMinutes();
1132
+ let sec = now.getSeconds();
1133
+ const name = `Paste-image-${year}-${month}-${date}-${hour}-${min}-${sec}`;
1134
+ let blob = null;
1135
+ const copiedData = event.clipboardData.items[0];
1136
+
1137
+ if (copiedData.type.indexOf('image') === 0) {
1138
+ blob = copiedData.getAsFile();
1139
+ }
1140
+
1141
+ if (!blob) return;
1142
+ const parts = [blob, new ArrayBuffer()];
1143
+ const file = new File(parts, `${name}.png`, {
1144
+ type: 'image/png'
1145
+ });
1146
+
1147
+ this._sendFile([file]);
1148
+ }
1149
+
1150
+ }
1151
+
1152
+ function isSummited(form) {
1153
+ let fields = util/* default.get */.Z.get(form, 'fields') || [];
1154
+ return util/* default.find */.Z.find(fields, field => !!field.answered);
1155
+ }
1156
+ ;// CONCATENATED MODULE: ./src/chatbox/ImageAttachments.js
1157
+
1158
+
1159
+
1160
+ class ImageAttachment extends common/* Com */.M {
1161
+ constructor(props) {
1162
+ super(props);
1163
+ }
1164
+
1165
+ render() {
1166
+ var attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
1167
+ var images = [];
1168
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
1169
+ util/* default.each */.Z.each(attachments, (att, i) => {
1170
+ if (!att) return;
1171
+ if (!util/* default.includes */.Z.includes(att.mimetype, 'image')) return;
1172
+ if (!att.url) return;
1173
+ var uri = att.url;
1174
+
1175
+ if (!uri.startsWith('https://') && !uri.startsWith('http://') && !uri.startsWith('content://') && !uri.startsWith('data:')) {
1176
+ att.url = this.props.store.FileURL + uri;
1177
+ }
1178
+
1179
+ images.push(att);
1180
+ });
1181
+ if (images.length === 0) return null;
1182
+ var $images = util/* default.map */.Z.map(images, (image, index) => (0,preact_module.h)("div", {
1183
+ class: `image-attachment image-attachment--${byType}`
1184
+ }, (0,preact_module.h)("a", {
1185
+ href: this.props.store.replaceFileUrl(image.thumbnail_url || image.url),
1186
+ target: "_blank"
1187
+ }, (0,preact_module.h)("img", {
1188
+ alt: true,
1189
+ class: "image-attachment__img",
1190
+ src: this.props.store.replaceFileUrl(image.thumbnail_url || image.url),
1191
+ onload: e => this.props.onLoad && this.props.onLoad()
1192
+ }))));
1193
+
1194
+ if (byType === 'agent') {
1195
+ return (0,preact_module.h)("div", {
1196
+ class: "message-agent"
1197
+ }, $images);
1198
+ } else {
1199
+ return (0,preact_module.h)("div", {
1200
+ class: "message-user"
1201
+ }, $images);
1202
+ }
1203
+ }
1204
+
1205
+ }
1206
+ ;// CONCATENATED MODULE: ./src/chatbox/AudioAttachments.js
1207
+
1208
+
1209
+
1210
+ class AudioAttachments extends common/* Com */.M {
1211
+ constructor(props) {
1212
+ super(props);
1213
+ }
1214
+
1215
+ render() {
1216
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
1217
+ var attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
1218
+ var audios = [];
1219
+ util/* default.each */.Z.each(attachments, (att, i) => {
1220
+ if (!att) return;
1221
+ if (util/* default.includes */.Z.includes(att.mimetype, 'audio')) audios.push(att);
1222
+ });
1223
+ if (audios.length === 0) return null;
1224
+ var $audios = util/* default.map */.Z.map(audios, (audio, index) => {
1225
+ return (0,preact_module.h)("div", {
1226
+ key: index,
1227
+ class: `audio-attachment audio-attachment--${byType}`
1228
+ }, (0,preact_module.h)("audio", {
1229
+ class: "audio-attachment__audio",
1230
+ controls: true
1231
+ }, (0,preact_module.h)("source", {
1232
+ src: this.props.store.replaceFileUrl(audio.url),
1233
+ type: audio.mimetype
1234
+ })));
1235
+ });
1236
+ return (0,preact_module.h)("div", {
1237
+ class: `message-${byType}`
1238
+ }, $audios);
1239
+ }
1240
+
1241
+ }
1242
+ ;// CONCATENATED MODULE: ./src/chatbox/FileAttachments.js
1243
+
1244
+
1245
+
1246
+ class FileAttachments extends common/* Com */.M {
1247
+ render() {
1248
+ var byType = util/* default.get */.Z.get(this.props.ev, 'by.type', 'agent');
1249
+ var attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
1250
+ var files = [];
1251
+ util/* default.each */.Z.each(attachments, att => {
1252
+ if (!att) return;
1253
+ if (!att.url && !att._file) return;
1254
+
1255
+ if (!util/* default.includes */.Z.includes(att.mimetype, 'video') && !util/* default.includes */.Z.includes(att.mimetype, 'audio') && !util/* default.includes */.Z.includes(att.mimetype, 'image') && att.type !== 'button' && att.type !== 'quick_replies' && att.type !== 'form' && att.type !== 'form_submit') {
1256
+ files.push(att);
1257
+ }
1258
+ });
1259
+ if (files.length === 0) return null;
1260
+ var $files = util/* default.map */.Z.map(files, (file, index) => {
1261
+ return (0,preact_module.h)("div", {
1262
+ key: index,
1263
+ class: `file-attachment file-attachment--${byType}`
1264
+ }, (0,preact_module.h)("a", {
1265
+ class: "file-attachment--link",
1266
+ href: this.props.store.replaceFileUrl(file.url),
1267
+ target: "_blank"
1268
+ }, (0,preact_module.h)("span", {
1269
+ class: "file-attachment--download mr-2"
1270
+ }), (0,preact_module.h)("span", {
1271
+ class: "file-attachment--filename"
1272
+ }, file.name)));
1273
+ });
1274
+ return (0,preact_module.h)("div", {
1275
+ class: `message-${byType}`
1276
+ }, $files);
1277
+ }
1278
+
1279
+ }
1280
+ ;// CONCATENATED MODULE: ./src/chatbox/Buttons.js
1281
+
1282
+
1283
+
1284
+ class Buttons extends common/* Com */.M {
1285
+ constructor(props) {
1286
+ super(props);
1287
+ }
1288
+
1289
+ render() {
1290
+ if (util/* default.size */.Z.size(this.props.buttons) === 0) return null;
1291
+ var $buttons = util/* default.map */.Z.map(this.props.buttons, (button, index) => {
1292
+ if (button.type === 'call_button') {
1293
+ return (0,preact_module.h)("a", {
1294
+ class: "url-button-attachment",
1295
+ href: 'tel:' + button.phone_number,
1296
+ key: index,
1297
+ title: button.title
1298
+ }, button.title);
1299
+ }
1300
+
1301
+ if (button.type === 'url_button') {
1302
+ return (0,preact_module.h)("a", {
1303
+ class: "url-button-attachment",
1304
+ href: button.url,
1305
+ target: "_blank",
1306
+ key: index,
1307
+ title: button.title
1308
+ }, button.title || button.url);
1309
+ }
1310
+
1311
+ if (button.type === 'postback_button') {
1312
+ return (0,preact_module.h)("a", {
1313
+ class: "url-button-attachment",
1314
+ href: "javascript:;",
1315
+ onClick: _ => this.props.onSelect(button)
1316
+ }, button.title);
1317
+ }
1318
+
1319
+ if (button.type === 'widget_ask_desktop_notify_button') return null;
1320
+ if (button.type === 'widget_ask_contact_info_button') return null;
1321
+ return null;
1322
+ });
1323
+ return (0,preact_module.h)("div", {
1324
+ class: "button-attachments"
1325
+ }, $buttons);
1326
+ }
1327
+
1328
+ }
1329
+ ;// CONCATENATED MODULE: ./src/chatbox/ButtonAttachments.js
1330
+
1331
+
1332
+
1333
+
1334
+ class ButtonAttachments extends common/* Com */.M {
1335
+ constructor(props) {
1336
+ super(props);
1337
+ }
1338
+
1339
+ render() {
1340
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
1341
+ if (byType === 'user') return null;
1342
+ let buttons = [];
1343
+ let attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
1344
+ util/* default.each */.Z.each(attachments, (att, i) => {
1345
+ if (!att || util/* default.get */.Z.get(att, 'type') !== 'button') return;
1346
+ util/* default.each */.Z.each(util/* default.get */.Z.get(att, 'buttons') || [], btn => buttons.push(btn));
1347
+ });
1348
+ return (0,preact_module.h)(Buttons, {
1349
+ store: this.props.store,
1350
+ buttons: buttons
1351
+ });
1352
+ }
1353
+
1354
+ }
1355
+ ;// CONCATENATED MODULE: ./src/chatbox/QuickReplies.js
1356
+
1357
+
1358
+
1359
+ class QuickReplies extends common/* Com */.M {
1360
+ constructor(props) {
1361
+ super(props);
1362
+ }
1363
+
1364
+ render() {
1365
+ if (util/* default.get */.Z.get(this.props.ev, 'by.type') === 'user') return null;
1366
+ let quickreplies = [];
1367
+ util/* default.map */.Z.map(util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []), att => {
1368
+ if (!att) return;
1369
+
1370
+ if (att.type === 'quick_replies') {
1371
+ quickreplies = util/* default.get */.Z.get(att, 'quick_replies', []);
1372
+ }
1373
+ });
1374
+ quickreplies = util/* default.filter */.Z.filter(quickreplies, r => r.title);
1375
+ if (quickreplies.length === 0) return null;
1376
+ let cid = util/* default.convoOfEv */.Z.convoOfEv(this.props.ev);
1377
+ let convo = this.props.store.matchConvo(cid);
1378
+ if (util/* default.get */.Z.get(convo, 'state') === 'ended') return null;
1379
+ let events = util/* default.map */.Z.map(this.props.store.listEvents(cid));
1380
+ events = util/* default.orderBy */.Z.orderBy(events, 'created', 'asc').filter(ev => ev.type === 'message_sent');
1381
+ let evindex = 0;
1382
+
1383
+ for (var i = 0; i < events.length; i++) {
1384
+ if (events[i].id === this.props.ev.id) {
1385
+ evindex = i;
1386
+ break;
1387
+ }
1388
+ }
1389
+
1390
+ for (var i = evindex + 1; i < events.length; i++) {
1391
+ if (util/* default.get */.Z.get(events[i], 'by.type') === 'user') return null;
1392
+ }
1393
+
1394
+ let $replies = util/* default.map */.Z.map(quickreplies, r => (0,preact_module.h)("div", {
1395
+ class: "message_quick_reply",
1396
+ onClick: e => this.props.onSelect(r)
1397
+ }, r.title));
1398
+ return (0,preact_module.h)("div", {
1399
+ class: "message_quick_replies"
1400
+ }, $replies);
1401
+ }
1402
+
1403
+ }
1404
+ ;// CONCATENATED MODULE: ./src/chatbox/ListField.js
1405
+
1406
+
1407
+
1408
+ class ListField extends common/* Com */.M {
1409
+ constructor(props) {
1410
+ super(props);
1411
+ this.setState({
1412
+ search: '',
1413
+ isShow: false
1414
+ });
1415
+ }
1416
+
1417
+ render() {
1418
+ let fields = util/* default.filter */.Z.filter(this.props.items, item => {
1419
+ let search = this.state.search.toLowerCase();
1420
+ let name = item || '';
1421
+ return name.toLowerCase().indexOf(search) > -1;
1422
+ });
1423
+ let $fields = util/* default.map */.Z.map(fields, field => {
1424
+ return (0,preact_module.h)("li", {
1425
+ class: "custom-select--item-options",
1426
+ onClick: () => this.add(field)
1427
+ }, field);
1428
+ });
1429
+ let $selected = util/* default.map */.Z.map(this.props.selected, (item, i) => {
1430
+ return (0,preact_module.h)("div", {
1431
+ class: "custom-select--selected-item",
1432
+ onClick: e => this.remove(e, i)
1433
+ }, item, (0,preact_module.h)("i", {
1434
+ class: "icn-delete delete-tag"
1435
+ }));
1436
+ });
1437
+ let $dropdown = (0,preact_module.h)("div", {
1438
+ class: "custom-select--wrap-options"
1439
+ }, (0,preact_module.h)("input", {
1440
+ onClick: e => {
1441
+ e.preventDefault();
1442
+ e.stopPropagation();
1443
+ this.setState({
1444
+ isShow: true
1445
+ });
1446
+ },
1447
+ type: "text",
1448
+ onInput: e => this.setState({
1449
+ search: e.target.value
1450
+ }),
1451
+ value: this.state.search,
1452
+ placeholder: "T\xECm ki\u1EBFm",
1453
+ class: "custom-select--input-search"
1454
+ }), (0,preact_module.h)("ul", {
1455
+ class: "custom-select--items-options"
1456
+ }, $fields));
1457
+
1458
+ if (!this.state.isShow) {
1459
+ $dropdown = null;
1460
+ }
1461
+
1462
+ return (0,preact_module.h)("div", {
1463
+ class: "form-control custom-select"
1464
+ }, (0,preact_module.h)(common/* Clickaway */.u, {
1465
+ onClickaway: e => this.clickaway()
1466
+ }, (0,preact_module.h)("div", {
1467
+ class: "custom-select--wrap-selected",
1468
+ onClick: () => this.setState({
1469
+ isShow: !this.state.isShow
1470
+ })
1471
+ }, (0,preact_module.h)("div", {
1472
+ class: "custom-select--selected-items"
1473
+ }, $selected), $dropdown, (0,preact_module.h)("div", {
1474
+ class: "custom-select--icon-dropdown"
1475
+ }, (0,preact_module.h)("svg", {
1476
+ width: "24",
1477
+ height: "24",
1478
+ viewBox: "0 0 24 24",
1479
+ fill: "none",
1480
+ xmlns: "http://www.w3.org/2000/svg"
1481
+ }, (0,preact_module.h)("g", {
1482
+ opacity: "0.6"
1483
+ }, (0,preact_module.h)("path", {
1484
+ d: "M7 9.5L12 14.5L17 9.5H7Z",
1485
+ fill: "black"
1486
+ })))))));
1487
+ }
1488
+
1489
+ clickaway() {
1490
+ this.setState({
1491
+ isShow: false
1492
+ });
1493
+ }
1494
+
1495
+ add(field) {
1496
+ this.props.onAddItem && this.props.onAddItem(field);
1497
+ }
1498
+
1499
+ remove(e, index) {
1500
+ e.preventDefault();
1501
+ e.stopPropagation();
1502
+ this.props.onRemoveItem && this.props.onRemoveItem(index);
1503
+ }
1504
+
1505
+ }
1506
+ ;// CONCATENATED MODULE: ./src/chatbox/FormAttachment.js
1507
+
1508
+
1509
+
1510
+
1511
+ class FormAttachment extends common/* Com */.M {
1512
+ constructor(props) {
1513
+ super(props);
1514
+ this.props.store.onUpdate(this, _ => this.forceUpdate());
1515
+ let user = this.props.store.matchUser();
1516
+ let fields = util/* default.get */.Z.get(this.props.form, 'fields') || [];
1517
+ let formData = util/* default.map */.Z.map(fields, field => {
1518
+ let is_required = field.is_required || false;
1519
+ var state = util/* default.parseJSON */.Z.parseJSON(field.state) || {};
1520
+ if (!is_required) is_required = state.require || false;
1521
+ var userattr = util/* default.getUserAttr */.Z.getUserAttr(user, field.name, state.type || 'text');
1522
+ return {
1523
+ name: field.name,
1524
+ items: field.items,
1525
+ value: util/* default.parseJSON */.Z.parseJSON(field.answer) || util/* default.parseJSON */.Z.parseJSON(field.default_answer) || userattr,
1526
+ is_required,
1527
+ label: field.title,
1528
+ type: field.input_type
1529
+ };
1530
+ });
1531
+ this.setState({
1532
+ formData
1533
+ });
1534
+ }
1535
+
1536
+ isSummited() {
1537
+ let found = util/* default.find */.Z.find(this.state.formData, field => !!field.answered);
1538
+ if (found) return true;
1539
+ let convo = this.props.store.matchConvo(util/* default.convoOfEv */.Z.convoOfEv(this.props.ev));
1540
+ return convo.state === 'ended';
1541
+ }
1542
+
1543
+ render() {
1544
+ if (util/* default.size */.Z.size(this.state.formData) === 0) return null;
1545
+ let $fields = this.renderFields();
1546
+ let $submitbutton = null;
1547
+
1548
+ if (!this.isSummited()) {
1549
+ $submitbutton = (0,preact_module.h)("div", {
1550
+ class: "mt-2"
1551
+ }, (0,preact_module.h)("button", {
1552
+ onClick: _ => this.submit(),
1553
+ type: "button",
1554
+ class: "form-attachment--submit-btn"
1555
+ }, this.props.t('btn_submit_form_attachment')));
1556
+ }
1557
+
1558
+ return (0,preact_module.h)("div", {
1559
+ class: "form-attachment",
1560
+ onClick: e => e.stopPropagation()
1561
+ }, this.props.t(this.props.form.title) || this.props.t('capture_lead_title'), $fields, $submitbutton);
1562
+ }
1563
+
1564
+ focus() {
1565
+ if (this.props.store.isPreview) return;
1566
+ if (util/* default.size */.Z.size(this.state.formData) === 0) return;
1567
+ let $field;
1568
+
1569
+ if (this.isFormFilled()) {
1570
+ var keys = Object.keys(this.state.formData);
1571
+ var lastkey = keys[util/* default.size */.Z.size(keys) - 1];
1572
+ var lastfield = this.state.formData[lastkey];
1573
+ $field = this['field.' + encode(lastfield.name)];
1574
+ } else {
1575
+ var firstunfilledfield = this.firstUnfilledField();
1576
+ if (!firstunfilledfield) return;
1577
+ $field = this['field.' + encode(firstunfilledfield.name)];
1578
+ }
1579
+
1580
+ if ($field) $field.focus();
1581
+ }
1582
+
1583
+ firstUnfilledField() {
1584
+ return util/* default.find */.Z.find(this.state.formData, field => field.value == null || field.value === '');
1585
+ }
1586
+
1587
+ isFormFilled() {
1588
+ return !util/* default.find */.Z.find(this.state.formData, field => field.value == null || field.value === '');
1589
+ }
1590
+
1591
+ onInputChange(index, val) {
1592
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
1593
+ formData[index].value = val;
1594
+ this.setState({
1595
+ formData
1596
+ });
1597
+ }
1598
+
1599
+ onListAddItem(index, val) {
1600
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
1601
+ let field = formData[index];
1602
+ field.value = field.value || [];
1603
+ field.value.push(val);
1604
+ this.setState({
1605
+ formData
1606
+ });
1607
+ }
1608
+
1609
+ onListRemoveItem(index, vindex) {
1610
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
1611
+ let field = formData[index];
1612
+ field.value = field.value || [];
1613
+ field.value.splice(vindex, 1);
1614
+ this.setState({
1615
+ formData
1616
+ });
1617
+ }
1618
+
1619
+ renderFields() {
1620
+ if (util/* default.size */.Z.size(this.state.formData) === 0) return null;
1621
+ let $fields = null;
1622
+ $fields = util/* default.map */.Z.map(this.state.formData, (field, index) => {
1623
+ let $field = null;
1624
+ var errclass = field.error ? 'input--error' : '';
1625
+
1626
+ if (field.type === 'text') {
1627
+ if (this.isSummited()) {
1628
+ $field = (0,preact_module.h)("div", {
1629
+ class: "form-control--container"
1630
+ }, (0,preact_module.h)("input", {
1631
+ disabled: true,
1632
+ ref: ref => {
1633
+ this['field.' + encode(field.name)] = ref;
1634
+ },
1635
+ value: field.value,
1636
+ onInput: e => this.onInputChange(index, e.target.value),
1637
+ class: `form-control ${errclass}`,
1638
+ type: "text"
1639
+ }), (0,preact_module.h)("i", {
1640
+ class: "form-control--check"
1641
+ }));
1642
+ } else {
1643
+ $field = (0,preact_module.h)("input", {
1644
+ ref: ref => {
1645
+ this['field.' + encode(field.name)] = ref;
1646
+ },
1647
+ value: field.value,
1648
+ onInput: e => this.onInputChange(index, e.target.value),
1649
+ class: `form-control ${errclass}`,
1650
+ type: "text"
1651
+ });
1652
+ }
1653
+ } else if (field.type === 'number') {
1654
+ if (this.isSummited()) {
1655
+ $field = (0,preact_module.h)("div", {
1656
+ class: "form-control--container"
1657
+ }, (0,preact_module.h)("input", {
1658
+ disabled: true,
1659
+ ref: ref => {
1660
+ this['field.' + encode(field.name)] = ref;
1661
+ },
1662
+ value: field.value,
1663
+ onInput: e => this.onInputChange(index, e.target.value),
1664
+ class: `form-control ${errclass}`,
1665
+ type: "number"
1666
+ }), (0,preact_module.h)("i", {
1667
+ class: "form-control--check"
1668
+ }));
1669
+ } else {
1670
+ $field = (0,preact_module.h)("input", {
1671
+ ref: ref => {
1672
+ this['field.' + encode(field.name)] = ref;
1673
+ },
1674
+ value: field.value,
1675
+ onInput: e => this.onInputChange(index, e.target.value),
1676
+ class: `form-control ${errclass}`,
1677
+ type: "number"
1678
+ });
1679
+ }
1680
+ } else if (field.type === 'boolean') {
1681
+ $field = (0,preact_module.h)("div", {
1682
+ class: "checkbox"
1683
+ }, (0,preact_module.h)("input", {
1684
+ ref: ref => {
1685
+ this['field.' + encode(field.name)] = ref;
1686
+ },
1687
+ type: "checkbox",
1688
+ id: 'checkbox.' + this.props.ev.id + '.' + field.name,
1689
+ onChange: e => this.onInputChange(index, ev.target.checked),
1690
+ checked: field.value
1691
+ }), (0,preact_module.h)("label", {
1692
+ class: "checkbox--label",
1693
+ for: 'checkbox.' + this.props.ev.id + '.' + field.name
1694
+ }, field.label), (0,preact_module.h)("div", {
1695
+ class: "checkbox--check"
1696
+ }, (0,preact_module.h)("div", null)));
1697
+ } else if (field.type === 'list') {
1698
+ let selected = field.value || [];
1699
+ let items = util/* default.filter */.Z.filter(util/* default.get */.Z.get(field, 'items', []), item => !selected.includes(item));
1700
+ $field = (0,preact_module.h)(ListField, {
1701
+ selected: selected,
1702
+ items: items,
1703
+ onAddItem: e => this.onListAddItem(index, e),
1704
+ onRemoveItem: item => this.onListRemoveItem(index, item)
1705
+ });
1706
+ } else if (field.type === 'datetime') {
1707
+ $field = (0,preact_module.h)("input", {
1708
+ ref: ref => {
1709
+ this['field.' + encode(field.name)] = ref;
1710
+ },
1711
+ value: field.value,
1712
+ onInput: e => this.onInputChange(index, e.target.value),
1713
+ class: `form-control ${errclass}`,
1714
+ type: "date"
1715
+ });
1716
+ }
1717
+
1718
+ let label = field.label;
1719
+
1720
+ if (field.name === 'fullname') {
1721
+ label = this.props.t('fullname');
1722
+ } else if (field.name === 'emails') {
1723
+ label = this.props.t('email');
1724
+ } else if (field.name === 'phones') {
1725
+ label = this.props.t('phones');
1726
+ }
1727
+
1728
+ return (0,preact_module.h)("div", null, (0,preact_module.h)("p", {
1729
+ class: "label mt-3"
1730
+ }, label, field.is_required ? (0,preact_module.h)("span", {
1731
+ class: "ml-1 red"
1732
+ }, "*") : ''), field.error ? (0,preact_module.h)("div", {
1733
+ class: "form-control--valid-input--error"
1734
+ }, field.error) : '', $field);
1735
+ });
1736
+ return (0,preact_module.h)("div", null, $fields);
1737
+ }
1738
+
1739
+ async submit() {
1740
+ var hasError = false;
1741
+ util/* default.map */.Z.map(this.state.formData, field => {
1742
+ if (field.is_required && (field.value === undefined || field.value === '' || util/* default.size */.Z.size(field.value) === 0 && Array.isArray(field.value))) {
1743
+ field.error = this.props.t('error_empty');
1744
+ hasError = true;
1745
+ } else {
1746
+ field.error = '';
1747
+ }
1748
+
1749
+ if (field.name === 'emails' && field.value) {
1750
+ if (!util/* default.isEmail */.Z.isEmail(field.value)) {
1751
+ field.error = this.props.t('error_email_invalid');
1752
+ hasError = true;
1753
+ }
1754
+ }
1755
+ });
1756
+ this.forceUpdate();
1757
+ if (hasError) return;
1758
+ let user = {};
1759
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
1760
+ util/* default.map */.Z.map(formData, field => {
1761
+ var attr = {
1762
+ key: field.name
1763
+ };
1764
+ field.answered = new util/* default.Date */.Z.Date().getTime();
1765
+
1766
+ if (field.type === 'number') {
1767
+ attr.number = parseInt(field.value);
1768
+ field.answer = util/* default.stringify */.Z.stringify(attr.number);
1769
+ }
1770
+
1771
+ if (field.type === 'datetime') {
1772
+ attr.datetime = new util/* default.Date */.Z.Date(field.value).toISOString();
1773
+ field.answer = util/* default.stringify */.Z.stringify(attr.datetime);
1774
+ }
1775
+
1776
+ if (field.type === 'list') {
1777
+ attr.list = field.value;
1778
+ field.answer = util/* default.stringify */.Z.stringify(attr.list);
1779
+ }
1780
+
1781
+ if (field.type === 'text' || field.type === 'boolean') {
1782
+ attr[field.type] = field.value;
1783
+ field.answer = util/* default.stringify */.Z.stringify(field.value);
1784
+ }
1785
+
1786
+ util/* default.setUserAttr */.Z.setUserAttr(user, attr);
1787
+ });
1788
+ util/* default.map */.Z.map(formData, field => {
1789
+ let ffield = util/* default.find */.Z.find(this.props.form.fields, ffield => ffield.name === field.name);
1790
+ if (!ffield) return;
1791
+ ffield.answered = field.answered;
1792
+ });
1793
+ this.setState({
1794
+ formData
1795
+ });
1796
+ this.props.store.setUser(user);
1797
+ let message = {
1798
+ attachments: [{
1799
+ type: 'form_submit',
1800
+ form_submit: {
1801
+ state: '{"user_id":"' + this.props.store.matchUser().id + '"}',
1802
+ form_message_id: util/* default.get */.Z.get(this.props.ev, 'id'),
1803
+ fields: formData
1804
+ }
1805
+ }]
1806
+ };
1807
+ let cid = util/* default.convoOfEv */.Z.convoOfEv(this.props.ev);
1808
+ this.props.store.sendConvoEvent(cid, 'message_sent', {
1809
+ message
1810
+ });
1811
+ this.props.onSubmit && this.props.onSubmit();
1812
+ }
1813
+
1814
+ }
1815
+
1816
+ function encode(key) {
1817
+ return btoa(key).split('=').join('');
1818
+ }
1819
+ ;// CONCATENATED MODULE: ./src/chatbox/FormAttachments.js
1820
+
1821
+
1822
+
1823
+
1824
+ class FormAttachments extends common/* Com */.M {
1825
+ constructor(props) {
1826
+ super(props);
1827
+ }
1828
+
1829
+ render() {
1830
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
1831
+ if (byType === 'user') return;
1832
+ let forms = [];
1833
+ let attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments') || [];
1834
+ util/* default.each */.Z.each(attachments, att => {
1835
+ if (!att) return;
1836
+ if (att.type !== 'form' && att.type !== 'ask_info_form') return;
1837
+ att.form._type = att.type;
1838
+ forms.push(att.form);
1839
+ });
1840
+ let $forms = util/* default.map */.Z.map(forms, (form, formIndex) => {
1841
+ return (0,preact_module.h)(FormAttachment, {
1842
+ store: this.props.store,
1843
+ onSubmit: this.props.onSubmit,
1844
+ ref: ref => {
1845
+ this['form.' + formIndex] = ref;
1846
+ },
1847
+ key: formIndex,
1848
+ form: form,
1849
+ ev: this.props.ev,
1850
+ t: this.props.t
1851
+ });
1852
+ });
1853
+ if ($forms.length === 0) return null;
1854
+ return (0,preact_module.h)("div", {
1855
+ class: "message-agent"
1856
+ }, $forms);
1857
+ }
1858
+
1859
+ focus() {
1860
+ var $form = this['form.0'];
1861
+ if ($form) $form.focus();
1862
+ }
1863
+
1864
+ }
1865
+ ;// CONCATENATED MODULE: ./src/chatbox/FormSubmitAttachments.js
1866
+
1867
+
1868
+
1869
+ class FormSubmitAttachments extends common/* Com */.M {
1870
+ constructor(props) {
1871
+ super(props);
1872
+ }
1873
+
1874
+ render() {
1875
+ return null;
1876
+ let submits = [];
1877
+ let attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments') || [];
1878
+ util/* default.each */.Z.each(attachments, att => {
1879
+ if (!att) return;
1880
+ if (att.type !== 'form_submit') return;
1881
+ if (!att.form_submit) return;
1882
+ submits.push(att.form_submit);
1883
+ });
1884
+ let $submits = util/* default.map */.Z.map(submits, (submit, index) => (0,preact_module.h)("div", {
1885
+ class: "info-message"
1886
+ }, (0,preact_module.h)("span", null, this.props.tt('prechat_form_thanks'))));
1887
+ return (0,preact_module.h)("div", null, $submits);
1888
+ }
1889
+
1890
+ }
1891
+ ;// CONCATENATED MODULE: ./src/chatbox/touchscroll.js
1892
+ function bind(el) {
1893
+ if (!el) return;
1894
+ el.removeEventListener('touchstart', el.md, 0);
1895
+ window.removeEventListener('touchend', el.mu, 0);
1896
+ window.removeEventListener('touchmove', el.mm, 0);
1897
+ var lastClientX, pushed;
1898
+
1899
+ el.md = function (e) {
1900
+ let touch = getFirstTouch(e);
1901
+
1902
+ if (!el.hasAttribute('nochilddrag') || !document.elementFromPoint(touch.pageX, touch.pageY)) {
1903
+ pushed = 1;
1904
+ lastClientX = touch.clientX;
1905
+ e.preventDefault();
1906
+ }
1907
+ };
1908
+
1909
+ el.mu = () => {
1910
+ pushed = 0;
1911
+ };
1912
+
1913
+ el.mm = function (e) {
1914
+ if (!pushed) return;
1915
+ let touch = getFirstTouch(e);
1916
+ el.scrollLeft -= -lastClientX + touch.clientX;
1917
+ lastClientX = touch.clientX;
1918
+ };
1919
+
1920
+ el.addEventListener('touchstart', el.md, {
1921
+ passive: true
1922
+ });
1923
+ window.addEventListener('touchend', el.mu, {
1924
+ passive: true
1925
+ });
1926
+ window.addEventListener('touchmove', el.mm, {
1927
+ passive: true
1928
+ });
1929
+ }
1930
+
1931
+ function getFirstTouch(ev) {
1932
+ if (!ev.touches) return {};
1933
+ if (!ev.touches.length) return {};
1934
+ return ev.touches[0];
1935
+ }
1936
+ ;// CONCATENATED MODULE: ./src/chatbox/GenericTemplateAttachments.js
1937
+
1938
+
1939
+
1940
+
1941
+
1942
+ class GenericTemplateAttachments extends common/* Com */.M {
1943
+ constructor(props) {
1944
+ super(props);
1945
+ this.state = {
1946
+ focusing: 0
1947
+ };
1948
+ this.galleryRef = (0,preact_module/* createRef */.Vf)();
1949
+ }
1950
+
1951
+ componentDidMount() {
1952
+ this.bindDrag();
1953
+ }
1954
+
1955
+ focus(eleindex) {
1956
+ this.setState({
1957
+ focusing: eleindex
1958
+ });
1959
+ this.galleryRef.current.scrollLeft = 190 * eleindex - 20;
1960
+ }
1961
+
1962
+ render() {
1963
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
1964
+ if (byType === 'user') return null;
1965
+ let attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
1966
+ let generics = util/* default.filter */.Z.filter(attachments, att => util/* default.get */.Z.get(att, 'type') === 'generic');
1967
+ if (generics.length === 0) return null;
1968
+ var $generics = util/* default.map */.Z.map(generics, (gen, index) => {
1969
+ var $eles = util/* default.map */.Z.map(gen.elements, ele => {
1970
+ let $title = ele.title ? (0,preact_module.h)("div", {
1971
+ class: "generic-attachment--element-title"
1972
+ }, ele.title) : null;
1973
+ let $subtitle = ele.subtitle ? (0,preact_module.h)("div", {
1974
+ class: "generic-attachment--element-subtitle"
1975
+ }, ele.subtitle) : null;
1976
+ return (0,preact_module.h)("div", {
1977
+ class: "generic-attachment--element swiper-slide"
1978
+ }, (0,preact_module.h)("div", null, (0,preact_module.h)("img", {
1979
+ alt: "generic attachment element",
1980
+ class: "generic-attachment--element-img",
1981
+ src: this.props.store.replaceFileUrl(ele.image_url)
1982
+ })), $title, $subtitle, (0,preact_module.h)(Buttons, {
1983
+ buttons: ele.buttons,
1984
+ onSelect: button => this.props.onSelect(button)
1985
+ }));
1986
+ });
1987
+ let elements = util/* default.get */.Z.get(attachments, '0.elements', []);
1988
+ let leftNavigatorCls = 'generic-attachment-navigator generic-attachment-navigator--left';
1989
+ let rightNavigatorCls = 'generic-attachment-navigator generic-attachment-navigator--right';
1990
+ if (this.state.focusing === 0) leftNavigatorCls += ' generic-attachment-navigator--disabled';
1991
+ if (this.state.focusing === elements.length - 1) rightNavigatorCls += ' generic-attachment-navigator--disabled';
1992
+ return (0,preact_module.h)("div", {
1993
+ class: "generic-attachment-container"
1994
+ }, (0,preact_module.h)("div", {
1995
+ class: "generic-attachment",
1996
+ ref: this.galleryRef
1997
+ }, $eles), !this.props.store.isMobile() && (0,preact_module.h)(preact_module/* Fragment */.HY, null, (0,preact_module.h)("div", {
1998
+ class: leftNavigatorCls,
1999
+ onClick: _ => this.focus(this.state.focusing - 1)
2000
+ }, (0,preact_module.h)("span", {
2001
+ class: "generic-attachment-navigator-icon"
2002
+ }, "\u2039")), (0,preact_module.h)("div", {
2003
+ class: rightNavigatorCls,
2004
+ onClick: _ => this.focus(this.state.focusing + 1)
2005
+ }, (0,preact_module.h)("span", {
2006
+ class: "generic-attachment-navigator-icon"
2007
+ }, "\u203A"))));
2008
+ });
2009
+ return $generics;
2010
+ }
2011
+
2012
+ bindDrag() {
2013
+ if (!this.props.store.isMobile()) return;
2014
+ let eles = document.getElementsByClassName('generic-attachment');
2015
+ util/* default.map */.Z.map(eles, ele => bind(ele, () => {}));
2016
+ }
2017
+
2018
+ }
2019
+ ;// CONCATENATED MODULE: ./src/chatbox/ProductAttachments.js
2020
+
2021
+
2022
+
2023
+ class ProductAttachments extends common/* Com */.M {
2024
+ render() {
2025
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
2026
+ if (byType === 'user') return null;
2027
+ let attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
2028
+ let products = util/* default.filter */.Z.filter(attachments, att => util/* default.get */.Z.get(att, 'type') === 'product' || util/* default.get */.Z.get(att, 'type') === 'product_preview');
2029
+ products = products.filter(product => product.product && product.product.name);
2030
+ if (products.length === 0) return null;
2031
+ let acc = this.props.store.matchAccount();
2032
+ let $products = util/* default.map */.Z.map(products, (att, index) => {
2033
+ let product = att.product;
2034
+ let $detailbtn = null;
2035
+ let url = product.url || product.mobile_url;
2036
+ if (this.props.store.isMobile()) url = product.mobile_url || product.url;
2037
+ if (url) $detailbtn = (0,preact_module.h)("a", {
2038
+ class: "product_attachment__btn",
2039
+ href: url,
2040
+ target: "_blank"
2041
+ }, this.props.t('detail'), (0,preact_module.h)("img", {
2042
+ src: __webpack_require__(8453),
2043
+ class: "product_attachment__btn_external_link"
2044
+ }));
2045
+ let $title = (0,preact_module.h)("a", {
2046
+ href: url,
2047
+ class: "product_attachment__title",
2048
+ target: "_blank"
2049
+ }, product.name);
2050
+ let $subtitle = null;
2051
+ let desc = product.description || product.long_description;
2052
+ if (desc) $subtitle = (0,preact_module.h)("div", {
2053
+ class: "product_attachment__subtitle"
2054
+ }, desc);
2055
+ let $price = null;
2056
+
2057
+ if (product.price) {
2058
+ $price = (0,preact_module.h)("div", {
2059
+ class: "product_attachment__price"
2060
+ }, product.currency || util/* default.get */.Z.get(acc, 'currency', ''), " ", util/* default.formatCurrency */.Z.formatCurrency(product.price));
2061
+ }
2062
+
2063
+ return (0,preact_module.h)("div", {
2064
+ class: 'product_attachment product_attachment__' + byType
2065
+ }, (0,preact_module.h)("div", null, (0,preact_module.h)("a", {
2066
+ href: this.props.store.replaceFileUrl(product.image),
2067
+ target: "_blank"
2068
+ }, (0,preact_module.h)("img", {
2069
+ class: "product_attachment__img",
2070
+ src: this.props.store.replaceFileUrl(product.image)
2071
+ }))), $title, $subtitle, $price, (0,preact_module.h)("div", {
2072
+ class: "product_attachment__btns"
2073
+ }, $detailbtn));
2074
+ });
2075
+ return $products;
2076
+ }
2077
+
2078
+ }
2079
+ ;// CONCATENATED MODULE: ./src/chatbox/OrderAttachments.js
2080
+
2081
+
2082
+
2083
+ class OrderAttachments_ProductAttachments extends common/* Com */.M {
2084
+ render() {
2085
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
2086
+ if (byType === 'user') return null;
2087
+ let acc = this.props.store.matchAccount();
2088
+ var attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
2089
+ let orders = util/* default.filter */.Z.filter(attachments, att => att.type === 'order' && att.order).map(att => att.order);
2090
+ if (orders.length === 0) return null;
2091
+ let $orders = util/* default.map */.Z.map(orders, (order, index) => {
2092
+ let $note = null;
2093
+
2094
+ if (order.note) {
2095
+ $note = (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
2096
+ class: "order_attachment__label"
2097
+ }, this.props.t('note')), (0,preact_module.h)("div", {
2098
+ class: "order_attachment__text_truncate"
2099
+ }, order.note));
2100
+ }
2101
+
2102
+ let $products = null;
2103
+
2104
+ if (util/* default.size */.Z.size(order.items) > 0) {
2105
+ $products = (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
2106
+ class: "order_attachment__label"
2107
+ }, this.props.t('product')), util/* default.map */.Z.map(order.items, item => {
2108
+ let product = item.product || {};
2109
+ return (0,preact_module.h)("div", {
2110
+ class: "order_attachment__product"
2111
+ }, (0,preact_module.h)("img", {
2112
+ class: "order_attachment__product_img",
2113
+ src: (util/* default.get */.Z.get(product, 'images.0'), __webpack_require__(9270))
2114
+ }), (0,preact_module.h)("div", {
2115
+ style: "overflow: hidden !important;"
2116
+ }, (0,preact_module.h)("div", {
2117
+ class: "order_attachment__product_name"
2118
+ }, product.name), (0,preact_module.h)("div", {
2119
+ class: "order_attachment__product_desc"
2120
+ }, product.description || product.long_description), (0,preact_module.h)("div", {
2121
+ class: "order_attachment__product_desc"
2122
+ }, this.props.t('qty'), " ", item.quantity, "\xA0\xB7\xA0", util/* default.formatCurrency */.Z.formatCurrency(product.price))));
2123
+ }));
2124
+ }
2125
+
2126
+ let $total = (0,preact_module.h)("div", {
2127
+ class: "order_attachment__footer"
2128
+ }, (0,preact_module.h)("div", null, this.props.t('total')), ' ', (0,preact_module.h)("div", null, (0,preact_module.h)("b", null, util/* default.formatCurrency */.Z.formatCurrency(order.total))));
2129
+ let addr = util/* default.get */.Z.get(order, 'shipping.address', {});
2130
+ let fulladdr = [addr.street, addr.ward, addr.district, addr.region, addr.country].filter(a => a).join(', ');
2131
+ let address = fulladdr;
2132
+ let phoneattr = util/* default.find */.Z.find(util/* default.get */.Z.get(order, 'user.attributes', []), attr => attr.key === 'phones') || {
2133
+ key: 'phones',
2134
+ text: ''
2135
+ };
2136
+ let phone = util/* default.get */.Z.get(order, 'shipping.address.phone', '').trim();
2137
+ phone = phone || util/* default.trim */.Z.trim(phoneattr.text);
2138
+ if (phone) phone = this.props.t('phn') + ': ' + phone;
2139
+ let $shipto = null;
2140
+
2141
+ if (address || phone) {
2142
+ $shipto = (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
2143
+ class: "order_attachment__label"
2144
+ }, this.props.t('ship_to')), (0,preact_module.h)("div", {
2145
+ class: "order_attachment__text_truncate"
2146
+ }, address), (0,preact_module.h)("div", {
2147
+ class: "order_attachment__text_truncate"
2148
+ }, phone));
2149
+ }
2150
+
2151
+ return (0,preact_module.h)("div", {
2152
+ class: `order_attachment order_attachment__${byType}`
2153
+ }, (0,preact_module.h)("div", {
2154
+ class: "order_attachment__header"
2155
+ }, this.props.t('order'), (0,preact_module.h)("span", {
2156
+ class: "order_attachment__text_muted order_attachment__text_sm"
2157
+ }, "#", order.id)), $products, $shipto, (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
2158
+ class: "order_attachment__label"
2159
+ }, this.props.t('payment')), (0,preact_module.h)("div", null, "COD")), $note, $total);
2160
+ });
2161
+ return $orders;
2162
+ }
2163
+
2164
+ }
2165
+ ;// CONCATENATED MODULE: ./src/chatbox/VideoAttachments.js
2166
+
2167
+
2168
+
2169
+ class VideoAttachments extends common/* Com */.M {
2170
+ constructor(props) {
2171
+ super(props);
2172
+ }
2173
+
2174
+ render() {
2175
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
2176
+ var attachments = util/* default.get */.Z.get(this.props.ev, 'data.message.attachments', []);
2177
+ var videos = [];
2178
+ util/* default.each */.Z.each(attachments, (att, i) => {
2179
+ if (!att) return;
2180
+ if (util/* default.includes */.Z.includes(att.mimetype, 'video')) videos.push(att);
2181
+ });
2182
+ if (videos.length === 0) return null;
2183
+ var $videos = util/* default.map */.Z.map(videos, (video, index) => {
2184
+ return (0,preact_module.h)("div", {
2185
+ class: `video-attachment video-attachment--${byType}`
2186
+ }, (0,preact_module.h)("video", {
2187
+ class: "video-attachment__video",
2188
+ src: this.props.store.replaceFileUrl(video.url),
2189
+ width: "100%",
2190
+ height: "",
2191
+ poster: this.props.store.replaceFileUrl(video.thumbnail_url),
2192
+ controls: "controls",
2193
+ preload: "metadata",
2194
+ onclick: "this.play()"
2195
+ }));
2196
+ });
2197
+ return (0,preact_module.h)("div", {
2198
+ class: `message-${byType}`
2199
+ }, $videos);
2200
+ }
2201
+
2202
+ }
2203
+ ;// CONCATENATED MODULE: ./src/chatbox/ShadowDomRoot.js
2204
+
2205
+
2206
+ class ShadowDomRoot extends common/* Com */.M {
2207
+ constructor(props) {
2208
+ super(props);
2209
+ this.ref = (0,preact_module/* createRef */.Vf)();
2210
+ }
2211
+
2212
+ componentDidMount() {
2213
+ this.shadowRoot = this.ref.current.attachShadow({
2214
+ mode: 'open'
2215
+ });
2216
+ this.update(this.props.html);
2217
+ }
2218
+
2219
+ update(html) {
2220
+ this.shadowRoot.innerHTML = `<style type="text/css">
2221
+ body { font-family: 'Roboto', sans-serif!important; font-size: 14px!important; line-height: 20px; overflow-y: hidden; margin:0 }
2222
+ h{ font-size: 14/18px!important; }
2223
+ a { text-decoration: none;}
2224
+ img { max-width: 100%; display: block; margin: 10px auto; }
2225
+ * { white-space: normal }
2226
+ ul > li { margin-bottom: 5px }
2227
+ ul:last-child { margin-bottom: 0 }
2228
+ p:first-child { margin-top: 0;}
2229
+ p:last-child { margin-bottom: 0;}
2230
+ </style>
2231
+ <div>${html}</div>`;
2232
+ let links = this.shadowRoot.querySelectorAll('a');
2233
+
2234
+ for (var i = 0; i < links.length; i++) links[i].target = '_blank';
2235
+ }
2236
+
2237
+ render() {
2238
+ return (0,preact_module.h)("div", {
2239
+ ref: this.ref,
2240
+ style: "white-space: normal !important"
2241
+ });
2242
+ }
2243
+
2244
+ }
2245
+ ;// CONCATENATED MODULE: ./src/chatbox/TextMessage.js
2246
+
2247
+ let mustrerender = [];
2248
+
2249
+ let marked = (obj, text) => {
2250
+ mustrerender.push(obj);
2251
+ return '';
2252
+ };
2253
+
2254
+ const loadMarked = () => __webpack_require__.e(/* import() */ 441).then(__webpack_require__.bind(__webpack_require__, 7441));
2255
+
2256
+ (async () => {
2257
+ let markedf = (await loadMarked()).marked;
2258
+
2259
+ marked = (obj, text) => markedf(text);
2260
+
2261
+ util/* default.map */.Z.map(mustrerender, obj => obj.forceUpdate());
2262
+ mustrerender = [];
2263
+ })();
2264
+
2265
+
2266
+
2267
+
2268
+
2269
+ class TextMessage extends common/* Com */.M {
2270
+ render() {
2271
+ var format = util/* default.get */.Z.get(this.props.ev, 'data.message.format', 'plaintext');
2272
+ if (format === 'markdown') return this.renderMarkdown();
2273
+ var text = util/* default.get */.Z.get(this.props.ev, 'data.message.text');
2274
+ text = util/* default.trim */.Z.trim(text);
2275
+ if (util/* default.size */.Z.size(text) === 0) return null;
2276
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
2277
+ var tags = util/* default.extractText */.Z.extractText(text).map(tag => {
2278
+ if (tag.type === 'emoji') return (0,preact_module.h)(Emoji, {
2279
+ emojiCode: tag.text,
2280
+ byType: byType
2281
+ });
2282
+
2283
+ if (tag.type === 'link') {
2284
+ return (0,preact_module.h)("a", {
2285
+ href: tag.text,
2286
+ target: "_blank"
2287
+ }, tag.text);
2288
+ }
2289
+
2290
+ if (tag.type === 'phone') return (0,preact_module.h)("a", {
2291
+ href: 'tel:' + tag.text
2292
+ }, tag.text);
2293
+ if (tag.type === 'email') return (0,preact_module.h)("a", {
2294
+ href: 'mailto:' + tag.text
2295
+ }, tag.text);
2296
+ return tag.text;
2297
+ });
2298
+ if (util/* default.size */.Z.size(tags) === 0) return null;
2299
+
2300
+ if (byType === 'agent') {
2301
+ return (0,preact_module.h)("div", {
2302
+ class: "message-agent message-text--agent"
2303
+ }, tags);
2304
+ }
2305
+
2306
+ return (0,preact_module.h)("div", {
2307
+ class: "message-user message-text--user"
2308
+ }, tags);
2309
+ }
2310
+
2311
+ renderMarkdown() {
2312
+ var text = util/* default.get */.Z.get(this.props.ev, 'data.message.text');
2313
+ if (util/* default.size */.Z.size(text) === 0) return null;
2314
+ let byType = util/* default.get */.Z.get(this.props.ev, 'by.type');
2315
+ text = util/* default.trim */.Z.trim(text);
2316
+ if (util/* default.size */.Z.size(text) === 0) return null;
2317
+
2318
+ if (byType === 'agent') {
2319
+ return (0,preact_module.h)("div", {
2320
+ class: "markdown-message message-agent message-text--agent"
2321
+ }, (0,preact_module.h)(ShadowDomRoot, {
2322
+ html: marked(this, text)
2323
+ }));
2324
+ }
2325
+
2326
+ return (0,preact_module.h)("div", {
2327
+ class: "d-flex flex-column align-items-end"
2328
+ }, (0,preact_module.h)("div", {
2329
+ class: "markdown-message message-user message-text--user"
2330
+ }, (0,preact_module.h)(ShadowDomRoot, {
2331
+ html: marked(this, text)
2332
+ })));
2333
+ }
2334
+
2335
+ }
2336
+ ;// CONCATENATED MODULE: ./src/chatbox/time.js
2337
+
2338
+ var g_pub = new util/* default.Pubsub */.Z.Pubsub();
2339
+ setInterval(() => g_pub.publish('time'), 20 * 1000);
2340
+
2341
+
2342
+ class Time extends common/* Com */.M {
2343
+ constructor(props) {
2344
+ super(props);
2345
+ this.setState({
2346
+ t: '',
2347
+ langCode: 'en_US'
2348
+ });
2349
+ }
2350
+
2351
+ updateTime() {
2352
+ var t = '';
2353
+
2354
+ if (this.props.ago) {
2355
+ if (this.props.short) {
2356
+ if (Math.abs(this.props.time - new util/* default.Date */.Z.Date().getTime()) > 86400000 * 10) {
2357
+ let tim = new util/* default.Date */.Z.Date(this.props.time);
2358
+ let tzyear = tim.getFullYear();
2359
+ let locale = util/* default.get */.Z.get(navigator, 'languages.0', 'en-US');
2360
+ let tzmonthname = tim.toLocaleDateString(locale, {
2361
+ month: 'short'
2362
+ });
2363
+ let tzdate = tim.getDate();
2364
+ t = tzdate + ' ' + tzmonthname + ' ' + tzyear;
2365
+ }
2366
+ }
2367
+
2368
+ if (!t && this.props.time > 0) t = ago(this.props.time, new util/* default.Date */.Z.Date().getTime());
2369
+ } else t = util/* default.shortTime */.Z.shortTime(this.props.time, this.props.tzoffset);
2370
+
2371
+ if (this.props.uppercase) t = t.toUpperCase();
2372
+ if (t === this.state.t) return;
2373
+ this.setState({
2374
+ t
2375
+ });
2376
+ }
2377
+
2378
+ componentDidMount() {
2379
+ g_pub.on2(this, 'time', () => this.updateTime());
2380
+ this.updateTime();
2381
+ }
2382
+
2383
+ render() {
2384
+ return (0,preact_module.h)("span", null, this.state.t);
2385
+ }
2386
+
2387
+ }
2388
+
2389
+ function ago(timeA, timeB) {
2390
+ const relObj = {
2391
+ s: '%d s',
2392
+ m: '1m',
2393
+ mm: '%dm',
2394
+ h: '1h',
2395
+ hh: '%dh',
2396
+ d: '1d',
2397
+ dd: '%dd',
2398
+ M: '1M',
2399
+ MM: '%M',
2400
+ y: '1y',
2401
+ yy: '%dy'
2402
+ };
2403
+ const loc = relObj;
2404
+ const T = [{
2405
+ l: 's',
2406
+ r: 44,
2407
+ d: 1000
2408
+ }, {
2409
+ l: 'm',
2410
+ r: 89
2411
+ }, {
2412
+ l: 'mm',
2413
+ r: 44,
2414
+ d: 60000
2415
+ }, {
2416
+ l: 'h',
2417
+ r: 89
2418
+ }, {
2419
+ l: 'hh',
2420
+ r: 21,
2421
+ d: 3600000
2422
+ }, {
2423
+ l: 'd',
2424
+ r: 35
2425
+ }, {
2426
+ l: 'dd',
2427
+ r: 25,
2428
+ d: 86400000
2429
+ }, {
2430
+ l: 'M',
2431
+ r: 45
2432
+ }, {
2433
+ l: 'MM',
2434
+ r: 10,
2435
+ d: 30 * 86400000
2436
+ }, {
2437
+ l: 'y',
2438
+ r: 17
2439
+ }, {
2440
+ l: 'yy',
2441
+ d: 365 * 86400000
2442
+ }];
2443
+ const Tl = T.length;
2444
+ let result;
2445
+ let out;
2446
+
2447
+ for (let i = 0; i < Tl; i += 1) {
2448
+ let t = T[i];
2449
+
2450
+ if (t.d) {
2451
+ result = (timeA - timeB) / t.d;
2452
+ }
2453
+
2454
+ let abs = Math.round(Math.abs(result));
2455
+
2456
+ if (abs <= t.r || !t.r) {
2457
+ if (abs <= 1 && i > 0) t = T[i - 1];
2458
+ out = loc[t.l].replace('%d', abs);
2459
+ break;
2460
+ }
2461
+ }
2462
+
2463
+ return out;
2464
+ }
2465
+ ;// CONCATENATED MODULE: ./src/chatbox/InfoMessage.js
2466
+
2467
+
2468
+ function getRateLang(rating) {
2469
+ if (!rating) return 'poor';
2470
+ if (rating < 2) return 'poor';
2471
+ if (rating < 4) return 'average';
2472
+ return 'great';
2473
+ }
2474
+
2475
+
2476
+
2477
+
2478
+ class InfoMessage extends common/* Com */.M {
2479
+ render() {
2480
+ let ev = this.props.ev.ev;
2481
+ var $time = null;
2482
+
2483
+ if (this.props.ev.show_time) {
2484
+ $time = (0,preact_module.h)("div", {
2485
+ class: "convo-event-time"
2486
+ }, (0,preact_module.h)(Time, {
2487
+ time: ev.created
2488
+ }));
2489
+ }
2490
+
2491
+ if (ev.type === 'conversation_rated') {
2492
+ var rating = util/* default.get */.Z.get(ev, 'data.conversation.ratings.0', {
2493
+ no_rating: true,
2494
+ rating: 0
2495
+ });
2496
+ if (rating.no_rating) return null;
2497
+ return (0,preact_module.h)("div", {
2498
+ class: "convo-event"
2499
+ }, $time, (0,preact_module.h)("div", {
2500
+ class: "info-message"
2501
+ }, this.props.t('rated_as') + ' ' + this.props.t(getRateLang(rating.rating)).toLowerCase()));
2502
+ }
2503
+
2504
+ if (ev.type === 'conversation_state_updated' && util/* default.get */.Z.get(ev, 'data.conversation.state') === 'ended') {
2505
+ return (0,preact_module.h)("div", {
2506
+ class: "convo-event"
2507
+ }, $time, (0,preact_module.h)("div", {
2508
+ class: "info-message"
2509
+ }, this.props.t('conversation_ended')));
2510
+ }
2511
+
2512
+ return null;
2513
+ }
2514
+
2515
+ }
2516
+ ;// CONCATENATED MODULE: ./src/chatbox/Event.js
2517
+
2518
+
2519
+
2520
+
2521
+
2522
+
2523
+
2524
+
2525
+
2526
+
2527
+
2528
+
2529
+
2530
+
2531
+
2532
+
2533
+
2534
+ class Event extends common/* Com */.M {
2535
+ constructor(props) {
2536
+ super(props);
2537
+ this.refForm = (0,preact_module/* createRef */.Vf)();
2538
+ }
2539
+
2540
+ render() {
2541
+ var ev = util/* default.get */.Z.get(this.props.event, 'ev', {});
2542
+
2543
+ switch (ev.type) {
2544
+ case 'conversation_joined':
2545
+ break;
2546
+
2547
+ case 'message_sent':
2548
+ return this.renderMessageSent();
2549
+
2550
+ case 'conversation_state_updated':
2551
+ case 'conversation_rating_requested':
2552
+ case 'conversation_rated':
2553
+ if (!util/* default.startsWith */.Z.startsWith(ev.id, 'ev')) return null;
2554
+ return (0,preact_module.h)(InfoMessage, {
2555
+ t: this.props.t,
2556
+ store: this.props.store,
2557
+ ev: this.props.event
2558
+ });
2559
+ }
2560
+
2561
+ return null;
2562
+ }
2563
+
2564
+ focus() {
2565
+ this.refForm.current && this.refForm.current.focus();
2566
+ }
2567
+
2568
+ chooseQuickReply(reply) {
2569
+ let ev = util/* default.get */.Z.get(this.props.event, 'ev', {});
2570
+ let message = {
2571
+ text: reply.title,
2572
+ format: 'plaintext'
2573
+ };
2574
+
2575
+ if (reply.payload) {
2576
+ message.attachments = [{
2577
+ type: 'postback',
2578
+ postback: {
2579
+ event_id: ev.id,
2580
+ payload: reply.payload
2581
+ }
2582
+ }];
2583
+ }
2584
+
2585
+ this.props.onSend(message);
2586
+ }
2587
+
2588
+ choosePostbackBtn(button) {
2589
+ let ev = util/* default.get */.Z.get(this.props.event, 'ev', {});
2590
+ let message = {
2591
+ text: button.title,
2592
+ format: 'plaintext'
2593
+ };
2594
+
2595
+ if (button.payload) {
2596
+ message.attachments = [{
2597
+ type: 'postback',
2598
+ postback: {
2599
+ event_id: ev.id,
2600
+ payload: button.payload
2601
+ }
2602
+ }];
2603
+ }
2604
+
2605
+ this.props.onSend(message);
2606
+ }
2607
+
2608
+ renderAgentAvatar(ev) {
2609
+ let bytype = util/* default.get */.Z.get(ev, 'by.type');
2610
+ let byid = util/* default.get */.Z.get(ev, 'by.display_id', util/* default.get */.Z.get(ev, 'by.id'));
2611
+ if (bytype === 'user') return null;
2612
+ var senderName = this.getSenderName(ev);
2613
+ let acc = this.props.store.matchAccount();
2614
+
2615
+ var uri = acc.logo_url || __webpack_require__(9895);
2616
+
2617
+ let agentM = this.props.store.matchAgent('*');
2618
+
2619
+ if (byid !== 'system' || bytype !== 'dummy') {
2620
+ uri = util/* default.get */.Z.get(agentM[byid], 'avatar_url') || acc.logo_url || __webpack_require__(4761);
2621
+ }
2622
+
2623
+ return (0,preact_module.h)("div", {
2624
+ class: "message-sender"
2625
+ }, (0,preact_module.h)("img", {
2626
+ alt: "sender",
2627
+ class: "message-sender-avatar",
2628
+ src: this.props.store.replaceFileUrl(uri)
2629
+ }), (0,preact_module.h)("p", {
2630
+ class: "message-sender-name"
2631
+ }, senderName));
2632
+ }
2633
+
2634
+ renderMessageSent() {
2635
+ let ev = this.props.event.ev;
2636
+ var $time = null;
2637
+
2638
+ if (this.props.event.show_time) {
2639
+ $time = (0,preact_module.h)("div", {
2640
+ class: "convo-event-time"
2641
+ }, (0,preact_module.h)(Time, {
2642
+ time: ev.created
2643
+ }));
2644
+ }
2645
+
2646
+ let t = new util/* default.Date */.Z.Date(ev.created).toLocaleString();
2647
+
2648
+ if (util/* default.get */.Z.get(ev, 'by.type') !== 'user') {
2649
+ let $sender = null;
2650
+ if (this.props.event.mode === 'lead') $sender = this.renderAgentAvatar(ev);
2651
+ return (0,preact_module.h)("div", {
2652
+ class: "convo-event agent-message",
2653
+ title: t
2654
+ }, $time, $sender, (0,preact_module.h)(TextMessage, {
2655
+ store: this.props.store,
2656
+ ev: ev
2657
+ }), (0,preact_module.h)(ImageAttachment, {
2658
+ store: this.props.store,
2659
+ ev: ev
2660
+ }), (0,preact_module.h)(AudioAttachments, {
2661
+ store: this.props.store,
2662
+ ev: ev
2663
+ }), (0,preact_module.h)(VideoAttachments, {
2664
+ store: this.props.store,
2665
+ ev: ev
2666
+ }), (0,preact_module.h)(FileAttachments, {
2667
+ store: this.props.store,
2668
+ ev: ev
2669
+ }), (0,preact_module.h)(ButtonAttachments, {
2670
+ store: this.props.store,
2671
+ ev: ev
2672
+ }), (0,preact_module.h)(FormAttachments, {
2673
+ store: this.props.store,
2674
+ onSubmit: this.props.onFormSubmit,
2675
+ ref: this.refForm,
2676
+ ev: ev,
2677
+ t: this.props.t
2678
+ }), (0,preact_module.h)(FormSubmitAttachments, {
2679
+ store: this.props.store,
2680
+ ev: ev,
2681
+ t: this.props.t
2682
+ }), (0,preact_module.h)(GenericTemplateAttachments, {
2683
+ store: this.props.store,
2684
+ ev: ev,
2685
+ onSelect: e => this.choosePostbackBtn(e)
2686
+ }), (0,preact_module.h)(ProductAttachments, {
2687
+ t: this.props.t,
2688
+ store: this.props.store,
2689
+ ev: ev
2690
+ }), (0,preact_module.h)(OrderAttachments_ProductAttachments, {
2691
+ t: this.props.t,
2692
+ store: this.props.store,
2693
+ ev: ev
2694
+ }), (0,preact_module.h)(QuickReplies, {
2695
+ store: this.props.store,
2696
+ ev: ev,
2697
+ onSelect: e => this.chooseQuickReply(e)
2698
+ }));
2699
+ }
2700
+
2701
+ if (util/* default.getMsgField */.Z.getMsgField(ev, 'idempotency') === ev.id && this.props.store.now() - ev.created < 900) {
2702
+ setTimeout(() => this.setState({
2703
+ refresh: this.state.refresh
2704
+ }), 1000);
2705
+ }
2706
+
2707
+ let $dot = (0,preact_module.h)("div", {
2708
+ class: "sending_dot"
2709
+ });
2710
+
2711
+ if (this.props.store.now() - ev.created < 900 || util/* default.getMsgField */.Z.getMsgField(ev, 'idempotency') !== ev.id) {
2712
+ $dot = (0,preact_module.h)("div", {
2713
+ class: "sending_dot sending_dot__hide"
2714
+ });
2715
+ }
2716
+
2717
+ let $sender = null;
2718
+ if (this.props.event.mode === 'lead') $sender = (0,preact_module.h)("div", {
2719
+ class: "pt-3"
2720
+ });
2721
+ let $error = null;
2722
+
2723
+ if (ev._error && ev.type === 'message_sent') {
2724
+ $error = (0,preact_module.h)("a", {
2725
+ class: "message_error",
2726
+ src: "javascript:;",
2727
+ onClick: e => this.resendMessage()
2728
+ }, (0,preact_module.h)("div", {
2729
+ class: "message_error__text"
2730
+ }, this.props.t('error_send_message')), (0,preact_module.h)("div", {
2731
+ class: "message_error__icon"
2732
+ }));
2733
+ }
2734
+
2735
+ return (0,preact_module.h)("div", {
2736
+ class: "convo-event user-message",
2737
+ title: t
2738
+ }, $time, $sender, (0,preact_module.h)("div", {
2739
+ class: "message-user__container"
2740
+ }, $dot, (0,preact_module.h)(TextMessage, {
2741
+ store: this.props.store,
2742
+ ev: ev,
2743
+ refresh: this.state.refresh
2744
+ }), (0,preact_module.h)(ImageAttachment, {
2745
+ store: this.props.store,
2746
+ ev: ev
2747
+ }), (0,preact_module.h)(AudioAttachments, {
2748
+ store: this.props.store,
2749
+ ev: ev
2750
+ }), (0,preact_module.h)(VideoAttachments, {
2751
+ store: this.props.store,
2752
+ ev: ev
2753
+ }), (0,preact_module.h)(FileAttachments, {
2754
+ store: this.props.store,
2755
+ ev: ev
2756
+ }), (0,preact_module.h)(ButtonAttachments, {
2757
+ store: this.props.store,
2758
+ ev: ev
2759
+ }), (0,preact_module.h)(FormAttachments, {
2760
+ store: this.props.store,
2761
+ onSubmit: this.props.onFormSubmit,
2762
+ ref: this.refForm,
2763
+ ev: ev
2764
+ }), (0,preact_module.h)(ProductAttachments, {
2765
+ t: this.props.t,
2766
+ store: this.props.store,
2767
+ ev: ev
2768
+ }), (0,preact_module.h)(FormSubmitAttachments, {
2769
+ store: this.props.store,
2770
+ ev: ev
2771
+ })), $error);
2772
+ }
2773
+
2774
+ renderUpdateConvo(ev) {
2775
+ var state = util/* default.get */.Z.get(ev, 'data.conversation.state');
2776
+ if (state === 'active') return null;
2777
+ if (state === 'pending') return null;
2778
+ return (0,preact_module.h)("div", {
2779
+ class: "message-system"
2780
+ }, this.props.t('conversation_state_updated', {
2781
+ state
2782
+ }));
2783
+ }
2784
+
2785
+ resendMessage() {
2786
+ let cid = util/* default.convoOfEv */.Z.convoOfEv(this.props.event.ev);
2787
+ const message = util/* default.get */.Z.get(this.props.event, 'ev.data.message');
2788
+ this.props.store.sendConvoEvent(cid, 'message_sent', {
2789
+ message
2790
+ });
2791
+ }
2792
+
2793
+ getSenderName(ev) {
2794
+ let bytype = util/* default.get */.Z.get(ev, 'by.type');
2795
+ let byid = util/* default.get */.Z.get(ev, 'by.display_id', util/* default.get */.Z.get(ev, 'by.id'));
2796
+ if (byid === 'system' || bytype === 'dummy') return 'system';
2797
+ let user = this.props.store.matchUser();
2798
+ let acc = this.props.store.matchAccount();
2799
+ if (bytype === 'user') return util/* default.getUserDisplayName */.Z.getUserDisplayName(user);
2800
+ if (bytype === 'agent') return util/* default.getAgentDisplayName */.Z.getAgentDisplayName(acc, this.props.store.matchAgent(byid));
2801
+ return '';
2802
+ }
2803
+
2804
+ }
2805
+ ;// CONCATENATED MODULE: ./src/chatbox/spinner.js
2806
+ const loadingimg = __webpack_require__(6484);
2807
+
2808
+
2809
+
2810
+ class Spinner extends common/* Com */.M {
2811
+ render() {
2812
+ let mode = (this.props.mode + '').toLowerCase();
2813
+ let mainColor = mode === 'dark' ? '#000000dd' : mode === 'blue' ? 'rgba(52, 152, 220, .8)' : '#ffffffdd';
2814
+ let borderColor = mode === 'dark' ? '#00000055' : mode === 'blue' ? 'rgba(52, 152, 220, .15)' : '#ffffff55';
2815
+ let size = this.props.size || 14;
2816
+ let borderWidth = Math.ceil(size / 14);
2817
+ let style = `width: ${size}px !important;height: ${size}px!important;color: ${borderColor} !important;border-width: ${borderWidth}px !important;
2818
+ border-left-color: ${borderColor} !important;border-top-color: ${borderColor} !important;
2819
+ border-bottom-color: ${borderColor} !important;border-right-color: ${mainColor} !important;`;
2820
+
2821
+ if (this.props.static) {
2822
+ let style = `width: ${size}px;height: ${size}px;`;
2823
+ if (size < 40) return (0,preact_module.h)(LoaderIcon, {
2824
+ size: size + '',
2825
+ style: `stroke:${mainColor}`
2826
+ });
2827
+
2828
+ if (this.props.center) {
2829
+ return (0,preact_module.h)("div", {
2830
+ class: "loading"
2831
+ }, (0,preact_module.h)("img", {
2832
+ alt: "loading",
2833
+ style: style,
2834
+ src: loadingimg
2835
+ }));
2836
+ }
2837
+
2838
+ return (0,preact_module.h)("img", {
2839
+ alt: "loading",
2840
+ style: style,
2841
+ src: loadingimg
2842
+ });
2843
+ }
2844
+
2845
+ return (0,preact_module.h)("div", {
2846
+ class: "spinner1",
2847
+ style: style
2848
+ });
2849
+ }
2850
+
2851
+ }
2852
+ ;// CONCATENATED MODULE: ./src/chatbox/Events.js
2853
+
2854
+
2855
+
2856
+ const convoemptyimg = __webpack_require__(6188);
2857
+
2858
+
2859
+
2860
+
2861
+
2862
+ class Events extends common/* Com */.M {
2863
+ constructor(props) {
2864
+ super(props);
2865
+ this.props.store.onUpdate(this, _ => this.forceUpdate());
2866
+ this.props.store.onConvoEvent(this, ev => this.onEvent(ev));
2867
+ this.loadConvo();
2868
+ this.refBody = null;
2869
+ this.checkAndSeen = util/* default.throttle */.Z.throttle(() => {
2870
+ if (this.props.isShow && this.isBottom() && this.props.store.browserVisibility === 'visible' && document.hasFocus()) {
2871
+ this.props.store.seenConvo(this.props.cid);
2872
+ }
2873
+ }, 500);
2874
+ this.checkAndSeen();
2875
+ }
2876
+
2877
+ componentDidUpdate(prevProps) {
2878
+ if (prevProps.cid !== this.props.cid) this.loadConvo();
2879
+ }
2880
+
2881
+ render() {
2882
+ if (this.state.error) return this.renderError();
2883
+ let events = util/* default.map */.Z.map(this.props.store.listEvents(this.props.cid));
2884
+
2885
+ if (!this.state.loading && util/* default.size */.Z.size(events) === 0) {
2886
+ return (0,preact_module.h)("div", {
2887
+ ref: ref => this.refBody = ref,
2888
+ class: "widget-body--events-container"
2889
+ }, (0,preact_module.h)("div", {
2890
+ class: "widget-body--empty"
2891
+ }, (0,preact_module.h)("div", {
2892
+ class: "widget-body--empty-icon"
2893
+ }), (0,preact_module.h)("div", {
2894
+ class: "widget-body--empty-text"
2895
+ }, this.props.t('empty_convo_text'))), (0,preact_module.h)(PoweredBy, {
2896
+ store: this.props.store
2897
+ }));
2898
+ }
2899
+
2900
+ events = util/* default.orderBy */.Z.orderBy(events, 'created', 'asc');
2901
+ let convo = this.props.store.matchConvo(this.props.cid);
2902
+ events = util/* default.map */.Z.map(events, ev => ({
2903
+ ev: ev
2904
+ }));
2905
+ processEvents(convo, events);
2906
+ let $events = util/* default.map */.Z.map(events, ev => (0,preact_module.h)(Event, {
2907
+ store: this.props.store,
2908
+ onFormSubmit: this.props.onFormSubmit,
2909
+ onSend: this.props.onSend,
2910
+ onPostback: this.props.onPostback,
2911
+ event: ev,
2912
+ t: this.props.t,
2913
+ key: ev.ev.id
2914
+ }));
2915
+ let $loading = null;
2916
+ let style = 'opacity: 1 !important';
2917
+
2918
+ if (this.state.loading || this.props.creating) {
2919
+ $loading = (0,preact_module.h)(Spinner, {
2920
+ static: true,
2921
+ mode: "blue",
2922
+ size: "120",
2923
+ center: true
2924
+ });
2925
+ style = 'opacity: 0 !important';
2926
+ }
2927
+
2928
+ return (0,preact_module.h)(preact_module/* Fragment */.HY, null, $loading, (0,preact_module.h)("div", {
2929
+ style: style,
2930
+ ref: ref => this.refBody = ref,
2931
+ class: "widget-body--events-container",
2932
+ onMouseOver: this.checkAndSeen
2933
+ }, (0,preact_module.h)("div", {
2934
+ class: "widget-body--events"
2935
+ }, $events), (0,preact_module.h)(PoweredBy, {
2936
+ store: this.props.store
2937
+ })));
2938
+ }
2939
+
2940
+ renderError() {
2941
+ let $tryAgainBtn = (0,preact_module.h)("a", {
2942
+ href: "#",
2943
+ onclick: _ => this.loadConvo()
2944
+ }, this.props.t('try_again'));
2945
+ if (this.state.loading) $tryAgainBtn = (0,preact_module.h)(Spinner, {
2946
+ size: "16",
2947
+ mode: "blue"
2948
+ });
2949
+ return (0,preact_module.h)("div", {
2950
+ class: "widget-body--events-container widget-body--events-container__error"
2951
+ }, (0,preact_module.h)("img", {
2952
+ alt: "empty",
2953
+ src: convoemptyimg
2954
+ }), (0,preact_module.h)("div", {
2955
+ class: "widget_body__events__error_msg"
2956
+ }, this.props.t('load_convo_error')), (0,preact_module.h)("div", {
2957
+ class: "widget_body__events__error_retry"
2958
+ }, $tryAgainBtn));
2959
+ }
2960
+
2961
+ focus() {
2962
+ let events = this.props.store.listEvents(this.props.cid);
2963
+ events = util/* default.orderBy */.Z.orderBy(util/* default.map */.Z.map(events), 'created', 'desc');
2964
+ var last_agent_sent;
2965
+
2966
+ for (let ev of events) {
2967
+ if (util/* default.get */.Z.get(ev, 'type') !== 'message_sent') continue;
2968
+ if (util/* default.get */.Z.get(ev, 'by.type') === 'user') continue;
2969
+ last_agent_sent = ev;
2970
+ break;
2971
+ }
2972
+
2973
+ if (util/* default.get */.Z.get(last_agent_sent, 'by.type') === 'user') last_agent_sent = null;
2974
+ let attachments = util/* default.get */.Z.get(last_agent_sent, 'data.message.attachments', []);
2975
+ let convo = this.props.store.matchConvo(this.props.cid);
2976
+ let pendingForms = util/* default.filter */.Z.filter(attachments, att => {
2977
+ if (!att) return false;
2978
+ if (att.type !== 'form' && att.type !== 'ask_info_form') return false;
2979
+ var form = att.form;
2980
+ if (!form) return false;
2981
+ var state = util/* default.parseJSON */.Z.parseJSON(form.state) || {};
2982
+ if (!state.require_finished && att.type !== 'ask_info_form') return false;
2983
+ if (Events_isSummited(att.form)) return false;
2984
+ if (convo.state === 'ended') return false;
2985
+ return true;
2986
+ });
2987
+ }
2988
+
2989
+ onEvent(newev) {
2990
+ if (util/* default.convoOfEv */.Z.convoOfEv(newev) !== this.props.cid) return;
2991
+ let isBottom = this.isBottom();
2992
+ var byme = false;
2993
+ if (util/* default.get */.Z.get(newev, 'type') === 'message_sent' && newev.id === util/* default.getMsgField */.Z.getMsgField(newev, 'idempotency')) byme = true;
2994
+ if (byme || isBottom) this.scrollToBottom();
2995
+ }
2996
+
2997
+ async loadConvo() {
2998
+ if (!this.props.cid) return;
2999
+ this.lastContentOffsetY = 0;
3000
+ this.setState({
3001
+ loading: true
3002
+ });
3003
+ let events = this.props.store.listEvents(this.props.cid);
3004
+
3005
+ if (util/* default.size */.Z.size(events) === 0) {
3006
+ let cid = this.props.cid;
3007
+ let {
3008
+ error
3009
+ } = await this.props.store.fetchMoreEvents(cid);
3010
+ this.setState({
3011
+ loading: false
3012
+ });
3013
+ if (cid !== this.props.cid) return;
3014
+
3015
+ if (error) {
3016
+ this.setState({
3017
+ error: true
3018
+ });
3019
+ return;
3020
+ }
3021
+ }
3022
+
3023
+ this.setState({
3024
+ loading: true
3025
+ });
3026
+ this.props.store.fetchMoreEvents(this.props.cid);
3027
+ this.setState({
3028
+ error: false
3029
+ });
3030
+ this.scrollToBottom();
3031
+ setTimeout(() => this.setState({
3032
+ loading: false
3033
+ }), 50);
3034
+ }
3035
+
3036
+ isBottom() {
3037
+ let $container = this.refBody;
3038
+ if (!$container) return false;
3039
+ return $container.scrollHeight < $container.scrollTop + $container.offsetHeight + 50;
3040
+ }
3041
+
3042
+ scrollToBottom() {
3043
+ setTimeout(() => {
3044
+ const $div = this.refBody;
3045
+ if ($div) $div.scrollTop = $div.scrollHeight;
3046
+ });
3047
+ setTimeout(() => {
3048
+ const $div = this.refBody;
3049
+ if ($div) $div.scrollTop = $div.scrollHeight;
3050
+ }, 200);
3051
+
3052
+ if (this.props.isShow) {
3053
+ if (this.props.store.browserVisibility === 'visible' && document.hasFocus()) {
3054
+ this.props.store.seenConvo(this.props.cid);
3055
+ }
3056
+ }
3057
+ }
3058
+
3059
+ }
3060
+
3061
+ function processEvents(convo, events) {
3062
+ events = events.filter(event => visibleEvent(event.ev));
3063
+ if (events.length < 1) return;
3064
+
3065
+ for (var i = 1; i < events.length; i++) {
3066
+ let curEvent = events[i];
3067
+ let lastEvent = events[i - 1];
3068
+
3069
+ if (visibleEvent(curEvent.ev)) {
3070
+ let elapsedSec = util/* default.unixSec */.Z.unixSec(curEvent.ev.created) - util/* default.unixSec */.Z.unixSec(lastEvent.ev.created);
3071
+ if (elapsedSec > 120) curEvent.show_time = true;
3072
+ }
3073
+ }
3074
+
3075
+ for (var i = 0; i < events.length; i++) {
3076
+ let curEvent = events[i];
3077
+
3078
+ if (util/* default.get */.Z.get(curEvent, 'ev.type') === 'message_sent') {
3079
+ curEvent.show_time = true;
3080
+ break;
3081
+ }
3082
+ }
3083
+
3084
+ for (var i = 0; i < events.length; i++) {
3085
+ let curEvent = events[i];
3086
+ let prevEvent = events[i - 1];
3087
+
3088
+ if (curEvent.ev.type === 'message_sent') {
3089
+ curEvent.mode = 'lead';
3090
+
3091
+ if (util/* default.get */.Z.get(prevEvent, 'ev.type') === 'message_sent' && util/* default.get */.Z.get(prevEvent, 'ev.by.id') === util/* default.get */.Z.get(curEvent, 'ev.by.id')) {
3092
+ curEvent.mode = 'follow';
3093
+ }
3094
+
3095
+ continue;
3096
+ }
3097
+ }
3098
+ }
3099
+
3100
+ function visibleEvent(ev) {
3101
+ let type = util/* default.get */.Z.get(ev, 'type');
3102
+ return type === 'message_sent' || type === 'conversation_state_updated';
3103
+ }
3104
+
3105
+ function Events_isSummited(form) {
3106
+ let fields = util/* default.get */.Z.get(form, 'fields') || [];
3107
+ return util/* default.find */.Z.find(fields, field => !!field.answered);
3108
+ }
3109
+ ;// CONCATENATED MODULE: ./src/chatbox/Typing.js
3110
+
3111
+
3112
+
3113
+ class Typing extends common/* Com */.M {
3114
+ constructor(props) {
3115
+ super(props);
3116
+ }
3117
+
3118
+ componentDidMount() {
3119
+ this.setState({
3120
+ isShow: false,
3121
+ ev: {}
3122
+ });
3123
+ this.props.store.onConvoEvent(this, ev => {
3124
+ if (util/* default.convoOfEv */.Z.convoOfEv(ev) !== this.props.cid) return;
3125
+ let user = this.props.store.matchUser();
3126
+ if (util/* default.get */.Z.get(ev, 'by.id') === user.id) return;
3127
+ let oldby = util/* default.get */.Z.get(this.state.ev, 'by.id');
3128
+ if (oldby && util/* default.get */.Z.get(ev, 'by.id') !== oldby) return;
3129
+
3130
+ if (util/* default.get */.Z.get(ev, 'type') === 'message_sent') {
3131
+ if (this.timer) clearTimeout(this.timer);
3132
+ this.timer = null;
3133
+ this.setState({
3134
+ isShow: false
3135
+ });
3136
+ return;
3137
+ }
3138
+
3139
+ if (util/* default.get */.Z.get(ev, 'type') !== 'conversation_typing') return;
3140
+ this.setState({
3141
+ ev: ev,
3142
+ isShow: true
3143
+ });
3144
+ if (this.timer) clearTimeout(this.timer);
3145
+ this.timer = setTimeout(() => {
3146
+ if (util/* default.convoOfEv */.Z.convoOfEv(ev) !== this.props.cid) return;
3147
+ this.timer = null;
3148
+ this.setState({
3149
+ isShow: false
3150
+ });
3151
+ }, 10000);
3152
+ });
3153
+ }
3154
+
3155
+ render() {
3156
+ let account = this.props.store.matchAccount();
3157
+ var cls = this.state.isShow ? '' : 'typing--hidden';
3158
+ let byid = util/* default.get */.Z.get(this.state.ev, 'by.display_id', util/* default.get */.Z.get(this.state.ev, 'by.id'));
3159
+ let agentName = util/* default.getAgentDisplayName */.Z.getAgentDisplayName(account, this.props.store.matchAgent(byid));
3160
+ return (0,preact_module.h)("div", {
3161
+ class: `typing ${cls}`
3162
+ }, agentName, " ", this.props.t('typing'));
3163
+ }
3164
+
3165
+ }
3166
+ ;// CONCATENATED MODULE: ./src/chatbox/releaseAnimation.js
3167
+
3168
+ /* harmony default export */ const releaseAnimation = (class {
3169
+ constructor(config) {
3170
+ this.duration = config.duration || 100;
3171
+ this.breakingV = config.breakingV || 7.0;
3172
+ this.maxY = config.maxY || 500;
3173
+ this.minY = config.minY || 0;
3174
+ }
3175
+
3176
+ play(v, y0, cb) {
3177
+ this.stop();
3178
+ var t0;
3179
+
3180
+ var run = t => {
3181
+ if (!t) t = new util/* default.Date */.Z.Date().getTime();
3182
+ var deltaT = t - t0;
3183
+ var [newy, done] = this.calcY(v, y0, deltaT);
3184
+ cb(newy);
3185
+ if (done) return this.stop();
3186
+ this.animationframe = window.requestAnimationFrame(run);
3187
+ };
3188
+
3189
+ this.animationframe = window.requestAnimationFrame(t => {
3190
+ t0 = t || new util/* default.Date */.Z.Date().getTime();
3191
+ run(t0);
3192
+ });
3193
+ }
3194
+
3195
+ calcY(v, y0, t) {
3196
+ var towardY;
3197
+ if (y0 > this.maxY) towardY = this.maxY;else if (y0 < this.minY) towardY = this.minY;else if (Math.abs(v) < this.breakingV) {
3198
+ if (Math.abs(this.maxY - y0) < Math.abs(this.minY - y0)) {
3199
+ towardY = this.maxY;
3200
+ } else {
3201
+ towardY = this.minY;
3202
+ }
3203
+ } else {
3204
+ if (v < 0) towardY = this.maxY;else towardY = this.minY;
3205
+ }
3206
+ var y = linearTransform(y0, towardY, t, this.duration);
3207
+ return [y, eqFloat(y, towardY)];
3208
+ }
3209
+
3210
+ stop() {
3211
+ window.cancelAnimationFrame(this.animationframe);
3212
+ }
3213
+
3214
+ });
3215
+
3216
+ function linearTransform(from, to, t, duration) {
3217
+ if (eqFloat(from, to)) return from;
3218
+ var s = to - from;
3219
+ var v = s / duration;
3220
+ var x = from + v * t;
3221
+ if (from < to && x > to) x = to;else if (to < from && x < to) x = to;
3222
+ return x;
3223
+ }
3224
+
3225
+ function eqFloat(a, b) {
3226
+ return Math.abs(a - b) <= 0.001;
3227
+ }
3228
+ ;// CONCATENATED MODULE: ./src/chatbox/Rating.js
3229
+ function Rating_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3230
+
3231
+
3232
+
3233
+ const POPUP_MAX_HEIGHT = 400;
3234
+ const POPUP_HARD_MAX_HEIGHT = 500;
3235
+ const POPUP_MIN_HEIGHT = 0;
3236
+
3237
+
3238
+ class Rating extends common/* Com */.M {
3239
+ constructor(props) {
3240
+ super(props);
3241
+
3242
+ Rating_defineProperty(this, "state", {
3243
+ hide: true,
3244
+ ratingHeight: 0,
3245
+ overlayOpacity: 0.3,
3246
+ comment: ''
3247
+ });
3248
+
3249
+ this.refComment = (0,preact_module/* createRef */.Vf)();
3250
+ this.refRating = (0,preact_module/* createRef */.Vf)();
3251
+ this.refHandle = (0,preact_module/* createRef */.Vf)();
3252
+ }
3253
+
3254
+ componentDidMount() {
3255
+ this.props.store.onUpdate(this, () => {
3256
+ if (this.shoudDisplay()) this.open();
3257
+ });
3258
+ this.props.store.onConvoEvent(this, ev => {
3259
+ var cid = util/* default.convoOfEv */.Z.convoOfEv(ev);
3260
+ if (cid !== this.props.cid) return;
3261
+ if (this.shoudDisplay()) this.open();
3262
+ });
3263
+
3264
+ this.mouseUp = e => this.onMouseUp(e);
3265
+
3266
+ this.mouseMove = e => this.onMouseMove(e);
3267
+
3268
+ this.mouseDown = e => this.onMouseDown(e);
3269
+
3270
+ var $ratingHandle = this.refHandle.current;
3271
+ $ratingHandle.addEventListener('mousedown', this.mouseDown, {
3272
+ passive: true
3273
+ });
3274
+ $ratingHandle.addEventListener('touchstart', this.mouseDown, {
3275
+ passive: true
3276
+ });
3277
+ window.addEventListener('mouseup', this.mouseUp, {
3278
+ passive: true
3279
+ });
3280
+ window.addEventListener('touchend', this.mouseUp, {
3281
+ passive: true
3282
+ });
3283
+ window.addEventListener('mousemove', this.mouseMove, {
3284
+ passive: true
3285
+ });
3286
+ window.addEventListener('touchmove', this.mouseMove, {
3287
+ passive: true
3288
+ });
3289
+ this.animation = new releaseAnimation({
3290
+ maxY: POPUP_MAX_HEIGHT,
3291
+ minY: POPUP_MIN_HEIGHT,
3292
+ duration: 150
3293
+ });
3294
+ this.close();
3295
+ if (this.shoudDisplay() || this.props.forceView === 'rating') this.open();
3296
+ }
3297
+
3298
+ componentWillUnmount() {
3299
+ var $ratingHandle = this.refHandle.current;
3300
+ $ratingHandle.removeEventListener('mousedown', this.mouseDown, 0);
3301
+ $ratingHandle.removeEventListener('touchstart', this.mouseDown, 0);
3302
+ window.removeEventListener('mouseup', this.mouseUp, 0);
3303
+ window.removeEventListener('touchend', this.mouseUp, 0);
3304
+ window.removeEventListener('mousemove', this.mouseMove, 0);
3305
+ window.removeEventListener('touchmove', this.mouseMove, 0);
3306
+ }
3307
+
3308
+ render() {
3309
+ let cls = this.state.hide ? 'd-none' : '';
3310
+ return (0,preact_module.h)("div", {
3311
+ class: cls
3312
+ }, (0,preact_module.h)("div", {
3313
+ class: "rating--overlay",
3314
+ style: `opacity: ${this.state.overlayOpacity * 0.5} !important;`
3315
+ }), (0,preact_module.h)("div", {
3316
+ class: "rating",
3317
+ ref: this.refRating,
3318
+ style: `color:red; height: ${this.state.ratingHeight}px !important;`
3319
+ }, (0,preact_module.h)("div", {
3320
+ class: "rating--handle",
3321
+ ref: this.refHandle
3322
+ }, (0,preact_module.h)("div", {
3323
+ class: "rating--thumb"
3324
+ })), (0,preact_module.h)("div", {
3325
+ class: "rating--content"
3326
+ }, (0,preact_module.h)("div", {
3327
+ class: "rating--heading"
3328
+ }, this.props.t('rating_title'), (0,preact_module.h)("div", {
3329
+ class: "rating--close-btn",
3330
+ onClick: e => this.onCloseRating(e)
3331
+ })), (0,preact_module.h)("div", {
3332
+ class: "rating--description"
3333
+ }, this.props.t('rating_description')), (0,preact_module.h)("textarea", {
3334
+ ref: this.refComment,
3335
+ type: "text",
3336
+ class: "rating--comment"
3337
+ }), (0,preact_module.h)("div", {
3338
+ class: "rating-faces-container"
3339
+ }, (0,preact_module.h)("div", {
3340
+ class: "rating-face-container",
3341
+ onClick: e => this.onRatingPoor(e)
3342
+ }, (0,preact_module.h)("img", {
3343
+ alt: "poor",
3344
+ src: __webpack_require__(8367)
3345
+ }), (0,preact_module.h)("p", {
3346
+ class: "rating-face--text"
3347
+ }, this.props.t('poor'))), (0,preact_module.h)("div", {
3348
+ class: "rating-face-container",
3349
+ onClick: e => this.onRatingAverage(e)
3350
+ }, (0,preact_module.h)("img", {
3351
+ alt: "average",
3352
+ src: __webpack_require__(6535)
3353
+ }), (0,preact_module.h)("p", {
3354
+ class: "rating-face--text"
3355
+ }, this.props.t('average'))), (0,preact_module.h)("div", {
3356
+ class: "rating-face-container",
3357
+ onClick: e => this.onRatingGreat(e)
3358
+ }, (0,preact_module.h)("img", {
3359
+ alt: "great",
3360
+ src: __webpack_require__(3824)
3361
+ }), (0,preact_module.h)("p", {
3362
+ class: "rating-face--text"
3363
+ }, this.props.t('great')))), (0,preact_module.h)("div", {
3364
+ class: "rating-no-thanks",
3365
+ onClick: e => this.onCloseRating(e)
3366
+ }, this.props.t('no_thanks')))));
3367
+ }
3368
+
3369
+ shoudDisplay() {
3370
+ if (!this.props.cid) return false;
3371
+ var requested;
3372
+ var rated;
3373
+ var ended;
3374
+ let user = this.props.store.matchUser();
3375
+ util/* default.map */.Z.map(this.props.store.listEvents(this.props.cid), ev => {
3376
+ if (util/* default.get */.Z.get(ev, 'type') === 'conversation_state_updated' && util/* default.get */.Z.get(ev, 'data.conversation.state') === 'ended') {
3377
+ ended = ev;
3378
+ }
3379
+
3380
+ if (util/* default.get */.Z.get(ev, 'type') === 'conversation_rating_requested') requested = ev;
3381
+ if (util/* default.get */.Z.get(ev, 'type') === 'conversation_rated' && util/* default.get */.Z.get(ev, 'by.id') === user.id) rated = ev;
3382
+ });
3383
+ if (rated) return false;
3384
+ let accountSetting = this.props.plugin.chatbox;
3385
+ var auto = accountSetting.auto_request_rating && ended;
3386
+ return requested || auto;
3387
+ }
3388
+
3389
+ onCloseRating() {
3390
+ this.props.onRate && this.props.onRate({
3391
+ no_rating: true,
3392
+ comment: this.refComment.current.value
3393
+ });
3394
+ this.close();
3395
+ }
3396
+
3397
+ onRatingPoor() {
3398
+ this.props.onRate && this.props.onRate({
3399
+ rating: 1,
3400
+ comment: this.refComment.current.value
3401
+ });
3402
+ this.close();
3403
+ }
3404
+
3405
+ onRatingAverage() {
3406
+ this.props.onRate && this.props.onRate({
3407
+ rating: 3,
3408
+ comment: this.refComment.current.value
3409
+ });
3410
+ this.close();
3411
+ }
3412
+
3413
+ onRatingGreat() {
3414
+ this.props.onRate && this.props.onRate({
3415
+ rating: 5,
3416
+ comment: this.refComment.current.value
3417
+ });
3418
+ this.close();
3419
+ }
3420
+
3421
+ open() {
3422
+ if (!this.state.hide) return;
3423
+ this.setState({
3424
+ hide: false
3425
+ });
3426
+ if (!this.refRating.current) return;
3427
+ setTimeout(() => {
3428
+ if (this.refComment.current) this.refComment.current.focus();
3429
+ }, 400);
3430
+ this.refComment.current.value = '';
3431
+ var popupStyle = this.refRating.current.currentStyle || window.getComputedStyle(this.refRating.current);
3432
+ var h0 = parseFloat(popupStyle.height);
3433
+ this.animation.play(-20, h0, h => {
3434
+ this.setState({
3435
+ ratingHeight: h,
3436
+ overlayOpacity: Math.min(1, (h - POPUP_MIN_HEIGHT) / (POPUP_HARD_MAX_HEIGHT - POPUP_MIN_HEIGHT))
3437
+ });
3438
+ });
3439
+ }
3440
+
3441
+ close() {
3442
+ if (this.state.hide) return;
3443
+ if (!this.refRating.current) return;
3444
+ var popupStyle = this.refRating.current.currentStyle || window.getComputedStyle(this.refRating.current);
3445
+ var h0 = parseFloat(popupStyle.height);
3446
+ this.animation.play(20, h0, h => {
3447
+ this.setState({
3448
+ ratingHeight: h,
3449
+ overlayOpacity: Math.min(1, (h - POPUP_MIN_HEIGHT) / (POPUP_HARD_MAX_HEIGHT - POPUP_MIN_HEIGHT))
3450
+ });
3451
+
3452
+ if (h < POPUP_MIN_HEIGHT + 10) {
3453
+ if (!this.state.hide) {
3454
+ this.setState({
3455
+ hide: true
3456
+ });
3457
+ }
3458
+ }
3459
+ });
3460
+ }
3461
+
3462
+ onMouseDown(e) {
3463
+ this.mousePushed = true;
3464
+ this.animation.stop();
3465
+ e.preventDefault();
3466
+ if (e.touches && e.touches[0]) e = e.touches[0];
3467
+ this.mousePushedDy = e.pageY - window.pageYOffset - this.refRating.current.getBoundingClientRect().y;
3468
+ }
3469
+
3470
+ onMouseUp(e) {
3471
+ if (!this.mousePushed) return;
3472
+ if (e.touches && e.touches[0]) e = e.touches[0];
3473
+ this.mousePushed = false;
3474
+ var popupStyle = this.refRating.current.currentStyle || window.getComputedStyle(this.refRating.current);
3475
+ var h0 = parseFloat(popupStyle.height);
3476
+ this.animation.play(this.mouseVelocity, h0, h => {
3477
+ this.setState({
3478
+ ratingHeight: h,
3479
+ overlayOpacity: Math.min(1, (h - POPUP_MIN_HEIGHT) / (POPUP_HARD_MAX_HEIGHT - POPUP_MIN_HEIGHT))
3480
+ });
3481
+
3482
+ if (h < POPUP_MIN_HEIGHT + 10) {
3483
+ if (!this.state.hide) {
3484
+ this.setState({
3485
+ hide: true
3486
+ });
3487
+ this.props.onRate && this.props.onRate({
3488
+ no_rating: true
3489
+ });
3490
+ }
3491
+ }
3492
+ });
3493
+ }
3494
+
3495
+ onMouseMove(e) {
3496
+ if (!this.mousePushed) return;
3497
+ if (e.touches && e.touches[0]) e = e.touches[0];
3498
+ var my = e.pageY;
3499
+ this.mouseVelocity = my - this.lastMouseY;
3500
+ this.lastMouseY = my;
3501
+ my = my - this.mousePushedDy;
3502
+ var K = 10000;
3503
+ var height = this.refRating.current.getBoundingClientRect().bottom - my;
3504
+
3505
+ if (height > POPUP_MAX_HEIGHT) {
3506
+ var beta = K / (POPUP_HARD_MAX_HEIGHT - POPUP_MAX_HEIGHT) - POPUP_MAX_HEIGHT;
3507
+ height = POPUP_HARD_MAX_HEIGHT - K / (height + beta);
3508
+ }
3509
+
3510
+ this.setState({
3511
+ ratingHeight: height,
3512
+ overlayOpacity: Math.min(1, (height - POPUP_MIN_HEIGHT) / (POPUP_HARD_MAX_HEIGHT - POPUP_MIN_HEIGHT))
3513
+ });
3514
+ }
3515
+
3516
+ }
3517
+ ;// CONCATENATED MODULE: ./src/chatbox/Widget.js
3518
+
3519
+
3520
+
3521
+
3522
+
3523
+
3524
+ var send = __webpack_require__(9737);
3525
+
3526
+ var checkedimg = __webpack_require__(8909);
3527
+
3528
+ var empty = __webpack_require__(29);
3529
+
3530
+
3531
+
3532
+
3533
+
3534
+
3535
+ const Widget_defaultAvatar = 'https://file-subiz.com/fiqoahedjbgwclpouoml-avatar_default_baa8a1d7.png';
3536
+
3537
+
3538
+
3539
+
3540
+ class Widget extends common/* Com */.M {
3541
+ constructor(props) {
3542
+ super(props);
3543
+ this.userSent = {};
3544
+ this.setState({
3545
+ creating: false,
3546
+ clickedJoin: false,
3547
+ formData: {}
3548
+ });
3549
+ this.props.store.onUpdate(this, _ => this.forceUpdate());
3550
+ }
3551
+
3552
+ componentDidMount() {
3553
+ if (!this.props.store.isMobile()) this.focusInput();
3554
+ }
3555
+
3556
+ componentDidUpdate(prevProp) {
3557
+ if (prevProp.isShow !== this.props.isShow) {
3558
+ if (this.props.isShow && !this.props.store.isMobile()) this.focusInput();
3559
+ if (this.props.isShow && this.props.store.isMobile()) this.blur();
3560
+ }
3561
+
3562
+ if (prevProp.cid !== this.props.cid) {
3563
+ this.setState({
3564
+ clickedJoin: false
3565
+ });
3566
+ setTimeout(() => {
3567
+ this.events && this.events.focus();
3568
+ if (!this.props.store.isMobile()) this.focusInput();
3569
+ }, 100);
3570
+ }
3571
+
3572
+ this.updateFormDataFields();
3573
+ }
3574
+
3575
+ shouldShowForm() {
3576
+ let formRequired = this.isFormRequired();
3577
+ return formRequired && !this.props.cid || formRequired && this.props.cid && this.state.clickedJoin;
3578
+ }
3579
+
3580
+ render() {
3581
+ let formRequired = this.isFormRequired();
3582
+ let showform = this.shouldShowForm();
3583
+ let form;
3584
+ let accountSetting = this.props.plugin.chatbox || {};
3585
+ let acc = this.props.store.matchAccount() || {};
3586
+ let submitLabel = this.props.t('prechat_form_btn');
3587
+ if (util/* default.get */.Z.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form;
3588
+ let offlineEnabled = util/* default.get */.Z.get(accountSetting, 'offline_form.enabled');
3589
+
3590
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) {
3591
+ form = accountSetting.offline_form;
3592
+ submitLabel = this.props.t('offline_form_btn');
3593
+ }
3594
+
3595
+ if (this.props.view === 'offline_form') {
3596
+ showform = true;
3597
+ form = accountSetting.offline_form;
3598
+ submitLabel = this.props.t('offline_form_btn');
3599
+ }
3600
+
3601
+ if (this.props.view === 'prechat_form') {
3602
+ showform = true;
3603
+ form = accountSetting.prechat_form;
3604
+ submitLabel = this.props.t('prechat_form_btn');
3605
+ }
3606
+
3607
+ let $body = null;
3608
+ if (this.props.view === 'list') $body = this.renderConvoList();else if (showform) $body = this.renderForm(form, submitLabel);else $body = this.renderChat();
3609
+ let position = util/* default.get */.Z.get(accountSetting, 'desktop_button.position') || 'right';
3610
+ if (this.props.store.isMobile()) position = util/* default.get */.Z.get(accountSetting, 'mobile_button.position', position);
3611
+ let cls = 'widget-container widget-container--' + position;
3612
+ if (!this.props.isShow) cls += ' widget-container--hide';
3613
+ return (0,preact_module.h)("div", {
3614
+ class: cls
3615
+ }, (0,preact_module.h)(Header, {
3616
+ t: this.props.t,
3617
+ plugin: this.props.plugin,
3618
+ store: this.props.store,
3619
+ cid: this.props.cid,
3620
+ view: this.props.view,
3621
+ onClose: this.props.onClose,
3622
+ onGotoList: () => this.props.onGo({
3623
+ view: 'list'
3624
+ })
3625
+ }), $body);
3626
+ }
3627
+
3628
+ async submitPrechatForm(form) {
3629
+ var hasError = false;
3630
+ util/* default.map */.Z.map(this.state.formData, (field, key) => {
3631
+ if (field.is_required && (field.value === undefined || field.value === '' || util/* default.size */.Z.size(field.value) === 0 && Array.isArray(field.value))) {
3632
+ field.error = this.props.t('error_empty');
3633
+ hasError = true;
3634
+ } else field.error = '';
3635
+
3636
+ if (key.substr(5) === 'emails' && !util/* default.isEmail */.Z.isEmail(field.value) && field.is_required) {
3637
+ field.error = this.props.t('error_email_invalid');
3638
+ hasError = true;
3639
+ }
3640
+
3641
+ if (key.substr(5) === 'phones' && !util/* default.isPhone */.Z.isPhone(field.value) && field.is_required) {
3642
+ field.error = this.props.t('error_phone_invalid');
3643
+ hasError = true;
3644
+ }
3645
+ });
3646
+ if (hasError) return this.forceUpdate();
3647
+ let data = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
3648
+ let user = util/* default.cloneDeep */.Z.cloneDeep(this.props.store.matchUser());
3649
+ util/* default.map */.Z.map(data, (field, key) => {
3650
+ if (!key.startsWith('attr:')) return;
3651
+ var attr = {
3652
+ key: key.substr(5)
3653
+ };
3654
+ if (field.type === 'number') attr.number = parseInt(field.value);
3655
+ if (field.type === 'datetime') attr.datetime = new util/* default.Date */.Z.Date(field.value).toISOString();
3656
+ if (field.type === 'list') attr.list = field.value;
3657
+ if (field.type === 'text' || field.type === 'boolean') attr[field.type] = field.value;
3658
+ util/* default.setUserAttr */.Z.setUserAttr(user, attr);
3659
+ });
3660
+ let firstmsg = util/* default.get */.Z.get(data, 'question.value');
3661
+ let groupid = util/* default.get */.Z.get(data, 'group.value', '');
3662
+
3663
+ if (this.props.cid) {
3664
+ this.props.store.setUser(user);
3665
+ this.setState({
3666
+ clickedJoin: false
3667
+ });
3668
+ await this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
3669
+ message: {
3670
+ text: firstmsg,
3671
+ format: 'plaintext',
3672
+ fields: [{
3673
+ key: 'to_agent_group',
3674
+ value: util/* default.stringify */.Z.stringify(groupid)
3675
+ }]
3676
+ }
3677
+ });
3678
+ if (form.end_conversation_after_submit) await this.props.store.endConvo(this.props.cid);
3679
+ return;
3680
+ }
3681
+
3682
+ this.setState({
3683
+ creating: true
3684
+ });
3685
+ let message = {
3686
+ text: firstmsg,
3687
+ format: 'plaintext'
3688
+ };
3689
+ let req = {
3690
+ group_id: groupid,
3691
+ message: firstmsg,
3692
+ locale: this.props.t.locale(),
3693
+ initial_by: user.id
3694
+ };
3695
+ this.setState({
3696
+ creatingError: null
3697
+ });
3698
+ const {
3699
+ error,
3700
+ convo
3701
+ } = await this.props.store.startConvo(req);
3702
+ this.props.store.setUser(user);
3703
+
3704
+ if (error) {
3705
+ this.setState({
3706
+ creating: false,
3707
+ creatingError: error
3708
+ });
3709
+ return;
3710
+ }
3711
+
3712
+ let newconvoid = convo.id;
3713
+ this.userSent[newconvoid] = true;
3714
+ this.props.onGo({
3715
+ view: 'chat',
3716
+ cid: newconvoid
3717
+ });
3718
+ this.props.store.sendConvoEvent(newconvoid, 'message_sent', {
3719
+ message
3720
+ });
3721
+ this.setState({
3722
+ creating: false,
3723
+ clickedJoin: false
3724
+ });
3725
+ if (!this.props.store.isMobile()) this.focusInput();
3726
+ }
3727
+
3728
+ formMounted(form) {
3729
+ let formData = this.fillForm(form);
3730
+ formData['question'] = {
3731
+ key: 'question',
3732
+ is_required: true,
3733
+ label: this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_question_label`, {})) || form.question_label,
3734
+ type: 'text'
3735
+ };
3736
+ this.setState({
3737
+ formData
3738
+ });
3739
+ if (!this.props.store.isMobile()) this.focusInput();
3740
+ }
3741
+
3742
+ onBooleanChange(key, e) {
3743
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
3744
+ let field = util/* default.find */.Z.find(formData, (_, fkkey) => fkkey === key);
3745
+ if (!field) return;
3746
+ field.value = e.target.checked;
3747
+ this.setState({
3748
+ formData
3749
+ });
3750
+ }
3751
+
3752
+ onInputChange(key, val) {
3753
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
3754
+ let field = util/* default.find */.Z.find(formData, (_, fkkey) => fkkey === key);
3755
+ if (!field) return;
3756
+ field.value = val;
3757
+ this.setState({
3758
+ formData
3759
+ });
3760
+ }
3761
+
3762
+ onListAddItem(key, val) {
3763
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
3764
+ let field = util/* default.find */.Z.find(formData, (_, fkkey) => fkkey === key);
3765
+ if (!field) return;
3766
+ field.value = field.value || [];
3767
+ field.value.push(val);
3768
+ this.setState({
3769
+ formData
3770
+ });
3771
+ }
3772
+
3773
+ onListRemoveItem(key, index) {
3774
+ let formData = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
3775
+ let field = util/* default.find */.Z.find(formData, (_, fkkey) => fkkey === key);
3776
+ if (!field) return;
3777
+ field.value = field.value || [];
3778
+ field.value.splice(index, 1);
3779
+ this.setState({
3780
+ formData
3781
+ });
3782
+ }
3783
+
3784
+ renderFields() {
3785
+ if (util/* default.size */.Z.size(this.state.formData) === 0) return null;
3786
+ let $fields = util/* default.map */.Z.map(this.state.formData, (field, key) => {
3787
+ let $field = null;
3788
+ var errclass = field.error ? 'input--error' : '';
3789
+
3790
+ if (field.type === 'text') {
3791
+ if (key === 'question') {
3792
+ $field = (0,preact_module.h)("textarea", {
3793
+ class: "form-control",
3794
+ ref: ref => {
3795
+ this['form_' + Widget_encode(key)] = ref;
3796
+ },
3797
+ value: field.value || '',
3798
+ onInput: e => this.onInputChange(key, e.target.value),
3799
+ row: "4",
3800
+ class: "form-control"
3801
+ });
3802
+ } else {
3803
+ $field = (0,preact_module.h)("input", {
3804
+ value: field.value || '',
3805
+ onInput: e => this.onInputChange(key, e.target.value),
3806
+ ref: ref => {
3807
+ this['form_' + Widget_encode(key)] = ref;
3808
+ },
3809
+ class: `form-control ${errclass}`,
3810
+ type: "text"
3811
+ });
3812
+ }
3813
+ } else if (field.type === 'number') {
3814
+ $field = (0,preact_module.h)("input", {
3815
+ value: field.value,
3816
+ onInput: e => this.onInputChange(key, e.target.value),
3817
+ ref: ref => {
3818
+ this['form_' + Widget_encode(key)] = ref;
3819
+ },
3820
+ class: `form-control ${errclass}`,
3821
+ type: "number"
3822
+ });
3823
+ } else if (field.type === 'boolean') {
3824
+ $field = (0,preact_module.h)("div", {
3825
+ class: "checkbox"
3826
+ }, (0,preact_module.h)("input", {
3827
+ type: "checkbox",
3828
+ id: 'form-checkbox' + Widget_encode(key),
3829
+ onInput: e => this.onBooleanChange(key, e),
3830
+ checked: field.value
3831
+ }), (0,preact_module.h)("label", {
3832
+ class: "checkbox--label",
3833
+ for: 'form-checkbox' + Widget_encode(key)
3834
+ }, field.label), (0,preact_module.h)("div", {
3835
+ class: "checkbox--check"
3836
+ }, (0,preact_module.h)("div", null)));
3837
+ } else if (field.type === 'group') {
3838
+ $field = util/* default.map */.Z.map(field.list, item => (0,preact_module.h)("div", {
3839
+ class: "radio"
3840
+ }, (0,preact_module.h)("input", {
3841
+ type: "radio",
3842
+ id: 'form-radio' + Widget_encode(key) + Widget_encode(item.value),
3843
+ checked: field.value === item.value,
3844
+ onInput: e => this.onInputChange(key, item.value)
3845
+ }), (0,preact_module.h)("label", {
3846
+ class: "radio--label",
3847
+ for: 'form-radio' + Widget_encode(key) + Widget_encode(item.value)
3848
+ }, item.label), (0,preact_module.h)("div", {
3849
+ class: "radio--check"
3850
+ }, (0,preact_module.h)("div", {
3851
+ class: "inside"
3852
+ }))));
3853
+ } else if (field.type === 'list') {
3854
+ let selected = this.state.formData[key].value || [];
3855
+ let items = util/* default.filter */.Z.filter(util/* default.get */.Z.get(field, 'list', []), item => {
3856
+ return !util/* default.includes */.Z.includes(selected, item);
3857
+ });
3858
+ $field = (0,preact_module.h)(ListField, {
3859
+ selected: selected,
3860
+ items: items,
3861
+ onAddItem: item => this.onListAddItem(key, item),
3862
+ onRemoveItem: item => this.onListRemoveItem(key, item)
3863
+ });
3864
+ } else if (field.type === 'datetime') {
3865
+ $field = (0,preact_module.h)("input", {
3866
+ value: field.value,
3867
+ onInput: e => this.onInputChange(key, e.target.value),
3868
+ class: `form-control ${errclass}`,
3869
+ type: "date"
3870
+ });
3871
+ }
3872
+
3873
+ let label = '';
3874
+
3875
+ if (field.key === 'fullname') {
3876
+ label = this.props.t('fullname');
3877
+ } else if (field.key === 'emails') {
3878
+ label = this.props.t('email');
3879
+ } else if (field.key === 'phones') {
3880
+ label = this.props.t('phones');
3881
+ } else if (field.key === 'question') {
3882
+ label = field.label || this.props.t('your_question');
3883
+ }
3884
+
3885
+ if (field.label) label = field.label;
3886
+ return (0,preact_module.h)("div", null, (0,preact_module.h)("div", {
3887
+ class: "label"
3888
+ }, label, field.is_required ? (0,preact_module.h)("span", {
3889
+ class: "ml-1 red"
3890
+ }, "*") : ''), field.error ? (0,preact_module.h)("div", {
3891
+ class: "form-control--valid-input--error"
3892
+ }, field.error) : '', $field);
3893
+ });
3894
+ return (0,preact_module.h)("div", {
3895
+ class: "pt-2"
3896
+ }, $fields);
3897
+ }
3898
+
3899
+ renderForm(form, submitLabel) {
3900
+ let $loading = null;
3901
+ if (this.state.creating) $loading = (0,preact_module.h)("span", {
3902
+ class: "ml-2"
3903
+ }, (0,preact_module.h)(Spinner, {
3904
+ size: "16",
3905
+ mode: "white"
3906
+ }));
3907
+ let title = this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_title`, {}));
3908
+ if (!title) title = util/* default.get */.Z.get(form, 'title', this.props.t('capture_lead_title'));
3909
+ title = title.replace('↵', '');
3910
+ return (0,preact_module.h)("div", {
3911
+ class: "widget-body"
3912
+ }, (0,preact_module.h)(FormMounter, {
3913
+ form: form,
3914
+ onMount: f => this.formMounted(f)
3915
+ }), (0,preact_module.h)("div", {
3916
+ class: "widget-body--content flex-grow-1 pl-3 pr-3 d-flex flex-column"
3917
+ }, (0,preact_module.h)("div", {
3918
+ class: "flex-grow-1"
3919
+ }, (0,preact_module.h)("div", {
3920
+ class: "form mt-3 pl-3 pr-3 pt-3 pb-3 d-flex flex-column"
3921
+ }, (0,preact_module.h)("div", null, title), this.renderFields())), (0,preact_module.h)(PoweredBy, {
3922
+ store: this.props.store,
3923
+ t: this.props.t
3924
+ })), (0,preact_module.h)("div", {
3925
+ class: "message-input message-input--preform"
3926
+ }, (0,preact_module.h)("button", {
3927
+ class: "btn--start-convo",
3928
+ onClick: _ => this.submitPrechatForm(form)
3929
+ }, submitLabel, " ", $loading)));
3930
+ }
3931
+
3932
+ goToConvo(cid) {
3933
+ this.props.onGo({
3934
+ view: 'chat',
3935
+ cid
3936
+ });
3937
+ }
3938
+
3939
+ renderConvoList() {
3940
+ let convoM = this.props.store.matchConvo('*');
3941
+ var convos = util/* default.map */.Z.map(convoM, convo => this.props.store.matchConvo(convo.id));
3942
+ convos = util/* default.filter */.Z.filter(convos, convo => !!convo);
3943
+ convos = util/* default.orderBy */.Z.orderBy(convos, 'created', 'desc');
3944
+ var $convos = util/* default.map */.Z.map(convos, convo => {
3945
+ let ags = util/* default.filter */.Z.filter(convo.members, m => {
3946
+ return (m.type === 'agent' || m.type === 'bot') && m.membership === 'active';
3947
+ });
3948
+ let agentids = util/* default.map */.Z.map(ags, m => m.id);
3949
+ agentids = agentids || util/* default.agentsOfConvo */.Z.agentsOfConvo(convo)[0];
3950
+ return (0,preact_module.h)("div", {
3951
+ class: "convo-list--item",
3952
+ onClick: () => this.goToConvo(convo.id),
3953
+ key: convo.id
3954
+ }, (0,preact_module.h)(AgentsAvatar, {
3955
+ plugin: this.props.plugin,
3956
+ store: this.props.store,
3957
+ mode: "member",
3958
+ class: "d-flex flex-row",
3959
+ tooltipPos: "right",
3960
+ agent_ids: agentids
3961
+ }), this.renderConvoSummary(convo));
3962
+ });
3963
+ let $body = (0,preact_module.h)("div", {
3964
+ class: "convo-list--list"
3965
+ }, $convos);
3966
+
3967
+ if (util/* default.size */.Z.size(convos) === 0) {
3968
+ $body = (0,preact_module.h)("div", {
3969
+ class: "convo-list--list"
3970
+ }, (0,preact_module.h)("div", {
3971
+ class: "empty-container"
3972
+ }, (0,preact_module.h)("img", {
3973
+ alt: "empty",
3974
+ src: empty
3975
+ }), (0,preact_module.h)("div", {
3976
+ class: "empty-desc"
3977
+ }, this.props.t('empty_convo'))));
3978
+ }
3979
+
3980
+ return (0,preact_module.h)("div", {
3981
+ class: "convo-list"
3982
+ }, (0,preact_module.h)("div", {
3983
+ class: "convo-list--container"
3984
+ }, (0,preact_module.h)("div", {
3985
+ class: "convo-list--title"
3986
+ }, this.props.t('conversations')), $body), (0,preact_module.h)("div", {
3987
+ class: "convo-list--footer"
3988
+ }, (0,preact_module.h)("button", {
3989
+ class: "btn--start-convo",
3990
+ onClick: _ => this.goToConvo('')
3991
+ }, (0,preact_module.h)("span", null, this.props.t('start_conversation')), (0,preact_module.h)("img", {
3992
+ src: send,
3993
+ alt: "send button",
3994
+ width: "26",
3995
+ height: "26"
3996
+ })), (0,preact_module.h)(PoweredBy, {
3997
+ store: this.props.store
3998
+ })));
3999
+ }
4000
+
4001
+ blur() {
4002
+ if (this.props.store.isPreview) return;
4003
+ var $input = this.msgInput;
4004
+ if (!$input) return;
4005
+ setTimeout(() => $input && $input.blur());
4006
+ setTimeout(() => $input && $input.blur(), 300);
4007
+ }
4008
+
4009
+ focusInput() {
4010
+ if (this.props.store.isPreview) return;
4011
+
4012
+ if (this.shouldShowForm()) {
4013
+ let firstemptykey = '';
4014
+ util/* default.map */.Z.map(this.state.formData, (field, key) => {
4015
+ if (field.type !== 'text') return;
4016
+ if (firstemptykey) return;
4017
+ if (!field.value) firstemptykey = key;
4018
+ });
4019
+ setTimeout(() => {
4020
+ var $input = this['form_' + Widget_encode(firstemptykey)];
4021
+ if (!$input) return;
4022
+ $input.focus();
4023
+ }, 300);
4024
+ return;
4025
+ }
4026
+
4027
+ var $input = this.msgInput;
4028
+ if (!$input) return;
4029
+ setTimeout(() => $input.focus());
4030
+ setTimeout(() => $input.focus(), 300);
4031
+ }
4032
+
4033
+ onRate(rating) {
4034
+ if (!this.props.cid) return;
4035
+ this.props.store.sendConvoEvent(this.props.cid, 'conversation_rated', {
4036
+ conversation: {
4037
+ ratings: [rating]
4038
+ }
4039
+ });
4040
+ this.focusInput();
4041
+ }
4042
+
4043
+ async sendMessage(message) {
4044
+ let text = message.text;
4045
+
4046
+ if (!this.props.cid) {
4047
+ this.creating = true;
4048
+ const {
4049
+ convo,
4050
+ error
4051
+ } = await this.props.store.startConvo({
4052
+ locale: this.props.t.locale(),
4053
+ message: text,
4054
+ initial_by: this.props.store.matchUser().id
4055
+ });
4056
+
4057
+ if (error) {}
4058
+
4059
+ this.creating = false;
4060
+ this.props.store.sendConvoEvent(convo.id, 'message_sent', {
4061
+ message
4062
+ });
4063
+ this.props.onGo({
4064
+ view: 'chat',
4065
+ cid: convo.id
4066
+ });
4067
+ return;
4068
+ }
4069
+
4070
+ this.props.store.sendConvoEvent(this.props.cid, 'message_sent', {
4071
+ message
4072
+ });
4073
+ }
4074
+
4075
+ createPostback(postback) {
4076
+ this.props.store.createPostback(this.props.cid, postback);
4077
+ }
4078
+
4079
+ renderChat() {
4080
+ let $input = (0,preact_module.h)(MessageInput, {
4081
+ store: this.props.store,
4082
+ ref: ref => this.msgInput = ref,
4083
+ cid: this.props.cid,
4084
+ onSend: e => this.sendMessage(e),
4085
+ t: this.props.t
4086
+ });
4087
+ let convo = this.props.store.matchConvo(this.props.cid) || {};
4088
+
4089
+ if (this.isFormRequired() || convo.state === 'ended') {
4090
+ $input = (0,preact_module.h)("div", {
4091
+ class: "message-input message-input--preform"
4092
+ }, (0,preact_module.h)("button", {
4093
+ class: "btn--start-convo",
4094
+ onClick: e => this.onStartConvoClick(e)
4095
+ }, this.props.t('offline_preform_btn')));
4096
+ }
4097
+
4098
+ return (0,preact_module.h)("div", {
4099
+ class: "widget-body"
4100
+ }, (0,preact_module.h)("div", {
4101
+ class: "widget-body--content",
4102
+ onClick: e => this.onContainerClick(e)
4103
+ }, (0,preact_module.h)(Events, {
4104
+ isShow: this.props.isShow,
4105
+ store: this.props.store,
4106
+ onFormSubmit: e => this.onEventFormSubmit(e),
4107
+ ref: ref => this.events = ref,
4108
+ cid: this.props.cid,
4109
+ creating: this.creating,
4110
+ onSend: e => this.sendMessage(e),
4111
+ onPostback: e => this.createPostback(e),
4112
+ t: this.props.t
4113
+ }), (0,preact_module.h)(Typing, {
4114
+ store: this.props.store,
4115
+ cid: this.props.cid,
4116
+ t: this.props.t
4117
+ })), (0,preact_module.h)(Rating, {
4118
+ forceView: this.props.view,
4119
+ plugin: this.props.plugin,
4120
+ store: this.props.store,
4121
+ onRate: e => this.onRate(e),
4122
+ cid: this.props.cid,
4123
+ t: this.props.t
4124
+ }), $input);
4125
+ }
4126
+
4127
+ async onStartConvoClick() {
4128
+ var convo = this.props.store.matchConvo(this.props.cid) || {};
4129
+ if (convo.state === 'ended') return this.props.onGo({
4130
+ view: 'chat',
4131
+ cid: ''
4132
+ });
4133
+ this.setState({
4134
+ clickedJoin: true
4135
+ });
4136
+ }
4137
+
4138
+ onEventFormSubmit() {
4139
+ this.focusInput();
4140
+ }
4141
+
4142
+ onContainerClick() {
4143
+ var selection = window.getSelection();
4144
+ if (selection.toString().length > 0) return;
4145
+ if (!this.props.store.isMobile()) this.focusInput();
4146
+ }
4147
+
4148
+ isFormRequired() {
4149
+ let form;
4150
+ let accountSetting = this.props.plugin.chatbox || {};
4151
+ let acc = this.props.store.matchAccount() || {};
4152
+ if (util/* default.get */.Z.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form;
4153
+ let offlineEnabled = util/* default.get */.Z.get(accountSetting, 'offline_form.enabled');
4154
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) form = accountSetting.offline_form;
4155
+ if (!form) return false;
4156
+ let formData = this.fillForm(form);
4157
+ let convo = this.props.store.matchConvo(this.props.cid) || {};
4158
+ if (convo.state === 'ended') return true;
4159
+ if (this.userHasSent(this.props.cid)) return false;
4160
+ if (convo.state && convo.state !== 'pending') delete formData.group;
4161
+ return !!util/* default.find */.Z.find(formData, field => field.value == null || field.value === '');
4162
+ }
4163
+
4164
+ renderConvoSummary(convo) {
4165
+ let agentM = this.props.store.matchAgent('*');
4166
+ let ags = util/* default.filter */.Z.filter(convo.members, m => {
4167
+ return (m.type === 'agent' || m.type === 'bot') && m.membership === 'active';
4168
+ });
4169
+ let agentids = util/* default.map */.Z.map(ags, m => m.id);
4170
+ agentids = agentids || util/* default.agentsOfConvo */.Z.agentsOfConvo(convo)[0];
4171
+ let agents = util/* default.map */.Z.map(agentids, id => agentM[id] || {
4172
+ avatar_url: Widget_defaultAvatar,
4173
+ fullname: 'Offline Agent'
4174
+ });
4175
+ var name = util/* default.each */.Z.each(agents, ag => ag.fullname).join(', ');
4176
+ if (!name) name = this.props.store.matchAccount().name;
4177
+ if (!name) name = this.props.t('agent');
4178
+ var $you = null;
4179
+
4180
+ if (convo.lastSenderType === 'user') {
4181
+ $you = (0,preact_module.h)("span", {
4182
+ class: "yourmessage"
4183
+ }, this.props.t('you'), ":");
4184
+ }
4185
+
4186
+ let seen = util/* default.isConvoSeen */.Z.isConvoSeen(convo, this.props.store.matchUser().id);
4187
+ var lastmsg = this.renderMessagePreview(convo.last_message_sent || {
4188
+ data: {
4189
+ message: util/* default.get */.Z.get(convo, 'last_message')
4190
+ }
4191
+ });
4192
+ var time = util/* default.getMs */.Z.getMs(util/* default.get */.Z.get(convo, 'last_message_sent.created')) || util/* default.getMs */.Z.getMs(util/* default.get */.Z.get(convo, 'last_sent.created')) || util/* default.getMs */.Z.getMs(convo.created);
4193
+ var $tim = (0,preact_module.h)(Time, {
4194
+ ago: true,
4195
+ time: time,
4196
+ key: time,
4197
+ short: true
4198
+ });
4199
+ let $unread = seen ? null : (0,preact_module.h)("div", {
4200
+ class: "convo-list--item-unread"
4201
+ });
4202
+
4203
+ if (convo.state === 'ended') {
4204
+ $unread = (0,preact_module.h)("img", {
4205
+ alt: "conversation ended",
4206
+ class: "convo-list--convo-completed",
4207
+ src: checkedimg,
4208
+ title: this.props.t('conversation_ended')
4209
+ });
4210
+ }
4211
+
4212
+ return (0,preact_module.h)("div", {
4213
+ class: "convo-list--convo-last-info"
4214
+ }, (0,preact_module.h)("div", {
4215
+ class: "d-flex flex-row"
4216
+ }, (0,preact_module.h)("div", {
4217
+ class: "convo-list--convo-name"
4218
+ }, name), (0,preact_module.h)("div", {
4219
+ class: "convo-list--convo-time"
4220
+ }, $tim)), (0,preact_module.h)("div", {
4221
+ class: "d-flex flex-row"
4222
+ }, (0,preact_module.h)("div", {
4223
+ class: "convo-list--convo-last-message"
4224
+ }, $you, lastmsg), $unread));
4225
+ }
4226
+
4227
+ agentsOfConvo(convo) {
4228
+ let agentM = this.props.store.matchAgent('*');
4229
+ var agentids = util/* default.agentsOfConvo */.Z.agentsOfConvo(convo, true);
4230
+ return util/* default.map */.Z.map(agentids, id => agentM[id] || {
4231
+ avatar_url: Widget_defaultAvatar,
4232
+ fullname: 'Offline Agent'
4233
+ });
4234
+ }
4235
+
4236
+ renderMessagePreview(ev) {
4237
+ let defmsg = this.props.t('sent_you_a_message');
4238
+ let message = util/* default.get */.Z.get(ev, 'data.message.text');
4239
+ var format = util/* default.get */.Z.get(ev, 'data.message.format');
4240
+ if (format !== 'plaintext') message = defmsg;
4241
+ if (!message && util/* default.size */.Z.size(util/* default.get */.Z.get(ev, 'data.message.attachments')) > 0) message = defmsg;
4242
+ if (!message) return null;
4243
+ let byType = util/* default.get */.Z.get(ev, 'by.type');
4244
+ return (0,preact_module.h)("div", {
4245
+ class: "convo-list--convo-last-mes"
4246
+ }, util/* default.map */.Z.map(util/* default.extractText */.Z.extractText(message), tag => {
4247
+ if (tag.type === 'emoji') return (0,preact_module.h)(Emoji, {
4248
+ emojiCode: tag.text,
4249
+ byType: byType
4250
+ });
4251
+ return tag.text;
4252
+ }));
4253
+ }
4254
+
4255
+ userHasSent(cid) {
4256
+ var convo = this.props.store.matchConvo(cid) || {};
4257
+ let user = this.props.store.matchUser();
4258
+ if (this.userSent[cid]) return true;
4259
+ let joined = util/* default.find */.Z.find(convo.members, mem => mem.id === user.id && (mem.membership === 'active' || mem.last_sent > 0));
4260
+ return joined;
4261
+ }
4262
+
4263
+ isOffline(acc, accSetting) {
4264
+ let enableWhen = util/* default.get */.Z.get(accSetting, 'offline_form.enable_when');
4265
+ let isonline = true;
4266
+ if (enableWhen === 'all_agents_offline') isonline = acc.is_online;
4267
+ if (enableWhen === 'out_of_bussiness_hour') isonline = acc.is_in_business_hour;
4268
+ return !isonline;
4269
+ }
4270
+
4271
+ updateFormDataFields() {
4272
+ let form;
4273
+ let accountSetting = this.props.plugin.chatbox || {};
4274
+ let acc = this.props.store.matchAccount() || {};
4275
+ if (util/* default.get */.Z.get(accountSetting, 'prechat_form.enabled')) form = accountSetting.prechat_form;
4276
+ let offlineEnabled = util/* default.get */.Z.get(accountSetting, 'offline_form.enabled');
4277
+
4278
+ if (this.isOffline(acc, accountSetting) && offlineEnabled) {
4279
+ form = accountSetting.offline_form;
4280
+ }
4281
+
4282
+ if (this.props.view === 'offline_form') {
4283
+ form = accountSetting.offline_form;
4284
+ }
4285
+
4286
+ if (this.props.view === 'prechat_form') {
4287
+ form = accountSetting.prechat_form;
4288
+ }
4289
+
4290
+ if (util/* default.size */.Z.size(form) === 0) return [];
4291
+ var data = {};
4292
+ util/* default.each */.Z.each(form.fields, f => {
4293
+ var newf = Object.assign({}, f);
4294
+
4295
+ if (f.type === 'list') {
4296
+ newf.list = f.list;
4297
+ }
4298
+
4299
+ newf.label = this.props.t.i18n(util/* default.get */.Z.get(f, `i18n_label`, {})) || f.label;
4300
+ data['attr:' + f.key] = newf;
4301
+ });
4302
+
4303
+ if (form.group_required && util/* default.size */.Z.size(form.groups) > 0) {
4304
+ data['group'] = {
4305
+ key: 'group',
4306
+ is_required: !!form.group_required,
4307
+ label: this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_group_label`, {})) || form.group_label,
4308
+ type: 'group',
4309
+ list: util/* default.map */.Z.map(form.groups, group => ({
4310
+ value: group.id,
4311
+ label: group.name
4312
+ }))
4313
+ };
4314
+ }
4315
+
4316
+ data['question'] = {
4317
+ key: 'question',
4318
+ is_required: true,
4319
+ label: this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_question_label`, {})) || form.question_label,
4320
+ type: 'text'
4321
+ };
4322
+
4323
+ if (this.isFormChanged(this.state.formData, data)) {
4324
+ this.setState({
4325
+ formData: data
4326
+ });
4327
+ }
4328
+ }
4329
+
4330
+ isFormChanged(oldForm, newForm) {
4331
+ let oldKeys = Object.keys(oldForm);
4332
+ let newKeys = Object.keys(newForm);
4333
+ if (oldKeys.length !== newKeys.length) return true;
4334
+
4335
+ for (let i = 0; i < oldKeys.length; i++) {
4336
+ if (util/* default.get */.Z.get(oldForm, `${oldKeys[i]}.label`) !== util/* default.get */.Z.get(newForm, `${newKeys[i]}.label`)) return true;
4337
+ if (util/* default.get */.Z.get(oldForm, `${oldKeys[i]}.is_required`) !== util/* default.get */.Z.get(newForm, `${newKeys[i]}.is_required`)) return true;
4338
+
4339
+ if (util/* default.stringify */.Z.stringify(util/* default.get */.Z.get(oldForm, `${oldKeys[i]}.list`)) !== util/* default.stringify */.Z.stringify(util/* default.get */.Z.get(newForm, `${newKeys[i]}.list`))) {
4340
+ return true;
4341
+ }
4342
+ }
4343
+
4344
+ return false;
4345
+ }
4346
+
4347
+ fillForm(form) {
4348
+ if (util/* default.size */.Z.size(form) === 0) return [];
4349
+ var data = {};
4350
+ let user = this.props.store.matchUser();
4351
+ util/* default.each */.Z.each(form.fields, f => {
4352
+ var newf = Object.assign({}, f);
4353
+ newf.value = util/* default.getUserAttr */.Z.getUserAttr(user, f.key, f.type);
4354
+ if (f.type === 'boolean' && !newf.value) newf.value = false;
4355
+
4356
+ if (f.type === 'datetime' && newf.value) {
4357
+ newf.value = new util/* default.Date */.Z.Date(data.value).toLocaleDateString('en-CA');
4358
+ }
4359
+
4360
+ if (f.type === 'list') {
4361
+ newf.list = f.list;
4362
+ }
4363
+
4364
+ newf.label = this.props.t.i18n(util/* default.get */.Z.get(f, `i18n_label`, {})) || f.label;
4365
+ data['attr:' + f.key] = newf;
4366
+ });
4367
+
4368
+ if (form.group_required && util/* default.size */.Z.size(form.groups) > 0) {
4369
+ data['group'] = {
4370
+ key: 'group',
4371
+ is_required: !!form.group_required,
4372
+ label: this.props.t.i18n(util/* default.get */.Z.get(form, `i18n_group_label`, {})) || form.group_label,
4373
+ type: 'group',
4374
+ list: util/* default.map */.Z.map(form.groups, group => ({
4375
+ value: group.id,
4376
+ label: group.name
4377
+ }))
4378
+ };
4379
+ }
4380
+
4381
+ return data;
4382
+ }
4383
+
4384
+ }
4385
+
4386
+ class FormMounter extends common/* Com */.M {
4387
+ componentDidMount() {
4388
+ this.props.onMount(this.props.form);
4389
+ }
4390
+
4391
+ }
4392
+
4393
+ function Widget_encode(key) {
4394
+ return btoa(key).split('=').join('');
4395
+ }
4396
+ ;// CONCATENATED MODULE: ./src/chatbox/main.js
4397
+
4398
+
4399
+
4400
+
4401
+
4402
+
4403
+ let promiseMainCSS = (() => __webpack_require__.e(/* import() */ 178).then(__webpack_require__.bind(__webpack_require__, 178)))();
4404
+
4405
+ class Main extends common/* Com */.M {
4406
+ constructor(props) {
4407
+ super(props);
4408
+ this.refButton = (0,preact_module/* createRef */.Vf)();
4409
+ }
4410
+
4411
+ async refreshCSS() {
4412
+ let plugins = this.props.store.matchPlugin();
4413
+ let found = util/* default.find */.Z.find(plugins, plugin => plugin.id === this.props.plugin.id);
4414
+ if (!found) return;
4415
+ let css = (await promiseMainCSS).default.default.toString();
4416
+ var outcss = util/* default.replaceCssVariable */.Z.replaceCssVariable(css, this.props.plugin.chatbox);
4417
+ util/* default.setCss */.Z.setCss(this.props.plugin.id, this.$cssStyleDiv, outcss);
4418
+ }
4419
+
4420
+ componentWillUnmount() {
4421
+ util/* default.setCss */.Z.setCss(this.props.plugin.id, this.$cssStyleDiv, '');
4422
+ }
4423
+
4424
+ async componentDidMount() {
4425
+ this.$cssStyleDiv = document.getElementById('subiz-style-for-' + this.props.plugin.id);
4426
+
4427
+ if (!this.$cssStyleDiv) {
4428
+ this.$cssStyleDiv = document.createElement('style');
4429
+ document.head.appendChild(this.$cssStyleDiv);
4430
+ this.$cssStyleDiv.type = 'text/css';
4431
+ this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id;
4432
+ }
4433
+
4434
+ this.setState({
4435
+ cssready: false,
4436
+ isShowWidget: false,
4437
+ widgetView: '',
4438
+ widgetConvoId: ''
4439
+ });
4440
+ this.checkExpand();
4441
+ this.props.store.onResetCSS(this, () => this.refreshCSS());
4442
+ this.props.store.onConvoEvent(this, _ => this.checkExpand());
4443
+ this.props.store.onUpdate(this, _ => this.checkExpand());
4444
+ await this.refreshCSS();
4445
+ this.setState({
4446
+ cssready: true
4447
+ });
4448
+
4449
+ if (this.props.store.matchIsOpen() && this.props.store.matchLastview().view) {
4450
+ if (this.props.store.isMobile()) return;
4451
+ this.showWidget(Object.assign({}, this.props.store.matchLastview().opts, {
4452
+ view: this.props.store.matchLastview().view
4453
+ }));
4454
+ } else {
4455
+ this.hideWidget();
4456
+ }
4457
+ }
4458
+
4459
+ render() {
4460
+ if (!this.state.cssready) return null;
4461
+ if (util/* default.isUserBanned */.Z.isUserBanned(this.props.store.matchUser())) return null;
4462
+ if (!this.props.t) return null;
4463
+ var cls = this.props.store.isMobile() ? 'mobile' : 'desktop';
4464
+ return (0,preact_module.h)("div", {
4465
+ class: cls
4466
+ }, (0,preact_module.h)(ChatButton, {
4467
+ plugin: this.props.plugin,
4468
+ store: this.props.store,
4469
+ key: "chat_button",
4470
+ ref: this.refButton,
4471
+ isShow: !this.state.isShowWidget,
4472
+ onClick: e => this.showWidget(e),
4473
+ t: this.props.t
4474
+ }), (0,preact_module.h)(Widget, {
4475
+ plugin: this.props.plugin,
4476
+ store: this.props.store,
4477
+ view: this.state.widgetView,
4478
+ cid: this.state.widgetConvoId,
4479
+ isShow: this.state.isShowWidget,
4480
+ onClose: a => this.onWidgetClose(a),
4481
+ onGo: a => this.showWidget(a),
4482
+ t: this.props.t
4483
+ }));
4484
+ }
4485
+
4486
+ checkExpand() {
4487
+ if (this.props.store.isMobile()) return;
4488
+ if (this.props.plugin._no_auto_expand) return;
4489
+ if (this.props.store.matchHasManuallyClosed()) return;
4490
+ let convoM = this.props.store.matchConvo('*');
4491
+ let redconvo = util/* default.find */.Z.find(convoM, convo => !util/* default.isConvoSeen */.Z.isConvoSeen(convo, this.props.store.matchUser().id));
4492
+ if (!redconvo || !redconvo.id) return;
4493
+ if (!this.state.isShowWidget) this.showWidget({
4494
+ view: 'chat',
4495
+ cid: redconvo.id
4496
+ });
4497
+ }
4498
+
4499
+ getCurrentView() {
4500
+ return {
4501
+ is_show_widget: this.state.isShowWidget,
4502
+ conversation_id: this.state.widgetConvoId,
4503
+ view: this.state.widgetView
4504
+ };
4505
+ }
4506
+
4507
+ async showWidget(p) {
4508
+ this.refButton.current && this.refButton.current.ClearPreview();
4509
+
4510
+ if (!p.view) {
4511
+ let lastview = this.props.store.matchLastview() || {};
4512
+ p.view = util/* default.get */.Z.get(lastview, 'view');
4513
+ p.cid = util/* default.get */.Z.get(lastview, 'opts.cid');
4514
+ }
4515
+
4516
+ p = p || {};
4517
+ if (this.props.store.isMobile()) modifyViewport();
4518
+ this.setState({
4519
+ widgetConvoId: p.cid,
4520
+ widgetView: p.view
4521
+ });
4522
+ this.props.store.setIsOpen(true);
4523
+ this.forceUpdate();
4524
+ this.setState({
4525
+ isShowWidget: true
4526
+ });
4527
+ this.props.store.setLastview(p.view, {
4528
+ cid: p.cid
4529
+ });
4530
+ }
4531
+
4532
+ showGreeting() {
4533
+ this.refButton.current && this.refButton.current.ShowGreeting();
4534
+ }
4535
+
4536
+ hideGreeting() {
4537
+ this.refButton.current && this.refButton.current.HideGreeting();
4538
+ }
4539
+
4540
+ hideWidget() {
4541
+ restoreViewport();
4542
+ this.props.store.setIsOpen(false);
4543
+ this.setState({
4544
+ isShowWidget: false
4545
+ });
4546
+ }
4547
+
4548
+ onWidgetClose() {
4549
+ this.refButton.current && this.refButton.current.ClearPreview();
4550
+ this.props.store.setHasManuallyClosed();
4551
+ this.hideWidget();
4552
+ }
4553
+
4554
+ }
4555
+
4556
+ function restoreViewport() {
4557
+ let metatag = document.getElementById('subiz-meta-viewport');
4558
+ if (metatag) metatag.remove();
4559
+ }
4560
+
4561
+ function modifyViewport() {
4562
+ let metatag = document.createElement('meta');
4563
+ metatag.httpEquiv = 'X-UA-Compatible';
4564
+ metatag.name = 'viewport';
4565
+ metatag.id = 'subiz-meta-viewport';
4566
+ metatag.content = 'maximum-scale=1.0, user-scalable=no, width=device-width, initial-scale=1.0';
4567
+ document.getElementsByTagName('head')[0].appendChild(metatag);
4568
+ }
4569
+
4570
+ /***/ }),
4571
+
4572
+ /***/ 2493:
4573
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
4574
+
4575
+ "use strict";
4576
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
4577
+ /* harmony export */ "M": () => (/* binding */ Com),
4578
+ /* harmony export */ "u": () => (/* binding */ Clickaway)
4579
+ /* harmony export */ });
4580
+ /* harmony import */ var preact__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6400);
4581
+ /* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(819);
4582
+
4583
+
4584
+ class Com extends preact__WEBPACK_IMPORTED_MODULE_0__/* .Component */ .wA {
4585
+ constructor(props) {
4586
+ super(props);
4587
+ this._isMounted = true;
4588
+ setTimeout(() => {
4589
+ if (this.componentWillUnmount) {
4590
+ let old = this.componentWillUnmount.bind(this);
4591
+
4592
+ this.componentWillUnmount = () => {
4593
+ old();
4594
+ this._isMounted = false;
4595
+ };
4596
+ }
4597
+ }, 10);
4598
+ }
4599
+
4600
+ }
4601
+ class Clickaway extends Com {
4602
+ constructor(props) {
4603
+ super(props);
4604
+ this.setWrapperRef = this.setWrapperRef.bind(this);
4605
+ this.onClick = this.onClick.bind(this);
4606
+ }
4607
+
4608
+ componentDidMount() {
4609
+ document.addEventListener('mousedown', this.onClick);
4610
+ }
4611
+
4612
+ componentWillUnmount() {
4613
+ document.removeEventListener('mousedown', this.onClick);
4614
+ }
4615
+
4616
+ setWrapperRef(node) {
4617
+ this.wrapperRef = node;
4618
+ }
4619
+
4620
+ onClick(event) {
4621
+ if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
4622
+ this.props.onClickaway && this.props.onClickaway();
4623
+ }
4624
+ }
4625
+
4626
+ render() {
4627
+ return (0,preact__WEBPACK_IMPORTED_MODULE_0__.h)("div", {
4628
+ ref: this.setWrapperRef
4629
+ }, this.props.children);
4630
+ }
4631
+
4632
+ }
4633
+
4634
+ /***/ }),
4635
+
4636
+ /***/ 6755:
4637
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4638
+
4639
+ module.exports = __webpack_require__.p + "assets/img/bubble_default.7d5e4ab.svg";
4640
+
4641
+ /***/ }),
4642
+
4643
+ /***/ 6188:
4644
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4645
+
4646
+ module.exports = __webpack_require__.p + "assets/img/convos_empty.2353007.svg";
4647
+
4648
+ /***/ }),
4649
+
4650
+ /***/ 9270:
4651
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4652
+
4653
+ module.exports = __webpack_require__.p + "assets/img/default.06e6ee0.jpg";
4654
+
4655
+ /***/ }),
4656
+
4657
+ /***/ 4761:
4658
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4659
+
4660
+ module.exports = __webpack_require__.p + "assets/img/default_avatar.5b74dc1.png";
4661
+
4662
+ /***/ }),
4663
+
4664
+ /***/ 8909:
4665
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4666
+
4667
+ module.exports = __webpack_require__.p + "assets/img/done_gray.d7e8203.svg";
4668
+
4669
+ /***/ }),
4670
+
4671
+ /***/ 29:
4672
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4673
+
4674
+ module.exports = __webpack_require__.p + "assets/img/empty.29bed2d.svg";
4675
+
4676
+ /***/ }),
4677
+
4678
+ /***/ 8453:
4679
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4680
+
4681
+ module.exports = __webpack_require__.p + "assets/img/external-link.90577cc.svg";
4682
+
4683
+ /***/ }),
4684
+
4685
+ /***/ 9895:
4686
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4687
+
4688
+ module.exports = __webpack_require__.p + "assets/img/image_default.be0698b.png";
4689
+
4690
+ /***/ }),
4691
+
4692
+ /***/ 6484:
4693
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4694
+
4695
+ module.exports = __webpack_require__.p + "assets/img/loading_static.8f403ae.svg";
4696
+
4697
+ /***/ }),
4698
+
4699
+ /***/ 6535:
4700
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4701
+
4702
+ module.exports = __webpack_require__.p + "assets/img/rating--average.1ea492c.svg";
4703
+
4704
+ /***/ }),
4705
+
4706
+ /***/ 3824:
4707
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4708
+
4709
+ module.exports = __webpack_require__.p + "assets/img/rating--great.e3d712e.svg";
4710
+
4711
+ /***/ }),
4712
+
4713
+ /***/ 8367:
4714
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4715
+
4716
+ module.exports = __webpack_require__.p + "assets/img/rating--poor.2938a25.svg";
4717
+
4718
+ /***/ }),
4719
+
4720
+ /***/ 9737:
4721
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4722
+
4723
+ module.exports = __webpack_require__.p + "assets/img/send.6db52a9.svg";
4724
+
4725
+ /***/ }),
4726
+
4727
+ /***/ 8430:
4728
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4729
+
4730
+ module.exports = __webpack_require__.p + "assets/img/subiz-mono.877e9f5.svg";
4731
+
4732
+ /***/ })
4733
+
4734
+ }]);