@subiz/widget-v4 4.1.175 → 4.1.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/app.js +10 -15
  2. package/assets/less/chatbox.less +1 -0
  3. package/assets/less/widget.less +1 -1
  4. package/cloudflare_worker.js +3 -4
  5. package/compiled_src/chatbox/main.js +11 -9
  6. package/compiled_src/lib.js +5 -0
  7. package/compiled_src/store/api.js +2 -2
  8. package/compiled_src/store/store.js +11 -0
  9. package/compiled_src/util/common.js +1 -0
  10. package/dist/185.js +1 -1
  11. package/dist/19937d43753.185.js +1 -0
  12. package/dist/19937d43753.27.js +1 -0
  13. package/dist/{198cd86b62f.278.js → 19937d43753.278.js} +1 -1
  14. package/dist/{198cd86b62f.339.js → 19937d43753.339.js} +1 -1
  15. package/dist/{198cd86b62f.459.js → 19937d43753.459.js} +1 -1
  16. package/dist/{198cd86b62f.997.js → 19937d43753.997.js} +1 -1
  17. package/dist/19937d43753.app.js +1 -0
  18. package/dist/{198cd86b62f.chat.html → 19937d43753.chat.html} +1 -1
  19. package/dist/19937d43753.chat.js +1 -0
  20. package/dist/{198cd86b62f.form.html → 19937d43753.form.html} +1 -1
  21. package/dist/19937d43753.form.js +1 -0
  22. package/dist/{198cd86b62f.index.html → 19937d43753.index.html} +1 -1
  23. package/dist/{198cd86b62f.library.html → 19937d43753.library.html} +1 -1
  24. package/dist/19937d43753.library.js +1 -0
  25. package/dist/{198cd86b62f.preview.html → 19937d43753.preview.html} +1 -1
  26. package/dist/19937d43753.preview.js +1 -0
  27. package/dist/19937d43753.webview.js +1 -0
  28. package/dist/27.js +1 -73
  29. package/dist/459.js +1 -73
  30. package/dist/997.js +0 -72
  31. package/dist/HASH +1 -1
  32. package/dist/screenshoot.js +501 -26
  33. package/package.json +4 -4
  34. package/src/chatbox/main.js +11 -9
  35. package/src/lib.js +13 -3
  36. package/src/store/api.js +4 -0
  37. package/src/store/store.js +14 -6
  38. package/src/util/common.js +1 -0
  39. package/tracking.js +3 -2
  40. package/dist/198cd86b62f.185.js +0 -1
  41. package/dist/198cd86b62f.27.js +0 -1
  42. package/dist/198cd86b62f.app.js +0 -1
  43. package/dist/198cd86b62f.chat.js +0 -1
  44. package/dist/198cd86b62f.form.js +0 -1
  45. package/dist/198cd86b62f.library.js +0 -1
  46. package/dist/198cd86b62f.preview.js +0 -1
  47. package/dist/198cd86b62f.webview.js +0 -1
  48. package/dist/278.js +0 -417
  49. /package/dist/{198cd86b62f.127.js → 19937d43753.127.js} +0 -0
  50. /package/dist/{198cd86b62f.132.js → 19937d43753.132.js} +0 -0
  51. /package/dist/{198cd86b62f.490.js → 19937d43753.490.js} +0 -0
  52. /package/dist/{198cd86b62f.74.js → 19937d43753.74.js} +0 -0
@@ -1 +0,0 @@
1
- (()=>{var e,t,r={9:(e,t,i)=>{var r=i(9143);e.exports=function(e,t,i){var s=[],n="idle",o=function(e){var t=e.map(function(e){return e.payload}),r=i(t);r&&r.then||(r=Promise.resolve(r));var s=e.map(function(e){return e.rs});return new Promise(function(e){r.then(function(t){s.map(function(e,i){e(t&&t[i])}),e()})})},a=function(){"executing"!==n&&(n="executing",r(function(){if(s.length<=e)return Promise.resolve(!1);var t=s.splice(0,e);return o(t).then(function(){return!0})}).then(function(){if(0!==s.length){var e=t-(Date.now()-s[0].created);if(e>=1){if(n="idle",s[0].settedTimeout)return;return s[0].settedTimeout=!0,void setTimeout(a,e)}var i=s;s=[],o(i).then(function(){n="idle",a()})}else n="idle"}))};return this.push=function(e,t){return new Promise(function(i){s.push({payload:e,priority:t,created:Date.now(),rs:i}),a()})},this}},318:e=>{var t="Content-Type",i="application/x-www-form-urlencoded",r="application/json; charset=utf-8";function s(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 r=e.shift();if(!u(r))return l(e,t,i);r(t,function(r){return!1===r?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=[],r=0;r<t.length;r++){var s=t[r],n="",o=e[s];if(void 0!==o){if(null===o)n=h(s);else if(Array.isArray(o)){for(var a=[],c=0;c<o.length;c++)void 0!==o[c]&&(a.push(p(s,o[c],a.length)),a.push(i));n=a.join("&")}else n=h(s)+"="+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 s(this,{_withCredentials:e})},setQuery:function(e){return s(this,{query:e})},clearHooks:function(){return s(this,{beforehooks:[],afterhooks:[]})},beforeHook:function(e){var t=this.beforehooks.slice();return t.push(e),s(this,{beforehooks:t})},afterHook:function(e){var t=this.afterhooks.slice();return t.push(e),s(this,{afterhooks:t})},setHeader:function(e){return(e=Object.assign({},this.headers,e))[t]=void 0,s(this,{headers:e})}},["put","head","patch","delete","post","get"].map(function(e){f[e]=function(h,p,f){return function(e,s,c){c=c||function(){},u(s)&&(c=s,s=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 s&&((e=e.clone()).body=s,e.content_type===r&&(e.body=m.Jsonify(s)),e.content_type===i&&(e.body=d(s))),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 r=d(e.query);if(r&&(r="?"+r),!m.XMLHttpRequest)return function(e,i,r){var s=Object.assign({},e.headers);e.content_type&&(s[t]=e.content_type),fetch(e.baseurl+r,{method:e.method,headers:s,credentials:e._withCredentials,body:e.body}).then(function(e){return e.text()}).then(function(e){i(void 0,e,res.status)}).catch(function(e){i("network_error",e,-1)})}(e,i,r);var s=new m.XMLHttpRequest;for(var n in s.onreadystatechange=function(e){4===s.readyState&&(0===s.status?i("network_error",s.responseText,s.status):i(void 0,s.responseText,s.status))},s.open(e.method,e.baseurl+r),s.withCredentials=e._withCredentials,e.headers)s.setRequestHeader(n,e.headers[n]);e.content_type&&s.setRequestHeader(t,e.content_type),s.send(e.body)}(i.request,function(t,i,r){l(e.afterhooks.slice(),{request:e,code:r,body:i,err:t},function(t){var i=t.body;if("network_error"==s)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 s=t.err;if("network_error"==s)return h({body:{error:n},code:t.code,error:n});!s&&(r<200||r>299)&&(s=i&&i.error?i.error:a),h({body:s?i||{error:s}:i,code:t.code,error:s})})})}),p}(s(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 s(this,{baseurl:e})},f.contentTypeJson=function(){return s(this,{content_type:r})},f.contentTypeForm=function(){return s(this,{content_type:i})},f.setContentType=function(e){return s(this,{content_type:c(e)})},f.setParser=function(e){return s(this,{parser:c(e)})},f.setBody=function(e){return s(this,{body:e})},f),m={Jsonify:JSON.stringify,ParseJson:JSON.parse};_.env=m,_.waterfall=l,e.exports=_},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,r){void 0===r?t.removeItem(e):(Object.prototype.hasOwnProperty.call(i,e)||t.length++,i[e]=r)},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},1139:(e,t,i)=>{"use strict";i.d(t,{A:()=>r});class r{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()})})}}},2839:(e,t,i)=>{var r=i(8193),{xhrsend:s,parseJSON:n,Pubsub:o}=i(7695);function a(e,t,i,o,a,h){a=a||s,t=t||{};var d="";h||(h="");var p=!1,f=!1,_=!0,m=function(t){p||a("get",e+"poll?token="+d+"&v=5&account-id="+h,void 0,function(i,r){if(!p){if(c(r))return f=!0,setTimeout(m,function(e){if(!e||-1===e)return 0;var t=1e3*Math.pow(1.5,e);return Math.min(1e4,t)}(t),t+1);if(200!==r)return f=!0,v("poll");f=!1,(i=n(i)||{}).host&&(e=l(i.host));var s=i.sequential_token;return s?(d=s,o(i.events||[]),m(0)):v("poll")}})},g=r.batch(50,100,function(i){if(p)return Promise.resolve(u("dead",i.length));if(i.length<=0)return Promise.resolve([]);var s,o=new Promise(e=>{s=e}),f=!1;return setTimeout(function(){f||p||(_=!0)},4e3),setTimeout(()=>{f||(f=!0,_=!0,s(u("dead",i.length)),p||v("subs"))},6e4),r.loop(function(){return new Promise(function(r){if(p)return s(u("dead",i.length)),r(!1);var o="?token="+d;t.getAccessToken().then(function(g){if(p)return s(u("dead",i.length)),r(!1);t.user_ref?o+="&user_ref="+encodeURIComponent(t.user_ref):t.user_mask?o+="&user-mask="+encodeURIComponent(t.user_mask):g&&(o+="&access-token="+g);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 s(u("dead",i.length)),r(!1);if(c(o))return _=!0,setTimeout(r,3e3,!0);if(200!==o)return v("subs"),s(u("dead",i.length)),r(!1);if(_=!1,f=!0,d)return s(i),r(!1);var a=(t=n(t)||{}).initial_token;return a?(t.host&&(e=l(t.host)),d=a,m(0),s(i),r(!1)):(v("subs"),s(u("dead",i.length)),r(!1))}})})})}),o});this.subscribe=g.push.bind(g),this.getStatus=function(){return p?"dead":_||f?"connecting":"active"};var v=function(e){p=!0,i(e)};this.kill=v}function c(e){return e>=500&&e<600||0===e||-1===e||429===e}function u(e,t){for(var i=[],r=0;r<t;r++)i.push(e);return i}function l(e){return(e=e||"").startsWith("//")?"https:"+e:e}e.exports=function(e,t,i,r,s){("string"==typeof e||e instanceof String)&&(e=[e]),(t=t||{}).getAccessToken||(t.getAccessToken=function(){return Promise.resolve("")}),r||(r=t.account_id||"");var n=new o,c={};this.stop=function(){u&&(u.kill(),u=void 0,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 r=e[i];r&&(c[r]||(c[r]=!0,t.push(u.subscribe(r))))}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)];u&&u.kill();var d=new a(o,t,function(e,t,i){void 0!==u&&d==u&&(u=void 0,n.emit("interrupted",e,t,i),s||setTimeout(h,2e3))},function(e){if(d==u)for(var t=0;t<e.length;t++)n.emit("event",e[t])},i,r);u=d;var p=Object.keys(c);return c={},l(p)};this.reconnect=h,h()}},3259:(e,t,i)=>{"use strict";i.r(t),i.d(t,{get:()=>a,set:()=>c});var r=Object.prototype.toString,s=Array.isArray||function(e){return"[object Array]"===r.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&&s(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 r=n(t[0]),s=o(e,r);return void 0===s?i:1===t.length?s:a(e[r],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 r=t[0],s=o(e,r);return 1===t.length?(e[r]=i,s):(void 0===s&&(e[r]="number"==typeof t[1]?[]:{}),c(e[r],t.slice(1),i))}},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/",BaseURL:"https://widget.sbz.vn"}},5219:(e,t,i)=>{var r=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 s={};if(r.map(e,function(e,t){s[t]=e}),i<=0&&(i=1),0===Object.keys(s).length)return Promise.resolve([]);Object.keys(s).length<i&&(i=Object.keys(s).length);var n={};return new Promise(function(e){let o=Object.keys(s).length;for(var a=function(){var i=Object.keys(s);if(0!==i.length){var c=i.shift(),u=s[c];delete s[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(r.map(n));a()})}},c=0;c<i;c++)setTimeout(a,1)})}},5369:(e,t,i)=>{"use strict";i.d(t,{A:()=>r});class r{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())}}},5672:function(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 null==e?t:e}};return e.defaults={},e.expiresMultiplier=86400,e.set=function(e,i,r){if(t.isPlainObject(e))for(var s in e)e.hasOwnProperty(s)&&this.set(s,e[s],i);else{var n=void 0!==(r=t.isPlainObject(r)?r:{expires:r}).expires?r.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=r.path||this.defaults.path;a=a?";path="+a:"";var c=r.domain||this.defaults.domain;c=c?";domain="+c:"";var u=r.secure||this.defaults.secure?";secure":"";!1===r.secure&&(u="");var l=r.sameSite||this.defaults.sameSite;l=l?";SameSite="+l:"",null===r.sameSite&&(l=""),document.cookie=t.encode(e)+"="+t.encode(i)+n+a+c+u+l}return this},e.setDefault=function(i,r,s){if(t.isPlainObject(i)){for(var n in i)void 0===this.get(n)&&this.set(n,i[n],r);return e}if(void 0===this.get(i))return this.set.apply(this,arguments)},e.remove=function(e){for(var i=0,r=(e=t.isArray(e)?e:t.toArray(arguments)).length;i<r;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 r=0,s=e.length;r<s;r++)this.set(e[r],"",i);return this},e.empty=function(){return this.remove(t.getKeys(this.all()))},e.get=function(e,i){var r=this.all();if(t.isArray(e)){for(var s={},n=0,o=e.length;n<o;n++){var a=e[n];s[a]=t.retrieve(r[a],i)}return s}return t.retrieve(r[e],i)},e.all=function(){if(""===document.cookie)return{};for(var e=document.cookie.split("; "),i={},r=0,s=e.length;r<s;r++){var n=e[r].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}()},6463:(e,t,i)=>{"use strict";i.d(t,{A:()=>n});var{filter:r,map:s}=i(9917);class n{constructor(){this.listeners={}}publish(e,t,i,n){this.listeners[e]=r(this.listeners[e],e=>e.obj._isMounted),s(this.listeners[e],({cb:e})=>e(t,i,n))}on2(e,t,i){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push({obj:e,cb:i})}}},7695:e=>{function t(e){return e<10?`0${e}`:`${e}`}var i=function(e,t,i,r){if("undefined"==typeof XMLHttpRequest)return function(e,t,i,r){let s={};i&&(s["content-type"]="text/plain"),fetch(t,{method:e,headers:s,body:i}).then(e=>e.text().then(t=>r&&r(t,e.status))).catch(e=>r&&r(e,-1))}(e,t,i,r);var s=new XMLHttpRequest;s.onreadystatechange=function(e){4===s.readyState&&(r&&r(s.responseText,s.status),r=void 0)},s.onerror=function(){r&&r(s.responseText,-1),r=void 0},s.open(e,t),i&&s.setRequestHeader("content-type","text/plain"),s.send(i)};e.exports={xhrsend:i,parseJSON:function(e){try{return JSON.parse(e)}catch(e){}},Pubsub:function(){var e={};this.emit=function(t){for(var i=[],r=1;r<arguments.length;r++)i.push(arguments[r]);var s=e[t];if(s)for(r=0;r<s.length;r++)s[r].apply(void 0,i)},this.on=function(t,i){e[t]||(e[t]=[]),e[t].push(i)}},randomString:function(e,t){var i,r="";(!e||e<1)&&(e=10);for(var s=0;s<e;s++)t?r+=t[Math.floor(Math.random()*t.length)]:(i=Math.floor(25*Math.random()+97),r+=String.fromCharCode(i));return r},logError:function(e,r,s,n){let o=function(e){let i=e.getUTCFullYear().toString().substr(2,2),r=e.getUTCMonth()+1,s=e.getUTCDate(),n=e.getUTCHours(),o=e.getUTCMinutes(),a=e.getUTCSeconds();return`${i}-${t(r)}-${t(s)} ${t(n)}:${t(o)}:${t(a)}`}(new Date),a=JSON.stringify({id:Date.now(),class:400,code:"frontend_error",number:n.split("").map(e=>e.charCodeAt(0).toString(16).padStart(2,"0")).join(""),fields:{message:JSON.stringify(s),user_id:r,url:JSON.stringify(location.href)}});i("POST","https://track.subiz.net/collect",`${o} app ERROR dashboard ${e} ${n} ${a}`)}}},8193:(e,t,i)=>{var r=i(9798),s=i(9143),n=i(5219),o=i(9);e.exports={sleep:r,loop:s,map:n,batch:o}},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 r=0;r<e.length;r++)i.push(t(e[r],r));return i}if("object"==typeof e){var s=Object.keys(e);for(r=0;r<s.length;r++){var n=s[r];i.push(t(e[n],n))}return i}return i}}},9143:e=>{e.exports=function e(t){var i=t();if(!i||!i.then){var r=i;i={then:function(e){e(r)}}}return i.then(function(i){return i?e(t):Promise.resolve()})}},9798:e=>{e.exports=function(e){return new Promise(function(t){setTimeout(t,e)})}},9917:(e,t,r)=>{"use strict";r.r(t),r.d(t,{DEFVAL:()=>_e,DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL:()=>fe,Date:()=>b,XMLHttpRequest:()=>z,agentsOfConvo:()=>D,blockToText:()=>$e,checkRunConditions:()=>ve,clearInterval:()=>S,clearTimeout:()=>C,cloneDeep:()=>I,convoOfEv:()=>P,convoToEv:()=>A,detectLang:()=>Ae,diffDay:()=>Se,diffYear:()=>Ce,each:()=>F,extract:()=>d,extractEmails:()=>l,extractEmojis:()=>c,extractLinks:()=>u,extractPhones:()=>h,extractText:()=>f,filter:()=>L,find:()=>Q,formatCurrency:()=>Ie,getAgentDisplayName:()=>re,getDayName:()=>ye,getMs:()=>Pe,getUrlParameter:()=>Oe,getUserAttr:()=>oe,hslToRgb:()=>a,includes:()=>U,isBlockEmpty:()=>Fe,isConvoSeen:()=>R,isEmail:()=>te,isEmptyBlock:()=>We,isEmptyMessage:()=>Ne,isNumber:()=>ee,isPhone:()=>K,isURL:()=>Y,isUserBanned:()=>se,js2css:()=>me,last:()=>ie,map:()=>$,merge:()=>j,noop:()=>ce,norm:()=>ae,offsetToMin:()=>xe,orderBy:()=>Z,orderByF:()=>X,parseJSON:()=>_,pipeExtracts:()=>p,preloadImg:()=>ke,preloadWebfonts:()=>we,randomString:()=>M,replaceAll:()=>V,replaceCssVariable:()=>he,replaceCssVariablePlugin:()=>le,requestAnimationFrame:()=>w,rgbToHsl:()=>o,sameDay:()=>ze,scrollIntoViewIfNeeded:()=>Le,setCss:()=>pe,setInterval:()=>x,setTimeout:()=>k,setUserAttr:()=>ne,shortTime:()=>Te,size:()=>N,sleep:()=>je,startsWith:()=>W,stringify:()=>v,throttle:()=>G,tokenize:()=>de,trim:()=>H,trimStart:()=>B,unicodeToAscii:()=>Me,unixSec:()=>Ee,usersOfConvo:()=>q});var s=r(3259);const n=r(318);function o(e,t,i){e/=255,t/=255,i/=255;var r,s,n=Math.max(e,t,i),o=Math.min(e,t,i),a=(n+o)/2;if(n==o)r=s=0;else{var c=n-o;switch(s=a>.5?c/(2-n-o):c/(n+o),n){case e:r=(t-i)/c+(t<i?6:0);break;case t:r=(i-e)/c+2;break;case i:r=(e-t)/c+4}r/=6}return[r,s,a]}function a(e,t,i){var r,s,n;if(0==t)r=s=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;r=c(a,o,e+1/3),s=c(a,o,e),n=c(a,o,e-1/3)}return[255*r,255*s,255*n]}function c(e){for(var t=[],i=0;i<e.length;i++)for(var r=0;r<De.length;r++)if(e.indexOf(De[r],i)===i){t.push({index:i,length:De[r].length}),i+=De[r].length-1;break}return t}function u(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,r=[];t=i.exec(e);)r.push({index:t.index,length:i.lastIndex-t.index});return r}function l(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,r=[];t=i.exec(e);)r.push({index:t.index,length:i.lastIndex-t.index});return r}function h(e){e=e||"";for(var t="",i={},r=0;r<e.length;r++){var s=e.charAt(r);if("."===s||"-"===s||" "===s){var n=r>0?e.charAt(r-1):"-",o=r<e.length-1?e.charAt(r+1):"-";-1!=="0123456789".indexOf(n)&&-1!=="0123456789".indexOf(o)||(i[(t+=s).length-1]=r)}else i[(t+=s).length-1]=r}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 d(e,t,i){if(!e)return[];var r=[],s=0,n=t(e);if(0===N(n))return[{type:"text",text:e}];F(n,t=>{r.push({type:"text",text:e.substr(s,t.index-s)}),r.push({type:i,text:e.substr(t.index,t.length)}),s=t.index+t.length});var o=ie(n);return r.push({type:"text",text:e.substr(o.index+o.length,e.length-o.index+o.length)}),L(r,e=>""!==e.text)}function p(e,t){var i=[];if(0===N(t))return[{type:"text",text:e}];var r=t.shift();return F(d(e,r,r.type),e=>{if("text"!==e.type)return i.push(e);i=i.concat(p(e.text,t.slice()))}),i}function f(e){var t=u;t.type="link";var i=l;i.type="email";var r=h;r.type="phone";var s=c;return s.type="emoji",p(e,[t,i,r,s])}function _(e){try{return y(e)}catch(e){}}var m=document.createElement("iframe");m.style.display="none",document.documentElement.appendChild(m);const g=m.contentDocument.createElement("div");m.contentDocument.body.appendChild(g);var v=m.contentWindow.JSON.stringify,y=m.contentWindow.JSON.parse,b=m.contentWindow.Date,w=m.contentWindow.requestAnimationFrame,k=m.contentWindow.setTimeout.bind(m.contentWindow),x=m.contentWindow.setInterval.bind(m.contentWindow),S=m.contentWindow.clearInterval.bind(m.contentWindow),C=m.contentWindow.clearTimeout.bind(m.contentWindow),z=m.contentWindow.XMLHttpRequest;const T=z.prototype.open,E=z.prototype.send;function P(e){return e?s.get(e,"data.conversation.id",s.get(e,"data.message.conversation_id")):""}function A(e,t){if(!t)return"";switch(t.type){case"message_sent":case"message_updated":case"message_pong":return s.set(t,"data.message.conversation_id",e);case"ticket_updated":return s.set(t,"data.ticket.conversation_id",e);default:return s.set(t,"data.conversation.id",e)}}function O(e){return e&&"object"==typeof e&&!Array.isArray(e)}function j(e,...t){if(!t.length)return e;const i=t.shift();if(O(e)&&O(i))for(const t in i)O(i[t])?(e[t]||Object.assign(e,{[t]:{}}),j(e[t],i[t])):Object.assign(e,{[t]:i[t]});return j(e,...t)}function I(e){if(e!==Object(e))return e;var t=v(e);return void 0!==t?y(t):void 0}function M(e){var t,i="";(!e||e<1)&&(e=10);for(var r=0;r<e;r++)t=Math.floor(25*Math.random()+97),i+=String.fromCharCode(t);return i}function L(e,t){if(!e)return[];if(!t)return e;var i=[];if(Array.isArray(e)){for(let r=0;r<e.length;r++)t(e[r],r)&&i.push(e[r]);return i}if("object"==typeof e){var r=Object.keys(e);for(let n=0;n<r.length;n++){var s=r[n];t(e[s],s)&&i.push(e[s])}return i}return i}function U(e,t){if(!e)return!1;var i="string"==typeof e||e instanceof String;return!(!Array.isArray(e)&&!i)&&e.includes(t)}function $(e,t){if(!e)return[];t||(t=e=>e);var i=[];if(Array.isArray(e)){for(let r=0;r<e.length;r++)i.push(t(e[r],r));return i}if("object"==typeof e){var r=Object.keys(e);for(let n=0;n<r.length;n++){var s=r[n];i.push(t(e[s],s))}return i}return i}function F(e,t){return $(e,t)}function q(e){return e?$(L(e.members,e=>"user"===e.type),e=>e.id):[]}function R(e,t){if("ended"===e.state)return!0;let i=e.last_message_sent;if(!i)return!0;if(s.get(i,"by.id")===t)return!0;let r=Q(e.members,e=>e.id===t);return!r||Pe(i.created)<Pe(r.seen_at)}function D(e,t){return e?$(L(e.members,e=>t?"agent"===e.type||"bot"===e.type:"agent"===e.type),e=>e.id):[]}function W(e,t){return((e||"")+"").startsWith(t)}function N(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 B(e,t){for(e=(e||"")+"";e.charAt(0)===t;)e=e.substr(1);return e}function G(e,t,i){var r,s,n,o=null,a=0;i||(i={});var c=function(){a=!1===i.leading?0:(new b).getTime(),o=null,n=e.apply(r,s),o||(r=s=null)};return function(){var u=(new b).getTime();a||!1!==i.leading||(a=u);var l=t-(u-a);return r=this,s=arguments,l<=0||l>t?(o&&(C(o),o=null),a=u,n=e.apply(r,s),o||(r=s=null)):o||!1===i.trailing||(o=k(c,l)),n}}function Q(e,t){if(e)return e[J(e,t)]}function J(e,t){if(!e)return-1;if(!t)return-1;if(Array.isArray(e)){for(let i=0;i<e.length;i++)if(t(e[i],i))return i;return-1}if("object"==typeof e){var i=Object.keys(e);for(let s=0;s<i.length;s++){var r=i[s];if(t(e[r],r))return r}}return-1}function Z(e,t,i){var r=[];return F(e,e=>r.push(e)),r.sort((e,r)=>{if(e[t]===r[t])return 0;var s=e[t]<r[t]?-1:1;return"desc"===i?-s:s}),r}function X(e,t,i){var r=[];return F(e,e=>r.push(e)),r.sort((e,r)=>{let s=t(e),n=t(r);if(s===n)return 0;var o=s<n?-1:1;return"desc"===i?-o:o}),r}function K(e){return/^[\+]?[(]?[0-9]{2,3}[)]?[-\s\.]?[0-9]{3,4}[-\s\.]?[0-9]{4,6}$/im.test(String(e))}function Y(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 ee(e){return/^\d+$/.test(String(e))}function te(e){return/^(([^<>()[\]\\.,;:\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(String(e).toLowerCase())}function ie(e){var t=null==e?0:e.length;return t?e[t-1]:void 0}function re(e,t){return s.get(t,"fullname")||s.get(t,"email")||s.get(e,"name")||"Agent"}function se(e){return oe(e,"is_ban","boolean")}function ne(e,t){if(e&&s.get(t,"key")){e.attributes=e.attributes||[];var i=J(e.attributes,e=>e&&e.key===t.key);-1!==i?e.attributes[i]=t:e.attributes.push(t)}}function oe(e,t,i){if(!e||!e.attributes)return;let r;return F(e.attributes,e=>{e&&e.key===t&&("datetime"===i&&(r=e.datetime),"boolean"===i&&(r=e.boolean),"number"===i&&(r=e.number),"text"===i&&(r=e.text),"list"===i&&(r=[e.text].concat(e.other_values)))}),r}function ae(e){return(e=e||"").trim().toLowerCase()}function ce(){}function ue(e){return("string"==typeof e||e instanceof String)&&(e=e.trim().replace(/;+$/,"")),e}function le(e,t){var i=[e];let r=t.spacer||10;t=Object.assign({},t,{spacer:r+"px",spacer0:r/2+"px",spacer2:2*r+"px",spacer3:3*r+"px"}),i=de(i,"'@font_family'"),i=de(i,"'@font_size'"),i=de(i,"'@text_color'"),i=de(i,"'@faded_text_color'"),i=de(i,"'@primary_color'"),i=de(i,"'@background'"),i=de(i,"'@spacer'"),i=de(i,"'@spacer0'"),i=de(i,"'@spacer2'"),i=de(i,"'@spacer3'");let n=Re(s.get(t,"primary_color")||s.get(_e,"primary_color"));n||(n={red:238,blue:238,green:238});let c=o(n.red,n.green,n.blue)[0],[u,l,h]=a(c,.25,.95);_e.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=s.get(t,_)||s.get(_e,_)||"";d.push(m)}else d.push(f)}return d.join("")}function he(e,t){var i=[e];i=de(i,"'@primary_color'"),i=de(i,"'@primary_color_faded'"),i=de(i,"@esc-primary-color-esc"),i=de(i,"'@secondary_color'"),i=de(i,"'@background'"),i=de(i,"'@text_color'"),i=de(i,"'@width'"),i=de(i,"'@height'"),i=de(i,"'@desktop_button.width'"),i=de(i,"'@desktop_button.height'"),i=de(i,"'@desktop_button.background'"),i=de(i,"'@desktop_button.border_radius'"),i=de(i,"'@desktop_button.margin_x'"),i=de(i,"'@desktop_button.margin_y'"),i=de(i,"'@mobile_button.width'"),i=de(i,"'@mobile_button.height'"),i=de(i,"'@mobile_button.background'"),i=de(i,"'@mobile_button.border_radius'"),i=de(i,"'@mobile_button.margin_x'"),i=de(i,"'@mobile_button.margin_y'"),i=de(i,"'@widget_position'"),i=de(i,"'@z_index'"),i=de(i,"'@z_index_2'"),i=de(i,"'@z_index_3'"),i=de(i,"'@z_index_4'"),i=de(i,"'@z_index_5'"),i=de(i,"'@form_background_color'"),i=de(i,"'@form_header_font_size'"),i=de(i,"'@form_header_font_family'"),i=de(i,"'@form_desc_font_size'"),i=de(i,"'@form_desc_font_family'"),i=de(i,"'@form_input_label_font_size'"),i=de(i,"'@form_input_label_font_family'");let r=Re(s.get(t,"primary_color")||s.get(_e,"primary_color"));r||(r={red:238,blue:238,green:238});let n=o(r.red,r.green,r.blue)[0],[c,u,l]=a(n,.25,.95);_e.primary_color_faded=`rgb(${c},${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);_=ue(_=s.get(t,f)||s.get(_e,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"!==s.get(t,"window_mode")?h.push(_):h.push("100%")}else _=s.get(t,"z_index")||s.get(_e,"z_index"),h.push(_+5);else _=s.get(t,"z_index")||s.get(_e,"z_index"),h.push(_+4);else{var _=s.get(t,"z_index")||s.get(_e,"z_index");h.push(_+3)}else{_=s.get(t,"z_index")||s.get(_e,"z_index");h.push(_+2)}else{_=s.get(t,"primary_color")||s.get(_e,"primary_color");h.push(encodeURIComponent(ue(_)))}else h.push(p)}return h.join("")}function de(e,t){if(!e||!e.length)return[];var i=[];for(let n=0;n<e.length;n++){var r=e[n];if("string"==typeof r){var s=r.split(t);for(let e=0;e<s.length;e++)i.push(s[e]),i.push({type:t});i.pop()}else i.push(r)}return i}function pe(e,t,i){i=V(i,"#sbz92","#"+e),t.styleSheet?t.styleSheet.cssText=i:(t.innerHTML="",t.appendChild(document.createTextNode(i)))}z.prototype.open=function(e,t,i,r,s){return this._url=t,T.apply(this,arguments)},z.prototype.send=function(e){let t=this.onreadystatechange;return this.onreadystatechange=function(e,i,r){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,r))},E.apply(this,arguments)},n.env.XMLHttpRequest=z;const fe="https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5",_e={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:fe,margin_x:.3,margin_y:.3},mobile_button:{width:.3,height:.3,border_radius:"100%",background_mask_url:fe,margin_x:.3,margin_y:.3},widget_position:"fixed",z_index:2e9};function me(e,t,i){var r={};for(var s in e)e.hasOwnProperty(s)&&(t&&t.length>0&&-1===t.indexOf(s)||("string"==typeof e[s]?r[s]=H(e[s]):r[s]=e[s]));e=r;let n="";for(var s in e)if(e.hasOwnProperty(s)){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[s]){let t=e[s]+"";$(i,(e,i)=>{-1!==t.indexOf(i)&&(t=V(t,i,e))}),n+=V(s,"_","-")+":"+t+" !important;","color"===s&&(n+="-webkit-text-fill-color: "+t+" !important;")}}return n}function ge(){var e=!!window.opr&&!!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),r=!i&&!!window.StyleMedia,s=!(!window.chrome||!window.chrome.webstore&&!window.chrome.runtime);s||(s=navigator.userAgent.indexOf("Chrome"));var n=s&&-1!=navigator.userAgent.indexOf("Edg"),o=(s||e)&&!!window.CSS;return e?"opera":t?"firefox":i?"ie":r||n?"edge":s?"chrome":o?"blink":"unknown"}function ve(e,t,i,r){var n=r.matchAccount()||{},o=r.matchLocation()||{};if(!function(e,t){return!(t&&(s.get(e,"once_per_user")||s.get(e,"once_per_session")&&ze(t.created,b.now())||s.get(e,"interval_sec")&&s.get(e,"interval_sec")>(b.now()-t.created)/1e3))}(e,i))return!1;for(let e=0;e<N(t);e++){var a=t[e];switch(a.key){case"url":let e=L(a.exclude_urls,e=>ae(e));if(N(e)>0&&Q(e,e=>ae(window.location.href).indexOf(ae(e))>-1))return!1;let t=L(a.urls,e=>ae(e));if(N(t)>0&&!Q(t,e=>ae(window.location.href).indexOf(ae(e))>-1))return!1;break;case"url_path":let i=L(a.exclude_url_paths,e=>ae(e));if(N(i)>0){let e=new URL(window.location.href).pathname||"";if("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),Q(i,t=>("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),e===t)))return!1}let h=L(a.url_paths,e=>ae(e));if(N(h)>0){let e=new URL(window.location.href).pathname||"";if("string"==typeof e&&e.endsWith("/")&&(e=e.substring(0,e.length-1)),!Q(h,t=>("string"==typeof t&&t.endsWith("/")&&(t=t.substring(0,t.length-1)),e===t)))return!1}break;case"browser":if(N(a.browsers)>0){var c=ge();if(!Q(a.browsers,e=>ae(e)===ae(c)))return!1}break;case"location":if(N(a.exclude_locations)>0&&Q(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(N(a.locations)>0&&!Q(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&&r.new_visitor)return!1;if(!a.returning_visitor&&!r.new_visitor)return!1;break;case"user_is_a_contact":let d=s.get(r.matchUser(),"attributes",[]),p=Q(d,e=>"emails"===e.key&&attr.text&&"related_email"===e.key&&attr.text),f=Q(d,e=>"phones"===e.key&&attr.text&&"related_phone"===e.key&&attr.text),m=p||f;if(a.user_is_a_contact&&!m)return!1;if(!a.user_is_a_contact&&m)return!1;break;case"device_type":if(N(a.device_types)>0){let e="desktop";if(r.isMobile()&&(e="mobile"),r.isTablet()&&(e="tablet"),!Q(a.device_types,t=>ae(t)===ae(e)))return!1}break;case"referer":if(N(a.exclude_referers)>0&&Q(a.exclude_referers,e=>ae(document.referrer).indexOf(ae(e))>-1))return!1;if(N(a.urls)>0&&!Q(a.referers,e=>ae(document.referrer).indexOf(ae(e))>-1))return!1;break;case"source":if(N(a.sources)>0){let e=r.matchTrafficSource()||"direct";if(!Q(a.sources,t=>ae(t)===ae(e)))return!1}break;case"user_attribute":case"user":let g,v=s.get(r.matchUser(),"attributes",[]),y=s.get(a,"user.operator");F(v,e=>{e&&e.key===s.get(a,"user.key")&&(g=e.datetime||e.boolean||e.number||e.text||e.list)});let w=!0;switch(y){case"cons":let e=_(a.value)||[];if(0===N(e))return!1;w=!!Q(e,e=>ae(g).indexOf(ae(e))>-1);break;case"notEmpty":w=!!g;break;case"empty":w=!g;break;case"true":w=!0===g||"true"===g;break;case"false":w=!g||!1===g||"false"===g}if(!w)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(N(a.days_of_week)>0&&!Q(a.days_of_week,e=>ae(ye((new b).getDay()))===ae(e)))return!1;if(N(a.minutes_of_day)>0&&N(a.minutes_of_day)%2==0){var u=new b,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 ye(e){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][e]}let be={};function we(e,t){for(var i=0;i<e.length;i++){let t=e[i];if(t&&!be[t]){be[t]=!0;for(var r=0;r<2;r++){let e=[400,500][r],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,k(()=>i.remove(),3e3)}}}}function ke(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?W(e,"/")||W(e,"data:")?e:(W(e,"http://")||W(e,"https://")||W(e,"//")||(e=H(t)+"/"+B(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 xe(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 r=parseInt(t[1]);return r<0||r>59?0:60*i+r}function Se(e,t,i){var r=-(new b).getTimezoneOffset();i&&(r=xe(i));var s=new b(e).getTime(),n=new b(t).getTime(),o=Math.ceil((s/60/1e3+r)/60/24),a=Math.ceil((n/60/1e3+r)/60/24);return Math.abs(o-a)}function Ce(e,t,i){var r=-(new b).getTimezoneOffset(),s=-(new b).getTimezoneOffset();i&&(s=xe(i));var n=new b(e).getTime()+60*(s-r)*1e3,o=new b(t).getTime()+60*(s-r)*1e3;return Math.abs(new b(n).getYear()-new b(o).getYear())}function ze(e,t,i){return 0===Se(e,t,i)}function Te(e,t,i,r){var n=-(new b).getTimezoneOffset(),o=n;t&&(o=xe(t));var a=new b(Pe(e));let c=new b(a);c.setMinutes(a.getMinutes()+o-n),i||(i=new b);let u=c.getHours(),l=c.getMinutes(),h=s.get(navigator,"languages.0","en-US");r&&(h=r);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),ze(a,i,t)?u+":"+l:Se(a,i,t)<=5?d+", "+u+":"+l:0===Ce(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 b(e).getTime()):e=0,e>1e18?Math.floor(e/1e6):e>1e15?Math.floor(e/1e3):e>1e12?e:1e3*e}function Ae(){let e=Oe("sbz_locale"),t=document.getElementsByTagName("html")[0].getAttribute("xml:lang")||document.getElementsByTagName("html")[0].getAttribute("lang"),i=navigator.language;return e||t||i}function Oe(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var je=e=>new Promise(t=>k(t,e));function Ie(e,t="VND"){let i=Ue.find(e=>e.code===t)||{name:"Dong",code:"VND",symbol:"₫"},r="",s="";return"VND"===t?(r="",s=" "+i.symbol):(r=i.symbol+" ",s=""),e?r+(e=Math.round(e)).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")+s:`${r}0${s}`}function Me(e){return(e=(e+="").replaceAll("đ","d").replaceAll("Đ","D")).normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function Le(e){centerIfNeeded=0===arguments.length||!!centerIfNeeded;var t=e.parentNode,i=window.getComputedStyle(t,null),r=parseInt(i.getPropertyValue("border-top-width")),s=parseInt(i.getPropertyValue("border-left-width")),n=e.offsetTop-t.offsetTop<t.scrollTop,o=e.offsetTop-t.offsetTop+e.clientHeight-r>t.scrollTop+t.clientHeight,a=e.offsetLeft-t.offsetLeft<t.scrollLeft,c=e.offsetLeft-t.offsetLeft+e.clientWidth-s>t.scrollLeft+t.clientWidth,u=n&&!o;(n||o)&&centerIfNeeded&&(t.scrollTop=e.offsetTop-t.offsetTop-t.clientHeight/2-r+e.clientHeight/2),(a||c)&&centerIfNeeded&&(t.scrollLeft=e.offsetLeft-t.offsetLeft-t.clientWidth/2-s+e.clientWidth/2),(n||o||a||c)&&!centerIfNeeded&&e.scrollIntoView(u)}const Ue=[{code:"USD",symbol:"$"},{code:"VND",symbol:"₫"}];function $e(e){return function(e){if(!e||!e.type)return"";let t="";if("bullet_list"==e.type||"ordered_list"==e.type)return $(e.content,r=>{preifx="\n* ","ordered_list"==e.type&&(prefix=i+"\n. "),t+=prefix+$e(r).trim()}),t;if("heading"!=e.type&&"paragraph"!=e.type||(t+="\n"),""==e.type||"text"==e.type||"link"==e.type||"mention-agent"==e.type||"dynamic-field"==e.type)return t+e.text;if("horizontal_rule"==e.type)return t+"\n---\n";if("emoji"==e.type){let i;if(N(e.attrs)>0&&(i=e.attrs.code),""==i&&(i=e.text),""!=i){let e=Q(LEXICAL_EMOJI_LIST,e=>e.code===i);s.get(e,"text",i)}return t}return $(e.content,e=>{t+=$e(e)}),t}(e).trim()}function Fe(e){return qe(e)}function qe(e={}){if(!N(e.content))return!(e.text||"").trim();let t=!0;return $(e.content,e=>{t=t&&qe(e)}),t}function Re(e){if(!e||!e.split)return"";g.style.color=e;const t=m.contentWindow.getComputedStyle(g).color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?{red:parseInt(t[1]),green:parseInt(t[2]),blue:parseInt(t[3])}:null}let De=["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 We(e){if(!e||!e.type)return!0;let t=N(L($(e.content,e=>We(e)),e=>!e))>0;return!H(e.text)&&!t}function Ne(e){return!e||!(e.text||!We(e.block)||N(e.attachments))||void 0}De=$(De,e=>":"+e+":")}},s={};function n(e){var t=s[e];if(void 0!==t)return t.exports;var i=s[e]={id:e,exports:{}};return r[e].call(i.exports,i,i.exports,n),i.exports}n.m=r,n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce((t,i)=>(n.f[i](e,t),t),[])),n.u=e=>"198cd86b62f."+e+".js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="@subiz/widget-v4:",n.l=(i,r,s,o)=>{if(e[i])e[i].push(r);else{var a,c;if(void 0!==s)for(var u=document.getElementsByTagName("script"),l=0;l<u.length;l++){var h=u[l];if(h.getAttribute("src")==i||h.getAttribute("data-webpack")==t+s){a=h;break}}a||(c=!0,(a=document.createElement("script")).charset="utf-8",a.timeout=120,n.nc&&a.setAttribute("nonce",n.nc),a.setAttribute("data-webpack",t+s),a.src=i),e[i]=[r];var d=(t,r)=>{a.onerror=a.onload=null,clearTimeout(p);var s=e[i];if(delete e[i],a.parentNode&&a.parentNode.removeChild(a),s&&s.forEach(e=>e(r)),t)return t(r)},p=setTimeout(d.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=d.bind(null,a.onerror),a.onload=d.bind(null,a.onload),c&&document.head.appendChild(a)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.p="https://vcdn.subiz-cdn.com/widget-v4/public/",(()=>{var e={325:0};n.f.j=(t,i)=>{var r=n.o(e,t)?e[t]:void 0;if(0!==r)if(r)i.push(r[2]);else{var s=new Promise((i,s)=>r=e[t]=[i,s]);i.push(r[2]=s);var o=n.p+n.u(t),a=new Error;n.l(o,i=>{if(n.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var s=i&&("load"===i.type?"missing":i.type),o=i&&i.target&&i.target.src;a.message="Loading chunk "+t+" failed.\n("+s+": "+o+")",a.name="ChunkLoadError",a.type=s,a.request=o,r[1](a)}},"chunk-"+t,t)}};var t=(t,i)=>{var r,s,[o,a,c]=i,u=0;if(o.some(t=>0!==e[t])){for(r in a)n.o(a,r)&&(n.m[r]=a[r]);c&&c(n)}for(t&&t(i);u<o.length;u++)s=o[u],n.o(e,s)&&e[s]&&e[s][0](),e[s]=0},i=self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[];i.forEach(t.bind(null,0)),i.push=t.bind(null,i.push.bind(i))})(),(()=>{"use strict";var e={};n.r(e),n.d(e,{trackAreaClicked:()=>o,trackExitIntent:()=>r,trackInactivity:()=>a,trackScrollingPercentage:()=>s,trackTimeOnPage:()=>u});var t=n(9917),i=n(9917);function r(e){let t=i=>{i.clientY>10||(e&&e(),document.removeEventListener("mouseout",t))};document.addEventListener("mouseout",t)}function s(e,t){let i=r=>{let s=r.srcElement.scrollingElement?r.srcElement.scrollingElement.scrollTop:r.srcElement.scrollTop,n=r.srcElement.scrollingElement?r.srcElement.scrollingElement.scrollHeight:r.srcElement.scrollHeight;s>0&&n>0&&(s+window.innerHeight)/n>=e&&(t&&t(),window.removeEventListener("scroll",i,!1))};window.addEventListener("scroll",i,!1)}function o(e,t){e&&(e=e||"",i.map(e.split("\n"),e=>{(e=i.trim(e))&&function(e,t,i){document.addEventListener("click",function(e){let r=document.querySelectorAll(t),s=e.target;for(let t=0,n=r.length;t<n;t++){let n=s,o=r[t];for(;n&&n!==document;){if(n===o)return i.call(o,e);n=n.parentNode}}})}(0,e,t)}))}function a(e=0,t){let r=["scroll","keyup","keydown","mousemove","mousewheel","mouseenter","mouseover","mousedown","touchstart","touchmove","touchenter"],s=0,n=()=>{s=0},o=i.setInterval(()=>{if(s++,!(s<e)){t&&t();for(let e of r)document.removeEventListener(e,n,!1);i.clearInterval(o)}},1e3);for(let e of r)document.addEventListener(e,n,!1)}let c=i.Date.now();function u(e=0,t){if(e<1)return i.setTimeout(function(){t(e)},100);let r=i.setInterval(()=>{let s=(i.Date.now()-c)/1e3;s<e||(t&&t(s),i.clearInterval(r))},200)}var l={};(l=Object.assign(l,t)).Gate=n(1139).A,l.Mutex=n(5369).A;var h=n(3259);l.get=h.get,l.set=h.set,l.Pubsub=n(6463).A;const d=l=Object.assign(l,e);function p(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 f=n(318);function _(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=d.stringify(i.body)),t(!0)}const m=class{constructor(e,t){p(this,"listConversations",e=>this.apireq.addQuery("user_id",this.uid).addQuery("integration_id",`${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`)),p(this,"listMessages",(e,t,i)=>this.apireq.addQuery("limit",t).addQuery("start_id",i).get(`/accounts/${this.accid}/conversations/${e}/messages`)),p(this,"ajax",f),p(this,"start",e=>{let t={touchpoint:{channel:"subiz",source:"web"}};return d.each(e,(e,i)=>{t[i]=e}),this.apireq.post(`/accounts/${this.accid}/conversations`,t)}),p(this,"sendConvoEvent",(e,t)=>this.apireq.addQuery("x-referer",d.get(location,"origin","")).post(`/accounts/${this.accid}/conversations/${e}/events`,t)),p(this,"createPostback",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/postbacks`,t)),p(this,"markAsReceived",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/receive`)),p(this,"markAsSeen",(e,t)=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/messages/${t}/seen`)),p(this,"getConversation",e=>this.apireq.get(`/accounts/${this.accid}/conversations/${e}`)),p(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/languages/${e}`)),p(this,"sendEvent",e=>this.apireq.addQuery("shorten",!0).addQuery("x-referer",d.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,e)),p(this,"submitForm",(e,t,i,r,s)=>this.apireq.addQuery("x-referer",d.get(location,"origin","")).post(`/accounts/${this.accid}/users/${this.uid}/events`,{by:{id:this.uid,device:i},type:"form_submitted",data:{user:s,form_submission:{user_id:this.uid,form_id:e,page_url:t,submitted_at:d.Date.now(),values:r}}})),p(this,"sendTyping",e=>this.apireq.post(`/accounts/${this.accid}/conversations/${e}/typing`)),p(this,"sendLostFocus",()=>this.apireq.post(`/accounts/${this.accid}/focuses/${this.uid}/delete`)),p(this,"uploadToS3",async e=>{let t=e.name.replace(/\s+/g,"_");var{body:i,error:r}=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,type:e.type}).post("/files");if(r)return{body:i,error:r};let s=i.signed_url,n=i.id,o=await new Promise(t=>{const i=new d.XMLHttpRequest;i.open("PUT",s,!0),i.setRequestHeader("Content-Type",e.mimetype),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:r}=await this.apireq.setBaseUrl("https://api5.subiz.com.vn/4.1").setQuery({"account-id":this.accid}).post(`/files/${n}/uploaded`);return r?{error:r}:{url:d.get(i,"file.url","")}}),p(this,"uploadToS32",async e=>{var{body:t,error:i}=await f.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(r=>i!=this.profile_id?t(!0):r?"error"==r?t(!1):(e.request=e.request.addQuery("x-access-token",r),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:d.get(t,"file.url")}}),p(this,"time",e=>f.setBaseUrl(this.ApiURL).withCredentials(!0).setParser("json").get("/time")),p(this,"updateUser",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`,e)),p(this,"getUser",e=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`)),p(this,"getAccountSetting",e=>{let t=d.get(document,"location.href");return e&&e.bot_id?this.apireq.addQuery("url",t).addQuery("bot_id",e.bot_id).get(`/accounts/${this.accid}/settings`):this.apireq.addQuery("url",t).get(`/accounts/${this.accid}/settings`)}),p(this,"sendImpression",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/impressions`,e)),p(this,"sendConversion",e=>this.apireq.post(`/accounts/${this.accid}/campaigns/${e.campaign_id}/conversions`,e)),p(this,"lookupOrder",e=>f.setBaseUrl(this.ApiURL).setContentType("text/plain").beforeHook(_).setParser("json").addQuery("x-signed-key",e).get("/orders/123")),p(this,"getOrder",e=>this.apireq.get(`/accounts/${this.accid}/orders/`+e)),p(this,"updateOrder",e=>this.apireq.post(`/accounts/${this.accid}/orders/`+e.id,e)),p(this,"fetchShippingAddresses",()=>this.apireq.get(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`)),p(this,"createShippingAddress",e=>this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/shipping-addresses`,e)),p(this,"list_provinces",()=>this.apireq.get(`/accounts/${this.accid}/provinces`)),p(this,"list_districts",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/districts`)),p(this,"list_wards",e=>this.apireq.setQuery(e).get(`/accounts/${this.accid}/wards`)),p(this,"checkFormToken",(e,t)=>this.api41.addQuery("account-id",e).get(`/submissions/${t}`)),p(this,"submitForm2",(e,t,i)=>this.api41.addQuery("account-id",e).post(`/submissions/${t}`,i)),p(this,"suggest_address",e=>this.apireq.setQuery({keyword:e}).get(`/accounts/${this.accid}/addresses`)),p(this,"create_ticket",e=>this.apireq.post(`/accounts/${this.accid}/tickets`,e)),this.refreshLock=new d.Mutex,this.FileURL=t,this.ApiURL=e,this.api41=f.setBaseUrl("https://api.sbz.vn/4.1").withCredentials(!0).setContentType("text/plain").beforeHook(_).setParser("json"),this.apireq=f.setBaseUrl(e).withCredentials(!0).addQuery("v","6").setContentType("text/plain").beforeHook(_).setParser("json").beforeHook((e,t)=>{if(this.token_generator){let i=this.profile_id;return void this.token_generator().then(r=>i!=this.profile_id?t(!0):r?"error"==r?t(!1):(e.request=e.request.addQuery("x-access-token",r),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 f.setBaseUrl(this.ApiURL).withCredentials(!0).addQuery("v","6").addQuery("x-user-ref",this.ref).setParser("json").get(`/accounts/${this.accid}/users/${this.ref}`),-1==d.get(e,"body.error.code","").indexOf("locked_account");t++){if(-1==d.get(e,"body.error.code","").indexOf("user_is_banned")){if(!d.get(e,"body.id")){let e=Math.min(2e3+400*t,6e4);await d.sleep(e);continue}break}await d.sleep(12e4)}return e.error?d.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||!d.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 r,s=this.profile_id;this.token_generator=async e=>{if(await this.refreshLock.lock(),i!=this.tokensession)return void this.refreshLock.unlock();let r,n,o=(d.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&&d.setTimeout(async()=>{let e,r;try{e=await t(s)}catch(e){r=e}i==this.tokensession?(this.last_token=r?"error":e,this.last_token_at=d.Date.now(),this.refreshLock.unlock()):this.refreshLock.unlock()}),this.last_token;try{r=await t(s)}catch(e){n=e}if(i==this.tokensession)return this.last_token=n?"error":r,this.last_token_at=d.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(r=await f.setBaseUrl(this.ApiURL).withCredentials(!0).addQuery("v","6").addQuery("x-access-token",this.last_token).setParser("json").get(`/accounts/${this.accid}/users/${s}`),!d.get(r,"body.id")){let t=Math.min(2e3+100*e,12e4);await d.sleep(t);continue}break}return r.error?d.get(r.body.code)?{error:r.body.code}:r:(this.uid=r.body.id,r.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,r,s,n){return r||(r=void 0),s||(s=void 0),this.sendEvent({by:{id:this.uid,device:e},type:"content_viewed",data:{product:{id:r,source_id:s,url:t,name:i,title:i,sku:n}}})}};let g=n(450),v="undefined"!=typeof window?window.requestIdleCallback:null;v||(v=e=>e());const y=class{constructor(e,t){if(this.localStorage=g,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 r=this.localStorage.key(i);r.startsWith(this.schema+"#"+e+"#")&&(this.allkeys[r]=!0,this.inmem?t.push(this.localStorage.getItem(r)):t.push(d.parseJSON(this.localStorage.getItem(r))))}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 r=this.localStorage.key(i);r.startsWith(this.schema+"#"+e+"#")&&t.push(r)}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),v(()=>{try{this.localStorage.setItem(this.schema+"#"+e+"#"+t,void 0===(r=i)?"null":JSON.stringify(r))}catch(t){this.clear(e)}var r})}};class b{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}}),k(e,(t,i)=>{if(x(t)<50)return;let r=function(e,t){var i=[];return k(e,e=>i.push(e)),i.sort((e,i)=>{if(e[t]===i[t])return 0;var r=e[t]<i[t]?-1:1;return-r}),i}(k(t),["index"]),s=[];for(var n=50;n<r.length;n++)s.push(r[n].full_id),delete t[r[n].id];this.db.removes("items",s),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,r){if(this.dead)return;let s=this.cache[e]||{},n=(w(s)||{}).index||"z";0==x(s)&&(n="");let o={id:t,index:i,value:r,chain:e,full_id:e+":"+t};delete s[o.id],n>o.index+""||(s[o.id]=o,this.cache[e]=s,this.db.put("items",o.full_id,o))}listM(e){if(this.dead)return{};let t=this.cache[e]||{},i={};return k(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 r=this.anchorCache[e]||"";var[s,n,o]=await i(e,r,t);if(o)return{error:o};if(this.dead)return{error:"dead"};let a=this.cache[e]||{};return 0===s.length?{end:!0}:(s.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,{})}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,r=Object.keys(e)[0];for(var s=0;s<t.length;s++){let n=e[t[s]]&&e[t[s]].index||-1/0;n>i&&(i=n,r=t[s])}return e[t[r]]}(this.listM(e))||{},r=i.index;r||(r=Date.now());for(var s="",n={};;){if(this.dead)return;let[i,o,a]=await t(e,s,50);if(a)return;if(this.dead)return;if(i.map(t=>{n[t.id]=Object.assign({},t,{chain:e,full_id:e+":"+t.id})}),0===i.length||o===s)break;if(n.length>=200){let t=this.cache[e]||{},i=[];k(t,t=>{t.chain===e&&i.push(t.full_id)}),this.db.removes("items",i),this.cache[e]={};break}if((w(n)||{}).index<=r){s=this.anchorCache[e]||o;break}s=o}for(var o=0;o<Object.keys(n).length;o++){let e=n[Object.keys(n)[o]];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 w(e){if(!e)return;let t=Object.keys(e);if(!t.length)return;let i=1/0,r=Object.keys(e)[0];for(var s=0;s<t.length;s++){let n=e[t[s]]&&e[t[s]].index||1/0;n<i&&(i=n,r=t[s])}return e[r]}function k(e,t){if(!e)return[];if(!t)return e;var i=[];if(Array.isArray(e)){for(let r=0;r<e.length;r++)i.push(t(e[r],r));return i}if("object"==typeof e){var r=Object.keys(e);for(let n=0;n<r.length;n++){var s=r[n];i.push(t(e[s],s))}return i}return i}function x(e){return e?void 0!==e.length?e.length:Object.keys(e).length:0}const S=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;let t=Object.keys(this.cache);if(t.length>500){let e=250/t.lenth,r=[];for(var i=0;i<500;i++){if(Math.random()<=e)continue;let s=t[i];delete this.cache[s],r.push(s)}this.db.removes("items",[r])}this.initialized=!0}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})}}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 C(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 z=n(318);function T(e,t){let i=e.request;"text/plain"===i.content_type&&void 0!==i.body&&(i.body=d.stringify(i.body)),t(!0)}const E=Promise.resolve({code:200}),P=class{constructor(e,t){C(this,"listConversations",e=>{let t=A(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:{anchor:"",conversations:[t]},code:200})}),C(this,"listMessages",(e,t,i)=>{let r=function(e,t,i,r){let s=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:r,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",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",idempotency_key:"wrueysyjbhqrkiwhsejpqrwqrdkkyaibajdw",integration_id:s,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:r,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:s,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:s,pongs:[{member_id:i,type:"seen",created:1616213267090}]}}},{id:"evqyiyjzjxzfcsexshcjbbnnf",account_id:e,created:1616213302432,type:"message_sent",by:{id:r,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:s,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:s,pongs:[{member_id:i,type:"seen",created:1616213312110}]}}}]}(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid);return Promise.resolve({body:r,code:200})}),C(this,"ajax",z),C(this,"start",e=>E),C(this,"sendConvoEvent",(e,t)=>E),C(this,"createPostback",(e,t)=>E),C(this,"markAsReceived",(e,t)=>E),C(this,"markAsSeen",(e,t)=>E),C(this,"getConversation",e=>Promise.resolve({body:A(this.accid,"csqwudlkftltnbebvq",this.uid,this.agentid),code:200})),C(this,"getLocaleContent",e=>this.apireq.get(`/accounts/${this.accid}/locales/${e}`)),C(this,"sendEvent",e=>E),C(this,"submitForm",(e,t,i,r,s)=>E),C(this,"sendTyping",e=>E),C(this,"sendPresence",e=>E),C(this,"sendContent",e=>E),C(this,"sendLostFocus",e=>E),C(this,"sendContentView",e=>E),C(this,"uploadToS3",async e=>E),C(this,"time",e=>Promise.resolve({code:200,body:(new d.Date).toISOString()})),C(this,"updateUser",e=>E),C(this,"getUser",e=>Promise.resolve({code:200,body:{id:"usqzgtgfake",attributes:[{key:"fullname",text:"Kiều Thanh"}]}})),C(this,"getAccountSetting",()=>this.apireq.get(`/accounts/${this.accid}/settings`)),C(this,"sendImpression",e=>E),C(this,"sendConversion",e=>E),this.FileURL=t,this.apireq=z.setBaseUrl(e).setContentType("text/plain").beforeHook(T).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 A(e,t,i,r){return{id:t,account_id:e,created:1610452894916,members:[{type:"user",id:i,membership:"active",invited_by:{id:i,type:"user"}},{type:"agent",id:r,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 O=class{onEvent(){}onInterrupted(){}subscribe(){}stop(){}getStatus(){return"active"}reconnect(){}};function j(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 I=n(8193),M=n(2839),L=n(5672);L.defaults.path="/",L.expiresMultiplier=86400,L.defaults.expires=3650;let U=n(450);const $=d.Date.now();class F{constructor(e,t,i,r,s){if(j(this,"inmem",!1),j(this,"cookie",L),j(this,"getConnectionStatus",()=>this.connectionStatus),j(this,"_currentViewingProduct",{}),j(this,"new_visitor",!0),j(this,"matchUser",()=>{if(this.cache)return this._touchAcc(),this.cache.match("user")}),j(this,"suggest_addresses",e=>this.api.suggest_address(e)),j(this,"matchAccount",()=>this.cache.match("account")),j(this,"matchPaymentMethods",()=>this.cache.match("payment_methods")),j(this,"matchUnread",()=>{let e=this.matchUser();if(!e||!e.id)return;let t=this.matchConvo("*"),i=0;return d.map(t,t=>{d.isConvoSeen(t,e.id)||i++}),i}),j(this,"matchPlugin",()=>d.size(this.forcePlugins)>0?d.cloneDeep(this.forcePlugins):d.cloneDeep(this.cache.match("plugin"))||{}),j(this,"device",{}),j(this,"browserVisibility","visible"),j(this,"matchAgent",e=>{let t=this.cache.match("agent")||{};return"*"===e?t:t[e]}),j(this,"matchConvo",e=>{if(e)return"*"===e?(this._touchAcc(),d.filter(this.cache.all(),(e,t)=>t.startsWith("convo_")).concat(d.map(this.lightConvos))):e.startsWith("cslight")?this.lightConvos[e]:(this.isInsync(e)||this.fetchConvo(e),this.cache.match("convo_"+e))}),j(this,"fetchConvo",async e=>{if(!e)return;if(e.startsWith("cslight"))return;if(this._die)return H;if(await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0),this.isInsync(e))return this.reconnectGate.open();this.markSync(e);let{body:t,error:i}=await this.api.getConversation(e);return t&&!i&&this._setConvo(t),this.reconnectGate.open()}),j(this,"list_provinces",()=>this.api.list_provinces()),j(this,"list_districts",e=>this.api.list_districts(e)),j(this,"list_wards",e=>this.api.list_wards(e)),j(this,"outofmsgM",{}),j(this,"listEvents",e=>{if(e&&"*"!==e&&"string"==typeof e)return e.startsWith("cslight")?d.get(this.lightConvos,[e,"events"],[]):this.chain.listM(e)}),j(this,"fetchMoreEvents",async e=>{if(e){if(e.startsWith("cslight"))return[[],""];if(!this.isInsync("events"+e)){if(await this.readyGate.entry(),await this.reconnectGate.entry(void 0,!0),this.isInsync("events"+e))return this.reconnectGate.open(),{};this.markSync("events"+e),await this.chain.reload(e,()=>[[],""]);let t=await this._doFetchMsg(e);return this.reconnectGate.open(),t}return this._doFetchMsg(e)}}),j(this,"_doFetchMsg",async e=>{let{error:t}=await this.chain.fetchMore(e,150,async(t,i,r)=>{if(this.outofmsgM[e])return[[],""];let[s,n,o,a]=await this.listmessageapi(t,i,r);return a&&(this.outofmsgM[e]=!0),[s,n,o]});return this.pubsub.publish("account"),{error:t}}),j(this,"matchLocation",()=>this.cache.match("location")||{}),j(this,"matchBot",()=>this.cache.match("bot")||{}),j(this,"readyGate",new d.Gate),j(this,"convoGate",new d.Gate(!0)),j(this,"reconnectGate",new d.Gate(!0)),j(this,"wsGate",new d.Gate(!0)),j(this,"matchLastview",()=>{let e=this.kv.match("lastview")||{},t=this.cache.match("user")||{};return t.id?e.user_id!=t.id?{}:e:{}}),j(this,"matchIsOpen",()=>!!this.kv.match("isopen")),j(this,"matchHasManuallyClosed",()=>!!this.kv.match("hasManuallyClosed")),j(this,"matchClosePreviewAt",()=>this.kv.match("close_preview_at")||0),j(this,"checkFormToken",(e,t)=>this.api.checkFormToken(e,t)),j(this,"submitForm2",(e,t,i)=>this.api.submitForm2(e,t,i)),j(this,"sendPresence",d.throttle(async()=>this._die?H:(await this.readyGate.entry(),d.get(this.cache.match("user"),"id")&&!d.isUserBanned(this.cache.match("user"))&&this._track_page_view?"visible"===this.browserVisibility&&document.hasFocus()?void this.api.sendContentView(this.device,location.href,document.title,this._currentViewingProduct.id,this._currentViewingProduct.source_id,this._currentViewingProduct.sku):this.api.sendLostFocus():void 0),1e3,{leading:!1})),j(this,"now",()=>d.Date.now()+this.timeDiff),j(this,"seenQueue",[]),j(this,"matchTrafficSource",()=>this.kv.match("traffic_source")),j(this,"_alreadyReceived",{}),j(this,"_typing",d.throttle(e=>this.api.sendTyping(e),3e3,{trailing:!1})),j(this,"onConvoEvent",(e,t)=>this.pubsub.on2(e,"events",t)),j(this,"onWidgetClose",(e,t)=>this.pubsub.on2(e,"sbz_close_widget",t)),j(this,"seenConvo",e=>{e&&"create"!==e&&this.seenQueue.push(e)}),j(this,"onUpdate",(e,t)=>this.pubsub.on2(e,"account",t)),j(this,"onDestroyed",(e,t)=>this.pubsub.on2(e,"destroy",t)),j(this,"onConnection",(e,t)=>this.pubsub.on2(e,"connection",t)),j(this,"onResetCSS",(e,t)=>this.pubsub.on2(e,"resetCSS",t)),j(this,"onHighlight",(e,t)=>this.pubsub.on2(e,"highlight",t)),j(this,"setHasManuallyClosed",()=>this.kv.put("hasManuallyClosed",!0)),j(this,"setIsOpen",e=>{let t=this.kv.match("isopen");this.kv.put("isopen",e),!t&&e&&D("SUBIZ Chat","Opened","Subiz Windows")}),j(this,"closePreview",()=>this.kv.put("close_preview_at",(new d.Date).getTime())),j(this,"setLastview",(e,t)=>{let i=this.cache.match("user")||{};i.id&&this.kv.put("lastview",{user_id:i.id,view:e,opts:t})}),j(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=s,this.FileURL=t,this._track_page_view=!0,this.device_type="desktop",this.fake?this.api=new P(e,t):this.api=new m(e,t),!r)try{document.cookie,localStorage}catch(e){r=!0}r&&(this.inmem=r,this.cookie=R),W(),this.pubsub=new d.Pubsub,this.kv=new S(new y("sbz2023",this.inmem),"kv"),this.cache=new S(new y("sbz2023",!0),"kv"),this.chain=new b(new y("cbz2023",!0),"ch"),this.getLocaleContent=this.api.getLocaleContent,this.g_haveSentSeenM={},this.last_focused=this.now(),window.addEventListener("blur",()=>{this.last_focused=this.now(),this.sendPresence()}),window.addEventListener("focus",()=>{this.last_focused=0,this.sendPresence()}),window.addEventListener("beforeunload",()=>this.api.sendLostFocus()),this.doNotStartBot=()=>{this._donotstartbot=!0},this.autoStartBot=()=>{this._donotstartbot=!1},this.matchAutoStartBot=()=>!this._donotstartbot,this._presenceInterval1=d.setInterval(()=>{if(this._die)return d.clearInterval(this._presenceInterval1);"visible"===this.browserVisibility&&document.hasFocus()&&this.sendPresence()},2e4),this._presenceInterval2=d.setInterval(()=>{if(this._die)return d.clearInterval(this._presenceInterval2);"visible"===this.browserVisibility&&document.hasFocus()||this.last_focused&&this.now()-this.last_focused>18e5||this.sendPresence()},6e4),function(e){var t="hidden";function i(i){var r="visible",s="hidden",n={focus:r,focusin:r,pageshow:r,blur:s,focusout:s,pagehide:s};(i=i||window.event).type in n?e(n[i.type]):e(this[t]?"hidden":"visible")}t in document?document.addEventListener("visibilitychange",i):(t="mozHidden")in document?document.addEventListener("mozvisibilitychange",i):(t="webkitHidden")in document?document.addEventListener("webkitvisibilitychange",i):(t="msHidden")in document?document.addEventListener("msvisibilitychange",i):"onfocusin"in document?document.onfocusin=document.onfocusout=i:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=i,void 0!==document[t]&&i({type:document[t]?"blur":"focus"})}(e=>{this._die||(this.browserVisibility=e,this.sendPresence())}),this.loopTime(),this.device=this.getDeviceInfo();const n=d.setInterval(()=>{let e=this.cache.match("user")||{};if(!e.id)return;var t=this.getDeviceInfo();if(!t.ga_tracking_ids||!t.ga_client_id)return;d.clearInterval(n),this.device=t;let i=t.ga_client_id;i!==d.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 d.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"))}}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 d.cloneDeep(this._currentViewingProduct)}isInsync(e){return d.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){d.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 r=d.get(t.events,"0");r.data.message=e,r.data.message.conversation_id=i,this.pubsub.publish("events",r)})}async overrideAcc(e){this.forceAcc=d.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(),d.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=(r=[],window.ga&&window.ga.getAll?window.ga&&window.ga.getAll?((window.ga.getAll()||[]).forEach(function(e){var t=e.get("trackingId");t&&r.push(t)}),r):[]:r);var r;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||d.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 $}overridePlugin(e){if(this._die)return H;if(!Array.isArray(e))throw"plugins must be be an array";let t={};d.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]=d.Date.now()}async _touchAcc(){this.isInsync("account")||(await this.readyGate.entry(),this.isInsync("account")||this.reconnect())}async init(e,t,i,r){if(this.g_sync={},r&&r.use_subdomain_cookie||window&&window.location&&window.location.hostname&&(L.defaults.domain="."+window.location.hostname),!i){try{i=this.cookie.get("__sbref","")}catch(e){}if(!i){if(!t)try{t=this.cookie.get("__sbmask","")}catch(e){}t?(t.split("@")[0]!=e&&(i=d.randomString(40),this.new_visitor=!0),this.new_visitor=!1,this.cookie.set("__sbmask",t)):(i=d.randomString(40),this.new_visitor=!0)}}return this.cookie.get("__sbref",i)!=i&&(N(),this.clearBrowserData()),this.api.setAuth({accid:e}),i&&this.cookie.set("__sbref",i),this._initResource(e,{accid:e,mask:t,ref:i},{account_id:e,user_ref:i,user_mask:t})}async _initResource(e,t,i){this.g_sync={};let r=await this.api.setAuth(t);return r.error?(console.error(r),r):(this.readyGate.close(),e=(e||"").trim(),this.lightConvos=this.kv.match("light_convos")||{},this.cache=new S(new y("sbz2023",!0),"kv"),this.realtime&&this.realtime.stop(),this.fake?this.realtime=new O:this.realtime=new M(this.RealtimeURL,i,V),this.realtime.onEvent(this.onWs.bind(this)),this.realtime.onInterrupted(async()=>{await this.reconnectWs(e,r.id),this.reconnect()}),this.seenLoop(),await this.reconnect({user:r}),this.readyGate.open(),this.reconnectWs(e,r.id),r)}async login(e,t,i){return this._die?H:(N(),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=[],d.clearInterval(this._seenInterval),this._seenInterval=d.setInterval(()=>{if(this._die)return d.clearInterval(this._seenInterval);if(!this.cache)return;this.seenQueue=[...new Set(this.seenQueue)];let e=this.cache.match("user")||{};d.map(this.seenQueue,t=>{var i=this.listEvents(t);if(!i)return;if(0===d.size(i))return;var r=(i=d.filter(i,e=>"message_sent"===e.type))[d.size(i)-1];if(!r)return;if(this.g_haveSentSeenM[r.id])return;if(r.id===r.data.message.idempotency_key)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 s=d.find(e.members,e=>"user"==e.type&&e.id==i.id);return s&&(s.seen_at=this.now()),this.kv.put("light_convos",this.lightConvos),void(this.g_haveSentSeenM[r.id]=!0)}this.api.markAsSeen(t,r.id);let s=this.cache.match("convo_"+t)||{},n=d.find(s.members,t=>t.id===e.id);n&&(n.seen_at=this.now()),this._setConvo(s),this.g_haveSentSeenM[r.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}`]),await this.readyGate.entry()}async reconnect(e){if(this._die)return;await this.reconnectGate.entry(void 0,!0),this.markSync("account");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})]),r=d.find(i,e=>e.error);if(r)return console.error(r);let s=i[1].body;s.user=i[0].body,await this._setSetting(s);let n=await this.api.listConversations();r=n.error;let o=n.body;if(!r){let e=d.get(o,"conversations",[]);d.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&this.now()-d.getMs(d.get(e,"actived"))>12096e5&&this.cache.del(t)}),d.map(e,e=>this._setConvo(e))}return this.reconnectGate.open()}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=d.cloneDeep(e);let t=this.cache.match("user")||{};var i=t.account_id||e.account_id,r=t.id||e.id;d.each(e.attributes,e=>{e&&(t.attributes=d.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=r,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=d.cloneDeep(e)||{}).account=Object.assign({},e.account,this.forceAcc),e.account.logo_url||(e.account.logo_url="https://vcdn.subiz-cdn.com/file/fiqpezhkmeyesdscyetk-default_logo.jpg"),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=d.get(e,"location",[]);this.cache.put("location",t);let i=d.get(e,"bots",[]),r={};d.map(i,e=>{r[e.id]=e}),this.cache.put("bot",r),this.device_type=e.device_type||"desktop";let s=d.get(e,"plugins",[]),n={};d.map(s,e=>{"chatbox"===e.type&&(e=d.merge(e,this.forceChatbox)),n[e.id]=e}),this.cache.put("plugin",n);var o=d.get(e,"agents",[]);if(d.size(o)>0){let e={};this.api.setAgentId(o[0].id),d.map(o,t=>{e[t.id]=t}),this.cache.put("agent",e)}let a=d.get(e,"payment_methods",[]);this.cache.put("payment_methods",a),this.pubsub.publish("account")}async track(){let e=await this.api.sendContentView(this.device,location.href,document.title,this._currentViewingProduct.id,this._currentViewingProduct.source_id,this._currentViewingProduct.sku),t=d.get(e,"body.by.device.source","");t&&this.kv.put("traffic_source",t)}async onWs(e){await this.wsGate.entry(),this.wsGate.close(),await this._onWs(e),this.wsGate.open()}async _onWs(e){if(this._die)return;if(!e||!e.type)return;if(e.created=d.getMs(e.created),"user_info_updated"===e.type)return;let t,i=this.cache.match("user")||{},r=d.convoOfEv(e),s=!1;if(r&&!r.startsWith("cslight")&&(t=this.cache.match("convo_"+r),!t||!t.id)){let{body:e,error:i}=await this.api.getConversation(r);if(!e)return;t=e,s=!0,this._setConvo(t)}if(r.startsWith("cslight")){if(t=this.lightConvos[r],!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=d.get(e,"data.conversation.members",[]),n=d.find(i,e=>e.id===this.cache.match("user").id);if(n&&!s){let{body:e}=await this.api.getConversation(r);e&&(t=e,this._setConvo(t)),this.pubsub.publish("account")}}return"message_sent"===e.type&&d.get(e,"by.id")!==i.id&&(this._alreadyReceived[e.id]||(this._alreadyReceived[e.id]=!0,this.api.markAsReceived(r,e.id))),d.startsWith(e.type,"message_")||d.startsWith(e.type,"conversation_")?(this.restConvoEvent(e),void("message_sent"===e.type&&d.get(e,"by.id")!==i.id&&D("SUBIZ Chat","Received","User"))):void 0}}async restConvoEvent(e){let t=this.cache.match("user"),i=d.convoOfEv(e),r=this.cache.match("convo_"+i)||{};if("conversation_state_updated"===e.type){if(!d.get(r,"id")){let{body:e,error:t}=await this.api.getConversation(i);if(t)return}r=Object.assign(r,d.get(e,"data.conversation"))}if("message_pong"===e.type){var s=d.get(e,"data.message.id"),n=this.chain.match(i,s);if(!d.get(n,"data.message"))return;var o=d.get(n,"data.message.pongs",[]);let a=d.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,d.map(o,e=>{if(e.member_id==t.id&&"seen"===e.type){let i=d.find(r.members,e=>e.id===t.id);i&&(i.seen_at=e.created)}}),this.chain.put(i,n.id,d.getMs(n.created),n),this.pubsub.publish("events",n)}if("message_pong"!==e.type&&"conversation_typing"!==e.type&&(this.chain.put(i,e.id,d.getMs(e.created),e),"message_sent"===e.type)){let t=d.get(e,"data.message.idempotency_key"),s=d.find(this.listEvents(i),e=>e.id===t);s&&(this.chain.del(i,s.id),e.created=s.created),r.last_message_sent=e}this._setConvo(r),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)}startLightConvo(e,t,i,r,s){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={};u.created=c,u.event_time=c,u.id="evfake"+c,u.type="message_sent",u.by={id:e,type:"bot"},u.data={message:t},u.data.message.conversation_id=n;let l={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:[u],is_testing:r,bot_versio:s};return this.lightConvos[n]=l,this.kv.put("light_convos",this.lightConvos),this.pubsub.publish("events",u),{convo:l}}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 r=d.randomString(36),s={id:r,by:{id:(this.cache.match("user")||{}).id,type:"user",device:this.device},data:i,type:t,created:this.now()};d.convoToEv(e,s);let n=[];if("message_sent"===t&&(s.data.message.idempotency_key=r,s.data.message.conversation_id=e,await I.map(s.data.message.attachments,2,async(e,t)=>{var i;if("file"===e.type&&e._file&&(n.push(e),q.includes(e._file.type))){let{width:t,height:r,url:s}=await(i=e._file,new Promise(e=>{var t=new window.FileReader;t.onload=t=>{let i=t.target.result,r=new Image;r.onload=()=>{e({url:i,width:r.width,height:r.height})},r.src=i},t.readAsDataURL(i)}));e.url=s,e.width=t,e.height=r}})),this.onWs(s),await this.convoGate.entry(),await I.map(n,1,async e=>{const{body:t,url:i,error:r}=await this.api.uploadToS3(e._file);"invalid_field_size"==d.get(t,"code")&&(s._error_message="cannot_send_too_big_file"),s._error=r,e.url=i}),s._error)return this.onWs(s);if(e&&e.startsWith("cslight"))return;let{body:o,error:a}=await this.api.sendConvoEvent(e,s);return a?(s._error=a,void this.onWs(s)):(this.onWs(o),D("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()),o)}_setConvo(e){this.cache.match("user");let t=d.get(e,"touchpoint.channel","");if(t&&"subiz"!=t)return;let i={};if(d.map(this.cache.all(),(e,t)=>{t.startsWith("convo_")&&(i[t]=e)}),d.size(i)>18){i=d.orderBy(d.map(i),"created","desc");for(var r=18;r<d.size(i);r++){let e=i[r];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 r=this.cache.match("user")||{},s={account_id:r.account_id,user_id:r.id,fields:t},n=this.kv.match("conversions")||{};return n[e]=!0,this.kv.put("conversions",n),this.api.sendConversion({account_id:r.account_id,web_plugin_id:e,campaign_id:e,user_id:d.get(r,"id"),url:window.location.href,device:this.device,submission:s,impression_token:i})}isConverted(e){return(this.kv.match("conversions")||{})[e]}async listmessageapi(e,t,i){let r=e;if(r&&r.startsWith("cslight"))return[fakeevents,"",void 0,!0];let{body:s,code:n,error:o}=await this.api.listMessages(r,-i,t);if(o||200!==n)return[[],t,o];t=d.get(d.last(s),"id"),s=d.map(s,e=>(e.created=d.getMs(e.created),{id:e.id,index:e.created,value:e}));let a=this.cache.match("user")||{};for(let e=0;e<s.length;e++){let t=s[e].value;if("message_sent"!==t.type)continue;if(d.get(t,"by.id")===a.id)continue;let i=d.find(d.get(t,"data.message.pongs"),e=>e.member_id===a.id);if(i)break;this._alreadyReceived[t.id]||(this._alreadyReceived[t.id]=!0,this.api.markAsReceived(r,t.id));break}return[s,t,void 0,d.size(s)<i]}async loopTime(){if(this._die)return;let e=this.now();if(!this.cache||!d.get(this.cache.match("user"),"id"))return d.setTimeout(()=>this.loopTime(),24e4);let{body:t,error:i}=await this.api.time();if(i)return d.setTimeout(()=>this.loopTime(),3e4);var r=Math.abs(this.now()-e)/2,s=new d.Date(t).getTime()+r,n=this.now();this.timeDiff=Math.floor(s-n),d.setTimeout(()=>this.loopTime(),24e4)}replaceFileUrl(e){return e?d.startsWith(e,"/")||d.startsWith(e,"data:")?e:(d.startsWith(e,"http://")||d.startsWith(e,"https://")||d.startsWith(e,"//")||(e=d.trim(this.FileURL,"/")+"/"+d.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(){d.each(this.cookie.all(),(e,t)=>{(t||"").startsWith("__sb")&&this.cookie.remove(t)}),this.kv&&this.kv.destroy(),this.kv=new S(new y("sbz2023",this.inmem),"kv"),this.chain&&this.chain.destroy(),this.chain=new b(new y("cbz2023",!0),"ch"),this.realtime&&this.realtime.stop(),this.cache&&this.cache.destroy(),this.pubsub.publish("destroy")}destroy(){this._die=!0,this.clearBrowserData(),d.clearInterval(this._seenInterval),this.realtime&&this.realtime.stop(),this.readyGate.close(),window.removeEventListener("blur",this.sendPresence),window.removeEventListener("focus",this.sendPresence)}}const q=["image/gif","image/jpeg","image/png","image/svg+xml"],R={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 D(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(r){const s=r.get("name");window.ga(s+".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 W=()=>{try{localStorage}catch(e){return}d.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020"))&&(localStorage.removeItem(e),U.removeItem(e))})},N=()=>{try{localStorage}catch(e){return}d.setTimeout(()=>{for(var e in localStorage)e&&(e.startsWith("cbz2020")||e.startsWith("sbz2020")||e.startsWith("sbz2022")||e.startsWith("sbz2023"))&&(localStorage.removeItem(e),U.removeItem(e))})};var V=function(e,t,i,r){if(void 0===d.XMLHttpRequest)return function(e,t,i,r){let s={};i&&(s["content-type"]="text/plain"),fetch(t,{method:e,headers:s,body:i}).then(e=>e.text().then(t=>r&&r(t,e.status))).catch(e=>r&&r(e,-1))}(e,t,i,r);var s=new d.XMLHttpRequest;s.onreadystatechange=function(e){4===s.readyState&&(r&&r(s.responseText,s.status),r=void 0)},s.onerror=function(){r&&r(s.responseText,-1),r=void 0},s.open(e,t),i&&s.setRequestHeader("content-type","text/plain"),s.send(i)};const H=new Error("sdk unloaded");var B,G,Q,J,Z,X,K,Y={},ee=[],te=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ie=Array.isArray;function re(e,t){for(var i in t)e[i]=t[i];return e}function se(e){var t=e.parentNode;t&&t.removeChild(e)}function ne(e,t,i){var r,s,n,o={};for(n in t)"key"==n?r=t[n]:"ref"==n?s=t[n]:o[n]=t[n];if(arguments.length>2&&(o.children=arguments.length>3?B.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 oe(e,o,r,s,null)}function oe(e,t,i,r,s){var n={type:e,props:t,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:null==s?++Q:s,__i:-1,__u:0};return null==s&&null!=G.vnode&&G.vnode(n),n}function ae(e){return e.children}function ce(e,t){this.props=e,this.context=t}function ue(e,t){if(null==t)return e.__?ue(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?ue(e):null}function le(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 le(e)}}function he(e){(!e.__d&&(e.__d=!0)&&J.push(e)&&!de.__r++||Z!==G.debounceRendering)&&((Z=G.debounceRendering)||X)(de)}function de(){var e,t,i,r,s,n,o,a,c;for(J.sort(K);e=J.shift();)e.__d&&(t=J.length,r=void 0,n=(s=(i=e).__v).__e,a=[],c=[],(o=i.__P)&&((r=re({},s)).__v=s.__v+1,G.vnode&&G.vnode(r),we(o,r,s,i.__n,void 0!==o.ownerSVGElement,32&s.__u?[n]:null,a,null==n?ue(s):n,!!(32&s.__u),c),r.__.__k[r.__i]=r,ke(a,r,c),r.__e!=n&&le(r)),J.length>t&&J.sort(K));de.__r=0}function pe(e,t,i,r,s,n,o,a,c,u,l){var h,d,p,f,_,m=r&&r.__k||ee,g=t.length;for(i.__d=c,fe(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?Y:m[p.__i]||Y,p.__i=h,we(e,p,d,s,n,o,a,c,u,l),f=p.__e,p.ref&&d.ref!=p.ref&&(d.ref&&Se(d.ref,null,p),l.push(p.ref,p.__c||f,p)),null==_&&null!=f&&(_=f),65536&p.__u||d.__k===p.__k?c=_e(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 fe(e,t,i){var r,s,n,o,a,c=t.length,u=i.length,l=u,h=0;for(e.__k=[],r=0;r<c;r++)null!=(s=e.__k[r]=null==(s=t[r])||"boolean"==typeof s||"function"==typeof s?null:"string"==typeof s||"number"==typeof s||"bigint"==typeof s||s.constructor==String?oe(null,s,null,null,s):ie(s)?oe(ae,{children:s},null,null,null):void 0===s.constructor&&s.__b>0?oe(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):s)?(s.__=e,s.__b=e.__b+1,a=me(s,i,o=r+h,l),s.__i=a,n=null,-1!==a&&(l--,(n=i[a])&&(n.__u|=131072)),null==n||null===n.__v?(-1==a&&h--,"function"!=typeof s.type&&(s.__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!==r+h&&(s.__u|=65536))):(n=i[r])&&null==n.key&&n.__e&&(n.__e==e.__d&&(e.__d=ue(n)),Ce(n,n,!1),i[r]=null,l--);if(l)for(r=0;r<u;r++)null!=(n=i[r])&&!(131072&n.__u)&&(n.__e==e.__d&&(e.__d=ue(n)),Ce(n,n))}function _e(e,t,i){var r,s;if("function"==typeof e.type){for(r=e.__k,s=0;r&&s<r.length;s++)r[s]&&(r[s].__=e,t=_e(r[s],t,i));return t}return e.__e!=t&&(i.insertBefore(e.__e,t||null),t=e.__e),t&&t.nextSibling}function me(e,t,i,r){var s=e.key,n=e.type,o=i-1,a=i+1,c=t[i];if(null===c||c&&s==c.key&&n===c.type)return i;if(r>(null==c||131072&c.__u?0:1))for(;o>=0||a<t.length;){if(o>=0){if((c=t[o])&&!(131072&c.__u)&&s==c.key&&n===c.type)return o;o--}if(a<t.length){if((c=t[a])&&!(131072&c.__u)&&s==c.key&&n===c.type)return a;a++}}return-1}function ge(e,t,i){"-"===t[0]?e.setProperty(t,null==i?"":i):e[t]=null==i?"":"number"!=typeof i||te.test(t)?i:i+"px"}function ve(e,t,i,r,s){var n;e:if("style"===t)if("string"==typeof i)e.style.cssText=i;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(t in r)i&&t in i||ge(e.style,t,"");if(i)for(t in i)r&&i[t]===r[t]||ge(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?r?i.u=r.u:(i.u=Date.now(),e.addEventListener(t,n?be:ye,n)):e.removeEventListener(t,n?be:ye,n);else{if(s)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]=null==i?"":i;break e}catch(e){}"function"==typeof i||(null==i||!1===i&&"-"!==t[4]?e.removeAttribute(t):e.setAttribute(t,i))}}function ye(e){var t=this.l[e.type+!1];if(e.t){if(e.t<=t.u)return}else e.t=Date.now();return t(G.event?G.event(e):e)}function be(e){return this.l[e.type+!0](G.event?G.event(e):e)}function we(e,t,i,r,s,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=G.__b)&&l(t);e:if("function"==typeof C)try{if(g=t.props,v=(l=C.contextType)&&r[l.__c],y=l?v?v.props.value:l.__:r,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 ce(g,y),h.constructor=C,h.render=ze),v&&v.sub(h),h.props=g,h.state||(h.state={}),h.context=y,h.__n=r,d=h.__d=!0,h.__h=[],h._sb=[]),null==h.__s&&(h.__s=h.state),null!=C.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=re({},h.__s)),re(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=G.__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&&(r=re(re({},r),h.getChildContext())),d||null==h.getSnapshotBeforeUpdate||(_=h.getSnapshotBeforeUpdate(p,f)),pe(e,ie(S=null!=l&&l.type===ae&&null==l.key?l.props.children:l)?S:[S],t,i,r,s,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),G.__e(e,t,i)}else null==n&&t.__v===i.__v?(t.__k=i.__k,t.__e=i.__e):t.__e=xe(i.__e,t,i,r,s,n,o,c,u);(l=G.diffed)&&l(t)}function ke(e,t,i){t.__d=void 0;for(var r=0;r<i.length;r++)Se(i[r],i[++r],i[++r]);G.__c&&G.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){G.__e(e,t.__v)}})}function xe(e,t,i,r,s,n,o,a,c){var u,l,h,d,p,f,_,m=i.props,g=t.props,v=t.type;if("svg"===v&&(s=!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=s?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&&B.call(e.childNodes),m=i.props||Y,!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||ve(e,u,null,p,s));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||ve(e,u,p,m[u],s);if(l)a||h&&(l.__html===h.__html||l.__html===e.innerHTML)||(e.innerHTML=l.__html),t.__k=[];else if(h&&(e.innerHTML=""),pe(e,ie(d)?d:[d],t,i,r,s&&"foreignObject"!==v,n,o,n?n[0]:i.__k&&ue(i,0),a,c),null!=n)for(u=n.length;u--;)null!=n[u]&&se(n[u]);a||(u="value",void 0!==f&&(f!==e[u]||"progress"===v&&!f||"option"===v&&f!==m[u])&&ve(e,u,f,m[u],!1),u="checked",void 0!==_&&_!==e[u]&&ve(e,u,_,m[u],!1))}return e}function Se(e,t,i){try{"function"==typeof e?e(t):e.current=t}catch(e){G.__e(e,i)}}function Ce(e,t,i){var r,s;if(G.unmount&&G.unmount(e),(r=e.ref)&&(r.current&&r.current!==e.__e||Se(r,null,t)),null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){G.__e(e,t)}r.base=r.__P=null,e.__c=void 0}if(r=e.__k)for(s=0;s<r.length;s++)r[s]&&Ce(r[s],t,i||"function"!=typeof e.type);i||null==e.__e||se(e.__e),e.__=e.__e=e.__d=void 0}function ze(e,t,i){return this.constructor(e,i)}B=ee.slice,G={__e:function(e,t,i,r){for(var s,n,o;t=t.__;)if((s=t.__c)&&!s.__)try{if((n=s.constructor)&&null!=n.getDerivedStateFromError&&(s.setState(n.getDerivedStateFromError(e)),o=s.__d),null!=s.componentDidCatch&&(s.componentDidCatch(e,r||{}),o=s.__d),o)return s.__E=s}catch(t){e=t}throw e}},Q=0,ce.prototype.setState=function(e,t){var i;i=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=re({},this.state),"function"==typeof e&&(e=e(re({},i),this.props)),e&&re(i,e),null!=e&&this.__v&&(t&&this._sb.push(t),he(this))},ce.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),he(this))},ce.prototype.render=ae,J=[],X="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,K=function(e,t){return e.__v.__b-t.__v.__b},de.__r=0;class Te extends ce{constructor(e){super(e),this._isMounted=!0,d.setTimeout(()=>{if(this.componentWillUnmount){let e=this.componentWillUnmount.bind(this);this.componentWillUnmount=()=>{e(),this._isMounted=!1}}},10)}}let Ee={},Pe=!1;function Ae(e,t,i){if(Pe)return new Promise(r=>d.setTimeout(()=>Ae(e,t,i).then(r),100));let r;return Pe=!0,"debug"===t||Ee[t]&&!i?(Pe=!1,Promise.resolve()):e.getLocaleContent(t).then(e=>{Pe=!1,r=d.get(e,"body.messages",[]),Ee[t]=r})}class Oe extends Te{render(){var e=this.props.emojiCode;if(d.size(e)<3)return null;var t=e.replace(/:/g,"");return ne("i",{"data-tooltip":e,class:`emoji emoji--${t}`})}}class je extends Te{constructor(e){super(e)}renderBlock(e){if(0==d.size(e))return null;let t={style:""};if(e.style&&d.map(e.style,(e,i)=>{t.style+=i+": "+e+";"}),t.attrs={},""!=e.title&&(t.attrs.title=e.title),""!=e.href&&(t.attrs.href=e.href),t.class=e.class,d.map(e.attrs,(e,i)=>{t.attrs[i]=e}),"bullet_list"!=e.type&&"ordered_list"!=e.type||("bullet_list"==e.type?t.tag="ul":t.tag="ol"),"list_item"==e.type&&(t.tag="li"),"heading"==e.type&&(e.level<1&&(e.level=1),e.level>6&&(e.level=6),t.tag="h"+e.level),"paragraph"!=e.type&&"section"!=e.type&&"div"!=e.type||(t.tag="div"),t.text=e.text,""!=e.type&&"text"!=e.type&&"dynamic-field"!=e.type||(t.tag="span",e.bold&&(t.tag="b"),e.italic&&("b"==t.tag?t.style+="font-style: italic;":t.tag="em"),e.underline&&(t.Style+="text-decoration:underline;"),e.strike_through&&(t.Style+="text-decoration: line-through;")),"dynamic-field"==e.type){let i=d.get(e.attrs,"key");t.text=d.get(this.props.data,[i],t.text)}if("link"==e.type&&(t.tag="a",t.attrs.href=e.href,t.attrs.target=e.target,t.attrs.title=e.title),"mention-agent"==e.type||"mention"==e.type){t.tag="span",t.class="mention";let i=e.attrs.id="";if("*"!=e.attrs.id&&"all"!=e.attrs.id||(t.text="@"+this.$t("all")),i.startsWith("ag")){let e=store.matchAgent(i),r=d.getAgentDisplayName(e,insert.mention.fullname);t.text="@"+r}}if("horizontal_rule"==e.type&&(t.tag="hr"),"emoji"==e.type){let i="";d.size(e.attrs)>0&&(i=e.attrs.code),""==i&&(i=e.Text),""!=i&&(t.tag="Emoji",t.attrs.emojiCode=i)}if("table"==e.type)return null;"image"===e.type&&(t.tag="img",t.attrs.src=d.get(e,"image.url"),t.attrs.alt=e.alt_text);let i=null;if(d.size(e.content))i=d.map(e.content,e=>this.renderBlock(e));else if("text"===e.type){i=d.extractText(t.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),ne("a",{href:t,target:"_blank",onClick:e=>this.props.onLink(e,t)},e.text)}return"phone"===e.type?ne("a",{href:"tel:"+e.text},e.text):"email"===e.type?ne("a",{href:"mailto:"+e.text},e.text):e.text})}else i=t.text;switch(t.tag){case"img":return ne("a",{class:this.props.textMessage?"message-text-inline-image-wrapper":"",href:d.get(t,"attrs.src"),target:"_blank"},ne("img",{class:this.props.textMessage?"message-text-inline-image":"",src:d.get(t,"attrs.src"),alt:d.get(t,"attrs.alt")||""}));case"div":return ne("div",null,i);case"h1":return ne("h1",null,i);case"h2":return ne("h2",null,i);case"h3":return ne("h3",null,i);case"h4":return ne("h4",null,i);case"h5":return ne("h5",null,i);case"h6":return ne("h6",null,i);case"ol":return ne("ol",{class:this.props.textMessage?"text-message-ol":""},i);case"ul":return ne("ul",{class:this.props.textMessage?"text-message-ul":""},i);case"li":return ne("li",{class:this.props.textMessage?"text-message-li":""},i);case"span":return ne("span",null,i);case"em":return ne("em",null,i);case"b":return ne("b",null,i);case"hr":return ne("hr",null);case"a":return ne("a",{href:t.attrs.href,target:this.props.textMessage?"_blank":t.attrs.target,title:t.attrs.title},i);case"Emoji":return ne(Oe,{emojiCode:t.attrs.emojiCode})}return null}render(){return this.renderBlock(this.props.block)}}function Ie(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 Me extends Te{constructor(e){super(e),Ie(this,"state",{hovering:0,selected:0}),Ie(this,"onMouseEnter",e=>{let{selected:t,hovering:i}=this.state;e<=t?this.setState({hovering:t}):this.setState({hovering:e})}),Ie(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 r="star-wrapper";e>=2?r+=" selected":t>=2&&(r+=" hovering");let s="star-wrapper";e>=3?s+=" selected":t>=3&&(s+=" 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"),ne("div",{class:"form-ratings-wrapper",onMouseLeave:()=>this.onMouseLeave()},ne("div",{class:i,onClick:()=>this.onToggleValue(1),onMouseEnter:()=>this.onMouseEnter(1)},ne("div",{class:"star"})),ne("div",{class:r,onClick:()=>this.onToggleValue(2),onMouseEnter:()=>this.onMouseEnter(2)},ne("div",{class:"star"})),ne("div",{class:s,onClick:()=>this.onToggleValue(3),onMouseEnter:()=>this.onMouseEnter(3)},ne("div",{class:"star"})),ne("div",{class:n,onClick:()=>this.onToggleValue(4),onMouseEnter:()=>this.onMouseEnter(4)},ne("div",{class:"star"})),ne("div",{class:o,onClick:()=>this.onToggleValue(5),onMouseEnter:()=>this.onMouseEnter(5)},ne("div",{class:"star"})))}}function Le(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 Ue extends Te{constructor(e){super(e),Le(this,"state",{errorFields:{},submiting:!1}),Le(this,"renderFormComponent",(e,t)=>"input"===e.type?this.renderField(e,t):"button"===e.type?this.renderSubmitButton(e,t):this.props.isSubmited?void 0:ne("div",{class:"form-component form-component-block"},ne(je,{block:e}))),Le(this,"renderSubmitButton",(e,t)=>{if(!this.props.isSubmited)return ne("div",{class:"form-component form-component-submit-button"},this.props.errorMessage&&ne("div",{class:"form-control--valid-input--error mb-1"},this.props.errorMessage),ne("div",null,ne("button",{class:"btn--start-convo",disabled:this.props.submiting},e.label)))}),Le(this,"renderField",(e,t)=>{let i=this.state.errorFields[e.key];if(this.props.isSubmited){let t=d.find(this.props.submission.values,t=>t.key===e.key)||{};return t=t.value||'""',t=d.parseJSON(t),Array.isArray(t)&&(t=t.join(", ")),ne("div",{class:"form-component submitted",key:e.key},ne("label",{class:"label"},e.label),ne("div",null,t||ne("span",{class:"text-muted text-italic"},this.props.t("no_info_input"))))}return ne("div",{class:"form-component",key:e.key},ne("label",{class:"label"},e.label," ",e.is_required&&ne("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&&ne("div",{class:"form-control--valid-input--error"},i))}),Le(this,"renderFieldTextInput",(e,t)=>{let i="form-control";this.state.errorFields[e.key]&&(i="form-control input--error");let r=d.find(this.props.submission.values,t=>t.key===e.key)||{};return r=r.value||'""',r=d.parseJSON(r),ne("input",{ref:this[`${e.key}_input`],type:"text",class:i,placeholder:e.placeholder,value:r,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Le(this,"renderFieldDateInput",(e,t)=>{let i=d.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=d.parseJSON(i);let r="form-control";return this.state.errorFields[e.key]&&(r="form-control input--error"),ne("input",{ref:this[`${e.key}_input`],class:r,type:"date",value:i,onInput:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}})}),Le(this,"renderFieldRadioInput",(e,t)=>{let i=d.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=d.parseJSON(i);let r="form-radios-wrapper";return d.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(r+=" horizontal"),ne("div",{class:r},d.map(e.input_options,(t,r)=>{let s=e.key+"_"+r;return ne("div",{class:"radio"},ne("input",{type:"radio",name:e.key,id:s,checked:t.value===i,onChange:()=>this.toggleRadioField(e.key,t.value)}),ne("label",{class:"radio--label",for:s},t.label),ne("div",{class:"radio--check"}))}))}),Le(this,"renderFieldCheckboxInput",(e,t)=>{let i=d.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||"[]",i=d.parseJSON(i);let r="form-checkboxes-wrapper";return d.size(e.input_options)>=3&&"attachment"!==this.props.mode&&(r+=" horizontal"),ne("div",{class:r},d.map(e.input_options,(t,r)=>{let s=e.key+"_"+r;return ne("div",{class:"checkbox"},ne("input",{type:"checkbox",name:e.key,id:s,checked:i.includes(t.value),onChange:()=>this.toggleCheckboxField(e.key,t.value)}),ne("label",{class:"checkbox--label",for:s},t.label),ne("div",{class:"checkbox--check"}))}))}),Le(this,"renderFieldDropdownInput",(e,t)=>{let i=d.find(this.props.submission.values,t=>t.key===e.key)||{};i=i.value||'""',i=d.parseJSON(i);let r="form-control";return this.state.errorFields[e.key]&&(r+=" input--error"),i||(r+=" form-control--empty"),ne("select",{class:r,ref:this[`${e.key}_input`],onChange:t=>{this.onChangeValue(e.key,t.target.value),this.clearError(e.key)}},ne("option",{value:""},"-- ",this.props.t("no_select")," --"),d.map(e.input_options,e=>ne("option",{value:e.value},e.label)))}),Le(this,"renderFieldTextareaInput",(e,t)=>{let i=d.find(this.props.submission.values,t=>t.key===e.key)||{};return i=i.value||'""',i=d.parseJSON(i),ne("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})}),Le(this,"renderFieldRatingInput",(e,t)=>ne(Me,{onChange:t=>this.onChangeValue(e.key,t)})),Le(this,"onSubmit",e=>{e.preventDefault(),this.validateForm()&&this.props.onSubmit()}),Le(this,"validateForm",()=>{let e=!0,t="",i={},r=d.get(this.props.formSetting,"components")||[];return d.each(r,r=>{if("input"===r.type){let s=d.find(this.props.submission.values,e=>e.key===r.key)||{};if(s=s.value||'""',s=d.parseJSON(s),r.is_required){let n=!1;"string"!=typeof s||s.trim()||(n=!0),Array.isArray(s)&&0===s.length&&(n=!0),n&&(e=!1,i[r.key]=this.props.t("cannot_be_empty"),t=`${r.key}_input`)}if(r.validation&&!Array.isArray(s)){let n=!1,o="";"email"!==r.validation||d.isEmail(s)||(o="Email",n=!0),"phone"!==r.validation||d.isPhone(s)||(o=this.props.t("phn"),n=!0),"number"!==r.validation||d.isNumber(s)||(o=this.props.t("number"),n=!0),"url"!==r.validation||d.isURL(s)||(n=!0,o="URL"),n&&(e=!1,i[r.key]=this.props.t("format_is_invalid")+" "+o,t=`${r.key}_input`)}}}),t&&this[t]&&this[t].current&&this[t].current.focus(),this.setState({errorFields:i}),e}),Le(this,"onChangeValue",(e,t)=>{let i=d.get(this.props.submission,"values")||[],r=d.find(i,t=>t.key===e);r?r.value=JSON.stringify(t):i.push({key:e,value:JSON.stringify(t)}),this.props.onChangeFormValues(i)}),Le(this,"clearError",e=>{let t=this.state.errorFields;t[e]="",this.setState({errorFields:t})}),Le(this,"renderFormHeader",()=>{let e=d.get(this.props.formSetting,"title")||"",t=d.get(this.props.formSetting,"description")||"";if("attachment"===this.props.mode&&(e.trim()||t.trim()))return ne("div",{class:"form-component form-component-block"},e&&ne("div",null,e),t&&ne("div",{class:"text-sm text-muted"},t));let i=d.get(this.props.formSetting,"logo.url"),r=d.get(this.props.formSetting,"brand_url"),s=null;i&&(s=ne("div",{class:"form-page-logo-wrapper"},ne("a",{href:r||"javascript:;"},ne("img",{src:i,class:"form-page-logo"}))));let n=null;return(e.trim()||t.trim())&&(n=ne("div",{class:"form-page-header"},ne("div",{class:"form-page-title"},e),t&&ne("div",{class:"form-page-desc"},t))),ne(ae,null,s,n)});let t=d.get(this.props.formSetting,"components")||[];d.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=d.find(this.props.submission.values,t=>t.key===e)||{};i=i.value||"[]",i=d.parseJSON(i),i.includes(t)?i=i.filter(e=>e!==t):i.push(t),this.clearError(e),this.onChangeValue(e,i)}render(){let e=d.get(this.props.formSetting,"components")||[],t=(d.get(this.props.formSetting,"title"),d.get(this.props.formSetting,"description"),"form-wrapper form");return"attachment"===this.props.mode&&(t+=" form-wrapper-attachment"),ne("div",{class:t},this.props.isSubmited&&ne("div",{class:"form-component"},this.props.t("you_have_submitted_info_successfully")),ne("form",{onSubmit:this.onSubmit},this.renderFormHeader(),d.map(e,this.renderFormComponent)))}}function $e(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 Fe=n.e(339).then(n.bind(n,5339));class qe extends Te{constructor(e){super(e),$e(this,"waitForFont",async e=>{if(0==d.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),d.size(Object.keys(t))===e.length)return}catch(e){}await d.sleep(200)}}),$e(this,"initCss",async()=>{let e=(await Fe).default.default.toString(),t=d.find(this.props.store.matchPlugin(),e=>"chatbox"===e.type)||{};t=t.chatbox||{};let i=t,r=d.replaceCssVariable(e,i),s=document.createElement("style");document.head.appendChild(s),s.type="text/css",s.id="subiz-style-for-form",this.cssDiv=s,d.setCss("form",s,r)}),$e(this,"insertCss",async(e,t)=>{let i=(await Fe).default.default.toString(),r=e;t.primary_color&&(r.primary_color=t.primary_color);let s=d.get(t,"header_style.font_family"),n=d.get(t,"text_style.font_family"),o=d.get(t,"input_style.font_family");r.form_background_color=t.background_color,r.form_header_font_size=d.get(t,"header_style.font_size")||"20",r.form_header_font_family=s,r.form_desc_font_size=d.get(t,"text_style.font_size")||"16",r.form_desc_font_family=n,r.form_input_label_font_size=d.get(t,"input_style.font_size")||"14",r.form_input_label_font_family=o;let a=d.replaceCssVariable(i,r),c=[];o&&!c.includes(o)&&c.push(o),s&&!c.includes(s)&&c.push(s),n&&!c.includes(n)&&c.push(n),d.size(c)&&(d.preloadWebfonts(c,[400,500]),await this.waitForFont(c)),d.setCss("form",this.cssDiv,a)}),$e(this,"fetchFormSetting",async()=>{let e=d.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=d.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=d.get(t,"body.form")||{},r=d.get(t,"body.form_submission")||{},s=d.size(r)>0;await this.insertCss(e,i),this.setState({loading:!1,loadError:!1,formSetting:i,submission:r,isSubmited:s})}),$e(this,"onChangeFormValues",e=>{this.setState({submission:{values:e}})}),$e(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:r,errorMessage:s,isSubmited:n,submiting:o}=this.state;if(t&&!i)return ne("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"loading"},ne("div",{class:"text-muted text-xl"},this.props.t("loading_data")," ..."));if(i)return ne("div",{class:"h-full w-full d-flex justify-content-center align-items-center",key:"error"},ne("div",{class:"text-center"},ne("div",{class:"text-danger text-lg mb-2"},this.props.t("error_occurs_when_load_data")),ne("br",null),ne("button",{disabled:t,type:"button",class:"btn--start-convo",onClick:this.fetchFormSetting},this.props.t("try_again"))));d.get(e,"logo.url");let a=d.get(e,"cover_image.url"),c="form-page";return a&&(c+=" sketch"),ne("div",{class:"form-page-body",key:"form"},this.props.previewJson&&ne("div",{class:"form-page-preview-noti"},"Form ở trạng thái xem thử, không ghi nhận phản hồi"),a&&ne("div",{class:"form-page-header-bg",style:`background: url(${a}); background-size: cover;`}),ne("div",{class:c},ne(Ue,{store:this.props.store,formSetting:e,t:this.props.t,submission:r,errorMessage:s,isSubmited:n,submiting:o,onChangeFormValues:this.onChangeFormValues,onSubmit:this.onSubmit})))}}n.e(278).then(n.bind(n,9278));const Re=n(5180);function De(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))}var We=document.createElement("link");We.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap",We.rel="stylesheet",document.head.append(We),async function(){let e=new F(Re.ApiURL,Re.FileURL,Re.RealtimeURL,!0);window.store=e;let t=De("id")||De("accid")||De("account-id")||"acqsulrowbxiugvginhw",i=De("token"),r=De("preview");await e.init(t);let s=e=>{if("debug"===n)return`{{${e}}}`;let t=d.get(Ee,n,[]),i=d.find(t,t=>t.key===e);return d.get(i,"message",e)},n="vi-VN";s.i18n=e=>{if(!e)return"";let t="vi-VN";return t=t.replace("-","_"),e[n.replace("-","_")]||e[t]},s.locale=()=>n,Ae(e,n).then(()=>{!function(e,t,i){var r,s,n,o;G.__&&G.__(e,t),s=(r="function"==typeof i)?null:i&&i.__k||t.__k,n=[],o=[],we(t,e=(!r&&i||t).__k=ne(ae,null,[e]),s||Y,Y,void 0!==t.ownerSVGElement,!r&&i?[i]:s?null:t.firstChild?B.call(t.childNodes):null,n,!r&&i?i:s?s.__e:t.firstChild,r,o),ke(n,e,o)}(ne(qe,{store:e,t:s,token:i,previewJson:r}),document.getElementById("form"))})}()})()})();