{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/xEahqZEsyG5uoZky61jQ/GjM5FE9Howd4yhncfoBW/_useProduct.js", "ssg:https://framerusercontent.com/modules/sLbkDuXdCdpfHR6EbULm/dJWyf6pEjSzLAS2pkmF8/Shopify_ProductAddToCart.js"],
  "sourcesContent": ["import{useState,useEffect,useMemo}from\"react\";import{useAtom}from\"jotai\";import{useShopify}from\"https://framerusercontent.com/modules/tdCHCV0pSkxlDaX5GkOX/DghEpnnhgC2rfmZyUB3b/_useShopify.js\";import{priceCode}from\"https://framerusercontent.com/modules/7dEgbg7qo3lsQk361YtS/NrF60tPHZRRgADqpoRFr/_utils.js\";import{selectedProductsAtom}from\"https://framerusercontent.com/modules/yZBbIevRfN36MGDPpltx/T3pmu5HZJD7fA9qJvLoW/_atoms.js\";import{DefaultProduct}from\"https://framerusercontent.com/modules/fWwtzMT2tYXMW4IKB8On/YQLekiPF3wNhgPh7ig35/_test_data.js\";const DefaultSelectedOption={quantity:1,quantityAvailable:null,selectedOption:null,sellingPlan:null};export function useProduct(productID,config,addToSelected){const[selectedProducts,setSelectedProducts]=useAtom(selectedProductsAtom);const{products}=useShopify(config);const[product,setProduct]=useState(config?.testMode?DefaultProduct:null);const selected=product?.id?selectedProducts[product.id]:null;// get price and compare price\nconst getPrice=(camparePrice,price)=>{const comparePriceValue=camparePrice&&camparePrice.amount!==\"0.0\"?priceCode(camparePrice,config):null;const priceValue=priceCode(price,config);return{camparePrice:comparePriceValue!==priceValue?comparePriceValue:null,price:priceValue};};const changeQuantity=quantity=>{if(!product)return;setSelectedProducts(state=>({...state,[product.id]:{...DefaultSelectedOption,...state[product.id],quantity}}));};const selectVariant=(item,sellingPlan)=>{if(!product)return;setSelectedProducts(state=>({...state,[product.id]:{...DefaultSelectedOption,...state[product.id],sellingPlan,quantityAvailable:item.quantityAvailable,selectedOption:item.id}}));};// set first variant as default selected when addToSelected is true\nuseEffect(()=>{if(product&&addToSelected){const defaultVariant=product.variants.nodes[0];setSelectedProducts(state=>({...state,[product.id]:{...DefaultSelectedOption,quantityAvailable:defaultVariant.quantityAvailable,selectedOption:defaultVariant.id}}));return()=>{setSelectedProducts(state=>({...state,[product.id]:null}));};}},[product,addToSelected]);// set product when productID found\nuseEffect(()=>{const foundProduct=products.find(item=>item.id===productID);if(foundProduct){setProduct(config?.testMode?DefaultProduct:foundProduct);}},[products,productID,config?.testMode]);// return result with two mode: when variant selected and when not selected\nconst result=useMemo(()=>{if(!product)return{product:null,availableForSale:null,multiplePrice:null,price:null,stock:null,selectedVariant:null,selectedProduct:null};const selectedVariant=product.variants.nodes.find(item=>item.id===selected?.selectedOption);if(selectedVariant){const selectedSellingPlan=selectedVariant?.sellingPlanAllocations?.nodes.find(item=>item.sellingPlan.id===selected?.sellingPlan);const{compareAtPriceV2,availableForSale,priceV2,quantityAvailable}=selectedVariant;const price=selectedSellingPlan?.checkoutChargeAmount??priceV2;return{product,price:getPrice(compareAtPriceV2,price),multiplePrice:false,availableForSale,stock:quantityAvailable,selectedVariant,selectedProduct:selected};}const{compareAtPriceRange,priceRange,availableForSale,totalInventory}=product??{};const multiplePrice=priceRange.minVariantPrice.amount!==priceRange.maxVariantPrice.amount;return{product,price:getPrice(compareAtPriceRange.minVariantPrice,priceRange.minVariantPrice),multiplePrice,availableForSale,stock:totalInventory,selectedVariant:null,selectedProduct:selected};},[product,selected,config?.languageIsoCode,config?.countryIsoCode]);return{...result,changeQuantity,selectVariant};}\nexport const __FramerMetadata__ = {\"exports\":{\"useProduct\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}", "import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{motion}from\"framer-motion\";import{cn,textProperties,ProductBaseControls,ConfigControls}from\"https://framerusercontent.com/modules/eAejHXy6apg0StNmpKvK/4uA71TWP0uSyqhDERFA6/_framer_utils.js\";import{useProduct}from\"https://framerusercontent.com/modules/xEahqZEsyG5uoZky61jQ/GjM5FE9Howd4yhncfoBW/_useProduct.js\";import{useCart}from\"https://framerusercontent.com/modules/kEMMGb5hqGCVwEpqX70U/Uia1w8lBzAPSVeHnYlMb/_useCart.js\";import ComponentWrapper from\"https://framerusercontent.com/modules/hQlZBgGeLDev5WuUJA4d/W5z3USVGl6mIjAon3RMp/ComponentWrapper.js\";import Button,{ButtonProperties}from\"https://framerusercontent.com/modules/EoMllm11FAeAfrQZgkjQ/OTJjldvcxdTzD2VPW9rd/Button.js\";/**\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function Shopify_ProductAddToCart(props){const{product,selectedProduct,availableForSale}=useProduct(props.productID??null,props.config);const{addToCart,actionLoading,cartError}=useCart(props.config);const handleAddToCart=async()=>{const merchandiseId=selectedProduct?.selectedOption||product?.variants.nodes[0].id;const quantity=selectedProduct?selectedProduct.quantity:1;const sellingPlanId=selectedProduct?.sellingPlan;// find & add attribute to cart\nconst attributes=[];const productElements=document.querySelectorAll('[name^=\"product-\"]');productElements.forEach(element=>{const key=element.getAttribute(\"name\").replace(\"product-\",\"\");const value=element.value;if(value&&value!==\"\"){attributes.push({key,value});}});// finally add to cart\nawait addToCart({merchandiseId,quantity,attributes,sellingPlanId});props.openCartEvent?.();};return /*#__PURE__*/_jsxs(ComponentWrapper,{style:cn(styles.wrapper),productID:props.productID||\"EMPTY\",config:props.config,children:[/*#__PURE__*/_jsx(Button,{onClick:handleAddToCart,loading:actionLoading,disabled:!availableForSale,...props}),cartError&&/*#__PURE__*/_jsx(motion.span,{style:cn(props.errorStyle),children:cartError})]});}Shopify_ProductAddToCart.displayName=\"Product Add To Cart\";addPropertyControls(Shopify_ProductAddToCart,{...ConfigControls,...ProductBaseControls,...ButtonProperties(\"Add to cart\"),errorStyle:{title:\"Error Style\",type:ControlType.Object,controls:{...textProperties(14,\"#bb0000\"),textTransform:{type:ControlType.Enum,defaultValue:\"none\",segmentedControlDirection:\"vertical\",options:[\"none\",\"lowercase\",\"uppercase\",\"capitalize\"],optionTitles:[\"Normal\",\"Lowercase\",\"Uppercase\",\"Capitalize\"]}}},openCartEvent:{type:ControlType.EventHandler}});const styles={wrapper:{display:\"flex\",flexDirection:\"column\",gap:8}};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Shopify_ProductAddToCart\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],
  "mappings": "2RAAuiB,IAAMA,EAAsB,CAAC,SAAS,EAAE,kBAAkB,KAAK,eAAe,KAAK,YAAY,IAAI,EAAS,SAASC,EAAWC,EAAUC,EAAOC,EAAc,CAAC,GAAK,CAACC,EAAiBC,CAAmB,EAAEC,EAAQC,CAAoB,EAAO,CAAC,SAAAC,CAAQ,EAAEC,EAAWP,CAAM,EAAO,CAACQ,EAAQC,CAAU,EAAEC,EAASV,GAAQ,SAASW,EAAe,IAAI,EAAQC,EAASJ,GAAS,GAAGN,EAAiBM,EAAQ,EAAE,EAAE,KAC/6BK,EAAS,CAACC,EAAaC,IAAQ,CAAC,IAAMC,EAAkBF,GAAcA,EAAa,SAAS,MAAMG,EAAUH,EAAad,CAAM,EAAE,KAAWkB,EAAWD,EAAUF,EAAMf,CAAM,EAAE,MAAM,CAAC,aAAagB,IAAoBE,EAAWF,EAAkB,KAAK,MAAME,CAAU,CAAE,EAAQC,EAAeC,GAAU,CAAKZ,GAAeL,EAAoBkB,IAAQ,CAAC,GAAGA,EAAM,CAACb,EAAQ,EAAE,EAAE,CAAC,GAAGX,EAAsB,GAAGwB,EAAMb,EAAQ,EAAE,EAAE,SAAAY,CAAQ,CAAC,EAAE,CAAE,EAAQE,EAAc,CAACC,EAAKC,IAAc,CAAKhB,GAAeL,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SAAAC,EAAS,WAAAE,EAAW,cAAAD,CAAa,CAAC,EAAEZ,EAAM,gBAAgB,CAAE,EAAE,OAAoBiB,EAAMC,EAAiB,CAAC,MAAMC,EAAGC,EAAO,OAAO,EAAE,UAAUpB,EAAM,WAAW,QAAQ,OAAOA,EAAM,OAAO,SAAS,CAAcqB,EAAKC,EAAO,CAAC,QAAQb,EAAgB,QAAQH,EAAc,SAAS,CAACH,EAAiB,GAAGH,CAAK,CAAC,EAAEO,GAAwBc,EAAKE,EAAO,KAAK,CAAC,MAAMJ,EAAGnB,EAAM,UAAU,EAAE,SAASO,CAAS,CAAC,CAAC,CAAC,CAAC,CAAE,CAACR,EAAyB,YAAY,sBAAsByB,EAAoBzB,EAAyB,CAAC,GAAG0B,EAAe,GAAGC,EAAoB,GAAGC,EAAiB,aAAa,EAAE,WAAW,CAAC,MAAM,cAAc,KAAKC,EAAY,OAAO,SAAS,CAAC,GAAGC,EAAe,GAAG,SAAS,EAAE,cAAc,CAAC,KAAKD,EAAY,KAAK,aAAa,OAAO,0BAA0B,WAAW,QAAQ,CAAC,OAAO,YAAY,YAAY,YAAY,EAAE,aAAa,CAAC,SAAS,YAAY,YAAY,YAAY,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,KAAKA,EAAY,YAAY,CAAC,CAAC,EAAE,IAAMR,EAAO,CAAC,QAAQ,CAAC,QAAQ,OAAO,cAAc,SAAS,IAAI,CAAC,CAAC",
  "names": ["DefaultSelectedOption", "useProduct", "productID", "config", "addToSelected", "selectedProducts", "setSelectedProducts", "useAtom", "selectedProductsAtom", "products", "useShopify", "product", "setProduct", "ye", "DefaultProduct", "selected", "getPrice", "camparePrice", "price", "comparePriceValue", "priceCode", "priceValue", "changeQuantity", "quantity", "state", "selectVariant", "item", "sellingPlan", "ue", "defaultVariant", "foundProduct", "se", "selectedVariant", "selectedSellingPlan", "compareAtPriceV2", "availableForSale", "priceV2", "quantityAvailable", "compareAtPriceRange", "priceRange", "totalInventory", "multiplePrice", "Shopify_ProductAddToCart", "props", "product", "selectedProduct", "availableForSale", "useProduct", "addToCart", "actionLoading", "cartError", "useCart", "handleAddToCart", "merchandiseId", "quantity", "sellingPlanId", "attributes", "element", "key", "value", "u", "ComponentWrapper", "cn", "styles", "p", "Button", "motion", "addPropertyControls", "ConfigControls", "ProductBaseControls", "ButtonProperties", "ControlType", "textProperties"]
}
