{"version":3,"file":"SN_BundleDiscountBadge.CSSup403.mjs","names":["useRef","useState","__esmMin","init_npm_react_18_3_1","init_ssg_sandbox_shims","window","ce","init_jsx_runtime","c","_e","de","addPropertyControls","RenderTarget","init_framer_DKtAEkcX","ControlType","init_SN_BundlePriceDisplay","useBundleComputedDetail","parseMoneyCents","value","raw","formatAmount","cents","SN_BundleDiscountBadge","props","isCanvas","ref","eventDetail","setEventDetail","listenToLiveEvent","cached","matchHandle","accept","d","handler","e","computed","productID","detail","savingsCents","percent","cur","price","cmp","comparePrice","label","mode","amountTemplate","percentTemplate","font","paddingV","paddingH","radius","borderWidth","borderColor","spaceBelow","init_SN_BundleDiscountBadge","p"],"sources":["https:/framerusercontent.com/modules/XKYWknNSDBgdy71ApVNM/hZ10Kzq3jxJuUEnkr1HD/SN_BundleDiscountBadge.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useState,useEffect,useRef}from\"react\";import{useBundleComputedDetail}from\"https://framerusercontent.com/modules/jJb9uOGH7PPskLBZklBW/GloWPmSexuDnNm2Z1aKZ/SN_BundlePriceDisplay.js\";function parseMoneyCents(value){if(value===null||value===undefined)return null;if(typeof value===\"number\")return Number.isFinite(value)?Math.round(value*100):null;const raw=String(value).replace(/[^0-9.\\-]/g,\"\").trim();if(raw===\"\"||!/^-?\\d*(\\.\\d+)?$/.test(raw))return null;const n=Number(raw);return Number.isFinite(n)?Math.round(n*100):null;}function formatAmount(cents){return cents%100===0?String(Math.round(cents/100)):(cents/100).toFixed(2);}export default function SN_BundleDiscountBadge(props){const{productID,mode,price,comparePrice,listenToLiveEvent,matchHandle,percentTemplate,amountTemplate,color,background,fontSize,fontWeight,paddingV,paddingH,radius,borderWidth,borderColor,spaceBelow,font}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const ref=useRef(null);// (1) live event\nconst[eventDetail,setEventDetail]=useState(()=>{if(typeof window===\"undefined\"||!listenToLiveEvent)return null;const cached=window.__acelinkBundlePrice;if(!cached)return null;if(matchHandle&&cached.bundleHandle!==matchHandle)return null;return cached;});useEffect(()=>{if(typeof window===\"undefined\"||!listenToLiveEvent||isCanvas)return;const accept=d=>{if(!d)return;if(matchHandle&&d.bundleHandle!==matchHandle)return;setEventDetail(d);};accept(window.__acelinkBundlePrice);const handler=e=>accept(e.detail);window.addEventListener(\"sn-bundle:price\",handler);return()=>window.removeEventListener(\"sn-bundle:price\",handler);// eslint-disable-next-line react-hooks/exhaustive-deps\n},[listenToLiveEvent,matchHandle,isCanvas]);// (2) computed by productID (shared with SN_BundlePriceDisplay)\nconst computed=useBundleComputedDetail(productID,ref);// The live-event cache is GLOBAL (window.__acelinkBundlePrice = the last\n// PDP configurator broadcast). After coming back from a PDP, every grid\n// card badge would adopt THAT bundle's discount (Asana 1216783719408759\n// part 2: all cards showed the visited bundle's -26%). When the per-card\n// computed detail resolves to a DIFFERENT bundle, computed wins; the live\n// event stays authoritative only where it matches (PDP, matchHandle).\nconst detail=eventDetail&&computed&&eventDetail.bundleHandle!==computed.bundleHandle?computed:eventDetail||computed;// resolve savings: detail (event/computed) first, then manual controls\nlet savingsCents=0;let percent=0;if(detail&&detail.hasCompare&&detail.savings>0){savingsCents=Math.round(detail.savings*100);percent=detail.savingsPercent;}else{const cur=parseMoneyCents(price);const cmp=parseMoneyCents(comparePrice);if(cur!==null&&cmp!==null&&cmp>cur){savingsCents=cmp-cur;percent=Math.round(savingsCents/cmp*100);}}if(isCanvas&&savingsCents<=0){savingsCents=31155;percent=34;}if(savingsCents<=0||percent<=0)return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{width:0,height:0}});const label=mode===\"Amount\"?(amountTemplate||\"-${amount}\").replace(\"{amount}\",formatAmount(savingsCents)):(percentTemplate||\"-{percent}%\").replace(\"{percent}\",String(percent));return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{display:\"inline-flex\",alignItems:\"center\",justifyContent:\"center\",fontFamily:'\"TASA Orbiter\", \"TASA Orbiter Placeholder\", sans-serif',fontWeight,fontSize,lineHeight:1,...font||{},color,background,padding:`${paddingV}px ${paddingH}px`,borderRadius:radius,...borderWidth&&borderWidth>0?{border:`${borderWidth}px solid ${borderColor||\"#0A0A0A\"}`}:{},whiteSpace:\"nowrap\",...spaceBelow&&spaceBelow>0?{marginBottom:spaceBelow}:{},userSelect:\"none\",pointerEvents:\"none\"},children:label});}SN_BundleDiscountBadge.defaultProps={productID:\"\",mode:\"Percent\",price:\"\",comparePrice:\"\",listenToLiveEvent:true,matchHandle:\"\",percentTemplate:\"-{percent}%\",amountTemplate:\"-${amount}\",color:\"var(--token-9fb53b3d-e0a8-4870-91e2-0dccf00d2c3b, rgb(224, 22, 22))\",background:\"var(--token-5d7827db-2504-44e9-9d0e-b4057d91463b, rgb(255, 255, 255))\",fontSize:14,fontWeight:600,paddingV:4,paddingH:4,radius:0,borderWidth:0,borderColor:\"#0A0A0A\",spaceBelow:0};addPropertyControls(SN_BundleDiscountBadge,{productID:{type:ControlType.String,title:\"Product ID\",description:\"Bind to the card's Product ID variable. Computes the bundle discount for grid/category cards. Leave empty on PDPs (live event drives it).\"},mode:{type:ControlType.Enum,title:\"Mode\",options:[\"Percent\",\"Amount\"],optionTitles:[\"Percent (-38%)\",\"Amount (-$200)\"],displaySegmentedControl:true},price:{type:ControlType.String,title:\"Price\",description:\"Last-resort fallback when no event/productID — bind to the card's Price variable.\"},comparePrice:{type:ControlType.String,title:\"Compare Price\"},listenToLiveEvent:{type:ControlType.Boolean,title:\"Live Event\",description:\"Follow sn-bundle:price from the bundle configurator.\"},matchHandle:{type:ControlType.String,title:\"Match Handle\",description:\"Only accept live events for this bundle handle.\"},spaceBelow:{type:ControlType.Number,title:\"Space Below\",defaultValue:0,min:0,max:40,description:\"Gap under the badge, only while it is visible (stacked badges).\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",displayFontSize:true,displayTextAlignment:false,description:\"Overrides the default TASA Orbiter / Font Size / Font Weight when set.\"},percentTemplate:{type:ControlType.String,title:\"% Template\"},amountTemplate:{type:ControlType.String,title:\"$ Template\"},color:{type:ControlType.Color,title:\"Text\"},background:{type:ControlType.Color,title:\"Background\"},fontSize:{type:ControlType.Number,title:\"Font Size\",min:8,max:40},fontWeight:{type:ControlType.Number,title:\"Font Weight\",min:300,max:900,step:100},paddingV:{type:ControlType.Number,title:\"Padding V\",min:0,max:40},paddingH:{type:ControlType.Number,title:\"Padding H\",min:0,max:40},radius:{type:ControlType.Number,title:\"Radius\",min:0,max:40},borderWidth:{type:ControlType.Number,title:\"Border\",min:0,max:8,defaultValue:0},borderColor:{type:ControlType.Color,title:\"Border Color\",defaultValue:\"#0A0A0A\",hidden:p=>!p.borderWidth}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SN_BundleDiscountBadge\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SN_BundleDiscountBadge.map"],"mappings":"A,+QAAuS,SAASiB,EAAgB,EAAM,CAAC,GAAGC,GAAQ,KAAwB,OAAO,KAAK,GAAG,OAAOA,GAAQ,SAAS,OAAO,OAAO,SAASA,CAAK,EAAE,KAAK,MAAMA,EAAM,GAAG,EAAE,KAAK,IAAMC,EAAI,OAAOD,CAAK,CAAC,CAAC,QAAQ,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,GAAGC,IAAM,IAAI,CAAC,kBAAkB,KAAKA,CAAG,EAAE,OAAO,KAAK,IAAM,EAAE,OAAOA,CAAG,EAAE,OAAO,OAAO,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,GAAG,EAAE,IAAK,CAAC,SAASC,EAAa,EAAM,CAAC,OAAOC,EAAM,KAAM,EAAE,OAAO,KAAK,MAAMA,EAAM,GAAG,CAAC,GAAGA,EAAM,IAAA,CAAK,QAAQ,CAAC,CAAE,CAAC,SAAwBC,EAAuB,EAAM,CAAC,G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