1import{b as g,bi as d,bj as u,bk as p,bl as y,aP as _,bm as n,bn as m,bo as a,bp as h,bq as S,N as v,p as E,r as b}from"./storefrontApp.DHj_rTVq.min.js";import{S as w}from"./chunk-storefront_settings_constants.DIF02Gz.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-vendor-lit.NvY0u02.js";import"./chunk-vendor-lodash.CWHFt7Z.js";import"./chunk-vendor-rxjs.Dp7kflo.js";import"./chunk-vendor-phoenix.cdKS79L.js";class A extends g{constructor({settingsApi:e,storeFactoryApi:t}){super(),this.moduleName=d.service,this.#t=null,this.#e=e,this.#s=t,this.#i=this.#s.createStore("local",u),this.#r=this.#s.createStore("session",p),this.#o=this.#e.isFeatureEnabled("dev_google_reviews_sticky_bars_fix"),window.___gcfg={lang:this.#e.getLocales().locale.split("_")[0]},(async()=>this._setupEvents())()}#e;#s;#i;#r;#o;#t;_setupEvents(){new y(async()=>{this._renderSurveyIfNotDisplayedBefore(),await this._renderBadge()}),this.eventBus.on(_.purchased,async({body:e})=>{e&&await this._renderSurveyOnPurchase(e)})}async _renderSurveyIfNotDisplayedBefore(){const e=this.#i.getObject(n);e&&await this._renderSurvey(e)}async _renderSurveyOnPurchase(e){const{merchantId:t,popupStyle:s,deliveryDays:i}=this._getConfigFromComponent(),o=e.basket.products.list,r={merchant_id:t,order_id:e.orderId,email:e.basket.billingAddress?.email||"",delivery_country:e.basket.shippingAddress?this._getDeliveryCountry(e.basket.shippingAddress):"",estimated_delivery_date:this._getEstimatedDeliveryDate(o,i),opt_in_style:m[s]};await this._renderSurvey(r)}_getConfigFromComponent(){const e=document.querySelector("google-customer-reviews");if(!e)throw new Error("Google Customer Reviews component not found");return{merchantId:e?.getAttribute("merchant-id")||"",popupStyle:e?.getAttribute("popup-style")||"1",deliveryDays:Number(e?.getAttribute("delivery-days")),widgetPosition:e?.getAttribute("position")||"1",isWidgetVisible:e?.getAttribute("is-visible")==="1"}}_getDeliveryCountry(e){let t=null;return e.countryId&&(t=this.#e.getCountryById(e?.countryId)),t?.isocode||this.#e.getLocales().locale.split("_")[1]}_getEstimatedDeliveryDate(e,t){const s=e.reduce((r,c)=>Math.max(r,c.delivery?.duration.timeInDays||1),0)+t,i=new Date;return new Date(i.setDate(i.getDate()+s)).toISOString().split("T")[0]}async _renderBadge(){const{merchantId:e,widgetPosition:t,isWidgetVisible:s}=this._getConfigFromComponent();if(s){await this._initGoogleApi();const i=document.createElement("div");i.setAttribute("data-turbo-permanent",""),document.body.appendChild(i),this.#o&&(i.style.setProperty("transition","transform 0.3s ease-in-out"),this.#t&&document.removeEventListener(a.mobileMenuHeightChanged,this.#t),this.#t=o=>{const r=o;i.style.setProperty("transform",`translateY(-${r.detail}px)`)},document.addEventListener(a.mobileMenuHeightChanged,this.#t)),window.gapi.load("ratingbadge",function(){window.gapi.ratingbadge.render(i,{merchant_id:e,position:h[t]})})}}async _renderSurvey(e){this.#r.get(e.order_id)||(this.#i.setObject(n,e),await this._initGoogleApi(),window.gapi.load("surveyoptin",()=>{window.gapi.surveyoptin.render(e),this.#i.remove(n)}),this.#r.set(e.order_id,"Already displayed"))}async _initGoogleApi(){return await S.create("google-apis","https://apis.google.com/js/platform.js")}}class G extends v{static{this.featureName=d.component}async init(){const e=await this.getApi(w.api),t=await this.getApi(E),s=new A({settingsApi:e,storeFactoryApi:t});return{cores:[{type:b.service,instance:[s]}]}}}export{G as GoogleCustomerReviewsInitializer};
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.