{"version":3,"file":"FC_CatalogFavoriteButton.BLP-Rkjv.mjs","names":["React.useRef","React.useState"],"sources":["https:/framerusercontent.com/modules/826gVc58am9OJ0CWzeuA/HEGlKhM2O5uKepIHz1Hk/FC_CatalogFavoriteButton.js"],"sourcesContent":["/*\n * Framer Commerce\n * Confidential and Proprietary - All Rights Reserved\n * Unauthorized use, reproduction, distribution, or disclosure of this\n * source code or any related information is strictly prohibited.\n *\n * This software is the exclusive property of Framer Commerce (\"Company\").\n * It is considered highly confidential and proprietary information.\n *\n * Any use, copying, modification, distribution, or sharing of this software,\n * in whole or in part, without the express written permission of the Company\n * is strictly prohibited and may result in legal action.\n *\n * DISCLAIMER: This software does not provide any express or\n * implied warranties, including, but not limited to, the implied warranties\n * of merchantability and fitness for a particular purpose. In no event shall\n * Framer Commerce be liable for any direct, indirect, incidental, special,\n * exemplary, or consequential damages (including, but not limited to, procurement\n * of substitute goods or services; loss of use, data, or profits; or business\n * interruption) however caused and on any theory of liability, whether in\n * contract, strict liability, or tort (including negligence or otherwise)\n * arising in any way out of the use of this software, even if advised of\n * the possibility of such damage.\n *\n * Any unauthorized possession, use, copying, distribution, or dissemination\n * of this software will be considered a breach of confidentiality and may\n * result in legal action.\n *\n * For inquiries, contact:\n * Framer Commerce\n * Email: hello@framercommerce.com\n *\n * © 2025 Butter Supply Inc. All Rights Reserved.\n */import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{cloneElement}from\"react\";// Use DOM element to store state without React re-renders\nconst favoriteStore={element:typeof document!==\"undefined\"?document.createElement(\"div\"):null,getState(productId){if(!this.element)return false;try{const favorites=JSON.parse(localStorage.getItem(\"favorites\")||\"[]\");return favorites.includes(productId);}catch{return false;}},toggle(productId){if(!this.element)return;try{const favorites=JSON.parse(localStorage.getItem(\"favorites\")||\"[]\");const isCurrentlyActive=favorites.includes(productId);const newFavorites=isCurrentlyActive?favorites.filter(id=>id!==productId):[...favorites,productId];// Update localStorage first\nlocalStorage.setItem(\"favorites\",JSON.stringify(newFavorites));// Immediately notify subscribers of state change\nconst event=new CustomEvent(\"favorite-changed\",{detail:{productId,isActive:!isCurrentlyActive}});this.element.dispatchEvent(event);// Then dispatch the collection event\nconst collectionEvent=new CustomEvent(\"favorites-updated\",{detail:{favorites:newFavorites,productId,action:isCurrentlyActive?\"remove\":\"add\"}});document.dispatchEvent(collectionEvent);}catch(error){console.error(\"Error updating favorites:\",error);}},subscribe(productId,callback){if(!this.element)return()=>{};const handler=e=>{if(e.detail.productId===productId){callback(e.detail.isActive);}};this.element.addEventListener(\"favorite-changed\",handler);return()=>{this.element.removeEventListener(\"favorite-changed\",handler);};}};/**\n * @framerDisableUnlink\n */export default function FC_CatalogFavoriteButton(props){const{DefaultState,ActiveState,productId}=props;const buttonRef=React.useRef(null);const[isActive,setIsActive]=React.useState(()=>favoriteStore.getState(productId));const isInitialMount=React.useRef(true);React.useEffect(()=>{const button=buttonRef.current;if(!button)return;// Handle click directly on the DOM element\nconst handleClick=e=>{e.preventDefault();e.stopPropagation();// Update state optimistically\nsetIsActive(!isActive);favoriteStore.toggle(productId);};// Add click listener directly to DOM\nbutton.addEventListener(\"click\",handleClick,{capture:true});// Subscribe to state changes for sync\nconst unsubscribe=favoriteStore.subscribe(productId,newIsActive=>{if(isInitialMount.current){isInitialMount.current=false;return;}if(isActive!==newIsActive){setIsActive(newIsActive);}});return()=>{button.removeEventListener(\"click\",handleClick,{capture:true});unsubscribe();};},[productId,isActive]);const componentInstance=isActive?ActiveState:DefaultState;const content=Array.isArray(componentInstance)?componentInstance[0]:componentInstance;if(!content||!/*#__PURE__*/React.isValidElement(content)){return /*#__PURE__*/_jsx(\"div\",{ref:buttonRef,style:{width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",color:\"#666\",fontSize:\"14px\",transform:\"none\"},children:\"Connect Instance\"});}const renderedContent=/*#__PURE__*/cloneElement(content,{style:{...content.props?.style||{},width:\"100%\",height:\"100%\",transform:\"none\"}});if(RenderTarget.current()===RenderTarget.canvas){return /*#__PURE__*/_jsx(\"div\",{ref:buttonRef,style:{height:\"100%\",width:\"100%\",transform:\"none\"},children:renderedContent});}return /*#__PURE__*/_jsx(\"div\",{ref:buttonRef,style:{height:\"100%\",width:\"100%\",transform:\"none\",cursor:\"pointer\"},children:renderedContent});}addPropertyControls(FC_CatalogFavoriteButton,{productId:{type:ControlType.String,title:\"Product ID\",description:\"Connect to CMS\"},DefaultState:{type:ControlType.ComponentInstance,title:\"Default State\"},ActiveState:{type:ControlType.ComponentInstance,title:\"Active State\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FC_CatalogFavoriteButton\",\"slots\":[\"DefaultState\",\"ActiveState\"],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FC_CatalogFavoriteButton.map"],"mappings":"6MAuCG,SAAwB,EAAyB,EAAM,CAAC,GAAK,CAAC,eAAa,cAAY,aAAW,EAAY,EAAUA,EAAa,KAAK,CAAM,CAAC,EAAS,GAAaC,MAAmB,EAAc,SAAS,EAAU,CAAC,CAAO,EAAeD,EAAa,GAAK,CAAC,MAAoB,CAAC,IAAM,EAAO,EAAU,QAAQ,GAAG,CAAC,EAAO,OACvU,IAAM,EAAY,GAAG,CAAC,EAAE,gBAAgB,CAAC,EAAE,iBAAiB,CAC5D,EAAY,CAAC,EAAS,CAAC,EAAc,OAAO,EAAU,EACtD,EAAO,iBAAiB,QAAQ,EAAY,CAAC,QAAQ,GAAK,CAAC,CAC3D,IAAM,EAAY,EAAc,UAAU,EAAU,GAAa,CAAC,GAAG,EAAe,QAAQ,CAAC,EAAe,QAAQ,GAAM,OAAW,IAAW,GAAa,EAAY,EAAY,EAAI,CAAC,UAAU,CAAC,EAAO,oBAAoB,QAAQ,EAAY,CAAC,QAAQ,GAAK,CAAC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