'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),core=require("@gem-sdk/core"),React=require("react"),types=require("../types.js"),SingleProduct=require("./Judgeme/SingleProduct.js"),WithoutProduct=require("./Judgeme/WithoutProduct.js");const InstantJudgemeReviews=({setting:e,styles:t,builderProps:r})=>{let{widgetType:s,publicToken:E}=e??{},d=core.useEditorMode(),{storefrontUrl:u}=core.useStoreFront(),_=u?.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)})},c=React.useCallback((e,t)=>{if(_&&t){let r=`jdgm = window.jdgm || {};jdgm.SHOP_DOMAIN = '${_}';jdgm.PLATFORM = 'shopify';jdgm.PUBLIC_TOKEN = '${t}';`,s=document.createElement("script");return s.id=e,s.text=r,document.head.appendChild(s),s}},[_]),n=e=>{let t=document.getElementById(e);t&&document.head.removeChild(t)};return React.useEffect(()=>{"edit"!==d&&i([[types.JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_ID,types.JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_URL],[types.JUDGEME_REVIEWS_INSTALLED_JS_ID,types.JUDGEME_REVIEWS_INSTALLED_JS_URL],[types.JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_I_V2,types.JUDGEME_REVIEWS_WIDGET_PRELOADER_JS_URL_V2]])},[d]),React.useEffect(()=>{E&&(n(types.JUDGEME_REVIEWS_PUBLIC_TOKEN_JS_ID),c(types.JUDGEME_REVIEWS_PUBLIC_TOKEN_JS_ID,E))},[c,E]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:"single_product_preview_badge"===s||"review_widget"===s?jsxRuntime.jsx(SingleProduct.default,{setting:e,styles:t,builderProps:r}):jsxRuntime.jsx(WithoutProduct.default,{setting:e,styles:t,builderProps:r})})};exports.default=InstantJudgemeReviews;
