{"version":3,"file":"FC_CatalogFilterResetButton.CVA57-e4.mjs","names":["useState","useRef","useCallback"],"sources":["https:/framerusercontent.com/modules/CffU1sgP5EvM90y1W3Yw/HqIjQeGXfIlXDJn49gve/FC_CatalogFilterResetButton.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{useCallback,cloneElement,useEffect,useState,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{parseUrlFilters,updateUrlWithFilters,convertFilterName}from\"https://framerusercontent.com/modules/A55TPw8oJtDToWtsjcDZ/efvR3aKErSMemVA7DBdP/filterMappings.js\";// Constants for debugging\nconst DEBUG_MODE=true;// Helper function for consistent logging\nconst logDebug=(action,data)=>{if(DEBUG_MODE){//console.log(`🔄 [FilterReset] ${action}:`, data);\n}};/**\n * @framerDisableUnlink\n */export default function FC_CatalogFilterResetButton(props){const{Default,showWhenNoFilters}=props;const[,setForceUpdate]=useState(0);const componentId=useRef(`filter-reset-${Date.now()}-${Math.random().toString(36).substr(2,9)}`).current;const mountedRef=useRef(true);// Force re-render when filters change\nuseEffect(()=>{if(!mountedRef.current)return;const handleFilterChange=()=>{logDebug(\"Filter change detected\");setForceUpdate(prev=>prev+1);};// Listen for filter changes\ndocument.addEventListener(\"product-filter-change\",handleFilterChange);document.addEventListener(\"filter-reset\",handleFilterChange);document.addEventListener(\"product-sort-change\",handleFilterChange);document.addEventListener(\"filter-navigation\",handleFilterChange);// Listen for URL changes\nconst observer=new MutationObserver(()=>{if(mountedRef.current){handleFilterChange();}});const body=document.querySelector(\"body\");if(body){observer.observe(body,{subtree:true,childList:true});}return()=>{mountedRef.current=false;document.removeEventListener(\"product-filter-change\",handleFilterChange);document.removeEventListener(\"filter-reset\",handleFilterChange);document.removeEventListener(\"product-sort-change\",handleFilterChange);document.removeEventListener(\"filter-navigation\",handleFilterChange);observer.disconnect();};},[]);const resetFilters=useCallback(()=>{try{logDebug(\"Resetting all filters\");// Get current URL and parse existing filters\nconst url=new URL(window.location.href);const currentFilters=parseUrlFilters(url.searchParams);// Log current state before reset\nlogDebug(\"Current filters before reset\",currentFilters);// Create empty filter state\nconst emptyFilters={collection:{active:false,values:[]},product_type:{active:false,values:[]},product_tag:{active:false,values:[]},variant:{active:false,values:[]},price:{active:false,values:[]},discount_amount:{active:false,values:[]},discount_percent:{active:false,values:[]},on_sale:{active:false,value:true},in_stock:{active:false,value:true},bundle:{active:false,value:true},subscription:{active:false,value:true}};// Update URL with empty filters\nupdateUrlWithFilters(emptyFilters,url);// Update URL without reloading the page\nwindow.history.pushState({},\"\",url.toString());// First send individual reset events for each filter type\nconst filterTypes=[\"collection\",\"product_type\",\"product_tag\",\"price\",\"discount_amount\",\"discount_percent\",\"variant\",\"on_sale\",\"in_stock\",\"bundle\",\"subscription\"];filterTypes.forEach(type=>{const legacyType=convertFilterName(type,true);logDebug(`Resetting filter: ${type} (legacy: ${legacyType})`);let eventDetail={type:legacyType,active:false,componentId:componentId};// Add specific value structure for different filter types\nif(type===\"discount_amount\"||type===\"discount_percent\"){eventDetail={...eventDetail,value:{values:[]}};}else if(type===\"variant\"){eventDetail={...eventDetail,value:\"\",values:[]};}else if(type===\"price\"){eventDetail={...eventDetail,value:{values:[]}};}else{eventDetail={...eventDetail,value:\"\",values:[]};}document.dispatchEvent(new CustomEvent(\"product-filter-change\",{detail:eventDetail}));});// Then send the filter-reset event to update UI\ndocument.dispatchEvent(new CustomEvent(\"filter-reset\",{detail:{timestamp:Date.now(),componentId:componentId,resetToInitialScope:true}}));// Reset sort to default\ndocument.dispatchEvent(new CustomEvent(\"product-sort-change\",{detail:{type:\"relevancy\",sortBy:\"relevancy\",sortDirection:null,componentId:componentId}}));// Dispatch filter navigation event\ndocument.dispatchEvent(new CustomEvent(\"filter-navigation\",{detail:{filters:emptyFilters,sourceComponentId:componentId}}));logDebug(\"All filters reset successfully\");}catch(error){console.error(\"Error resetting filters:\",error);}},[componentId]);// const handleClick = (e: React.MouseEvent) => {\n//     e.preventDefault();\n//     resetFilters();\n// };\n// Cleanup on unmount\nuseEffect(()=>{return()=>{mountedRef.current=false;};},[]);let content=Default?.[0]||null;if(!content){logDebug(\"No default content provided\");return null;}const clonedElement=/*#__PURE__*/cloneElement(content,{style:{...content.props?.style||{},width:\"100%\",height:\"100%\",cursor:\"pointer\"},onClick:resetFilters,\"aria-label\":\"Reset all filters\",role:\"button\",tabIndex:0,onKeyDown:e=>{if(e.key===\"Enter\"||e.key===\" \"){e.preventDefault();resetFilters();}}});// In canvas, always show\nif(typeof window===\"undefined\"||window.location.href.includes(\"framercanvas\")){return /*#__PURE__*/_jsx(\"div\",{style:{height:\"100%\",width:\"100%\"},children:clonedElement});}// In browser, check filters\nconst hasFilters=hasActiveFilters();// Show if there are filters OR showWhenNoFilters is true\nif(!hasFilters&&!showWhenNoFilters){return null;}return /*#__PURE__*/_jsx(\"div\",{style:{height:\"100%\",width:\"100%\"},children:clonedElement});}FC_CatalogFilterResetButton.defaultProps={Default:null,showWhenNoFilters:true};function hasActiveFilters(){if(typeof window===\"undefined\")return false;try{const url=new URL(window.location.href);const filters=parseUrlFilters(url.searchParams);// Check if any filter is active\nreturn Object.values(filters).some(filter=>filter.active);}catch(error){console.error(\"Error checking active filters:\",error);return false;}}addPropertyControls(FC_CatalogFilterResetButton,{Default:{type:ControlType.ComponentInstance,title:\"Button Design\"},showWhenNoFilters:{type:ControlType.Boolean,title:\"No Filters\",defaultValue:true,enabledTitle:\"Show\",disabledTitle:\"Hide\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FC_CatalogFilterResetButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FC_CatalogFilterResetButton.map"],"mappings":"sdAsCG,SAAwB,EAA4B,EAAM,CAAC,GAAK,CAAC,UAAQ,qBAAmB,EAAW,EAAE,GAAgBA,EAAS,EAAE,CAAO,EAAYC,EAAO,gBAAgB,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,QAAc,EAAWA,EAAO,GAAK,CAC9Q,MAAc,CAAC,GAAG,CAAC,EAAW,QAAQ,OAAO,IAAM,MAAuB,CAAC,EAAS,yBAAyB,CAAC,EAAe,GAAM,EAAK,EAAE,EAC1I,SAAS,iBAAiB,wBAAwB,EAAmB,CAAC,SAAS,iBAAiB,eAAe,EAAmB,CAAC,SAAS,iBAAiB,sBAAsB,EAAmB,CAAC,SAAS,iBAAiB,oBAAoB,EAAmB,CACxQ,IAAM,EAAS,IAAI,qBAAqB,CAAI,EAAW,SAAS,GAAoB,EAAI,CAAO,EAAK,SAAS,cAAc,OAAO,CAAgE,OAA5D,GAAM,EAAS,QAAQ,EAAK,CAAC,QAAQ,GAAK,UAAU,GAAK,CAA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