@subiz/widget-v4 4.0.85 → 4.0.86

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 (35) hide show
  1. package/compiled_src/chatbox/ChatButton.js +4 -8
  2. package/compiled_src/store/store.js +4 -6
  3. package/dist/132.js +10 -8
  4. package/dist/18224b3b0f8.132.js +1 -0
  5. package/dist/{181a9b734bb.178.js → 18224b3b0f8.178.js} +0 -0
  6. package/dist/{181a9b734bb.213.js → 18224b3b0f8.213.js} +1 -1
  7. package/dist/{181a9b734bb.335.js → 18224b3b0f8.335.js} +0 -0
  8. package/dist/{181a9b734bb.362.js → 18224b3b0f8.362.js} +1 -1
  9. package/dist/18224b3b0f8.441.js +1 -0
  10. package/dist/{181a9b734bb.605.js → 18224b3b0f8.605.js} +0 -0
  11. package/dist/{181a9b734bb.678.js → 18224b3b0f8.678.js} +0 -0
  12. package/dist/{181a9b734bb.782.js → 18224b3b0f8.782.js} +1 -1
  13. package/dist/18224b3b0f8.app.js +1 -0
  14. package/dist/{181a9b734bb.index.html → 18224b3b0f8.index.html} +1 -1
  15. package/dist/{181a9b734bb.library.html → 18224b3b0f8.library.html} +1 -1
  16. package/dist/18224b3b0f8.library.js +1 -0
  17. package/dist/{181a9b734bb.preview.html → 18224b3b0f8.preview.html} +1 -1
  18. package/dist/18224b3b0f8.preview.js +1 -0
  19. package/dist/18224b3b0f8.screenshoot.js +1 -0
  20. package/dist/213.js +6 -0
  21. package/dist/362.js +1 -1
  22. package/dist/441.js +12 -0
  23. package/dist/782.js +1 -1
  24. package/dist/HASH +1 -1
  25. package/dist/screenshoot.html +1 -1
  26. package/dist/screenshoot.js +10 -12
  27. package/package.json +5 -5
  28. package/src/chatbox/ChatButton.js +4 -4
  29. package/src/store/store.js +3 -4
  30. package/dist/181a9b734bb.132.js +0 -1
  31. package/dist/181a9b734bb.441.js +0 -1
  32. package/dist/181a9b734bb.app.js +0 -1
  33. package/dist/181a9b734bb.library.js +0 -1
  34. package/dist/181a9b734bb.preview.js +0 -1
  35. package/dist/181a9b734bb.screenshoot.js +0 -1
@@ -247,21 +247,17 @@ class ChatButton extends _common.Com {
247
247
  }
248
248
 
249
249
  onProfileReady() {
250
- if (this.state.buttonLoaded) this.setState({
250
+ if (this._buttonLoaded) this.setState({
251
251
  opacity: 1
252
252
  });
253
- this.setState({
254
- profileLoaded: true
255
- });
253
+ this._profileLoaded = true;
256
254
  }
257
255
 
258
256
  onButtonReady() {
259
- if (this.state.profileLoaded) this.setState({
257
+ if (this._profileLoaded) this.setState({
260
258
  opacity: 1
261
259
  });
262
- this.setState({
263
- buttonLoaded: true
264
- });
260
+ this._buttonLoaded = true;
265
261
  }
266
262
 
267
263
  renderButton() {
@@ -1232,7 +1232,10 @@ function sendToFBPixel(category, action, label) {
1232
1232
  }
1233
1233
 
1234
1234
  function sendToGA(category, action, label) {
1235
- console.log('SENT.', category, action, label);
1235
+ if (window.gtag) window.gtag('event', category, {
1236
+ Action: action,
1237
+ Label: label
1238
+ });
1236
1239
 
1237
1240
  if (window.ga && window.ga.getAll) {
1238
1241
  const allTrackers = window.ga.getAll() || [];
@@ -1240,11 +1243,6 @@ function sendToGA(category, action, label) {
1240
1243
  const name = tracker.get('name');
1241
1244
  window.ga(name + '.send', 'event', category, action, label);
1242
1245
  });
1243
- } else {
1244
- if (window.gtag) window.gtag('event', category, {
1245
- Action: action,
1246
- Label: label
1247
- });
1248
1246
  }
1249
1247
  }
1250
1248
 
package/dist/132.js CHANGED
@@ -258,21 +258,17 @@ class ChatButton extends common/* Com */.up {
258
258
  }
259
259
 
260
260
  onProfileReady() {
261
- if (this.state.buttonLoaded) this.setState({
261
+ if (this._buttonLoaded) this.setState({
262
262
  opacity: 1
263
263
  });
264
- this.setState({
265
- profileLoaded: true
266
- });
264
+ this._profileLoaded = true;
267
265
  }
268
266
 
269
267
  onButtonReady() {
270
- if (this.state.profileLoaded) this.setState({
268
+ if (this._profileLoaded) this.setState({
271
269
  opacity: 1
272
270
  });
273
- this.setState({
274
- buttonLoaded: true
275
- });
271
+ this._buttonLoaded = true;
276
272
  }
277
273
 
278
274
  renderButton() {
@@ -5758,17 +5754,23 @@ class Widget extends common/* Com */.up {
5758
5754
  if (hasError) return this.forceUpdate();
5759
5755
  let data = util/* default.cloneDeep */.Z.cloneDeep(this.state.formData);
5760
5756
  let user = util/* default.cloneDeep */.Z.cloneDeep(this.props.store.matchUser());
5757
+ let is_lead = false;
5761
5758
  util/* default.map */.Z.map(data, (field, key) => {
5762
5759
  if (!key.startsWith('attr:')) return;
5763
5760
  var attr = {
5764
5761
  key: key.substr(5)
5765
5762
  };
5763
+ is_lead = is_lead || key == 'emails' || key == 'phones';
5766
5764
  if (field.type === 'number') attr.number = parseInt(field.value);
5767
5765
  if (field.type === 'datetime') attr.datetime = new util/* default.Date */.Z.Date(field.value).toISOString();
5768
5766
  if (field.type === 'list') attr.list = field.value;
5769
5767
  if (field.type === 'text' || field.type === 'boolean') attr[field.type] = field.value;
5770
5768
  util/* default.setUserAttr */.Z.setUserAttr(user, attr);
5771
5769
  });
5770
+ if (is_lead) util/* default.setUserAttr */.Z.setUserAttr(user, {
5771
+ key: 'lead_source',
5772
+ text: 'widget'
5773
+ });
5772
5774
  let firstmsg = util/* default.get */.Z.get(data, 'question.value');
5773
5775
  let groupid = util/* default.get */.Z.get(data, 'group.value', '');
5774
5776
 
@@ -0,0 +1 @@
1
+ (self.webpackChunk_subiz_widget_v4=self.webpackChunk_subiz_widget_v4||[]).push([[132],{8132:(t,e,s)=>{"use strict";s.r(e),s.d(e,{default:()=>kt});var i=s(819),r=s(2493),o=s(6400);class a extends r.up{render(){var t=this.props.emojiCode;if(i.Z.size(t)<3)return null;var e=t.replace(/:/g,"");return(0,o.h)("i",{"data-tooltip":t,class:`emoji emoji--${e}`})}}var n=s(6755);let h=s(4761);class l extends r.up{constructor(t){super(t),this.setState({opacity:0,previewEvent:{},displayPreview:!1}),this.loadGreeting(),this.props.store.onUpdate(this,(t=>this.forceUpdate())),this.props.store.onConvoEvent(this,(t=>{if("message_sent"!==i.Z.get(t,"type"))return;let e=i.Z.get(t,"by.type");if("system"!==e&&"agent"!==e)return;let s=!1;i.Z.map(i.Z.get(t,"data.message.attachments",[]),(t=>{t&&"quick_replies"===t.type&&(s=!0)})),s||this.setState({displayPreview:!0,previewEvent:t})}))}fixMissingSetting(t){return t=i.Z.cloneDeep(t),i.Z.get(t,"desktop_button.background_image_url")&&(t.desktop_button.background_image_url=this.props.store.replaceFileUrl(t.desktop_button.background_image_url)),i.Z.get(t,"desktop_button.background_mask_url")&&(t.desktop_button.background_mask_url=this.props.store.replaceFileUrl(t.desktop_button.background_mask_url)),i.Z.get(t,"mobile_button.background_image_url")&&(t.mobile_button.background_image_url=this.props.store.replaceFileUrl(t.mobile_button.background_image_url)),i.Z.get(t,"mobile_button.background_mask_url")&&(t.mobile_button.background_mask_url=this.props.store.replaceFileUrl(t.mobile_button.background_mask_url)),t}render(){let t=this.props.plugin.chatbox,e=i.Z.get(t,"desktop_button.position")||"right";if(this.props.store.isMobile()&&(e=i.Z.get(t,"mobile_button.position")||e,i.Z.get(t,"mobile_button.hidden")))return null;if(i.Z.get(t,"desktop_button.hidden"))return null;let s="widget-layout widget-layout--"+e,r=this.state.opacity;return this.props.isShow||(s+=" widget-layout--hidden",r=0),(0,o.h)("div",{class:s,style:"opacity: "+r+" !important"},this.renderPreview(),this.renderButton())}ClearPreview(){this.setState({previewEvent:{}})}ShowGreeting(){let t=i.Z.get(this.props.plugin,"chatbox.greeting",{}),e=this.props.store.matchAgent("*"),s=t.agent_id;s||(s=function(t){var e=i.Z.filter(t,(t=>"agent"===t.type));return e[Math.floor(Math.random()*i.Z.size(e))]||{}}(e).id);let r=this.props.t.i18n(i.Z.get(t,"greeting",{}))||t.message;this.setState({previewEvent:{by:{id:s,type:"agent"},data:{message:{text:r,format:"plaintext"}}},displayPreview:!0})}HideGreeting(){this.setState({previewEvent:{}})}loadGreeting(){let t=this.props.plugin.chatbox;if((new i.Z.Date).getTime()-this.props.store.matchClosePreviewAt()<p)return;let e=i.Z.get(t,"greeting",{});(this.props.t.i18n(i.Z.get(e,"greeting",{}))||e.message)&&e.enabled?this.ShowGreeting():this.setState({previewEvent:{}})}onClick(){let t=this.props.store.matchLastview();return i.Z.get(t,"view")&&("list"!==t.view||i.Z.size(this.props.store.matchConvo("*"))>0)?this.props.onClick&&this.props.onClick(Object.assign({},t.opts,{view:t.view})):this.onPreviewClick()}onPreviewClick(t){let e=i.Z.convoOfEv(this.state.previewEvent);if(!e){let t=i.Z.map(this.props.store.matchConvo("*")),s=i.Z.find(t,(t=>!i.Z.isConvoSeen(t,this.props.store.matchUser().id)));s||(s=t[0]||{}),e=s.id}this.closePreview(t),this.props.onClick&&this.props.onClick({view:"chat",cid:e})}renderUnread(){let t=this.props.store.matchUnread();return 0===t?null:(0,o.h)("div",{class:"chat-button--unread"},t)}renderPreview(){let t=this.props.store.matchAccount(),e=this.props.plugin.chatbox,s=i.Z.get(this.state.previewEvent,"by.display_id",i.Z.get(this.state.previewEvent,"by.id")),r=i.Z.cloneDeep(this.props.store.matchAgent(s))||{};r.fullname=r.fullname||i.Z.get(t,"name")||this.props.t("agent"),r.avatar_url=r.avatar_url||h;let a=i.Z.get(e,"desktop_button.position")||"right";this.props.store.isMobile()&&(a=i.Z.get(e,"mobile_button.position")||a);let n="widget-preview widget-preview--"+a;this.state.displayPreview||(n+=" widget-preview--hidden");var l=this.renderMessagePreview(this.state.previewEvent,this.props.t("sent_you_a_message"));return 0===i.Z.size(l)&&(n+=" widget-preview--hidden"),(0,o.h)("div",{class:n},(0,o.h)("div",{class:"widget-preview--body"},(0,o.h)("img",{alt:"widget avatar",class:"widget-preview--avatar",src:this.props.store.replaceFileUrl(r.avatar_url),onError:t=>this.onProfileError(t),onload:t=>this.onProfileReady()}),(0,o.h)("div",{class:"widget-preview--content",onClick:t=>this.onPreviewClick(t)},(0,o.h)("div",{class:"widget-preview--title"},r.fullname),(0,o.h)("p",{class:"widget-preview--message"},l)),(0,o.h)("div",{class:"widget-preview--btn-close",onClick:t=>this.closePreview(t)})),(0,o.h)("div",{class:"widget-preview--action",onClick:t=>this.onPreviewClick(t)},(0,o.h)("div",{class:"widget-preview--action-text"},this.props.t("chat_now"))))}onProfileReady(){this._buttonLoaded&&this.setState({opacity:1}),this._profileLoaded=!0}onButtonReady(){this._profileLoaded&&this.setState({opacity:1}),this._buttonLoaded=!0}renderButton(){let t=this.props.plugin.chatbox;t=this.fixMissingSetting(t);let e=i.Z.get(t,"desktop_button.background_image_url")||i.Z.get(t,"desktop_button.background_mask_url")||n,s=i.Z.get(t,"background")||c,r=i.Z.get(t,"desktop_button.position")||"right",a=i.Z.get(t,"desktop_button.background_image_url"),h=i.Z.get(t,"desktop_button.background_mask_url");if(this.props.store.isMobile()){e=i.Z.get(t,"mobile_button.background_image_url")||i.Z.get(t,"mobile_button.background_mask_url")||e,r=i.Z.get(t,"mobile_button.position")||r;let s=i.Z.get(t,"mobile_button.background_image_url"),o=i.Z.get(t,"mobile_button.background_mask_url");(s||o)&&(a=s,h=o)}let l="chat-button--white-bg";!a&&h&&(l+=" chat-button--white-bg--mask-only");let p="";a=this.props.store.replaceFileUrl(a),e=this.props.store.replaceFileUrl(e),h=this.props.store.replaceFileUrl(h),a||h||(l+=" chat-button--white-bg--mask-only",p=`\n\t\t\t\t-webkit-mask-image: url("${encodeURI(d)}") !important;\n\t\t\t\t-o-mask-image: url("${encodeURI(d)}") !important;\n\t\t\t\t-moz-mask-image: url("${encodeURI(d)}") !important;\n\t\t\t\tmask-image: url("${encodeURI(d)}") !important;\n\t\t\t\theight: 70px !important;\n\t\t\t\twidth: 70px !important;\n\t\t\t\tbackground: ${s} !important;\n\t\t\t`),a&&h&&(p=`\n\t\t\t\t-webkit-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\t-o-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\t-moz-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\tmask-image: url("${encodeURI(h)}") !important;\n\t\t\t\tbackground-image: url("${encodeURI(a)}") !important;\n\t\t\t\tbackground-repeat: no-repeat !important;\n\t\t\t`),a&&!h&&(p=`\n\t\t\t\tbackground-image: url("${encodeURI(a)}") !important;\n\t\t\t\tbackground-repeat: no-repeat !important;\n\t\t\t`),!a&&h&&(p=`\n\t\t\t\t-webkit-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\t-o-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\t-moz-mask-image: url("${encodeURI(h)}") !important;\n\t\t\t\tmask-image: url("${encodeURI(h)}") !important;\n\t\t\t\theight: 70px !important;\n\t\t\t\twidth: 70px !important;\n\t\t\t\tbackground: ${s} !important;\n\t\t\t`);let u="chat-button chat-button--"+r;return(0,o.h)("div",{class:u,onClick:t=>this.onClick(t)},(0,o.h)("div",{class:l}),(0,o.h)("div",{class:"chat-button--img-container",style:p},(0,o.h)("img",{width:"70",height:"70",alt:"chat button",class:"chat-button--img",onload:()=>this.onButtonReady(),src:e,onError:(t,e)=>this.onChatButtonError(t,e)})),this.renderUnread())}onProfileError(t){t.target.src=h,this.onProfileReady()}onChatButtonError(t){this._onChatButtonErrorExecuted||(this._onChatButtonErrorExecuted=!0,t.target.src=n)}renderMessagePreview(t,e){e=e||"Sent you a message";let s=i.Z.get(t,"data.message.text");var r=i.Z.get(t,"data.message.format");if(r&&"plaintext"!==r&&(s=e),!s&&i.Z.size(i.Z.get(t,"data.message.attachments"))>0&&(s=e),!s)return null;let n=i.Z.get(t,"by.type");return i.Z.extractText(s).map((t=>"emoji"===t.type?(0,o.h)(a,{emojiCode:t.text,byType:n}):t.text))}closePreview(t){t&&(t.preventDefault(),t.stopPropagation()),this.setState({displayPreview:!1}),this.props.store.closePreview(),this.forceUpdate()}}const p=18e5,d="https://file-subiz.com/bubble_11.svg",c="linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)";var u=s(8430);class m extends r.up{constructor(t){super(t)}render(){if(this.props.store.isMobile())return null;var t=`https://subiz.com.vn/?utm_source=id-${this.props.store.matchUser().account_id}&utm_medium=widget&utm_campaign=widget_referral`;return(0,o.h)("div",{class:"poweredby"},(0,o.h)("a",{href:t,class:"poweredby--text",target:"_blank",rel:"noreferrer"},(0,o.h)("img",{width:"14",height:"10",class:"poweredby--subiz-logo",src:u,alt:"power by"})," Subiz"))}}class g extends r.up{constructor(t){super(t)}render(){let t=this.props.plugin.chatbox,e=this.props.store.matchAgent("*");var r=i.Z.map(this.props.agent_ids,(t=>e[t]));if(void 0===this.props.agent_ids||0===i.Z.size(this.props.agent_ids)){var a=i.Z.get(t,"header.agent_ids",[]);r=0!==(a=i.Z.filter(a,(t=>!!e[t]))).length?i.Z.map(a,(t=>e[t])):i.Z.filter(e,(t=>"agent"===t.type))}r=i.Z.filter(r,(t=>!!t));let n=this.props.store.matchAccount();var h=this.props.tooltipPos||"bottom",l=this.props.mode||"primary";if(0===r.length)return(0,o.h)("div",{class:`group-avatar group-avatar--${l}`},(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":n.name,"data-tooltip-position":h},(0,o.h)("img",{width:35,height:35,alt:"agent avatar left",class:"avatar group-avatar--agent-left",src:this.props.store.replaceFileUrl(n.logo_url)||s(9895)})));if(1===r.length){var p=r[0],d="primary"===l?"group-avatar--agent-middle":"group-avatar--agent-left";return(0,o.h)("div",{class:`group-avatar group-avatar--${l}`},(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":p.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{width:35,height:35,class:`avatar ${d}`,alt:"agent avatar",src:this.props.store.replaceFileUrl(p.avatar_url)||s(4761)})))}if(2===r.length){let t=r[0],e=r[1];return(0,o.h)("div",{class:`group-avatar group-avatar--${l}`},(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":t.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{width:35,height:35,alt:"agent avatar left",class:"avatar group-avatar--agent-left",src:this.props.store.replaceFileUrl(t.avatar_url)||s(4761)})),(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":e.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{alt:"agent avatar right",width:35,height:35,class:"avatar group-avatar--agent-right",src:this.props.store.replaceFileUrl(e.avatar_url)||s(4761)})))}let c=r[0],u=r[1],m=r[2];return(0,o.h)("div",{class:`group-avatar group-avatar--${l}`},(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":c.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{width:35,height:35,alt:"agent avatar left",class:"avatar group-avatar--agent-left",src:this.props.store.replaceFileUrl(c.avatar_url)||s(4761)})),(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":u.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{alt:"agent avatar middle",width:35,height:35,class:"avatar group-avatar--agent-middle",src:this.props.store.replaceFileUrl(u.avatar_url)||s(4761)})),(0,o.h)("div",{class:"d-inline-block pos-relative","data-tooltip":m.fullname||n.name,"data-tooltip-position":h},(0,o.h)("img",{width:35,height:35,alt:"agent avatar right",class:"avatar group-avatar--agent-right",src:this.props.store.replaceFileUrl(m.avatar_url)||s(4761)})))}}class v extends r.up{constructor(t){super(t)}render(){let t="widget-header",e=!1,s=!1,r="list"!==this.props.view&&!0,a=this.props.plugin.chatbox||{},n=i.Z.get(a,"header.layout");return r?t+=" widget-header--collapsed":(t+=" widget-header--convo-expanded",e="social"===n,s=!e),(0,o.h)("div",{class:t},this.renderCollapsedHeader(r),this.renderSocial(e),this.renderTeam(s))}renderCollapsedHeader(t){let e=this.props.plugin.chatbox||{},s=this.props.store.matchAccount().is_online?this.props.t("agent_online"):this.props.t("agent_offline"),r=i.Z.get(e,"tagline",{}),a=this.props.t.i18n(r)||e.introduction||s,n=i.Z.map(this.getAgentJoined(this.props.cid),(t=>t.id)),h="widget-header--inner widget-header--inner--collapsed";return t||(h+=" widget-header--inner--hidden"),(0,o.h)("div",{class:h},this.renderBackButton(),(0,o.h)(g,{plugin:this.props.plugin,store:this.props.store,mode:"secondary",agent_ids:n}),(0,o.h)("div",{class:"widget-header--title-container"},(0,o.h)("div",{class:"widget-header--title"},this.getTitle()),(0,o.h)("div",{class:"widget-header--description",title:a},a)),this.renderCloseButton())}renderSocial(t){let e=this.props.plugin.chatbox||{},s=this.props.store.matchAccount(),r=i.Z.get(e,"header.links")||[],n=i.Z.map(r,(t=>t.url&&t.type&&"subiz"!==t.type?"email"===t.type?(0,o.h)("div",null,(0,o.h)("a",{href:`mailto:${t.url}`,title:t.url},(0,o.h)("i",{class:`social__links-logo social__links-logo--${t.type}`}))):(0,o.h)("div",null,(0,o.h)("a",{href:t.url,target:"_blank",title:t.url,rel:"noreferrer"},(0,o.h)("i",{class:`social__links-logo social__links-logo--${t.type}`}))):null)),h=i.Z.get(e,"tagline",{});var l=this.props.t.i18n(h)||e.introduction||this.props.t("team_intro")||"Chúng tôi sẵn sàng trợ giúp :wave:.\nVui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi của bạn",p=i.Z.extractText(l).map((t=>"emoji"===t.type?(0,o.h)(a,{emojiCode:t.text}):t.text));let d="widget-header--inner widget-header--inner--expanded";return t||(d+=" widget-header--inner--hidden"),(0,o.h)("div",{class:d},(0,o.h)("div",{class:"widget-header-expand-container"},(0,o.h)("div",{class:"widget-header--top-wrapper"},(0,o.h)("div",{class:"widget-header--title"},this.getTitle()),this.renderCloseButton()),(0,o.h)("div",{class:"widget_header__body widget_header__body__social"},(0,o.h)("img",{alt:"logo",class:"social__account_logo",src:this.props.store.replaceFileUrl(i.Z.get(s,"logo_url"))}),(0,o.h)("div",null,(0,o.h)("div",{class:"social__introduction"},p),(0,o.h)("div",{class:"social__links"},n)))))}renderTeam(t){let e=this.props.plugin.chatbox||{},s=i.Z.get(e,"tagline",{});var r=this.props.t.i18n(s)||e.introduction||this.props.t("team_intro")||"Chúng tôi sẵn sàng trợ giúp :wave:.\nVui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi của bạn",n=i.Z.extractText(r).map((t=>"emoji"===t.type?(0,o.h)(a,{emojiCode:t.text}):t.text));let h="widget-header--inner widget-header--inner--expanded";return t||(h+=" widget-header--inner--hidden"),(0,o.h)("div",{class:h},(0,o.h)("div",{class:"widget-header-expand-container"},(0,o.h)("div",{class:"widget-header--top-wrapper"},(0,o.h)("div",{class:"widget-header--title"},this.getTitle()),this.renderCloseButton()),(0,o.h)("div",{class:"widget_header__body"},(0,o.h)("div",{class:"widget-header--avatar-wrapper"},(0,o.h)(g,{plugin:this.props.plugin,store:this.props.store,mode:"primary"})),(0,o.h)("div",{class:"widget-header--title-container"},(0,o.h)("div",{class:"widget-header--description"},n)))))}getTitle(){let t=this.props.plugin.chatbox||{},e=this.props.store.matchAccount(),s=this.getAgentJoined(this.props.cid),r=i.Z.get(this.props.plugin,"chatbox.caption",{}),o=this.props.t.i18n(r)||t.title;return f(s)||o||e.name||this.props.t("widget_title")}renderBackButton(){let t=this.props.store.matchConvo("*");if(0===i.Z.size(t))return null;var e=null;let s=this.props.store.matchUser(),r=0;return i.Z.map(t,(t=>{t.id!=this.props.cid&&(i.Z.isConvoSeen(t,s.id)||r++)})),0!==r&&(e=(0,o.h)("span",{class:"widget-header--total-unread-convo"},r)),(0,o.h)("div",{class:"widget-header--wrap-button-back "+(r?"widget-header--has-convo-unred":""),onClick:t=>this.onBackClick(t)},(0,o.h)("div",{class:"widget-header--button-back","data-tooltip":this.props.t("menu_back")}),e)}renderCloseButton(){return(this.props.plugin.chatbox||{}).hide_close_button?null:(0,o.h)("div",{class:"widget-header--button widget-header--button-close","data-tooltip":this.props.t("close"),"data-tooltip-position":"bottom",onClick:t=>this.onCloseClick(t)},(0,o.h)("span",{class:"widget-header--button-close-icon"}))}onBackClick(t){t.stopPropagation(),t.preventDefault(),this.props.onGotoList&&this.props.onGotoList()}onCloseClick(t){t.stopPropagation(),t.preventDefault(),this.props.onClose&&this.props.onClose()}getAgentJoined(t){var e=this.props.store.matchConvo(t)||{};return i.Z.filter(e.members,(t=>"agent"===t.type&&"active"===t.membership))}}let f=t=>i.Z.map(t,(t=>t.name)).join(", ");class _ extends r.up{constructor(t){var e,s,r;super(t),e=this,s="onEnter",r=i.Z.throttle((function(){this.submitMessage()}),50),s in e?Object.defineProperty(e,s,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[s]=r,this.refFileInput=(0,o.Vf)(),this.refMessageInput=(0,o.Vf)(),this.props.store.onUpdate(this,(t=>this.forceUpdate())),this.props.store.onConvoEvent(this,(t=>{i.Z.convoOfEv(t)===this.props.cid&&this.forceUpdate()})),this.focus(),this._forceUpdate=i.Z.throttle((()=>{this.forceUpdate()}),500),this.resizeInput=i.Z.throttle((function(){const t=this.refMessageInput.current;t.style.setProperty("height","1em","important");const e=Math.min(200,t.scrollHeight);t.style.setProperty("height",`${e}px`,"important")}),5)}render(){var t=(0,o.h)("div",{class:"d-flex flex-row align-self-end"},this.renderEmoji(),(0,o.h)("div",{"data-tooltip-poasition":"top-left",class:"message-input--button message-input--attachment-button",onClick:t=>this.selectFile(t)}));i.Z.trim(this.refMessageInput.current&&this.refMessageInput.current.value).length>0&&(t=(0,o.h)("div",{class:"d-flex flex-row align-self-end"},this.renderEmoji(),(0,o.h)("div",{"data-tooltip-position":"top-left",class:"message-input--button message-input--send-button",onClick:()=>this.submitMessage()})));var e="",s=this.hasUnfinishRequiredFormOrLock()||this.props.disabled;return s&&(e="message-input--disabled"),(0,o.h)("div",{class:`message-input ${e}`,onClick:t=>{this.refMessageInput.current&&this.refMessageInput.current.focus()}},(0,o.h)("input",{class:"d-none",ref:this.refFileInput,type:"file",onChange:t=>this.sendFile(t),multiple:!0}),(0,o.h)("textarea",{disabled:s,class:"message-input--input",maxlength:"1024",placeholder:this.props.t("message_input_help"),ref:this.refMessageInput,rows:"1",onInput:t=>this.onChange(t),onPaste:t=>this.pasteImage(t),"data-emojiable":"true",onKeydown:t=>this.onKeydown(t)}),t)}hasUnfinishRequiredFormOrLock(){let t=this.props.store.matchConvo(this.props.cid);if("ended"===i.Z.get(t,"state"))return!1;let e=this.props.store.listEvents(this.props.cid);e=i.Z.orderBy(e,"created","desc").filter((t=>"message_sent"===t.type));let s=i.Z.get(e[0],"data.message.attachments",[]);if(i.Z.find(s,(t=>i.Z.get(t,"lock_input"))))return!0;var r;for(let t of e)if("user"!==i.Z.get(t,"by.type")){r=t;break}s=i.Z.get(r,"data.message.attachments",[]);let o=i.Z.filter(s,(t=>{if(!t)return!1;if("form"!==t.type&&"ask_info_form"!==t.type)return!1;var e=t.form;return!(!e||!(i.Z.parseJSON(e.state)||{}).require_finished&&"ask_info_form"!==t.type||function(t){let e=i.Z.get(t,"fields")||[];return i.Z.find(e,(t=>!!t.answered))}(t.form))}));return i.Z.size(o)>0}renderEmojiPopup(){return this.state.openEmoji?(0,o.h)("div",{class:"emoji-picker","v-clickaway":t=>this.setState({openEmoji:!1})},(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":like:"),"data-tooltip":":like:",class:"emoji-picker--item emoji--like"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":unlike:"),"data-tooltip":":unlike:",class:"emoji-picker--item emoji--unlike"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":angry:"),"data-tooltip":":angry:",class:"emoji-picker--item emoji--angry"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":confused:"),"data-tooltip":":confused:",class:"emoji-picker--item emoji--confused"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":crying:"),"data-tooltip":":crying:",class:"emoji-picker--item emoji--crying"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":grinning:"),"data-tooltip":":grinning:",class:"emoji-picker--item emoji--grinning"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":heart-eyes:"),"data-tooltip":":heart-eyes:",class:"emoji-picker--item emoji--heart-eyes"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":neutral:"),"data-tooltip":":neutral:",class:"emoji-picker--item emoji--neutral"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":sad:"),"data-tooltip":":sad:",class:"emoji-picker--item emoji--sad"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":sleepy:"),"data-tooltip":":sleepy:",class:"emoji-picker--item emoji--sleepy"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":smiling:"),"data-tooltip":":smiling:",class:"emoji-picker--item emoji--smiling"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":surprised:"),"data-tooltip":":surprised:",class:"emoji-picker--item emoji--surprised"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":tired:"),"data-tooltip":":tired:",class:"emoji-picker--item emoji--tired"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":tongue-out:"),"data-tooltip":":tongue-out:",class:"emoji-picker--item emoji--tongue-out"})),(0,o.h)("div",{class:"emoji-picker-background-item"},(0,o.h)("div",{onClick:()=>this.emojiPick(":wink:"),"data-tooltip":":wink:",class:"emoji-picker--item emoji--wink"}))):null}focus(){this.props.disabled||(this.refMessageInput.current&&this.refMessageInput.current.focus(),setTimeout((()=>{this.refMessageInput.current&&this.refMessageInput.current.focus()})),setTimeout((()=>{this.refMessageInput.current&&this.refMessageInput.current.focus()}),100))}renderEmoji(){return(0,o.h)("div",null,this.renderEmojiPopup(),(0,o.h)("div",{class:"message-input--button message-input--emoji-button",onClick:t=>this.toggleEmoji(t)}))}toggleEmoji(t){t.stopPropagation(),this.focus(),this.props.disabled||this.setState({openEmoji:!this.state.openEmoji})}emojiPick(t){const e=this.refMessageInput.current,s=e.selectionStart,i=this.refMessageInput.current.value;this.setState({openEmoji:!1}),this.refMessageInput.current.value=[i.slice(0,s),t,i.slice(s)].join(""),this.resizeInput(),e.focus()}onKeydown(t){if(13===t.keyCode&&!1===t.shiftKey)return this.onEnter(),t.preventDefault();this._forceUpdate(),this.sendTyping()}onChange(){this.resizeInput()}selectFile(){this.props.disabled||this.refFileInput.current.click()}sendFile(){let t=this.refFileInput.current;this._sendFile(t.files),t.value=""}_sendFile(t){if(0===i.Z.size(t))return;if(this.props.disabled)return;let e=i.Z.map(t,(t=>({type:"file",mimetype:t.type,name:t.name,_file:t,size:t.size})));this.props.onSend&&this.props.onSend({attachments:e})}async submitMessage(t){(t=t||i.Z.trim(this.refMessageInput.current.value)||"")&&(this.props.disabled||(this.refMessageInput.current.value="",this.resizeInput(),this.setState({openEmoji:!1}),this.props.onSend&&this.props.onSend({text:t,format:"plaintext"})))}sendTyping(){if(this.props.cid)return this.props.store.typing(this.props.cid)}pasteImage(t){if(!(window.File&&window.FileReader&&window.FileList&&window.Blob))return;let e=new i.Z.Date;const s=`Paste-image-${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}-${e.getHours()}-${e.getMinutes()}-${e.getSeconds()}`;let r=null;const o=t.clipboardData.items[0];if(0===o.type.indexOf("image")&&(r=o.getAsFile()),!r)return;const a=[r,new ArrayBuffer],n=new File(a,`${s}.png`,{type:"image/png"});this._sendFile([n])}}class y extends r.up{constructor(t){super(t)}render(){var t=i.Z.get(this.props.ev,"data.message.attachments",[]),e=[];let s=i.Z.get(this.props.ev,"by.type");if(i.Z.each(t,((t,s)=>{if(t&&i.Z.includes(t.mimetype,"image")&&t.url){var r=t.url;r.startsWith("https://")||r.startsWith("http://")||r.startsWith("content://")||r.startsWith("data:")||(t.url=this.props.store.FileURL+r),e.push(t)}})),0===e.length)return null;var r=i.Z.map(e,((t,e)=>(0,o.h)("div",{class:`image-attachment image-attachment--${s}`},(0,o.h)("a",{href:this.props.store.replaceFileUrl(t.thumbnail_url||t.url),target:"_blank"},(0,o.h)("img",{alt:!0,class:"image-attachment__img",src:this.props.store.replaceFileUrl(t.thumbnail_url||t.url),onload:t=>this.props.onLoad&&this.props.onLoad()})))));return"agent"===s?(0,o.h)("div",{class:"message-agent"},r):(0,o.h)("div",{class:"message-user"},r)}}class b extends r.up{constructor(t){super(t)}render(){let t=i.Z.get(this.props.ev,"by.type");var e=i.Z.get(this.props.ev,"data.message.attachments",[]),s=[];if(i.Z.each(e,((t,e)=>{t&&i.Z.includes(t.mimetype,"audio")&&s.push(t)})),0===s.length)return null;var r=i.Z.map(s,((e,s)=>(0,o.h)("div",{key:s,class:`audio-attachment audio-attachment--${t}`},(0,o.h)("audio",{class:"audio-attachment__audio",controls:!0},(0,o.h)("source",{src:this.props.store.replaceFileUrl(e.url),type:e.mimetype})))));return(0,o.h)("div",{class:`message-${t}`},r)}}class w extends r.up{render(){var t=i.Z.get(this.props.ev,"by.type","agent"),e=i.Z.get(this.props.ev,"data.message.attachments",[]),s=[];if(i.Z.each(e,(t=>{t&&(t.url||t._file)&&(i.Z.includes(t.mimetype,"video")||i.Z.includes(t.mimetype,"audio")||i.Z.includes(t.mimetype,"image")||"button"===t.type||"quick_replies"===t.type||"form"===t.type||"form_submit"===t.type||s.push(t))})),0===s.length)return null;var r=i.Z.map(s,((e,s)=>(0,o.h)("div",{key:s,class:`file-attachment file-attachment--${t}`},(0,o.h)("a",{class:"file-attachment--link",href:this.props.store.replaceFileUrl(e.url),target:"_blank"},(0,o.h)("span",{class:"file-attachment--download mr-2"}),(0,o.h)("span",{class:"file-attachment--filename"},e.name)))));return(0,o.h)("div",{class:`message-${t}`},r)}}class k extends r.up{constructor(t){super(t)}render(){if(0===i.Z.size(this.props.buttons))return null;var t=i.Z.map(this.props.buttons,((t,e)=>"call_button"===t.type?(0,o.h)("a",{class:"url-button-attachment",href:"tel:"+t.phone_number,key:e,title:t.title},this.props.t.i18n(t.i18n_title)||t.title):"url_button"===t.type?(0,o.h)("a",{class:"url-button-attachment",href:t.url,target:"_blank",key:e,title:t.title},this.props.t.i18n(t.i18n_title)||t.title||t.url):"postback_button"===t.type?(0,o.h)("a",{class:"url-button-attachment",href:"javascript:;",onClick:e=>this.props.onSelect(t)},this.props.t.i18n(t.i18n_title)||t.title):("widget_ask_desktop_notify_button"===t.type||t.type,null)));return(0,o.h)("div",{class:"button-attachments"},t)}}class Z extends r.up{constructor(t){super(t)}render(){if("user"===i.Z.get(this.props.ev,"by.type"))return null;let t=[],e=i.Z.get(this.props.ev,"data.message.attachments",[]);return i.Z.each(e,((e,s)=>{e&&"button"===i.Z.get(e,"type")&&i.Z.each(i.Z.get(e,"buttons")||[],(e=>t.push(e)))})),(0,o.h)(k,{store:this.props.store,buttons:t,t:this.props.t})}}class x extends r.up{constructor(t){super(t)}render(){if("user"===i.Z.get(this.props.ev,"by.type"))return null;let t=[];if(i.Z.map(i.Z.get(this.props.ev,"data.message.attachments",[]),(e=>{e&&"quick_replies"===e.type&&(t=i.Z.get(e,"quick_replies",[]))})),t=i.Z.filter(t,(t=>t.title)),0===t.length)return null;let e=i.Z.convoOfEv(this.props.ev),s=this.props.store.matchConvo(e);if("ended"===i.Z.get(s,"state"))return null;let r=i.Z.map(this.props.store.listEvents(e));r=i.Z.orderBy(r,"created","asc").filter((t=>"message_sent"===t.type));let a=0;for(var n=0;n<r.length;n++)if(r[n].id===this.props.ev.id){a=n;break}for(n=a+1;n<r.length;n++)if("user"===i.Z.get(r[n],"by.type"))return null;let h=i.Z.map(t,(t=>(0,o.h)("div",{class:"message_quick_reply",onClick:e=>this.props.onSelect(t)},t.title)));return(0,o.h)("div",{class:"message_quick_replies"},h)}}class S extends r.up{constructor(t){super(t),this.setState({search:"",isShow:!1})}render(){let t=i.Z.filter(this.props.items,(t=>{let e=this.state.search.toLowerCase();return(t||"").toLowerCase().indexOf(e)>-1})),e=i.Z.map(t,(t=>(0,o.h)("li",{class:"custom-select--item-options",onClick:()=>this.add(t)},t))),s=i.Z.map(this.props.selected,((t,e)=>(0,o.h)("div",{class:"custom-select--selected-item",onClick:t=>this.remove(t,e)},t,(0,o.h)("i",{class:"icn-delete delete-tag"})))),a=(0,o.h)("div",{class:"custom-select--wrap-options"},(0,o.h)("input",{onClick:t=>{t.preventDefault(),t.stopPropagation(),this.setState({isShow:!0})},type:"text",onInput:t=>this.setState({search:t.target.value}),value:this.state.search,placeholder:"Tìm kiếm",class:"custom-select--input-search"}),(0,o.h)("ul",{class:"custom-select--items-options"},e));return this.state.isShow||(a=null),(0,o.h)("div",{class:"form-control custom-select"},(0,o.h)(r.u$,{onClickaway:t=>this.clickaway()},(0,o.h)("div",{class:"custom-select--wrap-selected",onClick:()=>this.setState({isShow:!this.state.isShow})},(0,o.h)("div",{class:"custom-select--selected-items"},s),a,(0,o.h)("div",{class:"custom-select--icon-dropdown"},(0,o.h)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,o.h)("g",{opacity:"0.6"},(0,o.h)("path",{d:"M7 9.5L12 14.5L17 9.5H7Z",fill:"black"})))))))}clickaway(){this.setState({isShow:!1})}add(t){this.props.onAddItem&&this.props.onAddItem(t)}remove(t,e){t.preventDefault(),t.stopPropagation(),this.props.onRemoveItem&&this.props.onRemoveItem(e)}}class C extends r.up{constructor(t){super(t),this.props.store.onUpdate(this,(t=>this.forceUpdate()));let e=this.props.store.matchUser(),s=i.Z.get(this.props.form,"fields")||[],r=i.Z.map(s,(t=>{let s=t.is_required||!1;var r=i.Z.parseJSON(t.state)||{};s||(s=r.require||!1);var o=i.Z.getUserAttr(e,t.name,r.type||"text");return{name:t.name,items:t.items,value:i.Z.parseJSON(t.answer)||i.Z.parseJSON(t.default_answer)||o,is_required:s,label:t.title,type:t.input_type}}));this.setState({formData:r})}isSummited(){return!!i.Z.find(this.state.formData,(t=>!!t.answered))||"ended"===this.props.store.matchConvo(i.Z.convoOfEv(this.props.ev)).state}render(){if(0===i.Z.size(this.state.formData))return null;let t=this.renderFields(),e=null;return this.isSummited()||(e=(0,o.h)("div",{class:"mt-2"},(0,o.h)("button",{onClick:t=>this.submit(),type:"button",class:"form-attachment--submit-btn"},this.props.t("btn_submit_form_attachment")))),(0,o.h)("div",{class:"form-attachment",onClick:t=>t.stopPropagation()},this.props.t(this.props.form.title)||this.props.t("capture_lead_title"),t,e)}focus(){if(this.props.store.isPreview)return;if(0===i.Z.size(this.state.formData))return;let t;if(this.isFormFilled()){var e=Object.keys(this.state.formData),s=e[i.Z.size(e)-1];t=this["field."+D(this.state.formData[s].name)]}else{var r=this.firstUnfilledField();if(!r)return;t=this["field."+D(r.name)]}t&&t.focus()}firstUnfilledField(){return i.Z.find(this.state.formData,(t=>null==t.value||""===t.value))}isFormFilled(){return!i.Z.find(this.state.formData,(t=>null==t.value||""===t.value))}onInputChange(t,e){let s=i.Z.cloneDeep(this.state.formData);s[t].value=e,this.setState({formData:s})}onListAddItem(t,e){let s=i.Z.cloneDeep(this.state.formData),r=s[t];r.value=r.value||[],r.value.push(e),this.setState({formData:s})}onListRemoveItem(t,e){let s=i.Z.cloneDeep(this.state.formData),r=s[t];r.value=r.value||[],r.value.splice(e,1),this.setState({formData:s})}renderFields(){if(0===i.Z.size(this.state.formData))return null;let t=null;return t=i.Z.map(this.state.formData,((t,e)=>{let s=null;var r=t.error?"input--error":"";if("text"===t.type)s=this.isSummited()?(0,o.h)("div",{class:"form-control--container"},(0,o.h)("input",{disabled:!0,ref:e=>{this["field."+D(t.name)]=e},value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"text"}),(0,o.h)("i",{class:"form-control--check"})):(0,o.h)("input",{ref:e=>{this["field."+D(t.name)]=e},value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"text"});else if("number"===t.type)s=this.isSummited()?(0,o.h)("div",{class:"form-control--container"},(0,o.h)("input",{disabled:!0,ref:e=>{this["field."+D(t.name)]=e},value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"number"}),(0,o.h)("i",{class:"form-control--check"})):(0,o.h)("input",{ref:e=>{this["field."+D(t.name)]=e},value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"number"});else if("boolean"===t.type)s=(0,o.h)("div",{class:"checkbox"},(0,o.h)("input",{ref:e=>{this["field."+D(t.name)]=e},type:"checkbox",id:"checkbox."+this.props.ev.id+"."+t.name,onChange:t=>this.onInputChange(e,ev.target.checked),checked:t.value}),(0,o.h)("label",{class:"checkbox--label",for:"checkbox."+this.props.ev.id+"."+t.name},t.label),(0,o.h)("div",{class:"checkbox--check"},(0,o.h)("div",null)));else if("list"===t.type){let r=t.value||[],a=i.Z.filter(i.Z.get(t,"items",[]),(t=>!r.includes(t)));s=(0,o.h)(S,{selected:r,items:a,onAddItem:t=>this.onListAddItem(e,t),onRemoveItem:t=>this.onListRemoveItem(e,t)})}else"datetime"===t.type&&(s=(0,o.h)("input",{ref:e=>{this["field."+D(t.name)]=e},value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"date"}));let a=t.label;return"fullname"===t.name?a=this.props.t("fullname"):"emails"===t.name?a=this.props.t("email"):"phones"===t.name&&(a=this.props.t("phones")),(0,o.h)("div",null,(0,o.h)("p",{class:"label mt-3"},a,t.is_required?(0,o.h)("span",{class:"ml-1 red"},"*"):""),t.error?(0,o.h)("div",{class:"form-control--valid-input--error"},t.error):"",s)})),(0,o.h)("div",null,t)}async submit(){var t=!1;if(i.Z.map(this.state.formData,(e=>{e.is_required&&(void 0===e.value||""===e.value||0===i.Z.size(e.value)&&Array.isArray(e.value))?(e.error=this.props.t("error_empty"),t=!0):e.error="","emails"===e.name&&e.value&&(i.Z.isEmail(e.value)||(e.error=this.props.t("error_email_invalid"),t=!0))})),this.forceUpdate(),t)return;let e={},s=i.Z.cloneDeep(this.state.formData);i.Z.map(s,(t=>{var s={key:t.name};t.answered=(new i.Z.Date).getTime(),"number"===t.type&&(s.number=parseInt(t.value),t.answer=i.Z.stringify(s.number)),"datetime"===t.type&&(s.datetime=new i.Z.Date(t.value).toISOString(),t.answer=i.Z.stringify(s.datetime)),"list"===t.type&&(s.list=t.value,t.answer=i.Z.stringify(s.list)),"text"!==t.type&&"boolean"!==t.type||(s[t.type]=t.value,t.answer=i.Z.stringify(t.value)),i.Z.setUserAttr(e,s)})),i.Z.map(s,(t=>{let e=i.Z.find(this.props.form.fields,(e=>e.name===t.name));e&&(e.answered=t.answered)})),this.setState({formData:s}),this.props.store.setUser(e);let r={attachments:[{type:"form_submit",form_submit:{state:'{"user_id":"'+this.props.store.matchUser().id+'"}',form_message_id:i.Z.get(this.props.ev,"id"),fields:s}}]},o=i.Z.convoOfEv(this.props.ev);this.props.store.sendConvoEvent(o,"message_sent",{message:r}),this.props.onSubmit&&this.props.onSubmit()}}function D(t){return btoa(t).split("=").join("")}class M extends r.up{constructor(t){super(t)}render(){if("user"===i.Z.get(this.props.ev,"by.type"))return;let t=[],e=i.Z.get(this.props.ev,"data.message.attachments")||[];i.Z.each(e,(e=>{e&&("form"!==e.type&&"ask_info_form"!==e.type||(e.form._type=e.type,t.push(e.form)))}));let s=i.Z.map(t,((t,e)=>(0,o.h)(C,{store:this.props.store,onSubmit:this.props.onSubmit,ref:t=>{this["form."+e]=t},key:e,form:t,ev:this.props.ev,t:this.props.t})));return 0===s.length?null:(0,o.h)("div",{class:"message-agent"},s)}focus(){var t=this["form.0"];t&&t.focus()}}class E extends r.up{constructor(t){super(t)}render(){return null}}function P(t){return t.touches&&t.touches.length?t.touches[0]:{}}class U extends r.up{constructor(t){super(t),this.state={focusing:0},this.galleryRef=(0,o.Vf)()}componentDidMount(){this.bindDrag()}focus(t){this.setState({focusing:t}),this.galleryRef.current.scrollTo({left:220*t,behavior:"smooth"})}render(){if("user"===i.Z.get(this.props.ev,"by.type"))return null;let t=i.Z.get(this.props.ev,"data.message.attachments",[]),e=i.Z.filter(t,(t=>"generic"===i.Z.get(t,"type")));return 0===e.length?null:i.Z.map(e,((e,s)=>{var r=i.Z.map(e.elements,(t=>{let e=this.props.t.i18n(t.i18n_title)||t.title,s=this.props.t.i18n(t.i18n_subtitle)||t.subtitle,i=e?(0,o.h)("div",{class:"generic-attachment--element-title"},e):null,r=s?(0,o.h)("div",{class:"generic-attachment--element-subtitle"},s):null;return(0,o.h)("div",{class:"generic-attachment--element swiper-slide"},(0,o.h)("div",null,(0,o.h)("img",{alt:"generic attachment element",class:"generic-attachment--element-img",src:this.props.store.replaceFileUrl(t.image_url)})),(0,o.h)("div",{class:"generic-attachment--element-content"},i,r),(0,o.h)(k,{buttons:t.buttons,onSelect:t=>this.props.onSelect(t),t:this.props.t}))}));let a=i.Z.get(t,"0.elements",[]),n="generic-attachment-navigator generic-attachment-navigator--left",h="generic-attachment-navigator generic-attachment-navigator--right";return 0===this.state.focusing&&(n+=" generic-attachment-navigator--disabled"),this.state.focusing===a.length-1&&(h+=" generic-attachment-navigator--disabled"),(0,o.h)("div",{class:"generic-attachment-container"},(0,o.h)("div",{class:"generic-attachment",ref:this.galleryRef},r),!this.props.store.isMobile()&&(0,o.h)(o.HY,null,(0,o.h)("div",{class:n,onClick:t=>this.focus(this.state.focusing-1)},(0,o.h)("span",{class:"generic-attachment-navigator-icon"},"‹")),(0,o.h)("div",{class:h,onClick:t=>this.focus(this.state.focusing+1)},(0,o.h)("span",{class:"generic-attachment-navigator-icon"},"›"))))}))}bindDrag(){if(!this.props.store.isMobile())return;let t=document.getElementsByClassName("generic-attachment");i.Z.map(t,(t=>{var e,s,i;(e=t)&&(e.removeEventListener("touchstart",e.md,0),window.removeEventListener("touchend",e.mu,0),window.removeEventListener("touchmove",e.mm,0),e.md=function(t){let r=P(t);e.hasAttribute("nochilddrag")&&document.elementFromPoint(r.pageX,r.pageY)||(i=1,s=r.clientX,t.preventDefault())},e.mu=()=>{i=0},e.mm=function(t){if(!i)return;let r=P(t);e.scrollLeft-=-s+r.clientX,s=r.clientX},e.addEventListener("touchstart",e.md,{passive:!0}),window.addEventListener("touchend",e.mu,{passive:!0}),window.addEventListener("touchmove",e.mm,{passive:!0}))}))}}class j extends r.up{render(){let t=i.Z.get(this.props.ev,"by.type");if("user"===t)return null;let e=i.Z.get(this.props.ev,"data.message.attachments",[]),r=i.Z.filter(e,(t=>"product"===i.Z.get(t,"type")||"product_preview"===i.Z.get(t,"type")));if(r=r.filter((t=>t.product&&t.product.name)),0===r.length)return null;let a=this.props.store.matchAccount();return i.Z.map(r,((e,r)=>{let n=e.product,h=[],l=n.url||n.mobile_url;this.props.store.isMobile()&&(l=n.mobile_url||n.url),l&&0==i.Z.size(n.buttons)&&h.push((0,o.h)("a",{class:"product_attachment__btn",href:l,target:"_blank"},this.props.t("detail"),(0,o.h)("img",{src:s(8453),class:"product_attachment__btn_external_link"}))),console.log("P",n),i.Z.size(n.buttons)>0&&(h=h.concat(i.Z.map(n.buttons,((t,e)=>"call_button"===t.type?(0,o.h)("a",{class:"product_attachment__btn",href:"tel:"+t.phone_number,key:e,title:t.title},this.props.t.i18n(t.i18n_title)||t.title):"url_button"===t.type?(0,o.h)("a",{class:"product_attachment__btn",href:t.url,target:"_blank",key:e,title:t.title},this.props.t.i18n(t.i18n_title)||t.title||this.props.t("detail")," ",(0,o.h)("img",{src:s(8453),class:"product_attachment__btn_external_link"})):"postback_button"===t.type?(0,o.h)("a",{class:"product_attachment__btn",href:"javascript:;",onClick:e=>this.props.onPostback(t)},this.props.t.i18n(t.i18n_title)||t.title):void 0))));let p=(0,o.h)("a",{href:l,class:"product_attachment__title",target:"_blank"},n.name),d=null,c=n.description||n.long_description;c&&(d=(0,o.h)("div",{class:"product_attachment__subtitle"},c));let u=null;return n.price&&(u=(0,o.h)("div",{class:"product_attachment__price"},n.currency||i.Z.get(a,"currency","")," ",i.Z.formatCurrency(n.price))),(0,o.h)("div",{class:"product_attachment product_attachment__"+t},(0,o.h)("div",null,(0,o.h)("a",{href:this.props.store.replaceFileUrl(n.image),target:"_blank"},(0,o.h)("img",{class:"product_attachment__img",src:this.props.store.replaceFileUrl(n.image)}))),p,d,u,(0,o.h)("div",{class:"product_attachment__btns"},h))}))}}class I extends r.up{render(){let t=i.Z.get(this.props.ev,"by.type");if("user"===t)return null;this.props.store.matchAccount();var e=i.Z.get(this.props.ev,"data.message.attachments",[]);let r=i.Z.filter(e,(t=>"order"===t.type&&t.order)).map((t=>t.order));return 0===r.length?null:i.Z.map(r,((e,r)=>{let a=null;e.note&&(a=(0,o.h)("div",null,(0,o.h)("div",{class:"order_attachment__label"},this.props.t("note")),(0,o.h)("div",{class:"order_attachment__text_truncate"},e.note)));let n=null;i.Z.size(e.items)>0&&(n=(0,o.h)("div",null,(0,o.h)("div",{class:"order_attachment__label"},this.props.t("product")),i.Z.map(e.items,(t=>{let e=t.product||{};return(0,o.h)("div",{class:"order_attachment__product"},(0,o.h)("img",{class:"order_attachment__product_img",alt:""+i.Z.get(e,"id"),src:i.Z.get(e,"images.0",s(9270))}),(0,o.h)("div",{style:"overflow: hidden !important;"},(0,o.h)("div",{class:"order_attachment__product_name"},e.name),(0,o.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,o.h)("div",{class:"order_attachment__product_desc"},this.props.t("qty")," ",t.quantity," · ",i.Z.formatCurrency(e.price))))}))));let h=(0,o.h)("div",{class:"order_attachment__footer"},(0,o.h)("div",null,this.props.t("total"))," ",(0,o.h)("div",null,(0,o.h)("b",null,i.Z.formatCurrency(e.total)))),l=i.Z.get(e,"shipping.address",{}),p=[l.street,l.ward,l.district,l.region,l.country].filter((t=>t)).join(", "),d=i.Z.find(i.Z.get(e,"user.attributes",[]),(t=>"phones"===t.key))||{key:"phones",text:""},c=i.Z.get(e,"shipping.address.phone","").trim();c=c||i.Z.trim(d.text),c&&(c=this.props.t("phn")+": "+c);let u=null;return(p||c)&&(u=(0,o.h)("div",null,(0,o.h)("div",{class:"order_attachment__label"},this.props.t("ship_to")),(0,o.h)("div",{class:"order_attachment__text_truncate"},p),(0,o.h)("div",{class:"order_attachment__text_truncate"},c))),(0,o.h)("div",{class:`order_attachment order_attachment__${t}`},(0,o.h)("div",{class:"order_attachment__header"},this.props.t("order"),(0,o.h)("span",{class:"order_attachment__text_muted order_attachment__text_sm"},"#",e.id)),n,u,(0,o.h)("div",null,(0,o.h)("div",{class:"order_attachment__label"},this.props.t("payment")),(0,o.h)("div",null,"COD")),a,h)}))}}class R extends r.up{constructor(t){super(t)}render(){let t=i.Z.get(this.props.ev,"by.type");var e=i.Z.get(this.props.ev,"data.message.attachments",[]),s=[];if(i.Z.each(e,((t,e)=>{t&&i.Z.includes(t.mimetype,"video")&&s.push(t)})),0===s.length)return null;var r=i.Z.map(s,((e,s)=>(0,o.h)("div",{class:`video-attachment video-attachment--${t}`},(0,o.h)("video",{class:"video-attachment__video",src:this.props.store.replaceFileUrl(e.url),width:"100%",height:"",poster:this.props.store.replaceFileUrl(e.thumbnail_url),controls:"controls",preload:"metadata",onclick:"this.play()"}))));return(0,o.h)("div",{class:`message-${t}`},r)}}class F extends r.up{constructor(t){super(t),this.ref=(0,o.Vf)()}componentDidMount(){this.shadowRoot=this.ref.current.attachShadow({mode:"open"}),this.update(this.props.html)}update(t){this.shadowRoot.innerHTML=`<style type="text/css">\nbody { font-family: 'Roboto', sans-serif!important; font-size: 14px!important; line-height: 20px; overflow-y: hidden; margin:0 }\nh{ font-size: 14/18px!important; }\na { text-decoration: none;}\nimg { max-width: 100%; display: block; margin: 10px auto; }\n* { white-space: normal }\nul > li { margin-bottom: 5px }\nul:last-child { margin-bottom: 0 }\np { margin-bottom: 0; margin-top: 0;}\n</style>\n<div>${t}</div>`;let e=this.shadowRoot.querySelectorAll("a");for(var s=0;s<e.length;s++)e[s].target="_blank"}render(){return(0,o.h)("div",{ref:this.ref,style:"white-space: normal !important"})}}let L=[],A=(t,e)=>(L.push(t),"");(async()=>{let t=(await s.e(441).then(s.bind(s,7441))).marked;A=(e,s)=>t(s),i.Z.map(L,(t=>t.forceUpdate())),L=[]})();class $ extends r.up{render(){var t=i.Z.get(this.props.ev,"data.message.format","plaintext");return"markdown"===t?this.renderMarkdown():"delta"===t?this.renderDelta():this.renderPlainText()}renderPlainText(){var t=i.Z.get(this.props.ev,"data.message.text");if(t=i.Z.trim(t),0===i.Z.size(t))return null;let e=i.Z.get(this.props.ev,"by.type");var s=i.Z.extractText(t).map((t=>{if("emoji"===t.type)return(0,o.h)(a,{emojiCode:t.text,byType:e});if("link"===t.type){let e=t.text||"";return e.startsWith("//")||e.startsWith("https://")||e.startsWith("http://")||e.startsWith("data:")||(e="//"+e),(0,o.h)("a",{href:e,target:"_blank",onClick:t=>this.props.onLink(t,e)},t.text)}return"phone"===t.type?(0,o.h)("a",{href:"tel:"+t.text},t.text):"email"===t.type?(0,o.h)("a",{href:"mailto:"+t.text},t.text):t.text}));return 0===i.Z.size(s)?null:"agent"===e?(0,o.h)("div",{class:"message-agent message-text--agent"},s):(0,o.h)("div",{class:"message-user message-text--user"},s)}renderDelta(){let t=i.Z.get(this.props.ev,"data.message.quill_delta");if(t=i.Z.parseJSON(t)||{},t=t.ops||[],i.Z.find(t,(t=>i.Z.get(t,"attributes.bold")||i.Z.get(t,"attributes.italic")||i.Z.get(t,"attributes.underline")||i.Z.get(t,"insert.emoji")))){var e=function(t){let e="";return i.Z.each(t,((t,s)=>{let r="",o=t.insert,a=t.attributes;o.emoji&&(r=z[o.emoji]||""),a&&(r=a.italic&&a.bold?`*__${o}__*`:a.italic?`*${o}*`:a.bold?`**${o}**`:o),o.dynamicField&&(r=`${i.Z.get(o,"dynamicField.text","")}`),o.emoji||a||o.dynamicField||(r=o||"",r=r.replace(/\n/g,"<br/>")),e+=r})),e}(t);return this.renderMarkdown(e)}return this.renderPlainText()}renderMarkdown(t){if(t||(t=i.Z.get(this.props.ev,"data.message.text")),0===i.Z.size(t))return null;let e=i.Z.get(this.props.ev,"by.type");return t=i.Z.trim(t),0===i.Z.size(t)?null:"agent"===e?(0,o.h)("div",{class:"markdown-message message-agent message-text--agent"},(0,o.h)(F,{html:A(this,t)})):(0,o.h)("div",{class:"d-flex flex-column align-items-end"},(0,o.h)("div",{class:"markdown-message message-user message-text--user"},(0,o.h)(F,{html:A(this,t)})))}}const z={like:"👍",unlike:"👎",angry:"😠",confused:"😕",crying:"😢",grinning:"😀","heart-eyes":"😍",neutral:"😐",sleepy:"😪",sad:"😞",smiling:"😄","tongue-out":"😛",tired:"😩",surprised:"😮",wink:"😉"};var O=new i.Z.Pubsub;setInterval((()=>O.publish("time")),2e4);class T extends r.up{constructor(t){super(t),this.setState({t:"",langCode:"en_US"})}updateTime(){var t="";if(this.props.ago){if(this.props.short&&Math.abs(this.props.time-(new i.Z.Date).getTime())>864e6){let e=new i.Z.Date(this.props.time),s=e.getFullYear(),r=i.Z.get(navigator,"languages.0","en-US"),o=e.toLocaleDateString(r,{month:"short"});t=e.getDate()+" "+o+" "+s}!t&&this.props.time>0&&(t=function(t,e){const s={s:"%d s",m:"1m",mm:"%dm",h:"1h",hh:"%dh",d:"1d",dd:"%dd",M:"1M",MM:"%M",y:"1y",yy:"%dy"},i=[{l:"s",r:44,d:1e3},{l:"m",r:89},{l:"mm",r:44,d:6e4},{l:"h",r:89},{l:"hh",r:21,d:36e5},{l:"d",r:35},{l:"dd",r:25,d:864e5},{l:"M",r:45},{l:"MM",r:10,d:2592e6},{l:"y",r:17},{l:"yy",d:31536e6}],r=i.length;let o,a;for(let n=0;n<r;n+=1){let r=i[n];r.d&&(o=(t-e)/r.d);let h=Math.round(Math.abs(o));if(h<=r.r||!r.r){h<=1&&n>0&&(r=i[n-1]),a=s[r.l].replace("%d",h);break}}return a}(this.props.time,(new i.Z.Date).getTime()))}else t=i.Z.shortTime(this.props.time,this.props.tzoffset);this.props.uppercase&&(t=t.toUpperCase()),t!==this.state.t&&this.setState({t})}componentDidMount(){O.on2(this,"time",(()=>this.updateTime())),this.updateTime()}render(){return(0,o.h)("span",{style:this.props.style},this.state.t)}}class B extends r.up{render(){let t=this.props.ev.ev;var e=null;if(this.props.ev.show_time&&(e=(0,o.h)("div",{class:"convo-event-time"},(0,o.h)(T,{time:t.created}))),"conversation_rated"===t.type){var s=i.Z.get(t,"data.conversation.ratings.0",{no_rating:!0,rating:0});return s.no_rating?null:(0,o.h)("div",{class:"convo-event"},e,(0,o.h)("div",{class:"info-message"},this.props.t("rated_as")+" "+this.props.t(function(t){return t?t<2?"poor":t<4?"average":"great":"poor"}(s.rating)).toLowerCase()))}return"conversation_state_updated"===t.type&&"ended"===i.Z.get(t,"data.conversation.state")?(0,o.h)("div",{class:"convo-event"},e,(0,o.h)("div",{class:"info-message"},this.props.t("conversation_ended"))):null}}class q extends r.up{constructor(t){super(t),this.refForm=(0,o.Vf)()}render(){var t=i.Z.get(this.props.event,"ev",{});switch(t.type){case"conversation_joined":break;case"message_sent":return this.renderMessageSent();case"conversation_state_updated":case"conversation_rating_requested":case"conversation_rated":return i.Z.startsWith(t.id,"ev")?(0,o.h)(B,{t:this.props.t,store:this.props.store,ev:this.props.event}):null}return null}focus(){this.refForm.current&&this.refForm.current.focus()}chooseQuickReply(t){let e=i.Z.get(this.props.event,"ev",{}),s={text:t.title,format:"plaintext"};t.payload&&(s.attachments=[{type:"postback",postback:{event_id:e.id,payload:t.payload}}]),this.props.onSend(s)}choosePostbackBtn(t){let e=i.Z.get(this.props.event,"ev",{}),s={text:t.title,format:"plaintext"};t.payload&&(s.attachments=[{type:"postback",postback:{event_id:e.id,payload:t.payload}}]),this.props.onSend(s)}renderAgentAvatar(t){let e=i.Z.get(t,"by.type"),r=i.Z.get(t,"by.display_id",i.Z.get(t,"by.id"));if("user"===e)return null;var a=this.getSenderName(t);let n=this.props.store.matchAccount();var h=n.logo_url||s(9895);let l=this.props.store.matchAgent("*");return"system"===r&&"dummy"===e||(h=i.Z.get(l[r],"avatar_url")||n.logo_url||s(4761)),(0,o.h)("div",{class:"message-sender"},(0,o.h)("img",{alt:"sender",class:"message-sender-avatar",src:this.props.store.replaceFileUrl(h)}),(0,o.h)("p",{class:"message-sender-name"},a))}renderMessageSent(){let t=this.props.event.ev;var e=null;this.props.event.show_time&&(e=(0,o.h)("div",{class:"convo-event-time"},(0,o.h)(T,{time:t.created})));let s=new i.Z.Date(t.created).toLocaleString();if("user"!==i.Z.get(t,"by.type")){let i=null;return"lead"===this.props.event.mode&&(i=this.renderAgentAvatar(t)),(0,o.h)("div",{class:"convo-event agent-message",title:s},e,i,(0,o.h)($,{store:this.props.store,ev:t,onLink:this.props.onLink}),(0,o.h)(y,{store:this.props.store,ev:t}),(0,o.h)(b,{store:this.props.store,ev:t}),(0,o.h)(R,{store:this.props.store,ev:t}),(0,o.h)(w,{store:this.props.store,ev:t}),(0,o.h)(Z,{store:this.props.store,ev:t,t:this.props.t}),(0,o.h)(M,{store:this.props.store,onSubmit:this.props.onFormSubmit,ref:this.refForm,ev:t,t:this.props.t}),(0,o.h)(E,{store:this.props.store,ev:t,t:this.props.t}),(0,o.h)(U,{store:this.props.store,ev:t,onSelect:t=>this.choosePostbackBtn(t),t:this.props.t}),(0,o.h)(j,{t:this.props.t,onPostback:t=>this.choosePostbackBtn(t),store:this.props.store,ev:t}),(0,o.h)(I,{t:this.props.t,store:this.props.store,ev:t}),(0,o.h)(x,{store:this.props.store,ev:t,onSelect:t=>this.chooseQuickReply(t)}))}i.Z.getMsgField(t,"idempotency")===t.id&&this.props.store.now()-t.created<900&&setTimeout((()=>this.setState({refresh:this.state.refresh})),1e3);let r=(0,o.h)("div",{class:"sending_dot"});(this.props.store.now()-t.created<900||i.Z.getMsgField(t,"idempotency")!==t.id)&&(r=(0,o.h)("div",{class:"sending_dot sending_dot__hide"}));let a=null;"lead"===this.props.event.mode&&(a=(0,o.h)("div",{class:"pt-3"}));let n=null;return t._error&&"message_sent"===t.type&&(n=(0,o.h)("a",{class:"message_error",src:"javascript:;",onClick:t=>this.resendMessage()},(0,o.h)("div",{class:"message_error__text"},this.props.t("error_send_message")),(0,o.h)("div",{class:"message_error__icon"}))),(0,o.h)("div",{class:"convo-event user-message",title:s},e,a,(0,o.h)("div",{class:"message-user__container"},r,(0,o.h)($,{store:this.props.store,ev:t,refresh:this.state.refresh,onLink:this.props.onLink}),(0,o.h)(y,{store:this.props.store,ev:t}),(0,o.h)(b,{store:this.props.store,ev:t}),(0,o.h)(R,{store:this.props.store,ev:t}),(0,o.h)(w,{store:this.props.store,ev:t}),(0,o.h)(Z,{store:this.props.store,ev:t,t:this.props.t}),(0,o.h)(M,{store:this.props.store,onSubmit:this.props.onFormSubmit,ref:this.refForm,ev:t}),(0,o.h)(j,{t:this.props.t,store:this.props.store,ev:t}),(0,o.h)(E,{store:this.props.store,ev:t})),n)}renderUpdateConvo(t){var e=i.Z.get(t,"data.conversation.state");return"active"===e||"pending"===e?null:(0,o.h)("div",{class:"message-system"},this.props.t("conversation_state_updated",{state:e}))}resendMessage(){let t=i.Z.convoOfEv(this.props.event.ev);const e=i.Z.get(this.props.event,"ev.data.message");this.props.store.sendConvoEvent(t,"message_sent",{message:e})}getSenderName(t){let e=i.Z.get(t,"by.type"),s=i.Z.get(t,"by.display_id",i.Z.get(t,"by.id"));if("system"===s||"dummy"===e)return"system";let r=this.props.store.matchUser(),o=this.props.store.matchAccount();return"user"===e?i.Z.getUserDisplayName(r):"agent"===e?i.Z.getAgentDisplayName(o,this.props.store.matchAgent(s)):""}}const V=s(6484);class W extends r.up{render(){let t=(this.props.mode+"").toLowerCase(),e="dark"===t?"#000000dd":"blue"===t?"rgba(52, 152, 220, .8)":"#ffffffdd",s="dark"===t?"#00000055":"blue"===t?"rgba(52, 152, 220, .15)":"#ffffff55",i=this.props.size||14,r=`width: ${i}px !important;height: ${i}px!important;color: ${s} !important;border-width: ${Math.ceil(i/14)}px !important;\n border-left-color: ${s} !important;border-top-color: ${s} !important;\n border-bottom-color: ${s} !important;border-right-color: ${e} !important;`;if(this.props.static){let t=`width: ${i}px !important;height: ${i}px !important;`;return i<40?(0,o.h)(LoaderIcon,{size:i+"",style:`stroke:${e}`}):this.props.center?(0,o.h)("div",{class:"loading"},(0,o.h)("img",{alt:"loading",style:t,src:V})):(0,o.h)("img",{alt:"loading",style:t,src:V})}return(0,o.h)("div",{class:"spinner1",style:r})}}const H=s(6188);class Y extends r.up{constructor(t){super(t),this.props.store.onUpdate(this,(t=>this.forceUpdate())),this.props.store.onConvoEvent(this,(t=>this.onEvent(t))),this.loadConvo(),this.refBody=null,this.checkAndSeen=i.Z.throttle((()=>{this.props.isShow&&this.isBottom()&&"visible"===this.props.store.browserVisibility&&document.hasFocus()&&this.props.store.seenConvo(this.props.cid)}),500),this.checkAndSeen()}componentDidUpdate(t){t.cid!==this.props.cid&&this.loadConvo()}render(){if(this.state.error)return this.renderError();let t=i.Z.map(this.props.store.listEvents(this.props.cid));if(!this.state.loading&&0===i.Z.size(t))return(0,o.h)("div",{ref:t=>this.refBody=t,class:"widget-body--events-container"},(0,o.h)("div",{class:"widget-body--empty"},(0,o.h)("div",{class:"widget-body--empty-icon"}),(0,o.h)("div",{class:"widget-body--empty-text"},this.props.t("empty_convo_text"))),(0,o.h)(m,{store:this.props.store}));t=i.Z.orderBy(t,"created","asc"),this.props.store.matchConvo(this.props.cid),t=i.Z.map(t,(t=>({ev:t}))),function(t,e){if(!((e=e.filter((t=>G(t.ev)))).length<1)){for(var s=1;s<e.length;s++){let t=e[s],r=e[s-1];G(t.ev)&&i.Z.unixSec(t.ev.created)-i.Z.unixSec(r.ev.created)>120&&(t.show_time=!0)}for(s=0;s<e.length;s++){let t=e[s];if("message_sent"===i.Z.get(t,"ev.type")){t.show_time=!0;break}}for(s=0;s<e.length;s++){let t=e[s],r=e[s-1];"message_sent"!==t.ev.type||(t.mode="lead","message_sent"===i.Z.get(r,"ev.type")&&i.Z.get(r,"ev.by.id")===i.Z.get(t,"ev.by.id")&&(t.mode="follow"))}}}(0,t);let e=i.Z.map(t,(t=>(0,o.h)(q,{onLink:this.props.onLink,store:this.props.store,onFormSubmit:this.props.onFormSubmit,onSend:this.props.onSend,onPostback:this.props.onPostback,event:t,t:this.props.t,key:t.ev.id}))),s=null,r="opacity: 1 !important";return(this.state.loading||this.props.creating)&&(s=(0,o.h)(W,{static:!0,mode:"blue",size:"120",center:!0}),r="opacity: 0 !important"),(0,o.h)(o.HY,null,s,(0,o.h)("div",{style:r,ref:t=>this.refBody=t,class:"widget-body--events-container",onMouseOver:this.checkAndSeen},(0,o.h)("div",{class:"widget-body--events"},e),(0,o.h)(m,{store:this.props.store})))}renderError(){let t=(0,o.h)("a",{href:"#",onclick:t=>this.loadConvo()},this.props.t("try_again"));return this.state.loading&&(t=(0,o.h)(W,{size:"16",mode:"blue"})),(0,o.h)("div",{class:"widget-body--events-container widget-body--events-container__error"},(0,o.h)("img",{alt:"empty",src:H}),(0,o.h)("div",{class:"widget_body__events__error_msg"},this.props.t("load_convo_error")),(0,o.h)("div",{class:"widget_body__events__error_retry"},t))}focus(){let t=this.props.store.listEvents(this.props.cid);var e;t=i.Z.orderBy(i.Z.map(t),"created","desc");for(let s of t)if("message_sent"===i.Z.get(s,"type")&&"user"!==i.Z.get(s,"by.type")){e=s;break}"user"===i.Z.get(e,"by.type")&&(e=null);let s=i.Z.get(e,"data.message.attachments",[]),r=this.props.store.matchConvo(this.props.cid);i.Z.filter(s,(t=>{if(!t)return!1;if("form"!==t.type&&"ask_info_form"!==t.type)return!1;var e=t.form;return!(!e||!(i.Z.parseJSON(e.state)||{}).require_finished&&"ask_info_form"!==t.type||function(t){let e=i.Z.get(t,"fields")||[];return i.Z.find(e,(t=>!!t.answered))}(t.form)||"ended"===r.state)}))}onEvent(t){if(i.Z.convoOfEv(t)!==this.props.cid)return;let e=this.isBottom();var s=!1;"message_sent"===i.Z.get(t,"type")&&t.id===i.Z.getMsgField(t,"idempotency")&&(s=!0),(s||e)&&this.scrollToBottom()}async loadConvo(){if(!this.props.cid)return;this.lastContentOffsetY=0,this.setState({loading:!0});let t=this.props.store.listEvents(this.props.cid);if(0===i.Z.size(t)){let t=this.props.cid,{error:e}=await this.props.store.fetchMoreEvents(t);if(this.setState({loading:!1}),t!==this.props.cid)return;if(e)return void this.setState({error:!0})}this.setState({loading:!0}),this.props.store.fetchMoreEvents(this.props.cid),this.setState({error:!1}),this.scrollToBottom(),setTimeout((()=>this.setState({loading:!1})),50)}isBottom(){let t=this.refBody;return!!t&&t.scrollHeight<t.scrollTop+t.offsetHeight+50}scrollToBottom(){setTimeout((()=>{const t=this.refBody;t&&(t.scrollTop=t.scrollHeight)})),setTimeout((()=>{const t=this.refBody;t&&(t.scrollTop=t.scrollHeight)}),200),this.props.isShow&&"visible"===this.props.store.browserVisibility&&document.hasFocus()&&this.props.store.seenConvo(this.props.cid)}}function G(t){let e=i.Z.get(t,"type");return"message_sent"===e||"conversation_state_updated"===e}class N extends r.up{constructor(t){super(t)}componentDidMount(){this.setState({isShow:!1,ev:{}}),this.props.store.onConvoEvent(this,(t=>{if(i.Z.convoOfEv(t)!==this.props.cid)return;let e=this.props.store.matchUser();if(i.Z.get(t,"by.id")===e.id)return;let s=i.Z.get(this.state.ev,"by.id");return s&&i.Z.get(t,"by.id")!==s?void 0:"message_sent"===i.Z.get(t,"type")?(this.timer&&clearTimeout(this.timer),this.timer=null,void this.setState({isShow:!1})):void("agent"!=(this.props.store.matchAgent(t.by.id)||{}).type&&"conversation_typing"===i.Z.get(t,"type")&&(this.setState({ev:t,isShow:!0}),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{i.Z.convoOfEv(t)===this.props.cid&&(this.timer=null,this.setState({isShow:!1}))}),5e3)))}))}render(){let t=this.props.store.matchAccount();var e=this.state.isShow?"":"typing--hidden";let s=i.Z.get(this.state.ev,"by.display_id",i.Z.get(this.state.ev,"by.id")),r=i.Z.getAgentDisplayName(t,this.props.store.matchAgent(s));return(0,o.h)("div",{class:`typing ${e}`},r," ",this.props.t("typing"))}}const J=class{constructor(t){this.duration=t.duration||100,this.breakingV=t.breakingV||7,this.maxY=t.maxY||500,this.minY=t.minY||0}play(t,e,s){var r;this.stop();var o=a=>{a||(a=(new i.Z.Date).getTime());var n=a-r,[h,l]=this.calcY(t,e,n);if(s(h),l)return this.stop();this.animationframe=window.requestAnimationFrame(o)};this.animationframe=window.requestAnimationFrame((t=>{r=t||(new i.Z.Date).getTime(),o(r)}))}calcY(t,e,s){var i,r=function(t,e,s,i){if(K(t,e))return t;var r=t+(e-t)/i*s;return(t<e&&r>e||e<t&&r<e)&&(r=e),r}(e,i=e>this.maxY?this.maxY:e<this.minY?this.minY:Math.abs(t)<this.breakingV?Math.abs(this.maxY-e)<Math.abs(this.minY-e)?this.maxY:this.minY:t<0?this.maxY:this.minY,s,this.duration);return[r,K(r,i)]}stop(){window.cancelAnimationFrame(this.animationframe)}};function K(t,e){return Math.abs(t-e)<=.001}class Q extends r.up{constructor(t){var e,s;super(t),s={hide:!0,ratingHeight:0,overlayOpacity:.3,comment:""},(e="state")in this?Object.defineProperty(this,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):this[e]=s,this.refComment=(0,o.Vf)(),this.refRating=(0,o.Vf)(),this.refHandle=(0,o.Vf)()}componentDidMount(){this.props.store.onUpdate(this,(()=>{this.shoudDisplay()&&this.open()})),this.props.store.onConvoEvent(this,(t=>{i.Z.convoOfEv(t)===this.props.cid&&this.shoudDisplay()&&this.open()})),this.mouseUp=t=>this.onMouseUp(t),this.mouseMove=t=>this.onMouseMove(t),this.mouseDown=t=>this.onMouseDown(t);var t=this.refHandle.current;t.addEventListener("mousedown",this.mouseDown,{passive:!0}),t.addEventListener("touchstart",this.mouseDown,{passive:!0}),window.addEventListener("mouseup",this.mouseUp,{passive:!0}),window.addEventListener("touchend",this.mouseUp,{passive:!0}),window.addEventListener("mousemove",this.mouseMove,{passive:!0}),window.addEventListener("touchmove",this.mouseMove,{passive:!0}),this.animation=new J({maxY:400,minY:0,duration:150}),this.close(),(this.shoudDisplay()||"rating"===this.props.forceView)&&this.open()}componentWillUnmount(){var t=this.refHandle.current;t.removeEventListener("mousedown",this.mouseDown,0),t.removeEventListener("touchstart",this.mouseDown,0),window.removeEventListener("mouseup",this.mouseUp,0),window.removeEventListener("touchend",this.mouseUp,0),window.removeEventListener("mousemove",this.mouseMove,0),window.removeEventListener("touchmove",this.mouseMove,0)}render(){let t=this.state.hide?"d-none":"";return(0,o.h)("div",{class:t},(0,o.h)("div",{class:"rating--overlay",style:`opacity: ${.5*this.state.overlayOpacity} !important;`}),(0,o.h)("div",{class:"rating",ref:this.refRating,style:`color:red; height: ${this.state.ratingHeight}px !important;`},(0,o.h)("div",{class:"rating--handle",ref:this.refHandle},(0,o.h)("div",{class:"rating--thumb"})),(0,o.h)("div",{class:"rating--content"},(0,o.h)("div",{class:"rating--heading"},this.props.t("rating_title"),(0,o.h)("div",{class:"rating--close-btn",onClick:t=>this.onCloseRating(t)})),(0,o.h)("div",{class:"rating--description"},this.props.t("rating_description")),(0,o.h)("textarea",{ref:this.refComment,type:"text",class:"rating--comment"}),(0,o.h)("div",{class:"rating-faces-container"},(0,o.h)("div",{class:"rating-face-container",onClick:t=>this.onRatingPoor(t)},(0,o.h)("img",{alt:"poor",src:s(8367)}),(0,o.h)("p",{class:"rating-face--text"},this.props.t("poor"))),(0,o.h)("div",{class:"rating-face-container",onClick:t=>this.onRatingAverage(t)},(0,o.h)("img",{alt:"average",src:s(6535)}),(0,o.h)("p",{class:"rating-face--text"},this.props.t("average"))),(0,o.h)("div",{class:"rating-face-container",onClick:t=>this.onRatingGreat(t)},(0,o.h)("img",{alt:"great",src:s(3824)}),(0,o.h)("p",{class:"rating-face--text"},this.props.t("great")))),(0,o.h)("div",{class:"rating-no-thanks",onClick:t=>this.onCloseRating(t)},this.props.t("no_thanks")))))}shoudDisplay(){if(!this.props.cid)return!1;var t,e,s;let r=this.props.store.matchUser();if(i.Z.map(this.props.store.listEvents(this.props.cid),(o=>{"conversation_state_updated"===i.Z.get(o,"type")&&"ended"===i.Z.get(o,"data.conversation.state")&&(s=o),"conversation_rating_requested"===i.Z.get(o,"type")&&(t=o),"conversation_rated"===i.Z.get(o,"type")&&i.Z.get(o,"by.id")===r.id&&(e=o)})),e)return!1;var o=this.props.plugin.chatbox.auto_request_rating&&s;return t||o}onCloseRating(){this.props.onRate&&this.props.onRate({no_rating:!0,comment:this.refComment.current.value}),this.close()}onRatingPoor(){this.props.onRate&&this.props.onRate({rating:1,comment:this.refComment.current.value}),this.close()}onRatingAverage(){this.props.onRate&&this.props.onRate({rating:3,comment:this.refComment.current.value}),this.close()}onRatingGreat(){this.props.onRate&&this.props.onRate({rating:5,comment:this.refComment.current.value}),this.close()}open(){if(this.state.hide&&(this.setState({hide:!1}),this.refRating.current)){setTimeout((()=>{this.refComment.current&&this.refComment.current.focus()}),400),this.refComment.current.value="";var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(-20,e,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)})}))}}close(){if(!this.state.hide&&this.refRating.current){var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(20,e,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||this.setState({hide:!0}))}))}}onMouseDown(t){this.mousePushed=!0,this.animation.stop(),t.preventDefault(),t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushedDy=t.pageY-window.pageYOffset-this.refRating.current.getBoundingClientRect().y}onMouseUp(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushed=!1;var e=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),s=parseFloat(e.height);this.animation.play(this.mouseVelocity,s,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||(this.setState({hide:!0}),this.props.onRate&&this.props.onRate({no_rating:!0})))}))}}onMouseMove(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]);var e=t.pageY;this.mouseVelocity=e-this.lastMouseY,this.lastMouseY=e,e-=this.mousePushedDy;var s=this.refRating.current.getBoundingClientRect().bottom-e;s>400&&(s=500-1e4/(s+-300)),this.setState({ratingHeight:s,overlayOpacity:Math.min(1,(s-0)/500)})}}}function X(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class tt extends r.up{constructor(t){super(t),X(this,"state",{show:!1,searchValue:""}),X(this,"filterRef",(0,o.Vf)()),X(this,"overlayRef",(0,o.Vf)()),X(this,"onTouchMove",(t=>{t.target===this.overlayRef.current&&(t.preventDefault(),t.stopPropagation())})),X(this,"hideDropdown",(()=>{this.setState({show:!1,searchValue:""})})),X(this,"onKeydown",(t=>{if("Escape"===t.key){if(!this.state.show)return;this.state.searchValue?this.setState({searchValue:""}):this.hideDropdown(),t.preventDefault(),t.stopPropagation()}})),X(this,"hasSearch",(()=>!!this.props.has_search||i.Z.size(this.props.items)>=10)),X(this,"getFilteredOptions",(()=>{let t=this.props.items;return this.state.searchValue&&this.hasSearch()&&(t=i.Z.filter(t,(t=>{let e=i.Z.unicodeToAscii(t.name).toLowerCase().replace(/ /g,""),s=i.Z.unicodeToAscii(t.desc).toLowerCase().replace(/ /g,""),r=i.Z.unicodeToAscii(this.state.searchValue).toLowerCase().replace(/ /g,"");return-1!=e.indexOf(r)||-1!=s.indexOf(r)}))),t})),X(this,"onChangeSearchValue",(t=>{this.setState({searchValue:t.target.value})})),X(this,"toogleDropdown",(async()=>{await this.setState({show:!0,searchValue:""}),this.focusFilter()})),X(this,"onSelect",(t=>{this.props.onSelect(t),this.hideDropdown()})),X(this,"onBackgroundScroll",(t=>{console.log("EEEEEEE",t),alert("y")})),document.addEventListener("touchmove",(function(t){}))}componentDidMount(){window.addEventListener("keydown",this.onKeydown)}componentWillUnmount(){window.removeEventListener("keydown",this.onKeydown)}renderEmpty(){return(0,o.h)("div",{class:"dropdown_select_filter__empty"},(0,o.h)("img",{class:"dropdown_select_filter__empty_img",src:s(6071)}),(0,o.h)("div",{class:"muted",style:"text-align: center !important;"},"Không có kết quả"))}renderLoading(){return(0,o.h)("div",{class:"dropdown_select_filter__empty pt-3"},(0,o.h)(W,{size:"40",static:!0}),(0,o.h)("div",{class:"muted mt-2",style:"text-align: center !important;"},"Đang tải dữ liệu"))}focusFilter(){this.filterRef.current&&(this.filterRef.current.focus(),setTimeout((()=>{this.filterRef.current&&this.filterRef.current.focus()}),100))}renderDropdown(){if(!this.state.show)return null;let t=this.getFilteredOptions(),e=i.Z.map(t,(t=>(0,o.h)("div",{class:"dropdown_select__item",onClick:e=>this.onSelect(t)},t.name))),r=null;if(this.hasSearch()){let t=(0,o.h)("img",{class:"dropdown_select_filter__icon",src:s(636)});this.props.loading&&(t=(0,o.h)("img",{class:"dropdown_select_filter__icon",src:s(5770)})),r=(0,o.h)("div",{class:"dropdown_select_filter"},t,(0,o.h)("input",{ref:this.filterRef,value:this.state.searchValue,onInput:this.onChangeSearchValue,type:"text",class:"dropdown_select_filter_input "}))}0==e.length&&(e=this.renderEmpty()),this.props.loading&&(e=this.renderLoading());let a=`width: ${this.props.width||"150px"} !important;`;return this.props.full?(a=" top: 20px !important; left: 20px !important; right: 20px !important; width: unset !important; ",(0,o.h)("div",{class:"dropdown_select__overlay",ref:this.overlayRef,onClick:this.hideDropdown,onTouchMove:this.onTouchMove},(0,o.h)("div",{class:"dropdown_select",style:a,onClick:t=>{t.preventDefault(),t.stopPropagation()}},r,(0,o.h)("div",{class:"dropdown_select__items"},e)))):(0,o.h)("div",{class:"dropdown_select",style:a},r,(0,o.h)("div",{class:"dropdown_select__items"},e))}render(){let t=(0,o.h)("div",{class:"muted text-truncate",style:"flex: 1 !important;"},"Chọn một phần tử");i.Z.get(this.props,"selected.name")&&(t=(0,o.h)("div",{class:"text-truncate",style:"flex: 1 !important;"},i.Z.get(this.props,"selected.name")));let e="position: relative !important;";return this.props.full&&(e=""),(0,o.h)("div",{style:e},(0,o.h)(r.u$,{onClickaway:this.hideDropdown},(0,o.h)("div",{type:"text",class:"dropdown_select_input "+this.props.extra_cls,onClick:this.toogleDropdown},t," ",(0,o.h)("img",{class:"dropdown_select__caret",src:s(8712)})),this.renderDropdown()))}}function et(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class st extends r.up{constructor(t){super(t),et(this,"state",{show:!1,searchValue:"",addresses:[]}),et(this,"filterRef",(0,o.Vf)()),et(this,"overlayRef",(0,o.Vf)()),et(this,"onTouchMove",(t=>{t.target===this.overlayRef.current&&(t.preventDefault(),t.stopPropagation())})),et(this,"hideDropdown",(()=>{this.setState({show:!1,searchValue:""})})),et(this,"onKeydown",(t=>{if("Escape"===t.key){if(!this.state.show)return;this.state.searchValue?this.setState({searchValue:""}):this.hideDropdown(),t.preventDefault(),t.stopPropagation()}t.key})),et(this,"doSearch",i.Z.throttle((async()=>{let t=Date.now();this.requestId=t;let e=await this.props.store.suggest_addresses(this.state.searchValue);this.requestId===t&&this.setState({addresses:i.Z.get(e,"body.addresses",[])})}),100)),et(this,"onChangeSearchValue",(t=>{this.setState({searchValue:t.target.value}),this.props.onChangeAddress(t.target.value),this.doSearch()})),et(this,"toogleDropdown",(async()=>{await this.setState({show:!0,searchValue:this.props.initAddress||""}),this.focusFilter()})),et(this,"onSelect",(t=>{this.props.onSelect(t),this.hideDropdown()})),et(this,"onBackgroundScroll",(t=>{console.log("EEEEEEE",t)})),document.addEventListener("touchmove",(function(t){}))}componentDidMount(){window.addEventListener("keydown",this.onKeydown)}componentWillUnmount(){window.removeEventListener("keydown",this.onKeydown)}renderEmpty(){return(0,o.h)("div",{class:"dropdown_select_filter__empty"},(0,o.h)("img",{class:"dropdown_select_filter__empty_img",src:s(6071)}),(0,o.h)("div",{class:"muted",style:"text-align: center !important;"},"Không có kết quả"))}renderLoading(){return(0,o.h)("div",{class:"dropdown_select_filter__empty pt-3"},(0,o.h)(W,{size:"40",static:!0}),(0,o.h)("div",{class:"muted mt-2",style:"text-align: center !important;"},"Đang tải dữ liệu"))}focusFilter(){this.filterRef.current&&(this.filterRef.current.focus(),setTimeout((()=>{this.filterRef.current&&this.filterRef.current.focus()}),100))}renderDropdown(){if(!this.state.show)return null;let t=i.Z.map(this.state.addresses,((t,e)=>{let s=[((t.address||"")+" "+it(t.street)).trim()].join(", "),i=[it(t.ward),it(t.district),it(t.province)].join(", ");return(0,o.h)("div",{class:"dropdown_select__item",onClick:e=>this.onSelect(t),key:e},(0,o.h)("div",null,(0,o.h)("b",null,s)),(0,o.h)("div",{style:"opacity: 0.7 !important;"},i))})),e=null,r=(0,o.h)("img",{class:"dropdown_select_filter__icon",src:s(636)});this.props.loading&&(r=(0,o.h)("img",{class:"dropdown_select_filter__icon",src:s(5770)})),e=(0,o.h)("div",{class:"dropdown_select_filter"},r,(0,o.h)("input",{ref:this.filterRef,value:this.state.searchValue,onInput:this.onChangeSearchValue,type:"text",class:"dropdown_select_filter_input "})),0==t.length&&(t=this.renderEmpty()),this.props.loading&&(t=this.renderLoading());let a=`width: ${this.props.width||"150px"} !important;`;return this.props.full?(a=" top: 20px !important; left: 20px !important; right: 20px !important; width: unset !important; ",(0,o.h)("div",{class:"dropdown_select__overlay",ref:this.overlayRef,onClick:this.hideDropdown,onTouchMove:this.onTouchMove},(0,o.h)("div",{class:"dropdown_select",style:a,onClick:t=>{t.preventDefault(),t.stopPropagation()}},e,(0,o.h)("div",{class:"dropdown_select__items"},t)))):(0,o.h)("div",{class:"dropdown_select",style:a},e,(0,o.h)("div",{class:"dropdown_select__items"},t))}render(){let t=(0,o.h)("div",{class:"text-truncate",style:"flex: 1 !important;"},this.props.initAddress),e="position: relative !important;";return this.props.full&&(e=""),(0,o.h)("div",{style:e},(0,o.h)(r.u$,{onClickaway:this.hideDropdown},(0,o.h)("div",{type:"text",class:"dropdown_select_input "+this.props.extra_cls,onClick:this.toogleDropdown},t),this.renderDropdown()))}}function it(t){let e=(t+"").toLowerCase();return e.startsWith("tp ")?t.substr(3):e.startsWith("thanh pho ")?t.substr("thanh pho ".length):e.startsWith("thành phố ")?t.substr("thành phố ".length):e.startsWith("tỉnh ")?t.substr("tỉnh ".length):e.startsWith("huyện ")?t.substr("huyện ".length):e.startsWith("tỉnh ")?t.substr("tỉnh ".length):e.startsWith("xã ")?t.substr("xã ".length):e.startsWith("thị trấn ")?t.substr("thị trấn ".length):e.startsWith("thị xã ")?t.substr("thị xã ".length):e.startsWith("đường ")&&(t[7]<"0"||t[7]>"9")?t.substr("đường ".length):e.startsWith("phường ")&&(t[7]<"0"||t[7]>"9")?t.substr("phường ".length):e.startsWith("quận ")&&(t[7]<"0"||t[7]>"9")?t.substr("quận ".length):t}s.e(178).then(s.bind(s,178));var rt=document.createElement("link");rt.href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap",rt.rel="stylesheet",document.head.append(rt),i.Z.preloadWebfonts(["Roboto"],[400,500]),s(4761);class ot extends r.up{render(){return"package"==this.props.name?this.props.active?(0,o.h)("img",{style:"width: 18px !important;",src:s(25)}):(0,o.h)("img",{style:"width: 18px !important;",src:s(1216)}):"shop"===this.props.name?this.props.active?(0,o.h)("img",{style:"width: 18px !important;",src:s(6180)}):(0,o.h)("img",{style:"width: 18px !important;",src:s(750)}):void 0}}function at(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}var nt=s(763),ht=s(2514);class lt extends r.up{constructor(t){super(t),at(this,"state",{loadProvince:!0,g_err:"",fullname:"",email:"",phone:"",loading:!0,order:{},err:{},shipping_address:"new",selectedProvince:null,selectedDistrict:null,selectedWard:null,street:"",address:"",sending:!1,step:""}),at(this,"renderMobileSuccess",(t=>(0,o.h)("div",{class:"order",style:"height: 100% !important"},(0,o.h)("div",{style:"display: flex !important; align-items: center !important; padding-top: 40px !important; padding-bottom: 20px !important; flex-direction: column !important; height: 100% !important"},(0,o.h)("img",{style:"width: 60px !important; height: 60px !important;",width:"60",height:"60",src:nt}),(0,o.h)("div",{style:"margin-top: 20px !important; margin-bottom: 10px !important"},(0,o.h)("b",{style:"font-size: 18px !important;"},"Đơn hàng của bạn đã được ghi nhận")),(0,o.h)("div",{class:"muted"},"Tôi sẽ liên hệ lại với bạn khi đơn hàng được xử lý"),(0,o.h)("div",{style:"flex:1 !important"}),(0,o.h)("div",{style:"margin-top: 20px !important; padding: 0px 20px 0 20px !important; width: 100% !important"},(0,o.h)("div",{class:"order_btn order__btn__light",onClick:this.close},this.props.t("close"))))))),at(this,"onSelectProvince",(async t=>{this.setState({selectedProvince:t,err:{},g_err:""}),this.setState({loadDistrict:!0});let e=await this.props.store.list_districts({id:t.id});this.setState({loadDistrict:!1}),e.error||this.setState({districts:i.Z.get(e,"body.addresses")})})),at(this,"onSelectDistrict",(async t=>{this.setState({selectedDistrict:t,err:{},g_err:""}),this.setState({loadWard:!0});let e=await this.props.store.list_wards({id:t.id});this.setState({loadWard:!1}),e.error||this.setState({wards:i.Z.get(e,"body.addresses")})})),at(this,"onSelectWard",(t=>this.setState({selectedWard:t,err:{},g_err:""}))),at(this,"onChangeFullname",(t=>this.setState({fullname:t.target.value,err:{},g_err:""}))),at(this,"onChangeAddress",(t=>this.setState({address:t,err:{},g_err:""}))),at(this,"onSelectAddress",(t=>{t&&(this.setState({address:[i.Z.trim(t.address),i.Z.trim(t.street)].join(" ").trim(),street:t.street,err:{},g_err:""}),this.onSelectWard({id:t.ward_id,name:t.ward}),this.onSelectDistrict({id:t.district_id,name:t.district}),this.onSelectProvince({id:t.province_id,name:t.province}))})),at(this,"onChangeEmail",(t=>this.setState({email:t.target.value,err:{},g_err:""}))),at(this,"onChangePhone",(t=>this.setState({phone:t.target.value,err:{},g_err:""}))),at(this,"onChangePaymentMethod",(t=>this.setState({pm:t}))),at(this,"onChangeQuantity",((t,e)=>{let s=parseInt(e)||1;t.quantity=s,this.forceUpdate()})),at(this,"confirm",(async()=>{this.setState({g_err:""});let t={};if(this.state.shipping||this.setState({g_err:"Mời bạn chọn địa chỉ giao hàng trước khi xác nhận"}),"shop"===this.state.shipping?(i.Z.isPhone(this.state.phone)||(t.phone=!0),i.Z.trim(this.state.fullname)||(t.name=!0),i.Z.trim(this.state.email)||(t.email=!0)):"new"==this.state.shipping_address&&(i.Z.isPhone(this.state.phone)||(t.phone=!0),i.Z.trim(this.state.fullname)||(t.name=!0),i.Z.trim(this.state.address)||(t.address=!0),0==i.Z.size(this.state.selectedWard)&&(t.ward=!0),0==i.Z.size(this.state.selectedDistrict)&&(t.district=!0),0==i.Z.size(this.state.selectedProvince)&&(t.province=!0)),i.Z.size(t)>0)return void this.setState({err:t,g_err:this.props.t("input_shipping_info_err")});let e=this.props.store.matchUser(),s=i.Z.getUserAttr(e,"fullname","text"),r=i.Z.getUserAttr(e,"emails","text"),o=i.Z.getUserAttr(e,"phones","text"),a=i.Z.cloneDeep(this.state.order);if("shop"===this.state.shipping)i.Z.set(a,"shipping.pickup_at_shop",!0),i.Z.set(a,"shipping.address.phone",this.state.phone),i.Z.set(a,"shipping.address.fullname",this.state.fullname),i.Z.set(a,"shipping.address.email",this.state.email);else if("new"==this.state.shipping_address){let t=await this.props.store.createShippingAddress({address:this.state.address,country:"Việt Nam",fullname:this.state.fullname,email:this.state.email,phone:this.state.phone,district:this.state.selectedDistrict.name,district_id:this.state.selectedDistrict.id,province:this.state.selectedProvince.name,province_id:this.state.selectedProvince.id,ward:this.state.selectedWard.name,street:this.state.street,ward_id:this.state.selectedWard.id});if(t.error)return this.setState({g_err:this.props.t("update_failed")});i.Z.set(a,"shipping.address",t.body)}else{let e=this.props.store.matchShippingAddresses(),s=i.Z.find(e,(t=>t.id===this.state.shipping_address));if(!s)return this.setState({err:t,g_err:this.props.t("input_shipping_info_err")});i.Z.set(a,"shipping.address",s)}let n=!1;!s&&this.state.fullname&&(n=!0,i.Z.setUserAttr(e,{key:"fullname",text:this.state.fullname})),!r&&this.state.email&&(n=!0,i.Z.setUserAttr(e,{key:"emails",text:this.state.email})),!o&&this.state.phone&&(n=!0,i.Z.setUserAttr(e,{key:"phones",text:this.state.phone})),n&&this.props.store.setUser(e),this.setState({sending:!0}),a.user_confirmation="confirmed";let h=await this.props.store.updateOrder(a);if(this.setState({sending:!1}),h.error)return this.setState({g_err:this.props.t("update_failed")});this.setState({step:"success"}),this.props.onResponse&&this.props.onResponse("confirmed")})),at(this,"onCancel",(()=>{if(this.props.onResponse&&this.props.onResponse("rejected"),this.props.cid&&!this.state.order.user_confirmation){let t=i.Z.cloneDeep(this.state.order);t.user_confirmation="rejected",this.props.store.updateOrder(t)}this.close()})),at(this,"close",(()=>{this.props.onClose&&this.props.onClose()})),this.load()}async load(){if(!this.props.order_id)return;let t=await this.props.store.fetchOrder(this.props.order_id);this.setState({loading:!1}),t.error?this.setState({error:t.error}):this.setState({order:t.body}),this.props.store.matchUser();let e=i.Z.get(this.props.store.matchUser(),"attributes",[]),s=i.Z.get(i.Z.find(e,(t=>"fullname"===t.key)),"text"),r=i.Z.get(i.Z.find(e,(t=>"emails"===t.key)),"text"),o=i.Z.get(i.Z.find(e,(t=>"phones"===t.key)),"text");this.setState({fullname:s,email:r,phone:o}),await this.props.store.fetchShippingAddresses();let a=await this.props.store.list_provinces();this.setState({loadProvince:!1}),a.error||this.setState({provinces:i.Z.get(a,"body.addresses")})}isMobile(){return!!this.props.cid||!!this.props.isMobile||this.props.store.isMobile()}onChangeShippingAddress(t){this.setState({shipping_address:t,err:{},g_err:""})}onChangeShipping(t){this.setState({shipping:t,err:{},g_err:""})}renderDesktopPaymentMethod(t){return null}renderDesktopShipping(t){let e=!1;if(t.status&&"open"!=t.status||(e=!t.user_confirmation),this.props.store.matchUser(),e){let t=this.props.store.matchShippingAddresses(),e=i.Z.map(this.state.provinces,(t=>({id:t.id,name:t.province}))),s=i.Z.map(this.state.districts,(t=>({id:t.id,name:t.district}))),r=i.Z.map(this.state.wards,(t=>({id:t.id,name:t.ward}))),a="ship_card",n=null,h=!1;if("ship"===this.state.shipping){h=!0;let l=i.Z.map(t,(t=>{let e=[t.street,t.ward,t.district,t.region,t.country].filter((t=>t)).join(", "),s=null;return t.phone&&(s=(0,o.h)(o.HY,null," · ",this.props.t("phn")," ",t.phone)),(0,o.h)("div",{style:"margin-bottom: 15px !important"},(0,o.h)("div",{class:"radio d-flex "},(0,o.h)("input",{type:"radio",id:"shipping_addr."+t.id,onInput:e=>this.onChangeShippingAddress(t.id),name:"shipping_address",checked:this.state.shipping_address===t.id}),(0,o.h)("label",{class:"radio--label",for:"shipping_addr."+t.id,style:`font-weight: ${this.state.shipping_address===t.id?500:400} !important`},t.fullname,s,(0,o.h)("div",{class:"mt-1 muted"},"DC ",e)),(0,o.h)("div",{class:"radio--check"},(0,o.h)("div",{class:"inside"}))))}));l.push((0,o.h)("div",{style:""},(0,o.h)("div",{class:"radio d-flex "},(0,o.h)("input",{type:"radio",id:"shipping_addr.new",onInput:t=>this.onChangeShippingAddress("new"),name:"shipping_address",checked:"new"===this.state.shipping_address}),(0,o.h)("label",{class:"radio--label",for:"shipping_addr.new"},"new"===this.state.shipping_address?(0,o.h)("b",null,"Tới địa chỉ khác"):"Tới địa chỉ khác"),(0,o.h)("div",{class:"radio--check"},(0,o.h)("div",{class:"inside"})))));let p=(0,o.h)("div",{style:"padding-left: 22px !important;"},(0,o.h)("div",{class:"d-flex"},(0,o.h)("div",{class:"mr-2",style:"flex: 1 !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("fullname")),(0,o.h)("input",{type:"text",class:"form-control "+(this.state.err.name&&"err"),onInput:this.onChangeFullname,value:this.state.fullname})),(0,o.h)("div",{class:"ml-2",style:"flex: 1 !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("phones")),(0,o.h)("input",{type:"text",class:"form-control "+(this.state.err.phone&&"err"),onInput:this.onChangePhone,value:this.state.phone}))),(0,o.h)("div",{class:"",style:"width: 100% !important"},(0,o.h)("div",{class:"order_form_label"},this.props.t("address")),(0,o.h)(st,{initAddress:this.state.address,store:this.props.store,width:"100%",onChangeAddress:this.onChangeAddress,full:this.isMobile(),onSelect:this.onSelectAddress,extra_cls:this.state.err.address&&"err"})),(0,o.h)("div",{class:"d-flex",style:"justify-content: space-between !important;"},(0,o.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-right: 7px !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("province")),(0,o.h)(tt,{width:"194",full:this.isMobile(),has_search:!0,loading:this.state.loadProvince,items:e,selected:this.state.selectedProvince,onSelect:this.onSelectProvince,extra_cls:this.state.err.province&&"err"})),(0,o.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-left: 7px !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("district")),(0,o.h)(tt,{width:"194",full:this.isMobile(),selected:this.state.selectedDistrict,has_search:!0,onSelect:this.onSelectDistrict,loading:this.state.loadDistrict,extra_cls:this.state.err.district&&"err",items:s}))),(0,o.h)("div",{class:"d-flex",style:"justify-content: space-between !important;"},(0,o.h)("div",{style:"flex: 1 !important; overflow:hidden !important; margin-right: 7px !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("ward")),(0,o.h)(tt,{width:"194",selected:this.state.selectedWard,full:this.isMobile(),has_search:!0,onSelect:this.onSelectWard,extra_cls:this.state.err.ward&&"err",loading:this.state.loadWard,items:r})),(0,o.h)("div",{style:"flex: 1 !important; margin-left: 7px !important;"})));a+=" ship_card__active",0==i.Z.size(t)?n=(0,o.h)("div",null,(0,o.h)("div",{class:"mt-3 mb-2 "},this.props.t("input_shipping_info")),p):("new"!==this.state.shipping_address&&(p=null),n=(0,o.h)("div",null,(0,o.h)("div",{class:"mt-3 mb-2",style:"margin-bottom: 10px !important;"},"Vui lòng chọn địa chỉ giao hàng"),(0,o.h)("div",{class:"form"},l),p))}let l="ship_card",p=!1;"shop"===this.state.shipping&&(p=!0,l+=" ship_card__active",n=(0,o.h)("div",null,(0,o.h)("div",{class:"d-flex"},(0,o.h)("div",{class:"mr-2",style:"flex: 3 !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("fullname")),(0,o.h)("input",{type:"text",class:"form-control "+(this.state.err.name&&"err"),onInput:this.onChangeFullname,value:this.state.fullname})),(0,o.h)("div",{class:"ml-2",style:"flex: 2 !important;"},(0,o.h)("div",{class:"order_form_label"},this.props.t("phones")),(0,o.h)("input",{type:"text",class:"form-control "+(this.state.err.phone&&"err"),onInput:this.onChangePhone,value:this.state.phone}))),(0,o.h)("div",null,(0,o.h)("div",{class:"order_form_label"},this.props.t("email")),(0,o.h)("input",{type:"text",class:"form-control "+(this.state.err.email&&"err"),onInput:this.onChangeEmail,value:this.state.email}))));let d="card_section";return this.isMobile()&&(d="order_section"),(0,o.h)(o.HY,null,(0,o.h)("div",{class:"order_section__line"}),(0,o.h)("div",{class:d},(0,o.h)("div",{class:"order_label"},this.props.t("ship_to")),(0,o.h)("div",{class:"d-flex"},(0,o.h)("div",{class:l+" mr-3",onClick:t=>this.onChangeShipping("shop")},(0,o.h)(ot,{name:"shop",active:p})," ",(0,o.h)("b",{class:"ml-2"},"Nhận hàng tại shop")),(0,o.h)("div",{class:a,onClick:t=>this.onChangeShipping("ship")},(0,o.h)(ot,{name:"package",active:h})," ",(0,o.h)("b",{class:"ml-2"},"Giao hàng cho tôi"))),n))}let s=i.Z.get(t,"shipping.address")||{},r=[s.address,s.ward,s.district,s.region,s.country].filter((t=>t)).join(", "),a=null;s.phone&&(a=(0,o.h)("div",{class:"mt-1 muted"},this.props.t("phn"),": ",s.phone)),i.Z.get(t,"shipping.pickup_at_shop")&&(r="Nhận hàng tại cửa hàng");let n=r?(0,o.h)("div",null,r):(0,o.h)("i",{class:"i muted"},"Chưa có địa chỉ giao hàng"),h="card_section";return this.isMobile()&&(h="order_section"),(0,o.h)("div",{class:h},(0,o.h)("div",{class:"order_label "},this.props.t("ship_to")),n,a)}renderDesktopSummary(t){let e=null;t.deposit>0&&(e=(0,o.h)("span",{class:"muted"},"(cọc ",i.Z.formatCurrency(t.deposit),")"));let r=null;t.total_discount>0&&(r=(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Giảm giá"),(0,o.h)("div",null,i.Z.formatCurrency(t.total_discount))));let a=null;(e||t.payment_made)&&(a=(0,o.h)(o.HY,null,(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Bạn đã trả"),(0,o.h)("div",null,e," ",i.Z.formatCurrency(t.payment_made))),(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Bạn chưa trả"),(0,o.h)("div",null,i.Z.formatCurrency((t.total||0)-(t.payment_made||0))))));let n=(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Tiền thuế"),(0,o.h)("div",null,i.Z.formatCurrency(t.total_tax))),h=(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Phí vận chuyển"),(0,o.h)("div",null,i.Z.get(t,"shipping.fee",0)," d")),l=!1;t.status&&"open"!=t.status||(l=!t.user_confirmation);let p=null;l&&(h=null,n=null,p=(0,o.h)("div",{class:"muted"},(0,o.h)("img",{class:"order_ship_icon",src:s(9256)}),"  Chưa bao gồm thuế và phí vận chuyển"));let d="";return this.isMobile()&&(d="order_section"),(0,o.h)(o.HY,null,(0,o.h)("div",{class:"order_section__line"}),(0,o.h)("div",{class:d},(0,o.h)("div",{class:"order_label"},"Tóm tắt"),(0,o.h)("div",{class:"order_summary_line"},(0,o.h)("div",null,"Tổng tiền hàng"),(0,o.h)("div",null,i.Z.formatCurrency(t.subtotal))),n,r,h,p,(0,o.h)("div",{class:"order_summary_line",style:"margin-top: 10px !important; padding-top: 15px !important; border-top: 1px solid #eee !important"},(0,o.h)("div",null,"Bạn phải trả"),(0,o.h)("div",{class:"order__total"},i.Z.formatCurrency(t.total))),a))}renderStatusBadge(t){let e=t.status||"open";return(0,o.h)("div",{style:"float: right !important;",class:"order_status order_status__"+e},e)}renderShippingInfo(t){"open"!=t.status||t.user_confirmation;let e=i.Z.get(t,"shipping.shipping_provider");if(!e)return null;let r=i.Z.get(t,"shipping.shipping_code"),a=null;return r&&(a=(0,o.h)("div",{class:"muted",style:"margin-top: 3px !important"},"Vận đơn ",(0,o.h)("a",{class:"order_tracking_link",target:"_blank",href:"https://giaohangtietkiem.vn/tra-cuu-van-don/"+r},r," ",(0,o.h)("img",{class:"order_tracking_link_icon",src:s(8453)})))),"ghtk"==e?(0,o.h)("div",{class:"order_section"},(0,o.h)("div",{class:"order_section_label"},"Đơn vị vận chuyển"),(0,o.h)("div",{class:"d-flex align-items-center"},(0,o.h)("img",{class:"order_shipping_provider_logo",src:pt.ghtk.logo}),(0,o.h)("div",null,pt.ghtk.name,a))):null}renderDesktopShippingInfo(t){let e=i.Z.get(t,"shipping.shipping_provider");if(!e)return null;let r=i.Z.get(t,"shipping.shipping_code"),a=null;return r&&(a=(0,o.h)("div",{class:"muted",style:"margin-top: 3px !important"},"Vận đơn ",(0,o.h)("a",{class:"order_tracking_link",target:"_blank",href:"https://giaohangtietkiem.vn/tra-cuu-van-don/"+r},r," ",(0,o.h)("img",{class:"order_tracking_link_icon",src:s(8453)})))),"ghtk"==e?(0,o.h)(o.HY,null,(0,o.h)("div",{class:"order_label"},"Đơn vị vận chuyển"),(0,o.h)("div",{class:"d-flex align-items-center"},(0,o.h)("img",{class:"order_shipping_provider_logo",src:pt.ghtk.logo}),(0,o.h)("div",null,pt.ghtk.name,a))):null}renderProducts(t){let e=null;return e=i.Z.map(t.items,(t=>{if(!t||!t.product)return null;let e=t.product;return(0,o.h)("div",{class:"order_attachment__product"},(0,o.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.Z.get(e,"images.0")||s(9270)}),(0,o.h)("div",{style:"overflow: hidden !important;"},(0,o.h)("div",{class:"order_attachment__product_name"},e.name),(0,o.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,o.h)("div",{class:"order_attachment__product_desc"},this.props.t("qty")," ",t.quantity," · ",i.Z.formatCurrency(e.price))))})),this.isMobile()?(0,o.h)("div",{class:"order_section"},(0,o.h)("div",{class:"order_section_label"},this.props.t("product")),e):(0,o.h)("div",null,(0,o.h)("div",{class:"order_label"},this.props.t("product")),e)}renderDesktopProducts(t){let e=null,r=!1;return t.status&&"open"!=t.status||(r=!t.user_confirmation),e=r?i.Z.map(t.items,(t=>{if(!t||!t.product)return null;let e=t.product;return(0,o.h)("div",{class:"order_attachment__product"},(0,o.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.Z.get(e,"images.0")||s(9270)}),(0,o.h)("div",{style:"overflow: hidden !important; flex: 1 !important"},(0,o.h)("div",{class:"order_attachment__product_name"},e.name),(0,o.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,o.h)("div",{class:"order_attachment__product_desc"},i.Z.formatCurrency(e.price))),(0,o.h)("input",{class:"form-control",style:"text-align: center !important; font-weight: 400 !important; width: 50px !important",value:t.quantity,onInput:e=>this.onChangeQuantity(t,e.target.value),type:"text"}),(0,o.h)("div",{style:"width: 80px !important; text-align: right !important; "},(0,o.h)("b",null,i.Z.formatCurrency(t.quantity*e.price))))})):i.Z.map(t.items,(t=>{if(!t||!t.product)return null;let e=t.product;return(0,o.h)("div",{class:"order_attachment__product"},(0,o.h)("img",{class:"order_attachment__product_img",alt:""+e.id,src:i.Z.get(e,"images.0")||s(9270)}),(0,o.h)("div",{style:"overflow: hidden !important; flex: 1 !important"},(0,o.h)("div",{class:"order_attachment__product_name"},e.name),(0,o.h)("div",{class:"order_attachment__product_desc"},e.description||e.long_description),(0,o.h)("div",{class:"order_attachment__product_desc"},i.Z.formatCurrency(e.price))),(0,o.h)("div",{style:"text-align: center !important; font-weight: 400 !important; width: 50px !important"},t.quantity),(0,o.h)("div",{style:"width: 80px !important; text-align: right !important; "},(0,o.h)("b",null,i.Z.formatCurrency(t.total))))})),(0,o.h)("div",{class:"card_section"},(0,o.h)("div",{class:"desktop_order__heading"},this.renderStatusBadge(t),(0,o.h)("b",{style:"font-size: 18px !important;"},this.props.t("order")," #",t.order_number||t.id),(0,o.h)("div",{class:"muted"},(0,o.h)(T,{style:"font-size: 13px !important;",time:t.issue_date||t.created}))),(0,o.h)("div",{class:"order_label d-flex",style:"margin-top: 20px !important;justify-content: space-between !important; align-items: flex-end !important;"},(0,o.h)("div",{style:"flex: 1 !important;"},this.props.t("product")),(0,o.h)("div",{style:"font-weight: 400 !important; text-align:center !important; width: 50px !important"},this.props.t("qty")),(0,o.h)("div",{style:"font-weight: 400 !important; text-align: right !important; width: 80px !important;"},this.props.t("total"))),e)}renderMobile(t){if("success"===this.state.step)return this.renderMobileSuccess(t);let e=null;this.state.g_err&&(e=(0,o.h)("div",{class:"mb-2 text__danger"},(0,o.h)("img",{style:"margin-top: -4px !important; height: 15px !important;",src:ht})," ",(0,o.h)("b",null,this.state.g_err)));let s=(0,o.h)("div",null,e,(0,o.h)("div",{class:"btn-confirm-order",style:"margin-top: 0 !important;",onClick:this.confirm},this.props.t("confirm_order"))),i=(0,o.h)("div",{class:"order_btn order__btn__light mt-3",onClick:this.onCancel},this.props.t("cancel_order"));return(t.user_confirmation||"open"!=t.status)&&(s=null,this.props.cid&&(i=(0,o.h)("div",{class:"order_btn order__btn__light mt-3",onClick:this.close},this.props.t("close")))),(0,o.h)("div",{class:"order",style:"height: 100% !important"},(0,o.h)("div",{class:"order--content"},(0,o.h)("div",{class:"order--heading"},this.renderStatusBadge(t),(0,o.h)("b",{style:"font-size: 16px !important;"},this.props.t("order")," #",t.order_number||t.id),(0,o.h)("div",{class:"muted"},(0,o.h)(T,{style:"font-size: 13px !important;",time:t.issue_date||t.created}))),this.renderProducts(t),this.renderDesktopShipping(t),this.renderShippingInfo(t),this.renderDesktopPaymentMethod(t),this.renderDesktopSummary(t),(0,o.h)("div",{class:"order_section pb-3",style:"padding-top: 0 !important;"},s,i)))}renderActions(t){let e=null,s=!1;if(t.status&&"open"!=t.status||(s=!t.user_confirmation),"success"===this.state.step)return(0,o.h)("div",{class:"d-flex",style:"align-items: center !important; justify-content: flex-end !important"},(0,o.h)("div",null,"Ghi nhận thành công")," ",(0,o.h)("img",{style:"width: 16px !important; height: 16px !important;",width:"16",height:"16",src:nt}));if(s){let t=null;this.state.g_err&&(t=(0,o.h)("div",{class:"mb-2 text__danger"},(0,o.h)("img",{style:"margin-top: -4px !important; height: 15px !important;",src:ht})," ",(0,o.h)("b",null,this.state.g_err))),e=(0,o.h)("div",null,t,(0,o.h)("div",{class:"btn-confirm-order",onClick:this.confirm},this.props.t("confirm_order")),(0,o.h)("div",{class:"btn-cancel-order",onClick:this.onCancel},this.props.t("cancel_order")))}return e}renderDesktop(t){let e=this.props.store.matchAccount();var i=e.logo_url||s(9895);return(0,o.h)("div",{class:"desktop order"},(0,o.h)("div",{class:"order_acc_header"},(0,o.h)("img",{class:"order_acc_logo",src:i}),(0,o.h)("div",{class:"order_acc_name"},e.name)),(0,o.h)("div",{class:"desktop_order__content"},(0,o.h)("div",{style:"flex: 1 !important; padding-right: 20px !important;"},this.renderDesktopProducts(t),this.renderDesktopShipping(t),this.renderDesktopShippingInfo(t),this.renderDesktopPaymentMethod(t),(0,o.h)("div",{class:"order__footer"},(0,o.h)("a",{target:"_blank",href:"https://subiz.com.vn",class:"order__footer_link"},"Cung cấp bởi ",(0,o.h)("b",null,"Subiz")),(0,o.h)("div",{class:"order__footer_delimiter"}),(0,o.h)("a",{target:"_blank",href:"https://subiz.com.vn/vi/terms-of-service.html",class:"order__footer_link"},"Điều khoản"),(0,o.h)("a",{target:"_blank",href:"https://subiz.com.vn/vi/privacy-policy.html",class:"order__footer_link"},"Quyền riêng tư"))),(0,o.h)("div",null,(0,o.h)("div",{class:"order_recap"},this.renderDesktopSummary(t),this.renderActions(t)))))}render(){if(this.state.loading)return(0,o.h)("div",{class:"order_error"},(0,o.h)(W,{class:"mt-4",size:"60",static:!0}));if(this.state.error)return(0,o.h)("div",{class:"order_error"},(0,o.h)("img",{class:"mt-3",src:s(6825)}),(0,o.h)("div",{class:"mt-3"},this.props.t("order_load_error")));let t=this.state.order;return this.isMobile()?this.renderMobile(t):this.renderDesktop(t)}}let pt={ghtk:{name:"Giao hàng tiết kiệm",logo:s(6890)},ghn:{name:"Giao hàng nhanh",logo:s(1473)}};function dt(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}s(4761);class ct extends r.up{constructor(t){super(t),dt(this,"state",{hide:!0,ratingHeight:0,overlayOpacity:.3}),dt(this,"onResponse",(t=>{this.setState({response:t})})),dt(this,"confirm",(()=>{this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:"confirm",attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"confirmed"})}}]}})})),dt(this,"close",(async()=>{if(await i.Z.sleep(100),"confirmed"===this.state.response?this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:this.props.t("confirm_order"),attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"confirmed"})}}]}}):"rejected"===this.state.response&&this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{format:"plaintext",text:this.props.t("cancel_order"),attachments:[{type:"postback",postback:{payload:JSON.stringify({type:"order_confirmation",status:"cancelled"})}}]}}),this.setState({response:""}),!this.state.hide&&this.refRating.current){var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(20,e,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||this.setState({hide:!0}))})),this.props.onClose()}})),this.refRating=(0,o.Vf)(),this.refHandle=(0,o.Vf)()}componentDidMount(){this.mouseUp=t=>this.onMouseUp(t),this.mouseMove=t=>this.onMouseMove(t),this.mouseDown=t=>this.onMouseDown(t);var t=this.refHandle.current;t.addEventListener("mousedown",this.mouseDown,{passive:!0}),t.addEventListener("touchstart",this.mouseDown,{passive:!0}),window.addEventListener("mouseup",this.mouseUp,{passive:!0}),window.addEventListener("touchend",this.mouseUp,{passive:!0}),window.addEventListener("mousemove",this.mouseMove,{passive:!0}),window.addEventListener("touchmove",this.mouseMove,{passive:!0}),this.animation=new J({maxY:400,minY:0,duration:150}),this.close()}componentWillUnmount(){var t=this.refHandle.current;t.removeEventListener("mousedown",this.mouseDown,0),t.removeEventListener("touchstart",this.mouseDown,0),window.removeEventListener("mouseup",this.mouseUp,0),window.removeEventListener("touchend",this.mouseUp,0),window.removeEventListener("mousemove",this.mouseMove,0),window.removeEventListener("touchmove",this.mouseMove,0)}render(){this._show!=this.props.show&&(this._show=this.props.show,setTimeout((()=>{this._show?this.open():this.close()})));let t=this.state.hide?"d-none":"";return(0,o.h)("div",{class:t},(0,o.h)("div",{class:"extension--overlay",style:`opacity: ${.5*this.state.overlayOpacity} !important;`}),(0,o.h)("div",{class:"extension",ref:this.refRating,style:`height: ${this.state.ratingHeight}px !important;`},(0,o.h)("div",{class:"extension--close-btn",onClick:this.close},this.props.t("close")),(0,o.h)("div",{class:"extension--handle",ref:this.refHandle},(0,o.h)("div",{class:"extension--thumb"})),(0,o.h)("div",{style:"overflow-x: hidden !important; overflow-y: scroll !important; height: 100% !important;"},(0,o.h)(lt,{key:this.props.order_id,store:this.props.store,onResponse:this.onResponse,onClose:this.close,t:this.props.t,order_id:this.props.order_id,cid:this.props.cid}))))}open(){if(this.state.hide&&this.props.order_id&&(this.setState({hide:!1}),this.refRating.current)){var t=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),e=parseFloat(t.height);this.animation.play(-20,e,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)})}))}}onMouseDown(t){this.mousePushed=!0,this.animation.stop(),t.preventDefault(),t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushedDy=t.pageY-window.pageYOffset-this.refRating.current.getBoundingClientRect().y}onMouseUp(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]),this.mousePushed=!1;var e=this.refRating.current.currentStyle||window.getComputedStyle(this.refRating.current),s=parseFloat(e.height);this.animation.play(this.mouseVelocity,s,(t=>{this.setState({ratingHeight:t,overlayOpacity:Math.min(1,(t-0)/500)}),t<10&&(this.state.hide||(this.setState({hide:!0}),this.props.onRate&&this.props.onRate({no_rating:!0})))}))}}onMouseMove(t){if(this.mousePushed){t.touches&&t.touches[0]&&(t=t.touches[0]);var e=t.pageY;this.mouseVelocity=e-this.lastMouseY,this.lastMouseY=e,e-=this.mousePushedDy;var s=this.refRating.current.getBoundingClientRect().bottom-e;s>400&&(s=500-1e4/(s+-300)),this.setState({ratingHeight:s,overlayOpacity:Math.min(1,(s-0)/500)})}}}function ut(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}var mt=s(9737),gt=s(8909),vt=s(29);const ft="https://file-subiz.com/fiqoahedjbgwclpouoml-avatar_default_baa8a1d7.png";class _t extends r.up{constructor(t){super(t),ut(this,"onLink",((t,e)=>{if(!e)return t.preventDefault();let s=e.replace(/(^\w+:|^)\/\//,"");if(s.startsWith("widget.subiz.com.vn/orders/")){let e=s.substr("widget.subiz.com.vn/orders/".length);return e=e.split("/")[0],this.setState({showOrder:!0,order_id:e}),void t.preventDefault()}})),ut(this,"closeOrder",(t=>{this.setState({showOrder:!1,order_id:""}),this.focusInput()})),this.userSent={},this.setState({creating:!1,clickedJoin:!1,formData:{},showOrder:!1,order_id:""}),this.props.store.onUpdate(this,(t=>this.forceUpdate()))}componentDidMount(){this.props.store.isMobile()||this.focusInput()}componentDidUpdate(t){t.isShow!==this.props.isShow&&(this.props.isShow&&!this.props.store.isMobile()&&this.focusInput(),this.props.isShow&&this.props.store.isMobile()&&this.blur()),t.cid!==this.props.cid&&(this.closeOrder(),this.setState({clickedJoin:!1}),setTimeout((()=>{this.events&&this.events.focus(),this.props.store.isMobile()||this.focusInput()}),100)),this.updateFormDataFields()}shouldShowForm(){let t=this.isFormRequired();return t&&!this.props.cid||t&&this.props.cid&&this.state.clickedJoin}render(){let t,e=this.shouldShowForm(),s=this.props.plugin.chatbox||{},r=this.props.store.matchAccount()||{},a=this.props.t("prechat_form_btn");i.Z.get(s,"prechat_form.enabled")&&(t=s.prechat_form);let n=i.Z.get(s,"offline_form.enabled");this.isOffline(r,s)&&n&&(t=s.offline_form,a=this.props.t("offline_form_btn")),"offline_form"===this.props.view&&(e=!0,t=s.offline_form,a=this.props.t("offline_form_btn")),"prechat_form"===this.props.view&&(e=!0,t=s.prechat_form,a=this.props.t("prechat_form_btn"));let h=null;h="list"===this.props.view?this.renderConvoList():e?this.renderForm(t,a):this.renderChat();let l=i.Z.get(s,"desktop_button.position")||"right";this.props.store.isMobile()&&(l=i.Z.get(s,"mobile_button.position",l));let p="widget-container widget-container--"+l;return this.props.isShow||(p+=" widget-container--hide"),(0,o.h)("div",{class:p},(0,o.h)(v,{t:this.props.t,plugin:this.props.plugin,store:this.props.store,cid:this.props.cid,view:this.props.view,onClose:this.props.onClose,onGotoList:()=>this.props.onGo({view:"list"})}),h)}async submitPrechatForm(t){var e=!1;if(i.Z.map(this.state.formData,((t,s)=>{t.is_required&&(void 0===t.value||""===t.value||0===i.Z.size(t.value)&&Array.isArray(t.value))?(t.error=this.props.t("error_empty"),e=!0):t.error="","emails"===s.substr(5)&&!i.Z.isEmail(t.value)&&t.is_required&&(t.error=this.props.t("error_email_invalid"),e=!0),"phones"===s.substr(5)&&!i.Z.isPhone(t.value)&&t.is_required&&(t.error=this.props.t("error_phone_invalid"),e=!0)})),e)return this.forceUpdate();let s=i.Z.cloneDeep(this.state.formData),r=i.Z.cloneDeep(this.props.store.matchUser()),o=!1;i.Z.map(s,((t,e)=>{if(e.startsWith("attr:")){var s={key:e.substr(5)};o=o||"emails"==e||"phones"==e,"number"===t.type&&(s.number=parseInt(t.value)),"datetime"===t.type&&(s.datetime=new i.Z.Date(t.value).toISOString()),"list"===t.type&&(s.list=t.value),"text"!==t.type&&"boolean"!==t.type||(s[t.type]=t.value),i.Z.setUserAttr(r,s)}})),o&&i.Z.setUserAttr(r,{key:"lead_source",text:"widget"});let a=i.Z.get(s,"question.value"),n=i.Z.get(s,"group.value","");if(this.props.cid)return this.props.store.setUser(r),this.setState({clickedJoin:!1}),await this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:{text:a,format:"plaintext",fields:[{key:"to_agent_group",value:i.Z.stringify(n)}]}}),void(t.end_conversation_after_submit&&await this.props.store.endConvo(this.props.cid));this.setState({creating:!0});let h={text:a,format:"plaintext"},l={group_id:n,message:a,locale:this.props.t.locale(),initial_by:r.id};this.setState({creatingError:null}),await this.props.store.setUser(r);const{error:p,convo:d}=await this.props.store.startConvo(l);if(p)return void this.setState({creating:!1,creatingError:p});let c=d.id;this.userSent[c]=!0,this.props.onGo({view:"chat",cid:c}),this.props.store.sendConvoEvent(c,"message_sent",{message:h}),this.setState({creating:!1,clickedJoin:!1}),this.props.store.isMobile()||this.focusInput()}formMounted(t){let e=this.fillForm(t);e.question={key:"question",is_required:!0,label:this.props.t.i18n(i.Z.get(t,"i18n_question_label",{}))||t.question_label,type:"text"},this.setState({formData:e}),this.props.store.isMobile()||this.focusInput()}onBooleanChange(t,e){let s=i.Z.cloneDeep(this.state.formData),r=i.Z.find(s,((e,s)=>s===t));r&&(r.value=e.target.checked,this.setState({formData:s}))}onInputChange(t,e){let s=i.Z.cloneDeep(this.state.formData),r=i.Z.find(s,((e,s)=>s===t));r&&(r.value=e,this.setState({formData:s}))}onListAddItem(t,e){let s=i.Z.cloneDeep(this.state.formData),r=i.Z.find(s,((e,s)=>s===t));r&&(r.value=r.value||[],r.value.push(e),this.setState({formData:s}))}onListRemoveItem(t,e){let s=i.Z.cloneDeep(this.state.formData),r=i.Z.find(s,((e,s)=>s===t));r&&(r.value=r.value||[],r.value.splice(e,1),this.setState({formData:s}))}renderFields(){if(0===i.Z.size(this.state.formData))return null;let t=i.Z.map(this.state.formData,((t,e)=>{let s=null;var r=t.error?"input--error":"";if("text"===t.type)s="question"===e?(0,o.h)("textarea",{class:"form-control",ref:t=>{this["form_"+bt(e)]=t},value:t.value||"",onInput:t=>this.onInputChange(e,t.target.value),row:"4",class:"form-control"}):(0,o.h)("input",{value:t.value||"",onInput:t=>this.onInputChange(e,t.target.value),ref:t=>{this["form_"+bt(e)]=t},class:`form-control ${r}`,type:"text"});else if("number"===t.type)s=(0,o.h)("input",{value:t.value,onInput:t=>this.onInputChange(e,t.target.value),ref:t=>{this["form_"+bt(e)]=t},class:`form-control ${r}`,type:"number"});else if("boolean"===t.type)s=(0,o.h)("div",{class:"checkbox"},(0,o.h)("input",{type:"checkbox",id:"form-checkbox"+bt(e),onInput:t=>this.onBooleanChange(e,t),checked:t.value}),(0,o.h)("label",{class:"checkbox--label",for:"form-checkbox"+bt(e)},t.label),(0,o.h)("div",{class:"checkbox--check"},(0,o.h)("div",null)));else if("group"===t.type)s=i.Z.map(t.list,(s=>(0,o.h)("div",{class:"radio"},(0,o.h)("input",{type:"radio",id:"form-radio"+bt(e)+bt(s.value),checked:t.value===s.value,onInput:t=>this.onInputChange(e,s.value)}),(0,o.h)("label",{class:"radio--label",for:"form-radio"+bt(e)+bt(s.value)},s.label),(0,o.h)("div",{class:"radio--check"},(0,o.h)("div",{class:"inside"})))));else if("list"===t.type){let r=this.state.formData[e].value||[],a=i.Z.filter(i.Z.get(t,"list",[]),(t=>!i.Z.includes(r,t)));s=(0,o.h)(S,{selected:r,items:a,onAddItem:t=>this.onListAddItem(e,t),onRemoveItem:t=>this.onListRemoveItem(e,t)})}else"datetime"===t.type&&(s=(0,o.h)("input",{value:t.value,onInput:t=>this.onInputChange(e,t.target.value),class:`form-control ${r}`,type:"date"}));let a="";return"fullname"===t.key?a=this.props.t("fullname"):"emails"===t.key?a=this.props.t("email"):"phones"===t.key?a=this.props.t("phones"):"question"===t.key&&(a=t.label||this.props.t("your_question")),t.label&&(a=t.label),(0,o.h)("div",null,(0,o.h)("div",{class:"label"},a,t.is_required?(0,o.h)("span",{class:"ml-1 red"},"*"):""),t.error?(0,o.h)("div",{class:"form-control--valid-input--error"},t.error):"",s)}));return(0,o.h)("div",{class:"pt-2"},t)}renderForm(t,e){let s=null;this.state.creating&&(s=(0,o.h)("span",{class:"ml-2"},(0,o.h)(W,{size:"16",mode:"white"})));let r=this.props.t.i18n(i.Z.get(t,"i18n_title",{}));return r||(r=i.Z.get(t,"title",this.props.t("capture_lead_title"))),r=r.replace("↵",""),(0,o.h)("div",{class:"widget-body"},(0,o.h)(yt,{form:t,onMount:t=>this.formMounted(t)}),(0,o.h)("div",{class:"widget-body--content flex-grow-1 pl-3 pr-3 d-flex flex-column"},(0,o.h)("div",{class:"flex-grow-1"},(0,o.h)("div",{class:"form mt-3 pl-3 pr-3 pt-3 pb-3 d-flex flex-column"},(0,o.h)("div",null,r),this.renderFields())),(0,o.h)(m,{store:this.props.store,t:this.props.t})),(0,o.h)("div",{class:"message-input message-input--preform"},(0,o.h)("button",{class:"btn--start-convo",onClick:e=>this.submitPrechatForm(t)},e," ",s)))}goToConvo(t){this.props.onGo({view:"chat",cid:t})}renderConvoList(){let t=this.props.store.matchConvo("*");var e=i.Z.map(t,(t=>this.props.store.matchConvo(t.id)));e=i.Z.filter(e,(t=>!!t)),e=i.Z.orderBy(e,"created","desc");var s=i.Z.map(e,(t=>{let e=i.Z.filter(t.members,(t=>("agent"===t.type||"bot"===t.type)&&"active"===t.membership)),s=i.Z.map(e,(t=>t.id));return s=s||i.Z.agentsOfConvo(t)[0],(0,o.h)("div",{class:"convo-list--item",onClick:()=>this.goToConvo(t.id),key:t.id},(0,o.h)(g,{plugin:this.props.plugin,store:this.props.store,mode:"member",class:"d-flex flex-row",tooltipPos:"right",agent_ids:s}),this.renderConvoSummary(t))}));let r=(0,o.h)("div",{class:"convo-list--list"},s);return 0===i.Z.size(e)&&(r=(0,o.h)("div",{class:"convo-list--list"},(0,o.h)("div",{class:"empty-container"},(0,o.h)("img",{alt:"empty",src:vt}),(0,o.h)("div",{class:"empty-desc"},this.props.t("empty_convo"))))),(0,o.h)("div",{class:"convo-list"},(0,o.h)("div",{class:"convo-list--container"},(0,o.h)("div",{class:"convo-list--title"},this.props.t("conversations")),r),(0,o.h)("div",{class:"convo-list--footer"},(0,o.h)("button",{class:"btn--start-convo",onClick:t=>this.goToConvo("")},(0,o.h)("span",null,this.props.t("start_conversation")),(0,o.h)("img",{src:mt,alt:"send button",width:"26",height:"26"})),(0,o.h)(m,{store:this.props.store})))}blur(){if(!this.props.store.isPreview){var t=this.msgInput;t&&(setTimeout((()=>t&&t.blur())),setTimeout((()=>t&&t.blur()),300))}}focusInput(){if(!this.props.store.isPreview){if(this.shouldShowForm()){let t="";return i.Z.map(this.state.formData,((e,s)=>{"text"===e.type&&(t||e.value||(t=s))})),void setTimeout((()=>{var e=this["form_"+bt(t)];e&&e.focus()}),300)}var t=this.msgInput;t&&(setTimeout((()=>t.focus())),setTimeout((()=>t.focus()),300))}}onRate(t){this.props.cid&&(this.props.store.sendConvoEvent(this.props.cid,"conversation_rated",{conversation:{ratings:[t]}}),this.focusInput())}async sendMessage(t){let e=t.text;if(!this.props.cid){this.creating=!0;const{convo:s,error:i}=await this.props.store.startConvo({locale:this.props.t.locale(),message:e,initial_by:this.props.store.matchUser().id});return this.creating=!1,this.props.store.sendConvoEvent(s.id,"message_sent",{message:t}),void this.props.onGo({view:"chat",cid:s.id})}this.props.store.sendConvoEvent(this.props.cid,"message_sent",{message:t})}createPostback(t){this.props.store.createPostback(this.props.cid,t)}renderChat(){let t=(0,o.h)(_,{store:this.props.store,ref:t=>this.msgInput=t,cid:this.props.cid,onSend:t=>this.sendMessage(t),t:this.props.t}),e=this.props.store.matchConvo(this.props.cid)||{};return(this.isFormRequired()||"ended"===e.state)&&(t=(0,o.h)("div",{class:"message-input message-input--preform"},(0,o.h)("button",{class:"btn--start-convo",onClick:t=>this.onStartConvoClick(t)},this.props.t("offline_preform_btn")))),(0,o.h)("div",{class:"widget-body"},(0,o.h)("div",{class:"widget-body--content",onClick:t=>this.onContainerClick(t)},(0,o.h)(Y,{isShow:this.props.isShow,onLink:this.onLink,store:this.props.store,onFormSubmit:t=>this.onEventFormSubmit(t),ref:t=>this.events=t,cid:this.props.cid,creating:this.creating,onSend:t=>this.sendMessage(t),onPostback:t=>this.createPostback(t),t:this.props.t}),(0,o.h)(N,{store:this.props.store,cid:this.props.cid,t:this.props.t})),(0,o.h)(Q,{forceView:this.props.view,plugin:this.props.plugin,store:this.props.store,onRate:t=>this.onRate(t),cid:this.props.cid,t:this.props.t}),(0,o.h)(ct,{forceView:this.props.view,plugin:this.props.plugin,show:this.state.showOrder,order_id:this.state.order_id,store:this.props.store,onClose:this.closeOrder,cid:this.props.cid,t:this.props.t}),t)}async onStartConvoClick(){if("ended"===(this.props.store.matchConvo(this.props.cid)||{}).state)return this.props.onGo({view:"chat",cid:""});this.setState({clickedJoin:!0})}onEventFormSubmit(){this.focusInput()}onContainerClick(){window.getSelection().toString().length>0||this.props.store.isMobile()||this.focusInput()}isFormRequired(){let t,e=this.props.plugin.chatbox||{},s=this.props.store.matchAccount()||{};i.Z.get(e,"prechat_form.enabled")&&(t=e.prechat_form);let r=i.Z.get(e,"offline_form.enabled");if(this.isOffline(s,e)&&r&&(t=e.offline_form),!t)return!1;let o=this.fillForm(t),a=this.props.store.matchConvo(this.props.cid)||{};return"ended"===a.state||!this.userHasSent(this.props.cid)&&(a.state&&"pending"!==a.state&&delete o.group,!!i.Z.find(o,(t=>null==t.value||""===t.value)))}renderConvoSummary(t){let e=this.props.store.matchAgent("*"),s=i.Z.filter(t.members,(t=>("agent"===t.type||"bot"===t.type)&&"active"===t.membership)),r=i.Z.map(s,(t=>t.id));r=r||i.Z.agentsOfConvo(t)[0];let a=i.Z.map(r,(t=>e[t]||{avatar_url:ft,fullname:"Offline Agent"}));var n=i.Z.each(a,(t=>t.fullname)).join(", ");n||(n=this.props.store.matchAccount().name),n||(n=this.props.t("agent"));var h=null;"user"===t.lastSenderType&&(h=(0,o.h)("span",{class:"yourmessage"},this.props.t("you"),":"));let l=i.Z.isConvoSeen(t,this.props.store.matchUser().id);var p=this.renderMessagePreview(t.last_message_sent||{data:{message:i.Z.get(t,"last_message")}}),d=i.Z.getMs(i.Z.get(t,"last_message_sent.created"))||i.Z.getMs(i.Z.get(t,"last_sent.created"))||i.Z.getMs(t.created),c=(0,o.h)(T,{ago:!0,time:d,key:d,short:!0});let u=l?null:(0,o.h)("div",{class:"convo-list--item-unread"});return"ended"===t.state&&(u=(0,o.h)("img",{alt:"conversation ended",class:"convo-list--convo-completed",src:gt,title:this.props.t("conversation_ended")})),(0,o.h)("div",{class:"convo-list--convo-last-info"},(0,o.h)("div",{class:"d-flex flex-row"},(0,o.h)("div",{class:"convo-list--convo-name"},n),(0,o.h)("div",{class:"convo-list--convo-time"},c)),(0,o.h)("div",{class:"d-flex flex-row"},(0,o.h)("div",{class:"convo-list--convo-last-message"},h,p),u))}agentsOfConvo(t){let e=this.props.store.matchAgent("*");var s=i.Z.agentsOfConvo(t,!0);return i.Z.map(s,(t=>e[t]||{avatar_url:ft,fullname:"Offline Agent"}))}renderMessagePreview(t){let e=this.props.t("sent_you_a_message"),s=i.Z.get(t,"data.message.text");if("plaintext"!==i.Z.get(t,"data.message.format")&&(s=e),!s&&i.Z.size(i.Z.get(t,"data.message.attachments"))>0&&(s=e),!s)return null;let r=i.Z.get(t,"by.type");return(0,o.h)("div",{class:"convo-list--convo-last-mes"},i.Z.map(i.Z.extractText(s),(t=>"emoji"===t.type?(0,o.h)(a,{emojiCode:t.text,byType:r}):t.text)))}userHasSent(t){var e=this.props.store.matchConvo(t)||{};let s=this.props.store.matchUser();return!!this.userSent[t]||i.Z.find(e.members,(t=>t.id===s.id&&("active"===t.membership||t.last_sent>0)))}isOffline(t,e){let s=i.Z.get(e,"offline_form.enable_when"),r=!0;return"all_agents_offline"===s&&(r=t.is_online),"out_of_bussiness_hour"===s&&(r=t.is_in_business_hour),!r}updateFormDataFields(){let t,e=this.props.plugin.chatbox||{},s=this.props.store.matchAccount()||{};i.Z.get(e,"prechat_form.enabled")&&(t=e.prechat_form);let r=i.Z.get(e,"offline_form.enabled");if(this.isOffline(s,e)&&r&&(t=e.offline_form),"offline_form"===this.props.view&&(t=e.offline_form),"prechat_form"===this.props.view&&(t=e.prechat_form),0===i.Z.size(t))return[];var o={};i.Z.each(t.fields,(t=>{var e=Object.assign({},t);"list"===t.type&&(e.list=t.list),e.label=this.props.t.i18n(i.Z.get(t,"i18n_label",{}))||t.label,o["attr:"+t.key]=e})),t.group_required&&i.Z.size(t.groups)>0&&(o.group={key:"group",is_required:!!t.group_required,label:this.props.t.i18n(i.Z.get(t,"i18n_group_label",{}))||t.group_label,type:"group",list:i.Z.map(t.groups,(t=>({value:t.id,label:t.name})))}),o.question={key:"question",is_required:!0,label:this.props.t.i18n(i.Z.get(t,"i18n_question_label",{}))||t.question_label,type:"text"},this.isFormChanged(this.state.formData,o)&&this.setState({formData:o})}isFormChanged(t,e){let s=Object.keys(t),r=Object.keys(e);if(s.length!==r.length)return!0;for(let o=0;o<s.length;o++){if(i.Z.get(t,`${s[o]}.label`)!==i.Z.get(e,`${r[o]}.label`))return!0;if(i.Z.get(t,`${s[o]}.is_required`)!==i.Z.get(e,`${r[o]}.is_required`))return!0;if(i.Z.stringify(i.Z.get(t,`${s[o]}.list`))!==i.Z.stringify(i.Z.get(e,`${r[o]}.list`)))return!0}return!1}fillForm(t){if(0===i.Z.size(t))return[];var e={};let s=this.props.store.matchUser();return i.Z.each(t.fields,(t=>{var r=Object.assign({},t);r.value=i.Z.getUserAttr(s,t.key,t.type),"boolean"!==t.type||r.value||(r.value=!1),"datetime"===t.type&&r.value&&(r.value=new i.Z.Date(e.value).toLocaleDateString("en-CA")),"list"===t.type&&(r.list=t.list),r.label=this.props.t.i18n(i.Z.get(t,"i18n_label",{}))||t.label,e["attr:"+t.key]=r})),t.group_required&&i.Z.size(t.groups)>0&&(e.group={key:"group",is_required:!!t.group_required,label:this.props.t.i18n(i.Z.get(t,"i18n_group_label",{}))||t.group_label,type:"group",list:i.Z.map(t.groups,(t=>({value:t.id,label:t.name})))}),e}}class yt extends r.up{componentDidMount(){this.props.onMount(this.props.form)}}function bt(t){return encodeURIComponent(t)}let wt=s.e(178).then(s.bind(s,178));class kt extends r.up{constructor(t){super(t),this.refButton=(0,o.Vf)()}async refreshCSS(){let t=this.props.store.matchPlugin();if(!i.Z.find(t,(t=>t.id===this.props.plugin.id)))return;let e=(await wt).default.default.toString();var s=i.Z.replaceCssVariable(e,this.props.plugin.chatbox);i.Z.setCss(this.props.plugin.id,this.$cssStyleDiv,s)}componentWillUnmount(){i.Z.setCss(this.props.plugin.id,this.$cssStyleDiv,"")}async componentDidMount(){if(this.$cssStyleDiv=document.getElementById("subiz-style-for-"+this.props.plugin.id),this.$cssStyleDiv||(this.$cssStyleDiv=document.createElement("style"),document.head.appendChild(this.$cssStyleDiv),this.$cssStyleDiv.type="text/css",this.$cssStyleDiv.id="subiz-style-for-"+this.props.plugin.id),this.setState({cssready:!1,isShowWidget:!1,widgetView:"",widgetConvoId:""}),this.checkExpand(),this.props.store.onResetCSS(this,(()=>this.refreshCSS())),this.props.store.onConvoEvent(this,(t=>this.checkExpand())),this.props.store.onUpdate(this,(t=>this.checkExpand())),await this.refreshCSS(),this.setState({cssready:!0}),this.props.store.matchIsOpen()&&this.props.store.matchLastview().view){if(this.props.store.isMobile())return;this.showWidget(Object.assign({},this.props.store.matchLastview().opts,{view:this.props.store.matchLastview().view}))}else Zt(),this.state.isShowWidget||this.hideWidget()}render(){if(!this.state.cssready)return null;if(i.Z.isUserBanned(this.props.store.matchUser()))return null;if(!this.props.t)return null;var t=this.props.store.isMobile()?"mobile":"desktop";return(0,o.h)("div",{class:t},(0,o.h)(l,{plugin:this.props.plugin,store:this.props.store,key:"chat_button",ref:this.refButton,isShow:!this.state.isShowWidget,onClick:t=>this.showWidget(t),t:this.props.t}),(0,o.h)(_t,{plugin:this.props.plugin,store:this.props.store,view:this.state.widgetView,cid:this.state.widgetConvoId,isShow:this.state.isShowWidget,onClose:t=>this.onWidgetClose(t),onGo:t=>this.showWidget(t),t:this.props.t}))}checkExpand(){if(this.props.store.isMobile())return;if(this.props.plugin._no_auto_expand)return;if(this.props.store.matchHasManuallyClosed())return;let t=this.props.store.matchConvo("*"),e=i.Z.find(t,(t=>!i.Z.isConvoSeen(t,this.props.store.matchUser().id)));e&&e.id&&(this.state.isShowWidget||this.showWidget({view:"chat",cid:e.id}))}getCurrentView(){return{is_show_widget:this.state.isShowWidget,conversation_id:this.state.widgetConvoId,view:this.state.widgetView}}async showWidget(t){if(this.refButton.current&&this.refButton.current.ClearPreview(),!t.view){let e=this.props.store.matchLastview()||{};t.view=i.Z.get(e,"view"),t.cid=i.Z.get(e,"opts.cid")}t=t||{},this.props.store.isMobile()&&function(){document.body&&document.body.classList&&document.body.classList.add("sbz_no_scroll");let t=document.createElement("meta");t.httpEquiv="X-UA-Compatible",t.name="viewport",t.id="subiz-meta-viewport",t.content="maximum-scale=1.0, user-scalable=no, width=device-width, initial-scale=1.0",document.getElementsByTagName("head")[0].appendChild(t)}(),this.setState({widgetConvoId:t.cid,widgetView:t.view}),this.props.store.setIsOpen(!0),this.forceUpdate(),this.setState({isShowWidget:!0}),this.props.store.setLastview(t.view,{cid:t.cid})}showGreeting(){this.refButton.current&&this.refButton.current.ShowGreeting()}hideGreeting(){this.refButton.current&&this.refButton.current.HideGreeting()}hideWidget(){Zt(),this.props.store.setIsOpen(!1),this.setState({isShowWidget:!1})}onWidgetClose(){this.refButton.current&&this.refButton.current.ClearPreview(),this.props.store.setHasManuallyClosed(),this.hideWidget()}}function Zt(){document.body&&document.body.classList&&document.body.classList.remove("sbz_no_scroll");let t=document.getElementById("subiz-meta-viewport");t&&t.remove()}},6755:(t,e,s)=>{t.exports=s.p+"assets/img/bubble_default.7d5e4ab.svg"},8712:(t,e,s)=>{t.exports=s.p+"assets/img/caret.998eb8f.svg"},6188:(t,e,s)=>{t.exports=s.p+"assets/img/convos_empty.2353007.svg"},9270:(t,e,s)=>{t.exports=s.p+"assets/img/default.06e6ee0.jpg"},4761:(t,e,s)=>{t.exports=s.p+"assets/img/default_avatar.5b74dc1.png"},8909:(t,e,s)=>{t.exports=s.p+"assets/img/done_gray.d7e8203.svg"},763:(t,e,s)=>{t.exports=s.p+"assets/img/done_green.b817fd4.svg"},29:(t,e,s)=>{t.exports=s.p+"assets/img/empty.29bed2d.svg"},6825:(t,e,s)=>{t.exports=s.p+"assets/img/empty_1.0b98af0.svg"},8453:(t,e,s)=>{t.exports=s.p+"assets/img/external-link.90577cc.svg"},1473:(t,e,s)=>{t.exports=s.p+"assets/img/ghn.070f8e3.svg"},6890:(t,e,s)=>{t.exports=s.p+"assets/img/ghtk.326eac1.svg"},9895:(t,e,s)=>{t.exports=s.p+"assets/img/image_default.be0698b.png"},9256:(t,e,s)=>{t.exports=s.p+"assets/img/info.ebce7ea.svg"},5770:(t,e,s)=>{t.exports=s.p+"assets/img/loader.37000a7.svg"},6484:(t,e,s)=>{t.exports=s.p+"assets/img/loading_static.8f403ae.svg"},6071:(t,e,s)=>{t.exports=s.p+"assets/img/not_found_search.2ddb8d1.png"},25:(t,e,s)=>{t.exports=s.p+"assets/img/package.8d37d0f.svg"},1216:(t,e,s)=>{t.exports=s.p+"assets/img/package_fade.763c001.svg"},6535:(t,e,s)=>{t.exports=s.p+"assets/img/rating--average.1ea492c.svg"},3824:(t,e,s)=>{t.exports=s.p+"assets/img/rating--great.e3d712e.svg"},8367:(t,e,s)=>{t.exports=s.p+"assets/img/rating--poor.2938a25.svg"},636:(t,e,s)=>{t.exports=s.p+"assets/img/search.f9705ff.svg"},9737:(t,e,s)=>{t.exports=s.p+"assets/img/send.6db52a9.svg"},6180:(t,e,s)=>{t.exports=s.p+"assets/img/shop.f7dc7d8.svg"},750:(t,e,s)=>{t.exports=s.p+"assets/img/shop_faded.df7845a.svg"},8430:(t,e,s)=>{t.exports=s.p+"assets/img/subiz-mono.877e9f5.svg"},2514:(t,e,s)=>{t.exports=s.p+"assets/img/x.26fdfa3.svg"}}]);
File without changes