{"version":3,"file":"AnalyticsTracking.odFJx8Sc.mjs","names":["useState","selectedVariantId"],"sources":["https:/framerusercontent.com/modules/MQu1tryMb63mlLwcSk10/Fzc2T4inWTv4lYzXt1su/Buy_now_button.js","https:/framerusercontent.com/modules/PUsu23DHpU7CmPQIPyYS/C5XEBoTj3xRrBjIlFAst/AnalyticsTracking.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState}from\"react\";import{ControlType,addPropertyControls}from\"framer\";import{parseShopifyData}from\"https://framerusercontent.com/modules/Vu8sM3DwKDdSi2bltsPi/rkjqZclSkQOy0QCpfAmc/Parse_shopify_data.js\";import{useProductSelectionStore}from\"https://framerusercontent.com/modules/8l7kldZFdo4Q33wHQBGB/R6492SgoPzpAhTwJ6Uq8/Product_selection_store.js\";import{createShopifyCart,addToShopifyCart}from\"https://framerusercontent.com/modules/HRm4FfVJHrd62RjWhV4c/nUNvmMzj3jcUZauIAaHc/Cart_service.js\";import{getIncludeSellingPlansFlag}from\"https://framerusercontent.com/modules/TgekT24FCXsp3m1M9KnX/51KiLjOfRPpzwxhbKXBD/Get_shopify_config.js\";import{createVariantGid}from\"https://framerusercontent.com/modules/tzN8qHzrVYThnxhKObeP/oWpbtfeZjvritjXviKiH/Shopify_utils.js\";import{QueryClientWrapper}from\"https://framerusercontent.com/modules/zParpRuqXNNcrHNZHUCA/c79VKYmrBl02dZ0c2Deg/Query_client_wrapper.js\";import{useLicense}from\"https://framerusercontent.com/modules/kGyAHPbQwKZr1zBe6pP6/RbuQS97niWMvAeN1meX9/Use_license.js\";import PresetButton from\"https://framerusercontent.com/modules/a6C1Qq7kxeKULOsvIpdv/qJhHdmQsP7KnXdnJHkkc/Preset_button.js\";import CustomButtonWrapper from\"https://framerusercontent.com/modules/KkMHEXBTzNGLCAGsRLrm/C2sk9cjUnc3YE4Ebu9Zq/Custom_button_wrapper.js\";import{PresetSecondaryButtonStyleControls,PresetButtonContentControls,CustomButtonControls,overrideControlDefaults,useInventoryDisabled,OutOfStockStyleControls}from\"https://framerusercontent.com/modules/jSzgfFOp8vV7JiKIMM1a/BHRSzpNTK9tPbKGRIYxx/Shared_button_props.js\";import{SHOPIFY_DATA_DESCRIPTION,SUPPORT_CONTROL}from\"https://framerusercontent.com/modules/G9UZNzEc4NZQrMJzPvWx/zpYQI5Hzt8wx5QiaCjMr/Shared_props.js\";import{isOnFramerCanvasFn}from\"https://framerusercontent.com/modules/0cFx6PDS8kp3yxNfnoIw/3wFcPS10LYSFljb1q710/Framer_utils.js\";// ------------------------------------------------------------ //\n// MAIN COMPONENT\n// ------------------------------------------------------------ //\nfunction BuyNowButtonContent(props){const isOnFramerCanvas=isOnFramerCanvasFn();const[isProcessing,setIsProcessing]=useState(false);const shopifyData=parseShopifyData(props.shopifyData);const{getSelectedVariant,getQuantity,getSelectedSellingPlan}=useProductSelectionStore();const{isFree:isFreeLicense}=useLicense();const selectedVariantId=getSelectedVariant(shopifyData.id,shopifyData.variants);const{isDisabled:isOutOfStockDisabled}=useInventoryDisabled(shopifyData.id,selectedVariantId,props.disableWhenOutOfStock);const handleBuyNow=async()=>{if(!shopifyData||isProcessing||isOutOfStockDisabled||isFreeLicense)return;try{setIsProcessing(true);props.onBuyNowStart?.();const includeSellingPlans=getIncludeSellingPlansFlag();// Get the selected variant for this product\nconst selectedVariantId=getSelectedVariant(shopifyData.id,shopifyData.variants);if(!selectedVariantId){throw new Error(\"No variant selected\");}// Get the quantity for this variant\nconst quantity=getQuantity(selectedVariantId);if(quantity<=0){throw new Error(\"Invalid quantity\");}// Get the selected selling plan (if any)\nconst sellingPlanId=getSelectedSellingPlan(shopifyData.id);// Create a fresh cart\nconst createCartResult=await createShopifyCart(undefined,includeSellingPlans);if(!createCartResult.data?.cartCreate?.cart){throw new Error(\"Failed to create cart\");}const newCartId=createCartResult.data.cartCreate.cart.id;// Add the selected variant to the cart (with selling plan if selected)\nconst addToCartResult=await addToShopifyCart({cartId:newCartId,variantId:createVariantGid(selectedVariantId),quantity,sellingPlanId:sellingPlanId??undefined,includeSellingPlans});if(!addToCartResult.data?.cartLinesAdd?.cart?.checkoutUrl){throw new Error(\"Failed to add item to cart\");}const checkoutUrl=addToCartResult.data.cartLinesAdd.cart.checkoutUrl;// Add return URL parameter\nconst finalCheckoutUrl=`${checkoutUrl}&return_url=${encodeURIComponent(window.location.origin+\"/checkout-complete\")}`;// Redirect to checkout\nif(props.newTab){window.open(finalCheckoutUrl,\"_blank\",\"noopener,noreferrer\");}else{window.location.href=finalCheckoutUrl;}}catch(error){console.error(\"Buy Now error:\",error);props.onBuyNowError?.(error);}finally{setIsProcessing(false);}};// Check if we have valid data\nconst isDisabled=isProcessing||!shopifyData||!shopifyData.variants?.length||isOutOfStockDisabled||isFreeLicense;const finalDisabled=isOnFramerCanvas?props.previewType===\"disabled\":isDisabled;// ---------------- BUTTON STYLES ---------------- //\nconst buttonText=isProcessing?\"Processing...\":finalDisabled?props.outOfStockStyle.text:props.text;const buttonOpacity=finalDisabled?props.outOfStockStyle.opacity:undefined;const disabledStyle={alignItems:props.presetButtonStyle.alignItems,justifyContent:props.presetButtonStyle.justifyContent,gap:props.presetButtonStyle.gap,padding:props.presetButtonStyle.padding,border:props.outOfStockStyle.border,borderRadius:props.presetButtonStyle.borderRadius,textColor:props.outOfStockStyle.textColor,backgroundColor:props.outOfStockStyle.backgroundColor,shadow:props.outOfStockStyle.shadow,tapScale:props.presetButtonStyle.tapScale,font:props.presetButtonStyle.font};if(props.buttonType===\"custom\"){return /*#__PURE__*/_jsx(CustomButtonWrapper,{onClick:handleBuyNow,customButtonSize:props.customButtonSize,disabled:finalDisabled,disabledButton:props.customButtonDisabled?.[0],children:props.customButton});}return /*#__PURE__*/_jsx(PresetButton,{onClick:handleBuyNow,disabled:finalDisabled,font:props.presetButtonStyle.font,leftIcon:props.leftIcon?.[0],rightIcon:props.rightIcon?.[0],text:buttonText,presetButtonStyle:props.presetButtonStyle,disabledStyle:disabledStyle,style:{opacity:buttonOpacity}});}// ------------------------------------------------------------ //\n// EXPORT WITH QUERY CLIENT\n// ------------------------------------------------------------ //\n/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 40\n * @framerDisableUnlink\n */export default function BuyNowButton(props){return /*#__PURE__*/_jsx(QueryClientWrapper,{children:/*#__PURE__*/_jsx(BuyNowButtonContent,{...props})});}// ------------------------------------------------------------ //\n// PROPERTY CONTROLS\n// ------------------------------------------------------------ //\naddPropertyControls(BuyNowButton,{shopifyData:{type:ControlType.String,description:SHOPIFY_DATA_DESCRIPTION},disableWhenOutOfStock:{type:ControlType.Boolean,title:\"Disable Out-of-Stock\",defaultValue:true,description:\"Disable if selected variant is out-of-stock\"},...OutOfStockStyleControls,...CustomButtonControls,...overrideControlDefaults(PresetSecondaryButtonStyleControls,{\"presetButtonStyle.tapScale\":.995}),...overrideControlDefaults(PresetButtonContentControls,{text:\"Buy Now\"}),newTab:{type:ControlType.Boolean,title:\"Open in New Tab\",defaultValue:true},previewType:{type:ControlType.Enum,title:\"Preview\",options:[\"default\",\"disabled\"],optionTitles:[\"Default\",\"Out of Stock\"],defaultValue:\"default\",displaySegmentedControl:true,segmentedControlDirection:\"vertical\"},...SUPPORT_CONTROL});BuyNowButton.displayName=\"Buy Now Button\";\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"BuyNowButton\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerIntrinsicHeight\":\"40\",\"framerIntrinsicWidth\":\"400\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}","import{jsx as _jsx}from\"react/jsx-runtime\";// 1. Tracks the \"Add to Cart\" Button Click\nexport function trackAddToCart(Component){return props=>{const handleClick=event=>{// Send to Google Analytics (GA4)\nif(typeof window!==\"undefined\"&&window.gtag){window.gtag(\"event\",\"add_to_cart\",{currency:\"USD\"});}// Send to Meta (Facebook) Pixel\nif(typeof window!==\"undefined\"&&window.fbq){window.fbq(\"track\",\"AddToCart\",{currency:\"USD\"});}// Ensure Framer's original button action (adding to cart) still happens\nif(props.onClick)props.onClick(event);};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};}// 2. Tracks the \"Buy Now / Checkout\" Button Click\nexport function trackCheckout(Component){return props=>{const handleClick=event=>{// Send to Google Analytics (GA4)\nif(typeof window!==\"undefined\"&&window.gtag){window.gtag(\"event\",\"begin_checkout\",{currency:\"USD\"});}// Send to Meta (Facebook) Pixel\nif(typeof window!==\"undefined\"&&window.fbq){window.fbq(\"track\",\"InitiateCheckout\");}// Ensure Framer's original button action (going to checkout) still happens\nif(props.onClick)props.onClick(event);};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};}\nexport const __FramerMetadata__ = {\"exports\":{\"trackCheckout\":{\"type\":\"reactHoc\",\"name\":\"trackCheckout\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"trackAddToCart\":{\"type\":\"reactHoc\",\"name\":\"trackAddToCart\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AnalyticsTracking.map"],"mappings":"6iBAGA,SAAS,EAAoB,EAAM,CAAC,IAAM,EAAiB,GAAoB,CAAM,CAAC,EAAa,GAAiBA,EAAS,GAAM,CAAO,EAAY,EAAiB,EAAM,YAAY,CAAM,CAAC,qBAAmB,cAAY,0BAAwB,GAA0B,CAAM,CAAC,OAAO,GAAe,GAAY,CAAO,EAAkB,EAAmB,EAAY,GAAG,EAAY,SAAS,CAAM,CAAC,WAAW,GAAsB,EAAqB,EAAY,GAAG,EAAkB,EAAM,sBAAsB,CAAO,EAAa,SAAS,CAAI,MAAC,GAAa,GAAc,GAAsB,GAAqB,GAAG,CAAC,EAAgB,GAAK,CAAC,EAA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