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