{"version":3,"file":"Buy_now_button.CAPI0-eO.mjs","names":["create","useState"],"sources":["https:/framerusercontent.com/modules/CEFL18JTsoVN7HzqbGVy/KndVJRNlxYcbiwXYnvWR/Custom_product_field_store.js","https:/framerusercontent.com/modules/MQu1tryMb63mlLwcSk10/8t9SrkljbGLQaO10JmCB/Buy_now_button.js"],"sourcesContent":["import{create}from\"https://framerusercontent.com/modules/ieMSnIJVCiFKJmsg1OmM/KWFJj6n258MVreTmJoNk/Zustand.js\";export const useCustomProductFieldStore=create((set,get)=>({fieldsByProductId:{},registerField:(productId,fieldId,field)=>{set(state=>({fieldsByProductId:{...state.fieldsByProductId,[productId]:{...state.fieldsByProductId[productId]||{},[fieldId]:{key:field.key,label:field.label,required:field.required,value:state.fieldsByProductId[productId]?.[fieldId]?.value??field.value??\"\"}}}}));},unregisterField:(productId,fieldId)=>{set(state=>{const productFields=state.fieldsByProductId[productId];if(!productFields?.[fieldId]){return state;}const nextProductFields={...productFields};delete nextProductFields[fieldId];if(Object.keys(nextProductFields).length===0){const nextFieldsByProductId={...state.fieldsByProductId};delete nextFieldsByProductId[productId];return{fieldsByProductId:nextFieldsByProductId};}return{fieldsByProductId:{...state.fieldsByProductId,[productId]:nextProductFields}};});},setFieldValue:(productId,fieldId,value)=>{set(state=>{const currentField=state.fieldsByProductId[productId]?.[fieldId];if(!currentField){return state;}return{fieldsByProductId:{...state.fieldsByProductId,[productId]:{...state.fieldsByProductId[productId],[fieldId]:{...currentField,value}}}};});},getFieldValue:(productId,fieldId)=>{return get().fieldsByProductId[productId]?.[fieldId]?.value??\"\";},getCartAttributes:productId=>{const productFields=Object.values(get().fieldsByProductId[productId]||{});return productFields.map(field=>({key:field.key.trim(),value:field.value.trim()})).filter(field=>field.key&&field.value);},hasInvalidRequiredFields:productId=>{const productFields=Object.values(get().fieldsByProductId[productId]||{});return productFields.some(field=>field.required&&field.value.trim().length===0);}}));\nexport const __FramerMetadata__ = {\"exports\":{\"useCustomProductFieldStore\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CartLineAttribute\":{\"type\":\"tsType\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Custom_product_field_store.map","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/5VMlieiI3PeoSFTKuy6T/Product_selection_store.js\";import{createShopifyCart,addToShopifyCart}from\"https://framerusercontent.com/modules/HRm4FfVJHrd62RjWhV4c/cgmljlQKq1mLwrqNm45E/Cart_service.js\";import{getIncludeSellingPlansFlag}from\"https://framerusercontent.com/modules/TgekT24FCXsp3m1M9KnX/51KiLjOfRPpzwxhbKXBD/Get_shopify_config.js\";import{buildCheckoutRedirectUrl,createVariantGid}from\"https://framerusercontent.com/modules/tzN8qHzrVYThnxhKObeP/7xRaFLeVY9UkDbqtIhhH/Shopify_utils.js\";import{QueryClientWrapper}from\"https://framerusercontent.com/modules/zParpRuqXNNcrHNZHUCA/c79VKYmrBl02dZ0c2Deg/Query_client_wrapper.js\";import{useLicense}from\"https://framerusercontent.com/modules/kGyAHPbQwKZr1zBe6pP6/7xP3DD50frYyeaii40ln/Use_license.js\";import PresetButton from\"https://framerusercontent.com/modules/a6C1Qq7kxeKULOsvIpdv/7z9EMNxcsZIiQTGrj76Y/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/YKtQgewLhirCE4hz19dy/Shared_button_props.js\";import{SHOPIFY_DATA_DESCRIPTION,SUPPORT_CONTROL}from\"https://framerusercontent.com/modules/G9UZNzEc4NZQrMJzPvWx/mIDGZDuYkLeEfvCEqoly/Shared_props.js\";import{isOnFramerCanvasFn}from\"https://framerusercontent.com/modules/0cFx6PDS8kp3yxNfnoIw/3wFcPS10LYSFljb1q710/Framer_utils.js\";import{useCustomProductFieldStore}from\"https://framerusercontent.com/modules/CEFL18JTsoVN7HzqbGVy/KndVJRNlxYcbiwXYnvWR/Custom_product_field_store.js\";// ------------------------------------------------------------ //\n// MAIN COMPONENT\n// ------------------------------------------------------------ //\nfunction BuyNowButtonContent(props){const isOnFramerCanvas=isOnFramerCanvasFn();const[isProcessing,setIsProcessing]=useState(false);const shopifyData=parseShopifyData(props.shopifyData);const{getSelectedVariant,getQuantity}=useProductSelectionStore();const selectedSellingPlan=useProductSelectionStore(state=>state.getSelectedSellingPlan(shopifyData.id));const hasSellingPlanSelection=useProductSelectionStore(state=>state.hasSellingPlanSelection(shopifyData.id));const selectorSelectionRequirement=useProductSelectionStore(state=>state.getSellingPlanSelectionRequirement(shopifyData.id));const hasInvalidRequiredFields=useCustomProductFieldStore(state=>state.hasInvalidRequiredFields(shopifyData.id));const{isFree:isFreeLicense}=useLicense();const selectedVariantId=getSelectedVariant(shopifyData.id,shopifyData.variants);const{isDisabled:isOutOfStockDisabled}=useInventoryDisabled(shopifyData.id,selectedVariantId,props.disableWhenOutOfStock);const hasSellingPlans=(shopifyData.sellingPlanGroups||[]).some(group=>(group.sellingPlans||[]).length>0);const selectionRequirement=shopifyData.requiresSellingPlan===true&&hasSellingPlans?\"sellingPlan\":selectorSelectionRequirement;const isMissingRequiredSellingPlan=selectionRequirement===\"sellingPlan\"?!hasSellingPlanSelection||selectedSellingPlan===null:selectionRequirement===\"purchaseOption\"&&!hasSellingPlanSelection;const handleBuyNow=async()=>{if(!shopifyData||isProcessing||isOutOfStockDisabled||isFreeLicense||hasInvalidRequiredFields||isMissingRequiredSellingPlan)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 attributes=useCustomProductFieldStore.getState().getCartAttributes(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:selectedSellingPlan??undefined,attributes,includeSellingPlans});if(!addToCartResult.data?.cartLinesAdd?.cart?.checkoutUrl){throw new Error(\"Failed to add item to cart\");}const finalCheckoutUrl=buildCheckoutRedirectUrl(addToCartResult.data.cartLinesAdd.cart.checkoutUrl);// 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||hasInvalidRequiredFields||isMissingRequiredSellingPlan;const finalDisabled=isOnFramerCanvas?props.previewType===\"disabled\":isDisabled;// ---------------- BUTTON STYLES ---------------- //\nconst buttonText=isProcessing?props.processingText??\"Processing...\":isOutOfStockDisabled?props.outOfStockStyle.text:props.text;const buttonOpacity=isOutOfStockDisabled?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\"}),processingText:{type:ControlType.String,title:\"Processing Text\",defaultValue:\"Processing...\",description:\"Shown for a moment after button is clicked, until checkout is created.\"},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\":{\"framerIntrinsicWidth\":\"400\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerDisableUnlink\":\"\",\"framerIntrinsicHeight\":\"40\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"ijBAA8G,EAAc,EAA2BA,GAAQ,EAAI,KAAO,CAAC,kBAAkB,CAAC,EAAE,eAAe,EAAU,EAAQ,IAAQ,CAAC,EAAI,IAAQ,CAAC,kBAAkB,CAAC,GAAG,EAAM,mBAAmB,GAAW,CAAC,GAAG,EAAM,kBAAkB,IAAY,CAAC,GAAG,GAAS,CAAC,IAAI,EAAM,IAAI,MAAM,EAAM,MAAM,SAAS,EAAM,SAAS,MAAM,EAAM,kBAAkB,EAAU,GAAG,EAAQ,EAAE,OAAO,EAAM,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAE,EAAE,iBAAiB,EAAU,IAAU,CAAC,EAAI,GAAO,CAAC,IAAM,EAAc,EAAM,kBAAkB,GAAW,GAAG,CAAC,IAAgB,GAAU,OAAO,EAAO,IAAM,EAAkB,CAAC,GAAG,CAAa,EAAoC,GAAlC,OAAO,EAAkB,GAAY,OAAO,KAAK,CAAiB,CAAC,CAAC,SAAS,EAAE,CAAC,IAAM,EAAsB,CAAC,GAAG,EAAM,iBAAiB,EAA0C,OAAxC,OAAO,EAAsB,GAAiB,CAAC,kBAAkB,CAAqB,CAAE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