"use strict";var core=require("@gem-sdk/core"),React=require("react"),helpers=require("../components/shop-pay-button/common/helpers.js");const useShopPayButton=e=>{let t=core.useEditorMode(),{quantity:n}=core.useQuantity(),{data:o}=core.useCartData(),r=core.useCurrentVariant(),i=core.useShopStore(e=>e.storefrontUrl),d=core.useCurrentVariantInStock(),s=helpers.getStoreUrl(i),c=React.useMemo(()=>{let e=o?.lineItems.map(e=>({id:e.variantId,quantity:e.quantity}))?.reduce((e,t)=>{let n=helpers.getIdFromGid(t?.id);return n&&e.push(`${n}:${t?.quantity??1}`),e},[]);return e},[o?.lineItems]),u=React.useMemo(()=>e?.kind==="cart-buy"?c:r?.baseID&&d&&n?[`${helpers.getIdFromGid(r.baseID)}:${n}`]:void 0,[e?.kind,r?.baseID,d,n,c]),a=`${s}/cart/${u?.join(",")}?payment=shop_pay`,p=({inputWidth:n=600,inputHeight:o=600})=>{if("edit"!==t){if(e?.openMode==="popup"){let e=void 0!==window.screenLeft?window.screenLeft:window.screenX,t=void 0!==window.screenTop?window.screenTop:window.screenY,r=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,i=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,d=r/window.screen.availWidth,s=(r-n)/2/d+e,c=(i-o)/2/d+t;window.open(a,"shop_pay",`scrollbars=yes, width=${n/d}, height=${o/d}, top=${c}, left=${s}`)}else a&&window.open(a)}};return{storeUrl:s,variants:u,handleOnPay:p}};exports.useShopPayButton=useShopPayButton;
