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