t.r===s));a.length>0?(e.src=a[0].thumbnail,o.querySelector(".ti-more-image-count").innerHTML="+"+a.length-1,1===a.length&&o.classList.remove("ti-has-more-image")):o.remove()}))}))}}class w{constructor(t){this.data=t.TrustindexReviewImageModule.data,this.widget=t,this.isLongScroll="popup"===this.widget.reviewTextMode,this.reviewMediaContainer=null}init(){if(this.isLongScroll)return this.initLongScroll();let t=``;this.lightbox=(new DOMParser).parseFromString(t,"text/html").querySelector(".ti-widget-lightbox"),this.image=this.lightbox.querySelector(".ti-card-media img"),this.reviewContent=this.lightbox.querySelector(".ti-review-content"),this.prevArrow=this.lightbox.querySelector(".ti-arrow-prev"),this.nextArrow=this.lightbox.querySelector(".ti-arrow-next"),this.currentIndex=0,this.currentReview=null,this.addWidgetStyles(),this.addEvents()}initLongScroll(){let t=``;this.isMoving=!1,this.lightbox=(new DOMParser).parseFromString(t,"text/html").querySelector(".ti-widget-lightbox"),this.lightbox.reviewsContainer=this.lightbox.querySelector(".ti-widget-lightbox-review-container"),this.lightbox.reviewsContainerInner=this.lightbox.querySelector(".ti-widget-lightbox-review-container-inner"),this.lightbox.mobileCloseBottom=this.lightbox.querySelector(".ti-widget-lightbox-mobile-close-bottom"),this.lightbox.mobileCloseBottomSwipe=this.lightbox.querySelector(".ti-widget-lightbox-mobile-close-bottom-swipe"),this.widget.classList.contains("ti-custom-stars")&&this.lightbox.classList.add("ti-custom-stars"),this.widget.querySelectorAll(".ti-review-item").forEach((t=>{let e=document.createElement("div");e.classList.add("ti-review-item");let i=t.querySelector(".ti-review-header").cloneNode(!0);i.classList.add("ti-lightbox-review-header");let s=t.querySelector(".ti-review-text-container").cloneNode(!0);s.setAttribute("class","ti-review-text"),s.setAttribute("style",""),s.querySelectorAll(".ti-review-image").forEach((t=>t.remove())),e.appendChild(i);let r=t.querySelector(".ti-stars");r&&e.appendChild(r.cloneNode(!0));let o=[];if(this.data.forEach((e=>{e.r===t.getAttribute("data-id")&&o.push(e)})),o.length>0){let t="",i="";o.forEach(((e,s)=>{t+=``,i+=``}));let s=(new DOMParser).parseFromString(`\n\t\t\t\t\t\n\t\t\t\t`,"text/html").querySelector(".ti-card-media");s.querySelector(".ti-card-media-thumbnail:first-child").classList.add("ti-active"),1===o.length&&(s.querySelector(".ti-arrow-prev").remove(),s.querySelector(".ti-arrow-next").remove(),s.querySelector(".ti-card-media-thumbnails").remove()),e.appendChild(s)}e.appendChild(s),t.classList.contains("ti-ai-summary-item")?(e.classList.add("ti-ai-summary-item"),e.classList.add("ti-lightbox-review-item"),s.classList.add("ti-review-content")):e.setAttribute("data-id",t.getAttribute("data-id")),this.lightbox.reviewsContainerInner.appendChild(e)})),this.addWidgetStyles(),this.addLongScrollEvents()}addWidgetStyles(){this.widget.classList.contains("ti-custom-stars")&&this.lightbox.classList.add("ti-custom-stars"),this.lightbox.style.fontFamily=window.getComputedStyle(this.widget.container,null).getPropertyValue("font-family")}addEvents(){let t,e,i,s;this.image.onload=()=>this.image.parentNode.classList.remove("ti-image-loading");let r=!1,o=!1;this.image.addEventListener("touchstart",(a=>{t=a.touches[0].pageX,i=a.touches[0].pageY,e=null,s=null,r=!1,o=!1}),{passive:!0}),this.image.addEventListener("touchmove",(a=>{e=a.touches[0].pageX,s=a.touches[0].pageY;let n=e-t,l=s-i;Math.abs(l)>10&&!r&&(o=!0),!o&&(Math.abs(n)>10||r)&&(r=!0)}),{passive:!0}),this.image.addEventListener("touchend",(i=>{if(r&&!o&&t&&e&&Math.abs(t-e)>25){let i=this.currentIndex-1;t>e&&(i=this.currentIndex+1),this.change(i)}return t=null,e=null,r=!1,o=!1,!1}),{passive:!0}),this.lightbox.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),t.target.matches(".ti-arrow-prev")?this.change(this.currentIndex-1):t.target.matches(".ti-arrow-next")?this.change(this.currentIndex+1):!t.target.matches(".ti-widget-lightbox")&&!t.target.matches(".ti-widget-lightbox-close")||t.target.closest(".ti-widget-lightbox-inner")||this.close()}))}addLongScrollEvents(){this.lightbox.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),t.target.matches(".ti-arrow-prev")||t.target.matches(".ti-arrow-next")||t.target.matches(".ti-card-media-thumbnail")?this.navigateReviewImage(t.target):!t.target.matches(".ti-widget-lightbox-review-container")&&!t.target.matches(".ti-widget-lightbox-close")||t.target.closest(".ti-review-item")?t.target.matches(".ti-widget-lightbox-mobile-close-bottom")&&this.close():this.close()}));let t,e,i,s,r,o,a=0,n=null,l=!1,d=!1,h=!1,g=!1,c=!1;this.reviewMediaContainer=null,this.lightbox.reviewsContainer.addEventListener("touchstart",(u=>{a=0,n=null,t=u.touches[0].pageX,i=u.touches[0].pageY,e=null,s=null,r=null,o=null,d=!1,l=!1,c=!1,this.reviewMediaContainer=u.target.closest(".ti-card-media"),this.lightbox.mobileCloseBottomSwipe.toggleHide(),g=this.getNavigationArrowState("next"),h=this.getNavigationArrowState("prev")}),{passive:!0}),this.lightbox.reviewsContainer.addEventListener("touchmove",(u=>{e=u.touches[0].pageX,s=u.touches[0].pageY;let p=e-t,w=s-i,m=Math.abs(Math.atan2(w,p)*(180/Math.PI));if(l=(l||Math.abs(w)>4&&m>60&&m<120)&&!d,d=(d||Math.abs(p)>4&&(m<=60||m>=120))&&!l,d){if(this.isMoving)return!1;if(u.preventDefault(),this.reviewMediaContainer){let i=t>e?"next":"prev";if("next"===i&&g||"prev"===i&&h){let t=this.reviewMediaContainer.getAttribute("data-position")||"0px";o=parseInt(t)+p,this.animateReviewImages(t,o+"px",0)}}}if(r=s,c)(w>0||d)&&(this.lightbox.reviewsContainer.style.overflow="",c=!1);else{let t=Math.abs(this.lightbox.reviewsContainer.scrollHeight-this.lightbox.reviewsContainer.scrollTop-this.lightbox.reviewsContainer.clientHeight);c=t<50&&w<0}if(l&&c){n=w+"px",this.lightbox.reviewsContainer.style.overflow="hidden",this.lightbox.reviewsContainer.animate({top:[a,n]},{duration:Math.abs((parseInt(a)-parseInt(n))/2),fill:"both",easing:"ease-in-out"}),a=n;let t=-Math.abs(w)/2.3;w>0&&(t=0),this.lightbox.mobileCloseBottom.toggleHide(),this.lightbox.mobileCloseBottomSwipe.toggleShow("inline-block"),this.lightbox.mobileCloseBottomSwipe.style.setProperty("--scale",t+"px")}}),{passive:!1}),this.lightbox.reviewsContainer.addEventListener("touchend",(i=>{if(d&&!l){let i=o;if(this.reviewMediaContainer&&(i=this.reviewMediaContainer.getAttribute("data-position")||"0px",g=this.getNavigationArrowState("next"),h=this.getNavigationArrowState("prev")),t&&e&&Math.abs(t-e)>25&&o){let s=t>e?"next":"prev";if("next"===s&&g||"prev"===s&&h){let t=parseInt(this.reviewMediaContainer.getAttribute("data-state")||"0")+("next"===s?1:-1);this.reviewMediaContainer.setAttribute("data-old-position",i),this.reviewMediaContainer.setAttribute("data-position",o+"px"),this.navigateReviewImage(null,t),this.reviewMediaContainer.removeAttribute("data-old-position")}else this.animateReviewImages(o+"px",i,120)}else o&&o!==parseInt(i)&&this.animateReviewImages(o+"px",i,120)}if(this.lightbox.mobileCloseBottom.toggleShow(),l&&n){this.lightbox.reviewsContainer.style.overflow="";let t=Math.abs(parseInt(n)),e=0;t>150&&parseInt(n)<0&&(t=500,e="-1000px",this.close(),this.lightbox.mobileCloseBottom.toggleHide()),this.lightbox.reviewsContainer.scrollTop=this.lightbox.reviewsContainer.scrollHeight,this.lightbox.reviewsContainer.animate({top:[n,e]},{duration:t/2,fill:"both",easing:"ease-in-out"})}this.reviewMediaContainer=null,this.lightbox.mobileCloseBottomSwipe.toggleHide(),a=0,n=null,t=null,e=null,r=null,o=null,d=!1,l=!1,c=!1}),{passive:!0})}show(t){void 0===this.lightbox&&this.init(),this.widget.isLightboxShowing=!0,document.querySelectorAll(".ti-widget-lightbox").forEach((t=>t.remove()));let e=t.closest(".ti-review-item").getAttribute("data-id"),i=0,s=parseInt(t.getAttribute("data-image-index"));for(let t=0,r=this.data.length;tt.scrollIntoView():t.scrollIntoView()}this.lightbox.mobileCloseBottom.toggleShow()}else this.change(i);setTimeout((()=>this.lightbox.classList.add("ti-widget-lightbox-appeared")),10)}close(){this.lightbox.classList.remove("ti-widget-lightbox-appeared"),setTimeout((()=>this.lightbox.remove()),300),this.isLongScroll&&this.lightbox.mobileCloseBottomSwipe.toggleHide(),delete this.widget.isLightboxShowing}change(t){this.currentIndex=t,this.image.parentNode.classList.add("ti-image-loading");let e=this.data[this.currentIndex].src;if(-1!==e.indexOf("google")&&(e=e.replace(/=w.+/,"=s"+Math.round(this.image.parentNode.offsetHeight*Trustindex.getDevicePixelRatio()))),this.image.src=e,this.currentReview!==this.data[this.currentIndex].r){this.currentReview=this.data[this.currentIndex].r,this.reviewContent.innerHTML="";let t=this.widget.querySelector('.ti-review-item[data-id="'+this.data[this.currentIndex].r+'"]');if(!t)return;let e=t.querySelector(".ti-review-header").cloneNode(!0);e.classList.add("ti-lightbox-review-header");let i=t.querySelector(".ti-review-text-container").cloneNode(!0);i.setAttribute("class","ti-review-text"),i.setAttribute("style",""),i.querySelectorAll(".ti-review-image").forEach((t=>t.remove())),this.reviewContent.appendChild(e),this.reviewContent.appendChild(t.querySelector(".ti-stars").cloneNode(!0)),this.reviewContent.appendChild(i),this.lightbox.querySelector(".ti-widget-card").setAttribute("class",t.getAttribute("class").replace("ti-review-item","ti-widget-card"))}this.prevArrow.toggleHide(),this.nextArrow.toggleHide(),t>0&&this.prevArrow.toggleShow(),t0&&n.classList.remove("ti-hidden"),e{t.classList.remove("ti-active"),parseInt(t.getAttribute("data-state"))===e&&t.classList.add("ti-active")})),setTimeout((()=>{this.isMoving=!1}),a)}animateReviewImages(t,e,i){if(!this.reviewMediaContainer)return!1;this.reviewMediaContainer.querySelectorAll(".ti-card-media-images .ti-card-media-image").forEach((s=>{s.animate({left:[t,e]},{duration:i,fill:"both",easing:"ease-in-out"})}))}click(t){(t.target.matches(".ti-review-image")||"popup"===this.widget.reviewTextMode&&t.target.matches(".ti-read-more-active:not(.ti-read-more-collapse"))&&(t.preventDefault(),this.show(t.target))}getNavigationArrowState(t){if(!this.reviewMediaContainer)return!1;let e=this.reviewMediaContainer.querySelector(".ti-arrow-"+t);return!!e&&!e.classList.contains("ti-hidden")}}class m{constructor(t){let e=t.querySelector('script.ti-ai-summary[type="application/ld+json"]');this.summary=JSON.parse(e.innerHTML).summary,e.remove(),this.widget=t}format(){let t=this.widget.reviewsContainer.querySelector(".ti-review-item");if(!t||void 0!==this.element)return;let e=t.cloneNode(!0);e.setAttribute("class",this.getClassName(e)),e.removeAttribute("data-id"),e.querySelectorAll(".ti-stars, .ti-platform-icon, .ti-review-image-container").forEach((t=>t.remove()));let i=e.querySelector(".ti-profile-details .ti-name");i&&(i.innerHTML=this.summary.title);let s=e.querySelector(".ti-profile-img");if(s){let e=s.querySelector("img");t.querySelector(".ti-profile-img").offsetWidth;if(e||(e=document.createElement("img"),s.innerHTML="",s.appendChild(e)),this.summary.images.length>0){for(let t=0;t")?" ti-with-checklist":"")}}var v=(t,e,i)=>new Promise(((s,r)=>{var o=t=>{try{n(i.next(t))}catch(t){r(t)}},a=t=>{try{n(i.throw(t))}catch(t){r(t)}},n=t=>t.done?s(t.value):Promise.resolve(t.value).then(o,a);n((i=i.apply(t,e)).next())}));class x{constructor(t){this.widget=t,this.isAutoDarkMode=!!this.widget.getAttribute("data-auto-dark-mode")}format(){if(this.isAutoDarkMode&&Trustindex.isDarkMode()&&!Trustindex.isAdminUrl()){let t=Trustindex.getCDNUrl()+`assets/widget-presetted-css/${this.widget.layoutId}-dark-background.css`;this.widget.cssVersion&&(t=t.replace("widget-presetted-css/",`widget-presetted-css/v${this.widget.cssVersion}/`)),(()=>{v(this,null,(function*(){let e=document.createElement("style");e.innerHTML=yield this.getCssContent(t),document.body.appendChild(e),this.changeLogosToDark(!0)}))})()}this.changeLogosToDark()}getCssContent(t){return v(this,null,(function*(){let e=yield fetch(t);if(!e.ok)return null;let i=yield e.text();return this.extractColorsFromCss(i)}))}extractColorsFromCss(t){t=t.replace('@charset "UTF-8";',"").replace(/@font-face{[^}]+}/g,"").replace(new RegExp("@(?:media|key-frames) [^{]*{(.*?})}","gs"),"").trim();let e=`[data-set-id="${this.widget.setId}"]`;"wp-widget"!==this.widget.pid&&(e+=`[data-pid="${this.widget.pid}"]`);let i=this.parseCss(t),s="";for(let t in i){s+=t.replace(/\[data-set-id='dark-background'\]/g,e)+"{";for(let e in i[t]){let r=i[t][e];-1===r.indexOf("!important")&&(r+="!important"),s+=`${e}:${r};`}s+="}"}return s}parseCss(t){let e={},i=/^(#(?:[0-9a-fA-F]{3}){1,2}|rgba?\(\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}(\s*,\s*(0|1|0?\.\d+))?\))$/;return t.matchAll(new RegExp("([^{]+){(.*?)}","gs")).forEach((t=>{let s=e[t[1]]||{};t[2].split(";").forEach((t=>{let e=t.split(":"),r=e.shift(),o=e.join(":");(-1!==r.indexOf("color")||-1!==["box-shadow","text-shadow"].indexOf(r)||i.test(o))&&(void 0!==s[r]&&-1===o.indexOf("!important")&&-1!==s[r].indexOf("!important")||(s[r]=o))})),Object.keys(s).length&&(e[t[1]]=s)})),e}changeLogosToDark(t=!1){this.widget.querySelectorAll('img[src*="/logo"][src$=".svg"]').forEach((e=>{let i=e.getAttribute("src").replace("-dark.svg",".svg");t||this.isLogoDark(e)?e.setAttribute("src",i.replace(".svg","-dark.svg")):e.setAttribute("src",i)}))}isLogoDark(t){if("dark-"===this.widget.setId.substr(0,5))return!0;let e=t.parentNode,i=!0;for(;e!==this.widget;){let t=window.getComputedStyle(e,null);if(!/rgba\(\d+, \d+, \d+, 0\)/.test(t.backgroundColor)){i=!1;break}e=e.parentNode}if(i)return!1;return-1!==["light-contrast","light-contrast-large","light-contrast-large-blue"].indexOf(this.widget.setId)}}if(Element.prototype.toggleShow=function(t){this.style.display=t||""},Element.prototype.toggleHide=function(){this.style.display="none"},void 0===window.TrustindexWidget){window.tiWidgetInstances=[],window.Trustindex=i,window.TrustindexWidget=s,window.TrustindexReviewWidget=r,window.TrustindexSliderWidget=o,window.TrustindexMasonryWidget=a,window.TrustindexPopupWidget=n,window.TrustindexTopRatedWidget=l,window.TrustindexFomoWidget=d,window.TrustindexCloseModule=h,window.TrustindexReadMoreModule=g,window.TrustindexLoadMoreModule=c,window.TrustindexHeaderModule=u,window.TrustindexReviewImageModule=p,window.TrustindexLightboxModule=w,window.TrustindexAiSummaryModule=m,window.TrustindexDarkModeModule=x,i.setConstants();let t=document.body?document.body.offsetWidth:0,e=null;window.addEventListener("resize",(()=>{document.body.offsetWidth!==t&&(t=document.body.offsetWidth,e&&clearTimeout(e),window.tiWidgetInstances.forEach((t=>t.resize())))})),document.addEventListener("click",(t=>{window.tiWidgetInstances.forEach((e=>e.documentClick(t)));let e=t.target.closest("a");if(e){let i=document.getElementById(e.getAttribute("href").slice(1));if(i&&!e.getAttribute("data-ti-enable-scroll")){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();let r=i.getBoundingClientRect();window.tiElementToWaitForVisibility.forEach(((t,e)=>{t.getBoundingClientRect().top{window.tiWidgetInstances.forEach((e=>e.documentKeyup(t)))})),window.tiElementToWaitForVisibility=[],window.tiElementToWaitForActivity=[];let v=function(t){window.tiElementToWaitForVisibility.forEach(((t,e)=>{t.isTriggerLoad()&&(new s(null,t),window.tiElementToWaitForVisibility.splice(e,1))}))},f=function(t){window.tiElementToWaitForActivity.forEach(((t,e)=>{if(window.tiElementToWaitForActivity.splice(e,1),!0===t.isWaitForVisibility&&!t.isTriggerLoad())return window.tiElementToWaitForVisibility.push(t);new s(null,t)}))};window.addEventListener("keydown",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("wheel",f,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("touchstart",f,!1),window.addEventListener("scroll",v,!1),window.addEventListener("wheel",v,!1),window.addEventListener("touchmove",v,!1),i.isMobileDevice()&&"hidden"===window.getComputedStyle(document.documentElement,null).getPropertyValue("overflow")&&(document.documentElement.style.overflow="unset")}if(void 0===window.renderTrustindexWidgets&&(window.renderTrustindexWidgets=function(){document.querySelectorAll("pre.ti-widget").forEach((t=>{t.firstChild?t.replaceWith(t.firstChild):t.remove()})),setTimeout((()=>{i.initWidgetsFromDom(),i.loadWidgetsFromDom()}),4)},!i.isAdminUrl())){let t=function(){new MutationObserver(window.renderTrustindexWidgets).observe(document.body,{childList:!0,subtree:!0})};if(document.body)t();else{let e=setInterval((()=>{document.body&&(t(),clearInterval(e))}),100)}}document.currentScript.getAttribute("data-skip-init")||window.renderTrustindexWidgets()})();
//# sourceMappingURL=loader.js.map