{"version":3,"file":"Shopify_ProductPrice.Dme-Rl5e.mjs","names":["useState","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/xEahqZEsyG5uoZky61jQ/tpRjked6AKZmNun2ZAEz/_useProduct.js","https:/framerusercontent.com/modules/XUMZkHzkb6JRq7hdD46W/JEGzsKrHHSsc3iq3qc0v/Shopify_ProductPrice.js"],"sourcesContent":["import{useState,useEffect,useMemo}from\"react\";import{useAtom}from\"jotai\";import{useShopify}from\"https://framerusercontent.com/modules/tdCHCV0pSkxlDaX5GkOX/T2HZ5a4bzltl1yZXtjGv/_useShopify.js\";import{priceCode}from\"https://framerusercontent.com/modules/7dEgbg7qo3lsQk361YtS/NrF60tPHZRRgADqpoRFr/_utils.js\";import{selectedProductsAtom}from\"https://framerusercontent.com/modules/yZBbIevRfN36MGDPpltx/QsMt3lifGFhrUUWGTJnm/_atoms.js\";import{DefaultProduct}from\"https://framerusercontent.com/modules/fWwtzMT2tYXMW4IKB8On/1dFHOQ0gPjMC0e1WUStY/_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,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{cn,ProductBaseControls,ConfigControls,textProperties}from\"https://framerusercontent.com/modules/eAejHXy6apg0StNmpKvK/GXn1lJ5V4nUwhRO9yQKC/_framer_utils.js\";import{useProduct}from\"https://framerusercontent.com/modules/xEahqZEsyG5uoZky61jQ/tpRjked6AKZmNun2ZAEz/_useProduct.js\";import ComponentWrapper from\"https://framerusercontent.com/modules/hQlZBgGeLDev5WuUJA4d/6ncqGCEKZWsfLWpBe7Jn/ComponentWrapper.js\";/**\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function Shopify_ProductPrice(props){const{product,price,multiplePrice,availableForSale}=useProduct(props.productID??null,props.config);return /*#__PURE__*/_jsx(ComponentWrapper,{style:styles.container,productID:props.productID||\"EMPTY\",hidden:!product,config:props.config,children:()=>/*#__PURE__*/_jsxs(_Fragment,{children:[price.camparePrice&&/*#__PURE__*/_jsxs(\"span\",{style:cn(props.comparePriceStyle,props.comparePriceStyle.textDecoration),children:[price.camparePrice,\" \"]}),/*#__PURE__*/_jsxs(\"span\",{style:cn(props.priceStyle),children:[multiplePrice?props.startFromTitle:\"\",\" \",price.price]}),!availableForSale&&props.soldOutTitle&&/*#__PURE__*/_jsx(\"span\",{style:cn(props.soldOutStyle),children:props.soldOutTitle})]})});}Shopify_ProductPrice.displayName=\"Product Price\";addPropertyControls(Shopify_ProductPrice,{...ConfigControls,...ProductBaseControls,startFromTitle:{title:\"Start from Label\",type:ControlType.String,defaultValue:\"Start from\"},soldOutTitle:{title:\"Sold out Label\",type:ControlType.String,defaultValue:\"Sold out\"},priceStyle:{title:\"Price\",buttonTitle:\"Style\",type:ControlType.Object,controls:{hidden:{type:ControlType.Boolean,defaultValue:false},...textProperties(18,\"rgba(18, 18, 18, 1)\")}},comparePriceStyle:{title:\"Compare Price\",buttonTitle:\"Style\",type:ControlType.Object,controls:{hidden:{type:ControlType.Boolean,defaultValue:false},textDecoration:{title:\"Decoration\",buttonTitle:\"Style\",type:ControlType.Object,controls:{textDecorationLine:{title:\"Line\",type:ControlType.Enum,options:[\"none\",\"line-through\",\"overline\",\"underline\"],optionTitles:[\"Hidden\",\"Line through\",\"Overline\",\"Underline\"],defaultValue:\"line-through\"},textDecorationColor:{title:\"Color\",type:ControlType.Color,optional:true},textDecorationStyle:{title:\"Style\",type:ControlType.Enum,options:[\"solid\",\"double\",\"dotted\",\"dashed\",\"wavy\"],optionTitles:[\"Solid\",\"Double\",\"Dotted\",\"Dashed\",\"Wavy\"],defaultValue:\"solid\"},textDecorationThickness:{title:\"Thickness\",type:ControlType.Number,min:1,max:30,defaultValue:1}}},...textProperties(16,\"rgba(18, 18, 18, 0.75)\")}},soldOutStyle:{title:\"Sold Out\",buttonTitle:\"Style\",type:ControlType.Object,controls:{hidden:{type:ControlType.Boolean,defaultValue:false},lineThrough:{type:ControlType.Boolean,defaultValue:true},...textProperties(14,\"#fff\"),backgroundColor:{type:ControlType.Color,defaultValue:\"#000000\"},border:{type:ControlType.Border,defaultValue:{borderWidth:0}},padding:{type:ControlType.Padding,defaultValue:\"2px 8px 2px 8px\"},borderRadius:{type:ControlType.BorderRadius,defaultValue:\"20px\"}}}});const styles={container:{display:\"flex\",flexDirection:\"row\",flexWrap:\"wrap\",gap:8,alignItems:\"center\"},comparePrice:{textDecoration:\"line-through\"}};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Shopify_ProductPrice\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"oWAA4oB,SAAgB,EAAW,EAAU,EAAO,EAAc,CAAC,GAAK,CAAC,EAAiB,GAAqB,EAAQ,EAAqB,CAAM,CAAC,YAAU,EAAW,EAAO,CAAM,CAAC,EAAQ,GAAYA,EAAS,GAAQ,SAAS,EAAe,KAAK,CAAO,EAAS,GAAS,GAAG,EAAiB,EAAQ,IAAI,KAC/6B,GAAU,EAAa,IAAQ,CAAC,IAAM,EAAkB,GAAc,EAAa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