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