@subiz/widget-v4 4.1.174 → 4.1.176

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 (55) hide show
  1. package/app.js +10 -15
  2. package/assets/less/chatbox.less +1 -0
  3. package/assets/less/widget.less +11 -2
  4. package/chat.js +10 -0
  5. package/cloudflare_worker.js +3 -4
  6. package/compiled_src/chatbox/main.js +11 -9
  7. package/compiled_src/lib.js +5 -0
  8. package/compiled_src/plugin.js +2 -0
  9. package/compiled_src/store/api.js +32 -4
  10. package/compiled_src/store/store.js +11 -0
  11. package/compiled_src/util/common.js +1 -0
  12. package/dist/185.js +11 -11
  13. package/dist/19937d43753.185.js +1 -0
  14. package/dist/19937d43753.27.js +1 -0
  15. package/dist/{198c50be7a7.278.js → 19937d43753.278.js} +1 -1
  16. package/dist/{198c50be7a7.339.js → 19937d43753.339.js} +1 -1
  17. package/dist/{198c50be7a7.459.js → 19937d43753.459.js} +1 -1
  18. package/dist/{198c50be7a7.997.js → 19937d43753.997.js} +1 -1
  19. package/dist/19937d43753.app.js +1 -0
  20. package/dist/{198c50be7a7.chat.html → 19937d43753.chat.html} +1 -1
  21. package/dist/19937d43753.chat.js +1 -0
  22. package/dist/{198c50be7a7.form.html → 19937d43753.form.html} +1 -1
  23. package/dist/19937d43753.form.js +1 -0
  24. package/dist/{198c50be7a7.index.html → 19937d43753.index.html} +1 -1
  25. package/dist/{198c50be7a7.library.html → 19937d43753.library.html} +1 -1
  26. package/dist/19937d43753.library.js +1 -0
  27. package/dist/{198c50be7a7.preview.html → 19937d43753.preview.html} +1 -1
  28. package/dist/19937d43753.preview.js +1 -0
  29. package/dist/19937d43753.webview.js +1 -0
  30. package/dist/27.js +1 -73
  31. package/dist/459.js +1 -73
  32. package/dist/997.js +0 -72
  33. package/dist/HASH +1 -1
  34. package/dist/screenshoot.js +515 -39
  35. package/package.json +4 -4
  36. package/src/chatbox/main.js +11 -9
  37. package/src/lib.js +13 -3
  38. package/src/plugin.js +3 -1
  39. package/src/store/api.js +34 -0
  40. package/src/store/store.js +14 -6
  41. package/src/util/common.js +1 -0
  42. package/tracking.js +6 -2
  43. package/dist/198c50be7a7.185.js +0 -1
  44. package/dist/198c50be7a7.27.js +0 -1
  45. package/dist/198c50be7a7.app.js +0 -1
  46. package/dist/198c50be7a7.chat.js +0 -1
  47. package/dist/198c50be7a7.form.js +0 -1
  48. package/dist/198c50be7a7.library.js +0 -1
  49. package/dist/198c50be7a7.preview.js +0 -1
  50. package/dist/198c50be7a7.webview.js +0 -1
  51. package/dist/278.js +0 -417
  52. /package/dist/{198c50be7a7.127.js → 19937d43753.127.js} +0 -0
  53. /package/dist/{198c50be7a7.132.js → 19937d43753.132.js} +0 -0
  54. /package/dist/{198c50be7a7.490.js → 19937d43753.490.js} +0 -0
  55. /package/dist/{198c50be7a7.74.js → 19937d43753.74.js} +0 -0
package/app.js CHANGED
@@ -16,11 +16,6 @@ import RunBot from './src/bot.js'
16
16
  var ajax = require('@subiz/ajax/src/ajax.js')
17
17
  var config = require('./config.js')
18
18
 
19
- var VERSION = detect()
20
- if (!VERSION) throw new Error('subiz cannot detect version')
21
-
22
- var apiV4 = new ApiV4(config.ApiURL, config.FileURL, config.RealtimeURL)
23
-
24
19
  // isV4 tells whether the website is using widget version 4.2 or not
25
20
  function isV4_2() {
26
21
  if (window.sbz_v4) return true
@@ -37,14 +32,6 @@ function isV4_2() {
37
32
  return false
38
33
  }
39
34
 
40
- // return widget version
41
- function detect() {
42
- if (window._sbzaccid) return '4.3'
43
- if (isV4_2()) return '4.2'
44
- if (window.subiz_account_id && window.subiz_account_id > 0) return '1'
45
- return undefined
46
- }
47
-
48
35
  function callV2(args) {
49
36
  args = args || []
50
37
  var out = []
@@ -110,9 +97,17 @@ function loopTitle(laststate) {
110
97
  return setTimeout(loopTitle, 2000, 'dirty invisible')
111
98
  }
112
99
 
113
- loopTitle()
114
-
100
+ var apiV4 = {}
115
101
  function init() {
102
+ let VERSION = undefined
103
+ if (window._sbzaccid) VERSION = '4.3'
104
+ else if (isV4_2()) VERSION = '4.2'
105
+ else if (window.subiz_account_id && window.subiz_account_id > 0) VERSION = '1'
106
+ if (!VERSION) throw new Error('subiz cannot detect version')
107
+
108
+ apiV4 = new ApiV4(config.ApiURL, config.FileURL, config.RealtimeURL)
109
+ loopTitle()
110
+
116
111
  if (VERSION === '4.2' || VERSION === '4.3') {
117
112
  let queue = (window.subiz && window.subiz.q) || []
118
113
  window.subiz = function () {
@@ -18,6 +18,7 @@
18
18
  //@desktop-chat-button-background-mask-url : '@desktop_button.background_mask_url'; //@default-chat-button-background-image-url;
19
19
  @desktop-chat-button-margin-x: '@desktop_button.margin_x'; //20px;
20
20
  @desktop-chat-button-margin-y: '@desktop_button.margin_y'; // 20px;
21
+ @desktop-widget-max-height: '@desktop_widget_max_height'; // calc(100% - desktop_buttom.margin_y)
21
22
 
22
23
  @form-page-background-color: '@form_background_color';
23
24
  @form-page-header-font-size: '@form_header_font_size';
@@ -195,7 +195,7 @@
195
195
 
196
196
  .widget-container {
197
197
  max-height: 100%;
198
- max-height: ~'calc(100% - 40px)';
198
+ max-height: @desktop-widget-max-height;
199
199
  max-width: 100%;
200
200
 
201
201
  background: @white;
@@ -292,7 +292,16 @@
292
292
  }
293
293
 
294
294
  .widget-body.embed-chat {
295
- max-width: 600px;
295
+ .widget-body--events {
296
+ width: 600px;
297
+ margin: 0 auto;
298
+ max-width: 100%;
299
+ }
300
+
301
+ .message-input {
302
+ max-width: 600px;
303
+ margin: 20px auto;
304
+ }
296
305
  }
297
306
 
298
307
  .widget-body--content {
package/chat.js CHANGED
@@ -33,6 +33,16 @@ async function run() {
33
33
  window.subiz = subiz
34
34
  if (botid) {
35
35
  await subiz.overrideBotId(botid)
36
+ subiz.overrideChatbox({
37
+ chatbox: {
38
+ offline_form: {
39
+ enabled: false,
40
+ },
41
+ prechat_form: {
42
+ enabled: false,
43
+ },
44
+ },
45
+ })
36
46
  }
37
47
  subiz._overrideDeviceType('mobile')
38
48
  if (window.innerWidth > 760) {
@@ -1,18 +1,17 @@
1
1
  let hash = 'XXXXXXXX' // do not change, will be replaced to real hash
2
2
 
3
- addEventListener('fetch', event => event.respondWith(handleRequest(event.request)))
3
+ addEventListener('fetch', (event) => event.respondWith(handleRequest(event.request)))
4
4
 
5
5
  /**
6
6
  * Respond to the request
7
7
  * @param {Request} request
8
8
  */
9
- async function handleRequest (request) {
10
- let body = `if (!window._subiz_init_2094850928430) {
9
+ async function handleRequest(request) {
10
+ let body = `if (!window._subiz_init_2094850928430) {
11
11
  window._subiz_init_2094850928430 = true
12
12
  window._subiz_init_2094850928430_keep_loading = true
13
13
  var tag = document.createElement('script')
14
14
  tag.async = 1
15
- tag.defer = true
16
15
  tag.src = 'https://public-gcs.subiz-cdn.com/widget-v4/public/${hash}.app.js'
17
16
  document.body.appendChild(tag)
18
17
  }`
@@ -9,21 +9,23 @@ var _ChatButton = _interopRequireDefault(require("./ChatButton.js"));
9
9
  var _Widget = _interopRequireDefault(require("./Widget.js"));
10
10
  var _common = require("../common.js");
11
11
  var _preact = require("preact");
12
+ var _css = _interopRequireDefault(require("./css.js"));
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
- let promiseMainCSS = (() => Promise.resolve().then(() => _interopRequireWildcard(require('./css.js'))))();
15
14
  class Main extends _common.Com {
16
15
  constructor(props) {
17
16
  super(props);
18
17
  this.refButton = (0, _preact.createRef)();
19
18
  this.refWidget = (0, _preact.createRef)();
20
19
  }
21
- async refreshCSS() {
20
+ refreshCSS() {
22
21
  let plugins = this.props.store.matchPlugin();
23
22
  let found = _index.default.find(plugins, plugin => plugin.id === this.props.plugin.id);
24
23
  if (!found) return;
25
- let css = (await promiseMainCSS).default.default.toString();
26
- var outcss = _index.default.replaceCssVariable(css, found.chatbox);
24
+ let css = _css.default.default.toString() + '';
25
+ let chatbox = found.chatbox;
26
+ let margin_y = _index.default.get(chatbox, 'desktop_button.margin_y');
27
+ chatbox.desktop_widget_max_height = margin_y ? `calc(100% - ${margin_y + 10}px)` : 'calc(100% - 40px)';
28
+ var outcss = _index.default.replaceCssVariable(css, chatbox);
27
29
  _index.default.setCss(this.props.plugin.id, this.$cssStyleDiv, outcss);
28
30
  }
29
31
  componentWillUnmount() {
@@ -38,7 +40,7 @@ class Main extends _common.Com {
38
40
  this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id;
39
41
  }
40
42
  this.setState({
41
- cssready: false,
43
+ cssReady: false,
42
44
  isShowWidget: false,
43
45
  widgetView: '',
44
46
  widgetConvoId: ''
@@ -53,9 +55,9 @@ class Main extends _common.Com {
53
55
  widgetConvoId: ''
54
56
  });
55
57
  });
56
- await this.refreshCSS();
58
+ this.refreshCSS();
57
59
  this.setState({
58
- cssready: true
60
+ cssReady: true
59
61
  });
60
62
  if (this.props.store.matchIsOpen() && this.props.store.matchLastview().view) {
61
63
  if (this.props.store.isMobile()) return;
@@ -68,7 +70,7 @@ class Main extends _common.Com {
68
70
  }
69
71
  }
70
72
  render() {
71
- if (!this.state.cssready) {
73
+ if (!this.state.cssReady) {
72
74
  if (typeof sbz_info != 'undefined') sbz_info.render_chatbox_css_not_ready = _index.default.Date.now();
73
75
  return null;
74
76
  }
@@ -112,6 +112,11 @@ class Widget {
112
112
  }
113
113
  async setAccount(id, $container, mask, cb) {
114
114
  if (typeof sbz_info != 'undefined') sbz_info.set_account = _index.default.Date.now();
115
+ if (document && document.location && document.location.href && document.location.href.indexOf('subiz-verification-1') > 0) {
116
+ window.subiz_verification_account_id = id;
117
+ if (typeof sbz_info != 'undefined') sbz_info = undefined;
118
+ return;
119
+ }
115
120
  if (!id) return {
116
121
  error: 'empty_account_id'
117
122
  };
@@ -182,7 +182,9 @@ function Plugin(plugin, store, $container, lib) {
182
182
  if (tr.type === 'after_pageview') _index.default.trackTimeOnPage(tr.after_pageview_sec, run);
183
183
  }
184
184
  this.update(plugin);
185
+ if (typeof sbz_info != 'undefined') sbz_info['load_lang'] = _index.default.Date.now();
185
186
  common.downloadLanguage(store, _locale).then(() => {
187
+ if (typeof sbz_info != 'undefined') sbz_info['load_lang_done'] = _index.default.Date.now();
186
188
  this.t = t;
187
189
  this.update(plugin);
188
190
  });
@@ -15,6 +15,34 @@ function jsonifyTextPlain(param, done) {
15
15
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
16
16
  done(true);
17
17
  }
18
+ let reqi = 0;
19
+ let trackRequestFn = (param, done) => {
20
+ if (typeof sbz_info == 'undefined') return done(true);
21
+ let req = param.request;
22
+ reqi++;
23
+ req._id = reqi;
24
+ sbz_info['ajax.' + reqi] = {
25
+ created: _index.default.Date.now(),
26
+ method: req.method,
27
+ baseurl: req.baseurl,
28
+ query: req.query
29
+ };
30
+ done(true);
31
+ };
32
+ let trackResponseFn = (param, done) => {
33
+ if (typeof sbz_info == 'undefined') return done(true);
34
+ let req = param.request;
35
+ let reqi = req._id;
36
+ if (!sbz_info['ajax.' + reqi]) sbz_info['ajax.' + reqi] = {
37
+ created: 0
38
+ };
39
+ sbz_info['ajax.' + reqi].out = {
40
+ duration: _index.default.Date.now() - sbz_info['ajax.' + reqi].created,
41
+ code: param.code,
42
+ err: param.err
43
+ };
44
+ done(true);
45
+ };
18
46
  class _default {
19
47
  constructor(ApiURL, FileURL) {
20
48
  _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
@@ -171,8 +199,8 @@ class _default {
171
199
  this.refreshLock = new _index.default.Mutex();
172
200
  this.FileURL = FileURL;
173
201
  this.ApiURL = ApiURL;
174
- this.api41 = ajax.setBaseUrl('https://api.sbz.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json');
175
- this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
202
+ this.api41 = ajax.setBaseUrl('https://api.sbz.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).beforeHook(trackRequestFn).setParser('json');
203
+ this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).afterHook(trackResponseFn).setParser('json').beforeHook(trackRequestFn).beforeHook((param, done) => {
176
204
  if (this.token_generator) {
177
205
  let user_id = this.profile_id;
178
206
  this.token_generator().then(token => {
@@ -199,7 +227,7 @@ class _default {
199
227
  if (obj.ref) {
200
228
  let outuser;
201
229
  for (let i = 0; true; i++) {
202
- outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
230
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).afterHook(trackResponseFn).beforeHook(trackRequestFn).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
203
231
  if (_index.default.get(outuser, 'body.error.code', '').indexOf('locked_account') != -1) break;
204
232
  if (_index.default.get(outuser, 'body.error.code', '').indexOf('user_is_banned') != -1) {
205
233
  await _index.default.sleep(120000);
@@ -285,7 +313,7 @@ class _default {
285
313
  for (let i = 0; true; i++) {
286
314
  await this.token_generator(true);
287
315
  if (tokensession != this.tokensession) break;
288
- outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${this.accid}/users/${profile_id}`);
316
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').afterHook(trackResponseFn).beforeHook(trackRequestFn).addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${this.accid}/users/${profile_id}`);
289
317
  if (!_index.default.get(outuser, 'body.id')) {
290
318
  let sleeptime = Math.min(2000 + i * 100, 120000);
291
319
  await _index.default.sleep(sleeptime);
@@ -447,15 +447,18 @@ class Store {
447
447
  }
448
448
  async init(accid, mask, userRef, options) {
449
449
  this.g_sync = {};
450
+ if (typeof sbz_info != 'undefined') sbz_info.store_0 = true;
450
451
  if (!options || !options.use_subdomain_cookie) {
451
452
  if (window && window.location && window.location.hostname) {
452
453
  cookie.defaults.domain = '.' + window.location.hostname;
453
454
  }
454
455
  }
456
+ if (typeof sbz_info != 'undefined') sbz_info.store_1 = true;
455
457
  if (!userRef) {
456
458
  try {
457
459
  userRef = this.cookie.get('__sbref', '');
458
460
  } catch (e) {}
461
+ if (typeof sbz_info != 'undefined') sbz_info.store_2 = true;
459
462
  if (!userRef) {
460
463
  if (!mask) {
461
464
  try {
@@ -476,14 +479,18 @@ class Store {
476
479
  }
477
480
  }
478
481
  }
482
+ if (typeof sbz_info != 'undefined') sbz_info.store_3 = true;
479
483
  if (this.cookie.get('__sbref', userRef) != userRef) {
480
484
  cleanMyLocalStorage();
481
485
  this.clearBrowserData();
482
486
  }
487
+ if (typeof sbz_info != 'undefined') sbz_info.store_4 = true;
483
488
  this.api.setAuth({
484
489
  accid: accid
485
490
  });
491
+ if (typeof sbz_info != 'undefined') sbz_info.store_5 = true;
486
492
  if (userRef) this.cookie.set('__sbref', userRef);
493
+ if (typeof sbz_info != 'undefined') sbz_info.store_6 = true;
487
494
  return this._initResource(accid, {
488
495
  accid: accid,
489
496
  mask: mask,
@@ -497,6 +504,7 @@ class Store {
497
504
  async _initResource(accid, auth, realtimep) {
498
505
  this.g_sync = {};
499
506
  let user = await this.api.setAuth(auth);
507
+ if (typeof sbz_info != 'undefined') sbz_info.store_7 = true;
500
508
  if (user.error) {
501
509
  console.error(user);
502
510
  return user;
@@ -512,10 +520,13 @@ class Store {
512
520
  await this.reconnectWs(accid, user.id);
513
521
  this.reconnect();
514
522
  });
523
+ if (typeof sbz_info != 'undefined') sbz_info.store_8 = true;
515
524
  this.seenLoop();
525
+ if (typeof sbz_info != 'undefined') sbz_info.store_9 = true;
516
526
  await this.reconnect({
517
527
  user: user
518
528
  });
529
+ if (typeof sbz_info != 'undefined') sbz_info.store_10 = true;
519
530
  this.readyGate.open();
520
531
  this.reconnectWs(accid, user.id);
521
532
  return user;
@@ -627,6 +627,7 @@ function replaceCssVariable(css, setting) {
627
627
  tokens = tokenize(tokens, "'@desktop_button.border_radius'");
628
628
  tokens = tokenize(tokens, "'@desktop_button.margin_x'");
629
629
  tokens = tokenize(tokens, "'@desktop_button.margin_y'");
630
+ tokens = tokenize(tokens, "'@desktop_widget_max_height'");
630
631
  tokens = tokenize(tokens, "'@mobile_button.width'");
631
632
  tokens = tokenize(tokens, "'@mobile_button.height'");
632
633
  tokens = tokenize(tokens, "'@mobile_button.background'");
package/dist/185.js CHANGED
@@ -466,7 +466,7 @@ function normalize(s) {
466
466
  }
467
467
  ;// ./src/order/icon.js
468
468
 
469
- let promiseMainCSS = (() => __webpack_require__.e(/* import() */ 278).then(__webpack_require__.bind(__webpack_require__, 9278)))();
469
+ let promiseMainCSS = (() => Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 9278)))();
470
470
  var $link = document.createElement('link');
471
471
  $link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap';
472
472
  $link.rel = 'stylesheet';
@@ -854,25 +854,25 @@ class order_Order extends common/* Com */.Mw {
854
854
  renderDesktopPaymentMethod(order) {
855
855
  return null;
856
856
  // removed by dead control flow
857
- {}
857
+
858
858
  // removed by dead control flow
859
- {}
859
+
860
860
  // removed by dead control flow
861
- {}
861
+
862
862
  // removed by dead control flow
863
- {}
863
+
864
864
  // removed by dead control flow
865
- {}
865
+
866
866
  // removed by dead control flow
867
- {}
867
+
868
868
  // removed by dead control flow
869
- {}
869
+
870
870
  // removed by dead control flow
871
- {}
871
+
872
872
  // removed by dead control flow
873
- {}
873
+
874
874
  // removed by dead control flow
875
- {}
875
+
876
876
  }
877
877
  renderDesktopShipping(order) {
878
878
  let editmode = false;
@@ -0,0 +1 @@
1
+ (self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[]).push([[185],{185:(t,e,s)=>{t.exports=s.p+"assets/img/loader.37000a7.svg"},1113:(t,e,s)=>{t.exports=s.p+"assets/img/ghn.070f8e3.svg"},2523:(t,e,s)=>{t.exports=s.p+"assets/img/shop_faded.df7845a.svg"},3080:(t,e,s)=>{t.exports=s.p+"assets/img/x.26fdfa3.svg"},3142:(t,e,s)=>{t.exports=s.p+"assets/img/not_found_search.2ddb8d1.png"},4185:(t,e,s)=>{"use strict";s.r(e),s.d(e,{default:()=>b});var i=s(5922),r=s(2988),o=s(1620),n=s(2840),a=s(172),h=s(4188);function l(t,e,s){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class d extends n.Mw{constructor(t){super(t),l(this,"state",{show:!1,searchValue:""}),l(this,"filterRef",(0,a._3)()),l(this,"overlayRef",(0,a._3)()),l(this,"onTouchMove",t=>{t.target===this.overlayRef.current&&(t.preventDefault(),t.stopPropagation())}),l(this,"hideDropdown",()=>{this.setState({show:!1,searchValue:""})}),l(this,"onKeydown",t=>{if("Escape"===t.key){if(!this.state.show)return;this.state.searchValue?this.setState({searchValue:""}):this.hideDropdown(),t.preventDefault(),t.stopPropagation()}}),l(this,"hasSearch",()=>!!this.props.has_search||i.A.size(this.props.items)>=10),l(this,"getFilteredOptions",()=>{let t=this.props.items;return this.state.searchValue&&this.hasSearch()&&(t=i.A.filter(t,t=>{let e=i.A.unicodeToAscii(t.name).toLowerCase().replace(/ /g,""),s=i.A.unicodeToAscii(t.desc).toLowerCase().replace(/ /g,""),r=i.A.unicodeToAscii(this.state.searchValue).toLowerCase().replace(/ /g,"");return-1!=e.indexOf(r)||-1!=s.indexOf(r)})),t}),l(this,"onChangeSearchValue",t=>{this.setState({searchValue:t.target.value})}),l(this,"toogleDropdown",async()=>{await this.setState({show:!0,searchValue:""}),this.focusFilter()}),l(this,"onSelect",t=>{this.props.onSelect(t),this.hideDropdown()}),l(this,"onBackgroundScroll",t=>{console.log("EEEEEEE",t),alert("y")}),document.addEventListener("touchmove",function(t){})}componentDidMount(){window.addEventListener("keydown",this.onKeydown)}componentWillUnmount(){window.removeEventListener("keydown",this.onKeydown)}renderEmpty(){return(0,a.h)("div",{class:"dropdown_select_filter__empty"},(0,a.h)("img",{class:"dropdown_select_filter__empty_img",src:s(3142)}),(0,a.h)("div",{class:"muted",style:"text-align: center !important;"},"Không có kết quả"))}renderLoading(){return(0,a.h)("div",{class:"dropdown_select_filter__empty pt-3"},(0,a.h)(h.A,{size:"40",static:!0}),(0,a.h)("div",{class:"muted mt-2",style:"text-align: center !important;"},"Đang tải dữ liệu"))}focusFilter(){this.filterRef.current&&(this.filterRef.current.focus(),i.A.setTimeout(()=>{this.filterRef.current&&this.filterRef.current.focus()},100))}renderDropdown(){if(!this.state.show)return null;let t=this.getFilteredOptions(),e=i.A.map(t,t=>(0,a.h)("div",{class:"dropdown_select__item",onClick:e=>this.onSelect(t)},t.name)),r=null;if(this.hasSearch()){let t=(0,a.h)("img",{class:"dropdown_select_filter__icon",src:s(5452)});this.props.loading&&(t=(0,a.h)("img",{class:"dropdown_select_filter__icon",src:s(185)})),r=(0,a.h)("div",{class:"dropdown_select_filter"},t,(0,a.h)("input",{ref:this.filterRef,value:this.state.searchValue,onInput:this.onChangeSearchValue,type:"text",class:"dropdown_select_filter_input "}))}0==e.length&&(e=this.renderEmpty()),this.props.loading&&(e=this.renderLoading());let o=`width: ${this.props.width||"150px"} !important;`;return this.props.full?(o=" top: 20px !important; left: 20px !important; right: 20px !important; width: unset !important; ",(0,a.h)("div",{class:"dropdown_select__overlay",ref:this.overlayRef,onClick:this.hideDropdown,onTouchMove:this.onTouchMove},(0,a.h)("div",{class:"dropdown_select",style:o,onClick:t=>{t.preventDefault(),t.stopPropagation()}},r,(0,a.h)("div",{class:"dropdown_select__items"},e)))):(0,a.h)("div",{class:"dropdown_select",style:o},r,(0,a.h)("div",{class:"dropdown_select__items"},e))}render(){let t=(0,a.h)("div",{class:"muted text-truncate",style:"flex: 1 !important;"},"Chọn một phần tử");i.A.get(this.props,"selected.name")&&(t=(0,a.h)("div",{class:"text-truncate",style:"flex: 1 !important;"},i.A.get(this.props,"selected.name")));let e="position: relative !important;";return this.props.full&&(e=""),(0,a.h)("div",{style:e},(0,a.h)(n.tW,{onClickaway:this.hideDropdown},(0,a.h)("div",{type:"text",class:"dropdown_select_input "+this.props.extra_cls,onClick:this.toogleDropdown},t," ",(0,a.h)("img",{class:"dropdown_select__caret",src:s(7741)})),this.renderDropdown()))}}function p(t,e,s){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class c extends n.Mw{constructor(t){super(t),p(this,"state",{show:!1,searchValue:"",addresses:[]}),p(this,"filterRef",(0,a._3)()),p(this,"overlayRef",(0,a._3)()),p(this,"onTouchMove",t=>{t.target===this.overlayRef.current&&(t.preventDefault(),t.stopPropagation())}),p(this,"hideDropdown",()=>{this.setState({show:!1,searchValue:""})}),p(this,"onKeydown",t=>{if("Escape"===t.key){if(!this.state.show)return;this.state.searchValue?this.setState({searchValue:""}):this.hideDropdown(),t.preventDefault(),t.stopPropagation()}t.key}),p(this,"doSearch",i.A.throttle(async()=>{let t=Date.now();this.requestId=t;let e=await this.props.store.suggest_addresses(this.state.searchValue);this.requestId===t&&this.setState({addresses:i.A.get(e,"body.addresses",[])})},100)),p(this,"onChangeSearchValue",t=>{this.setState({searchValue:t.target.value}),this.props.onChangeAddress(t.target.value),this.doSearch()}),p(this,"toogleDropdown",async()=>{await this.setState({show:!0,searchValue:this.props.initAddress||""}),this.focusFilter()}),p(this,"onSelect",t=>{this.props.onSelect(t),this.hideDropdown()}),p(this,"onBackgroundScroll",t=>{console.log("EEEEEEE",t)}),document.addEventListener("touchmove",function(t){})}componentDidMount(){window.addEventListener("keydown",this.onKeydown)}componentWillUnmount(){window.removeEventListener("keydown",this.onKeydown)}renderEmpty(){return(0,a.h)("div",{class:"dropdown_select_filter__empty"},(0,a.h)("img",{class:"dropdown_select_filter__empty_img",src:s(3142)}),(0,a.h)("div",{class:"muted",style:"text-align: center !important;"},"Không có kết quả"))}renderLoading(){return(0,a.h)("div",{class:"dropdown_select_filter__empty pt-3"},(0,a.h)(h.A,{size:"40",static:!0}),(0,a.h)("div",{class:"muted mt-2",style:"text-align: center !important;"},"Đang tải dữ liệu"))}focusFilter(){this.filterRef.current&&(this.filterRef.current.focus(),i.A.setTimeout(()=>{this.filterRef.current&&this.filterRef.current.focus()},100))}renderDropdown(){if(!this.state.show)return null;let t=i.A.map(this.state.addresses,(t,e)=>{let s=[((t.address||"")+" "+u(t.street)).trim()].join(", "),i=[u(t.ward),u(t.district),u(t.province)].join(", ");return(0,a.h)("div",{class:"dropdown_select__item",onClick:e=>this.onSelect(t),key:e},(0,a.h)("div",null,(0,a.h)("b",null,s)),(0,a.h)("div",{style:"opacity: 0.7 !important;"},i))}),e=null,r=(0,a.h)("img",{class:"dropdown_select_filter__icon",src:s(5452)});this.props.loading&&(r=(0,a.h)("img",{class:"dropdown_select_filter__icon",src:s(185)})),e=(0,a.h)("div",{class:"dropdown_select_filter"},r,(0,a.h)("input",{ref:this.filterRef,value:this.state.searchValue,onInput:this.onChangeSearchValue,type:"text",class:"dropdown_select_filter_input "})),0==t.length&&(t=this.renderEmpty()),this.props.loading&&(t=this.renderLoading());let o=`width: ${this.props.width||"150px"} !important;`;return this.props.full?(o=" top: 20px !important; left: 20px !important; right: 20px !important; width: unset !important; ",(0,a.h)("div",{class:"dropdown_select__overlay",ref:this.overlayRef,onClick:this.hideDropdown,onTouchMove:this.onTouchMove},(0,a.h)("div",{class:"dropdown_select",style:o,onClick:t=>{t.preventDefault(),t.stopPropagation()}},e,(0,a.h)("div",{class:"dropdown_select__items"},t)))):(0,a.h)("div",{class:"dropdown_select",style:o},e,(0,a.h)("div",{class:"dropdown_select__items"},t))}render(){let t=(0,a.h)("div",{class:"text-truncate",style:"flex: 1 !important;"},this.props.initAddress),e="position: relative !important;";return this.props.full&&(e=""),(0,a.h)("div",{style:e},(0,a.h)(n.tW,{onClickaway:this.hideDropdown},(0,a.h)("div",{type:"text",class:"dropdown_select_input "+this.props.extra_cls,onClick:this.toogleDropdown},t),this.renderDropdown()))}}function u(t){let e=(t+"").toLowerCase();return e.startsWith("tp ")?t.substr(3):e.startsWith("thanh pho ")||e.startsWith("thành phố ")?t.substr(10):e.startsWith("tỉnh ")?t.substr(5):e.startsWith("huyện ")?t.substr(6):e.startsWith("tỉnh ")?t.substr(5):e.startsWith("xã ")?t.substr(3):e.startsWith("thị trấn ")?t.substr(9):e.startsWith("thị xã ")?t.substr(7):e.startsWith("đường ")&&(t[7]<"0"||t[7]>"9")?t.substr(6):e.startsWith("phường ")&&(t[7]<"0"||t[7]>"9")?t.substr(7):e.startsWith("quận ")&&(t[7]<"0"||t[7]>"9")?t.substr(5):t}Promise.resolve().then(s.bind(s,9278));var m=document.createElement("link");m.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap",m.rel="stylesheet",document.head.append(m),i.A.preloadWebfonts(["Inter"],[400,500]),s(2538);class g extends n.Mw{render(){return"package"==this.props.name?this.props.active?(0,a.h)("img",{style:"width: 18px !important;",src:s(8512)}):(0,a.h)("img",{style:"width: 18px !important;",src:s(6857)}):"shop"===this.props.name?this.props.active?(0,a.h)("img",{style:"width: 18px !important;",src:s(5244)}):(0,a.h)("img",{style:"width: 18px !important;",src:s(2523)}):void 0}}function _(t,e,s){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}var v=s(5860),f=s(3080);class y extends n.Mw{constructor(t){super(t),_(this,"state",{loadProvince:!0,g_err:"",fullname:"",email:"",phone:"",loading:!0,order:{},err:{},shipping_address:"new",selectedProvince:null,selectedDistrict:null,selectedWard:null,street:"",address:"",sending:!1,step:""}),_(this,"renderMobileSuccess",t=>(0,a.h)("div",{class:"order",style:"height: 100% !important"},(0,a.h)("div",{style:"display: flex !important; align-items: center !important; padding-top: 40px !important; padding-bottom: 20px !important; flex-direction: column !important; height: 100% !important"},(0,a.h)("img",{style:"width: 60px !important; height: 60px !important;",width:"60",height:"60",src:v}),(0,a.h)("div",{style:"margin-top: 20px !important; margin-bottom: 10px !important"},(0,a.h)("b",{style:"font-size: 18px !important;"},"Đơn hàng của bạn đã được ghi nhận")),(0,a.h)("div",{class:"muted"},"Tôi sẽ liên hệ lại với bạn khi đơn hàng được xử lý"),(0,a.h)("div",{style:"flex:1 !important"}),(0,a.h)("div",{style:"margin-top: 20px !important; padding: 0px 20px 0 20px !important; width: 100% !important"},(0,a.h)("div",{class:"order_btn order__btn__light",onClick:this.close},this.props.t("close")))))),_(this,"onSelectProvince",async t=>{this.setState({selectedProvince:t,err:{},g_err:""}),this.setState({loadDistrict:!0});let e=await this.props.store.list_districts({id:t.id});this.setState({loadDistrict:!1}),e.error||this.setState({districts:i.A.get(e,"body.addresses")})}),_(this,"onSelectDistrict",async t=>{this.setState({selectedDistrict:t,err:{},g_err:""}),this.setState({loadWard:!0});let e=await this.props.store.list_wards({id:t.id});this.setState({loadWard:!1}),e.error||this.setState({wards:i.A.get(e,"body.addresses")})}),_(this,"onSelectWard",t=>this.setState({selectedWard:t,err:{},g_err:""})),_(this,"onChangeFullname",t=>this.setState({fullname:t.target.value,err:{},g_err:""})),_(this,"onChangeAddress",t=>this.setState({address:t,err:{},g_err:""})),_(this,"onSelectAddress",t=>{t&&(this.setState({address:[i.A.trim(t.address),i.A.trim(t.street)].join(" ").trim(),street:t.street,err:{},g_err:""}),this.onSelectWard({id:t.ward_id,name:t.ward}),this.onSelectDistrict({id:t.district_id,name:t.district}),this.onSelectProvince({id:t.province_id,name:t.province}))}),_(this,"onChangeEmail",t=>this.setState({email:t.target.value,err:{},g_err:""})),_(this,"onChangePhone",t=>this.setState({phone:t.target.value,err:{},g_err:""})),_(this,"onChangePaymentMethod",t=>this.setState({pm:t})),_(this,"onChangeQuantity",(t,e)=>{let s=parseInt(e)||1;t.quantity=s,this.forceUpdate()}),_(this,"confirm",async()=>{this.setState({g_err:""});let t={};if(this.state.shipping||this.setState({g_err:"Mời bạn chọn địa chỉ giao hàng trước khi xác nhận"}),"shop"===this.state.shipping?(i.A.isPhone(this.state.phone)||(t.phone=!0),i.A.trim(this.state.fullname)||(t.name=!0),i.A.trim(this.state.email)||(t.email=!0)):"new"==this.state.shipping_address&&(i.A.isPhone(this.state.phone)||(t.phone=!0),i.A.trim(this.state.fullname)||(t.name=!0),i.A.trim(this.state.address)||(t.address=!0),0==i.A.size(this.state.selectedWard)&&(t.ward=!0),0==i.A.size(this.state.selectedDistrict)&&(t.district=!0),0==i.A.size(this.state.selectedProvince)&&(t.province=!0)),i.A.size(t)>0)return void this.setState({err:t,g_err:this.props.t("input_shipping_info_err")});let e=this.props.store.matchUser(),s=i.A.getUserAttr(e,"fullname","text"),r=i.A.getUserAttr(e,"emails","text"),o=i.A.getUserAttr(e,"phones","text"),n=i.A.cloneDeep(this.state.order);if("shop"===this.state.shipping)i.A.set(n,"shipping.pickup_at_shop",!0),i.A.set(n,"shipping.address.phone",this.state.phone),i.A.set(n,"shipping.address.fullname",this.state.fullname),i.A.set(n,"shipping.address.email",this.state.email);else if("new"==this.state.shipping_address){let t=await this.props.store.createShippingAddress({address:this.state.address,country:"Việt Nam",fullname:this.state.fullname,email:this.state.email,phone:this.state.phone,district:this.state.selectedDistrict.name,district_id:this.state.selectedDistrict.id,province:this.state.selectedProvince.name,province_id:this.state.selectedProvince.id,ward:this.state.selectedWard.name,street:this.state.street,ward_id:this.state.selectedWard.id});if(t.error)return this.setState({g_err:this.props.t("update_failed")});i.A.set(n,"shipping.address",t.body)}else{let e=this.props.store.matchShippingAddresses(),s=i.A.find(e,t=>t.id===this.state.shipping_address);if(!s)return this.setState({err:t,g_err:this.props.t("input_shipping_info_err")});i.A.set(n,"shipping.address",s)}let a=!1;!s&&this.state.fullname&&(a=!0,i.A.setUserAttr(e,{key:"fullname",text:this.state.fullname})),!r&&this.state.email&&(a=!0,i.A.setUserAttr(e,{key:"emails",text:this.state.email})),!o&&this.state.phone&&(a=!0,i.A.setUserAttr(e,{key:"phones",text:this.state.phone})),a&&this.props.store.setUser(e),this.setState({sending:!0}),n.user_confirmation="confirmed";let h=await this.props.store.updateOrder(n);if(this.setState({sending:!1}),h.error)return this.setState({g_err:this.props.t("update_failed")});this.setState({step:"success"}),this.props.onResponse&&this.props.onResponse("confirmed")}),_(this,"onCancel",()=>{if(this.props.onResponse&&this.props.onResponse("rejected"),this.props.cid&&!this.state.order.user_confirmation){let t=i.A.cloneDeep(this.state.order);t.user_confirmation="rejected",this.props.store.updateOrder(t)}this.close()}),_(this,"close",()=>{this.props.onClose&&this.props.onClose()}),this.load()}async load(){if(!this.props.order_id)return;let t=await this.props.store.fetchOrder(this.props.order_id);this.setState({loading:!1}),t.error?this.setState({error:t.error}):this.setState({order:t.body}),this.props.store.matchUser();let e=i.A.get(this.props.store.matchUser(),"attributes",[]),s=i.A.get(i.A.find(e,t=>"fullname"===t.key),"text"),r=i.A.get(i.A.find(e,t=>"emails"===t.key),"text"),o=i.A.get(i.A.find(e,t=>"phones"===t.key),"text");this.setState({fullname:s,email:r,phone:o}),await this.props.store.fetchShippingAddresses();let n=await this.props.store.list_provinces();this.setState({loadProvince:!1}),n.error||this.setState({provinces:i.A.get(n,"body.addresses")})}isMobile(){return!!this.props.cid||!!this.props.isMobile||this.props.store.isMobile()}onChangeShippingAddress(t){this.setState({shipping_address:t,err:{},g_err:""})}onChangeShipping(t){this.setState({shipping:t,err:{},g_err:""})}renderDesktopPaymentMethod(t){return null}renderDesktopShipping(t){let e=!1;if(t.status&&"open"!=t.status||(e=!t.user_confirmation),this.props.store.matchUser(),e){let t=this.props.store.matchShippingAddresses(),e=i.A.map(this.state.provinces,t=>({id:t.id,name:t.province})),s=i.A.map(this.state.districts,t=>({id:t.id,name:t.district})),r=i.A.map(this.state.wards,t=>({id:t.id,name:t.ward})),o="ship_card",n=null,h=!1;if("ship"===this.state.shipping){h=!0;let l=i.A.map(t,t=>{let e=[t.street,t.ward,t.district,t.region,t.country].filter(t=>t).join(", "),s=null;return t.phone&&(s=(0,a.h)(a.FK,null," · ",this.props.t("phn")," ",t.phone)),(0,a.h)("div",{style:"margin-bottom: 15px !important"},(0,a.h)("div",{class:"radio d-flex "},(0,a.h)("input",{type:"radio",id:"shipping_addr."+t.id,onInput:e=>this.onChangeShippingAddress(t.id),name:"shipping_address",checked:this.state.shipping_address===t.id}),(0,a.h)("label",{class:"radio--label",for:"shipping_addr."+t.id,style:`font-weight: ${this.state.shipping_address===t.id?500:400} !important`},t.fullname,s,(0,a.h)("div",{class:"mt-1 muted"},"DC ",e)),(0,a.h)("div",{class:"radio--check"},(0,a.h)("div",{class:"inside"}))))});l.push((0,a.h)("div",{style:""},(0,a.h)("div",{class:"radio d-flex "},(0,a.h)("input",{type:"radio",id:"shipping_addr.new",onInput:t=>this.onChangeShippingAddress("new"),name:"shipping_address",checked:"new"===this.state.shipping_address}),(0,a.h)("label",{class:"radio--label",for:"shipping_addr.new"},"new"===this.state.shipping_address?(0,a.h)("b",null,"Tới địa chỉ khác"):"Tới địa chỉ khác"),(0,a.h)("div",{class:"radio--check"},(0,a.h)("div",{class:"inside"})))));let p=(0,a.h)("div",{style:"padding-left: 22px !important;"},(0,a.h)("div",{class:"d-flex"},(0,a.h)("div",{class:"mr-2",style:"flex: 1 !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("fullname")),(0,a.h)("input",{type:"text",class:"form-control "+(this.state.err.name&&"err"),onInput:this.onChangeFullname,value:this.state.fullname})),(0,a.h)("div",{class:"ml-2",style:"flex: 1 !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("phones")),(0,a.h)("input",{type:"text",class:"form-control "+(this.state.err.phone&&"err"),onInput:this.onChangePhone,value:this.state.phone}))),(0,a.h)("div",{class:"",style:"width: 100% !important"},(0,a.h)("div",{class:"order_form_label"},this.props.t("address")),(0,a.h)(c,{initAddress:this.state.address,store:this.props.store,width:"100%",onChangeAddress:this.onChangeAddress,full:this.isMobile(),onSelect:this.onSelectAddress,extra_cls:this.state.err.address&&"err"})),(0,a.h)("div",{class:"d-flex",style:"justify-content: space-between !important;"},(0,a.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-right: 7px !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("province")),(0,a.h)(d,{width:"194",full:this.isMobile(),has_search:!0,loading:this.state.loadProvince,items:e,selected:this.state.selectedProvince,onSelect:this.onSelectProvince,extra_cls:this.state.err.province&&"err"})),(0,a.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-left: 7px !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("district")),(0,a.h)(d,{width:"194",full:this.isMobile(),selected:this.state.selectedDistrict,has_search:!0,onSelect:this.onSelectDistrict,loading:this.state.loadDistrict,extra_cls:this.state.err.district&&"err",items:s}))),(0,a.h)("div",{class:"d-flex",style:"justify-content: space-between !important;"},(0,a.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-right: 7px !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("ward")),(0,a.h)(d,{width:"194",selected:this.state.selectedWard,full:this.isMobile(),has_search:!0,onSelect:this.onSelectWard,extra_cls:this.state.err.ward&&"err",loading:this.state.loadWard,items:r})),(0,a.h)("div",{style:"flex: 1 !important; margin-left: 7px !important;"})));o+=" ship_card__active",0==i.A.size(t)?n=(0,a.h)("div",null,(0,a.h)("div",{class:"mt-3 mb-2 "},this.props.t("input_shipping_info")),p):("new"!==this.state.shipping_address&&(p=null),n=(0,a.h)("div",null,(0,a.h)("div",{class:"mt-3 mb-2",style:"margin-bottom: 10px !important;"},"Vui lòng chọn địa chỉ giao hàng"),(0,a.h)("div",{class:"form"},l),p))}let l="ship_card",p=!1;"shop"===this.state.shipping&&(p=!0,l+=" ship_card__active",n=(0,a.h)("div",null,(0,a.h)("div",{class:"d-flex"},(0,a.h)("div",{class:"mr-2",style:"flex: 3 !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("fullname")),(0,a.h)("input",{type:"text",class:"form-control "+(this.state.err.name&&"err"),onInput:this.onChangeFullname,value:this.state.fullname})),(0,a.h)("div",{class:"ml-2",style:"flex: 2 !important;"},(0,a.h)("div",{class:"order_form_label"},this.props.t("phones")),(0,a.h)("input",{type:"text",class:"form-control "+(this.state.err.phone&&"err"),onInput:this.onChangePhone,value:this.state.phone}))),(0,a.h)("div",null,(0,a.h)("div",{class:"order_form_label"},this.props.t("email")),(0,a.h)("input",{type:"text",class:"form-control "+(this.state.err.email&&"err"),onInput:this.onChangeEmail,value:this.state.email}))));let u="card_section";return this.isMobile()&&(u="order_section"),(0,a.h)(a.FK,null,(0,a.h)("div",{class:"order_section__line"}),(0,a.h)("div",{class:u},(0,a.h)("div",{class:"order_label"},this.props.t("ship_to")),(0,a.h)("div",{class:"d-flex"},(0,a.h)("div",{class:l+" mr-3",onClick:t=>this.onChangeShipping("shop")},(0,a.h)(g,{name:"shop",active:p})," ",(0,a.h)("b",{class:"ml-2"},"Nhận hàng tại shop")),(0,a.h)("div",{class:o,onClick:t=>this.onChangeShipping("ship")},(0,a.h)(g,{name:"package",active:h})," ",(0,a.h)("b",{class:"ml-2"},"Giao hàng cho tôi"))),n))}let s=i.A.get(t,"shipping.address")||{},r=[s.address,s.ward,s.district,s.region,s.country].filter(t=>t).join(", "),o=null;s.phone&&(o=(0,a.h)("div",{class:"mt-1 muted"},this.props.t("phn"),": ",s.phone)),i.A.get(t,"shipping.pickup_at_shop")&&(r="Nhận hàng tại cửa hàng");let n=r?(0,a.h)("div",null,r):(0,a.h)("i",{class:"i muted"},"Chưa có địa chỉ giao hàng"),h="card_section";return this.isMobile()&&(h="order_section"),(0,a.h)("div",{class:h},(0,a.h)("div",{class:"order_label "},this.props.t("ship_to")),n,o)}renderDesktopSummary(t){let e=null;t.deposit>0&&(e=(0,a.h)("span",{class:"muted"},"(cọc ",i.A.formatCurrency(t.deposit),")"));let r=null;t.total_discount>0&&(r=(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Giảm giá"),(0,a.h)("div",null,i.A.formatCurrency(t.total_discount))));let o=null;(e||t.payment_made)&&(o=(0,a.h)(a.FK,null,(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Bạn đã trả"),(0,a.h)("div",null,e," ",i.A.formatCurrency(t.payment_made))),(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Bạn chưa trả"),(0,a.h)("div",null,i.A.formatCurrency((t.total||0)-(t.payment_made||0))))));let n=(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Tiền thuế"),(0,a.h)("div",null,i.A.formatCurrency(t.total_tax))),h=(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Phí vận chuyển"),(0,a.h)("div",null,i.A.get(t,"shipping.fee",0)," d")),l=!1;t.status&&"open"!=t.status||(l=!t.user_confirmation);let d=null;l&&(h=null,n=null,d=(0,a.h)("div",{class:"muted"},(0,a.h)("img",{class:"order_ship_icon",src:s(7324)}),"  Chưa bao gồm thuế và phí vận chuyển"));let p="";return this.isMobile()&&(p="order_section"),(0,a.h)(a.FK,null,(0,a.h)("div",{class:"order_section__line"}),(0,a.h)("div",{class:p},(0,a.h)("div",{class:"order_label"},"Tóm tắt"),(0,a.h)("div",{class:"order_summary_line"},(0,a.h)("div",null,"Tổng tiền hàng"),(0,a.h)("div",null,i.A.formatCurrency(t.subtotal))),n,r,h,d,(0,a.h)("div",{class:"order_summary_line",style:"margin-top: 10px !important; padding-top: 15px !important; border-top: 1px solid #eee !important"},(0,a.h)("div",null,"Bạn phải trả"),(0,a.h)("div",{class:"order__total"},i.A.formatCurrency(t.total))),o))}renderStatusBadge(t){let e=t.status||"open";return(0,a.h)("div",{style:"float: right !important;",class:"order_status order_status__"+e},e)}renderShippingInfo(t){"open"!=t.status||t.user_confirmation;let e=i.A.get(t,"shipping.shipping_provider");if(!e)return null;let r=i.A.get(t,"shipping.shipping_code"),o=null;return r&&(o=(0,a.h)("div",{class:"muted",style:"margin-top: 3px !important"},"Vận đơn ",(0,a.h)("a",{class:"order_tracking_link",target:"_blank",href:"https://giaohangtietkiem.vn/tra-cuu-van-don/"+r},r," ",(0,a.h)("img",{class:"order_tracking_link_icon",src:s(3266)})))),"ghtk"==e?(0,a.h)("div",{class:"order_section"},(0,a.h)("div",{class:"order_section_label"},"Đơn vị vận chuyển"),(0,a.h)("div",{class:"d-flex align-items-center"},(0,a.h)("img",{class:"order_shipping_provider_logo",src:w.ghtk.logo}),(0,a.h)("div",null,w.ghtk.name,o))):null}renderDesktopShippingInfo(t){let e=i.A.get(t,"shipping.shipping_provider");if(!e)return null;let r=i.A.get(t,"shipping.shipping_code"),o=null;return r&&(o=(0,a.h)("div",{class:"muted",style:"margin-top: 3px !important"},"Vận đơn ",(0,a.h)("a",{class:"order_tracking_link",target:"_blank",href:"https://giaohangtietkiem.vn/tra-cuu-van-don/"+r},r," ",(0,a.h)("img",{class:"order_tracking_link_icon",src:s(3266)})))),"ghtk"==e?(0,a.h)(a.FK,null,(0,a.h)("div",{class:"order_label"},"Đơn vị vận chuyển"),(0,a.h)("div",{class:"d-flex align-items-center"},(0,a.h)("img",{class:"order_shipping_provider_logo",src:w.ghtk.logo}),(0,a.h)("div",null,w.ghtk.name,o))):null}renderProducts(t){let e=null;return e=i.A.map(t.items,t=>{if(!t||!t.product)return null;let e=t.product;return(0,a.h)("div",{class:"order_attachment__product"},(0,a.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.A.get(e,"images.0")||s(2876)}),(0,a.h)("div",{style:"overflow: hidden !important;"},(0,a.h)("div",{class:"order_attachment__product_name"},e.name),(0,a.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,a.h)("div",{class:"order_attachment__product_desc"},this.props.t("qty")," ",t.quantity," · ",i.A.formatCurrency(e.price))))}),this.isMobile()?(0,a.h)("div",{class:"order_section"},(0,a.h)("div",{class:"order_section_label"},this.props.t("product")),e):(0,a.h)("div",null,(0,a.h)("div",{class:"order_label"},this.props.t("product")),e)}renderDesktopProducts(t){let e=null,r=!1;return t.status&&"open"!=t.status||(r=!t.user_confirmation),e=r?i.A.map(t.items,t=>{if(!t||!t.product)return null;let e=t.product;return(0,a.h)("div",{class:"order_attachment__product"},(0,a.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.A.get(e,"images.0")||s(2876)}),(0,a.h)("div",{style:"overflow: hidden !important; flex: 1 !important"},(0,a.h)("div",{class:"order_attachment__product_name"},e.name),(0,a.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,a.h)("div",{class:"order_attachment__product_desc"},i.A.formatCurrency(e.price))),(0,a.h)("input",{class:"form-control",style:"text-align: center !important; font-weight: 400 !important; width: 50px !important",value:t.quantity,onInput:e=>this.onChangeQuantity(t,e.target.value),type:"text"}),(0,a.h)("div",{style:"width: 80px !important; text-align: right !important; "},(0,a.h)("b",null,i.A.formatCurrency(t.quantity*e.price))))}):i.A.map(t.items,t=>{if(!t||!t.product)return null;let e=t.product;return(0,a.h)("div",{class:"order_attachment__product"},(0,a.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.A.get(e,"images.0")||s(2876)}),(0,a.h)("div",{style:"overflow: hidden !important; flex: 1 !important"},(0,a.h)("div",{class:"order_attachment__product_name"},e.name),(0,a.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,a.h)("div",{class:"order_attachment__product_desc"},i.A.formatCurrency(e.price))),(0,a.h)("div",{style:"text-align: center !important; font-weight: 400 !important; width: 50px !important"},t.quantity),(0,a.h)("div",{style:"width: 80px !important; text-align: right !important; "},(0,a.h)("b",null,i.A.formatCurrency(t.total))))}),(0,a.h)("div",{class:"card_section"},(0,a.h)("div",{class:"desktop_order__heading"},this.renderStatusBadge(t),(0,a.h)("b",{style:"font-size: 18px !important;"},this.props.t("order")," #",t.order_number||t.id),(0,a.h)("div",{class:"muted"},(0,a.h)(o.A,{style:"font-size: 13px !important;",time:t.issue_date||t.created}))),(0,a.h)("div",{class:"order_label d-flex",style:"margin-top: 20px !important;justify-content: space-between !important; align-items: flex-end !important;"},(0,a.h)("div",{style:"flex: 1 !important;"},this.props.t("product")),(0,a.h)("div",{style:"font-weight: 400 !important; text-align:center !important; width: 50px !important"},this.props.t("qty")),(0,a.h)("div",{style:"font-weight: 400 !important; text-align: right !important; width: 80px !important;"},this.props.t("total"))),e)}renderMobile(t){if("success"===this.state.step)return this.renderMobileSuccess(t);let e=null;this.state.g_err&&(e=(0,a.h)("div",{class:"mb-2 text__danger"},(0,a.h)("img",{style:"margin-top: -4px !important; height: 15px !important;",src:f})," ",(0,a.h)("b",null,this.state.g_err)));let s=(0,a.h)("div",null,e,(0,a.h)("div",{class:"btn-confirm-order",style:"margin-top: 0 !important;",onClick:this.confirm},this.props.t("confirm_order"))),i=(0,a.h)("div",{class:"order_btn order__btn__light mt-3",onClick:this.onCancel},this.props.t("cancel_order"));return(t.user_confirmation||"open"!=t.status)&&(s=null,this.props.cid&&(i=(0,a.h)("div",{class:"order_btn order__btn__light mt-3",onClick:this.close},this.props.t("close")))),(0,a.h)("div",{class:"order",style:"height: 100% !important"},(0,a.h)("div",{class:"order--content"},(0,a.h)("div",{class:"order--heading"},this.renderStatusBadge(t),(0,a.h)("b",{style:"font-size: 16px !important;"},this.props.t("order")," #",t.order_number||t.id),(0,a.h)("div",{class:"muted"},(0,a.h)(o.A,{style:"font-size: 13px !important;",time:t.issue_date||t.created}))),this.renderProducts(t),this.renderDesktopShipping(t),this.renderShippingInfo(t),this.renderDesktopPaymentMethod(t),this.renderDesktopSummary(t),(0,a.h)("div",{class:"order_section pb-3",style:"padding-top: 0 !important;"},s,i)))}renderActions(t){let e=null,s=!1;if(t.status&&"open"!=t.status||(s=!t.user_confirmation),"success"===this.state.step)return(0,a.h)("div",{class:"d-flex",style:"align-items: center !important; justify-content: flex-end !important"},(0,a.h)("div",null,"Ghi nhận thành công")," ",(0,a.h)("img",{style:"width: 16px !important; height: 16px !important;",width:"16",height:"16",src:v}));if(s){let t=null;this.state.g_err&&(t=(0,a.h)("div",{class:"mb-2 text__danger"},(0,a.h)("img",{style:"margin-top: -4px !important; height: 15px !important;",src:f})," ",(0,a.h)("b",null,this.state.g_err))),e=(0,a.h)("div",null,t,(0,a.h)("div",{class:"btn-confirm-order",onClick:this.confirm},this.props.t("confirm_order")),(0,a.h)("div",{class:"btn-cancel-order",onClick:this.onCancel},this.props.t("cancel_order")))}return e}renderDesktop(t){let e=this.props.store.matchAccount();var i=e.logo_url||s(3582);return(0,a.h)("div",{class:"desktop order"},(0,a.h)("div",{class:"order_acc_header"},(0,a.h)("img",{class:"order_acc_logo",src:i}),(0,a.h)("div",{class:"order_acc_name"},e.name)),(0,a.h)("div",{class:"desktop_order__content"},(0,a.h)("div",{style:"flex: 1 !important; padding-right: 20px !important;"},this.renderDesktopProducts(t),this.renderDesktopShipping(t),this.renderDesktopShippingInfo(t),this.renderDesktopPaymentMethod(t),(0,a.h)("div",{class:"order__footer"},(0,a.h)("a",{target:"_blank",href:"https://subiz.com.vn",class:"order__footer_link"},"Cung cấp bởi ",(0,a.h)("b",null,"Subiz")),(0,a.h)("div",{class:"order__footer_delimiter"}),(0,a.h)("a",{target:"_blank",href:"https://subiz.com.vn/vi/terms-of-service.html",class:"order__footer_link"},"Điều khoản"),(0,a.h)("a",{target:"_blank",href:"https://subiz.com.vn/vi/privacy-policy.html",class:"order__footer_link"},"Quyền riêng tư"))),(0,a.h)("div",null,(0,a.h)("div",{class:"order_recap"},this.renderDesktopSummary(t),this.renderActions(t)))))}render(){if(this.state.loading)return(0,a.h)("div",{class:"order_error"},(0,a.h)(h.A,{class:"mt-4",size:"60",static:!0}));if(this.state.error)return(0,a.h)("div",{class:"order_error"},(0,a.h)("img",{class:"mt-3",src:s(6907)}),(0,a.h)("div",{class:"mt-3"},this.props.t("order_load_error")));let t=this.state.order;return this.isMobile()?this.renderMobile(t):this.renderDesktop(t)}}let w={ghtk:{name:"Giao hàng tiết kiệm",logo:s(7362)},ghn:{name:"Giao hàng nhanh",logo:s(1113)}};function x(t,e,s){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var s=e.call(t,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}s(2538);class b extends n.Mw{constructor(t){super(t),x(this,"state",{hide:!0,ratingHeight:0,overlayOpacity:.3}),x(this,"onResponse",t=>{this.setState({response:t})}),x(this,"confirm",()=>{this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:"confirm",attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"confirmed"})}}]}})}),x(this,"close",async()=>{if(await i.A.sleep(100),"confirmed"===this.state.response?this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:this.props.t("confirm_order"),attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"confirmed"})}}]}}):"rejected"===this.state.response&&this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:this.props.t("cancel_order"),attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"cancelled"})}}]}}),this.setState({response:""}),!this.state.hide&&this.refRating.current){var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(20,e,t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||this.setState({hide:!0}))}),this.props.onClose()}}),this.refRating=(0,a._3)(),this.refHandle=(0,a._3)()}componentDidMount(){this.mouseUp=t=>this.onMouseUp(t),this.mouseMove=t=>this.onMouseMove(t),this.mouseDown=t=>this.onMouseDown(t);var t=this.refHandle.current;t.addEventListener("mousedown",this.mouseDown,{passive:!0}),t.addEventListener("touchstart",this.mouseDown,{passive:!0}),window.addEventListener("mouseup",this.mouseUp,{passive:!0}),window.addEventListener("touchend",this.mouseUp,{passive:!0}),window.addEventListener("mousemove",this.mouseMove,{passive:!0}),window.addEventListener("touchmove",this.mouseMove,{passive:!0}),this.animation=new r.A({maxY:400,minY:0,duration:150}),this.close()}componentWillUnmount(){var t=this.refHandle.current;t.removeEventListener("mousedown",this.mouseDown,0),t.removeEventListener("touchstart",this.mouseDown,0),window.removeEventListener("mouseup",this.mouseUp,0),window.removeEventListener("touchend",this.mouseUp,0),window.removeEventListener("mousemove",this.mouseMove,0),window.removeEventListener("touchmove",this.mouseMove,0)}render(){this._show!=this.props.show&&(this._show=this.props.show,i.A.setTimeout(()=>{this._show?this.open():this.close()}));let t=this.state.hide?"d-none":"";return(0,a.h)("div",{class:t},(0,a.h)("div",{class:"extension--overlay",style:`opacity: ${.5*this.state.overlayOpacity} !important;`}),(0,a.h)("div",{class:"extension",ref:this.refRating,style:`height: ${this.state.ratingHeight}px !important;`},(0,a.h)("div",{class:"extension--close-btn",onClick:this.close},this.props.t("close")),(0,a.h)("div",{class:"extension--handle",ref:this.refHandle},(0,a.h)("div",{class:"extension--thumb"})),(0,a.h)("div",{style:"overflow-x: hidden !important; overflow-y: scroll !important; height: 100% !important;"},(0,a.h)(y,{key:this.props.order_id,store:this.props.store,onResponse:this.onResponse,onClose:this.close,t:this.props.t,order_id:this.props.order_id,cid:this.props.cid}))))}open(){if(this.state.hide&&this.props.order_id&&(this.setState({hide:!1}),this.refRating.current)){var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(-20,e,t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)})})}}onMouseDown(t){this.mousePushed=!0,this.animation.stop(),t.preventDefault(),t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushedDy=t.pageY-window.pageYOffset-this.refRating.current.getBoundingClientRect().y}onMouseUp(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushed=!1;var e=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),s=parseFloat(e.height);this.animation.play(this.mouseVelocity,s,t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||(this.setState({hide:!0}),this.props.onRate&&this.props.onRate({no_rating:!0})))})}}onMouseMove(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]);var e=t.pageY;this.mouseVelocity=e-this.lastMouseY,this.lastMouseY=e,e-=this.mousePushedDy;var s=this.refRating.current.getBoundingClientRect().bottom-e;s>400&&(s=500-1e4/(s+-300)),this.setState({ratingHeight:s,overlayOpacity:Math.min(1,(s-0)/500)})}}}},5244:(t,e,s)=>{t.exports=s.p+"assets/img/shop.f7dc7d8.svg"},5452:(t,e,s)=>{t.exports=s.p+"assets/img/search.f9705ff.svg"},5860:(t,e,s)=>{t.exports=s.p+"assets/img/done_green.b817fd4.svg"},6857:(t,e,s)=>{t.exports=s.p+"assets/img/package_fade.763c001.svg"},6907:(t,e,s)=>{t.exports=s.p+"assets/img/empty_1.0b98af0.svg"},7324:(t,e,s)=>{t.exports=s.p+"assets/img/info.ebce7ea.svg"},7362:(t,e,s)=>{t.exports=s.p+"assets/img/ghtk.326eac1.svg"},7741:(t,e,s)=>{t.exports=s.p+"assets/img/caret.998eb8f.svg"},8512:(t,e,s)=>{t.exports=s.p+"assets/img/package.8d37d0f.svg"}}]);