@subiz/widget-v4 4.1.215 → 4.1.217

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 (57) hide show
  1. package/README.md +6 -0
  2. package/api.md +9 -5
  3. package/assets/img/bubble_default.svg +1 -0
  4. package/assets/less/message.less +83 -0
  5. package/assets/less/widget.less +12 -0
  6. package/compiled_src/chatbox/AudioAttachments.js +5 -0
  7. package/compiled_src/chatbox/ChatButton.js +19 -17
  8. package/compiled_src/chatbox/Event.js +9 -2
  9. package/compiled_src/chatbox/FileAttachments.js +9 -3
  10. package/compiled_src/chatbox/ImageAttachments.js +16 -6
  11. package/compiled_src/chatbox/UploadProgress.js +44 -0
  12. package/compiled_src/chatbox/VideoAttachments.js +5 -0
  13. package/compiled_src/store/api.js +77 -78
  14. package/compiled_src/store/api_fake.js +1 -1
  15. package/compiled_src/store/attachments.js +5 -1
  16. package/compiled_src/store/store.js +25 -4
  17. package/dist/{1a12a5ed6a9.278.js → 1a12ed33347.278.js} +1 -1
  18. package/dist/1a12ed33347.app.js +1 -0
  19. package/dist/{1a12a5ed6a9.chat.html → 1a12ed33347.chat.html} +1 -1
  20. package/dist/1a12ed33347.chat.js +1 -0
  21. package/dist/{1a12a5ed6a9.form.html → 1a12ed33347.form.html} +1 -1
  22. package/dist/{1a12a5ed6a9.form.js → 1a12ed33347.form.js} +1 -1
  23. package/dist/{1a12a5ed6a9.index.html → 1a12ed33347.index.html} +1 -1
  24. package/dist/{1a12a5ed6a9.library.html → 1a12ed33347.library.html} +1 -1
  25. package/dist/1a12ed33347.library.js +1 -0
  26. package/dist/{1a12a5ed6a9.preview.html → 1a12ed33347.preview.html} +1 -1
  27. package/dist/1a12ed33347.preview.js +1 -0
  28. package/dist/1a12ed33347.webview.js +1 -0
  29. package/dist/HASH +1 -0
  30. package/dist/assets/img/{bubble_default.7d5e4ab.svg → bubble_default.6f6eec8.svg} +1 -0
  31. package/dist/screenshoot.js +25 -20
  32. package/package.json +11 -10
  33. package/src/chatbox/AudioAttachments.js +2 -0
  34. package/src/chatbox/ChatButton.js +22 -20
  35. package/src/chatbox/Event.js +8 -4
  36. package/src/chatbox/FileAttachments.js +5 -2
  37. package/src/chatbox/ImageAttachments.js +6 -2
  38. package/src/chatbox/UploadProgress.js +21 -0
  39. package/src/chatbox/VideoAttachments.js +2 -0
  40. package/src/store/api.js +66 -81
  41. package/src/store/api_fake.js +1 -1
  42. package/src/store/attachments.js +5 -1
  43. package/src/store/store.js +13 -5
  44. package/up +18 -0
  45. package/dist/.HASH +0 -1
  46. package/dist/1a12a5ed6a9.app.js +0 -1
  47. package/dist/1a12a5ed6a9.chat.js +0 -1
  48. package/dist/1a12a5ed6a9.library.js +0 -1
  49. package/dist/1a12a5ed6a9.preview.js +0 -1
  50. package/dist/1a12a5ed6a9.webview.js +0 -1
  51. /package/dist/{1a12a5ed6a9.127.js → 1a12ed33347.127.js} +0 -0
  52. /package/dist/{1a12a5ed6a9.132.js → 1a12ed33347.132.js} +0 -0
  53. /package/dist/{1a12a5ed6a9.185.js → 1a12ed33347.185.js} +0 -0
  54. /package/dist/{1a12a5ed6a9.27.js → 1a12ed33347.27.js} +0 -0
  55. /package/dist/{1a12a5ed6a9.339.js → 1a12ed33347.339.js} +0 -0
  56. /package/dist/{1a12a5ed6a9.459.js → 1a12ed33347.459.js} +0 -0
  57. /package/dist/{1a12a5ed6a9.490.js → 1a12ed33347.490.js} +0 -0
@@ -1 +1 @@
1
- (()=>{var e={318(e){var t="Content-Type",i="application/x-www-form-urlencoded",s="application/json; charset=utf-8";function r(e,t){return Object.assign(e.clone(),t)}var n={code:"network_error,retry",number:"SBZ-EQNETWORK",message:{En_US:"Can not connect to the server. Please check your internet connection.",Vi_VN:"Không thể kết nối tới máy chủ. Vui lòng kiểm tra lại kết nối mạng."}},o={code:"invalid_response,retry",number:"SBZ-EQRESPONSE",message:{En_US:"Server error, please try again later",Vi_VN:"Lỗi máy chủ, vui lòng thử lại sau"}},a={code:"not_200,retry",number:"SBZ-EQCN200",message:{En_US:"Error while connecting to the server, please try again later",Vi_VN:"Lỗi kết nối với máy chủ, vui lòng thử lại sau"}};function c(e){return(e||"").trim()}function u(e){return e&&"[object Function]"==={}.toString.call(e)}function l(e,t,i){if(!e||0===e.length)return i(t);var s=e.shift();if(!u(s))return l(e,t,i);s(t,function(s){return!1===s?i(t):l(e,t,i)})}function h(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16)})}function d(e){if(!e)return"";for(var t=Object.keys(e),i=[],s=0;s<t.length;s++){var r=t[s],n="",o=e[r];if(void 0!==o){if(null===o)n=h(r);else if(Array.isArray(o)){for(var a=[],c=0;c<o.length;c++)void 0!==o[c]&&(a.push(p(r,o[c],a.length)),a.push(i));n=a.join("&")}else n=h(r)+"="+h(o);n.length>0&&i.push(n)}}return i.join("&")}function p(e,t){return null===t?h(e):[h(e),"=",h(t)].join("")}var f,_=(f={parser:"",beforehooks:[],afterhooks:[],baseurl:"",query:{},clone:function(){return Object.assign({},this,{query:Object.assign({},this.query)})},addQuery:function(e,t){var i=this.clone();return i.query[e]=t,i},removeQuery:function(e){var t=this.clone();return void 0!==t.query[e]&&(t.query[e]=void 0),t},withCredentials:function(e){return r(this,{_withCredentials:e})},setQuery:function(e){return r(this,{query:e})},clearHooks:function(){return r(this,{beforehooks:[],afterhooks:[]})},beforeHook:function(e){var t=this.beforehooks.slice();return t.push(e),r(this,{beforehooks:t})},afterHook:function(e){var t=this.afterhooks.slice();return t.push(e),r(this,{afterhooks:t})},setHeader:function(e){return(e=Object.assign({},this.headers,e))[t]=void 0,r(this,{headers:e})}},["put","head","patch","delete","post","get"].map(function(e){f[e]=function(h,p,f){return function(e,r,c){c=c||function(){},u(r)&&(c=r,r=void 0);var h,p=new Promise(function(e){h=function(t){try{c(t.error,t.body,t.code)}catch(e){}e(t)}});return r&&((e=e.clone()).body=r,e.content_type===s&&(e.body=m.Jsonify(r)),e.content_type===i&&(e.body=d(r))),l(e.beforehooks.slice(),{request:e},function(i){if(i.error)return h({body:{error:bq.error},code:0,error:i.error});!function(e,i){let s=d(e.query);if(s&&(s="?"+s),!m.XMLHttpRequest)return function(e,i,s){var r=Object.assign({},e.headers);e.content_type&&(r[t]=e.content_type);var n=0;fetch(e.baseurl+s,{method:e.method,headers:r,credentials:e._withCredentials,body:e.body}).then(function(e){return n=e.status,e.text()}).then(function(e){i(void 0,e,n)}).catch(function(e){i("network_error",e,-1)})}(e,i,s);var r=new m.XMLHttpRequest;for(var n in e.xhr=r,r.onreadystatechange=function(e){4===r.readyState&&(0===r.status?i("network_error",r.responseText,r.status):i(void 0,r.responseText,r.status))},r.open(e.method,e.baseurl+s),r.withCredentials=e._withCredentials,e.headers)r.setRequestHeader(n,e.headers[n]);e.content_type&&r.setRequestHeader(t,e.content_type),r.send(e.body)}(i.request,function(t,i,s){l(e.afterhooks.slice(),{request:e,code:s,body:i,err:t},function(t){var i=t.body;if("network_error"==r)return h({body:{error:n},code:t.code,error:n});if("json"==e.parser&&t.body)try{i=m.ParseJson(t.body)}catch(e){return h({body:{error:o,origin_body:t.body},code:t.code,error:o})}var r=t.err;if("network_error"==r)return h({body:{error:n},code:t.code,error:n});!r&&(s<200||s>299)&&(r=i&&i.error?i.error:a),h({body:r?i||{error:r}:i,code:t.code,error:r})})})}),p}(r(this,{method:e,baseurl:(_=this.baseurl,g=h,_=c(_),(g=c(g))&&_?g.startsWith("http://")||g.startsWith("https://")||g.startsWith("//")?g:(_.endsWith("/")||(_+="/"),g.startsWith("/")&&(g=g.substring(1)),_+g):_+g)}),p,f);var _,g}}),f.setBaseUrl=function(e){return r(this,{baseurl:e})},f.contentTypeJson=function(){return r(this,{content_type:s})},f.contentTypeForm=function(){return r(this,{content_type:i})},f.setContentType=function(e){return r(this,{content_type:c(e)})},f.setParser=function(e){return r(this,{parser:c(e)})},f.setBody=function(e){return r(this,{body:e})},f),m={Jsonify:JSON.stringify,ParseJson:JSON.parse};_.env=m,_.waterfall=l,e.exports=_},9(e,t,i){var s=i(9143);e.exports=function(e,t,i){var r=[],n="idle",o=function(e){var t=e.map(function(e){return e.payload}),s=i(t);s&&s.then||(s=Promise.resolve(s));var r=e.map(function(e){return e.rs});return new Promise(function(e){s.then(function(t){r.map(function(e,i){e(t&&t[i])}),e()})})},a=function(){"executing"!==n&&(n="executing",s(function(){if(r.length<=e)return Promise.resolve(!1);var t=r.splice(0,e);return o(t).then(function(){return!0})}).then(function(){if(0!==r.length){var e=t-(Date.now()-r[0].created);if(e>=1){if(n="idle",r[0].settedTimeout)return;return r[0].settedTimeout=!0,void setTimeout(a,e)}var i=r;r=[],o(i).then(function(){n="idle",a()})}else n="idle"}))};return this.push=function(e,t){return new Promise(function(i){r.push({payload:e,priority:t,created:Date.now(),rs:i}),a()})},this}},9096(e){e.exports={map:function(e,t){if(!e)return[];t||(t=function(e){return e});var i=[];if(Array.isArray(e)){for(var s=0;s<e.length;s++)i.push(t(e[s],s));return i}if("object"==typeof e){var r=Object.keys(e);for(s=0;s<r.length;s++){var n=r[s];i.push(t(e[n],n))}return i}return i}}},8193(e,t,i){var s=i(9798),r=i(9143),n=i(5219),o=i(9);e.exports={sleep:s,loop:r,map:n,batch:o}},9143(e){e.exports=function e(t){var i=t();if(!i||!i.then){var s=i;i={then:function(e){e(s)}}}return i.then(function(i){return i?e(t):Promise.resolve()})}},5219(e,t,i){var s=i(9096);e.exports=function(e,t,i){if("number"==typeof t){let e=i;i=t,t=e}t||(t=function(){}),("number"!=typeof i||i<=0)&&(i=1);var r={};if(s.map(e,function(e,t){r[t]=e}),i<=0&&(i=1),0===Object.keys(r).length)return Promise.resolve([]);Object.keys(r).length<i&&(i=Object.keys(r).length);var n={};return new Promise(function(e){let o=Object.keys(r).length;for(var a=function(){var i=Object.keys(r);if(0!==i.length){var c=i.shift(),u=r[c];delete r[c];var l=t(u,c);l&&l.then||(l=Promise.resolve(l)),l.then(function(t){if(n[c]=t,Object.keys(n).length===o)return e(s.map(n));a()})}},c=0;c<i;c++)setTimeout(a,1)})}},9798(e){e.exports=function(e){return new Promise(function(t){setTimeout(t,e)})}},7695(e){e.exports={xhrsend:function(e,t,i,s){if("undefined"==typeof XMLHttpRequest)return function(e,t,i,s){let r={};i&&(r["content-type"]="text/plain"),fetch(t,{method:e,headers:r,body:i}).then(e=>e.text().then(t=>s&&s(t,e.status))).catch(e=>s&&s(e,-1))}(e,t,i,s);var r=new XMLHttpRequest;r.onreadystatechange=function(e){4===r.readyState&&(s&&s(r.responseText,r.status),s=void 0)},r.onerror=function(){s&&s(r.responseText,-1),s=void 0},r.open(e,t),i&&r.setRequestHeader("content-type","text/plain"),r.send(i)},parseJSON:function(e){try{return JSON.parse(e)}catch(e){}},Pubsub:function(){var e={};this.emit=function(t){for(var i=[],s=1;s<arguments.length;s++)i.push(arguments[s]);var r=e[t];if(r)for(s=0;s<r.length;s++)r[s].apply(void 0,i)},this.on=function(t,i){e[t]||(e[t]=[]),e[t].push(i)}}}},2839(e,t,i){var s=i(8193),{xhrsend:r,parseJSON:n,Pubsub:o}=i(7695);function a(e,t,i,o,a,h){a=a||r,t=t||{};var d="";h||(h="");var p=!1,f=!1,_=!0,m=0,g=!1,v=function(t){p||(m=Date.now(),a("get",e+"poll?token="+d+"&v=5&account-id="+h,void 0,function(i,s){if(!p){var r=250-(Date.now()-m);if(r<0&&(r=0),c(s))return f=!0,setTimeout(v,Math.max(function(e){if(!e||-1===e)return 0;var t=1e3*Math.pow(1.5,e);return Math.min(1e4,t)}(t),r),t+1);if(200!==s)return f=!0,b("poll");f=!1,(i=n(i)||{}).host&&(e=l(i.host));var a=i.sequential_token;return a?(d=a,o(i.events||[]),r>0?setTimeout(v,r,0):v(0)):b("poll")}}))},y=s.batch(50,100,function(i){if(p)return Promise.resolve(u("dead",i.length));if(i.length<=0)return Promise.resolve([]);var r,o=new Promise(e=>{r=e}),f=!1;return setTimeout(function(){f||p||(_=!0)},4e3),setTimeout(()=>{f||(f=!0,_=!0,r(u("dead",i.length)),p||b("subs"))},6e4),s.loop(function(){return new Promise(function(s){if(p)return r(u("dead",i.length)),s(!1);var o="?token="+d;Promise.resolve().then(function(){return t.getAccessToken()}).then(function(m){if(p)return r(u("dead",i.length)),s(!1);t.user_ref?o+="&user_ref="+encodeURIComponent(t.user_ref):t.user_mask?o+="&user-mask="+encodeURIComponent(t.user_mask):m&&(o+="&access-token="+m);var y=e+"subs"+o+"&v=5&account-id="+encodeURIComponent(h||t.account_id);a("post",y,JSON.stringify({events:i}),function(t,o){if(!f){if(p)return r(u("dead",i.length)),s(!1);if(c(o))return _=!0,setTimeout(s,3e3,!0);if(200!==o)return b("subs"),r(u("dead",i.length)),s(!1);if(_=!1,f=!0,d)return r(i),s(!1);var a=(t=n(t)||{}).initial_token;return a?(t.host&&(e=l(t.host)),d=a,g||(g=!0,v(0)),r(i),s(!1)):(b("subs"),r(u("dead",i.length)),s(!1))}})}).catch(function(){_=!0,setTimeout(s,3e3,!0)})})}),o});this.subscribe=y.push.bind(y),this.getStatus=function(){return p?"dead":_||f?"connecting":"active"};var b=function(e){p=!0,i(e)};this.kill=b}function c(e){return e>=500&&e<600||0===e||-1===e||429===e}function u(e,t){for(var i=[],s=0;s<t;s++)i.push(e);return i}function l(e){return(e=e||"").startsWith("//")?"https:"+e:e}e.exports=function(e,t,i,s,r){("string"==typeof e||e instanceof String)&&(e=[e]),(t=t||{}).getAccessToken||(t.getAccessToken=function(){return Promise.resolve("")}),s||(s=t.account_id||"");var n=new o,c={};this.stop=function(){if(u){var e=u;u=void 0,e.kill(),n.emit("interrupted")}},this.onEvent=function(e){return n.on("event",e)},this.onInterrupted=function(e){return n.on("interrupted",e)},this.getStatus=function(){return u?u.getStatus():"dead"};var u,l=function(e){if(!u)return Promise.resolve({error:"dead"});if("string"==typeof e&&(e=[e]),!Array.isArray(e))return Promise.resolve({error:"param should be an array or string"});for(var t=[],i=0;i<e.length;i++){var s=e[i];s&&(c[s]||(c[s]=!0,t.push(u.subscribe(s))))}return 0===t.length?Promise.resolve({}):Promise.all(t).then(function(){return u&&"dead"!=u.getStatus()?{}:{error:"dead"}})};this.subscribe=l;var h=function(){var o=e[Math.floor(Math.random()*e.length)];if(u){var d=u;u=void 0,d.kill()}var p=new a(o,t,function(e,t,i){void 0!==u&&p==u&&(u=void 0,n.emit("interrupted",e,t,i),r||setTimeout(h,2e3))},function(e){if(p==u)for(var t=0;t<e.length;t++)n.emit("event",e[t])},i,s);u=p;var f=Object.keys(c);return c={},l(f)};this.reconnect=h,h()}},5180(e){e.exports={ApiURL:"https://api.sbz.vn/4.0",RealtimeURL:"https://api.sbz.vn/rts/0/",FileURL:"https://vcdn.subiz-cdn.com/file/"}},450(e){var t={},i={};t.length=0,t.cache=i,t.getItem=function(e){return e in i?i[e]:null},t.setItem=function(e,s){void 0===s?t.removeItem(e):(Object.prototype.hasOwnProperty.call(i,e)||t.length++,i[e]=s)},t.removeItem=function(e){Object.prototype.hasOwnProperty.call(i,e)&&(delete i[e],t.length--)},t.key=function(e){return Object.keys(i)[e]||null},t.clear=function(){i={},t.length=0},e.exports=t},5672(e){e.exports=function(){"use strict";var e=function(){return e.get.apply(e,arguments)},t=e.utils={isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},isPlainObject:function(e){return!!e&&"[object Object]"===Object.prototype.toString.call(e)},toArray:function(e){return Array.prototype.slice.call(e)},getKeys:Object.keys||function(e){var t=[],i="";for(i in e)e.hasOwnProperty(i)&&t.push(i);return t},encode:function(e){return String(e).replace(/[,;"\\=\s%]/g,function(e){return encodeURIComponent(e)})},decode:function(e){return decodeURIComponent(e)},retrieve:function(e,t){return e??t}};return e.defaults={},e.expiresMultiplier=86400,e.set=function(e,i,s){if(t.isPlainObject(e))for(var r in e)e.hasOwnProperty(r)&&this.set(r,e[r],i);else{var n=void 0!==(s=t.isPlainObject(s)?s:{expires:s}).expires?s.expires:this.defaults.expires||"",o=typeof n;"string"===o&&""!==n?n=new Date(n):"number"===o&&(n=new Date(+new Date+1e3*this.expiresMultiplier*n)),""!==n&&"toUTCString"in n&&(n=";expires="+n.toUTCString());var a=s.path||this.defaults.path;a=a?";path="+a:"";var c=s.domain||this.defaults.domain;c=c?";domain="+c:"";var u=s.secure||this.defaults.secure?";secure":"";!1===s.secure&&(u="");var l=s.sameSite||this.defaults.sameSite;l=l?";SameSite="+l:"",null===s.sameSite&&(l=""),document.cookie=t.encode(e)+"="+t.encode(i)+n+a+c+u+l}return this},e.setDefault=function(i,s,r){if(t.isPlainObject(i)){for(var n in i)void 0===this.get(n)&&this.set(n,i[n],s);return e}if(void 0===this.get(i))return this.set.apply(this,arguments)},e.remove=function(e){for(var i=0,s=(e=t.isArray(e)?e:t.toArray(arguments)).length;i<s;i++)this.set(e[i],"",-1);return this},e.removeSpecific=function(e,i){if(!i)return this.remove(e);e=t.isArray(e)?e:[e],i.expires=-1;for(var s=0,r=e.length;s<r;s++)this.set(e[s],"",i);return this},e.empty=function(){return this.remove(t.getKeys(this.all()))},e.get=function(e,i){var s=this.all();if(t.isArray(e)){for(var r={},n=0,o=e.length;n<o;n++){var a=e[n];r[a]=t.retrieve(s[a],i)}return r}return t.retrieve(s[e],i)},e.all=function(){if(""===document.cookie)return{};for(var e=document.cookie.split("; "),i={},s=0,r=e.length;s<r;s++){var n=e[s].split("="),o=t.decode(n.shift()),a=t.decode(n.join("="));i[o]=a}return i},e.enabled=function(){if(navigator.cookieEnabled)return!0;var t="_"===e.set("_","_").get("_");return e.remove("_"),t},e}()}};const t={};function i(s){const r=t[s];if(void 0!==r)return r.exports;const n=t[s]={id:s,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}i.m=e,i.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.cw=e=>{var t;return()=>{if(e){var i=e;e=0,t={exports:{}},i.call(t.exports,t,t.exports)}return t.exports}},i.d=(e,t)=>{if(Array.isArray(t))for(var s=0;s<t.length;){var r=t[s++],n=t[s++],o=0===n?{enumerable:!0,value:t[s++]}:{enumerable:!0,get:n};i.o(e,r)||Object.defineProperty(e,r,o)}else for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.f={},i.e=e=>{const t=[];return i.f.j(e,t),Promise.all(t)},i.u=e=>"1a12a5ed6a9."+e+".js",i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="@subiz/widget-v4:";i.l=(s,r,n,o)=>{if(e[s])return void e[s].push(r);let a,c;if(void 0!==n){const e=document.getElementsByTagName("script");for(var u=0;u<e.length;u++){const i=e[u];if(i.getAttribute("src")==s||i.getAttribute("data-webpack")==t+n){a=i;break}}}a||(c=!0,a=document.createElement("script"),a.charset="utf-8",i.nc&&a.setAttribute("nonce",i.nc),a.setAttribute("data-webpack",t+n),a.src=s),e[s]=[r];const l=(t,i)=>{a.onerror=a.onload=null,clearTimeout(h);const r=e[s];if(delete e[s],a.parentNode?.removeChild(a),r?.forEach(e=>e(i)),t)return t(i)},h=setTimeout(l.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=l.bind(null,a.onerror),a.onload=l.bind(null,a.onload),c&&document.head.appendChild(a)}})(),i.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.p="https://vcdn.subiz-cdn.com/widget-v4/public/",(()=>{const e={325:0};i.f.j=(t,s)=>{let r=i.o(e,t)?e[t]:void 0;if(0!==r)if(r)s.push(r[2]);else{const n=new Promise((i,s)=>r=e[t]=[i,s]);s.push(r[2]=n);const o=new Error,a=s=>{if(i.o(e,t)&&(r=e[t],0!==r&&(e[t]=void 0),r)){const e=s&&("load"===s.type?"missing":s.type),i=s&&s.target&&s.target.src;o.message="Loading chunk "+t+" failed.\n("+e+": "+i+")",o.name="ChunkLoadError",o.type=e,o.request=i,o.event=s,r[1](o)}};i.l(i.p+i.u(t),a,"chunk-"+t,t)}};const t=(t,s)=>{let[r,n,o]=s;var a,c,u=0;if(r.some(t=>0!==e[t])){for(a in n)i.o(n,a)&&(i.m[a]=n[a]);o&&o(i)}for(t&&t(s);u<r.length;u++)c=r[u],i.o(e,c)&&e[c]&&e[c][0](),e[c]=0},s=self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[];s.forEach(t.bind(null,0)),s.push=t.bind(null,s.push.bind(s))})(),(()=>{"use strict";var e=()=>i(318),t=()=>i(450),s=i.cw(function(t,s){i.r(s),i.d(s,{Date:()=>w,XMLHttpRequest:()=>A,agentsOfConvo:()=>W,blockToText:()=>Ue,checkRunConditions:()=>ye,checkUrlCondition:()=>Ve,clearInterval:()=>C,clearTimeout:()=>z,cloneDeep:()=>I,convoOfEv:()=>P,convoToEv:()=>O,detectLang:()=>Oe,diffDay:()=>Ce,diffYear:()=>ze,each:()=>F,extract:()=>p,extractEmails:()=>h,extractEmojis:()=>u,extractLinks:()=>l,extractPhones:()=>d,extractText:()=>_,filter:()=>R,find:()=>J,formatCurrency:()=>Ie,getAgentDisplayName:()=>re,getDayName:()=>be,getMs:()=>Pe,getUrlParameter:()=>je,getUserAttr:()=>ae,hslToRgb:()=>c,includes:()=>q,isBlockEmpty:()=>Fe,isConvoSeen:()=>$,isEmail:()=>ie,isEmptyBlock:()=>Ne,isEmptyMessage:()=>Be,isNumber:()=>te,isPhone:()=>Y,isURL:()=>ee,isUserBanned:()=>ne,js2css:()=>ge,last:()=>se,map:()=>U,merge:()=>M,noop:()=>ue,norm:()=>ce,offsetToMin:()=>Se,orderBy:()=>Z,orderByF:()=>K,parseJSON:()=>m,pipeExtracts:()=>f,preloadImg:()=>xe,preloadWebfonts:()=>ke,randomString:()=>L,replaceAll:()=>V,replaceCssVariable:()=>de,replaceCssVariablePlugin:()=>he,requestAnimationFrame:()=>k,rgbToHsl:()=>o,sameDay:()=>Ae,scrollIntoViewIfNeeded:()=>Re,setCss:()=>fe,setInterval:()=>S,setTimeout:()=>x,setUserAttr:()=>oe,shortTime:()=>Te,size:()=>B,sleep:()=>Me,startsWith:()=>N,stringify:()=>y,throttle:()=>Q,tokenize:()=>pe,trim:()=>H,trimStart:()=>G,unicodeToAscii:()=>Le,unixSec:()=>Ee,usersOfConvo:()=>D});var r=a();const n=e();function o(e,t,i){e/=255,t/=255,i/=255;var s,r,n=Math.max(e,t,i),o=Math.min(e,t,i),a=(n+o)/2;if(n==o)s=r=0;else{var c=n-o;switch(r=a>.5?c/(2-n-o):c/(n+o),n){case e:s=(t-i)/c+(t<i?6:0);break;case t:s=(i-e)/c+2;break;case i:s=(e-t)/c+4}s/=6}return[s,r,a]}function c(e,t,i){var s,r,n;if(0==t)s=r=n=i;else{function c(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+(t-e)*(2/3-i)*6:e}var o=i<.5?i*(1+t):i+t-i*t,a=2*i-o;s=c(a,o,e+1/3),r=c(a,o,e),n=c(a,o,e-1/3)}return[255*s,255*r,255*n]}function u(e){for(var t=[],i=0;i<e.length;i++)for(var s=0;s<We.length;s++)if(e.indexOf(We[s],i)===i){t.push({index:i,length:We[s].length}),i+=We[s].length-1;break}return t}function l(e){e=e||"";for(var t,i=/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim,s=[];t=i.exec(e);){const e=5;i.lastIndex-t.index>e+1&&s.push({index:t.index,length:i.lastIndex-t.index})}return s}function h(e){e=e||"";for(var t,i=/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/gim,s=[];t=i.exec(e);)s.push({index:t.index,length:i.lastIndex-t.index});return s}function d(e){e=e||"";for(var t="",i={},s=0;s<e.length;s++){var r=e.charAt(s);if("."===r||"-"===r||" "===r){var n=s>0?e.charAt(s-1):"-",o=s<e.length-1?e.charAt(s+1):"-";-1!=="0123456789".indexOf(n)&&-1!=="0123456789".indexOf(o)||(i[(t+=r).length-1]=s)}else i[(t+=r).length-1]=s}for(var a,c=/([0-9]{8,13})/gim,u=[];a=c.exec(t);)u.push({index:i[a.index],length:i[c.lastIndex-1]-i[a.index]+1});return u}function p(e,t,i){if(!e)return[];var s=[],r=0,n=t(e);if(0===B(n))return[{type:"text",text:e}];F(n,t=>{s.push({type:"text",text:e.substr(r,t.index-r)}),s.push({type:i,text:e.substr(t.index,t.length)}),r=t.index+t.length});var o=se(n);return s.push({type:"text",text:e.substr(o.index+o.length,e.length-o.index+o.length)}),R(s,e=>""!==e.text)}function f(e,t){var i=[];if(0===B(t))return[{type:"text",text:e}];var s=t.shift();return F(p(e,s,s.type),e=>{if("text"!==e.type)return i.push(e);i=i.concat(f(e.text,t.slice()))}),i}function _(e){var t=e=>{const t=h(e);return l(e).map(t=>{const i=e.substr(t.index,t.length);return{...t,length:i.replace(/[.,;!?]+$/,"").length}}).filter(e=>!t.some(t=>e.index>=t.index&&e.index+e.length<=t.index+t.length))};t.type="link";var i=h;i.type="email";var s=d;s.type="phone";var r=u;return r.type="emoji",f(e,[t,i,s,r])}function m(e){try{return b(e)}catch(e){}}var g=document.createElement("iframe");g.style.display="none",document.documentElement.appendChild(g);const v=g.contentDocument.createElement("div");g.contentDocument.body.appendChild(v);var y=g.contentWindow.JSON.stringify,b=g.contentWindow.JSON.parse,w=g.contentWindow.Date,k=g.contentWindow.requestAnimationFrame,x=g.contentWindow.setTimeout.bind(g.contentWindow),S=g.contentWindow.setInterval.bind(g.contentWindow),C=g.contentWindow.clearInterval.bind(g.contentWindow),z=g.contentWindow.clearTimeout.bind(g.contentWindow),A=g.contentWindow.XMLHttpRequest;const T=A.prototype.open,E=A.prototype.send;function P(e){return e?r.get(e,"data.conversation.id",r.get(e,"data.message.conversation_id")):""}function O(e,t){if(!t)return"";switch(t.type){case"message_sent":case"message_updated":case"message_deleted":case"message_pong":return r.set(t,"data.message.conversation_id",e);case"ticket_updated":return r.set(t,"data.ticket.conversation_id",e);default:return r.set(t,"data.conversation.id",e)}}function j(e){return e&&"object"==typeof e&&!Array.isArray(e)}function M(e,...t){if(!t.length)return e;const i=t.shift();if(j(e)&&j(i))for(const t in i)j(i[t])?(e[t]||Object.assign(e,{[t]:{}}),M(e[t],i[t])):Object.assign(e,{[t]:i[t]});return M(e,...t)}function I(e){if(e!==Object(e))return e;var t=y(e);return void 0!==t?b(t):void 0}function L(e){var t,i="";(!e||e<1)&&(e=10);for(var s=0;s<e;s++)t=Math.floor(25*Math.random()+97),i+=String.fromCharCode(t);return i}function R(e,t){if(!e)return[];if(!t)return e;var i=[];if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];t(e[r],r)&&i.push(e[r])}return i}if(Array.isArray(e)){for(let s=0;s<e.length;s++)t(e[s],s)&&i.push(e[s]);return i}return i}function q(e,t){if(!e)return!1;var i="string"==typeof e||e instanceof String;return!(!Array.isArray(e)&&!i)&&e.includes(t)}function U(e,t){if(!e)return[];t||(t=e=>e);var i=[];if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];i.push(t(e[r],r))}return i}if(Array.isArray(e)){for(let s=0;s<e.length;s++)i.push(t(e[s],s));return i}return i}function F(e,t){return U(e,t)}function D(e){return e?U(R(e.members,e=>"user"===e.type),e=>e.id):[]}function $(e,t){if("ended"===e.state)return!0;let i=e.last_message_sent;if(!i)return!0;if(r.get(i,"by.id")===t)return!0;let s=J(e.members,e=>e.id===t);return!s||Pe(i.created)<Pe(s.seen_at)}function W(e,t){return e?U(R(e.members,e=>t?"agent"===e.type||"bot"===e.type:"agent"===e.type),e=>e.id):[]}function N(e,t){return((e||"")+"").startsWith(t)}function B(e){return e?void 0!==e.length?e.length:Object.keys(e).length:0}function V(e,t,i){return(e||"").split(t).join(i)}function H(e,t){return((e||"")+"").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}function G(e,t){for(e=(e||"")+"";e.charAt(0)===t;)e=e.substr(1);return e}function Q(e,t,i){var s,r,n,o=null,a=0;i||(i={});var c=function(){a=!1===i.leading?0:(new w).getTime(),o=null,n=e.apply(s,r),o||(s=r=null)};return function(){var u=(new w).getTime();a||!1!==i.leading||(a=u);var l=t-(u-a);return s=this,r=arguments,l<=0||l>t?(o&&(z(o),o=null),a=u,n=e.apply(s,r),o||(s=r=null)):o||!1===i.trailing||(o=x(c,l)),n}}function J(e,t){if(e)return e[X(e,t)]}function X(e,t){if(!e)return-1;if(!t)return-1;if("object"==typeof e){var i=Object.keys(e);for(let r=0;r<i.length;r++){var s=i[r];if(t(e[s],s))return s}}if(Array.isArray(e)){for(let i=0;i<e.length;i++)if(t(e[i],i))return i;return-1}return-1}function Z(e,t,i){var s=[];return F(e,e=>s.push(e)),s.sort((e,s)=>{if(e[t]===s[t])return 0;var r=e[t]<s[t]?-1:1;return"desc"===i?-r:r}),s}function K(e,t,i){var s=[];return F(e,e=>s.push(e)),s.sort((e,s)=>{let r=t(e),n=t(s);if(r===n)return 0;var o=r<n?-1:1;return"desc"===i?-o:o}),s}function Y(e){if("string"!=typeof e&&"number"!=typeof e)return!1;const t=String(e).trim(),i=t.replace(/\((\d+)\)/g,"$1");if(!/^\+?\d+(?:[ .-]\d+)*$/.test(i))return!1;const s=t.replace(/\D/g,"");return!(s.length<7||s.length>15||/^(\d)\1+$/.test(s)||t.startsWith("+")&&s.startsWith("0"))}function ee(e){return/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi.test(String(e).toLowerCase())}function te(e){return/^\d+$/.test(String(e))}function ie(e){if("string"!=typeof e)return!1;const t=e.trim();if(t.length>254)return!1;const i=t.lastIndexOf("@"),s=t.slice(0,i),r=t.slice(i+1);return!(!s||s.length>64)&&(!(!s.startsWith('"')&&(s.startsWith(".")||s.endsWith(".")||s.includes("..")))&&(!(!r.startsWith("[")&&r.split(".").some(e=>e.length>63||!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(e)))&&/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t.toLowerCase())))}function se(e){var t=null==e?0:e.length;return t?e[t-1]:void 0}function re(e,t){return r.get(t,"fullname")||r.get(t,"email")||r.get(e,"name")||"Agent"}function ne(e){return ae(e,"is_ban","boolean")}function oe(e,t){if(e&&r.get(t,"key")){e.attributes=e.attributes||[];var i=X(e.attributes,e=>e&&e.key===t.key);-1!==i?e.attributes[i]=t:e.attributes.push(t)}}function ae(e,t,i){if(!e||!e.attributes)return;let s;return F(e.attributes,e=>{e&&e.key===t&&("datetime"===i&&(s=e.datetime),"boolean"===i&&(s=e.boolean),"number"===i&&(s=e.number),"text"===i&&(s=e.text),"list"===i&&(s=[e.text].concat(e.other_values)))}),s}function ce(e){return(e=e||"").trim().toLowerCase()}function ue(){}function le(e){return("string"==typeof e||e instanceof String)&&(e=e.trim().replace(/;+$/,"")),e}function he(e,t){var i=[e];let s=t.spacer||10;t=Object.assign({},t,{spacer:s+"px",spacer0:s/2+"px",spacer2:2*s+"px",spacer3:3*s+"px"}),i=pe(i,"'@font_family'"),i=pe(i,"'@font_size'"),i=pe(i,"'@text_color'"),i=pe(i,"'@faded_text_color'"),i=pe(i,"'@primary_color'"),i=pe(i,"'@background'"),i=pe(i,"'@spacer'"),i=pe(i,"'@spacer0'"),i=pe(i,"'@spacer2'"),i=pe(i,"'@spacer3'");let n=$e(r.get(t,"primary_color")||r.get(me,"primary_color"));n||(n={red:238,blue:238,green:238});let a=o(n.red,n.green,n.blue)[0],[u,l,h]=c(a,.25,.95);me.primary_color_faded=`rgb(${u},${l},${h})`;for(var d=[],p=0;p<i.length;p++){var f=i[p];if("string"!=typeof f){var _=f.type.substr(2,f.type.length-3),m=r.get(t,_)||r.get(me,_)||"";d.push(m)}else d.push(f)}return d.join("")}function de(e,t){var i=[e];i=pe(i,"'@primary_color'"),i=pe(i,"'@primary_color_faded'"),i=pe(i,"@esc-primary-color-esc"),i=pe(i,"'@secondary_color'"),i=pe(i,"'@background'"),i=pe(i,"'@text_color'"),i=pe(i,"'@width'"),i=pe(i,"'@height'"),i=pe(i,"'@desktop_button.width'"),i=pe(i,"'@desktop_button.height'"),i=pe(i,"'@desktop_button.background'"),i=pe(i,"'@desktop_button.border_radius'"),i=pe(i,"'@desktop_button.margin_x'"),i=pe(i,"'@desktop_button.margin_y'"),i=pe(i,"'@desktop_widget_max_height'"),i=pe(i,"'@preview_max_width'"),i=pe(i,"'@mobile_button.width'"),i=pe(i,"'@mobile_button.height'"),i=pe(i,"'@mobile_button.background'"),i=pe(i,"'@mobile_button.border_radius'"),i=pe(i,"'@mobile_button.margin_x'"),i=pe(i,"'@mobile_button.margin_y'"),i=pe(i,"'@mobile_height'"),i=pe(i,"'@widget_position'"),i=pe(i,"'@z_index'"),i=pe(i,"'@z_index_2'"),i=pe(i,"'@z_index_3'"),i=pe(i,"'@z_index_4'"),i=pe(i,"'@z_index_5'"),i=pe(i,"'@form_background_color'"),i=pe(i,"'@form_header_font_size'"),i=pe(i,"'@form_header_font_family'"),i=pe(i,"'@form_desc_font_size'"),i=pe(i,"'@form_desc_font_family'"),i=pe(i,"'@form_input_label_font_size'"),i=pe(i,"'@form_input_label_font_family'");let s=$e(r.get(t,"primary_color")||r.get(me,"primary_color"));s||(s={red:238,blue:238,green:238});let n=o(s.red,s.green,s.blue)[0],[a,u,l]=c(n,.25,.95);me.primary_color_faded=`rgb(${a},${u},${l})`;for(var h=[],d=0;d<i.length;d++){var p=i[d];if("string"!=typeof p)if("@esc-primary-color-esc"!==p.type)if("'@z_index_2'"!==p.type)if("'@z_index_3'"!==p.type)if("'@z_index_4'"!==p.type)if("'@z_index_5'"!==p.type){var f=p.type.substr(2,p.type.length-3);_=le(_=r.get(t,f)||r.get(me,f)||""),["mobile_button.width","mobile_button.height","mobile_button.margin_x","mobile_button.margin_y","desktop_button.width","desktop_button.height","desktop_button.margin_x","desktop_button.margin_y","form_header_font_size","form_desc_font_size","form_input_label_font_size","width","height"].includes(f)&&(_+="px"),"height"!==f||"full"!==r.get(t,"window_mode")?h.push(_):h.push("100%")}else _=r.get(t,"z_index")||r.get(me,"z_index"),h.push(_+5);else _=r.get(t,"z_index")||r.get(me,"z_index"),h.push(_+4);else{var _=r.get(t,"z_index")||r.get(me,"z_index");h.push(_+3)}else{_=r.get(t,"z_index")||r.get(me,"z_index");h.push(_+2)}else{_=r.get(t,"primary_color")||r.get(me,"primary_color");h.push(encodeURIComponent(le(_)))}else h.push(p)}return h.join("")}function pe(e,t){if(!e||!e.length)return[];var i=[];for(let n=0;n<e.length;n++){var s=e[n];if("string"==typeof s){var r=s.split(t);for(let e=0;e<r.length;e++)i.push(r[e]),i.push({type:t});i.pop()}else i.push(s)}return i}function fe(e,t,i){i=V(i,"#sbz92","#"+e),t.styleSheet?t.styleSheet.cssText=i:(t.innerHTML="",t.appendChild(document.createTextNode(i)))}A.prototype.open=function(e,t,i,s,r){return this._url=t,T.apply(this,arguments)},A.prototype.send=function(e){let t=this.onreadystatechange;return this.onreadystatechange=function(e,i,s){4==this.readyState&&((this.status>=400||0==this.status)&&"object"==typeof sbz_logs&&sbz_logs.push({type:"xhrfailed",url:this._url,status:this.status,response:this.responseText}),"function"==typeof t&&t(e,i,s))},E.apply(this,arguments)},n.env.XMLHttpRequest=A;const _e="https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5",me={primary_color:"#0265FF",secondary_color:"#555555",background:"linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)",text_color:"white",width:375,height:705,window_mode:"mini",desktop_button:{width:.3,height:.3,border_radius:"100%",background_mask_url:_e,margin_x:.3,margin_y:.3},mobile_button:{width:.3,height:.3,border_radius:"100%",background_mask_url:_e,margin_x:.3,margin_y:.3},mobile_height:"100%",widget_position:"fixed",z_index:2e9};function ge(e,t,i){var s={};for(var r in e)e.hasOwnProperty(r)&&(t&&t.length>0&&-1===t.indexOf(r)||("string"==typeof e[r]?s[r]=H(e[r]):s[r]=e[r]));e=s;let n="";for(var r in e)if(e.hasOwnProperty(r)){var o="";if(e.blur&&(o+="blur("+e.blur+") "),e.grayscale&&(o+="grayscale("+e+") "),o&&(n+="filter: "+o+"!important;"),void 0!==e.rotate&&(n+="transform:rotate("+e.rotate+") !important;"),void 0!==e[r]){let t=e[r]+"";U(i,(e,i)=>{-1!==t.indexOf(i)&&(t=V(t,i,e))}),n+=V(r,"_","-")+":"+t+" !important;","color"===r&&(n+="-webkit-text-fill-color: "+t+" !important;")}}return n}function ve(){var e=!!window.opr&&!!window.opr.addons||!!window.opera||navigator.userAgent.indexOf(" OPR/")>=0,t="undefined"!=typeof InstallTrigger,i=(/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString(),!!document.documentMode),s=!i&&!!window.StyleMedia,r=!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime);r||(r=navigator.userAgent.indexOf("Chrome"));var n=r&&-1!=navigator.userAgent.indexOf("Edg"),o=(r||e)&&!!window.CSS;return e?"opera":t?"firefox":i?"ie":s||n?"edge":r?"chrome":o?"blink":"unknown"}function ye(e,t,i,s){var n=s.matchAccount()||{},o=s.matchLocation()||{};if(!function(e,t){return!(t&&(r.get(e,"once_per_user")||r.get(e,"once_per_session")&&Ae(t.created,w.now())||r.get(e,"interval_sec")&&r.get(e,"interval_sec")>(w.now()-t.created)/1e3))}(e,i))return!1;for(let e=0;e<B(t);e++){var a=t[e];switch(a.key){case"url":if(!Ve(a,window.location.href))return!1;break;case"url_path":let e=R(a.exclude_url_paths,e=>ce(e));if(B(e)>0){let t=new URL(window.location.href).pathname||"";if("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),J(e,e=>("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),t===e)))return!1}let t=R(a.url_paths,e=>ce(e));if(B(t)>0){let e=new URL(window.location.href).pathname||"";if("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),!J(t,t=>("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),e===t)))return!1}break;case"browser":if(B(a.browsers)>0){var c=ve();if(!J(a.browsers,e=>ce(e)===ce(c)))return!1}break;case"location":if(B(a.exclude_locations)>0&&J(a.exclude_locations,e=>!(!e.city_name||!e.country_code||e.city_name!==o.city_name||e.country_code!==o.country_code)||!(!e.city_name||e.country_code||e.city_name!==o.city_name)||!(e.city_name||!e.country_code||e.country_code!==o.country_code)||void 0))return!1;if(B(a.locations)>0&&!J(a.locations,e=>!(!e.city_name||!e.country_code||e.city_name!==o.city_name||e.country_code!==o.country_code)||!(!e.city_name||e.country_code||e.city_name!==o.city_name)||!(e.city_name||!e.country_code||e.country_code!==o.country_code)||void 0))return!1;break;case"returning_visitor":if(a.returning_visitor&&s.new_visitor)return!1;if(!a.returning_visitor&&!s.new_visitor)return!1;break;case"user_is_a_contact":let i=r.get(s.matchUser(),"attributes",[]),h=J(i,e=>("emails"===e.key||"related_email"===e.key)&&e.text),d=J(i,e=>("phones"===e.key||"related_phone"===e.key)&&e.text),p=h||d;if(a.user_is_a_contact&&!p)return!1;if(!a.user_is_a_contact&&p)return!1;break;case"device_type":if(B(a.device_types)>0){let e="desktop";if(s.isMobile()&&(e="mobile"),s.isTablet()&&(e="tablet"),!J(a.device_types,t=>ce(t)===ce(e)))return!1}break;case"referer":if(B(a.exclude_referers)>0&&J(a.exclude_referers,e=>ce(document.referrer).indexOf(ce(e))>-1))return!1;if(B(a.urls)>0&&!J(a.referers,e=>ce(document.referrer).indexOf(ce(e))>-1))return!1;break;case"source":if(B(a.sources)>0){let e=s.matchTrafficSource()||"direct";if(!J(a.sources,t=>ce(t)===ce(e)))return!1}break;case"user_attribute":case"user":let f,_=r.get(s.matchUser(),"attributes",[]),g=r.get(a,"user.operator");F(_,e=>{e&&e.key===r.get(a,"user.key")&&(f=e.datetime||e.boolean||e.number||e.text||e.list)});let v=!0;switch(g){case"cons":let e=m(a.value)||[];if(0===B(e))return!1;v=!!J(e,e=>ce(f).indexOf(ce(e))>-1);break;case"notEmpty":v=!!f;break;case"empty":v=!f;break;case"true":v=!0===f||"true"===f;break;case"false":v=!f||!1===f||"false"===f}if(!v)return!1;break;case"timming":if("in"===a.business_hour&&!n.is_in_business_hour)return!1;if("notIn"===a.business_hour&&n.is_in_business_hour)return!1;if(B(a.days_of_week)>0&&!J(a.days_of_week,e=>ce(be((new w).getDay()))===ce(e)))return!1;if(B(a.minutes_of_day)>0&&B(a.minutes_of_day)%2==0){var u=new w,l=u.getMinutes()+60*u.getHours();let e=!1;for(let t=0;t<a.minutes_of_day.length;t+=2){if(a.minutes_of_day[t]<=l&&l<=a.minutes_of_day[t+1]){e=!0;break}if(a.minutes_of_day[t]>a.minutes_of_day[t+1]&&(l>=a.minutes_of_day[t]||l<=a.minutes_of_day[t+1])){e=!0;break}}if(!e)return!1}break;case"offline":if(!n.is_online!=!!a.offline)return!1}}return!0}function be(e){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e]}let we={};function ke(e,t){for(var i=0;i<e.length;i++){let t=e[i];if(t&&!we[t]){we[t]=!0;for(var s=0;s<2;s++){let e=[400,500][s],i=document.createElement("div");i.innerHTML="@!-/#Chào mỪng1",i.style.position="absolute",i.style.display="block",i.style.opacity="0.1",i.style.color="transparent",i.style.fontSize="20px",i.style.height="0px",i.style.top="0px",i.style.width="0px",i.style.fontWeight=e,i.setAttribute("subiz-preload",t+":"+e),document.body.appendChild(i),i.style.fontFamily=t,x(()=>i.remove(),3e3)}}}}function xe(e,t){if(t||(t=()=>{}),!e)return t(),Promise.resolve(!0);let i=new Image;return e=function(e){let t="https://vcdn.subiz-cdn.com/file/";return e?N(e,"/")||N(e,"data:")?e:(N(e,"http://")||N(e,"https://")||N(e,"//")||(e=H(t)+"/"+G(e,"/")),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace("https://file-subiz.com/",t)).replace("http://file-subiz.com/",t)).replace("https://file-v4.subiz.com/",t)).replace("http://file-v4.subiz.com/",t)).replace("https://filev4.subiz.com/",t)).replace("http://filev4.subiz.com/",t)).replace("https://filev4-1.subiz.com/",t)).replace("http://filev4-1.subiz.com/",t)).replace("https://file.subiz.com/",t)).replace("http://file.subiz.com/",t)).replace("https://file.mysubiz.com/",t)).replace("http://file.mysubiz.com/",t)):""}(e),i.src=e,new Promise(e=>{i.onload=()=>{t(),e()}})}function Se(e){if(!e)return 0;e.length<=2&&(e+=":00");let t=e.split(":");if(2!==t.length)return 0;let i=parseInt(t[0]);if(i<0||i>23)return 0;let s=parseInt(t[1]);return s<0||s>59?0:60*i+s}function Ce(e,t,i){var s=-(new w).getTimezoneOffset();i&&(s=Se(i));var r=new w(e).getTime(),n=new w(t).getTime(),o=Math.ceil((r/60/1e3+s)/60/24),a=Math.ceil((n/60/1e3+s)/60/24);return Math.abs(o-a)}function ze(e,t,i){var s=-(new w).getTimezoneOffset(),r=-(new w).getTimezoneOffset();i&&(r=Se(i));var n=new w(e).getTime()+60*(r-s)*1e3,o=new w(t).getTime()+60*(r-s)*1e3;return Math.abs(new w(n).getYear()-new w(o).getYear())}function Ae(e,t,i){return 0===Ce(e,t,i)}function Te(e,t,i,s){var n=-(new w).getTimezoneOffset(),o=n;t&&(o=Se(t));var a=new w(Pe(e));let c=new w(a);c.setMinutes(a.getMinutes()+o-n),i||(i=new w);let u=c.getHours(),l=c.getMinutes(),h=r.get(navigator,"languages.0","en-US");s&&(h=s);let d=c.toLocaleDateString(h,{weekday:"long"}),p=c.getFullYear(),f=c.getMonth()+1,_=c.toLocaleDateString(h,{month:"long"}),m=c.getDate();return u<10&&(u="0"+u),l<10&&(l="0"+l),Ae(a,i,t)?u+":"+l:Ce(a,i,t)<=5?d+", "+u+":"+l:0===ze(a,i,t)?"vi-VN"===h?m+" "+_+", "+u+":"+l:_+" "+m+", "+u+":"+l:"vi-VN"===h?m+"/"+f+"/"+p+", "+u+":"+l:p+"/"+f+"/"+m+", "+u+":"+l}function Ee(e){return Math.floor(Pe(e)/1e3)}function Pe(e){return e?"number"!=typeof e&&(e=new w(e).getTime()):e=0,e>1e18?Math.floor(e/1e6):e>1e15?Math.floor(e/1e3):e>1e12?e:1e3*e}function Oe(){let e=je("sbz_locale"),t=document.getElementsByTagName("html")[0].getAttribute("xml:lang")||document.getElementsByTagName("html")[0].getAttribute("lang"),i=navigator.language;return e||t||i}function je(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var Me=e=>new Promise(t=>x(t,e));function Ie(e,t="VND"){let i=qe.find(e=>e.code===t)||{name:"Dong",code:"VND",symbol:"₫"},s="",r="";return"VND"===t?(s="",r=" "+i.symbol):(s=i.symbol+" ",r=""),e?s+(e=Math.round(e)).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")+r:`${s}0${r}`}function Le(e){return(e=(e+="").replaceAll("đ","d").replaceAll("Đ","D")).normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function Re(e,t=!0){var i=e.parentNode,s=window.getComputedStyle(i,null),r=parseInt(s.getPropertyValue("border-top-width")),n=parseInt(s.getPropertyValue("border-left-width")),o=e.offsetTop-i.offsetTop<i.scrollTop,a=e.offsetTop-i.offsetTop+e.clientHeight-r>i.scrollTop+i.clientHeight,c=e.offsetLeft-i.offsetLeft<i.scrollLeft,u=e.offsetLeft-i.offsetLeft+e.clientWidth-n>i.scrollLeft+i.clientWidth,l=o&&!a;(o||a)&&t&&(i.scrollTop=e.offsetTop-i.offsetTop-i.clientHeight/2-r+e.clientHeight/2),(c||u)&&t&&(i.scrollLeft=e.offsetLeft-i.offsetLeft-i.clientWidth/2-n+e.clientWidth/2),(o||a||c||u)&&!t&&e.scrollIntoView(l)}const qe=[{code:"USD",symbol:"$"},{code:"VND",symbol:"₫"}];function Ue(e){return De(e).trim()}function Fe(e){return Ne(e)}function De(e){if(!e)return"";let t="";return"bullet_list"==e.type||"ordered_list"==e.type?(U(e.content,(i,s)=>{let r="ordered_list"==e.type?"\n"+(Number(s)+1)+". ":"\n* ";t+=r+De(i).trim()}),t):("heading"!=e.type&&"paragraph"!=e.type||(t+="\n"),""!=e.type&&"text"!=e.type&&"link"!=e.type&&"mention-agent"!=e.type&&"mention"!=e.type&&"dynamic-field"!=e.type||B(e.content)?"horizontal_rule"==e.type?t+"\n---\n":"emoji"==e.type?t+(r.get(e,"attrs.code")||e.text||e.Text||""):B(e.content)?(U(e.content,e=>{t+=De(e)}),t):t+(e.text||""):t+(e.text||""))}function $e(e){if(!e||!e.split)return"";v.style.color=e;const t=g.contentWindow.getComputedStyle(v).color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{red:parseInt(t[1]),green:parseInt(t[2]),blue:parseInt(t[3])}:null}let We=["like","unlike","wink","tongue-out","tired","surprised","smiling","sleepy","sad","neutral","heart-eyes","grinning","crying","confused","angry","cry","heart_eyes","neutral_face","emoji--disappointed","smile","open_mouth","tired_face","stuck_out_tongue","moyai","thumbsdown","dislike","thumbsup","ok_hand","octopus","pig2","wave","mouse","mouse2","rat"];function Ne(e){if(!e)return!0;if("image"===e.type&&r.get(e,"image.url"))return!1;if("emoji"===e.type&&(r.get(e,"attrs.code")||e.Text))return!1;if("horizontal_rule"===e.type)return!1;let t=B(R(U(e.content,e=>Ne(e)),e=>!e))>0;return!H(e.text)&&!t}function Be(e){return!e||!e.deleted&&!(e.text||!Ne(e.block)||!function(e){return!e||!B(e.attachments)||0==B(R(e.attachments,e=>"quick_replies"!=e.type||B(R(e.quick_replies,e=>B(H(e))>0))>0))}(e))}function Ve(e,t){let i=R(e.exclude_urls,e=>ce(e)),s=!1,r=0;U(i,e=>{ce(t).indexOf(e)>-1&&(r<B(e)&&(r=B(e)),s=!0)});let n=0,o=R(e.urls,e=>ce(e)),a=0==B(o);return U(o,e=>{ce(t).indexOf(e)>-1&&(n<B(e)&&(n=B(e)),a=!0)}),!(s&&r>=n||!a)}We=U(We,e=>":"+e+":"),i.d(s,["DEFVAL",0,me,"DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL",0,_e])}),r={};i.r(r),i.d(r,{DEFVAL:()=>s().DEFVAL,DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL:()=>s().DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL,Date:()=>s().Date,XMLHttpRequest:()=>s().XMLHttpRequest,agentsOfConvo:()=>s().agentsOfConvo,blockToText:()=>s().blockToText,checkRunConditions:()=>s().checkRunConditions,checkUrlCondition:()=>s().checkUrlCondition,clearInterval:()=>s().clearInterval,clearTimeout:()=>s().clearTimeout,cloneDeep:()=>s().cloneDeep,convoOfEv:()=>s().convoOfEv,convoToEv:()=>s().convoToEv,detectLang:()=>s().detectLang,diffDay:()=>s().diffDay,diffYear:()=>s().diffYear,each:()=>s().each,extract:()=>s().extract,extractEmails:()=>s().extractEmails,extractEmojis:()=>s().extractEmojis,extractLinks:()=>s().extractLinks,extractPhones:()=>s().extractPhones,extractText:()=>s().extractText,filter:()=>s().filter,find:()=>s().find,formatCurrency:()=>s().formatCurrency,getAgentDisplayName:()=>s().getAgentDisplayName,getDayName:()=>s().getDayName,getMs:()=>s().getMs,getUrlParameter:()=>s().getUrlParameter,getUserAttr:()=>s().getUserAttr,hslToRgb:()=>s().hslToRgb,includes:()=>s().includes,isBlockEmpty:()=>s().isBlockEmpty,isConvoSeen:()=>s().isConvoSeen,isEmail:()=>s().isEmail,isEmptyBlock:()=>s().isEmptyBlock,isEmptyMessage:()=>s().isEmptyMessage,isNumber:()=>s().isNumber,isPhone:()=>s().isPhone,isURL:()=>s().isURL,isUserBanned:()=>s().isUserBanned,js2css:()=>s().js2css,last:()=>s().last,map:()=>s().map,merge:()=>s().merge,noop:()=>s().noop,norm:()=>s().norm,offsetToMin:()=>s().offsetToMin,orderBy:()=>s().orderBy,orderByF:()=>s().orderByF,parseJSON:()=>s().parseJSON,pipeExtracts:()=>s().pipeExtracts,preloadImg:()=>s().preloadImg,preloadWebfonts:()=>s().preloadWebfonts,randomString:()=>s().randomString,replaceAll:()=>s().replaceAll,replaceCssVariable:()=>s().replaceCssVariable,replaceCssVariablePlugin:()=>s().replaceCssVariablePlugin,requestAnimationFrame:()=>s().requestAnimationFrame,rgbToHsl:()=>s().rgbToHsl,sameDay:()=>s().sameDay,scrollIntoViewIfNeeded:()=>s().scrollIntoViewIfNeeded,setCss:()=>s().setCss,setInterval:()=>s().setInterval,setTimeout:()=>s().setTimeout,setUserAttr:()=>s().setUserAttr,shortTime:()=>s().shortTime,size:()=>s().size,sleep:()=>s().sleep,startsWith:()=>s().startsWith,stringify:()=>s().stringify,throttle:()=>s().throttle,tokenize:()=>s().tokenize,trim:()=>s().trim,trimStart:()=>s().trimStart,unicodeToAscii:()=>s().unicodeToAscii,unixSec:()=>s().unixSec,usersOfConvo:()=>s().usersOfConvo});var n=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(e){this.isOpen=!0===e,this.cbs=[]}open(){this.isOpen=!0;let e=[];this.cbs.forEach(t=>{this.isOpen?t():e.push(t)}),this.cbs=e}close(){this.isOpen=!1}entry(e,t){return this.isOpen?(t&&(this.isOpen=!1),e&&e(),Promise.resolve()):new Promise(i=>{this.cbs.push(()=>{t&&(this.isOpen=!1),e&&e(),i()})})}}}),o=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(){this.isOpen=!0,this.cbs=[]}_check(){if(!this.isOpen)return;let e=this.cbs.pop();e&&(this.isOpen=!1,e())}lock(){return new Promise(e=>{this.cbs.push(e),this._check()})}unlock(){this.isOpen||(this.isOpen=!0,this._check())}}}),a=i.cw(function(e,t){i.r(t),i.d(t,{get:()=>a,set:()=>c,take:()=>u});var s=Object.prototype.toString,r=Array.isArray||function(e){return"[object Array]"===s.call(e)};function n(e){var t=parseInt(e);return t.toString()===e?t:e}function o(e,t){if(function(e,t){return"number"==typeof t&&r(e)||function(e,t){return null!=e&&Object.prototype.hasOwnProperty.call(e,t)}(e,t)}(e,t))return e[t]}function a(e,t,i){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if(null==e)return i;if("string"==typeof t)return a(e,t.split("."),i);var s=n(t[0]),r=o(e,s);return void 0===r?i:1===t.length?r:a(e[s],t.slice(1),i)}function c(e,t,i){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if("string"==typeof t)return c(e,t.split(".").map(n),i);var s=t[0],r=o(e,s);return 1===t.length?(e[s]=i,r):(void 0===r&&(e[s]="number"==typeof t[1]?[]:{}),c(e[s],t.slice(1),i))}function u(e,t=1){if(!Array.isArray(e))return[];let i=e.length;if("number"!=typeof i||i<=0)return[];if(t<=0)return[];let s=Math.min(t,i);return e.slice(0,s)}}),c=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(){this.listeners={}}publish(e,...t){const i=(this.listeners[e]||[]).slice();for(const e of i)e.obj._isMounted||e.unsubscribe(),e.active&&e.cb(...t)}on2(e,t,i){const s={obj:e,cb:i,active:!0};let r=()=>{};const n=()=>{s.active&&(s.active=!1,this.listeners[t]=(this.listeners[t]||[]).filter(e=>e!==s),this.listeners[t].length||delete this.listeners[t],r())};return s.unsubscribe=n,this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(s),"function"==typeof e.onDispose&&(r=e.onDispose(n)),n}clear(){for(const e of Object.values(this.listeners))for(const t of e.slice())t.unsubscribe()}}}),u={};i.r(u),i.d(u,{trackAreaClicked:()=>p,trackExitIntent:()=>h,trackInactivity:()=>f,trackScrollingPercentage:()=>d,trackTimeOnPage:()=>m}),s();var l=s();function h(e){let t=i=>{i.clientY>10||(e&&e(),document.removeEventListener("mouseout",t))};document.addEventListener("mouseout",t)}function d(e,t){let i=s=>{let r=s.srcElement.scrollingElement?s.srcElement.scrollingElement.scrollTop:s.srcElement.scrollTop,n=s.srcElement.scrollingElement?s.srcElement.scrollingElement.scrollHeight:s.srcElement.scrollHeight;r>0&&n>0&&(r+window.innerHeight)/n>=e&&(t&&t(),window.removeEventListener("scroll",i,!1))};window.addEventListener("scroll",i,!1)}function p(e,t){e&&(e=e||"",l.map(e.split("\n"),e=>{(e=l.trim(e))&&function(e,t,i){document.addEventListener("click",function(e){let s=document.querySelectorAll(t),r=e.target;for(let t=0,n=s.length;t<n;t++){let n=r,o=s[t];for(;n&&n!==document;){if(n===o)return i.call(o,e);n=n.parentNode}}})}(0,e,t)}))}function f(e=0,t){let i=["scroll","keyup","keydown","mousemove","mousewheel","mouseenter","mouseover","mousedown","touchstart","touchmove","touchenter"],s=0,r=()=>{s=0},n=l.setInterval(()=>{if(s++,!(s<e)){t&&t();for(let e of i)document.removeEventListener(e,r,!1);l.clearInterval(n)}},1e3);for(let e of i)document.addEventListener(e,r,!1)}let _=l.Date.now();function m(e=0,t){if(e<1)return l.setTimeout(function(){t(e)},100);let i=l.setInterval(()=>{let s=(l.Date.now()-_)/1e3;s<e||(t&&t(s),l.clearInterval(i))},200)}var g={};(g=Object.assign(g,r)).Gate=n().A,g.Mutex=o().A;var v=a();g.get=v.get,g.set=v.set,g.take=v.take,g.Pubsub=c().A;const y=g=Object.assign(g,u);function b(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const w=e();function k(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=y.stringify(i.body)),t(!0)}let x=0,S=(e,t)=>{if("undefined"==typeof sbz_info)return t(!0);let i=e.request;x++,i._id=x,sbz_info["ajax."+x]={created:y.Date.now(),method:i.method,baseurl:i.baseurl,query:i.query},t(!0)},C=(e,t)=>{if("undefined"==typeof sbz_info)return t(!0);let i=e.request._id;sbz_info["ajax."+i]||(sbz_info["ajax."+i]={created:0}),sbz_info["ajax."+i].out={duration:y.Date.now()-sbz_info["ajax."+i].created,code:e.code,err:e.err},t(!0)};const z=class{constructor(e,t){b(this,"listConversations",e=>this.apireq.addQuery("user_id",this.uid).addQuery("integration_id",`${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`)),b(this,"listMessages",(e,t,i)=>this.apireq.addQuery("limit",t).addQuery("start_id",i).get(`/accounts/${this.accid}/conversations/${e}/messages`)),b(this,"ajax",w),b(this,"start",(e,t,i,s)=>{let r=Object.assign({},e);return r.touchpoint||(r.touchpoint={}),r.touchpoint.channel||(r.touchpoint.channel="subiz"),r.touchpoint.source||(r.touchpoint.source="web"),r.source=y.get(document,"location.href"),this.apireq.post(`/accounts/${this.accid}/conversations`,r)}),b(this,"sendConvoEvent",(e,t)=>this.apireq.addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/conversations/${e}/events`,t)),b(this,"createPostback",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/postbacks`,t)),b(this,"markAsReceived",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/receive`)),b(this,"markAsSeen",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/seen`)),b(this,"getConversation",e=>this.apireq.get(`/accounts/${this.accid}/conversations/${e}`)),b(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/languages/${e}`)),b(this,"sendEvent",e=>this.apireq.addQuery("shorten",!0).addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,e)),b(this,"websiteFormRequest",()=>this.apireq.setBaseUrl(this.ApiURL.replace(/\/4\.[01]\/?$/,"/4.1"))),b(this,"submitWebsiteForm",(e,t)=>this.websiteFormRequest().post(`/accounts/${this.accid}/external-forms/${encodeURIComponent(e)}/submissions`,t)),b(this,"submitForm",(e,t,i,s,r)=>this.apireq.addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,{by:{id:this.uid,device:i},type:"form_submitted",data:{user:r,form_submission:{user_id:this.uid,form_id:e,page_url:t,submitted_at:y.Date.now(),values:s}}})),b(this,"sendTyping",e=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/typing`)),b(this,"sendLostFocus",()=>this.apireq.post(`/accounts/${this.accid}/focuses/${this.uid}/delete`)),b(this,"uploadToS3",async e=>{let t=e.name.replace(/\s+/g,"_");var{body:i,error:s}=await this.apireq.setBaseUrl("https://api5.subiz.com.vn/4.1").setQuery({"account-id":this.accid,description:"upload\n user-client: web-widget",name:t,presign:!0,size:e.size,"content-type":e.type}).post("/files");if(s)return{body:i,error:s};let r=i.signed_url,n=i.id,o=await new Promise(t=>{const i=new y.XMLHttpRequest;i.open("PUT",r,!0),i.setRequestHeader("Content-Type",e.type||""),i.onload=function(){200===i.status?t():t(new Error(`Upload failed: ${i.statusText}`))},i.onerror=function(){t(new Error("Network error during upload."))},i.send(e)});if(o)return{error:o};var{body:i,error:s}=await this.apireq.setBaseUrl("https://api5.subiz.com.vn/4.1").setQuery({"account-id":this.accid}).post(`/files/${n}/uploaded`);return s?{error:s}:{url:y.get(i,"file.url","")}}),b(this,"uploadToS32",async e=>{var{body:t,error:i}=await w.setBaseUrl("https://api5.subiz.com.vn/4.1").withCredentials(!0).setQuery({"account-id":this.accid,description:"upload\n user-client: web-widget",name:e.name.replace(/\s+/g,"_"),size:e.size,type:e.type}).setParser("json").beforeHook((e,t)=>{if(this.token_generator){let i=this.profile_id;return void this.token_generator().then(s=>i!=this.profile_id?t(!0):s?"error"==s?t(!1):(e.request=e.request.addQuery("x-access-token",s),t(!0)):t(!1))}return this.ref?e.request=e.request.addQuery("x-user-ref",this.ref):this.mask&&(e.request=e.request.addQuery("x-user-mask",this.mask)),t(!0)}).post("/files",e);return i?{body:t,error:i}:{url:y.get(t,"file.url")}}),b(this,"time",e=>w.setBaseUrl(this.ApiURL).withCredentials(!0).setParser("json").get("/time")),b(this,"updateUser",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`,e)),b(this,"getUser",e=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`)),b(this,"getAccountSetting",async e=>{let t=y.get(document,"location.href"),i={};if(i=e&&e.bot_id?await this.apireq.addQuery("url",t).addQuery("bot_id",e.bot_id).get(`/accounts/${this.accid}/settings`):await this.apireq.addQuery("url",t).get(`/accounts/${this.accid}/settings`),i.error)return i;let s=y.get(i,"body.plugins")||[];return y.map(s,e=>{if("popup"===e.type){let t=y.get(e,"popup.pages")||[];y.map(t,e=>{y.map(e.components,e=>{if("image"===e.type){let t=y.get(e,"image.url");y.set(e,"image.url",function(e){try{const t=new URL(e),i="storage.googleapis.com"===t.hostname,s=t.pathname.startsWith("/public-gcs.subiz-cdn.com/");return i&&s?`https://${t.pathname.slice(1)}`:e}catch(t){return e}}(t))}})})}}),y.set(i,"body.plugins",s),i}),b(this,"sendImpression",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/impressions`,e)),b(this,"sendConversion",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/conversions`,e)),b(this,"lookupOrder",e=>w.setBaseUrl(this.ApiURL).setContentType("text/plain").beforeHook(k).setParser("json").addQuery("x-signed-key",e).get("/orders/123")),b(this,"getOrder",e=>this.apireq.get(`/accounts/${this.accid}/orders/`+e)),b(this,"updateOrder",e=>this.apireq.post(`/accounts/${this.accid}/orders/`+e.id,e)),b(this,"fetchShippingAddresses",()=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`)),b(this,"createShippingAddress",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`,e)),b(this,"list_provinces",()=>this.apireq.get(`/accounts/${this.accid}/provinces`)),b(this,"list_districts",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/districts`)),b(this,"list_wards",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/wards`)),b(this,"checkFormToken",(e,t)=>this.api41.addQuery("account-id",e).get(`/submissions/${t}`)),b(this,"submitForm2",(e,t,i)=>this.api41.addQuery("account-id",e).post(`/submissions/${t}`,i)),b(this,"suggest_address",e=>this.apireq.setQuery({keyword:e}).get(`/accounts/${this.accid}/addresses`)),b(this,"create_ticket",e=>this.apireq.post(`/accounts/${this.accid}/tickets`,e)),this.refreshLock=new y.Mutex,this.FileURL=t,this.ApiURL=e,this.api41=w.setBaseUrl("https://api.sbz.vn/4.1").withCredentials(!0).setContentType("text/plain").beforeHook(k).afterHook(C).beforeHook(S).setParser("json"),this.apireq=w.setBaseUrl(e).withCredentials(!0).addQuery("v","6").setContentType("text/plain").beforeHook(k).afterHook(C).setParser("json").beforeHook(S).beforeHook((e,t)=>{if(this.token_generator){let i=this.profile_id;return void this.token_generator().then(s=>i!=this.profile_id?t(!0):s?"error"==s?t(!1):(e.request=e.request.addQuery("x-access-token",s),t(!0)):t(!1))}return this.ref?e.request=e.request.addQuery("x-user-ref",this.ref):this.mask&&(e.request=e.request.addQuery("x-user-mask",this.mask)),t(!0)})}setAgentId(e){this.agentid=e}async setAuth(e){if(e.accid&&(this.accid=e.accid),e.ref&&(this.ref=e.ref),this.mask=e.mask,this.profile_id=e.profile_id,e.ref){let e;for(let t=0;e=await w.setBaseUrl(this.ApiURL).withCredentials(!0).afterHook(C).beforeHook(S).addQuery("v","6").addQuery("x-user-ref",this.ref).setParser("json").get(`/accounts/${this.accid}/users/${this.ref}`),-1==y.get(e,"body.error.code","").indexOf("locked_account");t++){if(-1==y.get(e,"body.error.code","").indexOf("user_is_banned")){if(!y.get(e,"body.id")){let e=Math.min(2e3+400*t,6e4);await y.sleep(e);continue}break}await y.sleep(12e4)}return e.error?y.get(e.body.code)?{error:e.body.code}:e:(this.uid=e.body.id,e.body)}if(e.tokenGenerator){let t=e.tokenGenerator;this.tokensession=this.tokensession||0,this.tokensession++;let i=this.tokensession;if(!this.accid||!y.startsWith(this.accid,"ac"))return{error:"invalid_account_id"};if(!this.profile_id)return{error:"invalid_profile_id"};if("function"!=typeof t)return{error:"invalid_token_generator"};let s,r=this.profile_id;this.token_generator=async e=>{if(await this.refreshLock.lock(),i!=this.tokensession)return void this.refreshLock.unlock();let s,n,o=(y.Date.now()-(this.last_token_at||0))/1e3;if(!e&&this.last_token&&o<1800)return this.refreshLock.unlock(),this.last_token;if(!e&&this.last_token&&o<3e3)return this.token_generator&&y.setTimeout(async()=>{let e,s;try{e=await t(r)}catch(e){s=e}i==this.tokensession?(this.last_token=s?"error":e,this.last_token_at=y.Date.now(),this.refreshLock.unlock()):this.refreshLock.unlock()}),this.last_token;try{s=await t(r)}catch(e){n=e}if(i==this.tokensession)return this.last_token=n?"error":s,this.last_token_at=y.Date.now(),this.refreshLock.unlock(),this.last_token;this.refreshLock.unlock()};for(let e=0;await this.token_generator(!0),i==this.tokensession;e++){if(s=await w.setBaseUrl(this.ApiURL).withCredentials(!0).addQuery("v","6").afterHook(C).beforeHook(S).addQuery("x-access-token",this.last_token).setParser("json").get(`/accounts/${this.accid}/users/${r}`),!y.get(s,"body.id")){let t=Math.min(2e3+100*e,12e4);await y.sleep(t);continue}break}return s.error?y.get(s.body.code)?{error:s.body.code}:s:(this.uid=s.body.id,s.body)}if(this.mask){let e=this.mask.split("@");return this.uid=e[1],{id:this.uid}}return{error:"invalid_auth"}}sendContentView(e,t,i,s,r,n){return s||(s=void 0),r||(r=void 0),this.sendEvent({by:{id:this.uid,device:e},type:"content_viewed",data:{product:{id:s,source_id:r,url:t,name:i,title:i,sku:n}}})}};let A=t(),T="undefined"!=typeof window?window.requestIdleCallback:null;T||(T=e=>e());const E=class{constructor(e,t){if(this.localStorage=A,this.inmem=t,this.allkeys={},!t)try{window.localStorage.setItem("sbzstore1029","?"),window.localStorage.removeItem("sbzstore1029"),this.localStorage=window.localStorage}catch(e){}this.schema=e}all(e){let t=[];for(var i=0;i<this.localStorage.length;i++){let s=this.localStorage.key(i);s.startsWith(this.schema+"#"+e+"#")&&(this.allkeys[s]=!0,this.inmem?t.push(this.localStorage.getItem(s)):t.push(y.parseJSON(this.localStorage.getItem(s))))}return t}removes(e,t){for(var i=0;i<t.length;i++)delete this.allkeys[this.schema+"#"+e+"#"+t[i]],this.localStorage.removeItem(this.schema+"#"+e+"#"+t[i])}clear(e){for(var t=[],i=0;i<this.localStorage.length;i++){let s=this.localStorage.key(i);s.startsWith(this.schema+"#"+e+"#")&&t.push(s)}for(i=0;i<t.length;i++)this.localStorage.removeItem(t[i]);this.allkeys={}}put(e,t,i){if(this.allkeys[this.schema+"#"+e+"#"+t]=!0,this.inmem)return this.localStorage.setItem(this.schema+"#"+e+"#"+t,i);Object.keys(this.allkeys).length>80&&this.clear(e),T(()=>{try{this.localStorage.setItem(this.schema+"#"+e+"#"+t,void 0===(s=i)?"null":y.stringify(s))}catch(t){this.clear(e)}var s})}};class P{constructor(e,t,i){this.schema=t+"_chain",this.dead=!1,this.db=e,this.anchorCache={},this.cache={},this.init()}init(){let e={};this.db.all("items").map(t=>{e[t.chain]=e[t.chain]||{},e[t.chain][t.id]={id:t.id,chain:t.chain,full_id:t.full_id,index:t.index,value:t.value}}),j(e,(t,i)=>{if(M(t)<50)return;let s=(r=j(t),n=["index"],o=[],j(r,e=>o.push(e)),o.sort((e,t)=>{if(e[n]===t[n])return 0;var i=e[n]<t[n]?-1:1;return-i}),o);var r,n,o;let a=[];for(var c=50;c<s.length;c++)a.push(s[c].full_id),delete t[s[c].id];this.db.removes("items",a),e[i]=t}),this.cache=e}destroy(){this.db.clear("items"),this.dead=!0,this.cache={},this.anchorCache={},this.db=void 0}put(e,t,i,s){if(this.dead)return;let r=this.cache[e]||{},n=(O(r)||{}).index||"z";0==M(r)&&(n="");let o={id:t,index:i,value:s,chain:e,full_id:e+":"+t};delete r[o.id],n>o.index+""||(r[o.id]=o,this.cache[e]=r,this.db.put("items",o.full_id,o))}listM(e){if(this.dead)return{};let t=this.cache[e]||{},i={};return j(t,(e,t)=>{i[t]=e.value}),i}async fetchMore(e,t=20,i){if(this.dead)return{error:"dead"};if(!i)return{error:"no api"};let s=this.anchorCache[e]||"";var[r,n,o]=await i(e,s,t);if(o)return{error:o};if(this.dead)return{error:"dead"};let a=this.cache[e]||{};return 0===r.length?{end:!0}:(r.forEach(t=>{t.chain=e,t.full_id=e+":"+t.id,a[t.id]=t,this.db.put("items",t.full_id,t)}),this.anchorCache[e]=n,this.cache[e]=a,{})}merge(e,t){if(this.dead)return;const i=this.cache[e]||{};for(const s of t){const t={...s,chain:e,full_id:e+":"+s.id};i[s.id]=t,this.db.put("items",t.full_id,t)}this.cache[e]=i}del(e,t){if(this.dead)return;let i=e+":"+t;delete(this.cache[e]||{})[t],this.db.removes("items",[i])}match(e,t){return this.listM(e)[t]}async reload(e,t){if(this.dead)return;let i=(function(e){if(!e)return;let t=Object.keys(e);if(!t.length)return;let i=-1/0,s=Object.keys(e)[0];for(var r=0;r<t.length;r++){let n=e[t[r]]&&e[t[r]].index||-1/0;n>i&&(i=n,s=t[r])}return e[s]}(this.cache[e]||{})||{}).index;i||(i=Date.now());for(var s="",r={};;){if(this.dead)return;let[n,o,a]=await t(e,s,50);if(a)return;if(this.dead)return;if(n.map(t=>{r[t.id]=Object.assign({},t,{chain:e,full_id:e+":"+t.id})}),0===n.length||o===s)break;if((O(r)||{}).index<=i){s=this.anchorCache[e]||o;break}if(M(r)>=200){let t=this.cache[e]||{},i=[];j(t,t=>{t.chain===e&&i.push(t.full_id)}),this.db.removes("items",i),this.cache[e]={},s=o;break}s=o}for(const e of Object.values(r))this.db.put("items",e.full_id,e),this.cache[e.chain]=this.cache[e.chain]||{},this.cache[e.chain][e.id]=e;this.anchorCache[e]=s}}function O(e){if(!e)return;let t=Object.keys(e);if(!t.length)return;let i=1/0,s=Object.keys(e)[0];for(var r=0;r<t.length;r++){let n=e[t[r]]&&e[t[r]].index||1/0;n<i&&(i=n,s=t[r])}return e[s]}function j(e,t){if(!e)return[];if(!t)return e;var i=[];if(Array.isArray(e)){for(let s=0;s<e.length;s++)i.push(t(e[s],s));return i}if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];i.push(t(e[r],r))}return i}return i}function M(e){return e?void 0!==e.length?e.length:Object.keys(e).length:0}const I=class{constructor(e,t){this.name=t,t+="_kv",this.dead=!1,this.db=e,this.cache={},this.initialized=!1,this.init()}refreshCache(){if(this.dead)return;let e={};this.db.all("items").forEach(function(t){e[t.key]=t.value}),this.cache=e}init(){if(this.initialized)return;let e={};this.db.all("items").forEach(function(t){e[t.key]=t.value}),this.cache=e,this.trimCache(),this.initialized=!0}trimCache(){const e=Object.keys(this.cache);if(e.length<=500)return;const t=e.slice(0,e.length-Math.floor(250));for(const e of t)delete this.cache[e];this.db.removes("items",t)}all(){return this.dead?[]:this.initialized?this.cache:[]}match(e){if(!this.dead&&this.initialized&&e)return this.cache[e]}put(e,t){if(e){if(this.dead)return[];if(!this.initialized)throw new Error("uninitialized");this.cache[e]=t,this.db.put("items",e,{key:e,value:t}),this.trimCache()}}del(e){if(!this.dead){if(!this.initialized)throw new Error("uninitialized");delete this.cache[e],this.db.removes("items",[e])}}destroy(){this.db.clear("items"),this.dead=!0,this.db=void 0,this.cache=void 0,this.initialized=!1}};function L(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const R=e();function q(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=y.stringify(i.body)),t(!0)}const U=Promise.resolve({code:200}),F=class{constructor(e,t){L(this,"listConversations",e=>{let t=D(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:{anchor:"",conversations:[t]},code:200})}),L(this,"listMessages",(e,t,i)=>{let s=function(e,t,i,s){let r=e+".subizv4.subikon",n={type:"user",id:i,last_page_view_url:"https://subiz.com.vn/",conversation_id:t,membership:"active",invited_by:{id:i,type:"user"}},o={type:"agent",conversation_id:t,id:s,membership:"active",invited_by:{id:i,type:"user"}};return[{id:"evqyiyjmxrjsylftvnrghrfmq",account_id:e,created:1616213202264,type:"conversation_invited",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,members:[n],state:"pending"}}},{id:"evqyiyjmyqdgrouswczzawuzp",account_id:e,created:1616213202559,type:"conversation_invited",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,members:[o],state:"pending",source:"https://subiz.com.vn/vi/"}}},{id:"evqyiyjmyzjpyehnngvmcyauf",account_id:e,created:1616213202668,type:"conversation_state_updated",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,state:"active"}}},{id:"evqyiyjmzaozvqgbkljbwywdl",account_id:e,created:1616213202683,type:"conversation_joined",by:{id:i,type:"user"},data:{conversation:{id:t,members:[n]}}},{id:"evqyiyjmzatvtgpdmmpzwnwgn",source_event_id:"wrueysyjbhqrkiwhsejpqrwqrdkkyaibajdw",account_id:e,created:1616213202685,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"Xin chào",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213203068}]}}},{id:"evqyiyjrhsfyuxtetszmvkkke",account_id:e,created:1616213237491,type:"conversation_joined",by:{id:i,type:"user"},data:{conversation:{id:t,members:[o]}}},{id:"evqyiyjrhtroknjyakrlrwhgr",account_id:e,created:1616213237508,type:"message_sent",by:{id:s,client_id:"dashboard",type:"agent"},data:{message:{conversation_id:t,text:"chào bạn, mình có thể giúp gì được cho bạn :grinning:",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"receive",created:1616213237742},{member_id:i,type:"seen",created:1616213240057}]}}},{id:"evqyiyjuvjinmclneroerxmrl",account_id:e,created:1616213265805,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"mình muốn hỏi giá sản phẩm IPhone X",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213267090}]}}},{id:"evqyiyjzjxzfcsexshcjbbnnf",account_id:e,created:1616213302432,type:"message_sent",by:{id:s,client_id:"dashboard",type:"agent"},data:{message:{conversation_id:t,text:"IPhone X hiện đang được bán tại cửa hàng với giá 12tr đồng nha bạn",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"receive",created:1616213302698},{member_id:i,type:"seen",created:1616213305071}]}}},{id:"evqyiykaoizbwnkaecwphttwk",account_id:e,created:1616213311830,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"ok cám ơn!",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213312110}]}}}]}(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:s,code:200})}),L(this,"ajax",R),L(this,"start",e=>U),L(this,"sendConvoEvent",(e,t)=>U),L(this,"createPostback",(e,t)=>U),L(this,"markAsReceived",(e,t)=>U),L(this,"markAsSeen",(e,t)=>U),L(this,"getConversation",e=>Promise.resolve({body:D(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid),code:200})),L(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/locales/${e}`)),L(this,"sendEvent",e=>U),L(this,"submitForm",(e,t,i,s,r)=>U),L(this,"sendTyping",e=>U),L(this,"sendPresence",e=>U),L(this,"sendContent",e=>U),L(this,"sendLostFocus",e=>U),L(this,"sendContentView",e=>U),L(this,"uploadToS3",async e=>U),L(this,"time",e=>Promise.resolve({code:200,body:(new y.Date).toISOString()})),L(this,"updateUser",e=>U),L(this,"getUser",e=>Promise.resolve({code:200,body:{id:"usqzgtgfake",attributes:[{key:"fullname",text:"Kiều Thanh"}]}})),L(this,"getAccountSetting",()=>this.apireq.get(`/accounts/${this.accid}/settings`)),L(this,"sendImpression",e=>U),L(this,"sendConversion",e=>U),this.FileURL=t,this.apireq=R.setBaseUrl(e).setContentType("text/plain").beforeHook(q).setParser("json")}setAgentId(e){this.agentid=e}setAuth(e){return this.accid=e.accid,this.mask=e.mask,this.uid=e.uid,{account_id:this.accid,id:"usqzgtgfake",attributes:[{key:"fullname",text:"Kiều Thanh"}]}}};function D(e,t,i,s){return{id:t,account_id:e,created:1610452894916,members:[{type:"user",id:i,membership:"active",invited_by:{id:i,type:"user"}},{type:"agent",id:s,conversation_id:t,membership:"active",invited_by:{id:i,type:"user"}}],ended:1610454875505,state:"ended",actived:1610453070259,last_message_sent:{id:"evqyiykaoizbwnkaecwphttwk",account_id:e,created:1616213311830,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"ok cám ơn!",format:"plaintext",integration_id:e+".subizv4.subikon",pongs:[{member_id:i,type:"seen",created:1616213312110}]}}},assigned_to:{},first_message:"Xin chào",subject:"Chúc một ngày tốt lành",source:"https://subiz.com.vn/"}}const $=class{onEvent(){}onInterrupted(){}subscribe(){}stop(){}getStatus(){return"active"}reconnect(){}};function W(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var N=i(8193),B=i(2839),V=i(5672);V.defaults.path="/",V.expiresMultiplier=86400,V.defaults.expires=3650;let H=t();const G=y.Date.now(),Q="chat_state_cycle_started_at",J=["lastview","light_convos","bot_run_logs","close_preview_at"];class X{constructor(e,t,i,s,r){if(W(this,"inmem",!1),W(this,"cookie",V),W(this,"getConnectionStatus",()=>this.connectionStatus),W(this,"_currentViewingProduct",{}),W(this,"new_visitor",!0),W(this,"matchUser",()=>{if(this.cache)return this._touchAcc(),this.cache.match("user")}),W(this,"suggest_addresses",e=>this.api.suggest_address(e)),W(this,"matchAccount",()=>this.cache.match("account")),W(this,"matchPaymentMethods",()=>this.cache.match("payment_methods")),W(this,"matchUnread",()=>{let e=this.matchUser();if(!e||!e.id)return;let t=this.matchConvo("*"),i=0;return y.map(t,t=>{y.isConvoSeen(t,e.id)||i++}),i}),W(this,"matchPlugin",()=>{if(this.is_embed_chat_mode){let e=this.cache.match("plugin");y.size(this.forcePlugins)>0&&(e=this.forcePlugins);let t=y.filter(e,(e,t)=>e&&"chatbox"===e.type);if(0===y.size(t))return void console.error("no chatbox found.");let i=y.find(t,e=>!!e);return i||(i=t[0]),i=y.cloneDeep(i),i.triggers=void 0,{[i.id]:i}}return y.size(this.forcePlugins)>0?y.cloneDeep(this.forcePlugins):y.cloneDeep(this.cache.match("plugin"))||{}}),W(this,"device",{}),W(this,"browserVisibility","visible"),W(this,"matchAgent",e=>{let t=this.cache.match("agent")||{};return"*"===e?t:t[e]}),W(this,"matchConvo",e=>{if(e)return"*"===e?(this._touchAcc(),y.filter(this.cache.all(),(e,t)=>t.startsWith("convo_")).concat(y.map(this.lightConvos))):e.startsWith("cslight")?this.lightConvos[e]:(this.isInsync(e)||this.fetchConvo(e),this.cache.match("convo_"+e))}),W(this,"fetchConvo",async e=>{if(e&&!e.startsWith("cslight")){if(this._die)return se;await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die||this.isInsync(e))return;if(this.convoFetchAfter=this.convoFetchAfter||{},y.Date.now()<(this.convoFetchAfter[e]||0))return;this.convoFetchAfter[e]=y.Date.now()+15e3;let{body:t,error:i}=await this.api.getConversation(e);t&&!i&&this._setConvo(t)}catch(e){return{error:e}}finally{this.reconnectGate.open()}}}),W(this,"list_provinces",()=>this.api.list_provinces()),W(this,"list_districts",e=>this.api.list_districts(e)),W(this,"list_wards",e=>this.api.list_wards(e)),W(this,"outofmsgM",{}),W(this,"listEvents",e=>{if(e&&"*"!==e&&"string"==typeof e)return e.startsWith("cslight")?y.get(this.lightConvos,[e,"events"],[]):this.chain.listM(e)}),W(this,"fetchMoreEvents",(e,t=150)=>{if(this.historyRequests=this.historyRequests||new Map,this.historyRequests.has(e))return this.historyRequests.get(e);this.historyFailures=this.historyFailures||{};const i=this.historyFailures[e];if(i&&y.Date.now()<i.retryAt)return Promise.resolve({error:i.error});const s=this._fetchMoreEvents(e,t).then(t=>(t.error?this.historyFailures[e]={error:t.error,retryAt:y.Date.now()+15e3}:delete this.historyFailures[e],t)).finally(()=>{this.historyRequests.get(e)===s&&this.historyRequests.delete(e)});return this.historyRequests.set(e,s),s}),W(this,"syncConvoEvents",e=>{if(this._die||!e||e.startsWith("cslight"))return Promise.resolve({});if(this.messageSyncRequests=this.messageSyncRequests||new Map,this.messageSyncRequests.has(e))return this.messageSyncRequests.get(e);if(this.messageSyncNextAt=this.messageSyncNextAt||{},y.Date.now()<(this.messageSyncNextAt[e]||0))return Promise.resolve({skipped:!0});const t=this.chain,i=this._syncConvoEvents(e,t).then(i=>{if(t===this.chain&&!this._die){this.messageSyncFailures=this.messageSyncFailures||{};const t=i.error?Math.min((this.messageSyncFailures[e]||0)+1,4):0;this.messageSyncFailures[e]=t,this.messageSyncNextAt[e]=y.Date.now()+(t?15e3*2**(t-1):15e3)}return i}).finally(()=>{this.messageSyncRequests.get(e)===i&&this.messageSyncRequests.delete(e)});return this.messageSyncRequests.set(e,i),i}),W(this,"reloadConvoEvents",async e=>{await this.chain.reload(e,()=>[[],""]);let{error:t}=await this.chain.fetchMore(e,150,async(t,i,s)=>{let[r,n,o,a]=await this.listmessageapi(t,i,s);return a&&(this.outofmsgM[e]=!0),[r,n,o]});return{error:t}}),W(this,"_doFetchMsg",async(e,t=150)=>{let{error:i}=await this.chain.fetchMore(e,t,async(t,i,s)=>{if(this.outofmsgM[e])return[[],""];let[r,n,o,a]=await this.listmessageapi(t,i,s);return a&&(this.outofmsgM[e]=!0),[r,n,o]});return this.pubsub.publish("account"),{error:i}}),W(this,"matchLocation",()=>this.cache.match("location")||{}),W(this,"matchBot",()=>this.cache.match("bot")||{}),W(this,"readyGate",new y.Gate),W(this,"convoGate",new y.Gate(!0)),W(this,"reconnectGate",new y.Gate(!0)),W(this,"wsGate",new y.Gate(!0)),W(this,"matchLastview",()=>this.kv.match("lastview")||{}),W(this,"matchIsOpen",()=>!!this.kv.match("isopen")),W(this,"matchClosePreviewAt",()=>this.kv.match("close_preview_at")||0),W(this,"checkFormToken",(e,t)=>this.api.checkFormToken(e,t)),W(this,"submitForm2",(e,t,i)=>this.api.submitForm2(e,t,i)),W(this,"sendPresence",y.throttle(async()=>{if(this._track_page_view){if(this._die)return se;if(await this.readyGate.entry(),y.get(this.cache.match("user"),"id")&&!y.isUserBanned(this.cache.match("user")))return"visible"===this.browserVisibility&&document.hasFocus()?void this.sendPageview():this.api.sendLostFocus()}},1e3,{leading:!1})),W(this,"now",()=>y.Date.now()+this.timeDiff),W(this,"seenQueue",[]),W(this,"matchTrafficSource",()=>this.kv.match("traffic_source")),W(this,"_alreadyReceived",{}),W(this,"_typing",y.throttle(e=>this.api.sendTyping(e),3e3,{trailing:!1})),W(this,"onConvoEvent",(e,t)=>this.pubsub.on2(e,"events",t)),W(this,"onWidgetClose",(e,t)=>this.pubsub.on2(e,"sbz_close_widget",t)),W(this,"onMessageUpdated",(e,t)=>this.pubsub.on2(e,"message_updated",t)),W(this,"seenConvo",e=>{e&&"create"!==e&&this.seenQueue.push(e)}),W(this,"onUpdate",(e,t)=>this.pubsub.on2(e,"account",t)),W(this,"onDestroyed",(e,t)=>this.pubsub.on2(e,"destroy",t)),W(this,"onConnection",(e,t)=>this.pubsub.on2(e,"connection",t)),W(this,"onResetCSS",(e,t)=>this.pubsub.on2(e,"resetCSS",t)),W(this,"onHighlight",(e,t)=>this.pubsub.on2(e,"highlight",t)),W(this,"closePreview",()=>this.kv.put("close_preview_at",(new y.Date).getTime())),W(this,"updateLastview",e=>{let t=this.cache.match("user")||{};if(!t.id)return;let i=this.matchLastview()||{},s={...i,...e,user_id:t.id};this.kv.put("lastview",s),this.pubsub.publish("lastview",s,i)}),W(this,"onLastview",(e,t)=>this.pubsub.on2(e,"lastview",t)),W(this,"timeDiff",0),this.connectionStatus="active",this.CONNECTION_CHECK_INTERVAL=3e3,this.reconnectTimestamp=0,this.g_sync={},this._die=!1,this.forceDevice=null,this.forcePlugins={},this.forceAcc={},this.forceChatbox={},this.RealtimeURL=i,this.fake=r,this.FileURL=t,this._track_page_view=!0,this.device_type="desktop",this.fake?this.api=new F(e,t):this.api=new z(e,t),!s)try{document.cookie,localStorage}catch(e){s=!0}s&&(this.inmem=s,this.cookie=K),ee(),this.pubsub=new y.Pubsub,this.kv=new I(new E("sbz2023",this.inmem),"kv"),this.cache=new I(new E("sbz2023",!0),"kv"),this.chain=new P(new E("cbz2023",!0),"ch"),this.getLocaleContent=this.api.getLocaleContent,this.g_haveSentSeenM={},this.last_focused=this.now(),this._onBlur=()=>{this._die||(this.last_focused=this.now(),this.sendPresence())},this._onFocus=()=>{this._die||(this.last_focused=0,this.sendPresence())},this._onBeforeUnload=()=>{this._die||this.api.sendLostFocus()},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),window.addEventListener("beforeunload",this._onBeforeUnload),this._lastPresenceURL=window.location.href,this._urlCheckInterval=y.setInterval(()=>{if(this._die)return y.clearInterval(this._urlCheckInterval);this._lastPresenceURL!==window.location.href&&(this._lastPresenceURL=window.location.href,this.sendPresence())},2e3),this.doNotStartBot=()=>{this._donotstartbot=!0},this.autoStartBot=()=>{this._donotstartbot=!1},this.matchAutoStartBot=()=>!this._donotstartbot,this._presenceInterval1=y.setInterval(()=>{if(this._die)return y.clearInterval(this._presenceInterval1);"visible"===this.browserVisibility&&document.hasFocus()&&this.sendPresence()},2e4),this._presenceInterval2=y.setInterval(()=>{if(this._die)return y.clearInterval(this._presenceInterval2);"visible"===this.browserVisibility&&document.hasFocus()||this.last_focused&&this.now()-this.last_focused>18e5||this.sendPresence()},6e4),this._visibilityCleanup=function(e){var t="hidden";let i,s=document,r={};if(t in document)i="visibilitychange";else if((t="mozHidden")in document)i="mozvisibilitychange";else if((t="webkitHidden")in document)i="webkitvisibilitychange";else if((t="msHidden")in document)i="msvisibilitychange";else if("onfocusin"in document)r={onfocusin:document.onfocusin,onfocusout:document.onfocusout},document.onfocusin=document.onfocusout=n;else{s=window;for(const e of["onpageshow","onpagehide","onfocus","onblur"])r[e]=window[e],window[e]=n}function n(i){var s="visible",r="hidden",n={focus:s,focusin:s,pageshow:s,blur:r,focusout:r,pagehide:r};(i=i||window.event).type in n?e(n[i.type]):e(this[t]?"hidden":"visible")}return i&&s.addEventListener(i,n),void 0!==document[t]&&n({type:document[t]?"blur":"focus"}),()=>{i&&s.removeEventListener(i,n);for(const e of Object.keys(r))s[e]===n&&(s[e]=r[e])}}(e=>{this._die||(this.browserVisibility=e,this.sendPresence())}),this.loopTime(),this.device=this.getDeviceInfo(),this._gaInterval=y.setInterval(()=>{if(this._die)return;let e=this.cache.match("user")||{};if(!e.id)return;var t=this.getDeviceInfo();if(!t.ga_tracking_ids||!t.ga_client_id)return;y.clearInterval(this._gaInterval),this.device=t;let i=t.ga_client_id;i!==y.getUserAttr(e,"ga_client_id","text")&&this.setUser({attributes:[{type:"text",text:i,key:"ga_client_id"}]})},2e3),this.loopCheckConnectionStatus()}async loopCheckConnectionStatus(){for(;!this._die;){if(await y.sleep(this.CONNECTION_CHECK_INTERVAL),!this.realtime)continue;if(!this.realtime.getStatus||!this.realtime.reconnect)continue;this.connectionStatus;let e=this.connectionStatus;this.connectionStatus=this.realtime.getStatus(),e!==this.connectionStatus&&(console.log("publish connectionStatus",this.connectionStatus),this.pubsub.publish("connection")),"active"!==this.connectionStatus||!this._needsMessageSync&&"active"===e||(this._needsMessageSync=!1,this.syncKnownConvoEvents())}}syncKnownConvoEvents(){if(this._die)return Promise.resolve();if(this.knownConvoSyncRequest)return this.knownConvoSyncRequest;const e=this.chain,t=(async()=>{const t=y.filter(this.cache.all(),(e,t)=>t.startsWith("convo_"));for(const i of t){if(this._die||e!==this.chain)break;await this.syncConvoEvents(i.id)}})().finally(()=>{this.knownConvoSyncRequest===t&&(this.knownConvoSyncRequest=null)});return this.knownConvoSyncRequest=t,t}linkProduct(e){e?(e.id&&(this._currentViewingProduct.id=(e.id+"").trim()),e.source_id&&(this._currentViewingProduct.source_id=(e.source_id+"").trim()),e.sku&&(this._currentViewingProduct.sku=(e.sku+"").trim())):this._currentViewingProduct={}}getTrackPageview(){return this._track_page_view}setTrackPageview(e){this._track_page_view=!!e}getLinkedProduct(){return y.cloneDeep(this._currentViewingProduct)}isInsync(e){return y.Date.now()-(this.g_sync[e]||0)<6e5}async fetchShippingAddresses(){let e=await this.api.fetchShippingAddresses();if(e.error)return null;this.cache.put("shipping_address",e.body.shipping_addresses)}matchShippingAddresses(){return this.cache.match("shipping_address")}updateOrder(e){return this.api.updateOrder(e)}createShippingAddress(e){return this.api.createShippingAddress(e)}createTicket(e){return this.api.create_ticket(e)}overrideWelcomeMessage(e){y.map(this.lightConvos,(t,i)=>{t.last_message_sent&&(t.last_message_sent.data.message=e,t.last_message_sent.data.message.conversation_id=i);let s=y.get(t.events,"0");s.data.message=e,s.data.message.conversation_id=i,this.pubsub.publish("events",s)})}async overrideAcc(e){this.forceAcc=y.cloneDeep(e),await this.readyGate.entry(),this.reconnect()}async overrideBotId(e){this.forceBotId=e,await this.readyGate.entry()}async overrideChatbox(e){this.forceChatbox=e,await this.readyGate.entry(),await this.reconnect(),y.setTimeout(this.pubsub.publish("resetCSS"),10)}onShowMessageInfo(e){this.pubsub.publish("events",{type:"show_event_info",id:e})}getDeviceInfo(){let e={screen_resolution:window.screen.width+"x"+window.screen.height,source_referrer:document.referrer,platform:window.navigator.platform,language:navigator.language,page_url:document.URL,page_title:document.title},t=function(){if(!window.ga)return;if(!window.ga.getAll)return;var e=window.ga.getAll()||[];let t="";return e.forEach(function(e){t=e.get("clientId")}),t}();t&&(e.ga_client_id=t);let i=(s=[],window.ga&&window.ga.getAll?window.ga&&window.ga.getAll?((window.ga.getAll()||[]).forEach(function(e){var t=e.get("trackingId");t&&s.push(t)}),s):[]:s);var s;return i.length>0&&(e.ga_tracking_ids=i),e}highlight(e,t){this.pubsub.publish("highlight",e,t)}emitConvoEvent(e){this.pubsub.publish("events",e)}setAIDevMode(e){this.ai_dev_mode=e}setEmbebedChatMode(){this.is_embed_chat_mode=!0}isAIDevMode(){return this.ai_dev_mode}isEmbededChatMode(){return this.is_embed_chat_mode}overrideDeviceType(e){this.forceDevice=e,this.pubsub.publish("account")}isMobile(){return this.forceDevice?"mobile"===this.forceDevice:"mobile"==this.device_type||y.get(window,"screen.width",1e3)<576}isTablet(){return this.forceDevice?"tablet"===this.forceDevice:"tablet"==this.device_type}isDesktop(){return this.forceDevice?"desktop"===this.forceDevice:!this.isMobile()&&!this.isTable()}disconnect(e){this.g_sync[e]=0}pageLoaded(){return G}overridePlugin(e){if(this._die)return se;if(!Array.isArray(e))throw"plugins must be be an array";let t={};y.map(e,function(e){t[e.id]=e}),this.forcePlugins=t,this.pubsub.publish("account"),this.pubsub.publish("resetCSS")}markSync(e){this.g_sync[e]=y.Date.now()}async _touchAcc(){this.isInsync("account")||(await this.readyGate.entry(),this.isInsync("account")||this.refreshAccount())}refreshAccount(){if(!(this._die||y.Date.now()<(this.accountRefreshAfter||0)))return this.accountRefreshAfter=y.Date.now()+3e4,this.reconnect()}async _fetchMoreEvents(e,t=150){if(!e||e.startsWith("cslight"))return{};await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die)return se;!this.isInsync("events"+e)&&(this.chain.anchorCache[e]="",delete this.outofmsgM[e]);const i=await this._doFetchMsg(e,t);return i.error||this.markSync("events"+e),i}catch(e){return{error:e}}finally{this.reconnectGate.open()}}async _syncConvoEvents(e,t){await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die||t!==this.chain)return se;this.messageSyncTimes=this.messageSyncTimes||{},this.messageSyncProgress=this.messageSyncProgress||{};let i=this.messageSyncProgress[e];if(!i){const s=Object.values(t.listM(e)),r=this.messageSyncTimes[e]||s.reduce((e,t)=>Math.min(e,y.getMs(t.created)),1/0);i=this.messageSyncProgress[e]={boundary:r,anchor:"",newest:0,visited:new Set}}for(let s=0;s<5;s++){const s=(this.nextMessageSyncRequestAt||0)-y.Date.now();if(s>0&&await y.sleep(s),this._die||t!==this.chain)return se;this.nextMessageSyncRequestAt=y.Date.now()+250;const[r,n,o,a]=await this.listmessageapi(e,i.anchor,150);if(this._die||t!==this.chain)return se;if(o)return{error:o};t.merge(e,r);for(const e of r)i.newest=Math.max(i.newest,e.index);if(this.pubsub.publish("account"),a||!r.length||r.some(e=>e.index<i.boundary))return i.newest&&(this.messageSyncTimes[e]=i.newest),delete this.messageSyncProgress[e],{};if(i.visited.add(i.anchor),!n||i.visited.has(n))return delete this.messageSyncProgress[e],{error:"message_cursor_stalled"};i.anchor=n}return{pending:!0}}catch(e){return{error:e}}finally{this.reconnectGate.open()}}async init(e,t,i,s){if(this.g_sync={},"undefined"!=typeof sbz_info&&(sbz_info.store_0=!0),s&&s.use_subdomain_cookie||window&&window.location&&window.location.hostname&&(V.defaults.domain="."+window.location.hostname),"undefined"!=typeof sbz_info&&(sbz_info.store_1=!0),!i){try{i=this.cookie.get("__sbref","")}catch(e){}if("undefined"!=typeof sbz_info&&(sbz_info.store_2=!0),!i){if(!t)try{t=this.cookie.get("__sbmask","")}catch(e){}t?(t.split("@")[0]!=e&&(i=y.randomString(40),this.new_visitor=!0),this.new_visitor=!1,this.cookie.set("__sbmask",t)):(i=y.randomString(40),this.new_visitor=!0)}}return"undefined"!=typeof sbz_info&&(sbz_info.store_3=!0),this.cookie.get("__sbref",i)!=i&&(te(),this.clearBrowserData()),"undefined"!=typeof sbz_info&&(sbz_info.store_4=!0),this.api.setAuth({accid:e}),"undefined"!=typeof sbz_info&&(sbz_info.store_5=!0),i&&this.cookie.set("__sbref",i),"undefined"!=typeof sbz_info&&(sbz_info.store_6=!0),this._initResource(e,{accid:e,mask:t,ref:i},{account_id:e,user_ref:i,user_mask:t})}standardlizeLastview(){let e=this.kv.match("lastview")||{},t=this.cache.match("user")||{};if(t.id||(e={}),e.user_id!=t.id&&(e={}),e.screen||(e.screen="preview","list"!==e.view&&"chat"!==e.view||(e.screen="widget")),this.isMobile()){e.screen="preview";let t=this.matchPlugin()||{},i=y.find(t,e=>"chatbox"===e.type)||{};y.get(i,"chatbox.greeting.mobile_disabled")&&(e.screen="button")}this.kv.put("lastview",e)}resetChatStateIfExpired(){const e=this.now(),t=this.kv.match(Q);return!Number.isFinite(t)||t<=0||t>e?(this.kv.put(Q,e),!1):!(e-t<864e5||(y.map(J,e=>this.kv.del(e)),this.kv.put(Q,e),0))}async _initResource(e,t,i){this.g_sync={};let s=await this.api.setAuth(t);if("undefined"!=typeof sbz_info&&(sbz_info.store_7=!0),s.error)return console.error(s),s;this.readyGate.close(),e=(e||"").trim(),this.resetChatStateIfExpired();let r=this.kv.match("light_convos")||{};return this.lightConvos={},y.map(r,t=>{if("widget"===t.light_type&&(t.account_id!==e||t.initial_by!==s.id))return;let i=t.created>y.Date.now()-6048e5,r=y.filter(t.events,e=>"message_sent"===e.type),n=y.map(r,e=>y.get(e,"data.message")||{});n=y.filter(n,e=>!y.isEmptyMessage(e)),i&&y.size(n)&&(this.lightConvos[t.id]=t)}),this.cache=new I(new E("sbz2023",!0),"kv"),this.realtime&&this.realtime.stop(),this.fake?this.realtime=new $:this.realtime=new B(this.RealtimeURL,i,ie,e),this.realtime.onEvent(this.onWs.bind(this)),this.realtime.onInterrupted(async()=>{this._die||(this._needsMessageSync=!0,await this.reconnectWs(e,s.id),await this.refreshAccount())}),"undefined"!=typeof sbz_info&&(sbz_info.store_8=!0),this.seenLoop(),"undefined"!=typeof sbz_info&&(sbz_info.store_9=!0),await this.reconnect({user:s}),this.standardlizeLastview(),"undefined"!=typeof sbz_info&&(sbz_info.store_10=!0),this.readyGate.open(),this.reconnectWs(e,s.id),s}async login(e,t,i){return this._die?se:(te(),this.clearBrowserData(),this.new_visitor=!1,this._initResource(e,{accid:e,profile_id:t,tokenGenerator:i},{getAccessToken:()=>this.api.token_generator()}))}logout(e){return this.api.setAuth({ref:e})}seenLoop(){this.seenQueue=[],y.clearInterval(this._seenInterval),this._seenInterval=y.setInterval(()=>{if(this._die)return y.clearInterval(this._seenInterval);if(!this.cache)return;this.seenQueue=[...new Set(this.seenQueue)];let e=this.cache.match("user")||{};y.map(this.seenQueue,t=>{var i=this.listEvents(t);if(!i)return;if(0===y.size(i))return;var s=(i=y.filter(i,e=>"message_sent"===e.type))[y.size(i)-1];if(!s)return;if(this.g_haveSentSeenM[s.id])return;if(s.id===s.source_event_id)return;if(this.pubsub.publish("events",{created:this.now(),type:"message_pong",by:{type:"user"},data:{message:{conversation_id:t,id:"*",pongs:[{type:"seen",created:this.now()}]}}}),t.startsWith("cslight")){let e=this.lightConvos[t],i=this.matchUser();if(!e)return;let r=y.find(e.members,e=>"user"==e.type&&e.id==i.id);return r&&(r.seen_at=this.now()),this.kv.put("light_convos",this.lightConvos),void(this.g_haveSentSeenM[s.id]=!0)}this.api.markAsSeen(t,s.id);let r=this.cache.match("convo_"+t)||{},n=y.find(r.members,t=>t.id===e.id);n&&(n.seen_at=this.now()),this._setConvo(r),this.g_haveSentSeenM[s.id]=!0}),this.seenQueue=[]},1e3)}async reconnectWs(e,t){await this.realtime.subscribe([`conversation_state_updated.account.${e}.user.${t}`,`conversation_joined.account.${e}.user.${t}`,`conversation_typing.account.${e}.user.${t}`,`message_sent.account.${e}.user.${t}`,`message_pong.account.${e}.user.${t}`,`conversation_rating_requested.account.${e}.user.${t}`,`conversation_rated.account.${e}.user.${t}`,`conversation_events.account.${e}.user.${t}`]),await this.readyGate.entry()}reconnect(e){if(this.reconnectRequest)return this.reconnectRequest;const t=this._reconnect(e).finally(()=>{this.reconnectRequest===t&&(this.reconnectRequest=null)});return this.reconnectRequest=t,t}async _reconnect(e){if(!this._die){await this.reconnectGate.entry(void 0,!0);try{let t=e&&e.user?Promise.resolve({body:e.user}):this.api.getUser(),i=await Promise.all([t,this.api.getAccountSetting({bot_id:this.forceBotId})]),s=y.find(i,e=>e.error);if(s)return s;let r=i[1].body;r.user=i[0].body,await this._setSetting(r);let n=await this.api.listConversations();s=n.error;let o=n.body;if(!s){let e=y.get(o,"conversations",[]);y.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&this.now()-y.getMs(y.get(e,"actived"))>12096e5&&this.cache.del(t)}),y.map(e,e=>this._setConvo(e))}if(s)return{error:s};this.markSync("account")}catch(e){return{error:e}}finally{this.reconnectGate.open()}}}async submitWebsiteForm(e,t){await this.readyGate.entry();const i=re(this.api,e),s=this.kv,r=function(e){const t=e&&e.body,i=e&&e.error||t&&t.error,s=e&&e.code,r=t&&"string"==typeof t.conversation_id&&t.conversation_id&&"string"==typeof t.submission_id&&t.submission_id;if(i||!(s>=200&&s<300)||!r){const e=new Error("Subiz form request failed");throw e.code=i&&i.code||"form_request_failed",e.status=s,e}return t}(await this.api.submitWebsiteForm(e,t));try{s.put(i,{conversation_id:r.conversation_id,expires_at:y.Date.now()+6048e5})}catch(e){}return r}getFormStatus(e){const t=re(this.api,e);try{const e=this.kv.match(t);return e?Number.isFinite(e.expires_at)&&"string"==typeof e.conversation_id&&e.conversation_id?e.expires_at<=y.Date.now()?(this.kv.del(t),{submitted:!1,status:"expired"}):{submitted:!0,status:"found",conversation_id:e.conversation_id}:(this.kv.del(t),{submitted:!1,status:"not_found"}):{submitted:!1,status:"not_found"}}catch(e){return{submitted:!1,status:"storage_unavailable"}}}async submitForm(e,t,i){return await this.readyGate.entry(),i&&await this.setUser(i),this.api.submitForm(e,document.URL,this.device,t,i)}async setUser(e){if(e)return await this.readyGate.entry(),this._setUser(e),this.api.updateUser(e)}async setUserDiff(e){if(!e)return;await this.readyGate.entry();let t=await this.api.updateUser(e);t&&200==t.code&&t.body.id&&this._setUser(t.body)}_setUser(e){e=y.cloneDeep(e);let t=this.cache.match("user")||{};var i=t.account_id||e.account_id,s=t.id||e.id;y.each(e.attributes,e=>{e&&(t.attributes=y.filter(t.attributes,t=>!!t&&t.key!==e.key))}),t.attributes=t.attributes||[],t.attributes=t.attributes.concat(e.attributes),t.account_id=i,t.id=s,this.cache.put("user",t),this.pubsub.publish("account")}async setSetting(e){if(e)return await this.readyGate.entry(),this._setSetting(e)}async _setSetting(e){(e=y.cloneDeep(e)||{}).account=Object.assign({},e.account,this.forceAcc),e.account.logo_url||(e.account.logo_url="https://vcdn.subiz-cdn.com/widget-v4/public/assets/img/default_logo.dd13a2b.svg"),e.user&&(e.user.account_id=e.account.id,delete e.user.session,this._setUser(e.user)),e.account&&(e.account.is_online=e.is_online,e.account.is_in_business_hour=e.is_in_business_hour,this.cache.put("account",e.account),delete e.account);let t=y.get(e,"location",[]);this.cache.put("location",t);let i=y.get(e,"bots",[]),s={};y.map(i,e=>{s[e.id]=e}),this.cache.put("bot",s),this.device_type=e.device_type||"desktop";let r=y.get(e,"plugins",[]),n={};y.map(r,e=>{"chatbox"===e.type&&(e=y.merge(e,this.forceChatbox)),n[e.id]=e}),this.cache.put("plugin",n);var o=y.get(e,"agents",[]);if(y.size(o)>0){let e={};this.api.setAgentId(o[0].id),y.map(o,t=>{e[t.id]=t}),this.cache.put("agent",e)}let a=y.get(e,"payment_methods",[]);this.cache.put("payment_methods",a),this.pubsub.publish("account")}async sendPageview(e){e||(e={});let t=Object.assign({},this.device);return e.referrer&&(t.source_referrer=e.referrer),t.page_url=e.url||location.href,t.page_title=e.title||document.title,this.api.sendContentView(t,e.url||location.href,e.title||document.title,this._currentViewingProduct.id,this._currentViewingProduct.source_id,this._currentViewingProduct.sku)}async track(e){if(!e){let e=await this.sendPageview(),t=y.get(e,"body.by.device.source","");return t&&this.kv.put("traffic_source",t),e}return"object"==typeof e&&(e.data||(e.data={})),this.api.sendEvent(e)}async onWs(e){await this.wsGate.entry(void 0,!0);try{await this._onWs(e)}catch(e){return console.error(e),{error:e}}finally{this.wsGate.open()}}async _onWs(e){if(this._die)return;if(!e||!e.type)return;if("form"===y.get(e,"touchpoint.channel")||"form"===y.get(e,"data.conversation.touchpoint.channel"))return;if(e.created=y.getMs(e.created),"user_info_updated"===e.type)return;if("message_deleted"===e.type)return void this.pubsub.publish("message_updated",e);let t,i=this.cache.match("user")||{},s=y.convoOfEv(e),r=!1;if(s&&!s.startsWith("cslight")&&(t=this.cache.match("convo_"+s),!t||!t.id)){let{body:e,error:i}=await this.api.getConversation(s);if(!e)return;t=e,r=!0,this._setConvo(t)}if(s&&s.startsWith("cslight")){if(t=this.lightConvos[s],!t)return;return t.events.push(e),t.last_message_sent=e,this.kv.put("light_convos",this.lightConvos),void this.pubsub.publish("events",e)}if(t){if(this.pubsub.publish("events",e),"conversation_joined"===e.type){let i=y.get(e,"data.conversation.members",[]);if(y.find(i,e=>e.id===this.cache.match("user").id)&&!r){let{body:e}=await this.api.getConversation(s);e&&(t=e,this._setConvo(t)),this.pubsub.publish("account")}}return"message_sent"===e.type&&y.get(e,"by.id")!==i.id&&(this._alreadyReceived[e.id]||(this._alreadyReceived[e.id]=!0,this.api.markAsReceived(s,e.id))),y.startsWith(e.type,"message_")||y.startsWith(e.type,"conversation_")?(await this.restConvoEvent(e),void("message_sent"===e.type&&y.get(e,"by.id")!==i.id&&Y("SUBIZ Chat","Received","User"))):void 0}}async restConvoEvent(e){let t=this.cache.match("user"),i=y.convoOfEv(e),s=this.cache.match("convo_"+i)||{};if("conversation_state_updated"===e.type){if(!y.get(s,"id")){let{body:e,error:t}=await this.api.getConversation(i);if(t)return}s=Object.assign(s,y.get(e,"data.conversation"))}if("message_pong"===e.type){var r=y.get(e,"data.message.id"),n=this.chain.match(i,r);if(!y.get(n,"data.message"))return;var o=y.get(n,"data.message.pongs",[]);let a=y.get(e,"data.message.pongs",[])||[];if(o=o.concat(a),1===a.length){let e=a[0].type;"like"!==e&&"remove_dislike"!==e||(o=o.filter(e=>"dislike"!==e.type)),"dislike"!==e&&"remove_like"!==e||(o=o.filter(e=>"like"!==e.type))}n.data.message.pongs=o,y.map(o,e=>{if(e.member_id==t.id&&"seen"===e.type){let i=y.find(s.members,e=>e.id===t.id);i&&(i.seen_at=e.created)}}),this.chain.put(i,n.id,y.getMs(n.created),n),this.pubsub.publish("events",n)}if("message_pong"!==e.type&&"conversation_typing"!==e.type){if("message_sent"===e.type){let t=y.get(e,"source_event_id"),r=y.find(this.listEvents(i),e=>e.id===t);r&&(this.chain.del(i,r.id),e.created=r.created),s.last_message_sent=e}this.chain.put(i,e.id,y.getMs(e.created),e)}this._setConvo(s),this.pubsub.publish("account")}emitCloseWidgetEvent(){this.pubsub.publish("sbz_close_widget",{type:"chatbox_closed"})}typing(e){e&&(e.startsWith("cslight")||this._typing(e))}deleteLightConvo(e){delete this.lightConvos[e],this.kv.put("light_convos",this.lightConvos)}startWidgetConvo(e,t){const i=this.matchUser(),s=y.find(this.lightConvos,e=>"widget"===e.light_type&&e.account_id===i.account_id&&e.initial_by===i.id);if(s)return{convo:s};const r="cslightwidget_"+y.randomString(24),n=y.cloneDeep(e);n.data.message.conversation_id=r;const o={id:r,account_id:i.account_id,initial_by:i.id,locale:t,light_type:"widget",state:"pending",created:n.created,members:[{id:i.id,type:"user",seen_at:n.created+1}],events:[n],last_message_sent:n,touchpoint:{id:r,channel:"subiz",source:"web"}};return this.lightConvos[r]=o,this.kv.put("light_convos",this.lightConvos),this.pubsub.publish("account"),{convo:o}}promoteWidgetConvo(e,t){this.widgetConvoOrigins=this.widgetConvoOrigins||{},this.widgetConvoOrigins[t]=e;const i=y.cloneDeep(y.get(this.lightConvos,[e,"events",0]));i&&(i.source_event_id=i.id,i.data.message.conversation_id=t,this.chain.merge(t,[{id:i.id,index:i.created,value:i}])),this.deleteLightConvo(e)}startLightConvo(e,t,i,s,r){let n="cslight"+e+"_"+this.now(),o=this.cache.match("user")||{},a=this.lightConvos[n];if(a)return{convo:a};let c=this.now(),u={},l=y.map(t,(t,i)=>{let s={};return s.created=c,s.event_time=c,s.id="evfake"+c+i,s.type="message_sent",s.by={id:e,type:"bot"},s.data={message:t},s.data.message.conversation_id=n,u=s,s}),h={id:n,locale:i,initial_by:e,created:c,actived:c,last_message_sent:u,members:[{type:"user",id:o.id},{type:"bot",id:e,membership:"active"}],state:"active",touchpoint:{id:n,channel:"subiz",source:"web"},traffic_source:"direct",events:l,is_testing:s,bot_versio:r};return this.lightConvos[n]=h,this.kv.put("light_convos",this.lightConvos),this.pubsub.publish("events",u),{convo:h}}async startConvo(e){e||(e={}),await this.readyGate.entry(),this.convoGate.close(),e.source||(e.source=document.location.href);let{body:t,error:i}=await this.api.start(e);return this.convoGate.open(),i?{error:i}:(this._setConvo(t),{convo:t})}fetchOrder(e){return this.api.getOrder(e)}lookupOrder(e){return this.api.lookupOrder(e)}createPostback(e,t){if(!e||!e.startsWith("cslight"))return this.api.createPostback(e,t)}sendReaction(e,t){if(!e||!e.startsWith("cslight"))return this.api.sendConvoEvent(e,t)}async sendConvoEvent(e,t,i){await this.readyGate.entry();var s=y.randomString(36),r={id:s,by:{id:(this.cache.match("user")||{}).id,type:"user",device:this.device},data:i,type:t,created:this.now()};y.convoToEv(e,r);let n=[];"message_sent"===t&&(r.source_event_id=s,r.data.message.conversation_id=e,await N.map(r.data.message.attachments,2,async(e,t)=>{var i;if("file"===e.type&&e._file&&(n.push(e),Z.includes(e._file.type))){let{width:t,height:s,url:r}=await(i=e._file,new Promise(e=>{var t=new window.FileReader;t.onload=t=>{let i=t.target.result,s=new Image;s.onload=()=>{e({url:i,width:s.width,height:s.height})},s.src=i},t.readAsDataURL(i)}));e.url=r,e.width=t,e.height=s}})),this.onWs(r),await this.convoGate.entry();const o=await async function(e,t){let i,s;for(const r of e)try{const e=await t(r._file);if(e.body&&"invalid_field_size"===e.body.code&&(s="cannot_send_too_big_file"),e.error||!e.url){i=i||e.error||"upload_failed";continue}r.url=e.url}catch(e){i=i||e}return{error:i,errorMessage:s}}(n,e=>this.api.uploadToS3(e));if(r._error=o.error,o.errorMessage&&(r._error_message=o.errorMessage),r._error)return this.onWs(r);if(e&&e.startsWith("cslight"))return;let{body:a,error:c}=await this.api.sendConvoEvent(e,r);return c?(r._error=c,void this.onWs(r)):(this.onWs(a),Y("SUBIZ Chat","Sent","User"),this.kv.match("last_msg_sent")||(window.dataLayer||[]).push({event:"SUBIZ Chat",event_action:"Sent",event_label:"User",first_interaction:1}),this.kv.put("last_msg_sent",this.now()),a)}_setConvo(e){this.cache.match("user");let t=y.get(e,"touchpoint.channel","");if(t&&"subiz"!=t)return;let i={};if(y.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&(i[t]=e)}),y.size(i)>18){i=y.orderBy(y.map(i),"created","desc");for(var s=18;s<y.size(i);s++){let e=i[s];this.cache.del("convo_"+e.id)}}this.markSync(e.id),this.pubsub.publish("account"),this.cache.put("convo_"+e.id,e)}matchLastPluginRun(e){return(this.kv.match("plugin_run_logs")||{})[e]}matchLastBotRun(e){return(this.kv.match("bot_run_logs")||{})[e]}logBotRun(e){let t=this.kv.match("bot_run_logs")||{};t[e]={bot_id:e,created:this.now()},this.kv.put("bot_run_logs",t)}sendImpression(e){let t=this.cache.match("user")||{},i=this.kv.match("plugin_run_logs")||{};return i[e]={web_plugin_id:e,created:this.now()},this.kv.put("plugin_run_logs",i),this.api.sendImpression({account_id:t.account_id,campaign_id:e,web_plugin_id:e,user_id:t.id,url:window.location.href,device:this.device})}sendConversion(e,t,i){let s=this.cache.match("user")||{},r={account_id:s.account_id,user_id:s.id,fields:t},n=this.kv.match("conversions")||{};return n[e]=!0,this.kv.put("conversions",n),this.api.sendConversion({account_id:s.account_id,web_plugin_id:e,campaign_id:e,user_id:y.get(s,"id"),url:window.location.href,device:this.device,submission:r,impression_token:i})}isConverted(e){return(this.kv.match("conversions")||{})[e]}async listmessageapi(e,t,i){let s=e;if(s&&s.startsWith("cslight"))return[y.map(this.listEvents(s),e=>({id:e.id,index:e.created,value:e})),"",void 0,!0];let{body:r,code:n,error:o}=await this.api.listMessages(s,-i,t);if(o||200!==n)return[[],t,o||"message_fetch_failed"];t=y.get(y.last(r),"id"),r=y.map(r,e=>(e.created=y.getMs(e.created),{id:e.id,index:e.created,value:e}));let a=this.cache.match("user")||{};for(let e=0;e<r.length;e++){let t=r[e].value;if("message_sent"===t.type&&y.get(t,"by.id")!==a.id){if(y.find(y.get(t,"data.message.pongs"),e=>e.member_id===a.id))break;this._alreadyReceived[t.id]||(this._alreadyReceived[t.id]=!0,this.api.markAsReceived(s,t.id));break}}return[r,t,void 0,y.size(r)<i]}async loopTime(){if(this._die)return;let e=this.now();if(!this.cache||!y.get(this.cache.match("user"),"id"))return this._timeTimeout=y.setTimeout(()=>this.loopTime(),24e4);let{body:t,error:i}=await this.api.time();if(!this._die){if(i)return this._timeTimeout=y.setTimeout(()=>this.loopTime(),3e4);var s=Math.abs(this.now()-e)/2,r=new y.Date(t).getTime()+s,n=this.now();this.timeDiff=Math.floor(r-n),this._timeTimeout=y.setTimeout(()=>this.loopTime(),24e4)}}replaceFileUrl(e){return e?y.startsWith(e,"/")||y.startsWith(e,"data:")?e:(y.startsWith(e,"http://")||y.startsWith(e,"https://")||y.startsWith(e,"//")||(e=y.trim(this.FileURL,"/")+"/"+y.trimStart(e,"/")),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace("https://file-subiz.com/",this.FileURL)).replace("http://file-subiz.com/",this.FileURL)).replace("https://file-v4.subiz.com/",this.FileURL)).replace("http://file-v4.subiz.com/",this.FileURL)).replace("https://filev4.subiz.com/",this.FileURL)).replace("http://filev4.subiz.com/",this.FileURL)).replace("https://filev4-1.subiz.com/",this.FileURL)).replace("http://filev4-1.subiz.com/",this.FileURL)).replace("https://file.subiz.com/",this.FileURL)).replace("http://file.subiz.com/",this.FileURL)).replace("https://file.mysubiz.com/",this.FileURL)).replace("http://file.mysubiz.com/",this.FileURL)):""}clearBrowserData(){y.each(this.cookie.all(),(e,t)=>{(t||"").startsWith("__sb")&&this.cookie.remove(t)}),this.kv&&this.kv.destroy(),this.kv=new I(new E("sbz2023",this.inmem),"kv"),this.chain&&this.chain.destroy(),this.chain=new P(new E("cbz2023",!0),"ch"),this.outofmsgM={},this.messageSyncTimes={},this.messageSyncNextAt={},this.messageSyncFailures={},this.messageSyncProgress={},this.accountRefreshAfter=0,this.historyFailures={},this.convoFetchAfter={},this.realtime&&this.realtime.stop(),this.cache&&this.cache.destroy(),this.pubsub.publish("destroy")}isDead(){return this._die}destroy(){this._die||(this._die=!0,this.clearBrowserData(),y.clearInterval(this._seenInterval),y.clearInterval(this._urlCheckInterval),y.clearInterval(this._presenceInterval1),y.clearInterval(this._presenceInterval2),y.clearInterval(this._gaInterval),y.clearTimeout(this._timeTimeout),this.realtime&&this.realtime.stop(),this.readyGate&&this.readyGate.close(),window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),window.removeEventListener("beforeunload",this._onBeforeUnload),this._visibilityCleanup&&this._visibilityCleanup(),this.pubsub.clear())}}const Z=["image/gif","image/jpeg","image/png","image/svg+xml"],K={data:{},get(e,t){return this.data[e]||t},set(e,t){return this.data[e]=e},all(){return this.data},remove(e){delete this.data[e]}};function Y(e,t,i){document.dispatchEvent(new CustomEvent("subiz",{detail:{category:e,action:t,label:i}})),function(e,t,i){window.sbz_no_gtag?console.log("SKIPSENT.",e,t,i):((window.dataLayer||[]).push({event:e,event_action:t,event_label:i}),window.gtag&&window.gtag("event",e,{Action:t,Label:i}),window.ga&&window.ga.getAll&&(window.ga.getAll()||[]).forEach(function(s){const r=s.get("name");window.ga(r+".send","event",e,t,i)}))}(e,t,i),function(e,t,i){window.fbq&&window.fbq("trackCustom",e,{action:t,label:i})}(e,t,i)}let ee=()=>{try{localStorage}catch(e){return}y.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020"))&&(localStorage.removeItem(e),H.removeItem(e))})},te=()=>{try{localStorage}catch(e){return}y.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020")||e.startsWith("sbz2022")||e.startsWith("sbz2023"))&&(localStorage.removeItem(e),H.removeItem(e))})};var ie=function(e,t,i,s){if(void 0===y.XMLHttpRequest)return function(e,t,i,s){let r={};i&&(r["content-type"]="text/plain"),fetch(t,{method:e,headers:r,body:i}).then(e=>e.text().then(t=>s&&s(t,e.status))).catch(e=>s&&s(e,-1))}(e,t,i,s);var r=new y.XMLHttpRequest;r.onreadystatechange=function(e){4===r.readyState&&(s&&s(r.responseText,r.status),s=void 0)},r.onerror=function(){s&&s(r.responseText,-1),s=void 0},r.open(e,t),i&&r.setRequestHeader("content-type","text/plain"),r.send(i)};const se=new Error("sdk unloaded");function re(e,t){return"sbz_form_submitted:"+y.stringify([e.accid,e.uid,t])}var ne,oe,ae,ce,ue,le,he,de={},pe=[],fe=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_e=Array.isArray;function me(e,t){for(var i in t)e[i]=t[i];return e}function ge(e){var t=e.parentNode;t&&t.removeChild(e)}function ve(e,t,i){var s,r,n,o={};for(n in t)"key"==n?s=t[n]:"ref"==n?r=t[n]:o[n]=t[n];if(arguments.length>2&&(o.children=arguments.length>3?ne.call(arguments,2):i),"function"==typeof e&&null!=e.defaultProps)for(n in e.defaultProps)void 0===o[n]&&(o[n]=e.defaultProps[n]);return ye(e,o,s,r,null)}function ye(e,t,i,s,r){var n={type:e,props:t,key:i,ref:s,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:r??++ae,__i:-1,__u:0};return null==r&&null!=oe.vnode&&oe.vnode(n),n}function be(e){return e.children}function we(e,t){this.props=e,this.context=t}function ke(e,t){if(null==t)return e.__?ke(e.__,e.__i+1):null;for(var i;t<e.__k.length;t++)if(null!=(i=e.__k[t])&&null!=i.__e)return i.__e;return"function"==typeof e.type?ke(e):null}function xe(e){var t,i;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if(null!=(i=e.__k[t])&&null!=i.__e){e.__e=e.__c.base=i.__e;break}return xe(e)}}function Se(e){(!e.__d&&(e.__d=!0)&&ce.push(e)&&!Ce.__r++||ue!==oe.debounceRendering)&&((ue=oe.debounceRendering)||le)(Ce)}function Ce(){var e,t,i,s,r,n,o,a,c;for(ce.sort(he);e=ce.shift();)e.__d&&(t=ce.length,s=void 0,n=(r=(i=e).__v).__e,a=[],c=[],(o=i.__P)&&((s=me({},r)).__v=r.__v+1,oe.vnode&&oe.vnode(s),Me(o,s,r,i.__n,void 0!==o.ownerSVGElement,32&r.__u?[n]:null,a,n??ke(r),!!(32&r.__u),c),s.__.__k[s.__i]=s,Ie(a,s,c),s.__e!=n&&xe(s)),ce.length>t&&ce.sort(he));Ce.__r=0}function ze(e,t,i,s,r,n,o,a,c,u,l){var h,d,p,f,_,m=s&&s.__k||pe,g=t.length;for(i.__d=c,function(e,t,i){var s,r,n,o,a,c=t.length,u=i.length,l=u,h=0;for(e.__k=[],s=0;s<c;s++)null!=(r=e.__k[s]=null==(r=t[s])||"boolean"==typeof r||"function"==typeof r?null:"string"==typeof r||"number"==typeof r||"bigint"==typeof r||r.constructor==String?ye(null,r,null,null,r):_e(r)?ye(be,{children:r},null,null,null):void 0===r.constructor&&r.__b>0?ye(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):r)?(r.__=e,r.__b=e.__b+1,a=Te(r,i,o=s+h,l),r.__i=a,n=null,-1!==a&&(l--,(n=i[a])&&(n.__u|=131072)),null==n||null===n.__v?(-1==a&&h--,"function"!=typeof r.type&&(r.__u|=65536)):a!==o&&(a===o+1?h++:a>o?l>c-o?h+=a-o:h--:h=a<o&&a==o-1?a-o:0,a!==s+h&&(r.__u|=65536))):(n=i[s])&&null==n.key&&n.__e&&(n.__e==e.__d&&(e.__d=ke(n)),qe(n,n,!1),i[s]=null,l--);if(l)for(s=0;s<u;s++)null!=(n=i[s])&&!(131072&n.__u)&&(n.__e==e.__d&&(e.__d=ke(n)),qe(n,n))}(i,t,m),c=i.__d,h=0;h<g;h++)null!=(p=i.__k[h])&&"boolean"!=typeof p&&"function"!=typeof p&&(d=-1===p.__i?de:m[p.__i]||de,p.__i=h,Me(e,p,d,r,n,o,a,c,u,l),f=p.__e,p.ref&&d.ref!=p.ref&&(d.ref&&Re(d.ref,null,p),l.push(p.ref,p.__c||f,p)),null==_&&null!=f&&(_=f),65536&p.__u||d.__k===p.__k?c=Ae(p,c,e):"function"==typeof p.type&&void 0!==p.__d?c=p.__d:f&&(c=f.nextSibling),p.__d=void 0,p.__u&=-196609);i.__d=c,i.__e=_}function Ae(e,t,i){var s,r;if("function"==typeof e.type){for(s=e.__k,r=0;s&&r<s.length;r++)s[r]&&(s[r].__=e,t=Ae(s[r],t,i));return t}return e.__e!=t&&(i.insertBefore(e.__e,t||null),t=e.__e),t&&t.nextSibling}function Te(e,t,i,s){var r=e.key,n=e.type,o=i-1,a=i+1,c=t[i];if(null===c||c&&r==c.key&&n===c.type)return i;if(s>(null==c||131072&c.__u?0:1))for(;o>=0||a<t.length;){if(o>=0){if((c=t[o])&&!(131072&c.__u)&&r==c.key&&n===c.type)return o;o--}if(a<t.length){if((c=t[a])&&!(131072&c.__u)&&r==c.key&&n===c.type)return a;a++}}return-1}function Ee(e,t,i){"-"===t[0]?e.setProperty(t,i??""):e[t]=null==i?"":"number"!=typeof i||fe.test(t)?i:i+"px"}function Pe(e,t,i,s,r){var n;e:if("style"===t)if("string"==typeof i)e.style.cssText=i;else{if("string"==typeof s&&(e.style.cssText=s=""),s)for(t in s)i&&t in i||Ee(e.style,t,"");if(i)for(t in i)s&&i[t]===s[t]||Ee(e.style,t,i[t])}else if("o"===t[0]&&"n"===t[1])n=t!==(t=t.replace(/(PointerCapture)$|Capture$/,"$1")),t=t.toLowerCase()in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.l[t+n]=i,i?s?i.u=s.u:(i.u=Date.now(),e.addEventListener(t,n?je:Oe,n)):e.removeEventListener(t,n?je:Oe,n);else{if(r)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!==t&&"height"!==t&&"href"!==t&&"list"!==t&&"form"!==t&&"tabIndex"!==t&&"download"!==t&&"rowSpan"!==t&&"colSpan"!==t&&"role"!==t&&t in e)try{e[t]=i??"";break e}catch(e){}"function"==typeof i||(null==i||!1===i&&"-"!==t[4]?e.removeAttribute(t):e.setAttribute(t,i))}}function Oe(e){var t=this.l[e.type+!1];if(e.t){if(e.t<=t.u)return}else e.t=Date.now();return t(oe.event?oe.event(e):e)}function je(e){return this.l[e.type+!0](oe.event?oe.event(e):e)}function Me(e,t,i,s,r,n,o,a,c,u){var l,h,d,p,f,_,m,g,v,y,b,w,k,x,S,C=t.type;if(void 0!==t.constructor)return null;128&i.__u&&(c=!!(32&i.__u),n=[a=t.__e=i.__e]),(l=oe.__b)&&l(t);e:if("function"==typeof C)try{if(g=t.props,v=(l=C.contextType)&&s[l.__c],y=l?v?v.props.value:l.__:s,i.__c?m=(h=t.__c=i.__c).__=h.__E:("prototype"in C&&C.prototype.render?t.__c=h=new C(g,y):(t.__c=h=new we(g,y),h.constructor=C,h.render=Ue),v&&v.sub(h),h.props=g,h.state||(h.state={}),h.context=y,h.__n=s,d=h.__d=!0,h.__h=[],h._sb=[]),null==h.__s&&(h.__s=h.state),null!=C.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=me({},h.__s)),me(h.__s,C.getDerivedStateFromProps(g,h.__s))),p=h.props,f=h.state,h.__v=t,d)null==C.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(null==C.getDerivedStateFromProps&&g!==p&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(g,y),!h.__e&&(null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(g,h.__s,y)||t.__v===i.__v)){for(t.__v!==i.__v&&(h.props=g,h.state=h.__s,h.__d=!1),t.__e=i.__e,t.__k=i.__k,t.__k.forEach(function(e){e&&(e.__=t)}),b=0;b<h._sb.length;b++)h.__h.push(h._sb[b]);h._sb=[],h.__h.length&&o.push(h);break e}null!=h.componentWillUpdate&&h.componentWillUpdate(g,h.__s,y),null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(p,f,_)})}if(h.context=y,h.props=g,h.__P=e,h.__e=!1,w=oe.__r,k=0,"prototype"in C&&C.prototype.render){for(h.state=h.__s,h.__d=!1,w&&w(t),l=h.render(h.props,h.state,h.context),x=0;x<h._sb.length;x++)h.__h.push(h._sb[x]);h._sb=[]}else do{h.__d=!1,w&&w(t),l=h.render(h.props,h.state,h.context),h.state=h.__s}while(h.__d&&++k<25);h.state=h.__s,null!=h.getChildContext&&(s=me(me({},s),h.getChildContext())),d||null==h.getSnapshotBeforeUpdate||(_=h.getSnapshotBeforeUpdate(p,f)),ze(e,_e(S=null!=l&&l.type===be&&null==l.key?l.props.children:l)?S:[S],t,i,s,r,n,o,a,c,u),h.base=t.__e,t.__u&=-161,h.__h.length&&o.push(h),m&&(h.__E=h.__=null)}catch(e){t.__v=null,c||null!=n?(t.__e=a,t.__u|=c?160:32,n[n.indexOf(a)]=null):(t.__e=i.__e,t.__k=i.__k),oe.__e(e,t,i)}else null==n&&t.__v===i.__v?(t.__k=i.__k,t.__e=i.__e):t.__e=Le(i.__e,t,i,s,r,n,o,c,u);(l=oe.diffed)&&l(t)}function Ie(e,t,i){t.__d=void 0;for(var s=0;s<i.length;s++)Re(i[s],i[++s],i[++s]);oe.__c&&oe.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){oe.__e(e,t.__v)}})}function Le(e,t,i,s,r,n,o,a,c){var u,l,h,d,p,f,_,m=i.props,g=t.props,v=t.type;if("svg"===v&&(r=!0),null!=n)for(u=0;u<n.length;u++)if((p=n[u])&&"setAttribute"in p==!!v&&(v?p.localName===v:3===p.nodeType)){e=p,n[u]=null;break}if(null==e){if(null===v)return document.createTextNode(g);e=r?document.createElementNS("http://www.w3.org/2000/svg",v):document.createElement(v,g.is&&g),n=null,a=!1}if(null===v)m===g||a&&e.data===g||(e.data=g);else{if(n=n&&ne.call(e.childNodes),m=i.props||de,!a&&null!=n)for(m={},u=0;u<e.attributes.length;u++)m[(p=e.attributes[u]).name]=p.value;for(u in m)p=m[u],"children"==u||("dangerouslySetInnerHTML"==u?h=p:"key"===u||u in g||Pe(e,u,null,p,r));for(u in g)p=g[u],"children"==u?d=p:"dangerouslySetInnerHTML"==u?l=p:"value"==u?f=p:"checked"==u?_=p:"key"===u||a&&"function"!=typeof p||m[u]===p||Pe(e,u,p,m[u],r);if(l)a||h&&(l.__html===h.__html||l.__html===e.innerHTML)||(e.innerHTML=l.__html),t.__k=[];else if(h&&(e.innerHTML=""),ze(e,_e(d)?d:[d],t,i,s,r&&"foreignObject"!==v,n,o,n?n[0]:i.__k&&ke(i,0),a,c),null!=n)for(u=n.length;u--;)null!=n[u]&&ge(n[u]);a||(u="value",void 0!==f&&(f!==e[u]||"progress"===v&&!f||"option"===v&&f!==m[u])&&Pe(e,u,f,m[u],!1),u="checked",void 0!==_&&_!==e[u]&&Pe(e,u,_,m[u],!1))}return e}function Re(e,t,i){try{"function"==typeof e?e(t):e.current=t}catch(e){oe.__e(e,i)}}function qe(e,t,i){var s,r;if(oe.unmount&&oe.unmount(e),(s=e.ref)&&(s.current&&s.current!==e.__e||Re(s,null,t)),null!=(s=e.__c)){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(e){oe.__e(e,t)}s.base=s.__P=null,e.__c=void 0}if(s=e.__k)for(r=0;r<s.length;r++)s[r]&&qe(s[r],t,i||"function"!=typeof e.type);i||null==e.__e||ge(e.__e),e.__=e.__e=e.__d=void 0}function Ue(e,t,i){return this.constructor(e,i)}ne=pe.slice,oe={__e:function(e,t,i,s){for(var r,n,o;t=t.__;)if((r=t.__c)&&!r.__)try{if((n=r.constructor)&&null!=n.getDerivedStateFromError&&(r.setState(n.getDerivedStateFromError(e)),o=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e,s||{}),o=r.__d),o)return r.__E=r}catch(t){e=t}throw e}},ae=0,we.prototype.setState=function(e,t){var i;i=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=me({},this.state),"function"==typeof e&&(e=e(me({},i),this.props)),e&&me(i,e),null!=e&&this.__v&&(t&&this._sb.push(t),Se(this))},we.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},we.prototype.render=be,ce=[],le="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,he=function(e,t){return e.__v.__b-t.__v.__b},Ce.__r=0;class Fe extends we{constructor(e){super(e),this._isMounted=!0,this._subscriptions=new Set;const t=this.componentWillUnmount;this.componentWillUnmount=()=>{if(this._isMounted){this._isMounted=!1;for(const e of this._subscriptions)e();this._subscriptions.clear(),t&&t.call(this)}}}onDispose(e){return this._isMounted?this._subscriptions.add(e):e(),()=>this._subscriptions.delete(e)}}let De={},$e=!1;function We(e,t,i){if($e)return new Promise(s=>y.setTimeout(()=>We(e,t,i).then(s),100));let s;return $e=!0,"debug"===t||De[t]&&!i?($e=!1,Promise.resolve()):e.getLocaleContent(t).then(e=>{$e=!1,s=y.get(e,"body.messages",[]),De[t]=s})}class Ne extends Fe{render(){var e=this.props.emojiCode;if(y.size(e)<3)return null;var t=e.replace(/:/g,"");return ve("i",{"data-tooltip":e,class:`emoji emoji--${t}`})}}function Be(e,t=!1){if("string"!=typeof e)return"";const i=e.trim(),s=i.replace(/[\u0000-\u0020\u007f]/g,""),r=s.match(/^([a-z][a-z0-9+.-]*):/i);return r?/^https?$/i.test(r[1])||!t&&/^(mailto|tel)$/i.test(r[1])||t&&/^blob$/i.test(r[1])||t&&/^data:image\/(png|jpe?g|gif|webp|avif);base64,/i.test(s)?i:"":i}class Ve extends Fe{constructor(e){super(e)}renderBlock(e,t=!1){if(0==y.size(e))return null;let i={style:""};if(e.style&&y.map(e.style,(e,t)=>{i.style+=t+": "+e+";"}),i.attrs={},""!=e.title&&(i.attrs.title=e.title),""!=e.href&&(i.attrs.href=e.href),i.class=e.class,y.map(e.attrs,(e,t)=>{i.attrs[t]=e}),"bullet_list"!=e.type&&"ordered_list"!=e.type||("bullet_list"==e.type?i.tag="ul":i.tag="ol"),"list_item"==e.type&&(i.tag="li"),"heading"==e.type){let t=Math.max(1,Math.min(6,Math.floor(Number(e.level)||1)));i.tag="h"+t}if("paragraph"!=e.type&&"section"!=e.type&&"div"!=e.type||(i.tag="div"),i.text=e.text,""==e.type||"text"==e.type||"dynamic-field"==e.type){i.tag="span",e.bold&&(i.tag="b"),e.italic&&("b"==i.tag?i.style+="font-style: italic;":i.tag="em");let t=[];e.underline&&t.push("underline"),e.strike_through&&t.push("line-through"),t.length&&(i.style+="text-decoration: "+t.join(" ")+" !important;")}if("dynamic-field"==e.type){let t=y.get(e.attrs,"key");i.text=y.get(this.props.data,[t],i.text)}if("link"==e.type&&(i.tag="a",i.attrs.href=Be(e.href),i.attrs.target=e.target,i.attrs.title=e.title),"mention-agent"==e.type||"mention"==e.type){i.tag="span",i.class="mention";let t=y.get(e,"attrs.id","");if("*"!=t&&"all"!=t||(i.text="@"+(this.props.t?this.props.t("all"):"all")),"string"==typeof t&&/^(ag|at)/.test(t)&&this.props.store){let e=this.props.store.matchAgent(t),s=y.getAgentDisplayName(this.props.store.matchAccount(),e);i.text="@"+s}}if("horizontal_rule"==e.type&&(i.tag="hr"),"emoji"==e.type){let t="";y.size(e.attrs)>0&&(t=e.attrs.code),t||(t=e.text||e.Text),""!=t&&(i.tag="Emoji",i.attrs.emojiCode=t)}"image"===e.type&&(i.tag="img",i.attrs.src=Be(y.get(e,"image.url"),!0),i.attrs.alt=e.alt_text),"hard_break"==e.type&&(i.tag="br"),"pre"!=e.type&&"code"!=e.type||(i.tag=e.type);let s=null;switch(s=y.size(e.content)?y.map(e.content,i=>this.renderBlock(i,t||"code"==e.type)):"text"===e.type?t?i.text:y.extractText(i.text).map(e=>{if("link"===e.type){let t=e.text||"";return t.startsWith("//")||t.startsWith("https://")||t.startsWith("http://")||t.startsWith("data:")||(t="//"+t),t=Be(t),t?ve("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:e=>this.props.onLink&&this.props.onLink(e,t)},e.text):e.text}return"phone"===e.type?ve("a",{href:"tel:"+e.text},e.text):"email"===e.type?ve("a",{href:"mailto:"+e.text},e.text):e.text}):i.text,i.tag){case"img":return i.attrs.src?ve("a",{class:this.props.textMessage?"message-text-inline-image-wrapper":"",href:y.get(i,"attrs.src"),target:"_blank",rel:"noopener noreferrer"},ve("img",{class:this.props.textMessage?"message-text-inline-image":"",src:y.get(i,"attrs.src"),alt:y.get(i,"attrs.alt")||""})):e.alt_text||null;case"div":return ve("div",null,s);case"pre":return ve("pre",{class:"message-block-pre"},s);case"code":return ve("code",{class:"message-block-code"+(i.class?" "+i.class:"")},s);case"h1":return ve("h1",null,s);case"h2":return ve("h2",null,s);case"h3":return ve("h3",null,s);case"h4":return ve("h4",null,s);case"h5":return ve("h5",null,s);case"h6":return ve("h6",null,s);case"ol":return ve("ol",{class:this.props.textMessage?"text-message-ol":""},s);case"ul":return ve("ul",{class:this.props.textMessage?"text-message-ul":""},s);case"li":return ve("li",{class:this.props.textMessage?"text-message-li":""},s);case"span":return ve("span",{class:i.class,style:i.style},s);case"em":return ve("em",{style:i.style},s);case"b":return ve("b",{style:i.style},s);case"hr":return ve("hr",null);case"br":return ve("br",null);case"a":return i.attrs.href?ve("a",{class:this.props.textMessage?"message-text-link":"",href:i.attrs.href,target:this.props.textMessage?"_blank":i.attrs.target,title:i.attrs.title,rel:"noopener noreferrer",onClick:e=>this.props.onLink&&this.props.onLink(e,i.attrs.href)},s):ve("span",null,s);case"Emoji":return ve(Ne,{emojiCode:i.attrs.emojiCode})}return s}render(){return this.renderBlock(this.props.block)}}function He(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Ge extends Fe{constructor(e){super(e),He(this,"state",{hovering:0,selected:0}),He(this,"onMouseEnter",e=>{let{selected:t,hovering:i}=this.state;e<=t?this.setState({hovering:t}):this.setState({hovering:e})}),He(this,"onMouseLeave",()=>{let{selected:e,hovering:t}=this.state;this.setState({hovering:0})})}onToggleValue(e){let{selected:t}=this.state,i=e;e===t&&(i=0),this.setState({selected:i,hovering:i}),this.props.onChange(i)}render(){let{selected:e,hovering:t}=this.state,i="star-wrapper";e>=1?i+=" selected":t>=1&&(i+=" hovering");let s="star-wrapper";e>=2?s+=" selected":t>=2&&(s+=" hovering");let r="star-wrapper";e>=3?r+=" selected":t>=3&&(r+=" hovering");let n="star-wrapper";e>=4?n+=" selected":t>=4&&(n+=" hovering");let o="star-wrapper";return e>=5?o+=" selected":t>=5&&(o+=" hovering"),ve("div",{class:"form-ratings-wrapper",onMouseLeave:()=>this.onMouseLeave()},ve("div",{class:i,onClick:()=>this.onToggleValue(1),onMouseEnter:()=>this.onMouseEnter(1)},ve("div",{class:"star"})),ve("div",{class:s,onClick:()=>this.onToggleValue(2),onMouseEnter:()=>this.onMouseEnter(2)},ve("div",{class:"star"})),ve("div",{class:r,onClick:()=>this.onToggleValue(3),onMouseEnter:()=>this.onMouseEnter(3)},ve("div",{class:"star"})),ve("div",{class:n,onClick:()=>this.onToggleValue(4),onMouseEnter:()=>this.onMouseEnter(4)},ve("div",{class:"star"})),ve("div",{class:o,onClick:()=>this.onToggleValue(5),onMouseEnter:()=>this.onMouseEnter(5)},ve("div",{class:"star"})))}}function Qe(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Je extends Fe{constructor(e){super(e),Qe(this,"state",{errorFields:{},submiting:!1}),Qe(this,"renderFormComponent",(e,t)=>"input"===e.type?this.renderField(e,t):"button"===e.type?this.renderSubmitButton(e,t):this.props.isSubmited?void 0:ve("div",{class:"form-component form-component-block"},ve(Ve,{block:e}))),Qe(this,"renderSubmitButton",(e,t)=>{if(!this.props.isSubmited)return ve("div",{class:"form-component form-component-submit-button"},this.props.errorMessage&&ve("div",{class:"form-control--valid-input--error mb-1"},this.props.errorMessage),ve("div",null,ve("button",{class:"btn--start-convo",disabled:this.props.submiting},e.label)))}),Qe(this,"renderField",(e,t)=>{let i=this.state.errorFields[e.key];if(this.props.isSubmited){let t=y.find(this.props.submission.values,t=>t.key===e.key)||{};return t=t.value||'""',t=y.parseJSON(t),Array.isArray(t)&&(t=t.join(", ")),ve("div",{class:"form-component submitted",key:e.key},ve("label",{class:"label"},e.label),ve("div",null,t||ve("span",{class:"text-muted text-italic"},this.props.t("no_info_input"))))}return ve("div",{class:"form-component",key:e.key},ve("label",{class:"label"},e.label," ",e.is_required&&ve("span",{class:"red"},"*")),"text"===e.input_type&&this.renderFieldTextInput(e,t),"textarea"===e.input_type&&this.renderFieldTextareaInput(e,t),"date"===e.input_type&&this.renderFieldDateInput(e,t),"radio"===e.input_type&&this.renderFieldRadioInput(e,t),"checkbox"===e.input_type&&this.renderFieldCheckboxInput(e,t),("dropdown"===e.input_type||"select"===e.input_type)&&this.renderFieldDropdownInput(e,t),"rating"===e.input_type&&this.renderFieldRatingInput(e,t),i&&ve("div",{class:"form-control--valid-input--error"},i))}),Qe(this,"renderFieldTextInput",(e,t)=>{let i="form-control";this.state.errorFields[e.key]&&(i="form-control input--error");let s=y.find(this.props.submission.values,t=>t.key===e.key)||{};return s=s.value||'""',s=y.parseJSON(s),ve("input",{ref:this[`${e.key}_input`],type:"text",class:i,placeholder:e.placeholder,value:s,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Qe(this,"renderFieldDateInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-control";return this.state.errorFields[e.key]&&(s="form-control input--error"),ve("input",{ref:this[`${e.key}_input`],class:s,type:"date",value:i,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Qe(this,"renderFieldRadioInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-radios-wrapper";return y.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(s+=" horizontal"),ve("div",{class:s},y.map(e.input_options,(t,s)=>{let r=e.key+"_"+s;return ve("div",{class:"radio"},ve("input",{type:"radio",name:e.key,id:r,checked:t.value===i,onChange:()=>this.toggleRadioField(e.key,t.value)}),ve("label",{class:"radio--label",for:r},t.label),ve("div",{class:"radio--check"}))}))}),Qe(this,"renderFieldCheckboxInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||"[]",i=y.parseJSON(i);let s="form-checkboxes-wrapper";return y.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(s+=" horizontal"),ve("div",{class:s},y.map(e.input_options,(t,s)=>{let r=e.key+"_"+s;return ve("div",{class:"checkbox"},ve("input",{type:"checkbox",name:e.key,id:r,checked:i.includes(t.value),onChange:()=>this.toggleCheckboxField(e.key,t.value)}),ve("label",{class:"checkbox--label",for:r},t.label),ve("div",{class:"checkbox--check"}))}))}),Qe(this,"renderFieldDropdownInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-control";return this.state.errorFields[e.key]&&(s+=" input--error"),i||(s+=" form-control--empty"),ve("select",{class:s,ref:this[`${e.key}_input`],onChange:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}},ve("option",{value:""},"-- ",this.props.t("no_select")," --"),y.map(e.input_options,e=>ve("option",{value:e.value},e.label)))}),Qe(this,"renderFieldTextareaInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};return i=i.value||'""',i=y.parseJSON(i),ve("textarea",{onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)},ref:this[`${e.key}_input`],rows:"3",class:"form-control",placeholder:e.placeholder})}),Qe(this,"renderFieldRatingInput",(e,t)=>ve(Ge,{onChange:t=>this.onChangeValue(e.key,t)})),Qe(this,"onSubmit",e=>{e.preventDefault(),this.validateForm()&&this.props.onSubmit()}),Qe(this,"validateForm",()=>{let e=!0,t="",i={},s=y.get(this.props.formSetting,"components")||[];return y.each(s,s=>{if("input"===s.type){let r=y.find(this.props.submission.values,e=>e.key===s.key)||{};if(r=r.value||'""',r=y.parseJSON(r),s.is_required){let n=!1;"string"!=typeof r||r.trim()||(n=!0),Array.isArray(r)&&0===r.length&&(n=!0),n&&(e=!1,i[s.key]=this.props.t("cannot_be_empty"),t=`${s.key}_input`)}if(s.validation&&!Array.isArray(r)){let n=!1,o="";"email"!==s.validation||y.isEmail(r)||(o="Email",n=!0),"phone"!==s.validation||y.isPhone(r)||(o=this.props.t("phn"),n=!0),"number"!==s.validation||y.isNumber(r)||(o=this.props.t("number"),n=!0),"url"!==s.validation||y.isURL(r)||(n=!0,o="URL"),n&&(e=!1,i[s.key]=this.props.t("format_is_invalid")+" "+o,t=`${s.key}_input`)}}}),t&&this[t]&&this[t].current&&this[t].current.focus(),this.setState({errorFields:i}),e}),Qe(this,"onChangeValue",(e,t)=>{let i=y.get(this.props.submission,"values")||[],s=y.find(i,t=>t.key===e);s?s.value=JSON.stringify(t):i.push({key:e,value:JSON.stringify(t)}),this.props.onChangeFormValues(i)}),Qe(this,"clearError",e=>{let t=this.state.errorFields;t[e]="",this.setState({errorFields:t})}),Qe(this,"renderFormHeader",()=>{let e=y.get(this.props.formSetting,"title")||"",t=y.get(this.props.formSetting,"description")||"";if("attachment"===this.props.mode&&(e.trim()||t.trim()))return ve("div",{class:"form-component form-component-block"},e&&ve("div",null,e),t&&ve("div",{class:"text-sm text-muted"},t));let i=y.get(this.props.formSetting,"logo.url"),s=y.get(this.props.formSetting,"brand_url"),r=null;i&&(r=ve("div",{class:"form-page-logo-wrapper"},ve("a",{href:s||"javascript:;"},ve("img",{src:i,class:"form-page-logo"}))));let n=null;return(e.trim()||t.trim())&&(n=ve("div",{class:"form-page-header"},ve("div",{class:"form-page-title"},e),t&&ve("div",{class:"form-page-desc"},t))),ve(be,null,r,n)});let t=y.get(this.props.formSetting,"components")||[];y.each(t,e=>{"input"===e.type&&"checkbox"!==e.input_type&&"radio"!==e.input_type&&(this[`${e.key}_input`]={current:null})})}toggleRadioField(e,t){this.clearError(e),this.onChangeValue(e,t)}toggleCheckboxField(e,t){let i=y.find(this.props.submission.values,t=>t.key===e)||{};i=i.value||"[]",i=y.parseJSON(i),i.includes(t)?i=i.filter(e=>e!==t):i.push(t),this.clearError(e),this.onChangeValue(e,i)}render(){let e=y.get(this.props.formSetting,"components")||[],t=(y.get(this.props.formSetting,"title"),y.get(this.props.formSetting,"description"),"form-wrapper form");return"attachment"===this.props.mode&&(t+=" form-wrapper-attachment"),ve("div",{class:t},this.props.isSubmited&&ve("div",{class:"form-component"},this.props.t("you_have_submitted_info_successfully")),ve("form",{onSubmit:this.onSubmit},this.renderFormHeader(),y.map(e,this.renderFormComponent)))}}function Xe(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const Ze=i.e(339).then(()=>i(5339));class Ke extends Fe{constructor(e){super(e),Xe(this,"waitForFont",async e=>{if(0==y.size(e))return;let t={};for(let i=0;i<10;i++){for(let i=0;i<e.length;i++)try{if(document.fonts.check("normal 16px "+e[i])&&(t[e[i]]=!0),y.size(Object.keys(t))===e.length)return}catch(e){}await y.sleep(200)}}),Xe(this,"initCss",async()=>{let e=(await Ze).default.default.toString(),t=y.find(this.props.store.matchPlugin(),e=>"chatbox"===e.type)||{};t=t.chatbox||{};let i=t,s=y.replaceCssVariable(e,i),r=document.createElement("style");document.head.appendChild(r),r.type="text/css",r.id="subiz-style-for-form",this.cssDiv=r,y.setCss("form",r,s)}),Xe(this,"insertCss",async(e,t)=>{let i=(await Ze).default.default.toString(),s=e;t.primary_color&&(s.primary_color=t.primary_color);let r=y.get(t,"header_style.font_family"),n=y.get(t,"text_style.font_family"),o=y.get(t,"input_style.font_family");s.form_background_color=t.background_color,s.form_header_font_size=y.get(t,"header_style.font_size")||"20",s.form_header_font_family=r,s.form_desc_font_size=y.get(t,"text_style.font_size")||"16",s.form_desc_font_family=n,s.form_input_label_font_size=y.get(t,"input_style.font_size")||"14",s.form_input_label_font_family=o;let a=y.replaceCssVariable(i,s),c=[];o&&!c.includes(o)&&c.push(o),r&&!c.includes(r)&&c.push(r),n&&!c.includes(n)&&c.push(n),y.size(c)&&(y.preloadWebfonts(c,[400,500]),await this.waitForFont(c)),y.setCss("form",this.cssDiv,a)}),Xe(this,"fetchFormSetting",async()=>{let e=y.find(this.props.store.matchPlugin(),e=>"chatbox"===e.type)||{};if(e=e.chatbox||{},this.props.previewJson){this.setState({loading:!0});let t=atob(this.props.previewJson);return t=decodeURIComponent(t),t=y.parseJSON(t),await this.insertCss(e,t),void this.setState({formSetting:t,loading:!1})}if(this.state.loading)return;this.setState({loading:!0});let t=await this.props.store.checkFormToken(this.props.store.matchAccount().id,this.props.token);if(t.error)return void this.setState({loading:!1,loadError:!0});let i=y.get(t,"body.form")||{},s=y.get(t,"body.form_submission")||{},r=y.size(s)>0;await this.insertCss(e,i),this.setState({loading:!1,loadError:!1,formSetting:i,submission:s,isSubmited:r})}),Xe(this,"onChangeFormValues",e=>{this.setState({submission:{values:e}})}),Xe(this,"onSubmit",async()=>{this.setState({errorMessage:""}),this.props.previewJson?this.setState({isSubmited:!0}):this.state.submiting||(this.setState({submiting:!0}),(await this.props.store.submitForm2(this.props.store.matchAccount().id,this.props.token,this.state.submission)).error?this.setState({submiting:!1,errorMessage:this.props.t("form_submission_error")}):this.setState({submiting:!1,isSubmited:!0}))}),this.state={submission:{},formSetting:{},submiting:!1,errorMessage:"",isSubmited:!1,loading:!1,loadError:""}}async componentDidMount(){await this.initCss(),this.fetchFormSetting()}render(){const{formSetting:e,loading:t,loadError:i,submission:s,errorMessage:r,isSubmited:n,submiting:o}=this.state;if(t&&!i)return ve("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"loading"},ve("div",{class:"text-muted text-xl"},this.props.t("loading_data")," ..."));if(i)return ve("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"error"},ve("div",{class:"text-center"},ve("div",{class:"text-danger text-lg mb-2"},this.props.t("error_occurs_when_load_data")),ve("br",null),ve("button",{disabled:t,type:"button",class:"btn--start-convo",onClick:this.fetchFormSetting},this.props.t("try_again"))));y.get(e,"logo.url");let a=y.get(e,"cover_image.url"),c="form-page";return a&&(c+=" sketch"),ve("div",{class:"form-page-body",key:"form"},this.props.previewJson&&ve("div",{class:"form-page-preview-noti"},"Form ở trạng thái xem thử, không ghi nhận phản hồi"),a&&ve("div",{class:"form-page-header-bg",style:`background: url(${a}); background-size: cover;`}),ve("div",{class:c},ve(Je,{store:this.props.store,formSetting:e,t:this.props.t,submission:s,errorMessage:r,isSubmited:n,submiting:o,onChangeFormValues:this.onChangeFormValues,onSubmit:this.onSubmit})))}}i.e(278).then(()=>i(9278));const Ye=i(5180);function et(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var tt=document.createElement("link");tt.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap",tt.rel="stylesheet",document.head.append(tt),async function(){let e=new X(Ye.ApiURL,Ye.FileURL,Ye.RealtimeURL,!0);window.store=e;let t=et("id")||et("accid")||et("account-id")||"acqsulrowbxiugvginhw",i=et("token"),s=et("preview");await e.init(t);let r=e=>{if("debug"===n)return`{{${e}}}`;let t=y.get(De,n,[]),i=y.find(t,t=>t.key===e);return y.get(i,"message",e)},n="vi-VN";r.i18n=e=>{if(!e)return"";let t="vi-VN";return t=t.replace("-","_"),e[n.replace("-","_")]||e[t]},r.locale=()=>n,We(e,n).then(()=>{!function(e,t,i){var s,r,n,o;oe.__&&oe.__(e,t),r=(s="function"==typeof i)?null:i&&i.__k||t.__k,n=[],o=[],Me(t,e=(!s&&i||t).__k=ve(be,null,[e]),r||de,de,void 0!==t.ownerSVGElement,!s&&i?[i]:r?null:t.firstChild?ne.call(t.childNodes):null,n,!s&&i?i:r?r.__e:t.firstChild,s,o),Ie(n,e,o)}(ve(Ke,{store:e,t:r,token:i,previewJson:s}),document.getElementById("form"))})}()})()})();
1
+ (()=>{var e={318(e){var t="Content-Type",i="application/x-www-form-urlencoded",s="application/json; charset=utf-8";function r(e,t){return Object.assign(e.clone(),t)}var n={code:"network_error,retry",number:"SBZ-EQNETWORK",message:{En_US:"Can not connect to the server. Please check your internet connection.",Vi_VN:"Không thể kết nối tới máy chủ. Vui lòng kiểm tra lại kết nối mạng."}},o={code:"invalid_response,retry",number:"SBZ-EQRESPONSE",message:{En_US:"Server error, please try again later",Vi_VN:"Lỗi máy chủ, vui lòng thử lại sau"}},a={code:"not_200,retry",number:"SBZ-EQCN200",message:{En_US:"Error while connecting to the server, please try again later",Vi_VN:"Lỗi kết nối với máy chủ, vui lòng thử lại sau"}};function c(e){return(e||"").trim()}function u(e){return e&&"[object Function]"==={}.toString.call(e)}function l(e,t,i){if(!e||0===e.length)return i(t);var s=e.shift();if(!u(s))return l(e,t,i);s(t,function(s){return!1===s?i(t):l(e,t,i)})}function h(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16)})}function d(e){if(!e)return"";for(var t=Object.keys(e),i=[],s=0;s<t.length;s++){var r=t[s],n="",o=e[r];if(void 0!==o){if(null===o)n=h(r);else if(Array.isArray(o)){for(var a=[],c=0;c<o.length;c++)void 0!==o[c]&&(a.push(p(r,o[c],a.length)),a.push(i));n=a.join("&")}else n=h(r)+"="+h(o);n.length>0&&i.push(n)}}return i.join("&")}function p(e,t){return null===t?h(e):[h(e),"=",h(t)].join("")}var f,_=(f={parser:"",beforehooks:[],afterhooks:[],baseurl:"",query:{},clone:function(){return Object.assign({},this,{query:Object.assign({},this.query)})},addQuery:function(e,t){var i=this.clone();return i.query[e]=t,i},removeQuery:function(e){var t=this.clone();return void 0!==t.query[e]&&(t.query[e]=void 0),t},withCredentials:function(e){return r(this,{_withCredentials:e})},setQuery:function(e){return r(this,{query:e})},clearHooks:function(){return r(this,{beforehooks:[],afterhooks:[]})},beforeHook:function(e){var t=this.beforehooks.slice();return t.push(e),r(this,{beforehooks:t})},afterHook:function(e){var t=this.afterhooks.slice();return t.push(e),r(this,{afterhooks:t})},setHeader:function(e){return(e=Object.assign({},this.headers,e))[t]=void 0,r(this,{headers:e})}},["put","head","patch","delete","post","get"].map(function(e){f[e]=function(h,p,f){return function(e,r,c){c=c||function(){},u(r)&&(c=r,r=void 0);var h,p=new Promise(function(e){h=function(t){try{c(t.error,t.body,t.code)}catch(e){}e(t)}});return r&&((e=e.clone()).body=r,e.content_type===s&&(e.body=m.Jsonify(r)),e.content_type===i&&(e.body=d(r))),l(e.beforehooks.slice(),{request:e},function(i){if(i.error)return h({body:{error:bq.error},code:0,error:i.error});!function(e,i){let s=d(e.query);if(s&&(s="?"+s),!m.XMLHttpRequest)return function(e,i,s){var r=Object.assign({},e.headers);e.content_type&&(r[t]=e.content_type);var n=0;fetch(e.baseurl+s,{method:e.method,headers:r,credentials:e._withCredentials,body:e.body}).then(function(e){return n=e.status,e.text()}).then(function(e){i(void 0,e,n)}).catch(function(e){i("network_error",e,-1)})}(e,i,s);var r=new m.XMLHttpRequest;for(var n in e.xhr=r,r.onreadystatechange=function(e){4===r.readyState&&(0===r.status?i("network_error",r.responseText,r.status):i(void 0,r.responseText,r.status))},r.open(e.method,e.baseurl+s),r.withCredentials=e._withCredentials,e.headers)r.setRequestHeader(n,e.headers[n]);e.content_type&&r.setRequestHeader(t,e.content_type),r.send(e.body)}(i.request,function(t,i,s){l(e.afterhooks.slice(),{request:e,code:s,body:i,err:t},function(t){var i=t.body;if("network_error"==r)return h({body:{error:n},code:t.code,error:n});if("json"==e.parser&&t.body)try{i=m.ParseJson(t.body)}catch(e){return h({body:{error:o,origin_body:t.body},code:t.code,error:o})}var r=t.err;if("network_error"==r)return h({body:{error:n},code:t.code,error:n});!r&&(s<200||s>299)&&(r=i&&i.error?i.error:a),h({body:r?i||{error:r}:i,code:t.code,error:r})})})}),p}(r(this,{method:e,baseurl:(_=this.baseurl,g=h,_=c(_),(g=c(g))&&_?g.startsWith("http://")||g.startsWith("https://")||g.startsWith("//")?g:(_.endsWith("/")||(_+="/"),g.startsWith("/")&&(g=g.substring(1)),_+g):_+g)}),p,f);var _,g}}),f.setBaseUrl=function(e){return r(this,{baseurl:e})},f.contentTypeJson=function(){return r(this,{content_type:s})},f.contentTypeForm=function(){return r(this,{content_type:i})},f.setContentType=function(e){return r(this,{content_type:c(e)})},f.setParser=function(e){return r(this,{parser:c(e)})},f.setBody=function(e){return r(this,{body:e})},f),m={Jsonify:JSON.stringify,ParseJson:JSON.parse};_.env=m,_.waterfall=l,e.exports=_},9(e,t,i){var s=i(9143);e.exports=function(e,t,i){var r=[],n="idle",o=function(e){var t=e.map(function(e){return e.payload}),s=i(t);s&&s.then||(s=Promise.resolve(s));var r=e.map(function(e){return e.rs});return new Promise(function(e){s.then(function(t){r.map(function(e,i){e(t&&t[i])}),e()})})},a=function(){"executing"!==n&&(n="executing",s(function(){if(r.length<=e)return Promise.resolve(!1);var t=r.splice(0,e);return o(t).then(function(){return!0})}).then(function(){if(0!==r.length){var e=t-(Date.now()-r[0].created);if(e>=1){if(n="idle",r[0].settedTimeout)return;return r[0].settedTimeout=!0,void setTimeout(a,e)}var i=r;r=[],o(i).then(function(){n="idle",a()})}else n="idle"}))};return this.push=function(e,t){return new Promise(function(i){r.push({payload:e,priority:t,created:Date.now(),rs:i}),a()})},this}},9096(e){e.exports={map:function(e,t){if(!e)return[];t||(t=function(e){return e});var i=[];if(Array.isArray(e)){for(var s=0;s<e.length;s++)i.push(t(e[s],s));return i}if("object"==typeof e){var r=Object.keys(e);for(s=0;s<r.length;s++){var n=r[s];i.push(t(e[n],n))}return i}return i}}},8193(e,t,i){var s=i(9798),r=i(9143),n=i(5219),o=i(9);e.exports={sleep:s,loop:r,map:n,batch:o}},9143(e){e.exports=function e(t){var i=t();if(!i||!i.then){var s=i;i={then:function(e){e(s)}}}return i.then(function(i){return i?e(t):Promise.resolve()})}},5219(e,t,i){var s=i(9096);e.exports=function(e,t,i){if("number"==typeof t){let e=i;i=t,t=e}t||(t=function(){}),("number"!=typeof i||i<=0)&&(i=1);var r={};if(s.map(e,function(e,t){r[t]=e}),i<=0&&(i=1),0===Object.keys(r).length)return Promise.resolve([]);Object.keys(r).length<i&&(i=Object.keys(r).length);var n={};return new Promise(function(e){let o=Object.keys(r).length;for(var a=function(){var i=Object.keys(r);if(0!==i.length){var c=i.shift(),u=r[c];delete r[c];var l=t(u,c);l&&l.then||(l=Promise.resolve(l)),l.then(function(t){if(n[c]=t,Object.keys(n).length===o)return e(s.map(n));a()})}},c=0;c<i;c++)setTimeout(a,1)})}},9798(e){e.exports=function(e){return new Promise(function(t){setTimeout(t,e)})}},7695(e){e.exports={xhrsend:function(e,t,i,s){if("undefined"==typeof XMLHttpRequest)return function(e,t,i,s){let r={};i&&(r["content-type"]="text/plain"),fetch(t,{method:e,headers:r,body:i}).then(e=>e.text().then(t=>s&&s(t,e.status))).catch(e=>s&&s(e,-1))}(e,t,i,s);var r=new XMLHttpRequest;r.onreadystatechange=function(e){4===r.readyState&&(s&&s(r.responseText,r.status),s=void 0)},r.onerror=function(){s&&s(r.responseText,-1),s=void 0},r.open(e,t),i&&r.setRequestHeader("content-type","text/plain"),r.send(i)},parseJSON:function(e){try{return JSON.parse(e)}catch(e){}},Pubsub:function(){var e={};this.emit=function(t){for(var i=[],s=1;s<arguments.length;s++)i.push(arguments[s]);var r=e[t];if(r)for(s=0;s<r.length;s++)r[s].apply(void 0,i)},this.on=function(t,i){e[t]||(e[t]=[]),e[t].push(i)}}}},2839(e,t,i){var s=i(8193),{xhrsend:r,parseJSON:n,Pubsub:o}=i(7695);function a(e,t,i,o,a,h){a=a||r,t=t||{};var d="";h||(h="");var p=!1,f=!1,_=!0,m=0,g=!1,v=function(t){p||(m=Date.now(),a("get",e+"poll?token="+d+"&v=5&account-id="+h,void 0,function(i,s){if(!p){var r=250-(Date.now()-m);if(r<0&&(r=0),c(s))return f=!0,setTimeout(v,Math.max(function(e){if(!e||-1===e)return 0;var t=1e3*Math.pow(1.5,e);return Math.min(1e4,t)}(t),r),t+1);if(200!==s)return f=!0,b("poll");f=!1,(i=n(i)||{}).host&&(e=l(i.host));var a=i.sequential_token;return a?(d=a,o(i.events||[]),r>0?setTimeout(v,r,0):v(0)):b("poll")}}))},y=s.batch(50,100,function(i){if(p)return Promise.resolve(u("dead",i.length));if(i.length<=0)return Promise.resolve([]);var r,o=new Promise(e=>{r=e}),f=!1;return setTimeout(function(){f||p||(_=!0)},4e3),setTimeout(()=>{f||(f=!0,_=!0,r(u("dead",i.length)),p||b("subs"))},6e4),s.loop(function(){return new Promise(function(s){if(p)return r(u("dead",i.length)),s(!1);var o="?token="+d;Promise.resolve().then(function(){return t.getAccessToken()}).then(function(m){if(p)return r(u("dead",i.length)),s(!1);t.user_ref?o+="&user_ref="+encodeURIComponent(t.user_ref):t.user_mask?o+="&user-mask="+encodeURIComponent(t.user_mask):m&&(o+="&access-token="+m);var y=e+"subs"+o+"&v=5&account-id="+encodeURIComponent(h||t.account_id);a("post",y,JSON.stringify({events:i}),function(t,o){if(!f){if(p)return r(u("dead",i.length)),s(!1);if(c(o))return _=!0,setTimeout(s,3e3,!0);if(200!==o)return b("subs"),r(u("dead",i.length)),s(!1);if(_=!1,f=!0,d)return r(i),s(!1);var a=(t=n(t)||{}).initial_token;return a?(t.host&&(e=l(t.host)),d=a,g||(g=!0,v(0)),r(i),s(!1)):(b("subs"),r(u("dead",i.length)),s(!1))}})}).catch(function(){_=!0,setTimeout(s,3e3,!0)})})}),o});this.subscribe=y.push.bind(y),this.getStatus=function(){return p?"dead":_||f?"connecting":"active"};var b=function(e){p=!0,i(e)};this.kill=b}function c(e){return e>=500&&e<600||0===e||-1===e||429===e}function u(e,t){for(var i=[],s=0;s<t;s++)i.push(e);return i}function l(e){return(e=e||"").startsWith("//")?"https:"+e:e}e.exports=function(e,t,i,s,r){("string"==typeof e||e instanceof String)&&(e=[e]),(t=t||{}).getAccessToken||(t.getAccessToken=function(){return Promise.resolve("")}),s||(s=t.account_id||"");var n=new o,c={};this.stop=function(){if(u){var e=u;u=void 0,e.kill(),n.emit("interrupted")}},this.onEvent=function(e){return n.on("event",e)},this.onInterrupted=function(e){return n.on("interrupted",e)},this.getStatus=function(){return u?u.getStatus():"dead"};var u,l=function(e){if(!u)return Promise.resolve({error:"dead"});if("string"==typeof e&&(e=[e]),!Array.isArray(e))return Promise.resolve({error:"param should be an array or string"});for(var t=[],i=0;i<e.length;i++){var s=e[i];s&&(c[s]||(c[s]=!0,t.push(u.subscribe(s))))}return 0===t.length?Promise.resolve({}):Promise.all(t).then(function(){return u&&"dead"!=u.getStatus()?{}:{error:"dead"}})};this.subscribe=l;var h=function(){var o=e[Math.floor(Math.random()*e.length)];if(u){var d=u;u=void 0,d.kill()}var p=new a(o,t,function(e,t,i){void 0!==u&&p==u&&(u=void 0,n.emit("interrupted",e,t,i),r||setTimeout(h,2e3))},function(e){if(p==u)for(var t=0;t<e.length;t++)n.emit("event",e[t])},i,s);u=p;var f=Object.keys(c);return c={},l(f)};this.reconnect=h,h()}},5180(e){e.exports={ApiURL:"https://api.sbz.vn/4.0",RealtimeURL:"https://api.sbz.vn/rts/0/",FileURL:"https://vcdn.subiz-cdn.com/file/"}},450(e){var t={},i={};t.length=0,t.cache=i,t.getItem=function(e){return e in i?i[e]:null},t.setItem=function(e,s){void 0===s?t.removeItem(e):(Object.prototype.hasOwnProperty.call(i,e)||t.length++,i[e]=s)},t.removeItem=function(e){Object.prototype.hasOwnProperty.call(i,e)&&(delete i[e],t.length--)},t.key=function(e){return Object.keys(i)[e]||null},t.clear=function(){i={},t.length=0},e.exports=t},5672(e){e.exports=function(){"use strict";var e=function(){return e.get.apply(e,arguments)},t=e.utils={isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},isPlainObject:function(e){return!!e&&"[object Object]"===Object.prototype.toString.call(e)},toArray:function(e){return Array.prototype.slice.call(e)},getKeys:Object.keys||function(e){var t=[],i="";for(i in e)e.hasOwnProperty(i)&&t.push(i);return t},encode:function(e){return String(e).replace(/[,;"\\=\s%]/g,function(e){return encodeURIComponent(e)})},decode:function(e){return decodeURIComponent(e)},retrieve:function(e,t){return e??t}};return e.defaults={},e.expiresMultiplier=86400,e.set=function(e,i,s){if(t.isPlainObject(e))for(var r in e)e.hasOwnProperty(r)&&this.set(r,e[r],i);else{var n=void 0!==(s=t.isPlainObject(s)?s:{expires:s}).expires?s.expires:this.defaults.expires||"",o=typeof n;"string"===o&&""!==n?n=new Date(n):"number"===o&&(n=new Date(+new Date+1e3*this.expiresMultiplier*n)),""!==n&&"toUTCString"in n&&(n=";expires="+n.toUTCString());var a=s.path||this.defaults.path;a=a?";path="+a:"";var c=s.domain||this.defaults.domain;c=c?";domain="+c:"";var u=s.secure||this.defaults.secure?";secure":"";!1===s.secure&&(u="");var l=s.sameSite||this.defaults.sameSite;l=l?";SameSite="+l:"",null===s.sameSite&&(l=""),document.cookie=t.encode(e)+"="+t.encode(i)+n+a+c+u+l}return this},e.setDefault=function(i,s,r){if(t.isPlainObject(i)){for(var n in i)void 0===this.get(n)&&this.set(n,i[n],s);return e}if(void 0===this.get(i))return this.set.apply(this,arguments)},e.remove=function(e){for(var i=0,s=(e=t.isArray(e)?e:t.toArray(arguments)).length;i<s;i++)this.set(e[i],"",-1);return this},e.removeSpecific=function(e,i){if(!i)return this.remove(e);e=t.isArray(e)?e:[e],i.expires=-1;for(var s=0,r=e.length;s<r;s++)this.set(e[s],"",i);return this},e.empty=function(){return this.remove(t.getKeys(this.all()))},e.get=function(e,i){var s=this.all();if(t.isArray(e)){for(var r={},n=0,o=e.length;n<o;n++){var a=e[n];r[a]=t.retrieve(s[a],i)}return r}return t.retrieve(s[e],i)},e.all=function(){if(""===document.cookie)return{};for(var e=document.cookie.split("; "),i={},s=0,r=e.length;s<r;s++){var n=e[s].split("="),o=t.decode(n.shift()),a=t.decode(n.join("="));i[o]=a}return i},e.enabled=function(){if(navigator.cookieEnabled)return!0;var t="_"===e.set("_","_").get("_");return e.remove("_"),t},e}()}};const t={};function i(s){const r=t[s];if(void 0!==r)return r.exports;const n=t[s]={id:s,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.exports}i.m=e,i.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.cw=e=>{var t;return()=>{if(e){var i=e;e=0,t={exports:{}},i.call(t.exports,t,t.exports)}return t.exports}},i.d=(e,t)=>{if(Array.isArray(t))for(var s=0;s<t.length;){var r=t[s++],n=t[s++],o=0===n?{enumerable:!0,value:t[s++]}:{enumerable:!0,get:n};i.o(e,r)||Object.defineProperty(e,r,o)}else for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.f={},i.e=e=>{const t=[];return i.f.j(e,t),Promise.all(t)},i.u=e=>"1a12ed33347."+e+".js",i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{const e={},t="@subiz/widget-v4:";i.l=(s,r,n,o)=>{if(e[s])return void e[s].push(r);let a,c;if(void 0!==n){const e=document.getElementsByTagName("script");for(var u=0;u<e.length;u++){const i=e[u];if(i.getAttribute("src")==s||i.getAttribute("data-webpack")==t+n){a=i;break}}}a||(c=!0,a=document.createElement("script"),a.charset="utf-8",i.nc&&a.setAttribute("nonce",i.nc),a.setAttribute("data-webpack",t+n),a.src=s),e[s]=[r];const l=(t,i)=>{a.onerror=a.onload=null,clearTimeout(h);const r=e[s];if(delete e[s],a.parentNode?.removeChild(a),r?.forEach(e=>e(i)),t)return t(i)},h=setTimeout(l.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=l.bind(null,a.onerror),a.onload=l.bind(null,a.onload),c&&document.head.appendChild(a)}})(),i.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.p="https://vcdn.subiz-cdn.com/widget-v4/public/",(()=>{const e={325:0};i.f.j=(t,s)=>{let r=i.o(e,t)?e[t]:void 0;if(0!==r)if(r)s.push(r[2]);else{const n=new Promise((i,s)=>r=e[t]=[i,s]);s.push(r[2]=n);const o=new Error,a=s=>{if(i.o(e,t)&&(r=e[t],0!==r&&(e[t]=void 0),r)){const e=s&&("load"===s.type?"missing":s.type),i=s&&s.target&&s.target.src;o.message="Loading chunk "+t+" failed.\n("+e+": "+i+")",o.name="ChunkLoadError",o.type=e,o.request=i,o.event=s,r[1](o)}};i.l(i.p+i.u(t),a,"chunk-"+t,t)}};const t=(t,s)=>{let[r,n,o]=s;var a,c,u=0;if(r.some(t=>0!==e[t])){for(a in n)i.o(n,a)&&(i.m[a]=n[a]);o&&o(i)}for(t&&t(s);u<r.length;u++)c=r[u],i.o(e,c)&&e[c]&&e[c][0](),e[c]=0},s=self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[];s.forEach(t.bind(null,0)),s.push=t.bind(null,s.push.bind(s))})(),(()=>{"use strict";var e=()=>i(318),t=()=>i(450),s=i.cw(function(t,s){i.r(s),i.d(s,{Date:()=>w,XMLHttpRequest:()=>A,agentsOfConvo:()=>W,blockToText:()=>Ue,checkRunConditions:()=>ye,checkUrlCondition:()=>Ve,clearInterval:()=>C,clearTimeout:()=>z,cloneDeep:()=>I,convoOfEv:()=>P,convoToEv:()=>O,detectLang:()=>Oe,diffDay:()=>Ce,diffYear:()=>ze,each:()=>F,extract:()=>p,extractEmails:()=>h,extractEmojis:()=>u,extractLinks:()=>l,extractPhones:()=>d,extractText:()=>_,filter:()=>R,find:()=>J,formatCurrency:()=>Ie,getAgentDisplayName:()=>re,getDayName:()=>be,getMs:()=>Pe,getUrlParameter:()=>je,getUserAttr:()=>ae,hslToRgb:()=>c,includes:()=>q,isBlockEmpty:()=>Fe,isConvoSeen:()=>$,isEmail:()=>ie,isEmptyBlock:()=>Ne,isEmptyMessage:()=>Be,isNumber:()=>te,isPhone:()=>Y,isURL:()=>ee,isUserBanned:()=>ne,js2css:()=>ge,last:()=>se,map:()=>U,merge:()=>M,noop:()=>ue,norm:()=>ce,offsetToMin:()=>Se,orderBy:()=>Z,orderByF:()=>K,parseJSON:()=>m,pipeExtracts:()=>f,preloadImg:()=>xe,preloadWebfonts:()=>ke,randomString:()=>L,replaceAll:()=>V,replaceCssVariable:()=>de,replaceCssVariablePlugin:()=>he,requestAnimationFrame:()=>k,rgbToHsl:()=>o,sameDay:()=>Ae,scrollIntoViewIfNeeded:()=>Re,setCss:()=>fe,setInterval:()=>S,setTimeout:()=>x,setUserAttr:()=>oe,shortTime:()=>Te,size:()=>B,sleep:()=>Me,startsWith:()=>N,stringify:()=>y,throttle:()=>Q,tokenize:()=>pe,trim:()=>H,trimStart:()=>G,unicodeToAscii:()=>Le,unixSec:()=>Ee,usersOfConvo:()=>D});var r=a();const n=e();function o(e,t,i){e/=255,t/=255,i/=255;var s,r,n=Math.max(e,t,i),o=Math.min(e,t,i),a=(n+o)/2;if(n==o)s=r=0;else{var c=n-o;switch(r=a>.5?c/(2-n-o):c/(n+o),n){case e:s=(t-i)/c+(t<i?6:0);break;case t:s=(i-e)/c+2;break;case i:s=(e-t)/c+4}s/=6}return[s,r,a]}function c(e,t,i){var s,r,n;if(0==t)s=r=n=i;else{function c(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+(t-e)*(2/3-i)*6:e}var o=i<.5?i*(1+t):i+t-i*t,a=2*i-o;s=c(a,o,e+1/3),r=c(a,o,e),n=c(a,o,e-1/3)}return[255*s,255*r,255*n]}function u(e){for(var t=[],i=0;i<e.length;i++)for(var s=0;s<We.length;s++)if(e.indexOf(We[s],i)===i){t.push({index:i,length:We[s].length}),i+=We[s].length-1;break}return t}function l(e){e=e||"";for(var t,i=/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{2,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim,s=[];t=i.exec(e);){const e=5;i.lastIndex-t.index>e+1&&s.push({index:t.index,length:i.lastIndex-t.index})}return s}function h(e){e=e||"";for(var t,i=/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/gim,s=[];t=i.exec(e);)s.push({index:t.index,length:i.lastIndex-t.index});return s}function d(e){e=e||"";for(var t="",i={},s=0;s<e.length;s++){var r=e.charAt(s);if("."===r||"-"===r||" "===r){var n=s>0?e.charAt(s-1):"-",o=s<e.length-1?e.charAt(s+1):"-";-1!=="0123456789".indexOf(n)&&-1!=="0123456789".indexOf(o)||(i[(t+=r).length-1]=s)}else i[(t+=r).length-1]=s}for(var a,c=/([0-9]{8,13})/gim,u=[];a=c.exec(t);)u.push({index:i[a.index],length:i[c.lastIndex-1]-i[a.index]+1});return u}function p(e,t,i){if(!e)return[];var s=[],r=0,n=t(e);if(0===B(n))return[{type:"text",text:e}];F(n,t=>{s.push({type:"text",text:e.substr(r,t.index-r)}),s.push({type:i,text:e.substr(t.index,t.length)}),r=t.index+t.length});var o=se(n);return s.push({type:"text",text:e.substr(o.index+o.length,e.length-o.index+o.length)}),R(s,e=>""!==e.text)}function f(e,t){var i=[];if(0===B(t))return[{type:"text",text:e}];var s=t.shift();return F(p(e,s,s.type),e=>{if("text"!==e.type)return i.push(e);i=i.concat(f(e.text,t.slice()))}),i}function _(e){var t=e=>{const t=h(e);return l(e).map(t=>{const i=e.substr(t.index,t.length);return{...t,length:i.replace(/[.,;!?]+$/,"").length}}).filter(e=>!t.some(t=>e.index>=t.index&&e.index+e.length<=t.index+t.length))};t.type="link";var i=h;i.type="email";var s=d;s.type="phone";var r=u;return r.type="emoji",f(e,[t,i,s,r])}function m(e){try{return b(e)}catch(e){}}var g=document.createElement("iframe");g.style.display="none",document.documentElement.appendChild(g);const v=g.contentDocument.createElement("div");g.contentDocument.body.appendChild(v);var y=g.contentWindow.JSON.stringify,b=g.contentWindow.JSON.parse,w=g.contentWindow.Date,k=g.contentWindow.requestAnimationFrame,x=g.contentWindow.setTimeout.bind(g.contentWindow),S=g.contentWindow.setInterval.bind(g.contentWindow),C=g.contentWindow.clearInterval.bind(g.contentWindow),z=g.contentWindow.clearTimeout.bind(g.contentWindow),A=g.contentWindow.XMLHttpRequest;const T=A.prototype.open,E=A.prototype.send;function P(e){return e?r.get(e,"data.conversation.id",r.get(e,"data.message.conversation_id")):""}function O(e,t){if(!t)return"";switch(t.type){case"message_sent":case"message_updated":case"message_deleted":case"message_pong":return r.set(t,"data.message.conversation_id",e);case"ticket_updated":return r.set(t,"data.ticket.conversation_id",e);default:return r.set(t,"data.conversation.id",e)}}function j(e){return e&&"object"==typeof e&&!Array.isArray(e)}function M(e,...t){if(!t.length)return e;const i=t.shift();if(j(e)&&j(i))for(const t in i)j(i[t])?(e[t]||Object.assign(e,{[t]:{}}),M(e[t],i[t])):Object.assign(e,{[t]:i[t]});return M(e,...t)}function I(e){if(e!==Object(e))return e;var t=y(e);return void 0!==t?b(t):void 0}function L(e){var t,i="";(!e||e<1)&&(e=10);for(var s=0;s<e;s++)t=Math.floor(25*Math.random()+97),i+=String.fromCharCode(t);return i}function R(e,t){if(!e)return[];if(!t)return e;var i=[];if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];t(e[r],r)&&i.push(e[r])}return i}if(Array.isArray(e)){for(let s=0;s<e.length;s++)t(e[s],s)&&i.push(e[s]);return i}return i}function q(e,t){if(!e)return!1;var i="string"==typeof e||e instanceof String;return!(!Array.isArray(e)&&!i)&&e.includes(t)}function U(e,t){if(!e)return[];t||(t=e=>e);var i=[];if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];i.push(t(e[r],r))}return i}if(Array.isArray(e)){for(let s=0;s<e.length;s++)i.push(t(e[s],s));return i}return i}function F(e,t){return U(e,t)}function D(e){return e?U(R(e.members,e=>"user"===e.type),e=>e.id):[]}function $(e,t){if("ended"===e.state)return!0;let i=e.last_message_sent;if(!i)return!0;if(r.get(i,"by.id")===t)return!0;let s=J(e.members,e=>e.id===t);return!s||Pe(i.created)<Pe(s.seen_at)}function W(e,t){return e?U(R(e.members,e=>t?"agent"===e.type||"bot"===e.type:"agent"===e.type),e=>e.id):[]}function N(e,t){return((e||"")+"").startsWith(t)}function B(e){return e?void 0!==e.length?e.length:Object.keys(e).length:0}function V(e,t,i){return(e||"").split(t).join(i)}function H(e,t){return((e||"")+"").replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}function G(e,t){for(e=(e||"")+"";e.charAt(0)===t;)e=e.substr(1);return e}function Q(e,t,i){var s,r,n,o=null,a=0;i||(i={});var c=function(){a=!1===i.leading?0:(new w).getTime(),o=null,n=e.apply(s,r),o||(s=r=null)};return function(){var u=(new w).getTime();a||!1!==i.leading||(a=u);var l=t-(u-a);return s=this,r=arguments,l<=0||l>t?(o&&(z(o),o=null),a=u,n=e.apply(s,r),o||(s=r=null)):o||!1===i.trailing||(o=x(c,l)),n}}function J(e,t){if(e)return e[X(e,t)]}function X(e,t){if(!e)return-1;if(!t)return-1;if("object"==typeof e){var i=Object.keys(e);for(let r=0;r<i.length;r++){var s=i[r];if(t(e[s],s))return s}}if(Array.isArray(e)){for(let i=0;i<e.length;i++)if(t(e[i],i))return i;return-1}return-1}function Z(e,t,i){var s=[];return F(e,e=>s.push(e)),s.sort((e,s)=>{if(e[t]===s[t])return 0;var r=e[t]<s[t]?-1:1;return"desc"===i?-r:r}),s}function K(e,t,i){var s=[];return F(e,e=>s.push(e)),s.sort((e,s)=>{let r=t(e),n=t(s);if(r===n)return 0;var o=r<n?-1:1;return"desc"===i?-o:o}),s}function Y(e){if("string"!=typeof e&&"number"!=typeof e)return!1;const t=String(e).trim(),i=t.replace(/\((\d+)\)/g,"$1");if(!/^\+?\d+(?:[ .-]\d+)*$/.test(i))return!1;const s=t.replace(/\D/g,"");return!(s.length<7||s.length>15||/^(\d)\1+$/.test(s)||t.startsWith("+")&&s.startsWith("0"))}function ee(e){return/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi.test(String(e).toLowerCase())}function te(e){return/^\d+$/.test(String(e))}function ie(e){if("string"!=typeof e)return!1;const t=e.trim();if(t.length>254)return!1;const i=t.lastIndexOf("@"),s=t.slice(0,i),r=t.slice(i+1);return!(!s||s.length>64)&&(!(!s.startsWith('"')&&(s.startsWith(".")||s.endsWith(".")||s.includes("..")))&&(!(!r.startsWith("[")&&r.split(".").some(e=>e.length>63||!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(e)))&&/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t.toLowerCase())))}function se(e){var t=null==e?0:e.length;return t?e[t-1]:void 0}function re(e,t){return r.get(t,"fullname")||r.get(t,"email")||r.get(e,"name")||"Agent"}function ne(e){return ae(e,"is_ban","boolean")}function oe(e,t){if(e&&r.get(t,"key")){e.attributes=e.attributes||[];var i=X(e.attributes,e=>e&&e.key===t.key);-1!==i?e.attributes[i]=t:e.attributes.push(t)}}function ae(e,t,i){if(!e||!e.attributes)return;let s;return F(e.attributes,e=>{e&&e.key===t&&("datetime"===i&&(s=e.datetime),"boolean"===i&&(s=e.boolean),"number"===i&&(s=e.number),"text"===i&&(s=e.text),"list"===i&&(s=[e.text].concat(e.other_values)))}),s}function ce(e){return(e=e||"").trim().toLowerCase()}function ue(){}function le(e){return("string"==typeof e||e instanceof String)&&(e=e.trim().replace(/;+$/,"")),e}function he(e,t){var i=[e];let s=t.spacer||10;t=Object.assign({},t,{spacer:s+"px",spacer0:s/2+"px",spacer2:2*s+"px",spacer3:3*s+"px"}),i=pe(i,"'@font_family'"),i=pe(i,"'@font_size'"),i=pe(i,"'@text_color'"),i=pe(i,"'@faded_text_color'"),i=pe(i,"'@primary_color'"),i=pe(i,"'@background'"),i=pe(i,"'@spacer'"),i=pe(i,"'@spacer0'"),i=pe(i,"'@spacer2'"),i=pe(i,"'@spacer3'");let n=$e(r.get(t,"primary_color")||r.get(me,"primary_color"));n||(n={red:238,blue:238,green:238});let a=o(n.red,n.green,n.blue)[0],[u,l,h]=c(a,.25,.95);me.primary_color_faded=`rgb(${u},${l},${h})`;for(var d=[],p=0;p<i.length;p++){var f=i[p];if("string"!=typeof f){var _=f.type.substr(2,f.type.length-3),m=r.get(t,_)||r.get(me,_)||"";d.push(m)}else d.push(f)}return d.join("")}function de(e,t){var i=[e];i=pe(i,"'@primary_color'"),i=pe(i,"'@primary_color_faded'"),i=pe(i,"@esc-primary-color-esc"),i=pe(i,"'@secondary_color'"),i=pe(i,"'@background'"),i=pe(i,"'@text_color'"),i=pe(i,"'@width'"),i=pe(i,"'@height'"),i=pe(i,"'@desktop_button.width'"),i=pe(i,"'@desktop_button.height'"),i=pe(i,"'@desktop_button.background'"),i=pe(i,"'@desktop_button.border_radius'"),i=pe(i,"'@desktop_button.margin_x'"),i=pe(i,"'@desktop_button.margin_y'"),i=pe(i,"'@desktop_widget_max_height'"),i=pe(i,"'@preview_max_width'"),i=pe(i,"'@mobile_button.width'"),i=pe(i,"'@mobile_button.height'"),i=pe(i,"'@mobile_button.background'"),i=pe(i,"'@mobile_button.border_radius'"),i=pe(i,"'@mobile_button.margin_x'"),i=pe(i,"'@mobile_button.margin_y'"),i=pe(i,"'@mobile_height'"),i=pe(i,"'@widget_position'"),i=pe(i,"'@z_index'"),i=pe(i,"'@z_index_2'"),i=pe(i,"'@z_index_3'"),i=pe(i,"'@z_index_4'"),i=pe(i,"'@z_index_5'"),i=pe(i,"'@form_background_color'"),i=pe(i,"'@form_header_font_size'"),i=pe(i,"'@form_header_font_family'"),i=pe(i,"'@form_desc_font_size'"),i=pe(i,"'@form_desc_font_family'"),i=pe(i,"'@form_input_label_font_size'"),i=pe(i,"'@form_input_label_font_family'");let s=$e(r.get(t,"primary_color")||r.get(me,"primary_color"));s||(s={red:238,blue:238,green:238});let n=o(s.red,s.green,s.blue)[0],[a,u,l]=c(n,.25,.95);me.primary_color_faded=`rgb(${a},${u},${l})`;for(var h=[],d=0;d<i.length;d++){var p=i[d];if("string"!=typeof p)if("@esc-primary-color-esc"!==p.type)if("'@z_index_2'"!==p.type)if("'@z_index_3'"!==p.type)if("'@z_index_4'"!==p.type)if("'@z_index_5'"!==p.type){var f=p.type.substr(2,p.type.length-3);_=le(_=r.get(t,f)||r.get(me,f)||""),["mobile_button.width","mobile_button.height","mobile_button.margin_x","mobile_button.margin_y","desktop_button.width","desktop_button.height","desktop_button.margin_x","desktop_button.margin_y","form_header_font_size","form_desc_font_size","form_input_label_font_size","width","height"].includes(f)&&(_+="px"),"height"!==f||"full"!==r.get(t,"window_mode")?h.push(_):h.push("100%")}else _=r.get(t,"z_index")||r.get(me,"z_index"),h.push(_+5);else _=r.get(t,"z_index")||r.get(me,"z_index"),h.push(_+4);else{var _=r.get(t,"z_index")||r.get(me,"z_index");h.push(_+3)}else{_=r.get(t,"z_index")||r.get(me,"z_index");h.push(_+2)}else{_=r.get(t,"primary_color")||r.get(me,"primary_color");h.push(encodeURIComponent(le(_)))}else h.push(p)}return h.join("")}function pe(e,t){if(!e||!e.length)return[];var i=[];for(let n=0;n<e.length;n++){var s=e[n];if("string"==typeof s){var r=s.split(t);for(let e=0;e<r.length;e++)i.push(r[e]),i.push({type:t});i.pop()}else i.push(s)}return i}function fe(e,t,i){i=V(i,"#sbz92","#"+e),t.styleSheet?t.styleSheet.cssText=i:(t.innerHTML="",t.appendChild(document.createTextNode(i)))}A.prototype.open=function(e,t,i,s,r){return this._url=t,T.apply(this,arguments)},A.prototype.send=function(e){let t=this.onreadystatechange;return this.onreadystatechange=function(e,i,s){4==this.readyState&&((this.status>=400||0==this.status)&&"object"==typeof sbz_logs&&sbz_logs.push({type:"xhrfailed",url:this._url,status:this.status,response:this.responseText}),"function"==typeof t&&t(e,i,s))},E.apply(this,arguments)},n.env.XMLHttpRequest=A;const _e="https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5",me={primary_color:"#0265FF",secondary_color:"#555555",background:"linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)",text_color:"white",width:375,height:705,window_mode:"mini",desktop_button:{width:.3,height:.3,border_radius:"100%",background_mask_url:_e,margin_x:.3,margin_y:.3},mobile_button:{width:.3,height:.3,border_radius:"100%",background_mask_url:_e,margin_x:.3,margin_y:.3},mobile_height:"100%",widget_position:"fixed",z_index:2e9};function ge(e,t,i){var s={};for(var r in e)e.hasOwnProperty(r)&&(t&&t.length>0&&-1===t.indexOf(r)||("string"==typeof e[r]?s[r]=H(e[r]):s[r]=e[r]));e=s;let n="";for(var r in e)if(e.hasOwnProperty(r)){var o="";if(e.blur&&(o+="blur("+e.blur+") "),e.grayscale&&(o+="grayscale("+e+") "),o&&(n+="filter: "+o+"!important;"),void 0!==e.rotate&&(n+="transform:rotate("+e.rotate+") !important;"),void 0!==e[r]){let t=e[r]+"";U(i,(e,i)=>{-1!==t.indexOf(i)&&(t=V(t,i,e))}),n+=V(r,"_","-")+":"+t+" !important;","color"===r&&(n+="-webkit-text-fill-color: "+t+" !important;")}}return n}function ve(){var e=!!window.opr&&!!window.opr.addons||!!window.opera||navigator.userAgent.indexOf(" OPR/")>=0,t="undefined"!=typeof InstallTrigger,i=(/constructor/i.test(window.HTMLElement)||(!window.safari||"undefined"!=typeof safari&&window.safari.pushNotification).toString(),!!document.documentMode),s=!i&&!!window.StyleMedia,r=!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime);r||(r=navigator.userAgent.indexOf("Chrome"));var n=r&&-1!=navigator.userAgent.indexOf("Edg"),o=(r||e)&&!!window.CSS;return e?"opera":t?"firefox":i?"ie":s||n?"edge":r?"chrome":o?"blink":"unknown"}function ye(e,t,i,s){var n=s.matchAccount()||{},o=s.matchLocation()||{};if(!function(e,t){return!(t&&(r.get(e,"once_per_user")||r.get(e,"once_per_session")&&Ae(t.created,w.now())||r.get(e,"interval_sec")&&r.get(e,"interval_sec")>(w.now()-t.created)/1e3))}(e,i))return!1;for(let e=0;e<B(t);e++){var a=t[e];switch(a.key){case"url":if(!Ve(a,window.location.href))return!1;break;case"url_path":let e=R(a.exclude_url_paths,e=>ce(e));if(B(e)>0){let t=new URL(window.location.href).pathname||"";if("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),J(e,e=>("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),t===e)))return!1}let t=R(a.url_paths,e=>ce(e));if(B(t)>0){let e=new URL(window.location.href).pathname||"";if("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),!J(t,t=>("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),e===t)))return!1}break;case"browser":if(B(a.browsers)>0){var c=ve();if(!J(a.browsers,e=>ce(e)===ce(c)))return!1}break;case"location":if(B(a.exclude_locations)>0&&J(a.exclude_locations,e=>!(!e.city_name||!e.country_code||e.city_name!==o.city_name||e.country_code!==o.country_code)||!(!e.city_name||e.country_code||e.city_name!==o.city_name)||!(e.city_name||!e.country_code||e.country_code!==o.country_code)||void 0))return!1;if(B(a.locations)>0&&!J(a.locations,e=>!(!e.city_name||!e.country_code||e.city_name!==o.city_name||e.country_code!==o.country_code)||!(!e.city_name||e.country_code||e.city_name!==o.city_name)||!(e.city_name||!e.country_code||e.country_code!==o.country_code)||void 0))return!1;break;case"returning_visitor":if(a.returning_visitor&&s.new_visitor)return!1;if(!a.returning_visitor&&!s.new_visitor)return!1;break;case"user_is_a_contact":let i=r.get(s.matchUser(),"attributes",[]),h=J(i,e=>("emails"===e.key||"related_email"===e.key)&&e.text),d=J(i,e=>("phones"===e.key||"related_phone"===e.key)&&e.text),p=h||d;if(a.user_is_a_contact&&!p)return!1;if(!a.user_is_a_contact&&p)return!1;break;case"device_type":if(B(a.device_types)>0){let e="desktop";if(s.isMobile()&&(e="mobile"),s.isTablet()&&(e="tablet"),!J(a.device_types,t=>ce(t)===ce(e)))return!1}break;case"referer":if(B(a.exclude_referers)>0&&J(a.exclude_referers,e=>ce(document.referrer).indexOf(ce(e))>-1))return!1;if(B(a.urls)>0&&!J(a.referers,e=>ce(document.referrer).indexOf(ce(e))>-1))return!1;break;case"source":if(B(a.sources)>0){let e=s.matchTrafficSource()||"direct";if(!J(a.sources,t=>ce(t)===ce(e)))return!1}break;case"user_attribute":case"user":let f,_=r.get(s.matchUser(),"attributes",[]),g=r.get(a,"user.operator");F(_,e=>{e&&e.key===r.get(a,"user.key")&&(f=e.datetime||e.boolean||e.number||e.text||e.list)});let v=!0;switch(g){case"cons":let e=m(a.value)||[];if(0===B(e))return!1;v=!!J(e,e=>ce(f).indexOf(ce(e))>-1);break;case"notEmpty":v=!!f;break;case"empty":v=!f;break;case"true":v=!0===f||"true"===f;break;case"false":v=!f||!1===f||"false"===f}if(!v)return!1;break;case"timming":if("in"===a.business_hour&&!n.is_in_business_hour)return!1;if("notIn"===a.business_hour&&n.is_in_business_hour)return!1;if(B(a.days_of_week)>0&&!J(a.days_of_week,e=>ce(be((new w).getDay()))===ce(e)))return!1;if(B(a.minutes_of_day)>0&&B(a.minutes_of_day)%2==0){var u=new w,l=u.getMinutes()+60*u.getHours();let e=!1;for(let t=0;t<a.minutes_of_day.length;t+=2){if(a.minutes_of_day[t]<=l&&l<=a.minutes_of_day[t+1]){e=!0;break}if(a.minutes_of_day[t]>a.minutes_of_day[t+1]&&(l>=a.minutes_of_day[t]||l<=a.minutes_of_day[t+1])){e=!0;break}}if(!e)return!1}break;case"offline":if(!n.is_online!=!!a.offline)return!1}}return!0}function be(e){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e]}let we={};function ke(e,t){for(var i=0;i<e.length;i++){let t=e[i];if(t&&!we[t]){we[t]=!0;for(var s=0;s<2;s++){let e=[400,500][s],i=document.createElement("div");i.innerHTML="@!-/#Chào mỪng1",i.style.position="absolute",i.style.display="block",i.style.opacity="0.1",i.style.color="transparent",i.style.fontSize="20px",i.style.height="0px",i.style.top="0px",i.style.width="0px",i.style.fontWeight=e,i.setAttribute("subiz-preload",t+":"+e),document.body.appendChild(i),i.style.fontFamily=t,x(()=>i.remove(),3e3)}}}}function xe(e,t){if(t||(t=()=>{}),!e)return t(),Promise.resolve(!0);let i=new Image;return e=function(e){let t="https://vcdn.subiz-cdn.com/file/";return e?N(e,"/")||N(e,"data:")?e:(N(e,"http://")||N(e,"https://")||N(e,"//")||(e=H(t)+"/"+G(e,"/")),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace("https://file-subiz.com/",t)).replace("http://file-subiz.com/",t)).replace("https://file-v4.subiz.com/",t)).replace("http://file-v4.subiz.com/",t)).replace("https://filev4.subiz.com/",t)).replace("http://filev4.subiz.com/",t)).replace("https://filev4-1.subiz.com/",t)).replace("http://filev4-1.subiz.com/",t)).replace("https://file.subiz.com/",t)).replace("http://file.subiz.com/",t)).replace("https://file.mysubiz.com/",t)).replace("http://file.mysubiz.com/",t)):""}(e),i.src=e,new Promise(e=>{i.onload=()=>{t(),e()}})}function Se(e){if(!e)return 0;e.length<=2&&(e+=":00");let t=e.split(":");if(2!==t.length)return 0;let i=parseInt(t[0]);if(i<0||i>23)return 0;let s=parseInt(t[1]);return s<0||s>59?0:60*i+s}function Ce(e,t,i){var s=-(new w).getTimezoneOffset();i&&(s=Se(i));var r=new w(e).getTime(),n=new w(t).getTime(),o=Math.ceil((r/60/1e3+s)/60/24),a=Math.ceil((n/60/1e3+s)/60/24);return Math.abs(o-a)}function ze(e,t,i){var s=-(new w).getTimezoneOffset(),r=-(new w).getTimezoneOffset();i&&(r=Se(i));var n=new w(e).getTime()+60*(r-s)*1e3,o=new w(t).getTime()+60*(r-s)*1e3;return Math.abs(new w(n).getYear()-new w(o).getYear())}function Ae(e,t,i){return 0===Ce(e,t,i)}function Te(e,t,i,s){var n=-(new w).getTimezoneOffset(),o=n;t&&(o=Se(t));var a=new w(Pe(e));let c=new w(a);c.setMinutes(a.getMinutes()+o-n),i||(i=new w);let u=c.getHours(),l=c.getMinutes(),h=r.get(navigator,"languages.0","en-US");s&&(h=s);let d=c.toLocaleDateString(h,{weekday:"long"}),p=c.getFullYear(),f=c.getMonth()+1,_=c.toLocaleDateString(h,{month:"long"}),m=c.getDate();return u<10&&(u="0"+u),l<10&&(l="0"+l),Ae(a,i,t)?u+":"+l:Ce(a,i,t)<=5?d+", "+u+":"+l:0===ze(a,i,t)?"vi-VN"===h?m+" "+_+", "+u+":"+l:_+" "+m+", "+u+":"+l:"vi-VN"===h?m+"/"+f+"/"+p+", "+u+":"+l:p+"/"+f+"/"+m+", "+u+":"+l}function Ee(e){return Math.floor(Pe(e)/1e3)}function Pe(e){return e?"number"!=typeof e&&(e=new w(e).getTime()):e=0,e>1e18?Math.floor(e/1e6):e>1e15?Math.floor(e/1e3):e>1e12?e:1e3*e}function Oe(){let e=je("sbz_locale"),t=document.getElementsByTagName("html")[0].getAttribute("xml:lang")||document.getElementsByTagName("html")[0].getAttribute("lang"),i=navigator.language;return e||t||i}function je(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var Me=e=>new Promise(t=>x(t,e));function Ie(e,t="VND"){let i=qe.find(e=>e.code===t)||{name:"Dong",code:"VND",symbol:"₫"},s="",r="";return"VND"===t?(s="",r=" "+i.symbol):(s=i.symbol+" ",r=""),e?s+(e=Math.round(e)).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")+r:`${s}0${r}`}function Le(e){return(e=(e+="").replaceAll("đ","d").replaceAll("Đ","D")).normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function Re(e,t=!0){var i=e.parentNode,s=window.getComputedStyle(i,null),r=parseInt(s.getPropertyValue("border-top-width")),n=parseInt(s.getPropertyValue("border-left-width")),o=e.offsetTop-i.offsetTop<i.scrollTop,a=e.offsetTop-i.offsetTop+e.clientHeight-r>i.scrollTop+i.clientHeight,c=e.offsetLeft-i.offsetLeft<i.scrollLeft,u=e.offsetLeft-i.offsetLeft+e.clientWidth-n>i.scrollLeft+i.clientWidth,l=o&&!a;(o||a)&&t&&(i.scrollTop=e.offsetTop-i.offsetTop-i.clientHeight/2-r+e.clientHeight/2),(c||u)&&t&&(i.scrollLeft=e.offsetLeft-i.offsetLeft-i.clientWidth/2-n+e.clientWidth/2),(o||a||c||u)&&!t&&e.scrollIntoView(l)}const qe=[{code:"USD",symbol:"$"},{code:"VND",symbol:"₫"}];function Ue(e){return De(e).trim()}function Fe(e){return Ne(e)}function De(e){if(!e)return"";let t="";return"bullet_list"==e.type||"ordered_list"==e.type?(U(e.content,(i,s)=>{let r="ordered_list"==e.type?"\n"+(Number(s)+1)+". ":"\n* ";t+=r+De(i).trim()}),t):("heading"!=e.type&&"paragraph"!=e.type||(t+="\n"),""!=e.type&&"text"!=e.type&&"link"!=e.type&&"mention-agent"!=e.type&&"mention"!=e.type&&"dynamic-field"!=e.type||B(e.content)?"horizontal_rule"==e.type?t+"\n---\n":"emoji"==e.type?t+(r.get(e,"attrs.code")||e.text||e.Text||""):B(e.content)?(U(e.content,e=>{t+=De(e)}),t):t+(e.text||""):t+(e.text||""))}function $e(e){if(!e||!e.split)return"";v.style.color=e;const t=g.contentWindow.getComputedStyle(v).color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{red:parseInt(t[1]),green:parseInt(t[2]),blue:parseInt(t[3])}:null}let We=["like","unlike","wink","tongue-out","tired","surprised","smiling","sleepy","sad","neutral","heart-eyes","grinning","crying","confused","angry","cry","heart_eyes","neutral_face","emoji--disappointed","smile","open_mouth","tired_face","stuck_out_tongue","moyai","thumbsdown","dislike","thumbsup","ok_hand","octopus","pig2","wave","mouse","mouse2","rat"];function Ne(e){if(!e)return!0;if("image"===e.type&&r.get(e,"image.url"))return!1;if("emoji"===e.type&&(r.get(e,"attrs.code")||e.Text))return!1;if("horizontal_rule"===e.type)return!1;let t=B(R(U(e.content,e=>Ne(e)),e=>!e))>0;return!H(e.text)&&!t}function Be(e){return!e||!e.deleted&&!(e.text||!Ne(e.block)||!function(e){return!e||!B(e.attachments)||0==B(R(e.attachments,e=>"quick_replies"!=e.type||B(R(e.quick_replies,e=>B(H(e))>0))>0))}(e))}function Ve(e,t){let i=R(e.exclude_urls,e=>ce(e)),s=!1,r=0;U(i,e=>{ce(t).indexOf(e)>-1&&(r<B(e)&&(r=B(e)),s=!0)});let n=0,o=R(e.urls,e=>ce(e)),a=0==B(o);return U(o,e=>{ce(t).indexOf(e)>-1&&(n<B(e)&&(n=B(e)),a=!0)}),!(s&&r>=n||!a)}We=U(We,e=>":"+e+":"),i.d(s,["DEFVAL",0,me,"DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL",0,_e])}),r={};i.r(r),i.d(r,{DEFVAL:()=>s().DEFVAL,DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL:()=>s().DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL,Date:()=>s().Date,XMLHttpRequest:()=>s().XMLHttpRequest,agentsOfConvo:()=>s().agentsOfConvo,blockToText:()=>s().blockToText,checkRunConditions:()=>s().checkRunConditions,checkUrlCondition:()=>s().checkUrlCondition,clearInterval:()=>s().clearInterval,clearTimeout:()=>s().clearTimeout,cloneDeep:()=>s().cloneDeep,convoOfEv:()=>s().convoOfEv,convoToEv:()=>s().convoToEv,detectLang:()=>s().detectLang,diffDay:()=>s().diffDay,diffYear:()=>s().diffYear,each:()=>s().each,extract:()=>s().extract,extractEmails:()=>s().extractEmails,extractEmojis:()=>s().extractEmojis,extractLinks:()=>s().extractLinks,extractPhones:()=>s().extractPhones,extractText:()=>s().extractText,filter:()=>s().filter,find:()=>s().find,formatCurrency:()=>s().formatCurrency,getAgentDisplayName:()=>s().getAgentDisplayName,getDayName:()=>s().getDayName,getMs:()=>s().getMs,getUrlParameter:()=>s().getUrlParameter,getUserAttr:()=>s().getUserAttr,hslToRgb:()=>s().hslToRgb,includes:()=>s().includes,isBlockEmpty:()=>s().isBlockEmpty,isConvoSeen:()=>s().isConvoSeen,isEmail:()=>s().isEmail,isEmptyBlock:()=>s().isEmptyBlock,isEmptyMessage:()=>s().isEmptyMessage,isNumber:()=>s().isNumber,isPhone:()=>s().isPhone,isURL:()=>s().isURL,isUserBanned:()=>s().isUserBanned,js2css:()=>s().js2css,last:()=>s().last,map:()=>s().map,merge:()=>s().merge,noop:()=>s().noop,norm:()=>s().norm,offsetToMin:()=>s().offsetToMin,orderBy:()=>s().orderBy,orderByF:()=>s().orderByF,parseJSON:()=>s().parseJSON,pipeExtracts:()=>s().pipeExtracts,preloadImg:()=>s().preloadImg,preloadWebfonts:()=>s().preloadWebfonts,randomString:()=>s().randomString,replaceAll:()=>s().replaceAll,replaceCssVariable:()=>s().replaceCssVariable,replaceCssVariablePlugin:()=>s().replaceCssVariablePlugin,requestAnimationFrame:()=>s().requestAnimationFrame,rgbToHsl:()=>s().rgbToHsl,sameDay:()=>s().sameDay,scrollIntoViewIfNeeded:()=>s().scrollIntoViewIfNeeded,setCss:()=>s().setCss,setInterval:()=>s().setInterval,setTimeout:()=>s().setTimeout,setUserAttr:()=>s().setUserAttr,shortTime:()=>s().shortTime,size:()=>s().size,sleep:()=>s().sleep,startsWith:()=>s().startsWith,stringify:()=>s().stringify,throttle:()=>s().throttle,tokenize:()=>s().tokenize,trim:()=>s().trim,trimStart:()=>s().trimStart,unicodeToAscii:()=>s().unicodeToAscii,unixSec:()=>s().unixSec,usersOfConvo:()=>s().usersOfConvo});var n=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(e){this.isOpen=!0===e,this.cbs=[]}open(){this.isOpen=!0;let e=[];this.cbs.forEach(t=>{this.isOpen?t():e.push(t)}),this.cbs=e}close(){this.isOpen=!1}entry(e,t){return this.isOpen?(t&&(this.isOpen=!1),e&&e(),Promise.resolve()):new Promise(i=>{this.cbs.push(()=>{t&&(this.isOpen=!1),e&&e(),i()})})}}}),o=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(){this.isOpen=!0,this.cbs=[]}_check(){if(!this.isOpen)return;let e=this.cbs.pop();e&&(this.isOpen=!1,e())}lock(){return new Promise(e=>{this.cbs.push(e),this._check()})}unlock(){this.isOpen||(this.isOpen=!0,this._check())}}}),a=i.cw(function(e,t){i.r(t),i.d(t,{get:()=>a,set:()=>c,take:()=>u});var s=Object.prototype.toString,r=Array.isArray||function(e){return"[object Array]"===s.call(e)};function n(e){var t=parseInt(e);return t.toString()===e?t:e}function o(e,t){if(function(e,t){return"number"==typeof t&&r(e)||function(e,t){return null!=e&&Object.prototype.hasOwnProperty.call(e,t)}(e,t)}(e,t))return e[t]}function a(e,t,i){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if(null==e)return i;if("string"==typeof t)return a(e,t.split("."),i);var s=n(t[0]),r=o(e,s);return void 0===r?i:1===t.length?r:a(e[s],t.slice(1),i)}function c(e,t,i){if("number"==typeof t&&(t=[t]),!t||0===t.length)return e;if("string"==typeof t)return c(e,t.split(".").map(n),i);var s=t[0],r=o(e,s);return 1===t.length?(e[s]=i,r):(void 0===r&&(e[s]="number"==typeof t[1]?[]:{}),c(e[s],t.slice(1),i))}function u(e,t=1){if(!Array.isArray(e))return[];let i=e.length;if("number"!=typeof i||i<=0)return[];if(t<=0)return[];let s=Math.min(t,i);return e.slice(0,s)}}),c=i.cw(function(e,t){i.d(t,{A:()=>s});class s{constructor(){this.listeners={}}publish(e,...t){const i=(this.listeners[e]||[]).slice();for(const e of i)e.obj._isMounted||e.unsubscribe(),e.active&&e.cb(...t)}on2(e,t,i){const s={obj:e,cb:i,active:!0};let r=()=>{};const n=()=>{s.active&&(s.active=!1,this.listeners[t]=(this.listeners[t]||[]).filter(e=>e!==s),this.listeners[t].length||delete this.listeners[t],r())};return s.unsubscribe=n,this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(s),"function"==typeof e.onDispose&&(r=e.onDispose(n)),n}clear(){for(const e of Object.values(this.listeners))for(const t of e.slice())t.unsubscribe()}}}),u={};i.r(u),i.d(u,{trackAreaClicked:()=>p,trackExitIntent:()=>h,trackInactivity:()=>f,trackScrollingPercentage:()=>d,trackTimeOnPage:()=>m}),s();var l=s();function h(e){let t=i=>{i.clientY>10||(e&&e(),document.removeEventListener("mouseout",t))};document.addEventListener("mouseout",t)}function d(e,t){let i=s=>{let r=s.srcElement.scrollingElement?s.srcElement.scrollingElement.scrollTop:s.srcElement.scrollTop,n=s.srcElement.scrollingElement?s.srcElement.scrollingElement.scrollHeight:s.srcElement.scrollHeight;r>0&&n>0&&(r+window.innerHeight)/n>=e&&(t&&t(),window.removeEventListener("scroll",i,!1))};window.addEventListener("scroll",i,!1)}function p(e,t){e&&(e=e||"",l.map(e.split("\n"),e=>{(e=l.trim(e))&&function(e,t,i){document.addEventListener("click",function(e){let s=document.querySelectorAll(t),r=e.target;for(let t=0,n=s.length;t<n;t++){let n=r,o=s[t];for(;n&&n!==document;){if(n===o)return i.call(o,e);n=n.parentNode}}})}(0,e,t)}))}function f(e=0,t){let i=["scroll","keyup","keydown","mousemove","mousewheel","mouseenter","mouseover","mousedown","touchstart","touchmove","touchenter"],s=0,r=()=>{s=0},n=l.setInterval(()=>{if(s++,!(s<e)){t&&t();for(let e of i)document.removeEventListener(e,r,!1);l.clearInterval(n)}},1e3);for(let e of i)document.addEventListener(e,r,!1)}let _=l.Date.now();function m(e=0,t){if(e<1)return l.setTimeout(function(){t(e)},100);let i=l.setInterval(()=>{let s=(l.Date.now()-_)/1e3;s<e||(t&&t(s),l.clearInterval(i))},200)}var g={};(g=Object.assign(g,r)).Gate=n().A,g.Mutex=o().A;var v=a();g.get=v.get,g.set=v.set,g.take=v.take,g.Pubsub=c().A;const y=g=Object.assign(g,u);function b(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const w=e();function k(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=y.stringify(i.body)),t(!0)}let x=0,S=(e,t)=>{if("undefined"==typeof sbz_info)return t(!0);let i=e.request;x++,i._id=x,sbz_info["ajax."+x]={created:y.Date.now(),method:i.method,baseurl:i.baseurl,query:i.query},t(!0)},C=(e,t)=>{if("undefined"==typeof sbz_info)return t(!0);let i=e.request._id;sbz_info["ajax."+i]||(sbz_info["ajax."+i]={created:0}),sbz_info["ajax."+i].out={duration:y.Date.now()-sbz_info["ajax."+i].created,code:e.code,err:e.err},t(!0)};const z=class{constructor(e,t){b(this,"listConversations",e=>this.apireq.addQuery("user_id",this.uid).addQuery("integration_id",`${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`)),b(this,"listMessages",(e,t,i)=>this.apireq.addQuery("limit",t).addQuery("start_id",i).get(`/accounts/${this.accid}/conversations/${e}/messages`)),b(this,"ajax",w),b(this,"start",(e,t,i,s)=>{let r=Object.assign({},e);return r.touchpoint||(r.touchpoint={}),r.touchpoint.channel||(r.touchpoint.channel="subiz"),r.touchpoint.source||(r.touchpoint.source="web"),r.source=y.get(document,"location.href"),this.apireq.post(`/accounts/${this.accid}/conversations`,r)}),b(this,"sendConvoEvent",(e,t)=>this.apireq.addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/conversations/${e}/events`,t)),b(this,"createPostback",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/postbacks`,t)),b(this,"markAsReceived",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/receive`)),b(this,"markAsSeen",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/seen`)),b(this,"getConversation",e=>this.apireq.get(`/accounts/${this.accid}/conversations/${e}`)),b(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/languages/${e}`)),b(this,"sendEvent",e=>this.apireq.addQuery("shorten",!0).addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,e)),b(this,"websiteFormRequest",()=>this.apireq.setBaseUrl(this.ApiURL.replace(/\/4\.[01]\/?$/,"/4.1"))),b(this,"submitWebsiteForm",(e,t)=>this.websiteFormRequest().post(`/accounts/${this.accid}/external-forms/${encodeURIComponent(e)}/submissions`,t)),b(this,"submitForm",(e,t,i,s,r)=>this.apireq.addQuery("x-referer",y.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,{by:{id:this.uid,device:i},type:"form_submitted",data:{user:r,form_submission:{user_id:this.uid,form_id:e,page_url:t,submitted_at:y.Date.now(),values:s}}})),b(this,"sendTyping",e=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/typing`)),b(this,"sendLostFocus",()=>this.apireq.post(`/accounts/${this.accid}/focuses/${this.uid}/delete`)),b(this,"uploadToS3",async e=>{let t=e.name.replace(/\s+/g,"_");var{body:i,error:s}=await this.apireq.setBaseUrl("https://api5.subiz.com.vn/4.1").setQuery({"account-id":this.accid,description:"upload\n user-client: web-widget",name:t,presign:!0,size:e.size,"content-type":e.type}).post("/files");if(s)return{body:i,error:s};let r=i.signed_url,n=i.id,o=await new Promise(t=>{const i=new y.XMLHttpRequest;i.open("PUT",r,!0),i.setRequestHeader("Content-Type",e.type||""),i.onload=function(){200===i.status?t():t(new Error(`Upload failed: ${i.statusText}`))},i.onerror=function(){t(new Error("Network error during upload."))},i.send(e)});if(o)return{error:o};var{body:i,error:s}=await this.apireq.setBaseUrl("https://api5.subiz.com.vn/4.1").setQuery({"account-id":this.accid}).post(`/files/${n}/uploaded`);return s?{error:s}:{url:y.get(i,"file.url","")}}),b(this,"uploadToS32",async e=>{var{body:t,error:i}=await w.setBaseUrl("https://api5.subiz.com.vn/4.1").withCredentials(!0).setQuery({"account-id":this.accid,description:"upload\n user-client: web-widget",name:e.name.replace(/\s+/g,"_"),size:e.size,type:e.type}).setParser("json").beforeHook((e,t)=>{if(this.token_generator){let i=this.profile_id;return void this.token_generator().then(s=>i!=this.profile_id?t(!0):s?"error"==s?t(!1):(e.request=e.request.addQuery("x-access-token",s),t(!0)):t(!1))}return this.ref?e.request=e.request.addQuery("x-user-ref",this.ref):this.mask&&(e.request=e.request.addQuery("x-user-mask",this.mask)),t(!0)}).post("/files",e);return i?{body:t,error:i}:{url:y.get(t,"file.url")}}),b(this,"time",e=>w.setBaseUrl(this.ApiURL).withCredentials(!0).setParser("json").get("/time")),b(this,"updateUser",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`,e)),b(this,"getUser",e=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`)),b(this,"getAccountSetting",async e=>{let t=y.get(document,"location.href"),i={};if(i=e&&e.bot_id?await this.apireq.addQuery("url",t).addQuery("bot_id",e.bot_id).get(`/accounts/${this.accid}/settings`):await this.apireq.addQuery("url",t).get(`/accounts/${this.accid}/settings`),i.error)return i;let s=y.get(i,"body.plugins")||[];return y.map(s,e=>{if("popup"===e.type){let t=y.get(e,"popup.pages")||[];y.map(t,e=>{y.map(e.components,e=>{if("image"===e.type){let t=y.get(e,"image.url");y.set(e,"image.url",function(e){try{const t=new URL(e),i="storage.googleapis.com"===t.hostname,s=t.pathname.startsWith("/public-gcs.subiz-cdn.com/");return i&&s?`https://${t.pathname.slice(1)}`:e}catch(t){return e}}(t))}})})}}),y.set(i,"body.plugins",s),i}),b(this,"sendImpression",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/impressions`,e)),b(this,"sendConversion",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/conversions`,e)),b(this,"lookupOrder",e=>w.setBaseUrl(this.ApiURL).setContentType("text/plain").beforeHook(k).setParser("json").addQuery("x-signed-key",e).get("/orders/123")),b(this,"getOrder",e=>this.apireq.get(`/accounts/${this.accid}/orders/`+e)),b(this,"updateOrder",e=>this.apireq.post(`/accounts/${this.accid}/orders/`+e.id,e)),b(this,"fetchShippingAddresses",()=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`)),b(this,"createShippingAddress",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`,e)),b(this,"list_provinces",()=>this.apireq.get(`/accounts/${this.accid}/provinces`)),b(this,"list_districts",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/districts`)),b(this,"list_wards",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/wards`)),b(this,"checkFormToken",(e,t)=>this.api41.addQuery("account-id",e).get(`/submissions/${t}`)),b(this,"submitForm2",(e,t,i)=>this.api41.addQuery("account-id",e).post(`/submissions/${t}`,i)),b(this,"suggest_address",e=>this.apireq.setQuery({keyword:e}).get(`/accounts/${this.accid}/addresses`)),b(this,"create_ticket",e=>this.apireq.post(`/accounts/${this.accid}/tickets`,e)),this.refreshLock=new y.Mutex,this.FileURL=t,this.ApiURL=e,this.api41=w.setBaseUrl("https://api.sbz.vn/4.1").withCredentials(!0).setContentType("text/plain").beforeHook(k).afterHook(C).beforeHook(S).setParser("json"),this.apireq=w.setBaseUrl(e).withCredentials(!0).addQuery("v","6").setContentType("text/plain").beforeHook(k).afterHook(C).setParser("json").beforeHook(S).beforeHook((e,t)=>{if(this.token_generator){let i=this.profile_id;return void this.token_generator().then(s=>i!=this.profile_id?t(!0):s?"error"==s?t(!1):(e.request=e.request.addQuery("x-access-token",s),t(!0)):t(!1))}return this.ref?e.request=e.request.addQuery("x-user-ref",this.ref):this.mask&&(e.request=e.request.addQuery("x-user-mask",this.mask)),t(!0)})}setAgentId(e){this.agentid=e}async setAuth(e){if(e.accid&&(this.accid=e.accid),e.ref&&(this.ref=e.ref),this.mask=e.mask,this.profile_id=e.profile_id,e.ref){let e;for(let t=0;e=await w.setBaseUrl(this.ApiURL).withCredentials(!0).afterHook(C).beforeHook(S).addQuery("v","6").addQuery("x-user-ref",this.ref).setParser("json").get(`/accounts/${this.accid}/users/${this.ref}`),-1==y.get(e,"body.error.code","").indexOf("locked_account");t++){if(-1==y.get(e,"body.error.code","").indexOf("user_is_banned")){if(!y.get(e,"body.id")){let e=Math.min(2e3+400*t,6e4);await y.sleep(e);continue}break}await y.sleep(12e4)}return e.error?y.get(e.body.code)?{error:e.body.code}:e:(this.uid=e.body.id,e.body)}if(e.tokenGenerator){let t=e.tokenGenerator;this.tokensession=this.tokensession||0,this.tokensession++;let i=this.tokensession;if(!this.accid||!y.startsWith(this.accid,"ac"))return{error:"invalid_account_id"};if(!this.profile_id)return{error:"invalid_profile_id"};if("function"!=typeof t)return{error:"invalid_token_generator"};let s,r=this.profile_id;this.token_generator=async e=>{if(await this.refreshLock.lock(),i!=this.tokensession)return void this.refreshLock.unlock();let s,n,o=(y.Date.now()-(this.last_token_at||0))/1e3;if(!e&&this.last_token&&o<1800)return this.refreshLock.unlock(),this.last_token;if(!e&&this.last_token&&o<3e3)return this.token_generator&&y.setTimeout(async()=>{let e,s;try{e=await t(r)}catch(e){s=e}i==this.tokensession?(this.last_token=s?"error":e,this.last_token_at=y.Date.now(),this.refreshLock.unlock()):this.refreshLock.unlock()}),this.last_token;try{s=await t(r)}catch(e){n=e}if(i==this.tokensession)return this.last_token=n?"error":s,this.last_token_at=y.Date.now(),this.refreshLock.unlock(),this.last_token;this.refreshLock.unlock()};for(let e=0;await this.token_generator(!0),i==this.tokensession;e++){if(s=await w.setBaseUrl(this.ApiURL).withCredentials(!0).addQuery("v","6").afterHook(C).beforeHook(S).addQuery("x-access-token",this.last_token).setParser("json").get(`/accounts/${this.accid}/users/${r}`),!y.get(s,"body.id")){let t=Math.min(2e3+100*e,12e4);await y.sleep(t);continue}break}return s.error?y.get(s.body.code)?{error:s.body.code}:s:(this.uid=s.body.id,s.body)}if(this.mask){let e=this.mask.split("@");return this.uid=e[1],{id:this.uid}}return{error:"invalid_auth"}}sendContentView(e,t,i,s,r,n){return s||(s=void 0),r||(r=void 0),this.sendEvent({by:{id:this.uid,device:e},type:"content_viewed",data:{product:{id:s,source_id:r,url:t,name:i,title:i,sku:n}}})}};let A=t(),T="undefined"!=typeof window?window.requestIdleCallback:null;T||(T=e=>e());const E=class{constructor(e,t){if(this.localStorage=A,this.inmem=t,this.allkeys={},!t)try{window.localStorage.setItem("sbzstore1029","?"),window.localStorage.removeItem("sbzstore1029"),this.localStorage=window.localStorage}catch(e){}this.schema=e}all(e){let t=[];for(var i=0;i<this.localStorage.length;i++){let s=this.localStorage.key(i);s.startsWith(this.schema+"#"+e+"#")&&(this.allkeys[s]=!0,this.inmem?t.push(this.localStorage.getItem(s)):t.push(y.parseJSON(this.localStorage.getItem(s))))}return t}removes(e,t){for(var i=0;i<t.length;i++)delete this.allkeys[this.schema+"#"+e+"#"+t[i]],this.localStorage.removeItem(this.schema+"#"+e+"#"+t[i])}clear(e){for(var t=[],i=0;i<this.localStorage.length;i++){let s=this.localStorage.key(i);s.startsWith(this.schema+"#"+e+"#")&&t.push(s)}for(i=0;i<t.length;i++)this.localStorage.removeItem(t[i]);this.allkeys={}}put(e,t,i){if(this.allkeys[this.schema+"#"+e+"#"+t]=!0,this.inmem)return this.localStorage.setItem(this.schema+"#"+e+"#"+t,i);Object.keys(this.allkeys).length>80&&this.clear(e),T(()=>{try{this.localStorage.setItem(this.schema+"#"+e+"#"+t,void 0===(s=i)?"null":y.stringify(s))}catch(t){this.clear(e)}var s})}};class P{constructor(e,t,i){this.schema=t+"_chain",this.dead=!1,this.db=e,this.anchorCache={},this.cache={},this.init()}init(){let e={};this.db.all("items").map(t=>{e[t.chain]=e[t.chain]||{},e[t.chain][t.id]={id:t.id,chain:t.chain,full_id:t.full_id,index:t.index,value:t.value}}),j(e,(t,i)=>{if(M(t)<50)return;let s=(r=j(t),n=["index"],o=[],j(r,e=>o.push(e)),o.sort((e,t)=>{if(e[n]===t[n])return 0;var i=e[n]<t[n]?-1:1;return-i}),o);var r,n,o;let a=[];for(var c=50;c<s.length;c++)a.push(s[c].full_id),delete t[s[c].id];this.db.removes("items",a),e[i]=t}),this.cache=e}destroy(){this.db.clear("items"),this.dead=!0,this.cache={},this.anchorCache={},this.db=void 0}put(e,t,i,s){if(this.dead)return;let r=this.cache[e]||{},n=(O(r)||{}).index||"z";0==M(r)&&(n="");let o={id:t,index:i,value:s,chain:e,full_id:e+":"+t};delete r[o.id],n>o.index+""||(r[o.id]=o,this.cache[e]=r,this.db.put("items",o.full_id,o))}listM(e){if(this.dead)return{};let t=this.cache[e]||{},i={};return j(t,(e,t)=>{i[t]=e.value}),i}async fetchMore(e,t=20,i){if(this.dead)return{error:"dead"};if(!i)return{error:"no api"};let s=this.anchorCache[e]||"";var[r,n,o]=await i(e,s,t);if(o)return{error:o};if(this.dead)return{error:"dead"};let a=this.cache[e]||{};return 0===r.length?{end:!0}:(r.forEach(t=>{t.chain=e,t.full_id=e+":"+t.id,a[t.id]=t,this.db.put("items",t.full_id,t)}),this.anchorCache[e]=n,this.cache[e]=a,{})}merge(e,t){if(this.dead)return;const i=this.cache[e]||{};for(const s of t){const t={...s,chain:e,full_id:e+":"+s.id};i[s.id]=t,this.db.put("items",t.full_id,t)}this.cache[e]=i}del(e,t){if(this.dead)return;let i=e+":"+t;delete(this.cache[e]||{})[t],this.db.removes("items",[i])}match(e,t){return this.listM(e)[t]}async reload(e,t){if(this.dead)return;let i=(function(e){if(!e)return;let t=Object.keys(e);if(!t.length)return;let i=-1/0,s=Object.keys(e)[0];for(var r=0;r<t.length;r++){let n=e[t[r]]&&e[t[r]].index||-1/0;n>i&&(i=n,s=t[r])}return e[s]}(this.cache[e]||{})||{}).index;i||(i=Date.now());for(var s="",r={};;){if(this.dead)return;let[n,o,a]=await t(e,s,50);if(a)return;if(this.dead)return;if(n.map(t=>{r[t.id]=Object.assign({},t,{chain:e,full_id:e+":"+t.id})}),0===n.length||o===s)break;if((O(r)||{}).index<=i){s=this.anchorCache[e]||o;break}if(M(r)>=200){let t=this.cache[e]||{},i=[];j(t,t=>{t.chain===e&&i.push(t.full_id)}),this.db.removes("items",i),this.cache[e]={},s=o;break}s=o}for(const e of Object.values(r))this.db.put("items",e.full_id,e),this.cache[e.chain]=this.cache[e.chain]||{},this.cache[e.chain][e.id]=e;this.anchorCache[e]=s}}function O(e){if(!e)return;let t=Object.keys(e);if(!t.length)return;let i=1/0,s=Object.keys(e)[0];for(var r=0;r<t.length;r++){let n=e[t[r]]&&e[t[r]].index||1/0;n<i&&(i=n,s=t[r])}return e[s]}function j(e,t){if(!e)return[];if(!t)return e;var i=[];if(Array.isArray(e)){for(let s=0;s<e.length;s++)i.push(t(e[s],s));return i}if("object"==typeof e){var s=Object.keys(e);for(let n=0;n<s.length;n++){var r=s[n];i.push(t(e[r],r))}return i}return i}function M(e){return e?void 0!==e.length?e.length:Object.keys(e).length:0}const I=class{constructor(e,t){this.name=t,t+="_kv",this.dead=!1,this.db=e,this.cache={},this.initialized=!1,this.init()}refreshCache(){if(this.dead)return;let e={};this.db.all("items").forEach(function(t){e[t.key]=t.value}),this.cache=e}init(){if(this.initialized)return;let e={};this.db.all("items").forEach(function(t){e[t.key]=t.value}),this.cache=e,this.trimCache(),this.initialized=!0}trimCache(){const e=Object.keys(this.cache);if(e.length<=500)return;const t=e.slice(0,e.length-Math.floor(250));for(const e of t)delete this.cache[e];this.db.removes("items",t)}all(){return this.dead?[]:this.initialized?this.cache:[]}match(e){if(!this.dead&&this.initialized&&e)return this.cache[e]}put(e,t){if(e){if(this.dead)return[];if(!this.initialized)throw new Error("uninitialized");this.cache[e]=t,this.db.put("items",e,{key:e,value:t}),this.trimCache()}}del(e){if(!this.dead){if(!this.initialized)throw new Error("uninitialized");delete this.cache[e],this.db.removes("items",[e])}}destroy(){this.db.clear("items"),this.dead=!0,this.db=void 0,this.cache=void 0,this.initialized=!1}};function L(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const R=e();function q(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=y.stringify(i.body)),t(!0)}const U=Promise.resolve({code:200}),F=class{constructor(e,t){L(this,"listConversations",e=>{let t=D(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:{anchor:"",conversations:[t]},code:200})}),L(this,"listMessages",(e,t,i)=>{let s=function(e,t,i,s){let r=e+".subizv4.subikon",n={type:"user",id:i,last_page_view_url:"https://subiz.com.vn/",conversation_id:t,membership:"active",invited_by:{id:i,type:"user"}},o={type:"agent",conversation_id:t,id:s,membership:"active",invited_by:{id:i,type:"user"}};return[{id:"evqyiyjmxrjsylftvnrghrfmq",account_id:e,created:1616213202264,type:"conversation_invited",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,members:[n],state:"pending"}}},{id:"evqyiyjmyqdgrouswczzawuzp",account_id:e,created:1616213202559,type:"conversation_invited",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,members:[o],state:"pending",source:"https://subiz.com.vn/vi/"}}},{id:"evqyiyjmyzjpyehnngvmcyauf",account_id:e,created:1616213202668,type:"conversation_state_updated",by:{id:i,type:"user"},data:{conversation:{id:t,account_id:e,state:"active"}}},{id:"evqyiyjmzaozvqgbkljbwywdl",account_id:e,created:1616213202683,type:"conversation_joined",by:{id:i,type:"user"},data:{conversation:{id:t,members:[n]}}},{id:"evqyiyjmzatvtgpdmmpzwnwgn",source_event_id:"wrueysyjbhqrkiwhsejpqrwqrdkkyaibajdw",account_id:e,created:1616213202685,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"Xin chào",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213203068}]}}},{id:"evqyiyjrhsfyuxtetszmvkkke",account_id:e,created:1616213237491,type:"conversation_joined",by:{id:i,type:"user"},data:{conversation:{id:t,members:[o]}}},{id:"evqyiyjrhtroknjyakrlrwhgr",account_id:e,created:1616213237508,type:"message_sent",by:{id:s,client_id:"dashboard",type:"agent"},data:{message:{conversation_id:t,text:"chào bạn, mình có thể giúp gì được cho bạn :grinning:",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"receive",created:1616213237742},{member_id:i,type:"seen",created:1616213240057}]}}},{id:"evqyiyjuvjinmclneroerxmrl",account_id:e,created:1616213265805,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"mình muốn hỏi giá sản phẩm IPhone X",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213267090}]}}},{id:"evqyiyjzjxzfcsexshcjbbnnf",account_id:e,created:1616213302432,type:"message_sent",by:{id:s,client_id:"dashboard",type:"agent"},data:{message:{conversation_id:t,text:"IPhone X hiện đang được bán tại cửa hàng với giá 12tr đồng nha bạn",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"receive",created:1616213302698},{member_id:i,type:"seen",created:1616213305071}]}}},{id:"evqyiykaoizbwnkaecwphttwk",account_id:e,created:1616213311830,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"ok cám ơn!",format:"plaintext",integration_id:r,pongs:[{member_id:i,type:"seen",created:1616213312110}]}}}]}(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:s,code:200})}),L(this,"ajax",R),L(this,"start",e=>U),L(this,"sendConvoEvent",(e,t)=>U),L(this,"createPostback",(e,t)=>U),L(this,"markAsReceived",(e,t)=>U),L(this,"markAsSeen",(e,t)=>U),L(this,"getConversation",e=>Promise.resolve({body:D(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid),code:200})),L(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/locales/${e}`)),L(this,"sendEvent",e=>U),L(this,"submitForm",(e,t,i,s,r)=>U),L(this,"sendTyping",e=>U),L(this,"sendPresence",e=>U),L(this,"sendContent",e=>U),L(this,"sendLostFocus",e=>U),L(this,"sendContentView",e=>U),L(this,"uploadToS3",async e=>U),L(this,"time",e=>Promise.resolve({code:200,body:(new y.Date).toISOString()})),L(this,"updateUser",e=>U),L(this,"getUser",e=>Promise.resolve({code:200,body:{id:"usqzgtgfake",attributes:[{key:"fullname",text:"Kiều Thanh"}]}})),L(this,"getAccountSetting",()=>this.apireq.get(`/accounts/${this.accid}/settings`)),L(this,"sendImpression",e=>U),L(this,"sendConversion",e=>U),this.FileURL=t,this.apireq=R.setBaseUrl(e).setContentType("text/plain").beforeHook(q).setParser("json")}setAgentId(e){this.agentid=e}setAuth(e){return this.accid=e.accid,this.mask=e.mask,this.uid=e.uid,{account_id:this.accid,id:"usqzgtgfake",attributes:[{key:"fullname",text:"Kiều Thanh"}]}}};function D(e,t,i,s){return{id:t,account_id:e,created:1610452894916,members:[{type:"user",id:i,membership:"active",invited_by:{id:i,type:"user"}},{type:"agent",id:s,conversation_id:t,membership:"active",invited_by:{id:i,type:"user"}}],ended:1610454875505,state:"ended",actived:1610453070259,last_message_sent:{id:"evqyiykaoizbwnkaecwphttwk",account_id:e,created:1616213311830,type:"message_sent",by:{id:i,client_id:"clsubizapi",type:"user"},data:{message:{conversation_id:t,text:"ok cám ơn!",format:"plaintext",integration_id:e+".subizv4.subikon",pongs:[{member_id:i,type:"seen",created:1616213312110}]}}},assigned_to:{},first_message:"Xin chào",subject:"Chúc một ngày tốt lành",source:"https://subiz.com.vn/"}}const $=class{onEvent(){}onInterrupted(){}subscribe(){}stop(){}getStatus(){return"active"}reconnect(){}};function W(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var N=i(8193),B=i(2839),V=i(5672);V.defaults.path="/",V.expiresMultiplier=86400,V.defaults.expires=3650;let H=t();const G=y.Date.now(),Q="chat_state_cycle_started_at",J=["lastview","light_convos","bot_run_logs","close_preview_at"];class X{constructor(e,t,i,s,r){if(W(this,"inmem",!1),W(this,"cookie",V),W(this,"getConnectionStatus",()=>this.connectionStatus),W(this,"_currentViewingProduct",{}),W(this,"new_visitor",!0),W(this,"matchUser",()=>{if(this.cache)return this._touchAcc(),this.cache.match("user")}),W(this,"suggest_addresses",e=>this.api.suggest_address(e)),W(this,"matchAccount",()=>this.cache.match("account")),W(this,"matchPaymentMethods",()=>this.cache.match("payment_methods")),W(this,"matchUnread",()=>{let e=this.matchUser();if(!e||!e.id)return;let t=this.matchConvo("*"),i=0;return y.map(t,t=>{y.isConvoSeen(t,e.id)||i++}),i}),W(this,"matchPlugin",()=>{if(this.is_embed_chat_mode){let e=this.cache.match("plugin");y.size(this.forcePlugins)>0&&(e=this.forcePlugins);let t=y.filter(e,(e,t)=>e&&"chatbox"===e.type);if(0===y.size(t))return void console.error("no chatbox found.");let i=y.find(t,e=>!!e);return i||(i=t[0]),i=y.cloneDeep(i),i.triggers=void 0,{[i.id]:i}}return y.size(this.forcePlugins)>0?y.cloneDeep(this.forcePlugins):y.cloneDeep(this.cache.match("plugin"))||{}}),W(this,"device",{}),W(this,"browserVisibility","visible"),W(this,"matchAgent",e=>{let t=this.cache.match("agent")||{};return"*"===e?t:t[e]}),W(this,"matchConvo",e=>{if(e)return"*"===e?(this._touchAcc(),y.filter(this.cache.all(),(e,t)=>t.startsWith("convo_")).concat(y.map(this.lightConvos))):e.startsWith("cslight")?this.lightConvos[e]:(this.isInsync(e)||this.fetchConvo(e),this.cache.match("convo_"+e))}),W(this,"fetchConvo",async e=>{if(e&&!e.startsWith("cslight")){if(this._die)return se;await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die||this.isInsync(e))return;if(this.convoFetchAfter=this.convoFetchAfter||{},y.Date.now()<(this.convoFetchAfter[e]||0))return;this.convoFetchAfter[e]=y.Date.now()+15e3;let{body:t,error:i}=await this.api.getConversation(e);t&&!i&&this._setConvo(t)}catch(e){return{error:e}}finally{this.reconnectGate.open()}}}),W(this,"list_provinces",()=>this.api.list_provinces()),W(this,"list_districts",e=>this.api.list_districts(e)),W(this,"list_wards",e=>this.api.list_wards(e)),W(this,"outofmsgM",{}),W(this,"listEvents",e=>{if(e&&"*"!==e&&"string"==typeof e)return e.startsWith("cslight")?y.get(this.lightConvos,[e,"events"],[]):this.chain.listM(e)}),W(this,"fetchMoreEvents",(e,t=150)=>{if(this.historyRequests=this.historyRequests||new Map,this.historyRequests.has(e))return this.historyRequests.get(e);this.historyFailures=this.historyFailures||{};const i=this.historyFailures[e];if(i&&y.Date.now()<i.retryAt)return Promise.resolve({error:i.error});const s=this._fetchMoreEvents(e,t).then(t=>(t.error?this.historyFailures[e]={error:t.error,retryAt:y.Date.now()+15e3}:delete this.historyFailures[e],t)).finally(()=>{this.historyRequests.get(e)===s&&this.historyRequests.delete(e)});return this.historyRequests.set(e,s),s}),W(this,"syncConvoEvents",e=>{if(this._die||!e||e.startsWith("cslight"))return Promise.resolve({});if(this.messageSyncRequests=this.messageSyncRequests||new Map,this.messageSyncRequests.has(e))return this.messageSyncRequests.get(e);if(this.messageSyncNextAt=this.messageSyncNextAt||{},y.Date.now()<(this.messageSyncNextAt[e]||0))return Promise.resolve({skipped:!0});const t=this.chain,i=this._syncConvoEvents(e,t).then(i=>{if(t===this.chain&&!this._die){this.messageSyncFailures=this.messageSyncFailures||{};const t=i.error?Math.min((this.messageSyncFailures[e]||0)+1,4):0;this.messageSyncFailures[e]=t,this.messageSyncNextAt[e]=y.Date.now()+(t?15e3*2**(t-1):15e3)}return i}).finally(()=>{this.messageSyncRequests.get(e)===i&&this.messageSyncRequests.delete(e)});return this.messageSyncRequests.set(e,i),i}),W(this,"reloadConvoEvents",async e=>{await this.chain.reload(e,()=>[[],""]);let{error:t}=await this.chain.fetchMore(e,150,async(t,i,s)=>{let[r,n,o,a]=await this.listmessageapi(t,i,s);return a&&(this.outofmsgM[e]=!0),[r,n,o]});return{error:t}}),W(this,"_doFetchMsg",async(e,t=150)=>{let{error:i}=await this.chain.fetchMore(e,t,async(t,i,s)=>{if(this.outofmsgM[e])return[[],""];let[r,n,o,a]=await this.listmessageapi(t,i,s);return a&&(this.outofmsgM[e]=!0),[r,n,o]});return this.pubsub.publish("account"),{error:i}}),W(this,"matchLocation",()=>this.cache.match("location")||{}),W(this,"matchBot",()=>this.cache.match("bot")||{}),W(this,"readyGate",new y.Gate),W(this,"convoGate",new y.Gate(!0)),W(this,"reconnectGate",new y.Gate(!0)),W(this,"wsGate",new y.Gate(!0)),W(this,"matchLastview",()=>this.kv.match("lastview")||{}),W(this,"matchIsOpen",()=>!!this.kv.match("isopen")),W(this,"matchClosePreviewAt",()=>this.kv.match("close_preview_at")||0),W(this,"checkFormToken",(e,t)=>this.api.checkFormToken(e,t)),W(this,"submitForm2",(e,t,i)=>this.api.submitForm2(e,t,i)),W(this,"sendPresence",y.throttle(async()=>{if(this._track_page_view){if(this._die)return se;if(await this.readyGate.entry(),y.get(this.cache.match("user"),"id")&&!y.isUserBanned(this.cache.match("user")))return"visible"===this.browserVisibility&&document.hasFocus()?void this.sendPageview():this.api.sendLostFocus()}},1e3,{leading:!1})),W(this,"now",()=>y.Date.now()+this.timeDiff),W(this,"seenQueue",[]),W(this,"matchTrafficSource",()=>this.kv.match("traffic_source")),W(this,"_alreadyReceived",{}),W(this,"_typing",y.throttle(e=>this.api.sendTyping(e),3e3,{trailing:!1})),W(this,"onConvoEvent",(e,t)=>this.pubsub.on2(e,"events",t)),W(this,"onWidgetClose",(e,t)=>this.pubsub.on2(e,"sbz_close_widget",t)),W(this,"onMessageUpdated",(e,t)=>this.pubsub.on2(e,"message_updated",t)),W(this,"seenConvo",e=>{e&&"create"!==e&&this.seenQueue.push(e)}),W(this,"onUpdate",(e,t)=>this.pubsub.on2(e,"account",t)),W(this,"onDestroyed",(e,t)=>this.pubsub.on2(e,"destroy",t)),W(this,"onConnection",(e,t)=>this.pubsub.on2(e,"connection",t)),W(this,"onResetCSS",(e,t)=>this.pubsub.on2(e,"resetCSS",t)),W(this,"onHighlight",(e,t)=>this.pubsub.on2(e,"highlight",t)),W(this,"closePreview",()=>this.kv.put("close_preview_at",(new y.Date).getTime())),W(this,"updateLastview",e=>{let t=this.cache.match("user")||{};if(!t.id)return;let i=this.matchLastview()||{},s={...i,...e,user_id:t.id};this.kv.put("lastview",s),this.pubsub.publish("lastview",s,i)}),W(this,"onLastview",(e,t)=>this.pubsub.on2(e,"lastview",t)),W(this,"timeDiff",0),this.connectionStatus="active",this.CONNECTION_CHECK_INTERVAL=3e3,this.reconnectTimestamp=0,this.g_sync={},this._die=!1,this.forceDevice=null,this.forcePlugins={},this.forceAcc={},this.forceChatbox={},this.RealtimeURL=i,this.fake=r,this.FileURL=t,this._track_page_view=!0,this.device_type="desktop",this.fake?this.api=new F(e,t):this.api=new z(e,t),!s)try{document.cookie,localStorage}catch(e){s=!0}s&&(this.inmem=s,this.cookie=K),ee(),this.pubsub=new y.Pubsub,this.kv=new I(new E("sbz2023",this.inmem),"kv"),this.cache=new I(new E("sbz2023",!0),"kv"),this.chain=new P(new E("cbz2023",!0),"ch"),this.getLocaleContent=this.api.getLocaleContent,this.g_haveSentSeenM={},this.last_focused=this.now(),this._onBlur=()=>{this._die||(this.last_focused=this.now(),this.sendPresence())},this._onFocus=()=>{this._die||(this.last_focused=0,this.sendPresence())},this._onBeforeUnload=()=>{this._die||this.api.sendLostFocus()},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),window.addEventListener("beforeunload",this._onBeforeUnload),this._lastPresenceURL=window.location.href,this._urlCheckInterval=y.setInterval(()=>{if(this._die)return y.clearInterval(this._urlCheckInterval);this._lastPresenceURL!==window.location.href&&(this._lastPresenceURL=window.location.href,this.sendPresence())},2e3),this.doNotStartBot=()=>{this._donotstartbot=!0},this.autoStartBot=()=>{this._donotstartbot=!1},this.matchAutoStartBot=()=>!this._donotstartbot,this._presenceInterval1=y.setInterval(()=>{if(this._die)return y.clearInterval(this._presenceInterval1);"visible"===this.browserVisibility&&document.hasFocus()&&this.sendPresence()},2e4),this._presenceInterval2=y.setInterval(()=>{if(this._die)return y.clearInterval(this._presenceInterval2);"visible"===this.browserVisibility&&document.hasFocus()||this.last_focused&&this.now()-this.last_focused>18e5||this.sendPresence()},6e4),this._visibilityCleanup=function(e){var t="hidden";let i,s=document,r={};if(t in document)i="visibilitychange";else if((t="mozHidden")in document)i="mozvisibilitychange";else if((t="webkitHidden")in document)i="webkitvisibilitychange";else if((t="msHidden")in document)i="msvisibilitychange";else if("onfocusin"in document)r={onfocusin:document.onfocusin,onfocusout:document.onfocusout},document.onfocusin=document.onfocusout=n;else{s=window;for(const e of["onpageshow","onpagehide","onfocus","onblur"])r[e]=window[e],window[e]=n}function n(i){var s="visible",r="hidden",n={focus:s,focusin:s,pageshow:s,blur:r,focusout:r,pagehide:r};(i=i||window.event).type in n?e(n[i.type]):e(this[t]?"hidden":"visible")}return i&&s.addEventListener(i,n),void 0!==document[t]&&n({type:document[t]?"blur":"focus"}),()=>{i&&s.removeEventListener(i,n);for(const e of Object.keys(r))s[e]===n&&(s[e]=r[e])}}(e=>{this._die||(this.browserVisibility=e,this.sendPresence())}),this.loopTime(),this.device=this.getDeviceInfo(),this._gaInterval=y.setInterval(()=>{if(this._die)return;let e=this.cache.match("user")||{};if(!e.id)return;var t=this.getDeviceInfo();if(!t.ga_tracking_ids||!t.ga_client_id)return;y.clearInterval(this._gaInterval),this.device=t;let i=t.ga_client_id;i!==y.getUserAttr(e,"ga_client_id","text")&&this.setUser({attributes:[{type:"text",text:i,key:"ga_client_id"}]})},2e3),this.loopCheckConnectionStatus()}async loopCheckConnectionStatus(){for(;!this._die;){if(await y.sleep(this.CONNECTION_CHECK_INTERVAL),!this.realtime)continue;if(!this.realtime.getStatus||!this.realtime.reconnect)continue;this.connectionStatus;let e=this.connectionStatus;this.connectionStatus=this.realtime.getStatus(),e!==this.connectionStatus&&(console.log("publish connectionStatus",this.connectionStatus),this.pubsub.publish("connection")),"active"!==this.connectionStatus||!this._needsMessageSync&&"active"===e||(this._needsMessageSync=!1,this.syncKnownConvoEvents())}}syncKnownConvoEvents(){if(this._die)return Promise.resolve();if(this.knownConvoSyncRequest)return this.knownConvoSyncRequest;const e=this.chain,t=(async()=>{const t=y.filter(this.cache.all(),(e,t)=>t.startsWith("convo_"));for(const i of t){if(this._die||e!==this.chain)break;await this.syncConvoEvents(i.id)}})().finally(()=>{this.knownConvoSyncRequest===t&&(this.knownConvoSyncRequest=null)});return this.knownConvoSyncRequest=t,t}linkProduct(e){e?(e.id&&(this._currentViewingProduct.id=(e.id+"").trim()),e.source_id&&(this._currentViewingProduct.source_id=(e.source_id+"").trim()),e.sku&&(this._currentViewingProduct.sku=(e.sku+"").trim())):this._currentViewingProduct={}}getTrackPageview(){return this._track_page_view}setTrackPageview(e){this._track_page_view=!!e}getLinkedProduct(){return y.cloneDeep(this._currentViewingProduct)}isInsync(e){return y.Date.now()-(this.g_sync[e]||0)<6e5}async fetchShippingAddresses(){let e=await this.api.fetchShippingAddresses();if(e.error)return null;this.cache.put("shipping_address",e.body.shipping_addresses)}matchShippingAddresses(){return this.cache.match("shipping_address")}updateOrder(e){return this.api.updateOrder(e)}createShippingAddress(e){return this.api.createShippingAddress(e)}createTicket(e){return this.api.create_ticket(e)}overrideWelcomeMessage(e){y.map(this.lightConvos,(t,i)=>{t.last_message_sent&&(t.last_message_sent.data.message=e,t.last_message_sent.data.message.conversation_id=i);let s=y.get(t.events,"0");s.data.message=e,s.data.message.conversation_id=i,this.pubsub.publish("events",s)})}async overrideAcc(e){this.forceAcc=y.cloneDeep(e),await this.readyGate.entry(),this.reconnect()}async overrideBotId(e){this.forceBotId=e,await this.readyGate.entry()}async overrideChatbox(e){this.forceChatbox=e,await this.readyGate.entry(),await this.reconnect(),y.setTimeout(this.pubsub.publish("resetCSS"),10)}onShowMessageInfo(e){this.pubsub.publish("events",{type:"show_event_info",id:e})}getDeviceInfo(){let e={screen_resolution:window.screen.width+"x"+window.screen.height,source_referrer:document.referrer,platform:window.navigator.platform,language:navigator.language,page_url:document.URL,page_title:document.title},t=function(){if(!window.ga)return;if(!window.ga.getAll)return;var e=window.ga.getAll()||[];let t="";return e.forEach(function(e){t=e.get("clientId")}),t}();t&&(e.ga_client_id=t);let i=(s=[],window.ga&&window.ga.getAll?window.ga&&window.ga.getAll?((window.ga.getAll()||[]).forEach(function(e){var t=e.get("trackingId");t&&s.push(t)}),s):[]:s);var s;return i.length>0&&(e.ga_tracking_ids=i),e}highlight(e,t){this.pubsub.publish("highlight",e,t)}emitConvoEvent(e){this.pubsub.publish("events",e)}setAIDevMode(e){this.ai_dev_mode=e}setEmbebedChatMode(){this.is_embed_chat_mode=!0}isAIDevMode(){return this.ai_dev_mode}isEmbededChatMode(){return this.is_embed_chat_mode}overrideDeviceType(e){this.forceDevice=e,this.pubsub.publish("account")}isMobile(){return this.forceDevice?"mobile"===this.forceDevice:"mobile"==this.device_type||y.get(window,"screen.width",1e3)<576}isTablet(){return this.forceDevice?"tablet"===this.forceDevice:"tablet"==this.device_type}isDesktop(){return this.forceDevice?"desktop"===this.forceDevice:!this.isMobile()&&!this.isTable()}disconnect(e){this.g_sync[e]=0}pageLoaded(){return G}overridePlugin(e){if(this._die)return se;if(!Array.isArray(e))throw"plugins must be be an array";let t={};y.map(e,function(e){t[e.id]=e}),this.forcePlugins=t,this.pubsub.publish("account"),this.pubsub.publish("resetCSS")}markSync(e){this.g_sync[e]=y.Date.now()}async _touchAcc(){this.isInsync("account")||(await this.readyGate.entry(),this.isInsync("account")||this.refreshAccount())}refreshAccount(){if(!(this._die||y.Date.now()<(this.accountRefreshAfter||0)))return this.accountRefreshAfter=y.Date.now()+3e4,this.reconnect()}async _fetchMoreEvents(e,t=150){if(!e||e.startsWith("cslight"))return{};await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die)return se;!this.isInsync("events"+e)&&(this.chain.anchorCache[e]="",delete this.outofmsgM[e]);const i=await this._doFetchMsg(e,t);return i.error||this.markSync("events"+e),i}catch(e){return{error:e}}finally{this.reconnectGate.open()}}async _syncConvoEvents(e,t){await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0);try{if(this._die||t!==this.chain)return se;this.messageSyncTimes=this.messageSyncTimes||{},this.messageSyncProgress=this.messageSyncProgress||{};let i=this.messageSyncProgress[e];if(!i){const s=Object.values(t.listM(e)),r=this.messageSyncTimes[e]||s.reduce((e,t)=>Math.min(e,y.getMs(t.created)),1/0);i=this.messageSyncProgress[e]={boundary:r,anchor:"",newest:0,visited:new Set}}for(let s=0;s<5;s++){const s=(this.nextMessageSyncRequestAt||0)-y.Date.now();if(s>0&&await y.sleep(s),this._die||t!==this.chain)return se;this.nextMessageSyncRequestAt=y.Date.now()+250;const[r,n,o,a]=await this.listmessageapi(e,i.anchor,150);if(this._die||t!==this.chain)return se;if(o)return{error:o};t.merge(e,r);for(const e of r)i.newest=Math.max(i.newest,e.index);if(this.pubsub.publish("account"),a||!r.length||r.some(e=>e.index<i.boundary))return i.newest&&(this.messageSyncTimes[e]=i.newest),delete this.messageSyncProgress[e],{};if(i.visited.add(i.anchor),!n||i.visited.has(n))return delete this.messageSyncProgress[e],{error:"message_cursor_stalled"};i.anchor=n}return{pending:!0}}catch(e){return{error:e}}finally{this.reconnectGate.open()}}async init(e,t,i,s){if(this.g_sync={},"undefined"!=typeof sbz_info&&(sbz_info.store_0=!0),s&&s.use_subdomain_cookie||window&&window.location&&window.location.hostname&&(V.defaults.domain="."+window.location.hostname),"undefined"!=typeof sbz_info&&(sbz_info.store_1=!0),!i){try{i=this.cookie.get("__sbref","")}catch(e){}if("undefined"!=typeof sbz_info&&(sbz_info.store_2=!0),!i){if(!t)try{t=this.cookie.get("__sbmask","")}catch(e){}t?(t.split("@")[0]!=e&&(i=y.randomString(40),this.new_visitor=!0),this.new_visitor=!1,this.cookie.set("__sbmask",t)):(i=y.randomString(40),this.new_visitor=!0)}}return"undefined"!=typeof sbz_info&&(sbz_info.store_3=!0),this.cookie.get("__sbref",i)!=i&&(te(),this.clearBrowserData()),"undefined"!=typeof sbz_info&&(sbz_info.store_4=!0),this.api.setAuth({accid:e}),"undefined"!=typeof sbz_info&&(sbz_info.store_5=!0),i&&this.cookie.set("__sbref",i),"undefined"!=typeof sbz_info&&(sbz_info.store_6=!0),this._initResource(e,{accid:e,mask:t,ref:i},{account_id:e,user_ref:i,user_mask:t})}standardlizeLastview(){let e=this.kv.match("lastview")||{},t=this.cache.match("user")||{};if(t.id||(e={}),e.user_id!=t.id&&(e={}),e.screen||(e.screen="preview","list"!==e.view&&"chat"!==e.view||(e.screen="widget")),this.isMobile()){e.screen="preview";let t=this.matchPlugin()||{},i=y.find(t,e=>"chatbox"===e.type)||{};y.get(i,"chatbox.greeting.mobile_disabled")&&(e.screen="button")}this.kv.put("lastview",e)}resetChatStateIfExpired(){const e=this.now(),t=this.kv.match(Q);return!Number.isFinite(t)||t<=0||t>e?(this.kv.put(Q,e),!1):!(e-t<864e5||(y.map(J,e=>this.kv.del(e)),this.kv.put(Q,e),0))}async _initResource(e,t,i){this.g_sync={};let s=await this.api.setAuth(t);if("undefined"!=typeof sbz_info&&(sbz_info.store_7=!0),s.error)return console.error(s),s;this.readyGate.close(),e=(e||"").trim(),this.resetChatStateIfExpired();let r=this.kv.match("light_convos")||{};return this.lightConvos={},y.map(r,t=>{if("widget"===t.light_type&&(t.account_id!==e||t.initial_by!==s.id))return;let i=t.created>y.Date.now()-6048e5,r=y.filter(t.events,e=>"message_sent"===e.type),n=y.map(r,e=>y.get(e,"data.message")||{});n=y.filter(n,e=>!y.isEmptyMessage(e)),i&&y.size(n)&&(this.lightConvos[t.id]=t)}),this.cache=new I(new E("sbz2023",!0),"kv"),this.realtime&&this.realtime.stop(),this.fake?this.realtime=new $:this.realtime=new B(this.RealtimeURL,i,ie,e),this.realtime.onEvent(this.onWs.bind(this)),this.realtime.onInterrupted(async()=>{this._die||(this._needsMessageSync=!0,await this.reconnectWs(e,s.id),await this.refreshAccount())}),"undefined"!=typeof sbz_info&&(sbz_info.store_8=!0),this.seenLoop(),"undefined"!=typeof sbz_info&&(sbz_info.store_9=!0),await this.reconnect({user:s}),this.standardlizeLastview(),"undefined"!=typeof sbz_info&&(sbz_info.store_10=!0),this.readyGate.open(),this.reconnectWs(e,s.id),s}async login(e,t,i){return this._die?se:(te(),this.clearBrowserData(),this.new_visitor=!1,this._initResource(e,{accid:e,profile_id:t,tokenGenerator:i},{getAccessToken:()=>this.api.token_generator()}))}logout(e){return this.api.setAuth({ref:e})}seenLoop(){this.seenQueue=[],y.clearInterval(this._seenInterval),this._seenInterval=y.setInterval(()=>{if(this._die)return y.clearInterval(this._seenInterval);if(!this.cache)return;this.seenQueue=[...new Set(this.seenQueue)];let e=this.cache.match("user")||{};y.map(this.seenQueue,t=>{var i=this.listEvents(t);if(!i)return;if(0===y.size(i))return;var s=(i=y.filter(i,e=>"message_sent"===e.type))[y.size(i)-1];if(!s)return;if(this.g_haveSentSeenM[s.id])return;if(s.id===s.source_event_id)return;if(this.pubsub.publish("events",{created:this.now(),type:"message_pong",by:{type:"user"},data:{message:{conversation_id:t,id:"*",pongs:[{type:"seen",created:this.now()}]}}}),t.startsWith("cslight")){let e=this.lightConvos[t],i=this.matchUser();if(!e)return;let r=y.find(e.members,e=>"user"==e.type&&e.id==i.id);return r&&(r.seen_at=this.now()),this.kv.put("light_convos",this.lightConvos),void(this.g_haveSentSeenM[s.id]=!0)}this.api.markAsSeen(t,s.id);let r=this.cache.match("convo_"+t)||{},n=y.find(r.members,t=>t.id===e.id);n&&(n.seen_at=this.now()),this._setConvo(r),this.g_haveSentSeenM[s.id]=!0}),this.seenQueue=[]},1e3)}async reconnectWs(e,t){await this.realtime.subscribe([`conversation_state_updated.account.${e}.user.${t}`,`conversation_joined.account.${e}.user.${t}`,`conversation_typing.account.${e}.user.${t}`,`message_sent.account.${e}.user.${t}`,`message_pong.account.${e}.user.${t}`,`conversation_rating_requested.account.${e}.user.${t}`,`conversation_rated.account.${e}.user.${t}`,`conversation_events.account.${e}.user.${t}`]),await this.readyGate.entry()}reconnect(e){if(this.reconnectRequest)return this.reconnectRequest;const t=this._reconnect(e).finally(()=>{this.reconnectRequest===t&&(this.reconnectRequest=null)});return this.reconnectRequest=t,t}async _reconnect(e){if(!this._die){await this.reconnectGate.entry(void 0,!0);try{let t=e&&e.user?Promise.resolve({body:e.user}):this.api.getUser(),i=await Promise.all([t,this.api.getAccountSetting({bot_id:this.forceBotId})]),s=y.find(i,e=>e.error);if(s)return s;let r=i[1].body;r.user=i[0].body,await this._setSetting(r);let n=await this.api.listConversations();s=n.error;let o=n.body;if(!s){let e=y.get(o,"conversations",[]);y.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&this.now()-y.getMs(y.get(e,"actived"))>12096e5&&this.cache.del(t)}),y.map(e,e=>this._setConvo(e))}if(s)return{error:s};this.markSync("account")}catch(e){return{error:e}}finally{this.reconnectGate.open()}}}async submitWebsiteForm(e,t){await this.readyGate.entry();const i=re(this.api,e),s=this.kv,r=y.cloneDeep(t.values),n=function(e){const t=e&&e.body,i=e&&e.error||t&&t.error,s=e&&e.code,r=t&&"string"==typeof t.conversation_id&&t.conversation_id&&"string"==typeof t.submission_id&&t.submission_id;if(i||!(s>=200&&s<300)||!r){const e=new Error("Subiz form request failed");throw e.code=i&&i.code||"form_request_failed",e.status=s,e}return t}(await this.api.submitWebsiteForm(e,t));try{s.put(i,{conversation_id:n.conversation_id,values:r,expires_at:y.Date.now()+6048e5})}catch(e){}return n}getFormStatus(e){const t=re(this.api,e);try{const e=this.kv.match(t);return e?Number.isFinite(e.expires_at)&&"string"==typeof e.conversation_id&&e.conversation_id?e.expires_at<=y.Date.now()?(this.kv.del(t),{submitted:!1,status:"expired"}):{submitted:!0,status:"found",conversation_id:e.conversation_id,values:Array.isArray(e.values)?y.cloneDeep(e.values):[]}:(this.kv.del(t),{submitted:!1,status:"not_found"}):{submitted:!1,status:"not_found"}}catch(e){return{submitted:!1,status:"storage_unavailable"}}}async submitForm(e,t,i){return await this.readyGate.entry(),i&&await this.setUser(i),this.api.submitForm(e,document.URL,this.device,t,i)}async setUser(e){if(e)return await this.readyGate.entry(),this._setUser(e),this.api.updateUser(e)}async setUserDiff(e){if(!e)return;await this.readyGate.entry();let t=await this.api.updateUser(e);t&&200==t.code&&t.body.id&&this._setUser(t.body)}_setUser(e){e=y.cloneDeep(e);let t=this.cache.match("user")||{};var i=t.account_id||e.account_id,s=t.id||e.id;y.each(e.attributes,e=>{e&&(t.attributes=y.filter(t.attributes,t=>!!t&&t.key!==e.key))}),t.attributes=t.attributes||[],t.attributes=t.attributes.concat(e.attributes),t.account_id=i,t.id=s,this.cache.put("user",t),this.pubsub.publish("account")}async setSetting(e){if(e)return await this.readyGate.entry(),this._setSetting(e)}async _setSetting(e){(e=y.cloneDeep(e)||{}).account=Object.assign({},e.account,this.forceAcc),e.account.logo_url||(e.account.logo_url="https://vcdn.subiz-cdn.com/widget-v4/public/assets/img/default_logo.dd13a2b.svg"),e.user&&(e.user.account_id=e.account.id,delete e.user.session,this._setUser(e.user)),e.account&&(e.account.is_online=e.is_online,e.account.is_in_business_hour=e.is_in_business_hour,this.cache.put("account",e.account),delete e.account);let t=y.get(e,"location",[]);this.cache.put("location",t);let i=y.get(e,"bots",[]),s={};y.map(i,e=>{s[e.id]=e}),this.cache.put("bot",s),this.device_type=e.device_type||"desktop";let r=y.get(e,"plugins",[]),n={};y.map(r,e=>{"chatbox"===e.type&&(e=y.merge(e,this.forceChatbox)),n[e.id]=e}),this.cache.put("plugin",n);var o=y.get(e,"agents",[]);if(y.size(o)>0){let e={};this.api.setAgentId(o[0].id),y.map(o,t=>{e[t.id]=t}),this.cache.put("agent",e)}let a=y.get(e,"payment_methods",[]);this.cache.put("payment_methods",a),this.pubsub.publish("account")}async sendPageview(e){e||(e={});let t=Object.assign({},this.device);return e.referrer&&(t.source_referrer=e.referrer),t.page_url=e.url||location.href,t.page_title=e.title||document.title,this.api.sendContentView(t,e.url||location.href,e.title||document.title,this._currentViewingProduct.id,this._currentViewingProduct.source_id,this._currentViewingProduct.sku)}async track(e){if(!e){let e=await this.sendPageview(),t=y.get(e,"body.by.device.source","");return t&&this.kv.put("traffic_source",t),e}return"object"==typeof e&&(e.data||(e.data={})),this.api.sendEvent(e)}async onWs(e){await this.wsGate.entry(void 0,!0);try{await this._onWs(e)}catch(e){return console.error(e),{error:e}}finally{this.wsGate.open()}}async _onWs(e){if(this._die)return;if(!e||!e.type)return;if("form"===y.get(e,"touchpoint.channel")||"form"===y.get(e,"data.conversation.touchpoint.channel"))return;if(e.created=y.getMs(e.created),"user_info_updated"===e.type)return;if("message_deleted"===e.type)return void this.pubsub.publish("message_updated",e);let t,i=this.cache.match("user")||{},s=y.convoOfEv(e),r=!1;if(s&&!s.startsWith("cslight")&&(t=this.cache.match("convo_"+s),!t||!t.id)){let{body:e,error:i}=await this.api.getConversation(s);if(!e)return;t=e,r=!0,this._setConvo(t)}if(s&&s.startsWith("cslight")){if(t=this.lightConvos[s],!t)return;return t.events.push(e),t.last_message_sent=e,this.kv.put("light_convos",this.lightConvos),void this.pubsub.publish("events",e)}if(t){if(this.pubsub.publish("events",e),"conversation_joined"===e.type){let i=y.get(e,"data.conversation.members",[]);if(y.find(i,e=>e.id===this.cache.match("user").id)&&!r){let{body:e}=await this.api.getConversation(s);e&&(t=e,this._setConvo(t)),this.pubsub.publish("account")}}return"message_sent"===e.type&&y.get(e,"by.id")!==i.id&&(this._alreadyReceived[e.id]||(this._alreadyReceived[e.id]=!0,this.api.markAsReceived(s,e.id))),y.startsWith(e.type,"message_")||y.startsWith(e.type,"conversation_")?(await this.restConvoEvent(e),void("message_sent"===e.type&&y.get(e,"by.id")!==i.id&&Y("SUBIZ Chat","Received","User"))):void 0}}async restConvoEvent(e){let t=this.cache.match("user"),i=y.convoOfEv(e),s=this.cache.match("convo_"+i)||{};if("conversation_state_updated"===e.type){if(!y.get(s,"id")){let{body:e,error:t}=await this.api.getConversation(i);if(t)return}s=Object.assign(s,y.get(e,"data.conversation"))}if("message_pong"===e.type){var r=y.get(e,"data.message.id"),n=this.chain.match(i,r);if(!y.get(n,"data.message"))return;var o=y.get(n,"data.message.pongs",[]);let a=y.get(e,"data.message.pongs",[])||[];if(o=o.concat(a),1===a.length){let e=a[0].type;"like"!==e&&"remove_dislike"!==e||(o=o.filter(e=>"dislike"!==e.type)),"dislike"!==e&&"remove_like"!==e||(o=o.filter(e=>"like"!==e.type))}n.data.message.pongs=o,y.map(o,e=>{if(e.member_id==t.id&&"seen"===e.type){let i=y.find(s.members,e=>e.id===t.id);i&&(i.seen_at=e.created)}}),this.chain.put(i,n.id,y.getMs(n.created),n),this.pubsub.publish("events",n)}if("message_pong"!==e.type&&"conversation_typing"!==e.type){if("message_sent"===e.type){let t=y.get(e,"source_event_id"),r=y.find(this.listEvents(i),e=>e.id===t);r&&(this.chain.del(i,r.id),e.created=r.created),s.last_message_sent=e}this.chain.put(i,e.id,y.getMs(e.created),e)}this._setConvo(s),this.pubsub.publish("account")}emitCloseWidgetEvent(){this.pubsub.publish("sbz_close_widget",{type:"chatbox_closed"})}typing(e){e&&(e.startsWith("cslight")||this._typing(e))}deleteLightConvo(e){delete this.lightConvos[e],this.kv.put("light_convos",this.lightConvos)}startWidgetConvo(e,t){const i=this.matchUser(),s=y.find(this.lightConvos,e=>"widget"===e.light_type&&e.account_id===i.account_id&&e.initial_by===i.id);if(s)return{convo:s};const r="cslightwidget_"+y.randomString(24),n=y.cloneDeep(e);n.data.message.conversation_id=r;const o={id:r,account_id:i.account_id,initial_by:i.id,locale:t,light_type:"widget",state:"pending",created:n.created,members:[{id:i.id,type:"user",seen_at:n.created+1}],events:[n],last_message_sent:n,touchpoint:{id:r,channel:"subiz",source:"web"}};return this.lightConvos[r]=o,this.kv.put("light_convos",this.lightConvos),this.pubsub.publish("account"),{convo:o}}promoteWidgetConvo(e,t){this.widgetConvoOrigins=this.widgetConvoOrigins||{},this.widgetConvoOrigins[t]=e;const i=y.cloneDeep(y.get(this.lightConvos,[e,"events",0]));i&&(i.source_event_id=i.id,i.data.message.conversation_id=t,this.chain.merge(t,[{id:i.id,index:i.created,value:i}])),this.deleteLightConvo(e)}startLightConvo(e,t,i,s,r){let n="cslight"+e+"_"+this.now(),o=this.cache.match("user")||{},a=this.lightConvos[n];if(a)return{convo:a};let c=this.now(),u={},l=y.map(t,(t,i)=>{let s={};return s.created=c,s.event_time=c,s.id="evfake"+c+i,s.type="message_sent",s.by={id:e,type:"bot"},s.data={message:t},s.data.message.conversation_id=n,u=s,s}),h={id:n,locale:i,initial_by:e,created:c,actived:c,last_message_sent:u,members:[{type:"user",id:o.id},{type:"bot",id:e,membership:"active"}],state:"active",touchpoint:{id:n,channel:"subiz",source:"web"},traffic_source:"direct",events:l,is_testing:s,bot_versio:r};return this.lightConvos[n]=h,this.kv.put("light_convos",this.lightConvos),this.pubsub.publish("events",u),{convo:h}}async startConvo(e){e||(e={}),await this.readyGate.entry(),this.convoGate.close(),e.source||(e.source=document.location.href);let{body:t,error:i}=await this.api.start(e);return this.convoGate.open(),i?{error:i}:(this._setConvo(t),{convo:t})}fetchOrder(e){return this.api.getOrder(e)}lookupOrder(e){return this.api.lookupOrder(e)}createPostback(e,t){if(!e||!e.startsWith("cslight"))return this.api.createPostback(e,t)}sendReaction(e,t){if(!e||!e.startsWith("cslight"))return this.api.sendConvoEvent(e,t)}async sendConvoEvent(e,t,i){await this.readyGate.entry();var s=y.randomString(36),r={id:s,by:{id:(this.cache.match("user")||{}).id,type:"user",device:this.device},data:i,type:t,created:this.now()};y.convoToEv(e,r);let n=[];"message_sent"===t&&(r.source_event_id=s,r.data.message.conversation_id=e,await N.map(r.data.message.attachments,2,async(e,t)=>{var i;if("file"===e.type&&e._file&&(n.push(e),Z.includes(e._file.type))){let{width:t,height:s,url:r}=await(i=e._file,new Promise(e=>{var t=new window.FileReader;t.onload=t=>{let i=t.target.result,s=new Image;s.onload=()=>{e({url:i,width:s.width,height:s.height})},s.src=i},t.readAsDataURL(i)}));e.url=r,e.width=t,e.height=s}})),this.onWs(r),await this.convoGate.entry();const o=await async function(e,t){let i,s;for(const r of e)try{const e=await t(r._file);if(e.body&&"invalid_field_size"===e.body.code&&(s="cannot_send_too_big_file"),e.error||!e.url){i=i||e.error||"upload_failed";continue}r.url=e.url}catch(e){i=i||e}return{error:i,errorMessage:s}}(n,e=>this.api.uploadToS3(e));if(r._error=o.error,o.errorMessage&&(r._error_message=o.errorMessage),r._error)return this.onWs(r);if(e&&e.startsWith("cslight"))return;let{body:a,error:c}=await this.api.sendConvoEvent(e,r);return c?(r._error=c,void this.onWs(r)):(this.onWs(a),Y("SUBIZ Chat","Sent","User"),this.kv.match("last_msg_sent")||(window.dataLayer||[]).push({event:"SUBIZ Chat",event_action:"Sent",event_label:"User",first_interaction:1}),this.kv.put("last_msg_sent",this.now()),a)}_setConvo(e){this.cache.match("user");let t=y.get(e,"touchpoint.channel","");if(t&&"subiz"!=t)return;let i={};if(y.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&(i[t]=e)}),y.size(i)>18){i=y.orderBy(y.map(i),"created","desc");for(var s=18;s<y.size(i);s++){let e=i[s];this.cache.del("convo_"+e.id)}}this.markSync(e.id),this.pubsub.publish("account"),this.cache.put("convo_"+e.id,e)}matchLastPluginRun(e){return(this.kv.match("plugin_run_logs")||{})[e]}matchLastBotRun(e){return(this.kv.match("bot_run_logs")||{})[e]}logBotRun(e){let t=this.kv.match("bot_run_logs")||{};t[e]={bot_id:e,created:this.now()},this.kv.put("bot_run_logs",t)}sendImpression(e){let t=this.cache.match("user")||{},i=this.kv.match("plugin_run_logs")||{};return i[e]={web_plugin_id:e,created:this.now()},this.kv.put("plugin_run_logs",i),this.api.sendImpression({account_id:t.account_id,campaign_id:e,web_plugin_id:e,user_id:t.id,url:window.location.href,device:this.device})}sendConversion(e,t,i){let s=this.cache.match("user")||{},r={account_id:s.account_id,user_id:s.id,fields:t},n=this.kv.match("conversions")||{};return n[e]=!0,this.kv.put("conversions",n),this.api.sendConversion({account_id:s.account_id,web_plugin_id:e,campaign_id:e,user_id:y.get(s,"id"),url:window.location.href,device:this.device,submission:r,impression_token:i})}isConverted(e){return(this.kv.match("conversions")||{})[e]}async listmessageapi(e,t,i){let s=e;if(s&&s.startsWith("cslight"))return[y.map(this.listEvents(s),e=>({id:e.id,index:e.created,value:e})),"",void 0,!0];let{body:r,code:n,error:o}=await this.api.listMessages(s,-i,t);if(o||200!==n)return[[],t,o||"message_fetch_failed"];t=y.get(y.last(r),"id"),r=y.map(r,e=>(e.created=y.getMs(e.created),{id:e.id,index:e.created,value:e}));let a=this.cache.match("user")||{};for(let e=0;e<r.length;e++){let t=r[e].value;if("message_sent"===t.type&&y.get(t,"by.id")!==a.id){if(y.find(y.get(t,"data.message.pongs"),e=>e.member_id===a.id))break;this._alreadyReceived[t.id]||(this._alreadyReceived[t.id]=!0,this.api.markAsReceived(s,t.id));break}}return[r,t,void 0,y.size(r)<i]}async loopTime(){if(this._die)return;let e=this.now();if(!this.cache||!y.get(this.cache.match("user"),"id"))return this._timeTimeout=y.setTimeout(()=>this.loopTime(),24e4);let{body:t,error:i}=await this.api.time();if(!this._die){if(i)return this._timeTimeout=y.setTimeout(()=>this.loopTime(),3e4);var s=Math.abs(this.now()-e)/2,r=new y.Date(t).getTime()+s,n=this.now();this.timeDiff=Math.floor(r-n),this._timeTimeout=y.setTimeout(()=>this.loopTime(),24e4)}}replaceFileUrl(e){return e?y.startsWith(e,"/")||y.startsWith(e,"data:")?e:(y.startsWith(e,"http://")||y.startsWith(e,"https://")||y.startsWith(e,"//")||(e=y.trim(this.FileURL,"/")+"/"+y.trimStart(e,"/")),e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace("https://file-subiz.com/",this.FileURL)).replace("http://file-subiz.com/",this.FileURL)).replace("https://file-v4.subiz.com/",this.FileURL)).replace("http://file-v4.subiz.com/",this.FileURL)).replace("https://filev4.subiz.com/",this.FileURL)).replace("http://filev4.subiz.com/",this.FileURL)).replace("https://filev4-1.subiz.com/",this.FileURL)).replace("http://filev4-1.subiz.com/",this.FileURL)).replace("https://file.subiz.com/",this.FileURL)).replace("http://file.subiz.com/",this.FileURL)).replace("https://file.mysubiz.com/",this.FileURL)).replace("http://file.mysubiz.com/",this.FileURL)):""}clearBrowserData(){y.each(this.cookie.all(),(e,t)=>{(t||"").startsWith("__sb")&&this.cookie.remove(t)}),this.kv&&this.kv.destroy(),this.kv=new I(new E("sbz2023",this.inmem),"kv"),this.chain&&this.chain.destroy(),this.chain=new P(new E("cbz2023",!0),"ch"),this.outofmsgM={},this.messageSyncTimes={},this.messageSyncNextAt={},this.messageSyncFailures={},this.messageSyncProgress={},this.accountRefreshAfter=0,this.historyFailures={},this.convoFetchAfter={},this.realtime&&this.realtime.stop(),this.cache&&this.cache.destroy(),this.pubsub.publish("destroy")}isDead(){return this._die}destroy(){this._die||(this._die=!0,this.clearBrowserData(),y.clearInterval(this._seenInterval),y.clearInterval(this._urlCheckInterval),y.clearInterval(this._presenceInterval1),y.clearInterval(this._presenceInterval2),y.clearInterval(this._gaInterval),y.clearTimeout(this._timeTimeout),this.realtime&&this.realtime.stop(),this.readyGate&&this.readyGate.close(),window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),window.removeEventListener("beforeunload",this._onBeforeUnload),this._visibilityCleanup&&this._visibilityCleanup(),this.pubsub.clear())}}const Z=["image/gif","image/jpeg","image/png","image/svg+xml"],K={data:{},get(e,t){return this.data[e]||t},set(e,t){return this.data[e]=e},all(){return this.data},remove(e){delete this.data[e]}};function Y(e,t,i){document.dispatchEvent(new CustomEvent("subiz",{detail:{category:e,action:t,label:i}})),function(e,t,i){window.sbz_no_gtag?console.log("SKIPSENT.",e,t,i):((window.dataLayer||[]).push({event:e,event_action:t,event_label:i}),window.gtag&&window.gtag("event",e,{Action:t,Label:i}),window.ga&&window.ga.getAll&&(window.ga.getAll()||[]).forEach(function(s){const r=s.get("name");window.ga(r+".send","event",e,t,i)}))}(e,t,i),function(e,t,i){window.fbq&&window.fbq("trackCustom",e,{action:t,label:i})}(e,t,i)}let ee=()=>{try{localStorage}catch(e){return}y.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020"))&&(localStorage.removeItem(e),H.removeItem(e))})},te=()=>{try{localStorage}catch(e){return}y.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020")||e.startsWith("sbz2022")||e.startsWith("sbz2023"))&&(localStorage.removeItem(e),H.removeItem(e))})};var ie=function(e,t,i,s){if(void 0===y.XMLHttpRequest)return function(e,t,i,s){let r={};i&&(r["content-type"]="text/plain"),fetch(t,{method:e,headers:r,body:i}).then(e=>e.text().then(t=>s&&s(t,e.status))).catch(e=>s&&s(e,-1))}(e,t,i,s);var r=new y.XMLHttpRequest;r.onreadystatechange=function(e){4===r.readyState&&(s&&s(r.responseText,r.status),s=void 0)},r.onerror=function(){s&&s(r.responseText,-1),s=void 0},r.open(e,t),i&&r.setRequestHeader("content-type","text/plain"),r.send(i)};const se=new Error("sdk unloaded");function re(e,t){return"sbz_form_submitted:"+y.stringify([e.accid,e.uid,t])}var ne,oe,ae,ce,ue,le,he,de={},pe=[],fe=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_e=Array.isArray;function me(e,t){for(var i in t)e[i]=t[i];return e}function ge(e){var t=e.parentNode;t&&t.removeChild(e)}function ve(e,t,i){var s,r,n,o={};for(n in t)"key"==n?s=t[n]:"ref"==n?r=t[n]:o[n]=t[n];if(arguments.length>2&&(o.children=arguments.length>3?ne.call(arguments,2):i),"function"==typeof e&&null!=e.defaultProps)for(n in e.defaultProps)void 0===o[n]&&(o[n]=e.defaultProps[n]);return ye(e,o,s,r,null)}function ye(e,t,i,s,r){var n={type:e,props:t,key:i,ref:s,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:r??++ae,__i:-1,__u:0};return null==r&&null!=oe.vnode&&oe.vnode(n),n}function be(e){return e.children}function we(e,t){this.props=e,this.context=t}function ke(e,t){if(null==t)return e.__?ke(e.__,e.__i+1):null;for(var i;t<e.__k.length;t++)if(null!=(i=e.__k[t])&&null!=i.__e)return i.__e;return"function"==typeof e.type?ke(e):null}function xe(e){var t,i;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if(null!=(i=e.__k[t])&&null!=i.__e){e.__e=e.__c.base=i.__e;break}return xe(e)}}function Se(e){(!e.__d&&(e.__d=!0)&&ce.push(e)&&!Ce.__r++||ue!==oe.debounceRendering)&&((ue=oe.debounceRendering)||le)(Ce)}function Ce(){var e,t,i,s,r,n,o,a,c;for(ce.sort(he);e=ce.shift();)e.__d&&(t=ce.length,s=void 0,n=(r=(i=e).__v).__e,a=[],c=[],(o=i.__P)&&((s=me({},r)).__v=r.__v+1,oe.vnode&&oe.vnode(s),Me(o,s,r,i.__n,void 0!==o.ownerSVGElement,32&r.__u?[n]:null,a,n??ke(r),!!(32&r.__u),c),s.__.__k[s.__i]=s,Ie(a,s,c),s.__e!=n&&xe(s)),ce.length>t&&ce.sort(he));Ce.__r=0}function ze(e,t,i,s,r,n,o,a,c,u,l){var h,d,p,f,_,m=s&&s.__k||pe,g=t.length;for(i.__d=c,function(e,t,i){var s,r,n,o,a,c=t.length,u=i.length,l=u,h=0;for(e.__k=[],s=0;s<c;s++)null!=(r=e.__k[s]=null==(r=t[s])||"boolean"==typeof r||"function"==typeof r?null:"string"==typeof r||"number"==typeof r||"bigint"==typeof r||r.constructor==String?ye(null,r,null,null,r):_e(r)?ye(be,{children:r},null,null,null):void 0===r.constructor&&r.__b>0?ye(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):r)?(r.__=e,r.__b=e.__b+1,a=Te(r,i,o=s+h,l),r.__i=a,n=null,-1!==a&&(l--,(n=i[a])&&(n.__u|=131072)),null==n||null===n.__v?(-1==a&&h--,"function"!=typeof r.type&&(r.__u|=65536)):a!==o&&(a===o+1?h++:a>o?l>c-o?h+=a-o:h--:h=a<o&&a==o-1?a-o:0,a!==s+h&&(r.__u|=65536))):(n=i[s])&&null==n.key&&n.__e&&(n.__e==e.__d&&(e.__d=ke(n)),qe(n,n,!1),i[s]=null,l--);if(l)for(s=0;s<u;s++)null!=(n=i[s])&&!(131072&n.__u)&&(n.__e==e.__d&&(e.__d=ke(n)),qe(n,n))}(i,t,m),c=i.__d,h=0;h<g;h++)null!=(p=i.__k[h])&&"boolean"!=typeof p&&"function"!=typeof p&&(d=-1===p.__i?de:m[p.__i]||de,p.__i=h,Me(e,p,d,r,n,o,a,c,u,l),f=p.__e,p.ref&&d.ref!=p.ref&&(d.ref&&Re(d.ref,null,p),l.push(p.ref,p.__c||f,p)),null==_&&null!=f&&(_=f),65536&p.__u||d.__k===p.__k?c=Ae(p,c,e):"function"==typeof p.type&&void 0!==p.__d?c=p.__d:f&&(c=f.nextSibling),p.__d=void 0,p.__u&=-196609);i.__d=c,i.__e=_}function Ae(e,t,i){var s,r;if("function"==typeof e.type){for(s=e.__k,r=0;s&&r<s.length;r++)s[r]&&(s[r].__=e,t=Ae(s[r],t,i));return t}return e.__e!=t&&(i.insertBefore(e.__e,t||null),t=e.__e),t&&t.nextSibling}function Te(e,t,i,s){var r=e.key,n=e.type,o=i-1,a=i+1,c=t[i];if(null===c||c&&r==c.key&&n===c.type)return i;if(s>(null==c||131072&c.__u?0:1))for(;o>=0||a<t.length;){if(o>=0){if((c=t[o])&&!(131072&c.__u)&&r==c.key&&n===c.type)return o;o--}if(a<t.length){if((c=t[a])&&!(131072&c.__u)&&r==c.key&&n===c.type)return a;a++}}return-1}function Ee(e,t,i){"-"===t[0]?e.setProperty(t,i??""):e[t]=null==i?"":"number"!=typeof i||fe.test(t)?i:i+"px"}function Pe(e,t,i,s,r){var n;e:if("style"===t)if("string"==typeof i)e.style.cssText=i;else{if("string"==typeof s&&(e.style.cssText=s=""),s)for(t in s)i&&t in i||Ee(e.style,t,"");if(i)for(t in i)s&&i[t]===s[t]||Ee(e.style,t,i[t])}else if("o"===t[0]&&"n"===t[1])n=t!==(t=t.replace(/(PointerCapture)$|Capture$/,"$1")),t=t.toLowerCase()in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.l[t+n]=i,i?s?i.u=s.u:(i.u=Date.now(),e.addEventListener(t,n?je:Oe,n)):e.removeEventListener(t,n?je:Oe,n);else{if(r)t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!==t&&"height"!==t&&"href"!==t&&"list"!==t&&"form"!==t&&"tabIndex"!==t&&"download"!==t&&"rowSpan"!==t&&"colSpan"!==t&&"role"!==t&&t in e)try{e[t]=i??"";break e}catch(e){}"function"==typeof i||(null==i||!1===i&&"-"!==t[4]?e.removeAttribute(t):e.setAttribute(t,i))}}function Oe(e){var t=this.l[e.type+!1];if(e.t){if(e.t<=t.u)return}else e.t=Date.now();return t(oe.event?oe.event(e):e)}function je(e){return this.l[e.type+!0](oe.event?oe.event(e):e)}function Me(e,t,i,s,r,n,o,a,c,u){var l,h,d,p,f,_,m,g,v,y,b,w,k,x,S,C=t.type;if(void 0!==t.constructor)return null;128&i.__u&&(c=!!(32&i.__u),n=[a=t.__e=i.__e]),(l=oe.__b)&&l(t);e:if("function"==typeof C)try{if(g=t.props,v=(l=C.contextType)&&s[l.__c],y=l?v?v.props.value:l.__:s,i.__c?m=(h=t.__c=i.__c).__=h.__E:("prototype"in C&&C.prototype.render?t.__c=h=new C(g,y):(t.__c=h=new we(g,y),h.constructor=C,h.render=Ue),v&&v.sub(h),h.props=g,h.state||(h.state={}),h.context=y,h.__n=s,d=h.__d=!0,h.__h=[],h._sb=[]),null==h.__s&&(h.__s=h.state),null!=C.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=me({},h.__s)),me(h.__s,C.getDerivedStateFromProps(g,h.__s))),p=h.props,f=h.state,h.__v=t,d)null==C.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(null==C.getDerivedStateFromProps&&g!==p&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(g,y),!h.__e&&(null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(g,h.__s,y)||t.__v===i.__v)){for(t.__v!==i.__v&&(h.props=g,h.state=h.__s,h.__d=!1),t.__e=i.__e,t.__k=i.__k,t.__k.forEach(function(e){e&&(e.__=t)}),b=0;b<h._sb.length;b++)h.__h.push(h._sb[b]);h._sb=[],h.__h.length&&o.push(h);break e}null!=h.componentWillUpdate&&h.componentWillUpdate(g,h.__s,y),null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(p,f,_)})}if(h.context=y,h.props=g,h.__P=e,h.__e=!1,w=oe.__r,k=0,"prototype"in C&&C.prototype.render){for(h.state=h.__s,h.__d=!1,w&&w(t),l=h.render(h.props,h.state,h.context),x=0;x<h._sb.length;x++)h.__h.push(h._sb[x]);h._sb=[]}else do{h.__d=!1,w&&w(t),l=h.render(h.props,h.state,h.context),h.state=h.__s}while(h.__d&&++k<25);h.state=h.__s,null!=h.getChildContext&&(s=me(me({},s),h.getChildContext())),d||null==h.getSnapshotBeforeUpdate||(_=h.getSnapshotBeforeUpdate(p,f)),ze(e,_e(S=null!=l&&l.type===be&&null==l.key?l.props.children:l)?S:[S],t,i,s,r,n,o,a,c,u),h.base=t.__e,t.__u&=-161,h.__h.length&&o.push(h),m&&(h.__E=h.__=null)}catch(e){t.__v=null,c||null!=n?(t.__e=a,t.__u|=c?160:32,n[n.indexOf(a)]=null):(t.__e=i.__e,t.__k=i.__k),oe.__e(e,t,i)}else null==n&&t.__v===i.__v?(t.__k=i.__k,t.__e=i.__e):t.__e=Le(i.__e,t,i,s,r,n,o,c,u);(l=oe.diffed)&&l(t)}function Ie(e,t,i){t.__d=void 0;for(var s=0;s<i.length;s++)Re(i[s],i[++s],i[++s]);oe.__c&&oe.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){oe.__e(e,t.__v)}})}function Le(e,t,i,s,r,n,o,a,c){var u,l,h,d,p,f,_,m=i.props,g=t.props,v=t.type;if("svg"===v&&(r=!0),null!=n)for(u=0;u<n.length;u++)if((p=n[u])&&"setAttribute"in p==!!v&&(v?p.localName===v:3===p.nodeType)){e=p,n[u]=null;break}if(null==e){if(null===v)return document.createTextNode(g);e=r?document.createElementNS("http://www.w3.org/2000/svg",v):document.createElement(v,g.is&&g),n=null,a=!1}if(null===v)m===g||a&&e.data===g||(e.data=g);else{if(n=n&&ne.call(e.childNodes),m=i.props||de,!a&&null!=n)for(m={},u=0;u<e.attributes.length;u++)m[(p=e.attributes[u]).name]=p.value;for(u in m)p=m[u],"children"==u||("dangerouslySetInnerHTML"==u?h=p:"key"===u||u in g||Pe(e,u,null,p,r));for(u in g)p=g[u],"children"==u?d=p:"dangerouslySetInnerHTML"==u?l=p:"value"==u?f=p:"checked"==u?_=p:"key"===u||a&&"function"!=typeof p||m[u]===p||Pe(e,u,p,m[u],r);if(l)a||h&&(l.__html===h.__html||l.__html===e.innerHTML)||(e.innerHTML=l.__html),t.__k=[];else if(h&&(e.innerHTML=""),ze(e,_e(d)?d:[d],t,i,s,r&&"foreignObject"!==v,n,o,n?n[0]:i.__k&&ke(i,0),a,c),null!=n)for(u=n.length;u--;)null!=n[u]&&ge(n[u]);a||(u="value",void 0!==f&&(f!==e[u]||"progress"===v&&!f||"option"===v&&f!==m[u])&&Pe(e,u,f,m[u],!1),u="checked",void 0!==_&&_!==e[u]&&Pe(e,u,_,m[u],!1))}return e}function Re(e,t,i){try{"function"==typeof e?e(t):e.current=t}catch(e){oe.__e(e,i)}}function qe(e,t,i){var s,r;if(oe.unmount&&oe.unmount(e),(s=e.ref)&&(s.current&&s.current!==e.__e||Re(s,null,t)),null!=(s=e.__c)){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(e){oe.__e(e,t)}s.base=s.__P=null,e.__c=void 0}if(s=e.__k)for(r=0;r<s.length;r++)s[r]&&qe(s[r],t,i||"function"!=typeof e.type);i||null==e.__e||ge(e.__e),e.__=e.__e=e.__d=void 0}function Ue(e,t,i){return this.constructor(e,i)}ne=pe.slice,oe={__e:function(e,t,i,s){for(var r,n,o;t=t.__;)if((r=t.__c)&&!r.__)try{if((n=r.constructor)&&null!=n.getDerivedStateFromError&&(r.setState(n.getDerivedStateFromError(e)),o=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(e,s||{}),o=r.__d),o)return r.__E=r}catch(t){e=t}throw e}},ae=0,we.prototype.setState=function(e,t){var i;i=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=me({},this.state),"function"==typeof e&&(e=e(me({},i),this.props)),e&&me(i,e),null!=e&&this.__v&&(t&&this._sb.push(t),Se(this))},we.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},we.prototype.render=be,ce=[],le="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,he=function(e,t){return e.__v.__b-t.__v.__b},Ce.__r=0;class Fe extends we{constructor(e){super(e),this._isMounted=!0,this._subscriptions=new Set;const t=this.componentWillUnmount;this.componentWillUnmount=()=>{if(this._isMounted){this._isMounted=!1;for(const e of this._subscriptions)e();this._subscriptions.clear(),t&&t.call(this)}}}onDispose(e){return this._isMounted?this._subscriptions.add(e):e(),()=>this._subscriptions.delete(e)}}let De={},$e=!1;function We(e,t,i){if($e)return new Promise(s=>y.setTimeout(()=>We(e,t,i).then(s),100));let s;return $e=!0,"debug"===t||De[t]&&!i?($e=!1,Promise.resolve()):e.getLocaleContent(t).then(e=>{$e=!1,s=y.get(e,"body.messages",[]),De[t]=s})}class Ne extends Fe{render(){var e=this.props.emojiCode;if(y.size(e)<3)return null;var t=e.replace(/:/g,"");return ve("i",{"data-tooltip":e,class:`emoji emoji--${t}`})}}function Be(e,t=!1){if("string"!=typeof e)return"";const i=e.trim(),s=i.replace(/[\u0000-\u0020\u007f]/g,""),r=s.match(/^([a-z][a-z0-9+.-]*):/i);return r?/^https?$/i.test(r[1])||!t&&/^(mailto|tel)$/i.test(r[1])||t&&/^blob$/i.test(r[1])||t&&/^data:image\/(png|jpe?g|gif|webp|avif);base64,/i.test(s)?i:"":i}class Ve extends Fe{constructor(e){super(e)}renderBlock(e,t=!1){if(0==y.size(e))return null;let i={style:""};if(e.style&&y.map(e.style,(e,t)=>{i.style+=t+": "+e+";"}),i.attrs={},""!=e.title&&(i.attrs.title=e.title),""!=e.href&&(i.attrs.href=e.href),i.class=e.class,y.map(e.attrs,(e,t)=>{i.attrs[t]=e}),"bullet_list"!=e.type&&"ordered_list"!=e.type||("bullet_list"==e.type?i.tag="ul":i.tag="ol"),"list_item"==e.type&&(i.tag="li"),"heading"==e.type){let t=Math.max(1,Math.min(6,Math.floor(Number(e.level)||1)));i.tag="h"+t}if("paragraph"!=e.type&&"section"!=e.type&&"div"!=e.type||(i.tag="div"),i.text=e.text,""==e.type||"text"==e.type||"dynamic-field"==e.type){i.tag="span",e.bold&&(i.tag="b"),e.italic&&("b"==i.tag?i.style+="font-style: italic;":i.tag="em");let t=[];e.underline&&t.push("underline"),e.strike_through&&t.push("line-through"),t.length&&(i.style+="text-decoration: "+t.join(" ")+" !important;")}if("dynamic-field"==e.type){let t=y.get(e.attrs,"key");i.text=y.get(this.props.data,[t],i.text)}if("link"==e.type&&(i.tag="a",i.attrs.href=Be(e.href),i.attrs.target=e.target,i.attrs.title=e.title),"mention-agent"==e.type||"mention"==e.type){i.tag="span",i.class="mention";let t=y.get(e,"attrs.id","");if("*"!=t&&"all"!=t||(i.text="@"+(this.props.t?this.props.t("all"):"all")),"string"==typeof t&&/^(ag|at)/.test(t)&&this.props.store){let e=this.props.store.matchAgent(t),s=y.getAgentDisplayName(this.props.store.matchAccount(),e);i.text="@"+s}}if("horizontal_rule"==e.type&&(i.tag="hr"),"emoji"==e.type){let t="";y.size(e.attrs)>0&&(t=e.attrs.code),t||(t=e.text||e.Text),""!=t&&(i.tag="Emoji",i.attrs.emojiCode=t)}"image"===e.type&&(i.tag="img",i.attrs.src=Be(y.get(e,"image.url"),!0),i.attrs.alt=e.alt_text),"hard_break"==e.type&&(i.tag="br"),"pre"!=e.type&&"code"!=e.type||(i.tag=e.type);let s=null;switch(s=y.size(e.content)?y.map(e.content,i=>this.renderBlock(i,t||"code"==e.type)):"text"===e.type?t?i.text:y.extractText(i.text).map(e=>{if("link"===e.type){let t=e.text||"";return t.startsWith("//")||t.startsWith("https://")||t.startsWith("http://")||t.startsWith("data:")||(t="//"+t),t=Be(t),t?ve("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:e=>this.props.onLink&&this.props.onLink(e,t)},e.text):e.text}return"phone"===e.type?ve("a",{href:"tel:"+e.text},e.text):"email"===e.type?ve("a",{href:"mailto:"+e.text},e.text):e.text}):i.text,i.tag){case"img":return i.attrs.src?ve("a",{class:this.props.textMessage?"message-text-inline-image-wrapper":"",href:y.get(i,"attrs.src"),target:"_blank",rel:"noopener noreferrer"},ve("img",{class:this.props.textMessage?"message-text-inline-image":"",src:y.get(i,"attrs.src"),alt:y.get(i,"attrs.alt")||""})):e.alt_text||null;case"div":return ve("div",null,s);case"pre":return ve("pre",{class:"message-block-pre"},s);case"code":return ve("code",{class:"message-block-code"+(i.class?" "+i.class:"")},s);case"h1":return ve("h1",null,s);case"h2":return ve("h2",null,s);case"h3":return ve("h3",null,s);case"h4":return ve("h4",null,s);case"h5":return ve("h5",null,s);case"h6":return ve("h6",null,s);case"ol":return ve("ol",{class:this.props.textMessage?"text-message-ol":""},s);case"ul":return ve("ul",{class:this.props.textMessage?"text-message-ul":""},s);case"li":return ve("li",{class:this.props.textMessage?"text-message-li":""},s);case"span":return ve("span",{class:i.class,style:i.style},s);case"em":return ve("em",{style:i.style},s);case"b":return ve("b",{style:i.style},s);case"hr":return ve("hr",null);case"br":return ve("br",null);case"a":return i.attrs.href?ve("a",{class:this.props.textMessage?"message-text-link":"",href:i.attrs.href,target:this.props.textMessage?"_blank":i.attrs.target,title:i.attrs.title,rel:"noopener noreferrer",onClick:e=>this.props.onLink&&this.props.onLink(e,i.attrs.href)},s):ve("span",null,s);case"Emoji":return ve(Ne,{emojiCode:i.attrs.emojiCode})}return s}render(){return this.renderBlock(this.props.block)}}function He(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Ge extends Fe{constructor(e){super(e),He(this,"state",{hovering:0,selected:0}),He(this,"onMouseEnter",e=>{let{selected:t,hovering:i}=this.state;e<=t?this.setState({hovering:t}):this.setState({hovering:e})}),He(this,"onMouseLeave",()=>{let{selected:e,hovering:t}=this.state;this.setState({hovering:0})})}onToggleValue(e){let{selected:t}=this.state,i=e;e===t&&(i=0),this.setState({selected:i,hovering:i}),this.props.onChange(i)}render(){let{selected:e,hovering:t}=this.state,i="star-wrapper";e>=1?i+=" selected":t>=1&&(i+=" hovering");let s="star-wrapper";e>=2?s+=" selected":t>=2&&(s+=" hovering");let r="star-wrapper";e>=3?r+=" selected":t>=3&&(r+=" hovering");let n="star-wrapper";e>=4?n+=" selected":t>=4&&(n+=" hovering");let o="star-wrapper";return e>=5?o+=" selected":t>=5&&(o+=" hovering"),ve("div",{class:"form-ratings-wrapper",onMouseLeave:()=>this.onMouseLeave()},ve("div",{class:i,onClick:()=>this.onToggleValue(1),onMouseEnter:()=>this.onMouseEnter(1)},ve("div",{class:"star"})),ve("div",{class:s,onClick:()=>this.onToggleValue(2),onMouseEnter:()=>this.onMouseEnter(2)},ve("div",{class:"star"})),ve("div",{class:r,onClick:()=>this.onToggleValue(3),onMouseEnter:()=>this.onMouseEnter(3)},ve("div",{class:"star"})),ve("div",{class:n,onClick:()=>this.onToggleValue(4),onMouseEnter:()=>this.onMouseEnter(4)},ve("div",{class:"star"})),ve("div",{class:o,onClick:()=>this.onToggleValue(5),onMouseEnter:()=>this.onMouseEnter(5)},ve("div",{class:"star"})))}}function Qe(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Je extends Fe{constructor(e){super(e),Qe(this,"state",{errorFields:{},submiting:!1}),Qe(this,"renderFormComponent",(e,t)=>"input"===e.type?this.renderField(e,t):"button"===e.type?this.renderSubmitButton(e,t):this.props.isSubmited?void 0:ve("div",{class:"form-component form-component-block"},ve(Ve,{block:e}))),Qe(this,"renderSubmitButton",(e,t)=>{if(!this.props.isSubmited)return ve("div",{class:"form-component form-component-submit-button"},this.props.errorMessage&&ve("div",{class:"form-control--valid-input--error mb-1"},this.props.errorMessage),ve("div",null,ve("button",{class:"btn--start-convo",disabled:this.props.submiting},e.label)))}),Qe(this,"renderField",(e,t)=>{let i=this.state.errorFields[e.key];if(this.props.isSubmited){let t=y.find(this.props.submission.values,t=>t.key===e.key)||{};return t=t.value||'""',t=y.parseJSON(t),Array.isArray(t)&&(t=t.join(", ")),ve("div",{class:"form-component submitted",key:e.key},ve("label",{class:"label"},e.label),ve("div",null,t||ve("span",{class:"text-muted text-italic"},this.props.t("no_info_input"))))}return ve("div",{class:"form-component",key:e.key},ve("label",{class:"label"},e.label," ",e.is_required&&ve("span",{class:"red"},"*")),"text"===e.input_type&&this.renderFieldTextInput(e,t),"textarea"===e.input_type&&this.renderFieldTextareaInput(e,t),"date"===e.input_type&&this.renderFieldDateInput(e,t),"radio"===e.input_type&&this.renderFieldRadioInput(e,t),"checkbox"===e.input_type&&this.renderFieldCheckboxInput(e,t),("dropdown"===e.input_type||"select"===e.input_type)&&this.renderFieldDropdownInput(e,t),"rating"===e.input_type&&this.renderFieldRatingInput(e,t),i&&ve("div",{class:"form-control--valid-input--error"},i))}),Qe(this,"renderFieldTextInput",(e,t)=>{let i="form-control";this.state.errorFields[e.key]&&(i="form-control input--error");let s=y.find(this.props.submission.values,t=>t.key===e.key)||{};return s=s.value||'""',s=y.parseJSON(s),ve("input",{ref:this[`${e.key}_input`],type:"text",class:i,placeholder:e.placeholder,value:s,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Qe(this,"renderFieldDateInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-control";return this.state.errorFields[e.key]&&(s="form-control input--error"),ve("input",{ref:this[`${e.key}_input`],class:s,type:"date",value:i,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Qe(this,"renderFieldRadioInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-radios-wrapper";return y.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(s+=" horizontal"),ve("div",{class:s},y.map(e.input_options,(t,s)=>{let r=e.key+"_"+s;return ve("div",{class:"radio"},ve("input",{type:"radio",name:e.key,id:r,checked:t.value===i,onChange:()=>this.toggleRadioField(e.key,t.value)}),ve("label",{class:"radio--label",for:r},t.label),ve("div",{class:"radio--check"}))}))}),Qe(this,"renderFieldCheckboxInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||"[]",i=y.parseJSON(i);let s="form-checkboxes-wrapper";return y.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(s+=" horizontal"),ve("div",{class:s},y.map(e.input_options,(t,s)=>{let r=e.key+"_"+s;return ve("div",{class:"checkbox"},ve("input",{type:"checkbox",name:e.key,id:r,checked:i.includes(t.value),onChange:()=>this.toggleCheckboxField(e.key,t.value)}),ve("label",{class:"checkbox--label",for:r},t.label),ve("div",{class:"checkbox--check"}))}))}),Qe(this,"renderFieldDropdownInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=y.parseJSON(i);let s="form-control";return this.state.errorFields[e.key]&&(s+=" input--error"),i||(s+=" form-control--empty"),ve("select",{class:s,ref:this[`${e.key}_input`],onChange:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}},ve("option",{value:""},"-- ",this.props.t("no_select")," --"),y.map(e.input_options,e=>ve("option",{value:e.value},e.label)))}),Qe(this,"renderFieldTextareaInput",(e,t)=>{let i=y.find(this.props.submission.values,t=>t.key===e.key)||{};return i=i.value||'""',i=y.parseJSON(i),ve("textarea",{onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)},ref:this[`${e.key}_input`],rows:"3",class:"form-control",placeholder:e.placeholder})}),Qe(this,"renderFieldRatingInput",(e,t)=>ve(Ge,{onChange:t=>this.onChangeValue(e.key,t)})),Qe(this,"onSubmit",e=>{e.preventDefault(),this.validateForm()&&this.props.onSubmit()}),Qe(this,"validateForm",()=>{let e=!0,t="",i={},s=y.get(this.props.formSetting,"components")||[];return y.each(s,s=>{if("input"===s.type){let r=y.find(this.props.submission.values,e=>e.key===s.key)||{};if(r=r.value||'""',r=y.parseJSON(r),s.is_required){let n=!1;"string"!=typeof r||r.trim()||(n=!0),Array.isArray(r)&&0===r.length&&(n=!0),n&&(e=!1,i[s.key]=this.props.t("cannot_be_empty"),t=`${s.key}_input`)}if(s.validation&&!Array.isArray(r)){let n=!1,o="";"email"!==s.validation||y.isEmail(r)||(o="Email",n=!0),"phone"!==s.validation||y.isPhone(r)||(o=this.props.t("phn"),n=!0),"number"!==s.validation||y.isNumber(r)||(o=this.props.t("number"),n=!0),"url"!==s.validation||y.isURL(r)||(n=!0,o="URL"),n&&(e=!1,i[s.key]=this.props.t("format_is_invalid")+" "+o,t=`${s.key}_input`)}}}),t&&this[t]&&this[t].current&&this[t].current.focus(),this.setState({errorFields:i}),e}),Qe(this,"onChangeValue",(e,t)=>{let i=y.get(this.props.submission,"values")||[],s=y.find(i,t=>t.key===e);s?s.value=JSON.stringify(t):i.push({key:e,value:JSON.stringify(t)}),this.props.onChangeFormValues(i)}),Qe(this,"clearError",e=>{let t=this.state.errorFields;t[e]="",this.setState({errorFields:t})}),Qe(this,"renderFormHeader",()=>{let e=y.get(this.props.formSetting,"title")||"",t=y.get(this.props.formSetting,"description")||"";if("attachment"===this.props.mode&&(e.trim()||t.trim()))return ve("div",{class:"form-component form-component-block"},e&&ve("div",null,e),t&&ve("div",{class:"text-sm text-muted"},t));let i=y.get(this.props.formSetting,"logo.url"),s=y.get(this.props.formSetting,"brand_url"),r=null;i&&(r=ve("div",{class:"form-page-logo-wrapper"},ve("a",{href:s||"javascript:;"},ve("img",{src:i,class:"form-page-logo"}))));let n=null;return(e.trim()||t.trim())&&(n=ve("div",{class:"form-page-header"},ve("div",{class:"form-page-title"},e),t&&ve("div",{class:"form-page-desc"},t))),ve(be,null,r,n)});let t=y.get(this.props.formSetting,"components")||[];y.each(t,e=>{"input"===e.type&&"checkbox"!==e.input_type&&"radio"!==e.input_type&&(this[`${e.key}_input`]={current:null})})}toggleRadioField(e,t){this.clearError(e),this.onChangeValue(e,t)}toggleCheckboxField(e,t){let i=y.find(this.props.submission.values,t=>t.key===e)||{};i=i.value||"[]",i=y.parseJSON(i),i.includes(t)?i=i.filter(e=>e!==t):i.push(t),this.clearError(e),this.onChangeValue(e,i)}render(){let e=y.get(this.props.formSetting,"components")||[],t=(y.get(this.props.formSetting,"title"),y.get(this.props.formSetting,"description"),"form-wrapper form");return"attachment"===this.props.mode&&(t+=" form-wrapper-attachment"),ve("div",{class:t},this.props.isSubmited&&ve("div",{class:"form-component"},this.props.t("you_have_submitted_info_successfully")),ve("form",{onSubmit:this.onSubmit},this.renderFormHeader(),y.map(e,this.renderFormComponent)))}}function Xe(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const Ze=i.e(339).then(()=>i(5339));class Ke extends Fe{constructor(e){super(e),Xe(this,"waitForFont",async e=>{if(0==y.size(e))return;let t={};for(let i=0;i<10;i++){for(let i=0;i<e.length;i++)try{if(document.fonts.check("normal 16px "+e[i])&&(t[e[i]]=!0),y.size(Object.keys(t))===e.length)return}catch(e){}await y.sleep(200)}}),Xe(this,"initCss",async()=>{let e=(await Ze).default.default.toString(),t=y.find(this.props.store.matchPlugin(),e=>"chatbox"===e.type)||{};t=t.chatbox||{};let i=t,s=y.replaceCssVariable(e,i),r=document.createElement("style");document.head.appendChild(r),r.type="text/css",r.id="subiz-style-for-form",this.cssDiv=r,y.setCss("form",r,s)}),Xe(this,"insertCss",async(e,t)=>{let i=(await Ze).default.default.toString(),s=e;t.primary_color&&(s.primary_color=t.primary_color);let r=y.get(t,"header_style.font_family"),n=y.get(t,"text_style.font_family"),o=y.get(t,"input_style.font_family");s.form_background_color=t.background_color,s.form_header_font_size=y.get(t,"header_style.font_size")||"20",s.form_header_font_family=r,s.form_desc_font_size=y.get(t,"text_style.font_size")||"16",s.form_desc_font_family=n,s.form_input_label_font_size=y.get(t,"input_style.font_size")||"14",s.form_input_label_font_family=o;let a=y.replaceCssVariable(i,s),c=[];o&&!c.includes(o)&&c.push(o),r&&!c.includes(r)&&c.push(r),n&&!c.includes(n)&&c.push(n),y.size(c)&&(y.preloadWebfonts(c,[400,500]),await this.waitForFont(c)),y.setCss("form",this.cssDiv,a)}),Xe(this,"fetchFormSetting",async()=>{let e=y.find(this.props.store.matchPlugin(),e=>"chatbox"===e.type)||{};if(e=e.chatbox||{},this.props.previewJson){this.setState({loading:!0});let t=atob(this.props.previewJson);return t=decodeURIComponent(t),t=y.parseJSON(t),await this.insertCss(e,t),void this.setState({formSetting:t,loading:!1})}if(this.state.loading)return;this.setState({loading:!0});let t=await this.props.store.checkFormToken(this.props.store.matchAccount().id,this.props.token);if(t.error)return void this.setState({loading:!1,loadError:!0});let i=y.get(t,"body.form")||{},s=y.get(t,"body.form_submission")||{},r=y.size(s)>0;await this.insertCss(e,i),this.setState({loading:!1,loadError:!1,formSetting:i,submission:s,isSubmited:r})}),Xe(this,"onChangeFormValues",e=>{this.setState({submission:{values:e}})}),Xe(this,"onSubmit",async()=>{this.setState({errorMessage:""}),this.props.previewJson?this.setState({isSubmited:!0}):this.state.submiting||(this.setState({submiting:!0}),(await this.props.store.submitForm2(this.props.store.matchAccount().id,this.props.token,this.state.submission)).error?this.setState({submiting:!1,errorMessage:this.props.t("form_submission_error")}):this.setState({submiting:!1,isSubmited:!0}))}),this.state={submission:{},formSetting:{},submiting:!1,errorMessage:"",isSubmited:!1,loading:!1,loadError:""}}async componentDidMount(){await this.initCss(),this.fetchFormSetting()}render(){const{formSetting:e,loading:t,loadError:i,submission:s,errorMessage:r,isSubmited:n,submiting:o}=this.state;if(t&&!i)return ve("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"loading"},ve("div",{class:"text-muted text-xl"},this.props.t("loading_data")," ..."));if(i)return ve("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"error"},ve("div",{class:"text-center"},ve("div",{class:"text-danger text-lg mb-2"},this.props.t("error_occurs_when_load_data")),ve("br",null),ve("button",{disabled:t,type:"button",class:"btn--start-convo",onClick:this.fetchFormSetting},this.props.t("try_again"))));y.get(e,"logo.url");let a=y.get(e,"cover_image.url"),c="form-page";return a&&(c+=" sketch"),ve("div",{class:"form-page-body",key:"form"},this.props.previewJson&&ve("div",{class:"form-page-preview-noti"},"Form ở trạng thái xem thử, không ghi nhận phản hồi"),a&&ve("div",{class:"form-page-header-bg",style:`background: url(${a}); background-size: cover;`}),ve("div",{class:c},ve(Je,{store:this.props.store,formSetting:e,t:this.props.t,submission:s,errorMessage:r,isSubmited:n,submiting:o,onChangeFormValues:this.onChangeFormValues,onSubmit:this.onSubmit})))}}i.e(278).then(()=>i(9278));const Ye=i(5180);function et(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var tt=document.createElement("link");tt.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap",tt.rel="stylesheet",document.head.append(tt),async function(){let e=new X(Ye.ApiURL,Ye.FileURL,Ye.RealtimeURL,!0);window.store=e;let t=et("id")||et("accid")||et("account-id")||"acqsulrowbxiugvginhw",i=et("token"),s=et("preview");await e.init(t);let r=e=>{if("debug"===n)return`{{${e}}}`;let t=y.get(De,n,[]),i=y.find(t,t=>t.key===e);return y.get(i,"message",e)},n="vi-VN";r.i18n=e=>{if(!e)return"";let t="vi-VN";return t=t.replace("-","_"),e[n.replace("-","_")]||e[t]},r.locale=()=>n,We(e,n).then(()=>{!function(e,t,i){var s,r,n,o;oe.__&&oe.__(e,t),r=(s="function"==typeof i)?null:i&&i.__k||t.__k,n=[],o=[],Me(t,e=(!s&&i||t).__k=ve(be,null,[e]),r||de,de,void 0!==t.ownerSVGElement,!s&&i?[i]:r?null:t.firstChild?ne.call(t.childNodes):null,n,!s&&i?i:r?r.__e:t.firstChild,s,o),Ie(n,e,o)}(ve(Ke,{store:e,t:r,token:i,previewJson:s}),document.getElementById("form"))})}()})()})();