'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 l,JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_URL_V2 as a}from"../types.js";import u from"./Judgeme/SingleProduct.js";import g from"./Judgeme/WithoutProduct.js";let f=({setting:f,styles:h,builderProps:j})=>{let{widgetType:y,publicToken:P}=f??{},w=r(),{storefrontUrl:E}=d(),_=E?.replace("https://","")?.replace("http://","")?.split("/")?.[0],b=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)})},v=i((e,t)=>{if(_&&t){let r=`jdgm = window.jdgm || {};jdgm.SHOP_DOMAIN = '${_}';jdgm.PLATFORM = 'shopify';jdgm.PUBLIC_TOKEN = '${t}';`,d=document.createElement("script");return d.id=e,d.text=r,document.head.appendChild(d),d}},[_]),I=e=>{let t=document.getElementById(e);t&&document.head.removeChild(t)};return m(()=>{"edit"!==w&&b([[s,n],[p,c],[l,a]])},[w]),m(()=>{P&&(I(o),v(o,P))},[v,P]),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{f as default};
