'use client';
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("@gem-sdk/core"),o=require("react"),r=require("../../common/components/NoDataState.js");exports.default=({collectionHandle:n,productSrc:i,builderAttrs:a,children:c})=>{let u="STATIC"===t.usePageType(),d=t.useShopStore(e=>e.storefrontToken),l=t.useShopStore(e=>e.storefrontUrl),s="Collection"===i,[p,y]=o.useState(""),[f,m]=o.useState("get product"),[S,h]=o.useState(""),{t:g}=t.useI18nStore();o.useEffect(()=>{if(s){if(!n){y(g("We cannot find any collections from your Shopify store. Please try manually syncing the data from Shopify or add a new collection.")),m(g("get collection")),h(g("collection"));return}y(g("We cannot find any product of this collection from your Shopify store? Please try manually syncing the data from Shopify or add a new product to your collection.")),m(g("get product of collection")),h(g("product"));return}if(u&&!d){h(g("product")),y(g("We can not get your products from Shopify"));return}h(g("product")),m(g("get product")),y(g("We cannot find any products from your Shopify store. Please try manually syncing the data from Shopify or add a new product."))},[n,s,u,d]);let w=o.useMemo(()=>{if(!l)return;let e=new URL(l);return s?`${e.protocol}//${e.host}/admin/collections`:`${e.protocol}//${e.host}/admin/products`},[s,l]),b=e=>{let t=new CustomEvent("editor:sync-product",{bubbles:!0,detail:{uid:e}});window.dispatchEvent(t)};return e.jsx(r.default,{elementType:"primary",children:c,builderAttrs:a,title:g("Can not {textLink} from Shopify",{textLink:f}),description:p,primaryBtnTitle:g("Add {entity}",{entity:S}),secondaryBtnTitle:g("Sync from Shopify"),primaryBtnCb:()=>{w&&window.open(w,"_blank")},secondaryBtnCb:()=>b(a?.["data-uid"]??a?.uid)})};
