{"version":3,"file":"FC_CatalogResultCounter.B1v7SRte.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/Uua6HH41VQEb0xszmKqn/pVEgR8qI8XT6pbPUUpoi/FC_CatalogResultCounter.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{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useEffect,useState}from\"react\";/**\n * @framerIntrinsicWidth 100%\n * @framerIntrinsicHeight auto\n * @framerSupportedLayoutWidth fixed | fill\n * @framerSupportedLayoutHeight fixed | auto\n */// Helper function for consistent logging\nconst logDebug=(component,action,data)=>{//console.log(`🔍 [${component}] ${action}:`, data)\n};/**\n * @framerDisableUnlink\n */export default function FC_CatalogResultCounter(props){const{type,content,font,color,transform,noQuery,searchText,noFavorites,favoritesText,noResults,defaultText,preview}=props;// State for search term and result count\nconst[searchTerm,setSearchTerm]=useState(\"\");const[resultCount,setResultCount]=useState(0);// Track whether we've ever seen a positive (non-zero) result count.\n// This lets us avoid showing the Default empty state on initial load,\n// but still show it later when a user filters down to zero.\nconst[hasPositiveResults,setHasPositiveResults]=useState(false);// Delay rendering to prevent empty state flash on initial load\nconst[isReady,setIsReady]=useState(false);// Detect if we're in canvas\nconst isCanvas=()=>{if(typeof window===\"undefined\")return false;try{return window.document?.location?.href.includes(\"framer\")||window.document?.location?.pathname.includes(\"preview\")||!window.document?.location?.host||window.parent!==window;}catch(e){return true;}};// Apply text transform\nconst getTransformedText=(text,transform)=>{switch(transform){case\"Uppercase\":return text.toUpperCase();case\"Lowercase\":return text.toLowerCase();case\"Capitalize\":return text.split(\" \").map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase()).join(\" \");default:return text;}};// Replace placeholders with actual values\nconst getFormattedText=text=>{const term=isCanvas()&&!searchTerm?\"term\":searchTerm;return text.replace(/\\{\\{term\\}\\}/g,term).replace(/\\{\\{\\#\\}\\}/g,resultCount.toString());};// Check if URL has search param\nconst hasSearchParam=()=>{if(typeof window===\"undefined\")return false;const urlParams=new URLSearchParams(window.location.search);return urlParams.has(\"search\");};// Get the appropriate text content based on state\nconst getDisplayText=()=>{// Canvas preview mode: force show empty or populated state\nif(RenderTarget.current()===RenderTarget.canvas){if(preview===\"Empty\"){// Force empty state based on type\nif(type===\"Search\"){return noQuery===\"Show\"?searchText||\"\":\"\";}if(type===\"Favorites\"){return noFavorites===\"Show\"?favoritesText||\"\":\"\";}if(type===\"Default\"){return noResults===\"Show\"?defaultText||\"\":\"\";}}// Preview === 'Results': show populated state (content)\nif(preview===\"Results\"){return content;}}// Normal runtime behavior (browser view)\n// If type is Search and no query param exists\nif(type===\"Search\"&&!hasSearchParam()){// Show text if noQuery is 'Show', otherwise return empty\nif(noQuery===\"Show\"){return searchText||\"\";}return\"\";}// If type is Favorites and no favorites exist\nif(type===\"Favorites\"&&resultCount===0){// Show text if noFavorites is 'Show', otherwise return empty\nif(noFavorites===\"Show\"){return favoritesText||\"\";}return\"\";}// If type is Default and no results exist\nif(type===\"Default\"&&resultCount===0){// On canvas, always show the configured empty state so designers\n// can see it, regardless of runtime flicker concerns.\nif(!isCanvas()){// In live runtime, avoid showing empty state on very first load\n// before we've ever seen a positive count, to prevent flicker.\nif(!hasPositiveResults){return\"\";}}// Respect the configured empty state behavior.\nif(noResults===\"Show\"){return defaultText||\"\";}return\"\";}return content;};// Get favorites count from localStorage\nconst getFavoritesCount=()=>{if(typeof window===\"undefined\")return 0;try{const favorites=JSON.parse(localStorage.getItem(\"favorites\")||\"[]\");return favorites.length;}catch{return 0;}};// Delay visibility by 5 seconds to prevent empty state flash (browser only)\n// Component renders immediately but is invisible (opacity 0) to prevent layout shift\nuseEffect(()=>{// Always show immediately in canvas for design preview\nif(RenderTarget.current()===RenderTarget.canvas){setIsReady(true);return;}// In browser, delay visibility (fade in after X seconds)\nconst timer=setTimeout(()=>{setIsReady(true);},500);return()=>clearTimeout(timer);},[]);// Listen for search events\nuseEffect(()=>{// If type is Favorites, initialize count from localStorage\nif(type===\"Favorites\"){setResultCount(getFavoritesCount());}const handleSearchChange=e=>{logDebug(\"SearchResults\",\"Received search event\",e.detail);// Handle different event types\nconst term=e.detail.term||e.detail.search;setSearchTerm(term);if(e.detail.term===\"\"&&e.detail.count){// Only update count if not Favorites type\nif(type!==\"Favorites\"){setResultCount(e.detail.count);}}};const handleResultsChange=e=>{logDebug(\"SearchResults\",\"Received results count\",e.detail);// Only update count if not Favorites type\nif(type!==\"Favorites\"){const nextCount=e.detail.count||0;setResultCount(nextCount);if(e.detail.search===\"\"){setResultCount(e.detail.count);}if(nextCount>0){setHasPositiveResults(true);}}};const handleFavoritesUpdate=e=>{// Only handle favorites updates if type is Favorites\nif(type===\"Favorites\"){const{favorites}=e.detail||{};const countFromEvent=favorites&&Array.isArray(favorites)?favorites.length:null;if(countFromEvent!==null){setResultCount(countFromEvent);if(countFromEvent>0){setHasPositiveResults(true);}}else{// Fallback to reading from localStorage\nconst fallbackCount=getFavoritesCount();setResultCount(fallbackCount);if(fallbackCount>0){setHasPositiveResults(true);}}}};// Check URL for initial search term\nconst updateSearchFromURL=()=>{if(typeof window!==\"undefined\"){const urlParams=new URLSearchParams(window.location.search);const searchParam=urlParams.get(\"search\");if(searchParam){setSearchTerm(searchParam);}}};// Initial URL check\nupdateSearchFromURL();// Listen for URL changes\nwindow.addEventListener(\"popstate\",updateSearchFromURL);// Listen for all search-related events (only if not Favorites)\nif(type!==\"Favorites\"){document.addEventListener(\"product-search-change\",handleSearchChange);document.addEventListener(\"filter-navigation\",handleSearchChange);document.addEventListener(\"product-search-results\",handleResultsChange);}// Listen for favorites updates (only if type is Favorites)\nif(type===\"Favorites\"){document.addEventListener(\"favorites-updated\",handleFavoritesUpdate);}return()=>{window.removeEventListener(\"popstate\",updateSearchFromURL);if(type!==\"Favorites\"){document.removeEventListener(\"product-search-change\",handleSearchChange);document.removeEventListener(\"filter-navigation\",handleSearchChange);document.removeEventListener(\"product-search-results\",handleResultsChange);}if(type===\"Favorites\"){document.removeEventListener(\"favorites-updated\",handleFavoritesUpdate);}};},[type]);// Container style\nconst containerStyle={width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"center\"};// Text style\nconst textStyle={...font,color:color,textTransform:transform.toLowerCase()};// Always render to prevent layout shift, but control opacity\nreturn /*#__PURE__*/_jsx(\"div\",{style:{...containerStyle,opacity:isReady?1:0,transition:\"opacity 0.3s ease-in-out\"},children:/*#__PURE__*/_jsx(\"span\",{style:textStyle,children:getTransformedText(getFormattedText(getDisplayText()),transform)})});}FC_CatalogResultCounter.defaultProps={type:\"Default\",content:\"{{#}} items\",font:{family:\"Inter\",fontSize:16,weight:400},color:\"#000000\",transform:\"None\",noQuery:\"Hide\",searchText:\"\",noFavorites:\"Hide\",favoritesText:\"\",noResults:\"Hide\",defaultText:\"\",preview:\"Results\"};addPropertyControls(FC_CatalogResultCounter,{preview:{type:ControlType.Enum,title:\"Preview\",options:[\"Results\",\"Empty\"],defaultValue:\"Results\",displaySegmentedControl:true,segmentedControlDirection:\"horizontal\",description:\"For canvas preview only. Framer Preview won't show true behavior; test in real browser.\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},transform:{type:ControlType.Enum,title:\"Transform\",options:[\"None\",\"Uppercase\",\"Lowercase\",\"Capitalize\"],defaultValue:\"None\"},type:{type:ControlType.Enum,title:\"Type\",options:[\"Default\",\"Search\",\"Favorites\"],displaySegmentedControl:true,segmentedControlDirection:\"vertical\",defaultValue:\"Default\"},content:{type:ControlType.String,title:\"↳ Text\",defaultValue:\"{{#}} items\",description:\"Use {{#}} for item count. \\n \\n If on a dedicated Search page, use {{term}} for the search value.\"},noQuery:{type:ControlType.Enum,title:\"No Query\",options:[\"Show\",\"Hide\"],defaultValue:\"Hide\",displaySegmentedControl:true,segmentedControlDirection:\"horizontal\",hidden:props=>props.type!==\"Search\",description:\"Text to display if no query param exists.\"},searchText:{type:ControlType.String,title:\"↳ Text\",defaultValue:\"Start your search...\",hidden:props=>props.type!==\"Search\"||props.noQuery===\"Hide\"},noFavorites:{type:ControlType.Enum,title:\"No Favorites\",options:[\"Show\",\"Hide\"],defaultValue:\"Hide\",displaySegmentedControl:true,segmentedControlDirection:\"horizontal\",hidden:props=>props.type!==\"Favorites\",description:\"Text to display if no favorites exist.\"},favoritesText:{type:ControlType.String,title:\"↳ Text\",defaultValue:\"No favorites yet...\",hidden:props=>props.type!==\"Favorites\"||props.noFavorites===\"Hide\"},noResults:{type:ControlType.Enum,title:\"No Results\",options:[\"Show\",\"Hide\"],defaultValue:\"Hide\",displaySegmentedControl:true,segmentedControlDirection:\"horizontal\",hidden:props=>props.type!==\"Default\",description:\"Text to display if no results exist.\"},defaultText:{type:ControlType.String,title:\"↳ Text\",defaultValue:\"No results found...\",hidden:props=>props.type!==\"Default\"||props.noResults===\"Hide\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FC_CatalogResultCounter\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FC_CatalogResultCounter.map"],"mappings":"iMA0CG,SAAwB,EAAwB,EAAM,CAAC,GAAK,CAAC,OAAK,UAAQ,OAAK,QAAM,YAAU,UAAQ,aAAW,cAAY,gBAAc,YAAU,cAAY,WAAS,EACzK,CAAC,EAAW,GAAeA,EAAS,EAAE,EAAO,CAAC,EAAY,GAAgBA,EAAS,CAAC,EAGpF,CAAC,EAAmB,GAAuBA,EAAS,EAAK,EACzD,CAAC,EAAQ,GAAYA,EAAS,EAAK,EAClC,MAAa,CAAC,GAAU,IAAS,OAAY,MAAO,GAAM,GAAG,CAAC,OAAO,EAAO,UAAU,UAAU,KAAK,SAAS,QAAQ,GAAG,EAAO,UAAU,UAAU,SAAS,SAAS,SAAS,GAAG,CAAC,EAAO,UAAU,UAAU,MAAM,EAAO,SAAS,CAAO,MAAS,CAAC,MAAO,EAAK,CAAC,EAClQ,GAAoB,EAAK,IAAY,CAAC,OAAO,EAAP,CAAkB,IAAI,YAAY,OAAO,EAAK,YAAY,EAAE,IAAI,YAAY,OAAO,EAAK,YAAY,EAAE,IAAI,aAAa,OAAO,EAAK,MAAM,GAAG,CAAC,CAAC,IAAI,GAAM,EAAK,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,EAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,QAAQ,OAAO,CAAK,CAAC,EACvR,EAAiB,GAAM,CAAC,IAAM,EAAK,EAAS,GAAG,CAAC,EAAW,OAAO,EAAW,OAAO,EAAK,QAAQ,gBAAgB,CAAI,CAAC,CAAC,QAAQ,cAAc,EAAY,SAAS,CAAC,CAAE,EACrK,MAA8B,IAAS,QAA4F,IAA/C,gBAAgB,EAAO,SAAS,MAAuB,CAAC,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