1"use strict";!function(e){function t(t){return!!e(t).sbLoading()||(e(t).sbLoading(!0),!1)}function i(e,t=G){return se.storage(e,t)}function s(e){return se.translate(e)}function a(e=-1){if(-1===e)return window.sb_current_user;window.sb_current_user=e}function n(){let e=$?SB_ADMIN_SETTINGS.sound.volume:O.sound.volume;le.audio&&e&&(le.audio.volume=e)}function o(){(r=e(".sb-admin, .sb-chat, .sb-tickets")).length&&typeof SB_AJAX_URL!=G?(u=r.find(".sb-list").eq(0),h=r.find(".sb-editor"),p=h.find("textarea"),v=r.find($||E?".sb-list":"> div > .sb-scroll-area"),g=v.find(".sb-header"),m=h.find(".sb-emoji"),b=r.find(".sb-overlay-panel"),f=E?r.find(".sb-profile-agent .sb-status"):null,le.enabledAutoExpand(),le.audio=r.find("#sb-audio").get(0),le.label_date=r.find(".sb-label-date-top"),se.cookie("sb-check","ok",1,"set"),"ok"!=se.cookie("sb-check")?(z=!1,console.warn("Support Board: cookies not available.")):se.cookie("sb-check",!1,!1,!1),$?(n(),se.event("SBReady")):se.ajax({function:"get-front-settings",tickets:E,popup:!i("popup")&&!E},t=>{if(O=t,typeof SB_LOCAL_SETTINGS!=G&&e.extend(O,SB_LOCAL_SETTINGS),_=O.bot_id,y=O.dialogflow_human_takeover,F=O.agents_online,ae.active=O.pusher,O.language&&(SB_LANG="auto"!=O.language?[O.language,"front"]:!(!ee||"en"==Shopify.locale)&&Shopify.locale),typeof SB_REGISTRATION_REQUIRED!=G&&(O.registration_required=SB_REGISTRATION_REQUIRED,O.tickets_registration_required=SB_REGISTRATION_REQUIRED),typeof SB_ARTICLES_PAGE!=G&&SB_ARTICLES_PAGE&&(le.automations.runAll(),le.initArticlesPage()),typeof SB_ARTICLE_ID!=G&&le.initSingleArticlePage(),E&&O.tickets_manual_init||(!E||O.tickets_manual_init)&&(O.chat_manual_init||O.disable_offline&&!F||O.disable_office_hours&&!O.office_hours||O.chat_login_init&&!ue.login())||le.initChat(),O.cron&&setTimeout(function(){se.ajax({function:"cron-jobs"})},1e4),O.cron_email_piping&&setTimeout(function(){se.ajax({function:"email-piping"})},8e3),O.push_notifications_users&&se.serviceWorker.init(),E&&(O.tickets_default_department&&(le.default_department=O.tickets_default_department),O.dialogflow_disable_tickets&&(O.open_ai_active=!1)),ue.is("martfury")){let e=!1;setInterval(function(){if(a()){let t=se.cookie("XSRF-TOKEN");t&&t!=e&&(se.ajax({function:"martfury-session"}),e=t)}},3e3)}ee&&(ue.shopify.startCartSynchronization(),r.addClass("sb-shopify")),n(),ue.aecommerce.cart(),setTimeout(()=>{se.event("SBReady")},500)}),e(h).on("keydown","textarea",function(e){if(e)return 13!=e.which||E&&!O.tickets_enter_button||P||e.ctrlKey||e.shiftKey?void($&&13==e.which&&e.ctrlKey&&le.insertText("\n")):(le.submit(),e.preventDefault,!1)}),e(r).on("keydown",".sb-dashboard-articles input",function(t){13==t.which&&e(this).next().click()}),typeof SB_DEFAULT_DEPARTMENT!==G&&(le.default_department=SB_DEFAULT_DEPARTMENT),typeof SB_DEFAULT_AGENT!==G&&(le.default_agent=SB_DEFAULT_AGENT),typeof SB_DEFAULT_TAGS!==G&&(le.default_tags=SB_DEFAULT_TAGS),se.storage("call-active")&&($?SBAdmin.conversations.active_calls[se.storage("call-active")[0]]=se.storage("call-active")[1]:ie=se.storage("call-active")[1],se.call.decline(!0,se.storage("call-active")[0],()=>{setTimeout(()=>{$?SBAdmin.conversations.update():le.update()},1e3)}),se.storage("call-active",!1))):se.event("SBReady"),document.onpaste=function(e){let t=e.clipboardData.items[0];if(0===t.type.indexOf("image")){var i=new FileReader;i.onload=function(e){let t=e.target.result.split(","),i=t[0].indexOf("base64")>=0?atob(t[1]):decodeURI(t[1]),s=new Uint8Array(i.length);for(let e=0;e<i.length;e++)s[e]=i.charCodeAt(e);let a=new FormData;a.append("file",new Blob([s],{type:t[0].split(":")[1].split(";")[0]}),"image_print.jpg"),se.upload(a,function(e){le.uploadResponse(e)})},i.readAsDataURL(t.getAsFile())}},document.addEventListener("visibilitychange",function(){se.visibilityChange(document.visibilityState)},!1),e(r).on("click",function(){le.tab_active||se.visibilityChange()}),l=r,$&&(r=r.find(".sb-conversation")),B=l.find("#sb-call-bar"),e(v).on("scroll",function(){let t=v.scrollTop(),i=M.length;if(le.scrollHeader(),!le.label_date_show&&i&&M[i-1].getBoundingClientRect().top>u[0].getBoundingClientRect().top+u.outerHeight()&&(le.label_date_show=!0,i>1&&le.label_date.html(e(M[i-2]).html())),le.label_date_show&&(le.label_date.sbActive(!0),clearTimeout(D[0]),D[0]=setTimeout(()=>{le.label_date.sbActive(!1)},1500)),i)if(le.isBottom())le.label_date.html(e(M[i-1]).html()),le.label_date_show=M.length&&M[M.length-1].getBoundingClientRect().top<0;else{let a=le.label_date[0].getBoundingClientRect().top;for(var s=0;s<i;s++){let i=M[s].getBoundingClientRect().top;if(i-100<a&&i+100>a){let i=e(M[N[0]>t&&s>0?s-1:s]).html();i!=N[1]&&(le.label_date.html(i),N[1]=i);break}}}N[0]=t}),e(u).on("click",".sb-menu-btn",function(){let t=e(this).parent().find(".sb-menu"),i=e(t).sbActive();se.deactivateAll(),i||(e(t).sbActive(!0),se.deselectAll(),$&&(SBAdmin.open_popup=t))}),P&&(e(h).on("click",".sb-textarea",function(){r.addClass("sb-header-hidden"),e(this).find("textarea").get(0).focus(),le.isBottom()&&(le.scrollBottom(),setTimeout(()=>{le.scrollBottom()},200))}),e(h).on("focusout",".sb-textarea",function(){setTimeout(()=>{r.removeClass("sb-header-hidden")},300)}),e(h).on("click",".sb-submit",function(){p.blur()}),window.addEventListener("popstate",function(){le.chat_open&&le.open(!1)})),e(u).on("click",".sb-menu li",function(){e(this).parent().sbActive(!1)}),e(h).on("click",".sb-submit",function(){le.submit()}),e(h).on("click",".sb-clear-text",function(){p.val("").trigger("change").focus(),h.find(".sb-attachments").html(""),h.sbActive(!1)}),e("body").on("click",".sb-chat-btn,.sb-responsive-close-btn, #sb-open-chat, .
1sb-open-chat",function(){le.open(!le.chat_open)}),e(r).on("click",".sb-dashboard-btn",function(){le.showDashboard(),v.find(" > .sb-panel-articles > .sb-article").length&&le.showArticles(),i("open-conversation",0),q=!1}),e(r).on("click",".sb-user-conversations li",function(){le.openConversation(e(this).attr("data-conversation-id"))}),e(r).on("click",".sb-btn-new-conversation, .sb-departments-list > div, .sb-agents-list > div",function(){let t=e(this).data("id"),i=!1;if(!se.null(t)){let n=e(this).parent().hasClass("sb-departments-list");if(n?le.default_department=parseInt(t):le.default_agent=parseInt(t),e(this).parent().data("force-one")){let e=a()?a().conversations:[];for(var s=0;s<e.length;s++)if(n&&e[s].get("department")==t||!n&&e[s].get("agent_id")==t){i=!0,le.openConversation(e[s].id);break}}}i||(q="new-conversation",le.clear(),le.hideDashboard())}),e(r).on("click",".sb-btn-all-conversations",function(){r.find(".sb-dashboard-conversations").removeClass("sb-conversations-hidden")}),e(h).on("click",".sb-btn-attachment",function(){le.is_busy||h.find(".sb-upload-files").val("").click()}),e(h).on("click",".sb-attachments > div > i",function(t){return e(this).parent().remove(),p.val()||0!=h.find(".sb-attachments > div").length||h.sbActive(!1),t.preventDefault(),!1}),e(h).on("change",".sb-upload-files",function(t){le.busy(!0),e(this).sbUploadFiles(function(e){le.uploadResponse(e)}),se.event("SBAttachments")}),e(h).on("dragover",function(t){e(this).addClass("sb-drag"),clearTimeout(R),t.preventDefault(),t.stopPropagation()}),e(h).on("dragleave",function(t){R=setTimeout(()=>{e(this).removeClass("sb-drag")},200),t.preventDefault(),t.stopPropagation()}),e(h).on("drop",function(t){let i=t.originalEvent.dataTransfer.files;if(t.preventDefault(),t.stopPropagation(),i.length>0)for(var s=0;s<i.length;++s){let e=new FormData;e.append("file",i[s]),se.upload(e,function(e){le.uploadResponse(e)})}return e(this).removeClass("sb-drag"),!1}),e(r).on("click",".sb-articles > div, .sb-btn-all-articles:not([onclick])",function(){e(this).hasClass("sb-btn-all-articles")?le.showArticles():(le.showArticles(e(this).attr("data-id"),e(this).attr("data-is-category")),P||le.resize())}),e(r).on("click",".sb-dashboard-articles .sb-input-btn .sb-submit-articles",function(){le.searchArticles(e(this).parent().find("input").val(),this,e(this).parent().next())}),e(l).on("click",".sb-article [data-rating]",function(){le.articleRatingOnClick(this)}),e(u).on("click",".sb-rich-button a",function(t){let i=e(this).attr("href");if(0===i.indexOf("#")&&0===i.indexOf("#article-"))return le.showArticles(i.replace("#article-","")),t.preventDefault(),!1}),e("body").on("keydown",".sb-articles-header input",function(t){13!=t.which||P||t.ctrlKey||t.shiftKey||e(this).next().click()}),e(l).on("click","#sb-call-answer",function(){t(this)||se.call.answer()}),e(l).on("click","#sb-call-decline",function(){t(this)||se.call.decline(B.hasClass("sb-call-active")||B.hasClass("sb-call-ringing"))}),e(l).on("click","#sb-call-mute",function(){let t=!e(this).hasClass("sb-btn-red");se.call.mute(!t),e(this).setClass("sb-btn-red",t)}),e(b).on("click","[data-rating]",function(){let i=b.find(">
1 div:last-child"),s=e(this).attr("data-rating"),n=le.conversation?le.conversation:a().getLastConversation(),o=n.getLastUserMessage(!1,!0);t(i),se.ajax({function:"set-rating",conversation_id:n.id,agent_id:!!o&&o.get("user_id"),user_id:a().id,message:i.find("textarea").val(),rating:"positive"==s?1:-1},()=>{b.attr("data-close-chat")&&le.closeChat(),le.update(),b.sbActive(!1),i.sbLoading(!1)})}),e(l).on("click",".sb-lightbox-media > i",function(){return l.find(".sb-lightbox-media").sbActive(!1),$&&(SBAdmin.open_popup=!1),!1}),e(r).on("click",".sb-image",function(){se.lightbox(e(this).html())}),e(r).on("click",".sb-slider-images .sb-card-img",function(){se.lightbox(`<img loading="lazy" src="${e(this).attr("data-value")}" />`)}),e(document).on("SBConversationLoaded",function(){i("queue")&&le.queue(i("queue"))}),e(h).on("click",".sb-btn-emoji",function(){le.showEmoji(this)}),e(m).on("click",".sb-emoji-list li",function(t){le.insertEmoji(e(this).html()),P&&clearTimeout(R)}),e(m).find(".sb-emoji-list").on("touchend",function(e){R=setTimeout(()=>{le.mouseWheelEmoji(e)},50)}),e(m).find(".sb-emoji-list").on("mousewheel DOMMouseScroll",function(e){le.mouseWheelEmoji(e)}),e(m).find(".sb-emoji-list").on("touchstart",function(e){le.emoji_options.touch=e.originalEvent.touches[0].clientY}),e(m).on("click",".sb-emoji-bar > div",function(){le.clickEmojiBar(this)}),e(m).on("click",".sb-select li",function(){le.categoryEmoji(e(this).data("value"))}),e(m).find(".sb-search-btn input").on("change keyup paste",function(){le.searchEmoji(e(this).val())}),e(p).on("keyup",function(){le.textareaChange(this)}),e(p).on("focus input click",function(){p.parent().parent().addClass("sb-focus")}),e(p).on("focusout",function(){p.parent().parent().removeClass("sb-focus")}),e(r).on("click",".sb-privacy .sb-approve",function(){i("privacy-approved",!0),e(this).closest(".sb-privacy").remove(),r.removeClass("sb-init-form-active"),g.find(" > div").css({opacity:1,top:0}),le.initChat(),E?SBTickets.showPanel(se.setting("tickets_disable_first")?"":"new-ticket"):le.isInitDashboard()||le.hideDashboard()}),e(r).on("click",".sb-privacy .sb-decline",function(){let t=e(this).closest(".sb-privacy");e(t).find(".sb-text").html(e(t).attr("data-decline")),e(t).find(".sb-decline").remove(),le.scrollBottom(!0)}),e(r).on("click",".sb-popup-message .sb-icon-close",function(){le.popup(!0)}),e(r).on("click",".sb-rich-message .sb-submit,.sb-rich-message:not(.sb-rich-registration) .sb-select ul li",function(){let t=e(this).closest(".sb-rich-message");t[0].hasAttribute("disabled")||ce.submit(t,t.attr("data-type"),this)}),e(r).on("click",".sb-rich-message .sb-input > span",function(){e(this).sbActive(!0),e(this).siblings().focus()}),e(r).on("focus focusout click",".sb-rich-message .sb-input input,.sb-rich-message .sb-input select",function(t){switch(t.type){case"focusin":case"focus":e(this).siblings().sbActive(!0);break;case"focusout":e(this).val()?e(this).siblings().addClass("sb-filled sb-active"):setTimeout(()=>{K||e(this).siblings().sbActive(!1)},100);break;case"click":e(this).siblings().removeClass("sb-filled")}}),e(r).on("click",".sb-input-select-input > div",function(){K=!0,setTimeout(()=>{K=!1},250)}),e(r).on("click",".sb-slider-arrow",function(){ce.sliderChange(e(this).closest("[id]").attr("id"),e(this).hasClass("sb-icon-arrow-right")?"right":"left")}),e(r).on("change",'.sb-rich-message [data-type="select"] select',function(){e(this).siblings().sbActive(!0)}),e(r).on("click",'[data-type="select-input"] > div',function(){e(this).prev().sbActive(!0),e(this).next().addClass("sb-focus")}),e(r).on("focusout",'[data-type="select-input"] input,[data-type="select-input"] select',function(){let t=e(this).closest(".sb-input");t.find("> input").val()+t.find("select").val()==""&&t.find("span").sbActive(!1),t.find(".sb-focus").removeClass("sb-focus")}),e(r).on("click",".sb-rich-message .sb-login-area",function(){let t=r.hasClass("sb-init-form-active");e(this).closest(".sb-rich-message").replaceWith(ce.generate({},"login",t?"sb-init-form":"")),le.scrollBottom(t)}),e(r).on("click",".sb-forgot-password",function(){let t=r.hasClass("sb-init-form-active");e(this).closest(".sb-rich-login").replaceWith(ce.generate({},"login-link",t?"sb-init-form":"")),le.scrollBottom(t)}),e(r).on("click",".sb-rich-login .sb-registration-area",function(){if(O.registration_link)document.location=O.registration_link;else{let t=r.hasClass("sb-init-form-active");e(this).closest(".sb-rich-login").replaceWith(ce.generate({},"registration",t?"sb-init-form":"")),le.scrollBottom(t)}}),e(r).on("click",".sb-rich-login .sb-submit-login",function(){se.loginForm(this,!1,t=>{let i=e(this).closest(".sb-rich-login");if(a(new ne(t[0])),i.hasClass("sb-init-form"))q="open-conversation",le.initChat(),ae.start(),le.isInitDashboard()||le.hideDashboard(),e(document).on("SBPopulateConversations",function(){r.removeClass("sb-init-form-active"),i.remove(),e(document).off("SBPopulateConversations")});else{i=i.closest("[data-id]");let e=le.conversation.getMessage(i.attr("data-id")),t=`${s("Logged in as")} *${a().name}*`;e.set("message",t),le.updateMessage(e.id,t),i.replaceWith(e.getCode()),ae.started=!1,ae.start()}})}),e(r).on("click",".sb-submit-login-link",function(){const i=e(this).closest(".sb-rich-login-link,.sb-panel"),s=i.find("input").val();s&&s.includes("@")&&s.includes(".")&&!t(this)&&se.ajax({function:"login-link",email:s,url:se.URL()},()=>{i.sbActive(!0)})}),e(u).on("click",".sb-social-buttons div",function(){se.openWindow(e(this).attr("data-link"))}),e(r).on("click",".sb-close-chat",function(){le.closeChat()}),P||e(r).on("click",".sb-enlarge-chat-widget",function(){le.resize(!r.hasClass("sb-chat-large"))}),e(u).on("click",'.sb-rich-woocommerce_button a, [href="#"].sb-card-btn',function(i){let s=se.settingsStringToArray(e(this).closest(".sb-rich-message").attr("data-settings")),a="checkout"==s["link-type"]||s.checkout,n=e(this)[0].hasAttribute("data-ids")?e(this).attr("data-ids").split(","):[s.id.split("|")[e(this).parent().index()]];if(n.length){if(t(this))return;ue.wordpress.ajax("button-purchase",{product_ids:n,checkout:a,coupon:s.coupon},t=>{a?document.location=t:e(this).addClass("sb-icon-check").sbLoading(!1)})}return i.preventDefault(),!1}),e(u).on("click","#sb-waiting-list .sb-submit",function(){0==e(this).index()&&setTimeout(()=>{ue.woocommerce.waitingList("submit")},1e3)}),e(document).on("SBNewEmailAddress",function(e,t){"sb-waiting-list-email"==t.id&&ue.woocommerce.waitingList("submit")}
1),e(u).on("click",".sb-player-btn",function(){se.audio.play(this)}),e(u).on("click",".sb-player-speed",function(){se.audio.speed(this)}),e(u).on("click",".sb-player-download",function(){se.audio.download(this)}),e(h).on("click",".sb-btn-audio-clip",function(){if((S=le.conversation&&"wa"==le.conversation.get("source"))&&typeof SBAudioRecorder===G)return e.getScript(SB_URL+"/vendor/lame.min.js",()=>{this.click()},!0);navigator.mediaDevices.getUserMedia({audio:!0}).then(t=>{S?SBAudioRecorder.init(t):(typeof SBAudioRecorder!=G&&SBAudioRecorder.close(),J=[],(C=new MediaRecorder(t)).addEventListener("dataavailable",e=>{J.push(e.data)})),A||(A=h.find("#sb-audio-clip"),k=A.find(".sb-audio-clip-time"),A.on("click",".sb-btn-mic",function(){let t=e(this).hasClass("sb-icon-pause");if(t)S?SBAudioRecorder.pause():C.stop();else{let e=A.find(".sb-btn-clip-player");e.hasClass("sb-icon-pause")&&e.click(),S?SBAudioRecorder.resume():C.start()}Y[2]=!t,A.find(".sb-icon-play").sbActive(t),e(this).removeClass("sb-icon-"+(t?"pause":"mic")).addClass("sb-icon-"+(t?"mic":"pause"))}),A.on("click",".sb-btn-clip-player",function(){let t=e(this).hasClass("sb-icon-pause");if(t)X[3].pause(),X[2]=!1;else if(X[3])X[3].play(),X[2]=!0;else{let t=new Audio(URL.createObjectURL(S?SBAudioRecorder.blob(!1):new Blob(J,{type:"audio/webm"})));k.html("0:00"),t.play(),t.onended=(()=>{X[0]=0,X[2]=!1,X[3]=!1,k.html("0:00"),e(this).removeClass("sb-icon-pause").addClass("sb-icon-play")}),X[0]=0,X[2]=!0,X[3]=t}e(this).removeClass("sb-icon-"+(t?"pause":"play")).addClass("sb-icon-"+(t?"play":"pause"))}),A.on("click",".sb-icon-close",function(){J=[],clearInterval(Y[1]),clearInterval(X[1]),A.sbActive(!1),h.sbActive(!1).removeClass("sb-audio-message-active"),S?SBAudioRecorder.pause():C.stop(),T.getTracks()[0].stop()})),k.html("0:00"),T=t,clearInterval(Y[1]),clearInterval(X[1]),Y=[0,setInterval(()=>{Y[2]&&(Y[0]++,k.html(se.getMinutesSeconds(Y[0])))},1e3),!0],X=[0,setInterval(()=>{X[2]&&(X[0]++,k.html(se.getMinutesSeconds(X[0])))},1e3),!1,!1],S||C.start(),A.find(".sb-btn-clip-player").removeClass("sb-icon-pause").addClass("sb-icon-play").sbActive(!1),A.find(".sb-icon-mic").removeClass("sb-icon-mic").addClass("sb-icon-pause"),A.sbActive(!0),p.val("").css("height",""),h.sbActive(!0).addClass("sb-audio-message-active")}).catch(e=>{alert(e)})}),e(u).on("click","[data-action].sb-rich-btn",function(t){return ce.iframe.load(e(this).attr("data-action"),e(this).attr("data-extra"),e(this).html(),e(this).closest("[data-id]").attr("data-id")),t.preventDefault(),!1}),e(b).on("click","> div:first-child i",function(){r.find(".sb-overlay-panel").sbActive(!1),b.attr("data-close-chat")&&le.closeChat()}),e(r).on("change input","#phone > input",function(){let t=e(this).val().trim();if(/^[0-9+]+$/.test(t)||(t=t.replace(/[^0-9+]/g,""),e(this).val(t)),t.length>1&&0===t.indexOf("+")){let i=!1;"+1"==t.substring(0,2)&&(i=t.substring(0,2)),t.length>3&&(i=t.substring(0,3)),i&&(e(this).parent().find(`[data-value="${i}"]`).click(),e(this).parent().find(".sb-select").click(),e(this).val(t.replace(i,"")))}}),e(l).on("click",".sb-search-btn > i",function(){let t=e(this).parent(),i=e(t).sbActive();i&&(setTimeout(()=>{e(t).find("input").val("")},50),setTimeout(()=>{e(t).find("input").trigger("change")},550)),e(t).sbActive(!i),e(t).find("input").get(0).focus(),l.find(".sb-select ul").sbActive(!1)}),e(l).on("click",".sb-select",function(t){if(!t.target||!e(t.target).is("input")){let t=e(this).find("ul"),i=t.hasClass("sb-active");e(l).find(".sb-select ul").sbActive(!1),t.setClass("sb-active",!i),e(this).find(".sb-select-search").setClass("sb-active",!i),$&&(SBAdmin.open_popup=!i&&this)}}),e(l).on("click",".sb-select li",function(){let t=e(this).closest(".sb-select"),i=e(this).data("value"),s=e(t).find(`[data-value="${i}"]`);t.find("li").sbActive(!1),t.find("p").attr("data-value",i).html(e(s).html()),s.sbActive(!0)}),e(l).on("input",".sb-select-search input",function(t){let i=e(this).val();se.search(i,()=>{let t=e(this).parent().parent().find("li");t.setClass("sb-hide",i.length),i.length&&(i=i.toLowerCase(),t.each(function(){(e(this).attr("data-value").includes(i)||e(this).attr("data-country").includes(i))&&e(this).removeClass("sb-hide")}))})}),e(l).on("click",".sb-input-image .image",function(){c=e(this).parent(),h.find(".sb-upload-files").click()}),e(l).on("click",".sb-input-image .image > .sb-icon-close",function(t){return se.ajax({function:"delete-file",path:e(this).parent().attr("data-value")}),e(this).parent().removeAttr("data-value").css("background-image",""),t.preventDefault(),!1})}var r,l,c,d,u,h,p,g,f,m,v,b,_,y,w,S,A,k,C,T,x,B,$=!1,E=!1,R=!1,I=!1,L=!1,j=[],M=!1,N=[9999999,""],D=[!1,!1],U=document.title,O={},P=e(window).width()<465,q="",F=!1,G="undefined",z=!0,W=6e4*(new Date).getTimezoneOffset(),V=!1,H=!1,J=[],Y=[0,!1],X=[0,!1],K=!1,Q=!1,Z=0,ee=typeof Shopify!==G,te=0,ie=!1;
1e.fn.extend({manualExpandTextarea:function(){var t=this[0];t.style.height="auto",t.style.maxHeight="25px",window.getComputedStyle(t),t.style.height=(t.scrollHeight>350?350:t.scrollHeight)+"px",t.style.maxHeight="",e(t).trigger("textareaChanged")},autoExpandTextarea:function(){var t=this[0];t.addEventListener("input",function(i){e(t).manualExpandTextarea()},!1)}}),function(){var e=[].slice;String.prototype.autoLink=function(){var t,i,s,a,n,o,r;return o=/(^||[\s\n]|<[A-Za-z]*\/?>)((?:https?|ftp):\/\/[\w\-\u0080-\uFFFF+&@#\/%?=()~_|!:,.;]*[\w\-\u0080-\uFFFF+&@#\/%=~_|])/gi,0<(n=1<=arguments.length?e.call(arguments,0):[]).length?(a=n[0],t=a.callback,s=function(){var e;for(i in e=[],a)r=a[i],"callback"!==i&&e.push(" "+i+"='"+r+"'");return e}().join(""),this.replace(o,function(e,i,a){return""+i+(("function"==typeof t?t(a):void 0)||"<a href='"+a+"'"+s+">"+a+"</a>")})):this.replace(o,"$1<a href='$2'>$2</a>")}}.call(this);var se={visibility_status:"visible",loop_prevention:!1,ajax:function(t,i=!1){w?(w[0].push(t),w[1].push(i)):(w=[[t],[i]],setTimeout(()=>{let s=w[1],n={"login-cookie":se.loginCookie(),current_url:window.location.href};a()&&(n.user_id=a().id),typeof SB_LANG!=G&&(n.language=SB_LANG),V&&(n.cloud=V),location.search.includes("debug")&&(n.debug=!0),e.ajax({method:"POST",url:SB_AJAX_URL,data:e.extend({function:"ajax_calls",calls:w[0]},n)}).done(e=>{let a;if(Array.isArray(e))a=e;else if("invalid-session"===e)setTimeout(()=>{se.reset()},1e3);else{if($&&SB_ADMIN_SETTINGS.cloud&&e.includes("no-credits")&&!e.includes('"value":"no-credits'))return SBCloud.creditsAlertQuota();try{a="string"==typeof e||e instanceof String?JSON.parse(e):e}catch(i){return void this.ajax_error(e,t)}}for(var n=0;n<a.length;n++){let e=a[n];if(Array.isArray(e)||e.includes('["error')||(e=a),"success"==e[0])(i=s[n])&&i(e[1]);else if(se.errorValidation(e))i&&i(e);else{if($&&("security-error"==e[1]&&setTimeout(()=>{se.reset()},1e3),SBAdmin.conversations.busy=!1),le.is_busy_update=!1,le.busy(!1),"login-data-error"==e[1]&&!this.loop_prevention)return;let i=JSON.parse(e);Array.isArray(i)&&"error"==i[0]&&i[2]&&i[3]?se.error(i[3],i[2]):se.error(JSON.stringify(e).replace(/\\/g,"").replace(/\"/g,"").replace(/\[/g,"").replace(/\]/g,"").replace("error,",""),t.function)}}}).fail((e,t,i)=>{i&&(this.ajax_error("HTTP CURL ERROR"),console.log(i))}),w=!1},100))},ajax_error:function(e,t=!1){$&&(SBAdmin.conversations.busy=!1,ue.dialogflow.smart_reply_busy=!1),ue.dialogflow.busy&&(ue.dialogflow.busy=!1,!$&&le.conversation&&(se.ajax({function:"open-ai-send-fallback-message",conversation_id:le.conversation.id}),le.typing(-1,"stop"))),le.is_busy_update=!1,le.busy(!1),console.log(e),se.error(e.length>500?e.substr(0,500)+"... Check the console for more details.":e,`SBF.ajax.${t?t.function:""}`)},cors:function(e="GET",t,i){let s=new XMLHttpRequest;if("withCredentials"in s)s.open(e,t,!0);else{if(typeof XDomainRequest==G)return!1;(s=new XDomainRequest).open(e,t)}s.onload=function(){i(s.responseText)},s.onerror=function(){return!1},s.send()},upload:function(e,t){V&&e.append("cloud",V),jQuery.ajax({url:SB_URL+"/include/upload.php",cache:!1,contentType:!1,processData:!1,data:e,type:"POST",success:function(e){t(e)}})},getFileType:function(e){let t=String(e).split("#")[0].split("?")[0].split("/").pop(),i=t.includes(".")?t.split(".").pop().toLowerCase():"";return/jpg|jpeg|png|gif|webp/.test(i)?"image":/mp3|ogg|wav|aac/.test(i)?"audio":/mp4|mkv|vob|3gp|webm/.test(i)?"video":"file"},getFileIcon:function(e){let t=e.split(".").pop().split("?")[0].toLowerCase(),i={audio:["mp3","wav","ogg","m4a"],video:["mp4","avi","mov","mkv","webm","wmv"],pdf:["pdf"],doc:["doc","docx","rtf","odt"],ppt:["ppt","pptx","key","odp"],xls:["xls","xlsx","csv","ods"],archive:["zip","rar","7z","tar","gz","bz2"],image:["jpg","jpeg","png","gif","bmp","webp","svg","tiff","heic","psd","ai"],text:["txt","log","md","json"]};for(let e in i)if(i[e].includes(t))return e;return"default"},UTC:function(e){return new Date(e).getTime()-W},null:function(e){return typeof e===G||null===e||"null"===e||!1===e||!(e.length>0||"number"==typeof e||typeof e.length==G)||e===G},deactivateAll:function(){l&&l.find(".sb-popup, .sb-tooltip, .sb-list .sb-menu, .sb-select ul").sbActive(!1)},deselectAll:function(){window.getSelection?window.getSelection().removeAllRanges():document.selection&&document.selection.empty()},getURL:function(e=!1,t=!1){if(t||(t=location.search),0==e){for(var i=t.split("?").pop().split("&"),s={},a=0;a<i.length;a++){var n=i[a].split("=");s[n[0]]=se.escape(n[1])}return s}return t.indexOf("?")>
10&&(t=t.substr(0,t.indexOf("?"))),se.escape(decodeURIComponent((new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(t)||[,""])[1].replace(/\+/g,"%20")||""))},URL:function(){let e=window.location.href;return e.includes("?")?e.substring(0,e.indexOf("?")):e},stringToSlug:function(e){let t={"à¸":"k","à¸":"kh","à¸":"kh","à¸":"kh","à¸
":"kh","à¸":"kh","à¸":"ng","à¸":"ch","à¸":"ch","à¸":"ch","à¸":"s","à¸":"ch","à¸":"y","à¸":"d","à¸":"t","à¸":"th","à¸":"th","à¸":"th","à¸":"n","à¸":"d","à¸":"t","à¸":"th","à¸":"th","à¸":"th","à¸":"n","à¸":"b","à¸":"p","à¸":"ph","à¸":"f","à¸":"ph","à¸":"f","ภ":"ph","ม":"m","ย":"y","ร":"r","ล":"l","ว":"w","ศ":"s","ษ":"s","ส":"s","ห":"h","ฬ":"l","à¸":"o","ฮ":"h","ะ":"a","ั":"a","า":"a","ำ":"am","ิ":"i","ี":"i","ึ":"ue","ื":"ue","ุ":"u","ู":"u","à¹":"e","à¹":"ae","à¹":"o","à¹":"ai","à¹":"ai","ا":"a","ب":"b","ت":"t","Ø«":"th","ج":"j","Ø":"h","Ø®":"kh","د":"d","ذ":"dh","ر":"r","ز":"z","س":"s","Ø´":"sh","ص":"s","ض":"d","Ø·":"t","ظ":"z","ع":"a","غ":"gh","Ù":"f","Ù":"q","Ù":"k","Ù":"l","Ù
":"m","Ù":"n","Ù":"h","Ù":"w","Ù":"y","ä½ ":"ni","好":"hao","ä¸":"shi","ç":"jie","æ":"wo","æ¯":"shi","ä¸":"zhong","å½":"guo","人":"ren","è°¢":"xie","å":"zai","è§":"jian"},i="åà áãäâèéëêìÃïîòóöôùúüûñç·/_,:;";e=e.trim().toLowerCase().split("").map(e=>t[e]||e).join("");for(var s=0,a=i.length;s<a;s++)e=e.replace(new RegExp(i.charAt(s),"g"),"aaaaaaeeeeiiiioooouuuunc------".charAt(s));return e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-+/,"").replace(/-+$/,"").replace(/ /g,"")},slugToString:function(e){return(e=e.replace(/_/g," ").replace(/-/g," ")).charAt(0).toUpperCase()+e.slice(1)},random:function(){let e="";for(var t=5;t>0;--t)e+="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(62*Math.random())];return e},isAgent:function(e){return"agent"==e||"admin"==e||"bot"==e},beautifyTime:function(e,t=!1,i=!1){let a;if("0000-00-00 00:00:00"==e)return"";if(e.indexOf("-")>0){let t=e.split(/[- :]/);a=new Date(t[0],t[1]-1,t[2],t[3],t[4],t[5])}else{let t=e.split(/[. :]/);a=new Date(t[2],t[1]-1,t[0],t[3],t[4],t[5])}let n=new Date,o=new Date(Date.UTC(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),a.getMinutes(),a.getSeconds())),r=(n-o)/864e5*(i?-1:1),l=[s("Sunday"),s("Monday"),s("Tuesday"),s("Wednesday"),s("Thursday"),s("Friday"),s("Saturday")],c=o.toLocaleTimeString(navigator.language,{hour:"2-digit",minute:"2-digit"});return"0"===c.charAt(0)&&(c.includes("PM")||c.includes("AM"))&&(c=c.substring(1)),r<1&&n.getDate()==o.getDate()?t?`<span>${s("Today")}</span> <span>${c}</span>`:`<span data-today>${c}</span>`:r<6?`<span>${l[o.getDay()]}</span>${t?` <span>${c}</span>`:""}`:`<span>${o.toLocaleDateString(void 0,{year:"2-digit",month:"2-digit",day:"2-digit"})}</span>${t?` <span>${c}</span>`:""}`},unix:function(e){let t=e.split(/[- :]/);return Date.UTC(t[0],t[1]-1,t[2],t[3],t[4],t[5])},getLocationTimeString:function(e,t){if(e.timezone){let i={};i.timezone=e.timezone.value,i.country=e.country?e.country.value:i.timezone.split("/")[0].replace(/_/g," "),i.city=e.city?e.city.value:i.timezone.split("/")[1].replace(/_/g," "),t(`${new Intl.DateTimeFormat(void 0,{timeZone:i.timezone,hour:"2-digit",minute:"2-digit"}).format(new Date)} ${s("in")} ${i.city?i.city:""}${i.country?", "+i.country:""}`)}},dateDB:function(e){return"now"==e?((e=(new Date).toISOString().replace("T"," ")).indexOf(".")>0&&(e=e.substr(0,e.indexOf("."))),e):`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()} ${e.getHours()}:${e.getMinutes()}:${e.getSeconds()}`},getMinutesSeconds:function(e){let t=Math.floor(e/60);return e-=60*t,(t||"0")+":"+(e<10?"0"+e:e)},convertUTCDateToLocalDate:function(e,t=0){return e=new Date(e),e=new Date(e.getTime()+36e5*t),new Date(e.getTime()+-1*W)},call:{rtc:!1,recorder:!1,mixed_stream:!1,local_stream:!1,answer:function(e=!1){ue.whatsapp.call.answer(e||le.conversation.id,e=>{B.find("#sb-call-answer").sbLoading(!1),e.success?this.startCall():se.error(JSON.stringify(e),"SBConversations.call.answer")})},decline:function(e=!1,t=!1,i=!1){ue.whatsapp.call.decline(t||le.conversation.id,e,e=>{B.find("#sb-call-decline").sbLoading(!1),B.sbActive(!1),this.end(),e.success?(clearInterval(x),B.removeClass("sb-call-active")):se.error(JSON.stringify(e),"SBConversations.call.decline"),i&&i(e)})},startCall:function(){te=0,clearInterval(x),B.addClass("sb-call-active"),x=setInterval(()=>{te++,B.find("#call-timer").html(se.getMinutesSeconds(te))},1e3),i("call-active",[le.conversation.id,$?SBAdmin.conversations.active_calls[le.conversation.id]:ie])},start:function(e,t,i){this.initRTC(()=>{"whatsapp"==e&&ue.whatsapp.call.start(this.rtc.localDescription.sdp,t,e=>{i&&i(e)})})},initRTC:function(e,t=!1){(async()=>{const i=[];this.rtc=new RTCPeerConnection(t?{}:{iceServers:[]}),this.audio_ctx=new AudioContext,this.destination=this.audio_ctx.createMediaStreamDestination(),this.mixed_stream=this.destination.stream,this.recorder=new MediaRecorder(this.mixed_stream,{mimeType:"audio/webm;codecs=opus"}),this.recorder.ondataavailable=(e=>{e.data.size&&i.push(e.data)}),this.recorder.onstop=(()=>{const e=new FormData,t=new Blob(i,{type:this.recorder.mimeType});if(B.hasClass("sb-call-ringing"))return;e.append("file",new File([t],`call_${le.conversation.id}_${Date.now()}.webm`));const s=new Audio;s.src=URL.createObjectURL(t),s.addEventListener("loadedmetadata",()=>{se.upload(e,e=>{"success"===(e=JSON.parse(e))[0]?setTimeout(()=>{se.ajax({function:"whatsapp-call-save-audio",conversation_id:le.conversation.id,audio_file_url:e[1],duration:s.duration})},1e3):se.error(e[1],"call.initRTC"),URL.revokeObjectURL(s.src)})})}),this.rtc.ontrack=(e=>{const t=e.streams[0],i=l.find("#sb-audio-call")[0];i.srcObject=t,i.autoplay=!0;this.audio_ctx.createMediaStreamSource(t).connect(this.destination)}),this.local_stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}}),this.audio_ctx.createMediaStreamSource(this.local_stream).connect(this.destination),this.local_stream.getTracks().forEac
1h(e=>{this.rtc.addTrack(e,this.local_stream)}),t&&await this.rtc.setRemoteDescription({type:"offer",sdp:t});const s=t?await this.rtc.createAnswer():await this.rtc.createOffer({offerToReceiveAudio:!0});await this.rtc.setLocalDescription(s),t||(this.rtc.onicecandidate=(()=>{}),await new Promise(e=>setTimeout(e,500))),"running"!==this.audio_ctx.state&&await this.audio_ctx.resume(),this.recorder.start(),this.stopRecording=(()=>{this.recorder&&"inactive"!==this.recorder.state&&this.recorder.stop()}),e(s)})()},show:function(e=!0,t=!1){B.removeClass("sb-call-active sb-call-ringing"),t&&B.addClass("sb-call-ringing"),setTimeout(()=>{B.sbActive(e)},300)},end:function(){this.recorder&&"inactive"!==this.recorder.state&&this.recorder.stop(),this.local_stream&&(this.local_stream.getTracks().forEach(e=>e.stop()),this.local_stream=null),this.mixed_stream&&(this.mixed_stream.getTracks().forEach(e=>e.stop()),this.mixed_stream=null),this.rtc&&(this.rtc.getSenders().forEach(e=>e.track&&e.track.stop()),this.rtc.getReceivers().forEach(e=>e.track&&e.track.stop()),this.rtc.close(),this.rtc=null);const e=l.find("#sb-audio-call")[0];e&&(e.srcObject=null,e.pause())},mute:function(e=!0){this.local_stream&&this.local_stream.getAudioTracks().forEach(t=>{t.enabled=!e})}},updateUsersActivity:function(e,t,i){ae.active?i($&&SB_ADMIN_SETTINGS.bot_id==t||!$&&O.bot_id==t?"online":ae.online_ids.includes(t)?"online":"offline"):se.ajax({function:"update-users-last-activity",user_id:e,return_user_id:t,check_slack:!$&&O.slack_active},e=>{i("online"===e?"online":"offline")})},search:function(e,t){(e=e.toLowerCase())!=d?(clearTimeout(R),R=setTimeout(function(){d=e,t()},1e3)):l.find(".sb-search-btn i").sbLoading(!1)},searchClear:function(t,i){e(t).next().val()&&(e(t).next().val(""),i())},error:function(e,t){let i=e.includes(t);if(!$||!SBAdmin.is_logout)throw e instanceof Error&&(e=e.message),"."==e[e.length-1]&&(e=e.slice(0,-1)),$&&(!e||t.includes("update-users-last-activity")||t.startsWith("security-error")||(SBAdmin.infoPanel(`<pre>${e.includes("]:")?"Error: "+e.substr(e.indexOf("]:")+2):e}. Check the console for more details.</pre>`,"info",!1,"error","",!0),l.find(".sb-lightbox-overlay").sbActive(!1)),ue.dialogflow.smart_reply_busy=!1),l.find(".sb-loading").sbLoading(!1),le.busy(!1),se.event("SBError",{message:e,function_name:t}),new Error(i?e:`Support Board Error [${t}]: ${e}.`)},errorValidation:function(e,t=!0){return Array.isArray(e)&&"validation-error"===e[0]&&(!0===t||e[1]==t)},loginForm:function(t,i=!1,a=!1,n=!0){if(!(t=e(t)).sbLoading()){i=!1===i?t.closest(".sb-rich-login"):e(i);let o=e.trim(i.find("#email input").val()),r=e.trim(i.find("#password input").val());o&&r?(se.ajax({function:"login",email:o,password:r},e=>{if(e&&Array.isArray(e)){if(!$&&this.isAgent(e[0].user_type))de.showErrorMessage(i,"You cannot sign in as an agent."),le.scrollBottom();else{let t=new ne(e[0]);t.set("conversation_id",!!le.conversation&&le.conversation.id),this.loginCookie(e[1]),this.event("SBLoginForm",t),a&&a(e)}"wp"==se.setting("wp-users-system")&&ue.wordpress.ajax("wp-login",{user:o,password:r})}else{if($&&ue.is("wordpress"))return ue.wordpress.ajax("wp-login-admin",{user:o,password:r},()=>{t.sbLoading(!1),n?this.loginForm(t,i,a,!1):i.find(".sb-info").html(s("ip-ban"===e?"Too many login attempts. Please retry again in a few hours.":"Invalid email or password.")).sbActive(!0)});i.find(".sb-info").html(s("ip-ban"===e?"Too many login attempts. Please retry again in a few hours.":"Invalid email or password.")).sbActive(!0),$||le.scrollBottom()}t.sbLoading(!1)}),i.find(".sb-info").html("").sbActive(!1),t.sbLoading(!0)):(i.find(".sb-info").html(s("Please insert email and password.")).sbActive(!0),le.scrollBottom())}},loginCookie:function(e=!1){if(!1===e)return this.cookie("sb-login")?this.cookie("sb-login"):i("login");O.cloud?i("login",e):this.cookie("sb-login",e,3650,"set")},login:function(e="",t="",i="",s="",a=!1){se.ajax({function:"login",email:e,password:t,user_id:i,token:s},e=>!(0==e||!Array.isArray(e))&&(this.loginCookie(e[1]),a&&a(e),!0))},logout:function(e=!0){le.stopRealTime(),this.cookie("sb-login","","",!1),this.cookie("sb-cloud","","",!1),i("open-conversation",""),i("login",""),le.conversations=!1,a(!1),typeof sb_beams_client!==G&&sb_beams_client.stop(),typeof SB_AJAX_URL!==G&&se.ajax({function:"logout"},()=>{se.event("SBLogout"),e&&setTimeout(()=>{location.reload()},500)})},activeUser:function(){return a()}
1,getActiveUser:function(e=!1,t){let s=ue.login(),n=se.getURL("token");!s&&(i("wp-login")||i("whmcs-login")||i("perfex-login")||i("aecommerce-login"))&&(this.cookie("sb-login","","","delete"),a(!1),i("login",""),i("wp-login",""),i("whmcs-login",""),i("perfex-login",""),i("aecommerce-login","")),n&&history.replaceState(null,"",se.URL()),se.ajax({function:"get-active-user",db:e,login_app:JSON.stringify(s),user_token:n},e=>{if(!e)return t(),!1;if(e.cookie&&se.loginCookie(e.cookie),e.user_type)if(!$&&se.isAgent(e.user_type)){let e="You are logged in as both agent and user. Logout or use another browser, Incognito or Private mode, to login as user. Force a logout by running the function SBF.reset() in the console.";i("double-login-alert")||(i("double-login-alert",!0),alert(e)),console.warn("Support Board: "+e),se.event("SBDoubleLoginError")}else a(new ne(e,e.phone?{phone:e.phone}:{})),ae.start(),s&&i(s[1]+"-login",!0),t(),se.event("SBActiveUserLoaded",e)})},reset:function(){let e=["sb-login","sb-cloud"];for(var t=0;t<e.length;t++)this.cookie(e[t],"",0,!1);try{localStorage.removeItem("support-board")}catch(e){}this.logout()},lightbox:function(t){let i=e($?l:r).find(".sb-lightbox-media");i.sbActive(!0).find(" > div").html(t),$&&(SBAdmin.open_popup=i)},storage:function(e,t=G){try{if(typeof localStorage==G)return!1}catch(e){return!1}let i=localStorage.getItem("support-board");if(i=null===i?{}:JSON.parse(i),t===G)return e in i&&i[e];t?i[e]=t:delete i[e],localStorage.setItem("support-board",JSON.stringify(i))},storageTime:function(e,t=!1){let s=new Date;if(!1!==t)return 0==i(e)||s.getTime()-i(e)>36e5*t&&(i(e,!1),!0);i(e,s.getTime())},cookie:function(e,t=!1,i=!1,s="get",a=!1){let n="https:"==location.protocol?"SameSite=None;Secure;":"",o=window[$?"SB_ADMIN_SETTINGS":"CHAT_SETTINGS"],r=o&&o.cookie_domain?"domain="+o.cookie_domain+";":"";if("get"==s){if(!z)return this.storage(e);let t=document.cookie.split(";");for(var l=0;l<t.length;l++){for(var c=t[l];" "==c.charAt(0);)c=c.substring(1);if(0==c.indexOf(e)){let t=c.substring(e.length+1,c.length);return!this.null(t)&&t}}return!1}if("set"==s)if(z){let s=new Date;s.setTime(s.getTime()+i*(a?1:86400)*1e3),document.cookie=e+"="+t+";expires="+s.toUTCString()+";path=/;"+n+r}else this.storage(e,t);else this.cookie(e)&&(z?document.cookie=e+"="+t+";expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;"+n+r:this.storage(e,""))},setting:function(e,t=-1){if(-1===t)return typeof O!==G&&e in O&&O[e];typeof O!==G&&(O[e]=t)},shortcode:function(e){return ce.shortcode(e)},event:function(t,i){e(document).trigger(t,i);let s=$?typeof SB_ADMIN_SETTINGS!==G&&SB_ADMIN_SETTINGS.webhooks:O.webhooks,a={SBGetUser:"get-user",SBSMSSent:"sms-sent",SBLoginForm:"login",SBRegistrationForm:"registration",SBUserDeleted:"user-deleted",SBNewMessagesReceived:"new-messages",SBNewConversationReceived:"new-conversation",SBSlackMessageSent:"slack-message-sent",SBMessageDeleted:"message-deleted",SBRichMessageSubmit:"rich-message",SBNewEmailAddress:"new-email-address"};if(s&&t in a){if(!0!==s&&(Array.isArray(s)||(s=s.replace(/ /g,"").split(",")),!s.includes(a[t])))return;se.ajax({function:"webhooks",function_name:t,parameters:i})}},translate:function(e){if(!$&&se.null(O)||$&&typeof SB_TRANSLATIONS===G)return e;let t=$?SB_TRANSLATIONS:O.translations;return t&&t[e]&&t[e]?t[e]:e},escape:function(e){return e?e.replace(/</gi,"<").replace(/javascript:|onclick|onerror|ontoggle|onmouseover|onload|oncontextmenu|ondblclick|onmousedown|onmouseenter|onmouseleave|onmousemove|onmouseout|onmouseup/gi,""):""},strip:function(e){e=e.replace("```","");let t=[/\*([^\**]+)\*/,/\__([^\____]+)\__/,/\~([^\~~]+)\~/,/\`([^\``]+)\`/];for(var i=0;i<2;i++)t.forEach(t=>{e=e.replace(t,e=>e.replace(/[\*\_\~\`]/g,""))});return e.replace(/\\,/g,",").replace(/\\:/g,":")},visibilityChange:function(e=""){this.visibility_status=e;let t=$&&typeof SBAdmin!==G;"hidden"==e?($||le.stopRealTime(),le.tab_active=!1,this.visibility_was_hidden=!0):(a()&&!$&&le.startRealTime(),le.tab_active=!0,clearInterval(L),clearInterval(le.audio_interval),le.conversation&&(le.conversation.updateMessagesStatus(),(le.chat_open||$)&&le.updateNotifications(le.conversation.id),t&&setTimeout(()=>{SBAdmin.conversations.notificationsCounterReset(le.conversation.id)},2e3)),t&&(Date.now()-(P?6e4:18e4)>
1Z&&(SBAdmin.conversations.update(),Z=Date.now()),P&&le.update()),document.title=U,this.serviceWorker.closeNotifications())},settingsStringToArray:function(e){if(this.null(e))return[];let t=[];e=e.split(",");for(var i=0;i<e.length;i++){let s=e[i].split(":");t[s[0]]="false"!=s[1]&&("true"==s[1]||s[1])}return t},openWindow:function(e,t=550,i=350){let s=screen.width/2-t/2,a=screen.height/2-i/2;return window.open(e,"targetWindow","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+t+",height="+i+", top="+a+", left="+s),!1},loadResource:function(e,t=!1,i=!1,s=!1){let a=document.createElement(t?"script":"link");if(e){let s="sb-"+se.stringToSlug(e.split("/").pop());if(document.getElementById(s))return void(i&&i());t?a.src=e:a.href=e,a.type=t?"text/javascript":"text/css",a.id=s}else a.innerHTML=s;i&&(a.onload=function(){i()}),t||(a.rel="stylesheet"),document.head.appendChild(a)},debounce:function(e,t,i=500){t in j||(j[t]=!0,e(),setTimeout(()=>{delete j[t]},i))},serviceWorker:{sw:!1,timeout:!1,init:function(){navigator.serviceWorker&&navigator.serviceWorker.register($||"undefined"!=typeof SB_CLOUD_SW?SB_URL.replace("/script","")+"/sw.js?v=3.9.1":O.push_notifications_url+"?v=3.9.1").then(e=>{e.update(),this.sw=e}).catch(function(e){console.warn(e)})},initPushNotifications:function(){$&&("pusher"==SB_ADMIN_SETTINGS.push_notifications_provider||"onesignal"!=SB_ADMIN_SETTINGS.push_notifications_provider)||!$&&("pusher"==O.push_notifications_provider||"pushalert"!=O.push_notifications_provider)?ae.initPushNotifications():e.getScript("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js",()=>{window.OneSignalDeferred=window.OneSignalDeferred||[],OneSignalDeferred.push(e=>{e.init({appId:SB_ADMIN_SETTINGS.push_notifications_id})}),OneSignalDeferred.push(e=>{e.User.PushSubscription.addEventListener("change",t=>{if(t.current.optedIn){let t=($&&SB_ADMIN_SETTINGS.cloud?SB_ADMIN_SETTINGS.cloud.cloud_user_id+"-":!$&&O.cloud?O.cloud.cloud_user_id+"-":"")+($?SB_ACTIVE_AGENT.id:a().id);1==t&&(t="SB-1"),e.User.addTag("user_type",$?"agents":"users"),e.login(t)}se.event("SBPushNotificationSubscription",t.current)})}),Q=!1})},closeNotifications:function(e=0){this.sw&&this.sw.getNotifications().then(t=>{if(t.length)for(let e=0;e<t.length;
1e+=1)t[e].close();else e<300&&"visible"==se.visibility_status&&setTimeout(()=>{this.closeNotifications(e+1)},10)})},pushNotification:function(e,t=!1){let i=$?SB_ACTIVE_AGENT.profile_image:a().image;se.ajax({function:"push-notification",title:$?SB_ACTIVE_AGENT.full_name:a().name,message:se.strip(e),icon:i.indexOf("user.svg")>0?O.notifications_icon:i,interests:t||le.getRecipientUserID(),conversation_id:!!le.conversation&&le.conversation.id},e=>e)}},beautifyAttachmentName:function(e){let t=e.indexOf("_");return-1!==t?e.substring(t+1):e},audio:{play:function(t,i=!1){let s=(t=e(t)).parent().find("audio").get(0),a=t.hasClass("sb-icon-play"),n=t.parent().find(".sb-player-time");e(i||u).find("audio").each(function(){e(this).get(0).pause(),e(this).unbind("ended"),e(this).parent().find(".sb-player-btn").removeClass("sb-icon-pause").addClass("sb-icon-play")}),a?(s.play(),t.removeClass("sb-icon-play")):s.pause(),e(s).unbind("ended"),e(s).bind("ended",()=>{t.removeClass("sb-icon-pause").addClass("sb-icon-play")}),t.addClass("sb-icon-"+(a?"pause":"play")),s.ontimeupdate&&(s.removeEventListener("timeupdate",s.ontimeupdate),s.removeEventListener("loadedmetadata",s.onloadedmetadata)),n&&(s.ontimeupdate=(()=>{n.find("span:first-child").html(se.getMinutesSeconds(s.currentTime.toFixed(0)))}),s.onloadedmetadata=(()=>{n.find("span:last-child").html(se.getMinutesSeconds(s.duration.toFixed(0)))}),s.addEventListener("timeupdate",s.ontimeupdate),s.addEventListener("timeupdate",s.onloadedmetadata))},speed:function(t){let i=e(t).parent();
1if(i.find(".sb-player-btn").hasClass("sb-icon-pause")){let s=e(t).find(".sb-player-speed-number"),a=parseFloat(s.html());(a+=.5)>2&&(a=1),i.find("audio").get(0).playbackRate=a,s.html(a)}},download:function(t){window.open(e(t).parent().find("audio source").attr("src"))}}},ae={channels:{},channels_presence:[],active:!1,pusher:!1,started:!1,pusher_beams:!1,initialized:!1,online_ids:[],beams_loaded:!1,init:function(t=!1){if(ae.active){if(this.pusher)return!t||t();if(!t)return;e(window).one("SBPusherInit",()=>{t()}),this.initialized=!0,typeof Pusher===G?e.getScript("https://js.pusher.com/8.2.0/pusher.min.js",()=>{window.Pusher=Pusher,this.init_2()},!0):this.init_2()}},init_2:function(){this.pusher=new Pusher($?SB_ADMIN_SETTINGS.pusher_key:O.pusher_key,{cluster:$?SB_ADMIN_SETTINGS.pusher_cluster:O.pusher_cluster,channelAuthorization:{endpoint:SB_URL+"/include/pusher.php",params:{login:se.loginCookie(),cloud_user_id:!!O.cloud&&O.cloud.cloud_user_id}}}),se.event("SBPusherInit")},initPushNotifications:function(){(a()||$)&&(this.beams_loaded?this.initPushNotifications_2():e.getScript("https://js.pusher.com/beams/2.0.0-beta.0/push-notifications-cdn.js",()=>{this.initPushNotifications_2()},!0))},initPushNotifications_2:function(){window.navigator.serviceWorker.ready.then(e=>{this.pusher_beams=new PusherPushNotifications.Client({instanceId:$?SB_ADMIN_SETTINGS.push_notifications_id:O.push_notifications_id,serviceWorkerRegistration:e}),se.serviceWorker.closeNotifications(),this.pusher_beams.start().then(()=>this.pusher_beams.setDeviceInterests($?[SB_ACTIVE_AGENT.id,"agents"]:[a().id,"users"])).catch(console.error),Q=!1})},start:function(){$||this.started||!a()||(this.active&&this.init(()=>{this.event("client-typing",e=>{e.user_id==le.agent_id&&le.conversation&&e.conversation_id==le.conversation.id&&(le.typing(-1,"start"),clearTimeout(I),I=setTimeout(()=>{le.typing(-1,"stop")},1e3))}),this.event("new-message",e=>{!(e&&a()&&e.conversation_id)||a().getConversationByID(e.conversation_id)&&le.conversation&&le.conversation.id==e.conversation_id?(e&&e.action&&["message_delete","message_update"].includes(e.action)&&(le.id_last_message_conversation=e.message_id-1),le.update()):le.updateConversations()}),this.presence(1,()=>{this.started=!0,le.automations.runAll()})}),O.push_notifications_users&&("pusher"!=O.push_notifications_provider&&"onesignal"==O.push_notifications_provider||(typeof Notification!=G&&"granted"==Notification.permission?this.initPushNotifications():Q=!0)))},subscribe:function(e,t=!1){if(!this.pusher)return this.init(()=>{this.subscribe(e,t)});e=this.cloudChannelRename(e);let i=this.pusher.subscribe(e);i.bind("pusher:subscription_error",e=>console.log(e)),i.bind("pusher:subscription_succeeded",()=>{this.channels[e]=i,t&&t()})},event:function(e,t,i="private-user-"+a().id){if(!this.pusher)return this.init(()=>{this.event(e,t,i)});let s=i;(i=this.cloudChannelRename(i))in this.channels?(this.channels[i].unbind(e),this.channels[i].bind(e,e=>{t(e)})):this.subscribe(s,()=>{this.event(e,t,s)})},trigger:function(e,t={},i="private-user-"+a().id){if(0==e.indexOf("client-"))return this.channels[this.cloudChannelRename(i)].trigger(e,t);se.ajax({function:"pusher-trigger",channel:i,event:e,data:t},e=>e)},presence:function(e=1,t){if(!this.pusher)return this.init(()=>{this.presence()});let i=this.pusher.subscribe(this.cloudChannelRename("presence-"+e));i.bind("pusher:subscription_succeeded",i=>{if(i.count>98)return this.subscribe(e+1);i.each(e=>{this.presenceCheck(e)&&this.online_ids.push(e.id)}),le.updateUsersActivity(),t&&t()}),i.bind("pusher:subscription_error",e=>console.log(e)),i.bind("pusher:member_added",e=>{this.presenceCheck(e)&&this.presenceAdd(e.id),$&&se.storageTime("online-user-notification-"+e.id,24)&&(SBAdmin.users.onlineUserNotification(e),se.storageTime("online-user-notification-"+e.id))}),i.bind("pusher:member_removed",e=>{this.presenceRemove(e.id)}),this.channels_presence.push(i),!$&&O.slack_active&&(this.event("add-user-presence",e=>{this.presenceAdd(e.agent_id)}),se.ajax({function:"slack-presence",list:!0},e=>{for(var t=0;t<e.length;t++)this.presenceAdd(e[t]);le.updateUsersActivity()}))},presenceCheck:function(e){let t=se.isAgent(e.info.user_type);return($&&!t||!$&&t)&&!this.online_ids.includes(e.id)},presenceAdd:function(e){typeof e==G||this.online_ids.includes(e)||(this.online_ids.push(e),this.presenceUpdateAdmin(e),le.updateUsersActivity(e))},presenceRemove:function(e){if(typeof e==G)return;let t=this.online_ids.indexOf(e);-1!==t?(this.online_ids.splice(t,1),this.presenceUpdateAdmin(e),le.updateUsersActivity()):$&&l.find(`.sb-conversation-busy[data-agent="${e}"]`).remove()},presenceUnsubscribe:function(){for(var e=0;e<this.channels_presence.length;
1e++)this.channels_presence[e].unsubscribe(this.cloudChannelRename("presence-"+(e+1)))},presenceUpdateAdmin:function(e){$&&(l.find(".sb-area-users.sb-active").length&&SBAdmin.users.update(),a()&&a().id==e&&SBAdmin.users.updateUsersActivity())},cloudChannelRename:function(e){return O.cloud||$&&SB_ADMIN_SETTINGS.cloud?e+"-"+($?SB_ADMIN_SETTINGS.cloud.cloud_user_id:O.cloud.cloud_user_id):e}};window.SBF=se,window.SBPusher=ae,window.sb_current_user=!1,e.fn.sbActive=function(t=-1){return-1===t?e(this).hasClass("sb-active"):(e(this).setClass("sb-active",t),this)},e.fn.sbLoading=function(t="check"){return"check"==t?e(this).hasClass("sb-loading"):(e(this).setClass("sb-loading",t),this)},e.fn.sbTogglePopup=function(t=!1){let i=!0;return $&&(SBAdmin.open_popup=!1),e(this).sbActive()?(e(this).sbActive(!1),l.removeClass("sb-popup-active"),i=!1):(l.addClass("sb-popup-active"),l.find(".sb-popup").sbActive(!1),t&&e(this).css("left",e(t).offset().left+15).sbActive(!0),$&&setTimeout(()=>{SBAdmin.open_popup=this},500),se.deselectAll()),i},e.fn.sbUploadFiles=function(t,i=!1){let a=e(this).prop("files");for(var n=!1===i?0:i;n<(!1===i?a.length:i+1);n++){let e=a[n],i=e.size/1048576,o=$?SB_ADMIN_SETTINGS.max_file_size:O.max_file_size;if(i>o){let e=s("Maximum upload size is {R}MB. File size: {R2}MB.").replace("{R}",o).replace("{R2}",i.toFixed(2));le.is_busy_update=!1,le.busy(!1),$?(SBAdmin.conversations.busy=!1,SBAdmin.infoPanel(e,"info")):alert(e)}let r=new FormData;r.append("file",e),se.upload(r,t)}e(this).value=""},e.fn.setProfile=function(t=!1,i=!1){return se.null(t)&&(t=a()?a().name:""),se.null(i)&&(i=a()?a().image:SB_URL+"/media/user.svg"),t&&e(this).removeClass("sb-profile-empty"),e(this).find("img").attr("src",i),e(this).find(".sb-name").html(t),this},e.fn.setClass=function(t,i=!0){return i?e(this).addClass(t):e(this).removeClass(t),this};class ne{constructor(e={},t={}){this.details=e,this.extra=t,this.conversations=[],this.processArray(e)}get id(){return this.get("id")?this.get("id"):this.get("user_id")}get type(){return this.get("user_type")}get email(){return this.get("email")}get name(){return this.details.first_name?this.details.first_name+(this.details.last_name?" "+this.details.last_name:""):""}get nameBeautified(){let e=$?SB_ADMIN_SETTINGS.visitor_default_name:O.visitor_default_name;return!e||this.details.last_name&&"#"!=this.details.last_name.charAt(0)?this.name:e}get image(){return this.get("profile_image")}get language(){let e=this.getExtra("language");return e||(e=this.getExtra("browser_language")),e?e.value.toLowerCase():""}get(e){return e in this.details&&!se.null(this.details[e])?this.details[e]:""}getExtra(e){return e in this.extra&&!se.null(this.extra[e])?this.extra[e]:""}set(e,t){this.details[e]=t}setExtra(e,t){this.extra[e]=t}processArray(e){if(e&&e.details){for(var t=0;t<e.details.length;t++)this.setExtra(e.details[t].slug,e.details[t]);delete e.details,this.details=e}}update(e){this.id?se.ajax({function:"get-user",user_id:this.id,extra:!0},t=>{this.processArray(t),e(t),se.event("SBGetUser",this)}):se.error("Missing user ID","SBUser.update")}getConversations(e=!1,t){this.id?se.ajax({function:"get-user-conversations",user_id:this.id,exclude_id:t,agent:se.isAgent(this.type)},t=>{if(!se.errorValidation(t)){let s=[];for(var i=0;i<t.length;i++)le.isConversationAllowed(t[i].source,t[i].conversation_status_code,t[i].payload)&&s.push(new re([new oe(t[i])],t[i]));this.conversations=s,e&&e(s)}}):se.error("Missing user ID","SBUser.getConversations")}getConversationsCode(e=!1){let t="",i=le.conversation?le.conversation.id:-1;e||(e=this.conversations);for(var s=0;s<e.length;s++)if(e[s]instanceof re){if(!$&&!le.isConversationAllowed(e[s].get("source"),e[s].status_code,!!e[s].getLastMessage()&&JSON.stringify(e[s].getLastMessage().payload())))continue;let n=0,o=i==e[s].id;if(!$&&!o)for(var a=0;a<le.notifications.length;a++)le.notifications[a][0]==e[s].id&&n++;t+=`<li ${o?'class="sb-active" ':""}data-conversation-status="${o?0:e[s].status_code}" data-conversation-id="${e[s].id}" data-department="${e[s].get("department")}">${e[s].getCode()}${n?'<span data-count="'+n+'">'+n+"</span>":""}</li>`}else se.error("Conversation not of type SBConversation","SBUser.getConversationsCode");return t}getFullConversation(e=!1,t=!1){!1!==e?se.ajax({function:"get-conversation",conversation_id:e},e=>{let i=[];if(e){if("agent-not-authorized"===e)return void(window.location.href=se.URL());for(var s=0;s<e.messages.length;
1s++)i.push(new oe(e.messages[s]))}t&&t(new re(i,!!e&&e.details))}):se.error("Missing conversation ID","SBUser.getFullConversation")}getConversationByID(e,t=!1){for(var i=0;i<this.conversations.length;i++)if(this.conversations[i].id==e)return t?i:this.conversations[i];return!1}addConversation(e){if(e instanceof re){let i=e.id,s=!0;for(var t=0;t<this.conversations.length;t++)if(this.conversations[t].id==i){this.conversations[t]=e,s=!1;break}return s&&this.conversations.unshift(e),s}se.error("Conversation not of type SBConversation","SBUser.addConversation")}removeConversation(e){let t=this.getConversationByID(e,!0);!1!==t&&this.conversations.splice(t,1)}getLastConversation(){if(this.isConversationsEmpty())return!1;for(var e in this.conversations){let t=this.conversations[e];if(le.isConversationAllowed(t.get("source"),t.status_code,JSON.stringify(t.getLastMessage().payload())))return t}}isConversationsEmpty(){if(!this.conversations.length)return!0;for(var e in this.conversations){let t=this.conversations[e];if(le.isConversationAllowed(t.get("source"),t.status_code,JSON.stringify(t.getLastMessage().payload())))return!1}return!0}isExtraEmpty(){return 0===Object.keys(this.extra).length&&this.extra.constructor===Object}delete(e){this.id?se.ajax({function:"delete-user",user_id:this.id},()=>(se.event("SBUserDeleted",this.id),e(),!0)):se.error("Missing user ID","SBUser.delete")}}window.SBUser=ne;class oe{constructor(e={}){this.details=Object.assign({},e);let t=["message_status_code","message_id","message_profile_image","message_first_name","message_last_name","message_user_id","message_user_type"],i=["source","extra","title","tags","agent_id","department","last_update_time","conversation_creation_time","conversation_id","conversation_status_code","conversation_user_id"];for(s=0;s<t.length;s++)e[t[s]]&&(this.details[t[s].replace("message_","")]=e[t[s]]),delete this.details[t[s]];this.details.first_name&&(this.details.full_name=this.details.first_name+(this.details.last_name?" "+this.details.last_name:"")),e.last_update_time&&(this.details.creation_time=e.last_update_time);for(var s=0;s<i.length;s++)delete this.details[i[s]];let a=this.get("payload");if(a){if("string"==typeof a)try{var n=JSON.parse(this.get("payload").replace("\\'","'"));a=n&&"object"==typeof n?n:{}}catch(e){a={}}}else a={};this.set("payload",a)}get id(){return this.get("id")}get attachments(){return se.null(this.details.attachments)?[]:JSON.parse(this.details.attachments)}get message(){return $?this.payload("translation")&&this.payload("translation-language")==SB_ADMIN_SETTINGS.active_agent_language?this.payload("translation"):this.payload("original-message-language")==SB_ADMIN_SETTINGS.active_agent_language?this.payload("original-message"):this.get("message"):this.get("message")}get(e){return e in this.details&&!se.null(this.details[e])?this.details[e]:""}set(e,t){this.details[e]=t}payload(e=!1,t=!1){let i=this.get("payload");if(!1!==e&&!1!==t)i[e]=t,this.set("payload",i);else if(!1!==e)return e in i?i[e]:!(!i.id||i.id!=e)&&i;return["boolean","string"].includes(typeof i)?[]:i}getCode(){let e=se.isAgent(this.details.user_type),t=this.message,i=this.attachments,a=this.payload("reply"),n=$?SBAdmin.conversations.messageMenu(e,t,!a&&!e&&(!le.conversation||["tg","fb","wa",""].includes(le.conversation.get("source")))):"",o="",r="",l=$&&SB_ADMIN_SETTINGS.show_profile_images||!$&&(e&&!O.hide_agents_thumb||!e&&O.display_users_thumb)?`<div class="sb-thumb"><img loading="lazy" src="${this.details.profile_image}"><div class="sb-tooltip"><div>${this.details.full_name}</div></div></div>`:"",c=($&&e||!$&&!e?"sb-right":"")+(l?" sb-thumb-active":""),d="",u=!$&&e&&O.sender_name||$&&"chat-admin"==SB_ADMIN_SETTINGS.sender_name?`<span class="sb-agent-name">${this.get("full_name")}</span>`:"",h=!!$&&this.payload("delivery_failed");if(!t&&!i.length){if($&&(t=SBAdmin.conversations.getInfoMessage(this)),!t)return"";c+=" sb-info-message"}if(a&&le.conversation&&le.conversation.getMessage(a)){a=le.conversation.getMessage(a);let e=se.isAgent(a.get("user_type")),t=a.message;t||(t='<div class="sb-message-attachments">
1',i.forEach(e=>{t+=`<a>${e[0]}</a>`}),t+="</div>"),a=`<div class="sb-reply-message${e?" sb-reply-agent":""}"><span>${e&&$||!e&&!$?s("You"):a.get("full_name")}</span> ${t}</div>`}else a="";if(e){let e=(t=(t=t.replace(/\n/g,"<br>")).replace(/`([\s\S]*?)`/g,e=>e.replace(/\[/g,"["))).match(/\[([^\[\]]*(?:\[[^\[\]]*\][^\[\]]*)*)\]/g)||[],i=!1,s=e.length;for(g=0;g<s;g++){let s=ce.shortcode(e[g]);if(s[0])if("action"==s[0])t=t.replace(e[g],"");else{let a=ce.generate(s[1],s[0]);a&&(t=t.replace(e[g],a),i=!0,d=`data-type="${s[0]}"`)}}i&&(c+=" sb-rich-cnt",s>1&&(d='data-type="multiple"'))}else if(t.includes("[rating ")){let e=ce.shortcode(t);t=ce.generate(e[1],e[0])}let p=t.includes("data-success")?[...t.matchAll(/data-success="([^"]*)"/g)].map(e=>e[1]):[];for(g=0;g<p.length;g++)t=t.replace(p[g],"{R"+g+"}");t=this.render(t);for(g=0;g<p.length;g++)t=t.replace("{R"+g+"}",p[g]);if(i.length){o='<div class="sb-message-attachments">';for(var g=0;g<i.length;g++){let e=i[g][1],s=e+i[g][0];if("image"==se.getFileType(s)){let t="";i[g].length>2&&(t=`width="${(t=i[g][2].split("|"))[0]}" style="aspect-ratio: ${t[0]} / ${t[1]}"`),r+=`<div class="sb-image${s.includes(".png")?" sb-image-png":e.includes("sticker_")?" sb-image-sticker":""}"><img loading="lazy" src="${e}" ${t}/></div>`}else"audio"==se.getFileType(s)||e.includes("voice_message")||e.includes("audioclip")?(($&&!SB_ADMIN_SETTINGS.speech_recognition||!$&&!O.speech_recognition)&&(t=""),o+=`<div class="sb-player"><div class="sb-player-btn sb-icon-play"></div><div class="sb-player-speed"><div class="sb-player-speed-number">1</div><div class="sb-icon-close"></div></div><div class="sb-player-download sb-icon-arrow-down"></div><audio><source src="${e}" type="audio/mpeg"></audio></div>`):e&&(o+=`<a rel="noopener" target="_blank" data-type="${se.getFileIcon(e)}" href="${e}">${se.beautifyAttachmentName(i[g][0])}</a>`)}o+="</div>"}let f=(h?SBAdmin.conversations.getDeliveryFailedMessage(h):"")+(u+t+r).trim();return f||o?`<div data-id="${this.details.id}" class="${c}" ${d}>${l}${a}<div class="sb-cnt"><div class="sb-message${r&&!t?" sb-message-media":""}"${h?' style="opacity:.7"':""}>${f}</div>${o}<div class="sb-time">${se.beautifyTime(this.details.creation_time,!0)}${$&&e&&2==this.details.status_code?'<i class="sb-icon-check"></i>':""}</div></div>${n}</div>`:""}render(t=!1){!1===t&&(t=""+this.details.message);let i=t.length,s=t.match(/```([\s\S]*?)```/g)||[];for(n=0;n<s.length;n++)t=t.replace(s[n],"[code-"+n+"]");if(t=t.replace(/(?:\r\n|\r|\n)/g,"<br>"),t=t.replace(/\*([^\**]+)\*/g,"<b>$1</b>"),t=t.replace(/__(.+?)__/g,"<i>$1</i>"),t=t.replace(/\~([^\~~]+)\~/g,"<del>$1</del>"),t=t.replace(/\`([^\``]+)\`/g,"<code>$1</code>"),((6==i||5==i)&&t.startsWith("&#x")||i<3&&t.match(/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/))&&(t=`<span class="emoji-large">${t}</span>`),t.includes("](http")){let e=t.split("[");t="";for(n=0;n<e.length;n++)e[n].includes("](http")&&(e[n]=e[n].substring(e[n].indexOf("](")+2,e[n].indexOf(")"))),t+=e[n]}t.includes("www.")&&(t=t.replaceAll("www.","https://www.").replaceAll("https://https:","https:").replaceAll("http://https:","http:"));let a=[['href="http',"[L1]"],['src="http',"[L2]"],['url("http',"[L3]"],["url('http","[L4]"],['extra="http',"[L5]"],['data-link="http',"[L6]"],['data-value="http',"[L7]"]];for(n=0;n<a.length;n++)t=t.replaceAll(a[n][0],a[n][1]);t.includes("http")&&(t=t.autoLink({target:"_blank",callback:function(e){return e.includes("#sb-")?`<a href="${e.split("#sb-")[0]}" target="_blank">${e.split("#sb-")[1].replaceAll("--"," ")}</a>`:null}}));for(n=0;n<a.length;n++)t=t.replaceAll(a[n][1],a[n][0]);for(var n=0;n<s.length;n++)t=t.replace("[code-"+n+"]","<pre>"+e.trim(e.trim(s[n].replace(/```<br>/g,"```").replace(/<br>```/g,"```")).replace(/```/g,"").replace(/(?:\r\n|\r|\n)/g,"<br>"))+"</pre>");return t.replace(/&lt;/g,"<")}strip(e=!1){return se.strip(!1===e?""+this.details.message:e)}}window.SBMessage=oe;class re{constructor(e,t){this.details=se.null(t)?{}:t,Array.isArray(e)?(this.messages=[],e.length&&(e[0]instanceof oe?this.messages=e:se.error("Messages not of type SBMessage","SBConversation.constructor"))):se.error("Message array not of type Array","SBConversation.constructor");let i=["conversation_id","conversation_user_id","conversation_first_name","conversation_last_name","conversation_profile_image","conversation_user_type","conversation_creation_time","conversation_status_code"],s=["payload"];for(a=0;a<i.length;a++)t[i[a]]&&(this.details[i[a].replace("conversation_","")]=t[i[a]]),delete this.details[i[a]];for(var a=0;a<s.length;a++)delete this.details[s[a]];t&&(this.details.tags="tags"in t?"string"==typeof t.tags?t.tags.split(","):t.tags:[])}get id(){return this.get("id")}get status_code(){return this.get("status_code")}get(e){if(e in this.details&&!se.null(this.details[e]))return this.details[e];if("title"==e){if(this.details.title)return this.details.title;if(this.details.first_name)return this.details.first_name+" "+this.details.last_name;if(this.messages.length)return this.messages[0].get("full_name")}return""}set(e,t){this.details[e]=t}getMessage(e){for(var t=0;t<this.messages.length;t++)if(this.messages[t].id==e)return this.messages[t].set("index",t),this.messages[t];return!1}
1getLastMessage(e=!1){let t=this.messages.length-1;if(e)return t>-1&&this.messages[t];for(var i=t;i>-1;i--)if(this.messages[i].message||this.messages[i].attachments.length||this.messages[i].payload("preview"))return this.messages[i];return!1}getLastUserMessage(e=!1,t=!1){!1===e&&(e=this.messages.length-1);for(var i=e;i>-1;i--){let e=this.messages[i],s=e.get("user_type");if((e.message||e.attachments.length)&&(!t&&!se.isAgent(s)||!0===t&&("agent"==s||"admin"==s)||"bot"==t&&"bot"==s||"no-bot"==t&&"bot"!=s||"all"==t&&se.isAgent(s)))return this.messages[i].set("index",i-1),this.messages[i]}return!1}getNextMessage(e,t=!1){let i=this.messages.length;for(var s=0;s<i;s++)if(this.messages[s].id==e&&s<i-1){for(var a=s+1;a<i;a++){let e=this.messages[a].get("user_type"),i=this.messages[s+1];if(!t||"agent"==t&&se.isAgent(e)||"user"==t&&!se.isAgent(e))return i}break}return!1}getUserMessages(e="user"){let t=[],i="user"==e?["visitor","lead","user"]:"agents"==e?["agent","admin"]:["bot"];for(var s=0;s<this.messages.length;s++)i.includes(this.messages[s].get("user_type"))&&(this.messages[s].set("index",s),t.push(this.messages[s]));return t}updateMessage(e,t){if(t instanceof oe){for(var i=0;i<this.messages.length;i++)if(this.messages[i].id==e)return this.messages[i]=t,!0}else se.error("Message not of type SBMessage","SBConversation.updateMessage");return!1}addMessages(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)e[t]instanceof oe&&this.messages.push(e[t]);else e instanceof oe?this.messages.push(e):se.error("Messages not of type SBMessage","SBConversation.addMessages()");return this}getCode(e=!1){let t=this.getLastMessage();if(t){let n=t.message;if(!n&&t.payload("preview")&&(n=t.payload("preview")),$&&(n=t.payload().preview?t.payload().preview:n),!1!==(n=n.replace(/(\r\n|\n|\r)/gm," ")).indexOf("[")){let e=n.match(/\[.+?\]/g)||[];if(e.length){let t=ce.shortcode(e[0]);t[0]&&(n=n.replace(e[0],"action"==t[0]?"":s(t[1].message?t[1].message:t[1].title?t[1].title:t[1].name&&"false"!=t[1].name&&"true"!=t[1].name?t[1].name:t[1].link?t[1].link:t[1].values?t[1].values.replaceAll(",",", ").replaceAll(" "," "):t[1].options?t[1].options.replaceAll(",",", ").replaceAll(" "," "):s(se.slugToString(t[0])))))}}if(!n&&t.attachments.length)for(var i=0;i<t.attachments.length;i++)n+=t.attachments[i][0]+" ";if((n=se.strip(n)).length>114&&(n=n.substr(0,114)+" ..."),e)return n;let o=this.get("title");return(!o||a()&&a().name==o||E&&O.tickets_conversations_title_user)&&(o=a()&&t.get("user_id")==a().id?s("You"):t.get("full_name")),"image"==se.getFileType(o)&&(o=`<img src="${o}" />${o.includes("t=")?` <span>${new URL(o).searchParams.get("t")}</span>`:""}`),`<div class="sb-conversation-item" data-user-id="${this.get("user_id")}"><img loading="lazy" src="${t.get("profile_image")}"><div><span class="sb-name">${o}</span><span class="sb-time">${se.beautifyTime(t.get("creation_time"))}</span></div><div class="sb-message">${n}</div></div>`}return""}deleteMessage(e){for(var t=0;t<this.messages.length;t++)if(this.messages[t].id==e)return this.messages.splice(t,1),!0;return!1}searchMessages(e,t=!1){let i=[];for(var s in this.messages){let a=this.messages[s].message,n=JSON.stringify(this.messages[s].payload());(t&&(a==e||n==e)||!t&&(a.includes(e)||n.includes(e)))&&(this.messages[s].set("index",s),i.push(this.messages[s]))}return i}getAttachments(){let e=[];for(var t=0;t<this.messages.length;t++){let s=this.messages[t].attachments;for(var i=0;i<s.length;i++){let a=s[i][1];e.push([s[i][0],a,a.substr(a.lastIndexOf(".")+1),this.messages[t].id])}}return e}updateMessagesStatus(e=!1){if(e)for(t=0;t<this.messages.length;t++){let i=this.messages[t].id;if(e.includes(i)){let e=u.find(`[data-id="${i}"] .sb-time`);e.find("i").length||e.append('<i class="sb-icon-check"></i>')}}else if(!$&&"visible"==se.visibility_status){e=[];for(var t=0;t<this.messages.length;t++){let i=this.messages[t];se.isAgent(i.get("user_type"))&&2!=i.get("status_code")&&(e.push(i.id),i.set("status_code",2))}e.length&&se.ajax({function:"update-messages-status",message_ids:e})}}}window.SBConversation=re;var le={emoji_options:{range:0,range_limit:47,list:[],list_now:[],touch:!1},initialized:!1,editor_listening:!1,conversation:!1,is_busy:!1,is_busy_update:!1,is_busy_populate:!1,
1chat_open:!1,real_time:!1,agent_id:-1,agent_online:!1,user_online:!1,expanded:!1,main_header:!0,start_header:!1,desktop_notifications:!1,flash_notifications:!1,id_last_message:0,id_last_message_conversation:0,datetime_last_message_conversation:"2000-01-01 00:00:00",audio:!1,audio_interval:!1,tab_active:!0,notifications:i("notifications")?i("notifications"):[],typing_settings:{typing:!1,sent:!1,timeout:!1},email_sent:!1,dashboard:!1,articles:!1,articles_allowed_ids:!1,articles_category:!1,skip:!1,queue_interval:!1,departments:!1,default_department:null,default_agent:null,default_tags:null,offline_message_set:!1,label_date:!1,label_date_show:!1,sendMessage:function(t=-1,i="",n=[],o=!1,r=!1,l=!1){let c=y&&ue.dialogflow.active(),d=!1,g=this.conversation,f=h.find("> [data-reply]").attr("data-reply"),m=h.find("> [data-edit-message]").attr("data-edit-message");if(r||(r={}),!a()&&!$)return this.addUserAndLogin(()=>this.sendMessage(t,i,n,o,r),!0),void this.busy(!0);if(!g){let e=!$&&a().getLastConversation();if(!e||"new-conversation"==q||le.default_department&&le.default_department!=e.get("department")||le.default_agent&&le.default_agent!=e.get("agent_id"))return this.newConversation(l,t,"",[],$&&SB_ACTIVE_AGENT.department?SB_ACTIVE_AGENT.department:null,null,()=>this.sendMessage(t,i,n,o,r)),void this.busy(!0);this.openConversation(e.id),this.setConversation(e),q=!1}this.calculateLabelDateFirst(),-1==t&&(t=$?SB_ACTIVE_AGENT.id:a().id);let v=t!=_;if(i||n.length||(i=p.val().trim(),h.find(".sb-attachments > div").each(function(){let t=[e(this).attr("data-name"),e(this).attr("data-value")];e(this).attr("data-size")&&t.push(e(this).attr("data-size")),n.push(t)}),$&&SBAdmin.must_translate&&i&&(ue.dialogflow.translate([i],a().language,e=>{if(e.length){let t=$?SB_ADMIN_SETTINGS.active_agent_language:a().language;r||(r={}),r["original-message"]=i,r["original-message-language"]=t,e[0]&&(i=e[0])}this.sendMessage(t,i,n,o,r,l)}),d=!0)),this.busy(!0),v&&(p.val("").css("height",""),h.find(".sb-attachments").html("")),h.sbActive(!1),!d)if(!1===l&&t==_&&(l="skip"),$||!v||c||(l=2),f&&(r.reply=i),i||n.length||r){let e={user_id:t,user:a(),conversation_id:g.id,conversation:g,conversation_status_code:l,attachments:n,payload:r};se.ajax({function:m?"update-message":"send-message",user_id:t,conversation_id:g.id,message:i,attachments:n,conversation_status_code:l,queue:!$&&O.queue&&v,payload:r,recipient_id:!!$&&a().id,message_id:m},s=>{let l=$||!c||s.human_takeover_active;$||t!=_||(this.dashboard?this.updateConversations():this.chat_open||this.updateNotifications(g.id,s.id)),($&&!this.user_online||!$&&!this.agent_online)&&this.update(),$||!v||y||(this.followUp(),this.offlineMessage()),$||!v||r&&"sb-human-takeover"==r.id||ue.dialogflow.message(i,n),!$&&v&&"visitor"==a().type?se.ajax({function:"update-user-to-lead",user_id:t},()=>{a().set("user_type","lead"),O.slack_active&&l&&ue.slack.message(t,a().name,a().image,i,n)}):l&&!this.skip&&($&&SB_ADMIN_SETTINGS.slack_active?ue.slack.message(a().id,SB_ACTIVE_AGENT.full_name,SB_ACTIVE_AGENT.profile_image,i,n):O.slack_active&&ue.slack.message(a().id,v?a().name:O.bot_name,v?a().image:O.bot_image,i,n)),v&&O.language_detection&&g&&i.split(" ").length&&i.length>3&&!se.storage("language-detection-completed")&&(se.ajax({function:"google-language-detection-update-user",user_id:t,string:i,token:ue.dialogflow.token},e=>{e&&(O.translations=e)}),se.storage("language-detection-completed",!0)),!this.articles||$||!O.articles||O.office_hours||this.isInitDashboard()||setTimeout(()=>{this.conversation&&g.id==this.conversation.id&&(this.sendMessage(_,"[articles]"),this.scrollBottom(),this.articles=!1)},5e3),s.queue&&this.queue(this.conversation.id),e.message=s.message,e.message_id=s.id,se.event(m?"SBMessageUpdated":"SBMessageSent",e),E&&SBTickets.onMessageSent(),o&&o(e),s.notifications&&s.notifications.length&&se.event("SBNotificationsSent",s.notifications),this.skip&&(this.skip=!1),$&&(SBAdmin.conversations.previous_editor_text=!1),m&&(u.find(`[data-id="${m}"] .sb-message`).html(i),le.cancelEdit()),this.busy(!1)}),v&&!m&&(i=se.escape(i),u.append(new oe({id:"sending",profile_image:$?SB_ACTIVE_AGENT.profile_image:a().image,full_name:$?SB_ACTIVE_AGENT.full_name:a().name,creation_time:"0000-00-00 00:00:00",message:i.replaceAll("<","<"),user_type:$?"agent":"user"}).getCode().replace('<div class="sb-time"></div>
1',`<div class="sb-time">${s("Sending")}<i></i></div>`))),this.dashboard||!v&&!this.isBottom()||this.scrollBottom()}else this.busy(!1)},updateMessage:function(e,t=""){se.ajax({function:"update-message",message_id:e,message:t})},sendEmail:function(e,t,i=!1,s=!1){let n=i?!0===i?a().id:i:this.getRecipientUserID();if(!$&&!isNaN(n)&&this.agent_online)return!1;se.ajax({function:"create-email",recipient_id:n,sender_name:$?i?SB_ACTIVE_AGENT.full_name:a().name:i?O.bot_name:a().name,sender_profile_image:$?i?SB_ACTIVE_AGENT.profile_image:a().name:i?O.bot_image:a().image,message:e,attachments:t,department:!!this.conversation&&this.conversation.get("department"),conversation_id:!!this.conversation&&this.conversation.id},e=>{s&&s(e)})},sendSMS:function(e){let t=this.getRecipientUserID();if(!$&&!isNaN(t)&&this.agent_online)return!1;se.ajax({function:"send-sms",to:t,message:e,conversation_id:!!this.conversation&&this.conversation.id},t=>{"sent"==t.status||"queued"==t.status?se.event("SBSMSSent",{recipient_id:this.getRecipientUserID(),message:e,response:t}):t.message&&se.error(t.message,"SBChat.sendSMS")})},desktopNotification:function(e,t,i,s=!1,n=!1){if("granted"!==Notification.permission)Notification.requestPermission();else{se.serviceWorker.sw.showNotification(e,{body:se.strip(t),icon:i.indexOf("user.svg")>0?O.notifications_icon:i}).onclick=(()=>{$?s?(SBAdmin.conversations.openConversation(s,0==n?a().id:n),SBAdmin.conversations.update()):n&&SBAdmin.profile.show(n):this.start(),window.focus()})}},getRecipientUserID:function(){return $?a().id:this.lastAgent(!1)?this.lastAgent(!1).user_id:se.null(this.conversation.get("agent_id"))?se.null(this.conversation.get("department"))?"agents":"department-"+this.conversation.get("department"):this.conversation.get("agent_id")},submit:function(){if(!this.is_busy){if(A&&A.sbActive()){let e=A.find(".sb-btn-mic");return A.sbActive(!1),e.hasClass("sb-icon-pause")&&e.click(),void setTimeout(()=>{let e=new FormData,t=!!this.conversation&&this.conversation.get("source");"wa"==t||J.length?(e.append("file",new File(["wa"==t?SBAudioRecorder.blob():new Blob(J,{type:"ig"==t?"audio/wav":"audio/mp3"})],"voice_message."+("ig"==t?"wav":"mp3"))),se.upload(e,e=>{le.uploadResponse(e),this.submit()})):this.submit(),A.find(".sb-icon-close").click()},100)}this.sendMessage(),O.cron_email_piping_active&&(setTimeout(()=>{se.ajax({function:"email-piping"}),O.cron_email_piping_active=!0},6e4),O.cron_email_piping_active=!1),Q&&se.serviceWorker.initPushNotifications(),$&&SBAdmin.conversations.setStatus(1,!1,!0),le.cancelReply()}},initChat:function(){$||se.getActiveUser(!0,()=>{let e=!1!==a(),t=!!e&&a().type;if(E||!O.popup||i("popup")||P&&O.popup_mobile_hidden||this.popup(),le.automations.runAll(),E||!O.privacy||O.registration_required||i("privacy-approved")){if(typeof Notification!==G&&!O.push_notifications_users&&(["all","users"].includes(O.desktop_notifications)||$&&"agents"==O.desktop_notifications)&&(this.desktop_notifications=!0),(["all","users"].includes(O.flash_notifications)||$&&"agents"==O.flash_notifications)&&(this.flash_notifications=!0),this.registration(!0)&&!E)return this.registration(),void(!e&&O.visitors_registration&&this.addUserAndLogin());e||!(typeof SB_WP_WAITING_LIST!==G||O.visitors_registration||O.welcome||E||O.flow_on_load)||E&&O.tickets_registration_required?!this.conversation&&e?this.populateConversations():this.finalizeInit():this.addUserAndLogin(()=>{this.welcome(),ue.dialogflow.flowOnLoad(),ue.woocommerce.waitingList(),this.finalizeInit()}),O.header_name&&e&&"user"==t&&!E&&g.find(".sb-title").html(s(O.header_name).replace("{user_name}",a().nameBeautified)),this.welcome(),ae.active||setInterval(()=>{this.updateConversations(),this.updateUsersActivity()},10200),ue.dialogflow.flowOnLoad(),ue.woocommerce.waitingList(),this.scrollBottom(!0)}else this.privacy()})},finalizeInit:function(){this.initialized||(r.attr("style",""),$||E||(this.isInitDashboard()&&this.showDashboard(),!P&&window.innerHeight<760&&r.find(" > .sb-body").css("max-height",window.innerHeight-130+"px")),this.initialized=!0,$||(a()&&!this.registration(!0)&&(se.getURL("conversation")?this.openConversation(se.getU
1RL("conversation"),()=>{if(se.getURL("rating")){setTimeout(()=>{ce.rating()},600);let e=le.conversation.getLastUserMessage(!1,!0);se.ajax({function:"set-rating",conversation_id:se.getURL("conversation"),agent_id:!!e&&e.get("user_id"),user_id:a().id,rating:se.getURL("rating")})}}):i("open-conversation")&&this.openConversation(i("open-conversation"))),(!this.chat_open&&(!P&&i("chat-open")||"open"==se.getURL("chat"))||se.getURL("conversation"))&&setTimeout(()=>{this.start()},500),O.woocommerce_returning_visitor&&(!1===i("returning-visitor")?se.storageTime("returning-visitor"):se.storageTime("returning-visitor",24)&&!i("returning-visitor-processed")&&setTimeout(()=>{se.ajax({function:"woocommerce-returning-visitor"},()=>{i("returning-visitor-processed",!0)})},15e3)),O.timetable_type&&le.offlineMessage(),O.queue_human_takeover&&ue.dialogflow.humanTakeoverActive()&&(O.queue=!0),e(window).on("resize",function(){!P&&window.innerHeight<760&&r.find(" > .sb-body").css("max-height",window.innerHeight-130+"px")}),ue.dialogflow.flowOnLoad()),E&&SBTickets.init(),se.event("SBInit"))},start:function(){this.initialized&&(this.populate(),this.headerAgent(),this.updateUsersActivity(),this.startRealTime(),this.popup(!0),this.conversation&&this.updateNotifications(this.conversation.id),r.sbActive(!0),e("body").addClass("sb-chat-open"),this.chat_open=!0,"open"!=O.welcome_trigger||this.registration(!0)||this.welcome(),ue.martfury.privateChat(),this.calculateLabelDates())},open:function(t=!0){t&&!this.chat_open?(this.start(),this.chat_open=!0,this.startRealTime(),r.sbActive(!0),e("body").addClass("sb-chat-open"),i("chat-open",!0),this.conversation&&i("last-open-message",this.conversation.getLastMessage().id),P&&history.pushState({"chat-open":!0},"",""),se.event("SBChatOpen")):!t&&this.chat_open&&(r.sbActive(!1),this.stopRealTime(),this.chat_open=!1,i("chat-open",!1),e("body").removeClass("sb-chat-open"),se.event("SBChatClose"))},openConversation:function(e,t=!1){a().getFullConversation(e,s=>{if(!s.id||!le.isConversationAllowed(s.get("source"),s.status_code,JSON.stringify(s&&s.getLastMessage()?s.getLastMessage().payload():{})))return i("open-conversation",""),!1;this.setConversation(s),this.hideDashboard(),this.populate(),this.main_header=!1,i("chat-open")&&!P&&le.open(),i("queue")==e&&this.queue(e),(this.chat_open||E)&&this.updateNotifications(e),E&&SBTickets.activateConversation(s),t&&t(s),i("open-conversation",e),se.event("SBConversationOpen",s)})},update:function(){if(this.conversation){if(this.is_busy_update)return;let e=this.conversation.getLastMessage(!0),t=!1;se.ajax({function:"get-new-messages",conversation_id:this.conversation.id,datetime:this.datetime_last_message_conversation,last_id:this.id_last_message_conversation},s=>{let n=s.length;if(this.is_busy_update=!1,this.conversation&&Array.isArray(s)&&n>0&&(!e||e.id!=s[n-1].id||e.message!=s[n-1].message||e.payload!=s[n-1].payload||e.attachments!=s[n-1].attachments)){let e="",r=[],l=[],c=!1;this.calculateLabelDateFirst();for(var o=0;o<n;o++)if(!(l.includes(s[o].id)||$&&this.conversation.id!=s[o].conversation_id)){let n=new oe(s[o]),d=n.payload();if(this.id_last_message_conversation=n.id,this.datetime_last_message_conversation=n.get("creation_time"),d.event){let e=d.event;("delete-message"!=e||!1===this.conversation.getMessage(n.id))&&($||n.message||n.attachments.length||d)||this.deleteMessage(n.id),"woocommerce-update-cart"!=e||$||ue.woocommerce.updateCart(d.action,d.id),"woocommerce-checkout"!=e||$||ue.wordpress.ajax("url",{url_name:"checkout"},e=>{setTimeout(()=>document.location=e,500)}),ue.dialogflow.active()||"conversation-status-update-3"!=e&&"conversation-status-update-4"!=e&&"activate-bot"!=e||(ue.dialogflow.active("activate"),c=!0),"conversation-status-update-3"==e&&this.conversationArchived()}d["human-takeover"]&&O.queue_human_takeover&&(O.queue=!0,le.queue(le.conversation.id)),d["human-takeover-fallback"]&&(ue.dialogflow.typing_enabled=!1),this.conversation.getMessage(s[o].id)?(this.conversation.updateMessage(n.id,n),u.find(`[data-id="${n.id}"]`).replaceWith(n.getCode()),t=!0):((n.message||n.attachments.length)&&u.find('[data-id="sending"]').remove(),this.conversation.id==s[o].conversation_id&&(this.conversation.addMessages(n),e+=n.getCode(),t=!1)),this.conversation.updateMessagesStatus(),r.push(n),l.push(n.id),this.chat_open&&i("last-open-message",n.id),$||!this.dashboard&&this.chat_open&&this.tab_active||n.get("user_id")==a().id||!n.message&&!n.attachments.length||this.updateNotifications(this.conversation.id,n.id)}u.append(e);let d=this.conversation.getLastMessage(),h=!!d&&d.get("user_type"),p=se.isAgent(h),g=p&&"bot"!=h;!$&&g&&(this.chat_open&&(!d||d.message.includes("sb-rich-success")||s[0].payload&&s[0].payload.includes("conversation-status-update")||this.setConversationStatus(0),O.follow&&clearTimeout(R)),c||ue.dialogflow.active(!1)),i("queue")==this.conversation.id&&g&&this.queue("clear"),!r.length||se.null(r[0].message)&&se.null(r[0].attachments)&&1==n||($||this.tab_active||this.flashNotification(),this.audio&&(!$&&p&&O.sound||$&&!p&&SB_ADMIN_SETTINGS.sound)&&this.playSound()),this.headerAgent(),t||this.dashboard||(this.scrollBottom(),setTimeout(()=>{this.scrollBottom()},300)),!O.auto_open||!this.dashboard&&this.chat_open||this.open(),g&&this.typing(-1,"stop"),this.busy(!1),se.event("SBNewMessagesReceived",{messages:r,conversation_id:this.conversation.id}),E&&SBTickets.onNewMessageReceived(r[0],this.conversation.id)}}),this.is_busy_update=!0,setTimeout(()=>{this.is_busy_update=!1},5e3)}else this.updateConversations()},updateConversations:function(){a()&&se.ajax({function:"get-new-user-conversations",datetime:this.id_last_message},e=>{if(e.length){this.id_last_message=e[0].message_id,this.chat_open&&i("last-open-message",this.id_last_message);for(var t=0;t<e.length;t++){let i=e[t].conversation_status_code;if(!le.isConversationAllowed(e[t].source,i,e[t].payload))continue;let s=e[t].conversation_id,n=new oe(e[t]),o=new re([n],e[t]),r=a().addConversation(o);e[t].message_user_id==a().id||this.conversation.id==s&&this.chat_open||!n.message&&!n.attachments.length||(this.updateNotifications(s,n.id),O.auto_open&&this.open());let l=n.payload();if("boolean"!=typeof l&&l.event){if("open-chat"==l.event&&((this.conversation.id!=s||this.dashboard)&&this.openConversation(s),P||setTimeout(()=>{this.open()},500)),!n.message&&!n.attachments.length)continue}this.tab_active||(this.desktop_notifications&&le.desktopNotification(n.get("full_name"),n.message,n.get("profile_image")),this.flash_notifications&&this.flashNotification(),$||!this.audio||!O.sound||this.chat_open&&!this.dashboard&&this.conversation.id==s||se.null(n.message)&&se.null(n.attachments)||this.playSound()),r&&se.event("SBNewConversationReceived",o),E&&SBTickets.onConversationReceived(o),!this.conversation&&r&&this.openConversation(o.id)}this.conversation&&this.conversation.updateMessagesStatus(),r.find(".sb-user-conversations").html(a().getConversationsCode()),r.find(".sb-dashboard-conversations").setClass("sb-conversations-hidden",r.find(".sb-user-conversations > li").length>3)}})},populate:function(){if(this.conversation){let t="",a=u.find(" > .sb-notify-message"),n=!1,o=this.conversation.id;for(var e=0;e<this.conversation.messages.length;e++){let i=this.conversation.messages[e],a=se.beautifyTime(i.get("creation_time"));a.includes("today")&&(a=`<span>${s("Today")}</span>`),a!=n&&(i.message||i.attachments.length||$&&["terminate_call","incoming_call","call_permission_request","call_response","conversation-department-update","conversation-agent-update","conversation-status-update"].includes(i.payload("event")))&&(t+=`<div class="sb-label-date">${a}</div>`,n=a),t+=i.getCode()}if(u.html((a.length?a[0].outerHTML:"")+t),!this.dashboard&&(this.scrollBottom(),this.calculateLabelDates(),$&&SB_ADMIN_SETTINGS.notify_email_cron||!$&&O.notify_email_cron)){let e=this.conversation.getLastUserMessage(!1,!$);
1e&&e.id!=i("email-cron-"+o)&&(se.ajax({function:"remove-email-cron",conversation_id:o}),i("email-cron-"+o,e.id))}}else a()&&!a().isConversationsEmpty()&&(O.disable_dashboard?this.openConversation(a().conversations[0].id):this.showDashboard())},populateConversations:function(e=!1){!this.is_busy_populate&&a()&&(this.is_busy_populate=!0,setTimeout(()=>{this.is_busy_populate=!1},5e3),a().getConversations(t=>{let s=t.length,n=[];if(s){let e=Date.now(),l=t[0].messages[0];this.id_last_message=l.id;for(o=0;o<s;o++)n.push(t[o].id),E||1!=t[o].status_code||!(i("last-open-message")<l.id)||this.conversation&&this.conversation.id==t[o].id||this.updateNotifications(t[o].id,l.id),!P&&e-se.UTC(t[o].messages[0].get("creation_time"))<6e3&&this.open();r.find(".sb-user-conversations").html(a().getConversationsCode()),r.find(".sb-dashboard-conversations").setClass("sb-conversations-hidden",r.find(".sb-user-conversations > li").length>3)}r.setClass("sb-no-conversations",!s),this.initialized&&"open-conversation"!=q||1!=s||this.isInitDashboard()||i("open-conversation")||(this.openConversation(a().getLastConversation().id),"open-conversation"==q&&(q=""));for(var o=0;o<le.notifications.length;o++)this.updateNotifications(le.notifications[o][0],!!n.includes(le.notifications[o][0])&&le.notifications[o][1]);e&&e(t),this.finalizeInit(),se.event("SBPopulateConversations",{conversations:t})}))},newConversation:function(e,t=-1,i="",s=[],n=null,o=null,l=!1){a()?se.ajax({function:"new-conversation",status_code:e,title:E?r.find(".sb-ticket-title input").val():null,department:se.null(n)?this.default_department:n,agent_id:se.null(o)?this.default_agent:o,tags:this.default_tags,source:E?"tk":""},a=>{if(se.errorValidation(a,"user-not-found"))return void this.addUserAndLogin(()=>{this.newConversation(e,t,i,s,n,o,l)});let r=new re([],a.details);this.setConversation(r),(i||s.length)&&this.sendMessage(t,i,s),t!=_&&setTimeout(()=>{this.queue(r.id)},1e3),l&&l(r)}):se.error("activeUser() not setted","SBChat.newConversation")},setConversation:function(e){if(e instanceof re){let s=a().conversations,n=!0;this.conversation=e,this.id_last_message_conversation=this.conversation.getLastMessage(!0)?this.conversation.getLastMessage(!0).id:0,this.datetime_last_message_conversation=0==this.conversation.getLastMessage(!0)?"2000-01-01 00:00:00":this.conversation.getLastMessage(!0).get("creation_time"),e.id!=this.conversation.id&&this.queue(e.id);for(var t=0;t<s.length;t++)if(s[t].id==e.id){s[t]=e,n=!1;break}n&&s.push(e),i("open-conversation",e.id),ue.dialogflow.typing_enabled=!0,this.headerAgent(),se.event("SBActiveConversationChanged",e)}else se.error("Value not of type SBConversation","SBChat.setConversation")},queue:function(e){if("clear"==e)return r.removeClass("sb-notify-active sb-queue-active"),u.find(" > .sb-notify-message").remove(),clearInterval(this.queue_interval),this.queue_interval=!1,i("queue",""),void(O.queue_sound&&!le.tab_active&&le.playSound(999));!$&&O.queue&&se.ajax({function:"queue",conversation_id:e,department:this.conversation.get("department")},t=>{u.find(" > .sb-notify-message").remove();let a=t[0];if(0==a)this.queue("clear");else{let n=(O.queue_response_time?parseInt(O.queue_response_time):5)*a,o=s(O.queue_message?O.queue_message:"Please wait for an agent. You are number {position} in the queue. Your waiting time is approximately {minutes} minutes.").replace("{position}","<b>"+a+"</b>").replace("{minutes}","<b>"+n+"</b>");t[1]&&u.prepend(`<div class="sb-notify-message sb-rich-cnt"><div class="sb-cnt"><div class="sb-message">${o}</div></div></div>`),!1===this.queue_interval&&(this.queue_interval=setInterval(()=>{this.queue(e)},10100),t[1]&&r.addClass("sb-notify-active sb-queue-active"),i("queue",e))}se.event("SBQueueUpdate",a)})},getDepartmentCode(e,t){if(this.departments)if("all"==e){let e="";for(var i in this.departments)this.getDepartmentCode(this.departments[i].id,t=>{e+=t});t(e)}else t(`<div data-color="${this.departments[e].color}">${this.departments[e].image?`<img loading="lazy" src="${this.departments[e].image}" />`:""}<div>${this.departments[e].name}<div></div>`);
1else se.ajax({function:"get-departments"},i=>{i&&(this.departments=i,this.getDepartmentCode(e,t))})},startRealTime:function(){ae.active||(this.stopRealTime(),this.real_time=setInterval(()=>{this.update(),this.typing($?a()?a().id:-1:this.agent_id,"check")},1e3))},stopRealTime:function(){clearInterval(this.real_time)},updateUsersActivity:function(t=!1){se.updateUsersActivity(!!a()&&a().id,this.agent_id,i=>{this.typing_settings.typing||("online"==i||this.agent_id==_||(!this.conversation||this.conversation&&!this.dashboard)&&-1==this.agent_id&&(F||t&&(!a()||t!=a().id))?(e(f).addClass("sb-status-online").html(s("Online")),this.agent_online=this.agent_id!=_):(e(f).removeClass("sb-status-online").html(s("Away")),this.agent_online=!1))})},busy:function(e){h&&h.find(".sb-loader").sbActive(e),this.is_busy=e,se.event("SBBusy",e)},headerAgent:function(e=!1){if(!$&&!E&&!this.dashboard&&(-1==this.agent_id||this.conversation&&this.conversation.getLastMessage()&&se.isAgent(this.conversation.getLastMessage().get("user_type"))&&this.conversation.getLastMessage().get("user_id")!=this.agent_id)){let t=this.lastAgent(!1),i=!0;
1if((t=t&&ue.dialogflow.humanTakeoverActive()&&ae.active&&!ae.presenceCheck({info:{user_type:"agent"},id:t.user_id})?t:this.lastAgent())||this.conversation&&(!this.conversation||this.dashboard)||(O.is_chatbot_active?e=!0:(i=!g.hasClass("sb-header-agent"))&&(t=g.hasClass("sb-header-type-agents")?{user_id:g.find(".sb-profiles > div:first-child").attr("data-id"),full_name:g.find(".sb-profiles > div:first-child > span").text().trim(),profile_image:g.find("img").eq(0).attr("src")}:{user_id:-1,full_name:g.find(".sb-title").text().trim(),profile_image:g.find("img").attr("src")})),!t&&e&&(t={user_id:O.bot_id,full_name:O.bot_name,profile_image:O.bot_image}),t){let e=this.agent_id!=t.user_id&&g.hasClass("sb-header-agent");this.headerReset(),this.agent_id=t.user_id,g.addClass("sb-header-agent").attr("data-agent-id",this.agent_id),e?(g.find(".sb-profile").addClass("sb-replace-agent-animation"),setTimeout(()=>{g.find("img").attr("src",t.profile_image),g.find(".sb-name").html(t.full_name)},500)):g.html(`<div class="sb-dashboard-btn sb-icon-arrow-left"></div><div class="sb-profile">${t.profile_image?`<img loading="lazy" src="${t.profile_image}" />`:""}<div><span class="sb-name">${t.full_name}</span><span class="sb-status">${s("Away")}</span></div><i class="sb-icon sb-icon-close ${O.close_chat?"sb-close-chat":"sb-responsive-close-btn"}"></i>${P?"":'<i class="sb-icon sb-icon-arrows-'+(r.hasClass("sb-chat-large")?"in":"out")+' sb-enlarge-chat-widget"></i>'}</div><div class="sb-label-date-top"></div>`),f=g.find(".sb-status"),this.updateUsersActivity(),this.label_date=g.find(".sb-label-date-top"),se.storageTime("header-animation",1)&&this.headerAnimation()}else i&&(this.headerReset(),g.html(this.start_header[0]).addClass(this.start_header[1]))}},headerReset:function(){0==this.start_header&&(this.start_header=[g.html(),g.attr("class")]),g.removeClass("sb-header-main sb-header-brand sb-header-agent sb-header-minimal"),this.main_header=!1},headerAnimation:function(){g.addClass("sb-header-animation"),setTimeout(()=>{g.removeClass("sb-header-animation")},8e3),se.storageTime("header-animation")},lastAgent:function(e=!0){let t=!1;if(this.conversation){let i=this.conversation.getLastUserMessage(!1,!e||"all");i&&(t={user_id:i.get("user_id"),full_name:i.get("full_name"),profile_image:i.get("profile_image")})}return t},scrollBottom:function(e=!1){setTimeout(()=>{v.scrollTop(e?0:v[0].scrollHeight),this.scrollHeader()},20)},isBottom:function(){return v[0].scrollTop===v[0].scrollHeight-v[0].offsetHeight},resize:function(e=!0){let t=window.innerHeight-130,i=g.find(".sb-enlarge-chat-widget");r.setClass("sb-chat-large",e),r.find(" > .sb-body").css("max-height",(e?t:t>650?650:t)+"px"),i.removeClass("sb-icon-arrows-in sb-icon-arrows-out"),i.addClass(e?"sb-icon-arrows-in":"sb-icon-arrows-out")},scrollHeader:function(){if(this.main_header&&this.dashboard){let e=v.scrollTop();e>-1&&e<1e3&&g.find(".sb-content").css({opacity:1-e/500,top:e/10*-1+"px"})}},showDashboard:function(){$||E||(r.addClass("sb-dashboard-active"),g.removeClass("sb-header-agent"),this.hidePanel(),this.start_header&&g.html(this.start_header[0]).addClass(this.start_header[1]),v.find(" > div").sbActive(!1),r.find(".sb-dashboard").sbActive(!0),this.populateConversations(),this.conversation=!1,this.agent_id=-1,this.stopRealTime(),this.dashboard=!0,this.main_header=!0,this.scrollBottom(!0),this.resize(!1),se.event("SBDashboard"))},hideDashboard:function(){$||E||(u.sbActive(!0),r.removeClass("sb-dashboard-active").find(".sb-dashboard").sbActive(!1),this.dashboard=!1,this.headerAgent(),this.scrollHeader(0),this.chat_open&&this.startRealTime(),se.event("SBDashboardClosed"))},showPanel:function(e,t){if(E)return SBTickets.showPanel(e,t);let i=v.find(" > .sb-panel-"+e);i.length&&(v.find(" > div").sbActive(!1),i.sbActive(!0),this.start_header||(this.start_header=[g.html(),g.attr("class")]),g.attr("class","sb-header sb-header-panel").html(`<span>${s(t)}</span>${P?"":'<i class="sb-icon sb-icon-arrows-'+(r.hasClass("sb-chat-large")?"in":"out")+' sb-enlarge-chat-widget sb-enlarge-chat-widget-panel"></i>'}<div class="sb-dashboard-btn sb-icon-close"></div>`),r.addClass("sb-panel-active"),this.dashboard=!0),se.event("SBPanelActive",e)},hidePanel:function(){r.removeClass("sb-panel-active"),g.removeClass("sb-header-panel")},clear:function(){this.conversation=!1,u.html("")},updateNotifications:function(e,t=!1){let s=!1;if(t){for(a=0;a<this.notifications.length;a++)this.notifications[a][0]==e&&t==this.notifications[a][1]&&(s=!0);
1s||(this.notifications.push([e,t]),!this.dashboard&&this.conversation&&this.conversation.id!=e&&this.headerAnimation())}else{let t=[];for(var a=0;a<this.notifications.length;a++)this.notifications[a][0]==e?s=!0:t.push(this.notifications[a]);!$&&s&&["0",0].includes(this.conversation.status_code)&&this.setConversationStatus(1,!0),this.notifications=t}let n=this.notifications.length;i("notifications",this.notifications),r.find(".sb-chat-btn span").attr("data-count",n).html(n>-1?n:0),se.event("SBNotificationsUpdate",{conversation_id:e,message_id:t})},setConversationStatus:function(e,t=!1){return!!this.conversation&&(se.ajax({function:"update-conversation-status",conversation_id:this.conversation.id,status_code:e,prevent_2_to_1:t},()=>{this.conversation.set("status_code",e),se.event("SBActiveConversationStatusUpdated",{conversation_id:this.conversation.id,status_code:e})}),!0)},typing:function(t=-1,i="check"){if(this.conversation){let n=this.agent_online||$&&this.user_online;if("check"==i&&!ae.active&&-1!=t&&t!=_&&n)se.ajax({function:"is-typing",user_id:t,conversation_id:this.conversation.id},e=>{e&&!this.typing_settings.typing?this.typing(-1,"start"):!e&&this.typing_settings.typing&&this.typing(-1,"stop")});else if("set"==i&&n){let e=this.conversation.get("source");clearTimeout(I),e&&(e="fb"==e?[e,a().getExtra("facebook-id").value,this.conversation.get("extra")]:"tw"==e&&[e,a().getExtra("twitter-id").value]),ae.active?se.debounce(()=>{ae.trigger("client-typing",{user_id:$?SB_ACTIVE_AGENT.id:a().id,conversation_id:this.conversation.id}),e&&se.ajax({function:"set-typing",source:e})},"#2"):this.typing_settings.sent?(clearTimeout(this.typing_settings.timeout),this.typing_settings.timeout=setTimeout(()=>{se.ajax({function:"set-typing",user_id:t,conversation_id:-1},()=>{this.typing_settings.sent=!1})},2e3)):(this.typing_settings.sent=!0,se.ajax({function:"set-typing",user_id:t,conversation_id:this.conversation.id,source:e}),this.typing(t,"set"))}else if("start"==i||"stop"==i){let t="start"==i;if(!$&&f)if(t){let t=this.lastAgent();e(f).addClass("sb-status-typing").html(s("Typing")),!t&&O.is_chatbot_active&&(t={user_id:O.bot_id,full_name:O.bot_name,profile_image:O.bot_image}),t&&!u.find('[data-id="typing"]').length&&(u.append(new oe({id:"typing",profile_image:t.profile_image,full_name:t.full_name,user_type:"agent",creation_time:"0000-00-00 00:00:00",message:" "}).getCode()),this.scrollBottom())}else{let t=this.agent_online||this.agent_id==_;clearTimeout(I),e(f).removeClass("sb-status-typing").html(s(t?"Online":"Away")),t&&e(f).addClass("sb-status-online"),u.find('[data-id="typing"]').remove()}this.typing_settings.typing=t,se.event("SBTyping",t)}}},showArticles:function(e=!1,t=!1){let i=E?r.find(".sb-panel-main .sb-panel"):v.find(" > .sb-panel-articles");i.html("").sbLoading(!0),this.showPanel("articles",O.articles_title?O.articles_title:"Help Center"),!e&&O.articles_categories?this.getArticleCategories(e=>{this.showArticles_(e,i,{categories:e})},"parent"):this.getArticles(!t&&e,s=>{e&&!t?(i.html(this.getArticleCode(s[0])),i.sbLoading(!1),se.event("SBArticles",{id:e,articles:s})):this.showArticles_(s,i,{id:e,articles:s})},!!t&&e)},showArticles_:function(e,t,i){let s="",a=typeof SB_LANG!=G&&SB_LANG[0];for(var n=0;n<e.length;n++){let t="content"in e[n];s+=`<div data-id="${e[n].id}"${t?"":' data-is-category="true"'}><div>${t?e[n].title:a&&e[n].languages&&e[n].languages[a]?e[n].languages[a].title:e[n].title}</div><span>${t?e[n].content:a&&e[n].languages&&e[n].languages[a]?e[n].languages[a].description:e[n].description?e[n].description:""}</span></div>`}t.html(`<div class="sb-articles">${s}</div>`),t.sbLoading(!1),se.event("SBArticles",i)},getArticles:function(e=!1,t=!1,i=!1,s=!1){se.ajax({function:"get-articles",categories:this.articles_category?this.articles_category:i,id:e||this.articles_allowed_ids,count:s,return_categories:!!this.articles_category,full:e,skip_language:!0},e=>{t(e)})},getArticleCategories:function(e=!1,t=!1){se.ajax({function:"get-articles-categories",category_type:t},t=>{e(t)})},searchArticles:function(t,i,a){t&&(e(i).sbLoading(!0),se.ajax({function:"search-articles",search:t},t=>{let n="";if(0==t.length)n+=`<p class="sb-no-results">${s("No articles found.")}</p>`;else for(var o=0;o<t.length;o++)n+=`<div data-id="${t[o].id}"><div>${t[o].title}</div><span>${t[o].content}</span></div>`;e(a).html(n),e(i).sbLoading(!1)}))},setArticleRating:function(e,t,i=!1){se.ajax({function:"article-ratings",article_id:e,rating:t},e=>{i&&i(e)})},articleRatingOnClick:function(t){let i=e(t).closest(".sb-article");
1if(!i[0].hasAttribute("data-user-rating")){e(t).parent().sbLoading();let s="positive"==e(t).attr("data-rating")?1:-1,a=e(t).closest(".sb-article").attr("data-id");le.setArticleRating(a,s,()=>{se.storage("article-rating-"+a,s),i.attr("data-user-rating",s),e(t).parent().sbLoading(!1)})}},getArticleCode:function(e){let t=se.storage("article-rating-"+e.id),i="";if(this.articles_categories&&!se.null(e.categories))for(var a=0;a<this.articles_categories.length;a++){let t=this.articles_categories[a].id;(e.categories.includes(t)||e.parent_category==t)&&(i+=`<span data-id="${t}">${s(this.articles_categories[a].title)}</span>`)}return`<div data-id="${e.id}"${t?` data-user-rating="${t}"`:""} class="sb-article"><div class="sb-title">${e.title}<div class="sb-close sb-icon-close"></div></div><div class="sb-content">${e.content.replace(/(?:\r\n|\r|\n)/g,"<br>")}</div>${e.link?`<div class="sb-read-more-cnt"><a href="${e.link}" target="_blank" class="sb-btn">${s("Read more")}</a></div>`:""}${i?`<div class="sb-article-category-links">${i}</div>`:""}<div class="sb-rating"><span>${s("Rate and review")}</span><div><i data-rating="positive" class="sb-submit sb-icon-like"><span>${s("Helpful")}</span></i><i data-rating="negative" class="sb-submit sb-icon-dislike"><span>${s("Not helpful")}</span></i></div></div></div>`},initArticlesPage:function(){let i=se.getURL("article_id"),a=se.getU
1RL("category"),n=se.getURL("search");if(O.articles_url_rewrite){let e=location.href.replace(O.articles_url_rewrite,"").split("/");"category"==e[e.length-2]&&(a=e[e.length-1]),(2==e.length&&!e[0]&&e[1]||1==e.length&&e[0])&&(i=e[e.length-1]),O.articles_page_url}if((H=e("body").find("#sb-articles")).length||(H=e("body")),H.sbLoading()){let e=SB_URL+"/include/articles.php"+(a?"?category="+a:i?"?article_id="+i:n?"?search="+n:"");V&&(e+=(e.includes("?")?"&":"?")+"cloud="+V),se.getURL("lang")&&(e+=(e.includes("?")?"&":"?")+"lang="+se.getURL("lang")),se.loadResource(SB_URL+"/css/articles.css"),se.cors("GET",e,e=>{H.html(e),H.sbLoading(!1),this.initSingleArticlePage()})}H.on("keydown",".sb-panel-side input",function(t){13==t.which&&e(this).next().click()}),H.on("click",".sb-articles > [data-id]",function(){cache=panel_main.html(),panel_main.sbLoading(!0),le.getArticles(e(this).attr("data-id"),e=>{panel_main.removeClass("sb-articles").html(le.getArticleCode(e)),panel_main.sbLoading(!1)})}),H.on("click",".sb-article [data-rating]",function(){le.articleRatingOnClick(this)}),H.on("click",".sb-article .sb-title .sb-close",function(){H.find(".sb-panel-main").addClass("sb-articles").html(cache)}),H.on("click",".sb-submit-articles",function(){let t=e(this).parent().find("input").val();t?(cache=panel_main.html(),panel_main.html(""),le.searchArticles(t,this,panel_main)):panel_main.html(cache),panel_main.addClass("sb-articles")}),H.on("click",".sb-article-categories [data-id]",function(){if(t(panel_main))return;let i="";cache=panel_main.html(),H.find(".sb-article-categories [data-id]").sbActive(!1),e(this).sbActive(!0),le.getArticles(-1,e=>{for(var t=0;t<e.length;t++)i+=`<div data-id="${e[t].id}"><div>${e[t].title}</div><span>${e[t].content}</span></div>`;panel_main.addClass("sb-articles").html(i||`<p class="sb-no-results">${s("No articles found.")}</p>`),panel_main.sbLoading(!1)},e(this).attr("data-id"))})},initSingleArticlePage:function(){if(typeof SB_ARTICLE_ID===G)return;let t=se.storage("article-rating-"+SB_ARTICLE_ID);const i=e(".sb-article"),s=e(".sb-articles-nav"),a=s.find('a[href^="#"]'),n=[],o=s[0].getBoundingClientRect().top+40+"px";t&&i.attr("data-user-rating",t),i.on("click",".sb-rating-ext [data-rating]",function(e){return le.articleRatingOnClick(this),e.preventDefault(),!1}),s.on("click",".sb-articles-nav-mobile-btn",function(){e(this).parent().toggleClass("sb-active")}),s.on("click","a",function(){window.innerWidth<768&&s.removeClass("sb-active"),history.replaceState(null,"",e(this).attr("href"))}),s.css("--offset",o),e(".sb-articles-list-nav").css("--offset",o),a.eq(0).addClass("sb-active"),a.each((t,s)=>{const a=i.find("#"+e(s).attr("href").slice(1));a.length&&n.push({link:e(s),section:a[0]})});const r=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){a.removeClass("sb-active");const t=n.find(t=>t.section===e.target);t&&t.link.addClass("sb-active")}})},{rootMargin:"-40% 0px -50% 0px",threshold:0});n.forEach(e=>r.observe(e.section)),a.each((t,s)=>{e(s).on("click",function(t){t.preventDefault();const s=i.find("#"+e(this).attr("href").slice(1));s.length&&window.scrollTo({top:s[0].offsetTop-80,behavior:"smooth"})})})},categoryEmoji:function(e){let t=this.emoji_options.list;if("all"==e)this.emoji_options.list_now=t;else{this.emoji_options.list_now=[];for(var i=0;i<t.length;i++)t[i].category.startsWith(e)&&this.emoji_options.list_now.push(t[i])}this.emoji_options.range=0,this.populateEmoji(0),this.populateEmojiBar()},mouseWheelEmoji:function(e){let t=this.emoji_options.range;(function(e){let t=e.originalEvent.wheelDelta;return typeof t==G&&(t=e.originalEvent.deltaY),typeof t==G&&(t=-1*e.originalEvent.detail),t})(e)>0||P&&typeof e.originalEvent.changedTouches!==G&&this.emoji_options.touch<e.originalEvent.changedTouches[0].clientY?t-=t<1?0:1:t+=t>this.emoji_options.range_limit?0:1,m.find(".sb-emoji-bar > div").sbActive(!1).eq(t).sbActive(!0),this.emoji_options.range=t,this.populateEmoji(t),e.preventDefault()},insertEmoji:function(t){t.indexOf(".svg")>0&&(t=e.parseHTML(t)[0].alt),this.insertText(t),m.sbTogglePopup()},showEmoji:function(e){m.sbTogglePopup(e)&&($||m.css({left:h.offset().left+(E?68:20),top:h.offset().top-window.scrollY-(E?h.height()-330:304)}),m.find(".sb-emoji-list > ul").html()||jQuery.ajax({method:"POST",url:SB_AJAX_URL,data:{function:"emoji","login-cookie":se.loginCookie()}}).done(e=>{this.emoji_options.list=JSON.parse(e),this.emoji_options.list_now=this.emoji_options.list,this.populateEmoji(0),this.populateEmojiBar()}),se.deselectAll())},populateEmoji:function(e){let t="",i=P?42:48,s=e*i+i,a=this.emoji_options.list_now;s>a.length&&(s=a.length),this.emoji_options.range_limit=a.length/i-1,this.emoji_options.range=e;for(var n=e*i;n<s;
1n++)t+=`<li>${a[n].char}</li>`;m.find(".sb-emoji-list").html(`<ul>${t}</ul>`)},populateEmojiBar:function(){let e='<div class="sb-active"></div>',t=P?42:49;for(var i=0;i<this.emoji_options.list_now.length/t-1;i++)e+="<div></div>";this.emoji_options.range=0,m.find(".sb-emoji-bar").html(e)},clickEmojiBar:function(t){let i=e(t).index();this.populateEmoji(i),this.emoji_options.range=i,m.find(".sb-emoji-bar > div").sbActive(!1).eq(i).sbActive(!0)},searchEmoji:function(e){se.search(e,()=>{if(e.length>1){let i=this.emoji_options.list,s=[];for(var t=0;t<i.length;t++)(i[t].category.toLowerCase().includes(e)||i[t].name.toLowerCase().includes(e))&&s.push(i[t]);this.emoji_options.list_now=s}else this.emoji_options.list_now=this.emoji_options.list;this.emoji_options.range=0,this.populateEmoji(0),this.populateEmojiBar()})},textareaChange:function(t){let i=e(t).val();$&&(SBAdmin.conversations.savedReplies(t,i),SBAdmin.apps.openAI.rewriteButton(i)),i&&this.typing($&&!ae.active?SB_ACTIVE_AGENT.id:a().id,"set"),h.sbActive(i)},insertText:function(t){let i=e(p.get(0)),s=0;if(this.dashboard||!t)return!1;if(i.get(0).selectionStart)s=i.get(0).selectionStart;else if(document.selection){i.focus();let e=document.selection.createRange();var a=document.selection.createRange().text.length;e.moveStart("character",-i.value.length),s=e.text.length-a}i.val(i.val().substr(0,s)+t+i.val().substr(s)),i.focus(),i.manualExpandTextarea(),h.sbActive(!0)},enabledAutoExpand:function(){p.length&&p.autoExpandTextarea()},cancelReply:function(){h.find("[data-reply]").remove(),u.removeClass("sb-reply-active")},cancelEdit:function(){h.find("[data-edit-message]").remove(),u.removeClass("sb-edit-message-active")},privacy:function(){se.ajax({function:"get-block-setting",value:"privacy"},e=>{v.append(`<div class="sb-privacy sb-init-form" data-decline="${e.decline}"><div class="sb-title">${e.title}</div><div class="sb-text">${e.message.replace(/\n/g,"<br>")}</div>`+(e.link?`<a target="_blank" href="${e.link}">${e["link-name"]}</a>`:"")+`<div class="sb-buttons"><a class="sb-btn sb-approve">${e["btn-approve"]}</a><a class="sb-btn sb-decline">${e["btn-decline"]}</a></div></div>`),this.finalizeInit(),se.event("SBPrivacy")}),this.dashboard||this.showDashboard(),this.dashboard=!0,r.addClass("sb-init-form-active")},popup:function(e=!1,t=!1){if(e){let e=r.find(".sb-popup-message"),t=e.attr("data-id");return i("popup"+(se.null(t)?"":t),!0),void e.remove()}setTimeout(()=>{this.chat_open||(0==t&&(t=O.popup),r.find(".sb-popup-message").remove(),r.append(`<div data-id="${t.id?t.id:""}" class="sb-popup-message">`+(t.image?`<img loading="lazy" src="${t.image}" />`:"")+(t.title?`<div class="sb-top">${t.title}</div>`:"")+`<div class="sb-text">${t.message}</div><div class="sb-icon-close"></div></div>`),se.event("SBPopup",t))},1e3)},followUp:function(){this.followUpCheck()&&se.ajax({function:"execute-bot-message",conversation_id:this.conversation.id,name:"follow_up",check:!1},e=>{e.settings.sound&&this.audio&&this.audio.play(),this.skip=!0,se.storageTime("email"),se.event("SBFollowUp")})},followUpCheck:function(){return!$&&this.conversation&&O.follow&&a()&&!a().email&&se.storageTime("email",24)},welcome:function(){let e=!E&&("open"!=O.welcome_trigger||this.chat_open)&&(O.office_hours||!O.welcome_disable_office_hours)&&O.welcome&&!i("welcome")&&a();setTimeout(()=>{if(e){if(this.conversation&&this.conversation.searchMessages("welcome-message"))return;se.ajax({function:"get-block-setting",value:"welcome"},e=>{this.sendMessage(_,e.message,[],!1,{type:"welcome-message"},3),e.open&&!P&&this.start(),e.sound&&this.audio.play(),this.skip=!0,se.event("SBWelcomeMessage")})}},1e3*parseInt(E?0:O.welcome_delay)),e&&i("welcome",!0)},offlineMessage:function(){if(!$&&O.timetable&&(!O.office_hours||!F&&!O.timetable_disable_agents)){let e=O.t
1imetable_message;switch(O.timetable_type){case"header":this.offline_message_set||(e[0]&&g.find(".sb-title").html(e[0]),g.find(".sb-text").html(e[1]),this.offline_message_set=!0);break;case"info":this.offline_message_set||(u.prepend(`<div class="sb-notify-message sb-rich-cnt"><div class="sb-cnt"><div class="sb-message">${e[0]?`<b>${e[0]}</b> `:""}${e[1]}</div></div></div>`),r.addClass("sb-notify-active"),this.offline_message_set=!0);break;default:setTimeout(()=>{if(this.conversation){let t=O.timetable_hide?`${e[0]?`*${e[0]}*\n`:""}${e[1]}`:"[timetable]",i=this.conversation.searchMessages(t,!0);if(i=!!i.length&&i){let e=this.conversation.getLastUserMessage(!1,!0);i=!e||(e.get("index")<i[i.length-1].get("index")&&Date.now()-36e5)<se.unix(i[0].get("creation_time"))}i||this.sendMessage(_,t)}},5e3)}}},deleteMessage:function(e){se.ajax({function:"delete-message",message_id:e},()=>{this.conversation&&this.conversation.deleteMessage(e),u.find(`[data-id="${e}"]`).remove(),se.event("SBMessageDeleted",e)})},registration:function(e=!1,t=O.registration_required){if(e)return O.registration_required&&(!O.registration_offline||!F)&&(typeof SB_DEFAULT_USER==G||!SB_DEFAULT_USER.email)&&(!O.registration_timetable||!O.office_hours)&&(!1===a()||["visitor","lead"].includes(a().type));v.append(ce.generate({},O.registration_link||"registration-login"==O.registration_required?"login":t,"sb-init-form")),this.dashboard||this.showDashboard(),this.dashboard=!0,this.finalizeInit(),r.addClass("sb-init-form-active")},addUserAndLogin:function(e=!1,t=!1){let i=typeof SB_DEFAULT_USER!=G&&SB_DEFAULT_USER?SB_DEFAULT_USER:{};i.user_type=t?"lead":"visitor",se.ajax({function:"add-user-and-login",settings:i,settings_extra:i.extra},i=>{if(se.errorValidation(i)){if("duplicate-email"==i[1]||"duplicate-phone"==i[1])return delete SB_DEFAULT_USER.email,delete SB_DEFAULT_USER.extra.phone,this.addUserAndLogin(e,t)}else se.loginCookie(i[1]),a(new ne(i[0])),ae.start(),ae.active||le.automations.runAll(),e&&e(i)})},isInitDashboard:function(){return O.init_dashboard||a()&&a().conversations.length>1},uploadResponse:function(t){if("success"==(t=JSON.parse(t))[0])if("extension_error"==t[1]){let e="The file you are trying to upload has an extension that is not allowed.";$?SBAdmin.infoPanel(e,"info"):alert(e)}else if(e(c).hasClass("sb-input-image")){let i=e(c).find(".image"),s=i.attr("data-value");s&&!s.includes("media/user.svg")&&se.ajax({function:"delete-file",path:s}),i.attr("data-value","").css("background-image",""),setTimeout(()=>{i.attr("data-value",t[1]).css("background-image",`url("${t[1]}?v=${se.random()}")`).append('<i class="sb-icon-close"></i>'),c=!1},500)}else{let e=se.beautifyAttachmentName(t[1].substr(t[1].lastIndexOf("/")+1));h.find(".sb-attachments").append(`<div data-name="${e}" data-type="${se.getFileIcon(e)}" data-value="${t[1]}"${t.length>2?' data-size="'+t[2][0]+"|"+t[2][1]+'"':""}>${e}<i class="sb-icon-close"></i></div>`),h.sbActive(!0)}else se.error(t[1],"sb-upload-files.change");this.busy(!1)},closeChat:function(e=!0){let t=this.conversation.id;le.clear(),e?se.ajax({function:"update-conversation-status",conversation_id:t,status_code:3},()=>{this.closeChat_(t)}):this.closeChat_(t)},closeChat_(e){r.find(`li[data-conversation-id="${e}"]`).remove(),q="new-conversation",le.clear(),i("open-conversation",""),i("welcome",""),i("flow_on_load",""),a().removeConversation(e),O.disable_dashboard||le.showDashboard()},conversationArchived:function(){let e=!E&&O.close_chat||E&&O.tickets_close;if(e&&!O.rating)return this.closeChat(!1);O.rating&&ce.rating(e)},automations:{history:[],busy:[],scroll_position_intervals:{},timeout_queue:[],runAll:function(){let t=O.automations;for(var i=0;i<t.length;i++){let o=t[i],r=o.conditions,l=0==r.length,c=!1,d=!1,u=!1;for(var s=0;s<r.length;s++){let t=r[s][1];switch(l=!1,r[s][0]){case"browsing_time":l=!0,c=t;break;case"scroll_position":l=!0,d=t;break;case"referring":case"url":let i="referring"==r[s][0]?document.referrer:window.location.href,o=r[s][2].replace(/https?:\/\/|www\./g,"").split(",");i=i.replace(/https?:\/\/|www\./g,"");for(n=0;n<o.length;n++)if(i.includes(o[n])){l="contains"==t;break}break;case"include_urls":case"exclude_urls":let h="referring"==r[s][0]?document.referrer:window.location.href,p=r[s][2].replace(/https?:\/\/|www\./g,"").split(","),g="exclude_urls"!=r[s][0];g||(l=!0),h=h.replace(/https?:\/\/|www\./g,"");for(var n=0;n<p.length;n++)if(p[n]=e.trim(p[n].replace("https://","").replace("http://","").replace("www.","")),"contains"==t&&-1!=h.indexOf(p[n])||"does-not-contain"==t&&-1==
1h.indexOf(p[n])||"is-exactly"==t&&p[n]==h||"is-not"==t&&p[n]!=h){l=g;break}break;case"custom_variable":let f=t.split("=");f[0]in window&&window[f[0]]==f[1]&&(l=!0);break;case"returning_visitor":case"user_type":case"cities":case"languages":case"countries":case"postal_code":case"website":case"company":case"creation_time":case"last_activity":l=a(),u=!0;break;case"phone":l=a()&&a().getExtra("phone");break;case"email":l=a()&&a().email;break;default:l=a()&&a().getExtra(r[s][0])}if(!l)break}["messages","emails","sms"].includes(o.type)&&!a()&&(l=!1),l&&(u?o.id in this.busy||(se.ajax({function:"automations-validate",automation:o},e=>{!1!==e&&this.runAll_final(o,d,c),delete this.busy[o.id]}),this.busy[o.id]=!0):"messages"==o.type&&le.registration(!0)||this.runAll_final(o,d,c))}},runAll_final:function(t,i,s){i?this.scroll_position_intervals[t.id]=setInterval(()=>{e(window).scrollTop()>parseInt(i)&&(s?setTimeout(()=>{this.run(t)},1e3*parseInt(s)):this.run(t),clearInterval(this.scroll_position_intervals[t.id]))},1e3):s?this.timeout_queue.includes(t.id)||(setTimeout(()=>{this.run(t)},1e3*parseInt(s)),this.timeout_queue.push(t.id)):this.run(t)},run:function(e){if(!this.history.includes(e.id))switch(e.type){case"messages":case"emails":case"sms":if((!ae.active||ae.started)&&!(e.id in this.busy)){if("messages"==e.type&&le.chat_open){let e=!!le.conversation&&le.conversation.getLastUserMessage(!1,"no-bot");if(e&&Date.now()-6e5<se.unix(e.get("creation_time")))return}se.ajax({function:"automations-run",automation:e},t=>{!1!==t&&(this.history.push(e.id),"messages"!=e.type||ae.active||le.updateConversations()),delete this.busy[e.id]}),this.busy[e.id]=!0}break;case"popups":if(!i("popup"+e.id))if(le.chat_open){if(e.fallback){let t=!!le.conversation&&le.conversation.getLastUserMessage(!1,"no-bot");(!t||Date.now()-6e5>se.unix(t.get("creation_time")))&&(le.sendMessage(_,(se.null(e.title)?"":`*${e.title}*\n`)+e.message,[],!1,!1,0),i("popup"+e.id,!0),this.history.push(e.id))}}else setTimeout(()=>{le.popup(!1,{id:e.id,image:e.profile_image,title:e.title,message:e.message})},1e3),this.history.push(e.id);break;case"design":e.background&&g.css("background-image",`url("${e.background}")`),e.brand&&g.find(".sb-brand img").attr("src",e.brand),e.title&&g.find(".sb-title").html(e.title),e.message&&g.find(".sb-text").html(e.message),e.icon&&r.find(".sb-chat-btn .sb-icon").attr("src",e.icon),(e.color_1||e.color_2||e.color_3)&&se.ajax({function:"chat-css",color_1:e.color_1,color_2:e.color_2,color_3:e.color_3},e=>{l.append(`<style>${e}</style>`)}),this.history.push(e.id);break;case"more":let t={};if(e.department&&(le.default_department=e.department,t={function:"update-conversation-department",department:e.department}),e.agent&&(le.default_agent=e.agent,t={function:"update-conversation-agent",agent_id:e.agent}),e.tags&&(e.tags=e.tags.split(","),le.default_tags=e.tags,t={function:"update-tags",tags:e.tags,add:!0}),le.conversation.id&&(e.tags||e.agent||e.department)&&(t.conversation_id=le.conversation.id,se.ajax(t)),e.articles||e.articles_category){let t=r.find(".sb-dashboard-articles > .sb-articles");le.articles_allowed_ids=e.articles,le.articles_category=e.articles_category,t&&le.getArticles(e.articles,e=>{let i="";for(var s=0;s<2;s++)i+=`<div data-id="${e[s].id}"><div>${e[s].title}</div><span>${e[s].content}</span></div>`;t.html(i)},e.articles_category,2)}this.history.push(e.id)}}},flashNotification:function(){clearInterval(L),L=setInterval(function(){let e=$?SBAdmin.conversations.getNotificationsCounterCount():le.notifications.length;e&&(document.title=document.title==U?"("+e+") "+s("New message"+(e>1?"s":"")):U)},2e3)},calculateLabelDates:function(){($||this.chat_open)&&(M=u.find(".sb-label-date"))},calculateLabelDateFirst:function(){this.conversation.messages.length||u.append(`<div class="sb-label-date"><span>${s("Today")}</span></div>`)},playSound:function(e=!1){this.audio.play();let t=e||($?SB_ADMIN_SETTINGS.sound.repeat:O.sound.repeat);t&&!this.tab_active&&(clearInterval(this.audio_interval),this.audio_interval=setInterval(()=>{this.audio.play(),--t||clearInterval(this.audio_interval)},1e3*this.audio.duration+1500))},isConversationAllowed:function(e,t,i){return(!O.tickets_hide||E&&"tk"==e||!E&&"tk"!=e)&&(![3,4,"3","4"].includes(t)||i&&i.includes("-message")||!E&&!O.close_chat||E&&!O.tickets_close)}};window.SBChat=le;var ce={rich_messsages:{email:"",button:"",video:"",image:"",woocommerce_button:"",rating:"",chips:'<div class="sb-buttons">[options]</div>',buttons:'<div class="sb-buttons">[options]</div>',select:'<div class="sb-select"><p></p><ul>[options]</ul></div>
1',list:'<div class="sb-text-list">[values]</div>',"list-image":'<div class="sb-image-list">[values]</div>',table:"<table><tbody>[header][values]</tbody></table>",inputs:'<div class="sb-form">[values]</div>',card:'<div class="sb-card">[settings]</div>',share:'<div class="sb-social-buttons">[settings]</div>',slider:'<div class="sb-slider"><div>[items]</div></div><div class="sb-slider-arrow sb-icon-arrow-left[class]"></div><div class="sb-slider-arrow sb-icon-arrow-right sb-active[class]"></div>',"slider-images":'<div class="sb-slider sb-slider-images"><div>[items]</div></div><div class="sb-slider-arrow sb-icon-arrow-left[class]"></div><div class="sb-slider-arrow sb-icon-arrow-right sb-active[class]"></div>'},cache:{},duplicated_email:!1,generate:function(t,i,n=""){let o,l=!0,c=t.id?t.id:se.random(),d=new oe({});if(i in this.rich_messsages)o=this.rich_messsages[i];else if(i in this.cache)o=this.cache[i];else{if(!this.isShortcode(i))return!1;t.id||(c=i),o='<div class="sb-rich-loading sb-loading"></div>',se.ajax({function:"get-rich-message",name:i,settings:t},s=>{s=this.initInputs(s),"timetable"==i&&(s=this.timetable(s)),e($&&"chatbot"==SBAdmin.active_admin_area?".sb-playground":r).find(`.sb-rich-message[id="${c}"]`).html(`<div class="sb-content">${s}</div>`),this.cache[i]=s,le.scrollBottom(le.dashboard),se.event("SBRichMessageShown",{name:i,settings:t,response:s})}),l=!1}let h=t.disabled;if(l){let n,r="";switch(i){case"email":let l=[],c=a().email,d="#"==a().get("last_name").charAt(0);"true"==t.name&&l.push(["first_name","true"==t["last-name"]?"First name":"Name",d?"":"true"==t["last-name"]?a().get("first_name"):a().name,"text",!0]),"true"==t["last-name"]&&l.push(["last_name","Last name",d?"":a().get("last_name"),"text",!0]);for(g=0;g<l.length;g++)o+=`<div id="${l[g][0]}" data-type="text" class="sb-input sb-input-text"><span class="${l[g][2]?"sb-active sb-filled":""}">${s(l[g][1])}</span><input value="${l[g][2]}" autocomplete="false" type="${l[g][3]}" ${l[g][4]?"required":""}></div>`;if("true"==t.phone){let e=a().getExtra("phone");this.cache.phone||(this.cache.phone=!0,se.ajax({function:"get-select-phone"},e=>{this.cache.phone=e,u.find("#phone .sb-select-phone").html(e)})),o+=`<div id="phone" data-type="select-input" class="sb-input sb-input-select-input"><span class="${e?"sb-active sb-filled":""}">${s("Phone")}</span><div class="sb-select-phone">${this.cache.phone?this.cache.phone:""}</div><input autocomplete="false" type="text" data-phone="true"${"false"!=t["phone-required"]?" required":""}></div>`}o+=`<div id="email" data-type="email" class="sb-input sb-input-btn"><span class="${c?"sb-active sb-filled":""}">${s(se.null(t.placeholder)?"Email":t.placeholder)}</span><input value="${c}" autocomplete="off" type="email" required><div class="sb-submit sb-icon-arrow-right"></div></div><div id="otp" class="sb-input"><span>${s("One-time code")}</span><input autocomplete="false" type="text"></div>`;break;case"image":o=`<div class="sb-image"><img loading="lazy" src="${t.url}"></div>`;break;case"video":o=`<iframe loading="lazy"${t.height?` height="${t.height}"`:""} src="https://${"youtube"==t.type?"www.youtube.com/embed/":"player.vimeo.com/video/"}${t.id}" allowfullscreen></iframe>`;break;case"select":n=t&&t.options?t.options.replace(/\\,/g,"{R}").split(","):[];for(g=0;g<n.length;g++){let e=n[g].replace(/{R}/g,",");r+=`<li data-value="${se.stringToSlug(e)}">${s(e)}</li>`}o=o.replace("[options]",r);break;case"chips":case"buttons":n=t&&t.options?t.options.replace(/\\,/g,"{R}").split(","):[];for(g=0;g<n.length;g++)r+=`<div class="sb-btn sb-submit">${s(n[g].replace(/{R}/g,",").split("|")[0])}</div>`;o=o.replace("[options]",r);break;case"button":if(t&&t.link){let e=t.link.includes("calendly.com")?"calendly":!!t.link.includes("tidycal.com")&&"tidycal";o=`<a ${e?`data-action="${e}" data-extra="${t.link}|${t.success?t.success.replaceAll('"',"'"):""}" `:""}href="${e?"#":t.link.replace(/<i>/g,"_").replace(/<\/i>/g,"_")}"${t.target&&!e?' target="_blank"':""} class="sb-rich-btn sb-btn${"link"==t.style?"-text":""}">${s(t.name)}</a>`}break;case"list":if(t.values){n=t.values.replace(/\\,/g,"{R}").replace(/\\:/g,"{R2}").replace(/:\/\//g,"{R3}").split(",");let a="list"==i,l=a&&n.length&&n[0].indexOf(":")>0;a&&!l&&(o=o.replace("sb-text-list","sb-text-list sb-text-list-single")),t.numeric&&(o=o.replace("sb-text-list","sb-text-list sb-text-list-numeric"));for(g=0;g<n.length;g++){let t=n[g].replace(/{R}/g,","),i="-"===t.substr(0,1);r+=l&&t.includes(":")?`<div><div>${s(t.split(":")[0].replace(/{R2}/g,":").replace(/{R3}/g,"://"))}</div><div>${s(t.split(":")[1].replace(/{R2}/g,":").replace(/{R3}/g,"://"))}</div></div>`:`<div${i?' data-inner="true"':""}>${e.trim(s((i?t.substr(1):t).replace(/{R2}/g,":").replace(/{R3}/g,"://")))}</div>`}o=o.replace("[values]",r)}break;case"list-image":if(t.values){n=t.values.split(",");for(g=0;g<n.length;g++){let e=n[g].replace("://","///").split(":");r+=`<div><div class="sb-thumb" style="background-image:url('${e[0].replace("///","://")}')"></div><div class="sb-list-title">${e[1]}</div><div>${e[2]}</div></div>`}o=o.replace("[values]",r)}break;case"table":if(t.values){n=t.header.split(","),r+="<tr>";for(g=0;g<n.length;g++)r+=`<th>${n[g]}</th>`;r+="</tr>",o=o.replace("[header]",r),r="",n=t.values.split(",");for(g=0;g<n.length;g++){let e=n[g].split(":");r+="<tr>";for(var p=0;p<e.length;p++)r+=`<td>${e[p]}</td>`;r+="</tr>"}o=o.replace("[values]",r)}break;case"inputs":if(t.values){n=t.values.split(",");for(g=0;g<n.length;g++)h&&!n[g]||(r+=`<div id="${se.stringToSlug(n[g])}" data-type="text" class="sb-input sb-input-text"><span>${s(n[g])}</span><input autocomplete="false" type="text" required></div>`);r+='<div class="sb-btn sb-submit">'+s(t.button?t.button:"Send now")+"</div>",o=o.replace("[values]",r)}break;case"card":r=`${t.image?`<div class="sb-card-img" style="background-image:url('${t.image}')"></div>`:""}<div class="sb-card-header">${t.header}</div>${t.extra?`<div class="sb-card-extra">${t.extra}</div>`:""}${t.description?`<div class="sb-card-description">${t.description}</div>`:""}${t.link?`<a class="sb-card-btn" href="${t.link}"${t.target?' target="_blank"':""}>${s(t["link-text"])}</a>`:""}`,o=o.replace("[settings]",r);break;case"share":let f=t.channels?t.channels.replace(/ /g,"").split(","):["fb","tw","li","wa","pi"],m="";for(g=0;g<f.length;
1g++){switch(f[g]){case"fb":m="www.facebook.com/sharer.php?u=";break;case"tw":m="twitter.com/intent/tweet?url=";break;case"li":m="www.linkedin.com/sharing/share-offsite/?url=";break;case"wa":m="web.whatsapp.com/send?text=";break;case"pi":m="www.pinterest.com/pin/create/button/?url="}r+=`<div class="sb-${f[g]} sb-icon-social-${f[g]}" data-link="https://${m}${encodeURIComponent(t[f[g]])}"></div>`}o=o.replace("[settings]",r);break;case"slider":let v=0;for(g=1;g<16&&"header-"+g in t;g++)r+=`<div>${"image-"+g in t?`<div class="sb-card-img" style="background-image:url('${t["image-"+g]}')"></div>`:""}<div class="sb-card-header">${t["header-"+g]}</div>${"extra-"+g in t?`<div class="sb-card-extra">${t["extra-"+g]}</div>`:""}${"description-"+g in t?`<div class="sb-card-description">${t["description-"+g]}</div>`:""}${"link-"+g in t?`<a class="sb-card-btn" href="${t["link-"+g]}"${t.target?' target="_blank"':""}>${s(t["link-text-"+g])}</a>`:""}</div>`,v++;o=o.replace("[items]",r).replace(/\[class\]/g,1==v?" sb-hide":"");break;case"slider-images":if(t.images){let e=t.images.split(",");for(var g=0;g<e.length;g++)r+=`<div class="sb-card-img" data-value="${e[g]}" style="background-image:url('${e[g]}')"></div>`;o=o.replace(/\[class\]/g,1==e.length?" sb-hide":"")}o=o.replace("[items]",r);break;case"woocommerce_button":t.settings=`checkout:${t.checkout},coupon:${t.coupon}`,o=`<a href="#" data-ids="${t.ids}" class="sb-rich-btn sb-btn">${t.name}</a>`;break;case"rating":o=`<div class="sb-rating-message sb-rating-${1==t.value?"positive":"negative"}"><div><i class="sb-icon-${1==t.value?"like":"dislike"}"></i> ${s(1==t.value?"Helpful":"Not helpful")}</div>${t.message?"<div>"+t.message+"</div>":""}</div>`,t.message=!1}}return`<div id="${c}" data-type="${i}"${h?'disabled="true"':""}${t.settings?` data-settings="${t.settings}"`:""}class="sb-rich-message sb-rich-${i} ${n}">`+(t.title?`<div class="sb-top">${d.render(s(t.title))}</div>`:"")+(t.message?`<div class="sb-text">${d.render(s(t.message))}</div>`:"")+`<div class="sb-content">${o}</div>${"email"==i?`<div data-success="${t.success?t.success.replace(/"/g,""):""}" class="sb-info"></div>`:""}</div>`},submit:function(i,n,o){if(!$&&!t(o)&&!this.is_busy){let t="",c="",d={},u=e(i).find("[data-success]").length?e(i).find("[data-success]").attr("data-success"):"",h=e(i).closest(".sb-rich-message").attr("id"),p=e(i).closest("[data-id]").attr("data-id"),g="",f={"rich-messages":{}},m=0==a()?{profile_image:"",first_name:"",last_name:"",email:"",password:"",user_type:""}:{profile_image:a().image,first_name:a().get("first_name"),last_name:a().get("last_name"),email:a().email,password:"",user_type:""},v={},b=e(o),w=!1!==le.conversation,S={},A={},k=i.find("#otp");if(se.null(p))p=-1;else{let e=le.conversation.getMessage(p);g=e.message,(f=e.payload())["rich-messages"]||(f["rich-messages"]={})}switch(e(o).hasClass("sb-btn")||e(o).hasClass("sb-select")||e(o).hasClass("sb-submit")||(b=e(o).closest(".sb-btn,.sb-select")),e(i).find(".sb-info").html("").sbActive(!1),n){case"email":if(v=de.getAll(i),e.each(v,function(e,t){v[e]=t[0]}),v.first_name&&(m.user_type="user",v.last_name||(m.last_name="")),v.phone&&(S={phone:[v.phone,"Phone"]}),e.extend(m,v),t="Please fill in all required fields and make sure the email is valid.",u&&(u=s(u).replace("{user_email}",m.email).replace("{user_name_}",m.first_name+(v.last_name?" "+m.last_name:""))),k.sbActive()){let e=k.attr("data-otp");m.otp=!!e&&[e,i.find("#otp input").val()]}f["rich-messages"][h]={type:n,result:v},f.event="update-user",d={function:"update-user-and-message",settings:m,settings_extra:S,payload:f,skip_otp:!0};break;case"registration":if(v=de.getAll(i.find(".sb-form-main")),S=de.getAll(i.find(".sb-form-extra")),e.each(v,function(e,t){v[e]=t[0]}),e.extend(m,v),A=e.extend({},m),u&&(u=s(u)),O.registration_details){u+='[list values="';for(var l in m){let e=m[l].replace(/:|,/g,"");e&&("profile_image"==l&&(e=e.substr(e.lastIndexOf("/")+1)),["password","password-check","envato-purchase-code","otp"].includes(l)?(e="********",A[l]="********"):u+=m[l]?`${s(se.slugToString(l.replace("first_name","name")))}:${e},`:"")}for(var l in S)S[l][0]&&(u+=`${s(S[l][1].replace(/:|,/g,""))}:${S[l][0].replace(/:|,/g,"")},`);u=u.slice(0,-1)+'"]'}if(k.sbActive()){let e=k.attr("data-otp");m.otp=!!e&&[e,i.find("#otp input").val()]}m.user_type="user",f["rich-messages"][h]={type:n,result:{user:A,extra:S}},f.event="update-user",d=O.registration_otp&&m.email&&!m.otp?{function:"otp",email:m.email}:{function:a()?"update-user-and-message":"add-user-and-login",settings:m,settings_extra:S,payload:f},t=de.getRegistrationErrorMessage(i);break;case"chips":case"select":case"buttons":v=se.escape(e(o).html()),u&&(u=s(u)+` *${v}*`),f["rich-messages"][h]={type:n,result:v},d={function:"update-message",payload:f},"chips"==n&&(le.sendMessage(a().id,v,[],!1,{id:h,event:"chips-click",result:v},"sb-human-takeover"==h&&0==b.index()&&2),"sb-human-takeover"==h&&0==e(o).index()&&ue.dialogflow.humanTakeover(),e(o).closest(".sb-content").remove());break;case"inputs":if(v=de.getAll(i),t="All fields are required.",u){u=s(u)+' [list values="';for(var l in v)u+=`${s(v[l][1].replace(/:|,/g,""))}:${v[l][0].replace(/:|,/g,"")},`;u=u.slice(0,-1)+'"]'}
1f["rich-messages"][h]={type:n,result:v},d={function:"update-message",payload:f}}if(c=g.substr(g.indexOf("["+n)),c=c.substr(0,c.indexOf("]")+1),t&&de.errors(i))return de.showErrorMessage(i,t),b.sbLoading(!1),(le.dashboard||w&&le.conversation.getLastMessage().id==p)&&le.scrollBottom(),!1;if(!u&&"registration"!=n){let e=this.shortcode(c),t=e[1].id?`id="${e[1].id}"`:"",i=e[1].title?`title="${e[1].title}"`:"",s=e[1].message?`message="${e[1].message}"`:"",a="";if(["inputs","email"].includes(n)){for(var l in v)"otp"!=l&&(a+=v[l]+",");a=`values="${a.slice(0,-1)}"`}else a=`options="${v}"`;u=`[${"email"==n?"inputs":n} ${t} ${i} ${s} ${a} disabled="true"]`}-1!=p&&(u=u.replace(/<br>/g,"\n"),e.extend(d,{message_id:p,message:g?"chips"==n?g.replace("]",' disabled="true"]'):g.replace(c,u):u,payload:f})),se.ajax(d,t=>{if(t&&!se.errorValidation(t)){switch(n){case"email":for(var l in m)a().set(l,m[l]);for(var l in S)a().setExtra(l,S[l][0]);if(se.loginCookie(t[1]),t[0].user_change)return void location.reload();"sb-follow-up"==h&&se.ajax({function:"subscribe-email",email:a().email}),le.automations.runAll(),se.event("SBNewEmailAddress",{id:h,name:a().name,email:a().email});break;case"registration":let o=i.find("#otp");if(O.registration_otp&&!o.sbActive())return o.attr("data-otp",t).sbActive(!0),o.find("input").attr("required",!0).addClass("sb-error"),de.showErrorMessage(i,s("Please check your email for the one-time code.")),le.scrollBottom(),void b.sbLoading(!1);if(se.loginCookie(t[1]),m.id=t[0].id,a()){for(var l in m)a().set(l,m[l]);for(var l in S)a().setExtra(l,S[l][0]);le.automations.runAll(),le.welcome()}else{a(new ne(t[0]));for(var l in S)a().setExtra(l,S[l][0]);this.duplicated_email&&!O.init_dashboard&&(q="open-conversation"),ae.start(),le.initChat(),this.duplicated_email||O.init_dashboard&&r.find(".sb-departments-list").length||!u||le.sendMessage(_,u,[],!1,!1,3)}le.dashboard&&(r.removeClass("sb-init-form-active"),e(i).remove(),le.isInitDashboard()||O.init_dashboard&&this.duplicated_email||le.hideDashboard()),O.wp_registration&&m.email&&m.password?ue.wordpress.ajax("wp-registration",{user_id:t[0].id,first_name:t[0].first_name,last_name:t[0].last_name,password:m.password,email:m.email}):"wp"==O.wp_users_system&&ue.wordpress.ajax("wp-login",{user:m.email,password:m.password}),delete this.cache.registration,setTimeout(()=>{se.event("SBRegistrationForm",{id:h,conversation_id:!!le.conversation&&le.conversation.id,user:m,extra:f["rich-messages"][h].result.extra})},5e3);break;case"buttons":le.scrollBottom()}-1==p?e(o).closest(".sb-rich-message").html(u):(b.sbLoading(!1),f.type&&"close-message"==f.type||y||le.setConversationStatus(2)),["login","chips"].includes(n)||!O.dialogflow_send_user_details&&["email","registration"].includes(n)||ue.dialogflow.message(`${h}${dialogflow_response?"|"+dialogflow_response:""}`),!O.slack_active||y&&!ue.dialogflow.humanTakeoverActive()||ue.slack.message(a().id,a().name,a().image,u),ae.active&&le.update(),"registration"!=n&&"email"!=n&&se.event("SBRichMessageSubmit",{result:t,data:f["rich-messages"][h],id:h})}else"registration"!=n&&"email"!=n||!se.errorValidation(t,"duplicate-email")?(this.duplicated_email=!1,de.showErrorMessage(i,de.getRegistrationErrorMessage(t,"response"))):(se.ajax({function:"otp",email:m.email},e=>{let t=i.find("#otp");t.attr("data-otp",e).sbActive(!0),t.find("input").attr("required",!0).addClass("sb-error"),de.showErrorMessage(i,s("This email is already in use. Please check your email for the one-time code.")),"registration"==n&&(i.find(".sb-submit").html(s("Sign in")),le.scrollBottom())}),this.duplicated_email=!0),le.dashboard&&le.scrollBottom(),b.sbLoading(!1)})}},shortcode:function(t){let i={},s=t.includes(" ")?t.substr(1,t.indexOf(" ")-1):t.slice(1,-1);if(/\?|"|'|`|\*/gi.test(s))return[!1,!1];let a=(t=t.slice(1,-1).substr(s.length+1)).split('" ');for(var n=0;n<a.length;n++)if(a[n].includes("=")){let t=[a[n].substr(0,a[n].indexOf("=")),a[n].substr(a[n].indexOf("=")+2)];i[e.trim(t[0])]=t[1].replace(/"/g,"")}return[s,i]},initInputs:function(t){return(t=e(e.parseHTML("<div>"+t+"</div>"))).find(".sb-input input").each(function(){e(this).val()&&e(this).siblings().addClass("sb-active sb-filled")}),t.html()},timetable:function(t){let i=e(e.parseHTML(`<div>${t}</div>`)),a=i.find("[data-offset]").attr("data-offset");return a=se.null(a)?0:parseFloat(a),i.find("[data-time]").each(function(){let n=e(this).attr("data-time").split("|");t="";for(var o=0;o<n.length;o++){if(!n[o]||"closed"==n[o]){t+=s("Closed");break}if(n[o]){let e=n[o].split(":"),i=se.convertUTCDateToLocalDate(`01/01/2000 ${e[0]}:${e[1]}`,a);t+=i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})+(0==o||2==o?`<span>${s("to")}</span>`:1==o&&n[o+1]?"<br />":"")}}i.find(" > div > span").html(`<i class="sb-icon-clock"></i> ${s("Time zone")} ${Intl.DateTimeFormat().resolvedOptions().timeZone}`),e(this).html(t)}),i.html()},sliderChange:function(e,t="left"){let i=u.find(`#${e}`);if(i.length&&!i.hasClass("sb-moving")){let e=i.find(".sb-slider > div > div"),s=e.eq(0),a=Math.ceil(s.closest(".sb-slider").width()),n="right"==t?-1:1,o=parseFloat(parseFloat(parseFloat(s.css("margin-left"))+a*n)),r=a*(e.length-1)*-1;o<1&&o>=r&&(s.css("margin-left",o+"px"),i.addClass("sb-moving"),setTimeout(()=>{i.removeClass("sb-moving")},1200)),i.find(".sb-icon-arrow-right").sbActive(!(r>o-15&&r<o+15)),i.find(".sb-icon-arrow-left").sbActive(o<-10)}},iframe:{script_loaded:!1,load:function(e,t,i,a){if(t=t.split("|"),ce.iframe.
1script_loaded)"calendly"==e?this.load_(e,t[0],i):b.sbActive(!0).attr("data-id",e);else{let n={calendly:["https://assets.calendly.com/assets/external/widget.js"],tidycal:["https://asset-tidycal.b-cdn.net/js/embed.js"]}[e];"tidycal"==e&&this.load_(e,t[0],i),se.loadResource(n[0],!0,()=>{ce.iframe.script_loaded=!0,window.addEventListener("message",function(i){console.log(i),("calendly"==e&&"https://calendly.com"===i.origin&&"calendly.event_scheduled"==i.data.event||"tidycal"==e&&"https://tidycal.com"===i.origin&&i.data.data&&i.data.data.booking)&&(le.updateMessage(a,s(t[1]?t[1]:"Booking completed.")),b.sbActive(!1))}),"calendly"==e&&this.load_(e,t[0],i)})}},load_:function(e,t,i){"calendly"==e&&Calendly.initInlineWidget({url:(t.includes("http")?"":"https://")+t+"?hide_landing_page_details=1&hide_event_type_details=1&hide_gdpr_banner=1",parentElement:b.find("> div").eq(1),prefil:"user"==a().type?{name:a().name,email:a().email}:{}}),"tidycal"==e&&b.find("> div").eq(1).html(`<div class="sb-scroll-area"><div class="tidycal-embed" data-path="${t.replace("https://tidycal.com/","")}"></div></div>`),b.find(">
1 div:first-child > div").html(s(i)),b.sbActive(!0).attr("data-id",e)}},rating:function(e=!1){b.find("> div:first-child > div").html(s(O.rating_title)),b.find("> div:last-child").html(`<div class="sb-text">${s(O.rating_text)}</div>${O.rating_message?`<div class="sb-input sb-input-textarea"><textarea placeholder="${s("Add a message here...")}"></textarea></div>`:""}<div class="sb-rating"><div><i data-rating="positive" class="sb-submit sb-icon-like"><span>${s("Helpful")}</span></i><i data-rating="negative" class="sb-submit sb-icon-dislike"><span>${s("Not helpful")}</span></i></div></div>`),b.sbActive(!0).attr("data-id","rating").attr("data-close-chat",e?"true":"")},isShortcode:function(e){return e in this.rich_messsages||$&&SB_ADMIN_SETTINGS.rich_messages.includes(e)||!$&&O.rich_messages.includes(e)}};window.SBRichMessages=ce;var de={getAll:function(t){let i={};return e(t).find(".sb-input[id]").each((t,s)=>{i[e(s).attr("id")]=this.get(s)}),i},get:function(t){let i=(t=e(t)).data("type"),a=s(se.escape(t.find(" > span").html()));switch(i){case"image":let e=t.find(".image").attr("data-value");return[se.null(e)?"":e,a];case"select":return[se.escape(t.find("select").val()),a];case"select-input":let s=t.find("select,input[disabled]");return[se.escape((s.is("select")||s.is("input")?s.val():t.find(".sb-select").length?t.find(".sb-select > p").attr("data-value"):t.find("> div").html())+t.find("> input").val()),a];default:let n=t.find("input");return[se.escape(n.length?n.val():t.find("[data-value]").attr("data-value")),a]}},set:function(t,i){if((t=e(t)).length){switch(t.data("type")){case"image":i?t.find(".image").attr("data-value",i).css("background-image",`url("${i}")`):t.find(".image").removeAttr("data-value").removeAttr("style");break;case"select":t.find("select").val(i);break;default:t.find("input,textarea").val(i)}return!0}return!1},clear:function(t){e(t).find(".sb-input,.sb-setting").each((t,i)=>{this.set(i,""),e(i).find("input, select, textarea").removeClass("sb-error")}),this.set(e(t).find("#user_type"),"user")},errors:function(t){let i=!1,s=e(t).find("input, select, textarea").removeClass("sb-error");return s.each(function(t){let a=e.trim(e(this).val()),n=e(this).attr("type"),o=e(this).prop("required");(o&&!a||(o||a)&&("password"==n&&(a.length<8||s.length>t+1&&"password"==s.eq(t+1).attr("type")&&s.eq(t+1).val()!=a)||"email"==n&&(!a.includes("@")||!a.includes(".")||/;|:|\/|\\|,|#|"|!|=|\*|{|}|[|]|£|\$|â¬|~|'|>|<|\^|&/.test(a))||e(this).attr("data-phone")&&a&&(!e(this).parent().find("select").val()&&!e(this).prev().find("> div > p").attr("data-value")&&!e(this).parent().find("div").html().trim().startsWith("+")||isNaN(a)||a.includes("+")||a.length<5)))&&(i=!0,e(this).addClass("sb-error"))}),(s=e(t).find("[data-required]").removeClass("sb-error")).each(function(){se.null(e(this).attr("data-value"))&&(e(this).addClass("sb-error"),i=!0)}),i},showErrorMessage:function(t,i){e(t).find(".sb-info").html(s(i)).sbActive(!0),clearTimeout(R),R=setTimeout(function(){e(t).find(".sb-info").sbActive(!1)},7e3)},showSuccessMessage:function(t,i){e(t).find(".sb-info").remove(),e(t).addClass("sb-success").find(".sb-content").html(`<div class="sb-text">${i}</div>`)},getRegistrationErrorMessage(t,i="validation"){let a="";return"response"==i?se.errorValidation(t,"duplicate-email")?"This email is already in use. Please use another email.":se.errorValidation(t,"duplicate-phone")?"This phone number is already in use. Please use another number.":se.errorValidation(t,"invalid-envato-purchase-code")||se.errorValidation(t,"invalid-boxcoin-license-key")?"Invalid license key.":se.errorValidation(t,"invalid-otp")?"Invalid one-time code.":"Error. Please check your information and try again.":(e(t).find(".sb-input:not(#password-check) [required]").each(function(){a+=", "+e(this).closest(".sb-input").find("span").html()+("password"==e(this).attr("type")?" ("+s("8 characters minimum")+")":"")}),`${a.substring(2)} ${s((a.includes(",")?"are":"is")+" required.")}`)}};window.SBForm=de;var ue={login:function(){return typeof SB_DEFAULT_USER!=G&&SB_DEFAULT_USER?[SB_DEFAULT_USER,"default"]:this.is("wp")&&typeof SB_WP_ACTIVE_USER!=G&&"wp"==O.wp_users_system?[[SB_WP_ACTIVE_USER,typeof SB_WP_AVATAR!=G?SB_WP_AVATAR:""],"wp"]:typeof SB_SHOPIFY_ACTIVE_USER!=G?[SB_SHOPIFY_ACTIVE_USER,"shopify"]:typeof SB_PERFEX_ACTIVE_USER!=G?[[SB_PERFEX_ACTIVE_USER,SB_PERFEX_CONTACT_ID],"perfex"]:typeof SB_WHMCS_ACTIVE_USER!=G?[SB_WHMCS_ACTIVE_USER,"whmcs"]:typeof SB_AECOMMERCE_ACTIVE_USER!=G&&[SB_AECOMMERCE_ACTIVE_USER,"aecommerce"]},is:function(e){return $?SBAdmin.apps.is(e):"wordpress"==e||"wp"==e?O.wp:e in O&&O[e]},shopify:{startCartSynchronization:function(){setInterval(()=>{a()&&fetch("/cart.js").then(e=>e.json()).then(e=>{e={total:e.total_price,currency:e.currency,items:e.items.map(e=>({id:e.product_id,price:e.price,handle:e.handle,title:e.title,quantity:e.quantity}))};let t=JSON.stringify(e);i("shopify-cart")!=t&&(i("shopify-cart",t),se.ajax({function:"shopify-cart-sync",cart:e}))})},1e4)}},wordpress:{ajax:function(t,i,s=!1){if(typeof SB_WP_AJAX_URL==G)return!!s&&s(!1);e.ajax({method:"POST",url:SB_WP_AJAX_URL,data:e.extend({action:"sb_wp_ajax",type:t},i)}).done(e=>{s&&s(e)})}},dialogflow:{typing_enabled:!0,project_id:!1,busy:!1,message:function(t="",i=[],s=!1){if(!(t.length<2)||i.length){if(!s)for(var a=0;a<i.length;a++)i[a][0].includes("voice_message")&&(s=i[a][1]);e(".sb-emoji-list").html().includes("<li>"+t+"</li>")||this.openAI(t,!1,s,i)}},openAI:function(t,i=!1,s=!1,n=[]){if(O.is_chatbot_active){if(le.headerAgent(!0),le.agent_id!=_||ue.dialogflow.humanTakeoverActive()&&!this.t
1yping_enabled||this.typing(),this.chatbotLimit())return le.sendMessage(_,this.chatbotLimit());setTimeout(()=>{se.ajax({function:"open-ai-message",message:t,conversation_id:!!le.conversation&&le.conversation.id,audio:s,extra:{token:ue.dialogflow.token},attachments:n,context:!!O.open_ai_context_awareness&&(document.title.toUpperCase()+"\n\n\n"+e('meta[name="description"]').attr("content")||"")},e=>{this.busy=!1,le.typing(-1,"stop"),se.event("SBOpenAIMessage",{response:e,message:t}),e&&(e[0]||e[5])?(O.chatbot_limit&&this.chatbot_limit++,O.slack_active&&t&&(!y||ue.dialogflow.humanTakeoverActive())&&ue.slack.message(a().id,O.bot_name,O.bot_image,e[1]),e[3]&&(le.offlineMessage(),le.followUp()),e[5]&&(e[5].redirect&&setTimeout(()=>{document.location=e[5].redirect},500),e[5].open_article&&le.showArticles(e[5].open_article),"conversation-status-update-3"==e[5].event&&le.conversationArchived(),e[5].login_cookie&&(se.loginCookie(e[5].login_cookie[1]),a(new ne(e[5].login_cookie[0])))),this.chatbotLimit(!1)):!1!==e[1]&&se.error(e[1].error?e[1].error.message:e[1],"SBApps.dialogflow.openAI"),i&&i(e)}),this.busy=!0},0==O.bot_delay?2e3:1e3*parseInt(O.bot_delay))}},flowOnLoad(){O.flow_on_load&&!i("flow-on-load")&&a()&&(le.conversation?se.ajax({function:"run-flow-on-load",message:O.flow_on_load,conversation_id:le.conversation.id}):le.newConversation(3,a().id,"",[],null,null,()=>{se.ajax({function:"run-flow-on-load",message:O.flow_on_load,conversation_id:le.conversation.id})}),i("flow-on-load",!0))},typing:function(){clearTimeout(I),I=setTimeout(()=>{le.typing(-1,"start")},1e3)},active:function(e=!0){return!1===e?(le.conversation.set("is_human_takeover",!0),!1):("activate"==e&&le.conversation.set("is_human_takeover",!1),!(!$&&ue.dialogflow.humanTakeoverActive()&&O.dialogflow_human_takeover_disable_chatbot)&&(O.is_chatbot_active&&!$&&(!le.conversation||!ue.dialogflow.humanTakeoverActive()||!le.agent_online)&&(!O.dialogflow_office_hours||!O.office_hours)))},humanTakeover:function(){se.ajax({function:"human-takeover",conversation_id:le.conversation.id},()=>{le.offlineMessage(),le.followUp(),this.active(!1),O.queue_human_takeover&&(O.queue=!0,le.queue(le.conversation.id))})},humanTakeoverActive:function(){return!!le.conversation&&le.conversation.get("is_human_takeover")},translate:function(e,t,i,s,a){se.ajax({function:"google-translate",strings:e,language_code:t,message_ids:s,conversation_id:a},e=>{i(e)})},chatbotLimit:function(e=!0){if(O.chatbot_limit){let s=i("chatbot_limit"),a=(new Date).getTime()/1e3;if(s||(s=[]),e){let e=a-O.chatbot_limit.interval,n=[];for(var t=0;t<s.length;t++)s[t]>e&&n.push(s[t]);if(i("chatbot_limit",n),n.length>=O.chatbot_limit.quota)return O.chatbot_limit.message}else s.push(a),i("chatbot_limit",s)}return!1}},woocommerce:{updateCart:function(e,t,i=!1){ue.wordpress.ajax(e,{product_id:t},i)},waitingList:function(e="request",t=!1){typeof SB_WP_WAITING_LIST!==G&&("request"!=e||SB_WP_WAITING_LIST&&se.storageTime("waiting-list-"+SB_WP_PAGE_ID,24))&&a()&&se.ajax({function:"woocommerce-waiting-list",product_id:!1===t?SB_WP_PAGE_ID:t,conversation_id:le.conversation.id,action:e,token:this.token},t=>{t&&(se.storageTime("waiting-list-"+SB_WP_PAGE_ID),"request"!=e||le.chat_open&&!le.dashboard||le.updateConversations())})}},aecommerce:{cart:function(){ue.is("aecommerce")&&typeof SB_AECOMMERCE_CART!=G&&typeof SB_AECOMMERCE_ACTIVE_USER!=G&&i("aecommerce")!=JSON.stringify(SB_AECOMMERCE_CART)&&se.ajax({function:"aecommerce-cart",cart:SB_AECOMMERCE_CART},()=>{i("aecommerce",JSON.stringify(SB_AECOMMERCE_CART))})}},martfury:{privateChat:function(){let t=e("#tab-vendor > h4,.ps-product__vendor > a");if(t.length){t=t.html().toLowerCase();for(var i=0;i<O.martfury.length;i++)if(t==O.martfury[i]["martfury-linking-store"].toLowerCase()){let e=O.martfury[i]["martfury-linking-agent"],t=se.activeUser()?se.activeUser().conversations:[];le.default_agent=e;for(var s=0;s<t.length;s++)if(t[s].get("agent_id")==e)return void le.openConversation(t[s].id);le.clear(),le.hideDashboard()}}}},whatsapp:{call:{answer:function(e,t){const i=$?SBAdmin.conversations.active_calls[e]:ie;i&&se.call.initRTC(e=>{se.ajax({function:"whatsapp-call-answer",phone_number_id:i.phone_number_id,call_id:i.id,sdp_answer:e.sdp},()=>{se.ajax({function:"whatsapp-call-answer",phone_number_id:i.phone_number_id,call_id:i.id,sdp_answer:e.sdp,is_accept:!0},e=>{t(e)})})},i.session.sdp)},decline:function(e,t,i){const s=$?SBAdmin.conversations.active_calls[e]:ie;s&&se.ajax({function:"whatsapp-call-decline",phone_number_id:s.phone_number_id,call_id:s.id,is_terminate:t},e=>{i(e)})},start:function(e,t,i){se.ajax({function:"whatsapp-call-start",sdp:e,user_id:t},e=>{e.error?se.error(e.error.message,"SBApps.whatsapp.call.start"):"request-sent"==e&&$?SBAdmin.infoPanel("Call permission request sent successfully. The user will receive a message asking for consent to receive voice calls."):ie=e,i(e)})}}},slack:{slack_channel:[-1,-1],message:function(e,t,i,s,n=[]){if(!le.conversation||!s&&!n.length)return!1;let o=le.conversation.id;se.ajax({function:"send-slack-message",user_id:e,full_name:t,profile_image:i,conversation_id:o,message:s,attachments:n,channel:this.slack_channel[0]==a().id&&this.slack_channel[1]},e=>{this.slack_channel=[a().id,e[1]],se.event("SBSlackMessageSent",{message:s,conversation_id:o,slack_channel:e[1]})})}}};window.SBApps=ue,e(document).ready(function(){if((r=e(".sb-admin, .sb-admin-start")).length)return $=!0,void o();let t,i,s=!1;if(typeof SB_INIT_URL!=G)SB_INIT_URL.includes(".js")||(SB_INIT_URL+="/js/main.js?v=3.9.1"),t=SB_INIT_URL;else{let e=document.getElementsByTagName("script"),i=["init.js","main.js","min/init.min.js","min/main.min.js"];for(var a=0;a<e.length;a++){let o=e[a].src;if("sbinit"==e[a].id){t=o,s=s||t.includes("init.");break}for(var n=0;n<i.length;n++)if(o&&o.includes("/supportboard/js/"+i[n])){t=o,s=s||t.includes("init.");break}}}let l=se.getURL(!1,t);if(l.url&&(t=l.url),typeof SB_DISABLED!=G&&SB_DISABLED)return;if(s)return void o();typeof SB_TICKETS==G&&"tickets"!=l.mode||(E=!0,l.mode="tickets"),l.cloud&&(V=l.cloud);let c=!(!ee||"en"==Shopify.locale)&&Shopify.locale,d=t.lastIndexOf("main.min.js"),u=(i=t.substr(0,t.lastIndexOf("main.js")>0?t.lastIndexOf("main.js")-4:d-8))+"/include/init.php"+(l.lang?"?lang="+l.lang:"")+(c?"?lang_optional="+c:"")+(l.mode?"&mode="+l.mode:"")+(V?"&cloud="+V:"");se.cors("GET",u.replace(".php&",".php?"),t=>{let s="body";E&&e("#sb-tickets").length&&(s="#sb-tickets"),e(s).append(t),se.loadResource(i+"/css/"+(E?"tickets":"main")+".css"),E?se.loadResource(i+"/apps/tickets/tickets"+(d>0?".min":"")+".js?v=3.9.1",!0,()=>{o()}):o(),l.lang&&(SB_LANG=[l.lang,$?"admin":"front"])})})}(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.