'use client';
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useEditorMode as r,useStoreFront as d}from"@gem-sdk/core";import{useCallback as i,useEffect as m}from"react";import{JUDGEME_REVIEWS_PUBLIC_TOKEN_JS_ID as o,JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_ID as s,JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_URL as n,JUDGEME_REVIEWS_INSTALLED_JS_ID as p,JUDGEME_REVIEWS_INSTALLED_JS_URL as c,JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_I_V2 as a,JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_URL_V2 as l}from"../types.js";import u from"./Judgeme/SingleProduct.js";import g from"./Judgeme/WithoutProduct.js";let InstantJudgemeReviews=({setting:f,styles:h,builderProps:j})=>{let{widgetType:y,publicToken:w}=f??{},P=r(),{storefrontUrl:v}=d(),E=v?.replace("https://","")?.replace("http://","")?.split("/")?.[0],I=e=>{e.forEach(([e,t])=>{if(document.getElementById(e))return;let r=document.createElement("script");Object.assign(r,{id:e,src:t,defer:!0,type:"text/javascript"}),r.setAttribute("data-cfasync","false"),document.head.appendChild(r)})},_=i((e,t)=>{if(E&&t){let r=`jdgm = window.jdgm || {};jdgm.SHOP_DOMAIN = '${E}';jdgm.PLATFORM = 'shopify';jdgm.PUBLIC_TOKEN = '${t}';`,d=document.createElement("script");return d.id=e,d.text=r,document.head.appendChild(d),d}},[E]),b=e=>{let t=document.getElementById(e);t&&document.head.removeChild(t)};return m(()=>{"edit"!==P&&I([[s,n],[p,c],[a,l]])},[P]),m(()=>{w&&(b(o),_(o,w))},[_,w]),e(t,{children:"single_product_preview_badge"===y||"review_widget"===y?e(u,{setting:f,styles:h,builderProps:j}):e(g,{setting:f,styles:h,builderProps:j})})};export{InstantJudgemeReviews as default};
