"use strict";function _readOnlyError(t){throw new TypeError('"'+t+'" is read-only')}function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function _objectSpread(t){for(var e=1;e")),this.storage.setItem("clicked",(new Date).getTime()))}},{key:"trackWidgetView",value:function(){if(this.isDashboard())console.debug("Not tracking dashboard views");else{if(!this.storage.getItem("viewed")){var t={"Api-Token":this.settings.cid};fetch(this.getApiUrl("/v1/trackings/widget_view"),{headers:t,method:"post"})}this.storage.setItem("viewed",(new Date).getTime())}}},{key:"getWidgetUrl",value:function(t){switch(t){case"widgetCode":var e=new URLSearchParams(window.location.search),n=Object.fromEntries(e.entries());return"".concat(this.settings.portal_url,"/w/").concat(n.widgetCode,"/new");case"defaultWidget":return this.getDefaultWidgetUrl();default:return"".concat(this.settings.portal_url,"/widgets/").concat(t,"/bid_requests/new")}}},{key:"getDefaultOpenState",value:function(){return!1!==this.settings.forceOpen&&(!!this.settings.fullscreenSelector||(this.isMobile()?this.settings.widget_mobile_alwayson:this.settings.widget_desktop_alwayson))}},{key:"isMobile",value:function(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"isWidgetOpen",value:function(){if(this.settings.fullscreenSelector&&null!==document.querySelector(this.settings.fullscreenSelector))return!0;var t=new URLSearchParams(window.location.search),e=Object.fromEntries(t.entries());if(e.widgetCode)return!0;if("true"===e[this.settings.prefix])return!0;var n=this.storage.getItem("opened");return null===n?this.getDefaultOpenState():"false"!==n}},{key:"getDefaultWidgetUrl",value:function(){return"".concat(this.settings.appUrl,"/widget/").concat(this.settings.cid)}},{key:"syncStorageState",value:function(t,e){var n=this;this.isWidgetOpen()&&e.forEach((function(t){return t.classList.add(n.getWidgetClass("hidden"))}))}},{key:"injectWidgetButtons",value:function(t){var e=this;if(!this.settings.show_button||this.settings.suppressButton)return[];document.body.insertAdjacentHTML("beforeend",'\n
\n \n "));var n=[document.getElementById(this.getWidgetClass("floating-button")),document.getElementById(this.getWidgetClass("wide-button"))];return n.forEach((function(n){n.onclick=function(){e.showWidget(t),e.trackClick(),e.trackEvent("Clicked ".concat(e.settings.app," Button"))}})),n}},{key:"showWidget",value:function(t){var e=this;t.classList.remove("closed"),[document.getElementById(this.getWidgetClass("floating-button")),document.getElementById(this.getWidgetClass("wide-button"))].filter((function(t){return t})).forEach((function(t){return t.classList.add(e.getWidgetClass("hidden"))})),console.debug("showing widget..."),this.storage.setItem("opened",!0),this.trackWidgetView()}},{key:"reloadWidget",value:function(t){var e=this;this.hideWidget(t),this.loadUrl(t).then((function(){return e.showWidget(t)})),sessionStorage.clear()}},{key:"hideWidget",value:function(t){var e=this;return new Promise((function(n,i){t.classList.add("closed"),[document.getElementById(e.getWidgetClass("floating-button")),document.getElementById(e.getWidgetClass("wide-button"))].filter((function(t){return t})).forEach((function(t){return t.classList.remove(e.getWidgetClass("hidden"))})),console.debug("hiding widget..."),e.storage.setItem("opened",!1),n()}))}},{key:"loadUrl",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return new Promise((function(i,o){t.onload=function(){return i()},t.src=e.getWidgetUrl(n||e.getWidgetId()),n&&e.storage.setItem("widgetId",n)}))}},{key:"getWidgetId",value:function(){var t=new URLSearchParams(window.location.search),e=Object.fromEntries(t.entries());if(e.widgetCode)return"widgetCode";var n=e.widgetId||this.settings.widgetId;return n||(this.storage.getItem("widgetId")||"defaultWidget")}},{key:"setWidgetStorageItem",value:function(t,e){var n="".concat(this.settings.prefix,"_").concat(this.settings.cid.substring(3,8),"_v2_widget_storage"),i=JSON.parse(sessionStorage.getItem(n)||"{}");i[t]=e,sessionStorage.setItem(n,JSON.stringify(i))}},{key:"getWidgetStorageItem",value:function(t){var e="".concat(this.settings.prefix,"_").concat(this.settings.cid.substring(3,8),"_v2_widget_storage");return JSON.parse(sessionStorage.getItem(e)||"{}")[t]}},{key:"handleWidgetEvents",value:function(t){var e=this;window.onmessage=function(n){var i=n.data;if(i.action)switch(i.action){case"minimize":!e.settings.fullscreenSelector&&e.hideWidget(t);break;case"reload":e.reloadWidget(t);break;case"track":var o=i.data,a=o.action,s=o.label;e.trackEvent(a,s);break;case"setItem":e.setWidgetStorageItem(i.key,i.value),e._postStorageChange(t);case"loadStorage":e._postStorageChange(t)}}}},{key:"_postStorageChange",value:function(t){var e="".concat(this.settings.prefix,"_").concat(this.settings.cid.substring(3,8),"_v2_widget_storage"),n=JSON.parse(sessionStorage.getItem(e)||"{}");console.debug("onStorageChange",n),t.contentWindow.postMessage({action:"onStorageChange",data:n},"*")}},{key:"trackEvent",value:function(t,e){var n="event",i=this.settings.app;"undefined"!=typeof gtag?gtag(n,t,{event_category:i,event_label:i}):"undefined"!=typeof ga&&ga("send",n,i,t,e)}},{key:"buildFrameElement",value:function(){var t=document.createElement("iframe");return t.style.border=0,t.classList.add(this.getWidgetClass("widget")),t.classList.add("closed"),t.style.zIndex=2e7,t}},{key:"injectStyles",value:function(){var t='');document.head.insertAdjacentHTML("beforeend",t),document.head.appendChild(this.buildCustomStylesElement())}},{key:"initializeAnalytics",value:function(){var t,e,n,i,o,a;if(0!==this.settings.ga_property_id.indexOf("UA-")){if("undefined"==typeof gtag){var s=document.createElement("script");s.src="https://www.googletagmanager.com/gtag/js?id=".concat(this.settings.ga_property_id),s.async=1,document.body.appendChild(s),window.dataLayer=window.dataLayer||[],window.gtag=function(){dataLayer.push(arguments)}}}else if("undefined"==typeof ga){"development"===this.settings.env&&_readOnlyError("gaScript"),t=window,e=document,n="script",i="ga",t.GoogleAnalyticsObject=i,t.ga=t.ga||function(){(t.ga.q=t.ga.q||[]).push(arguments)},t.ga.l=1*new Date,o=e.createElement(n),a=e.getElementsByTagName(n)[0],o.async=1,o.src="https://www.google-analytics.com/analytics.js",a.parentNode.insertBefore(o,a)}}},{key:"trackWidgetLoad",value:function(){"undefined"!=typeof ga&&(ga("create",this.settings.ga_property_id,"auto"),"development"===this.settings.env&&ga("set","sendHitTask",null)),"undefined"!=typeof gtag&&(gtag("js",new Date),gtag("config",this.settings.ga_property_id))}},{key:"buildCustomStylesElement",value:function(){var t=document.createElement("style"),e=this.settings.styleConfig({prefix:this.settings.prefix,settings:this.settings}).join("\n");return t.appendChild(document.createTextNode(e)),t.type="text/css",t}}]),e}();new e(window.__smilesnap).load();var n=function(){document.documentElement.style.setProperty("--app-height","".concat(window.innerHeight,"px"))};window.addEventListener("resize",n),n()}))}(),window.__smilesnap.styleConfig=function(t){var e=t.prefix,n=t.settings,i=[];return i.push("\n #".concat(e,", .").concat(e,"-widget {\n left: unset !important;\n right: unset !important;\n ").concat(n.widget_desktop_position.toLowerCase(),": ").concat(n.widget_desktop_margin_horizontal,"px !important;\n bottom: ").concat(n.widget_desktop_margin_vertical,"px !important;\n border-radius: 10px;\n height: ").concat(n.widget_desktop_height,"px;\n width: ").concat(n.widget_desktop_width,"px;\n }\n ")),i.push("@media only screen and (max-width: 767px) {\n :root {\n --app-height: 100vh;\n }\n\n #".concat(e,", .").concat(e,"-widget {\n ").concat(n.widget_mobile_position.toLowerCase(),": 0px !important;\n border-radius: 0px;\n }\n\n #").concat(e," {\n left: unset !important;\n right: unset !important;\n }\n\n .").concat(e,"-widget {\n left: 0 !important;\n right: 0 !important;\n position: fixed;\n bottom: 0 !important;\n height: 100vh;\n height: calc(var(--vh, 1vh) * 100);\n height: var(--app-height);\n min-width: 100%;\n z-index: 1000;\n max-width: 0;\n max-height: 100%;\n }\n }")),n.widget_header_background&&i.push("div#".concat(e," div#").concat(e,"-header {\n background-color: ").concat(n.widget_header_background,";\n ").concat(n.widget_header_gradient_background?"background: linear-gradient(135deg, ".concat(n.widget_header_background," 0%, ").concat(n.widget_header_gradient_background," 100%);"):"","\n }")),n.widget_button_color&&i.push("div#".concat(e," button, div#").concat(e," .").concat(e,"-btn {\n background: ").concat(n.widget_button_color,";\n border: 1px solid ").concat(n.widget_button_color,";\n }\n div#").concat(e,"-spinner {\n border-top: 16px solid ").concat(n.widget_button_color,";\n }\n div#").concat(e," .").concat(e,"-question-list.").concat(e,"-numbered-list > li::before {\n background-color: ").concat(n.widget_button_color,";\n }")),n.show_button?(i.push("div#".concat(e,"-wide-button, div#").concat(e,"-floating-button { left: unset !important; right: unset !important;\n ").concat("Center"==n.button_desktop_position?"left: ".concat(n.button_desktop_margin_horizontal,"px !important;\n right: ").concat(n.button_desktop_margin_horizontal,"px !important;\n margin: 0 auto;"):"".concat(n.button_desktop_position.toLowerCase(),": ").concat(n.button_desktop_margin_horizontal,"px !important;"),"\n bottom: ").concat(n.button_desktop_margin_vertical,"px !important;\n background: ").concat(n.button_color||"rgb(30, 136, 228)",";\n }")),i.push("div#".concat(e,"-wide-button {\n ").concat(0!=n.button_desktop_width?"width: ".concat(n.button_desktop_width,"px !important;"):"","\n display: ").concat("Button"!=n.button_desktop_type?"none":"table-cell",";\n }")),i.push("div#".concat(e,"-floating-button {\n display: ").concat("Icon"!=n.button_desktop_type?"none":"flex",";\n }")),i.push("@media only screen and (max-width: 767px) {\n div#".concat(e,"-wide-button, div#").concat(e,"-floating-button { left: unset !important; right: unset !important;\n ").concat("Center"==n.button_mobile_position?"left: ".concat(n.button_mobile_margin_horizontal,"px !important;\n right: ").concat(n.button_mobile_margin_horizontal,"px !important;\n margin: 0 auto;"):"".concat(n.button_mobile_position.toLowerCase(),": ").concat(n.button_mobile_margin_horizontal,"px !important;"),"\n bottom: ").concat(n.button_mobile_margin_vertical,"px !important;\n }\n\n div#").concat(e,"-wide-button {\n ").concat(0!=n.button_mobile_width?"width: ".concat(n.button_mobile_width,"px !important;"):"","\n display: ").concat("Button"!=n.button_mobile_type?"none":"table-cell",";\n }\n\n div#").concat(e,"-floating-button {\n display: ").concat("Icon"!=n.button_mobile_type?"none":"flex",";\n }\n }"))):i.push("#".concat(e,"-wide-button, #").concat(e,"-floating-button { display: none !important; }")),i};