{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/4w9sJWojogi6mWAJoJH9/yWDuikQSaQQDOJT4sG0Q/FC_SortButton.js"],
  "sourcesContent": ["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";export default function FC_SortButton(props){const{DropdownVisual,relevanceText=\"Relevance\",titleAscText=\"A-Z\",titleDescText=\"Z-A\",priceAscText=\"Price (lowest first)\",priceDescText=\"Price (highest first)\",newestText=\"Newest\",bestSellingText=\"Best Selling\"}=props;const[currentSort,setCurrentSort]=React.useState(\"relevance\");// Map internal sort values to display text\nconst sortOptions=React.useMemo(()=>{return[{value:\"relevance\",text:relevanceText},{value:\"title_asc\",text:titleAscText},{value:\"title_desc\",text:titleDescText},{value:\"price_asc\",text:priceAscText},{value:\"price_desc\",text:priceDescText},{value:\"newest\",text:newestText},{value:\"best_selling\",text:bestSellingText}].filter(option=>option.text)// Filter out options with empty text\n;},[relevanceText,titleAscText,titleDescText,priceAscText,priceDescText,newestText,bestSellingText]);// Get the current sort text\nconst getCurrentSortText=React.useCallback(()=>{const option=sortOptions.find(opt=>opt.value===currentSort);return option?.text||relevanceText;},[currentSort,sortOptions,relevanceText]);// Helper function to update text content with {{param}}\nconst updateButtonContent=element=>{if(!element||typeof element!==\"object\")return element;// Handle arrays\nif(Array.isArray(element)){return element.map(child=>updateButtonContent(child));}if(!/*#__PURE__*/React.isValidElement(element))return element;const{children,...otherProps}=element.props;// Special handling for Framer Text components\nif(element.type?.displayName?.includes(\"Text\")){const text=element.props.text||\"\";const newText=text.replace(/{{param}}/g,getCurrentSortText());return /*#__PURE__*/React.cloneElement(element,{...otherProps,text:newText});}// Handle children recursively\nlet newChildren=children;if(children){if(typeof children===\"string\"){newChildren=children.replace(/{{param}}/g,getCurrentSortText());}else if(/*#__PURE__*/React.isValidElement(children)||Array.isArray(children)){newChildren=updateButtonContent(children);}}return /*#__PURE__*/React.cloneElement(element,{...otherProps,children:newChildren});};// Handle sort change\nconst handleSortChange=React.useCallback(e=>{const value=e.target.value;setCurrentSort(value);// Map URL sort parameter to internal sort configuration\nlet sortConfig;switch(value){case\"relevance\":sortConfig={type:\"relevancy\",sortBy:\"relevancy\",sortDirection:null};break;case\"title_asc\":sortConfig={type:\"name\",sortBy:\"name\",sortDirection:\"aToZ\"};break;case\"title_desc\":sortConfig={type:\"name\",sortBy:\"name\",sortDirection:\"zToA\"};break;case\"price_asc\":sortConfig={type:\"price\",sortBy:\"price\",sortDirection:\"lowToHigh\"};break;case\"price_desc\":sortConfig={type:\"price\",sortBy:\"price\",sortDirection:\"highToLow\"};break;case\"newest\":sortConfig={type:\"created\",sortBy:\"created\",sortDirection:\"newest\"};break;case\"best_selling\":sortConfig={type:\"best-selling\",sortBy:\"best-selling\",sortDirection:null};break;}// Update URL with sort parameter\nif(typeof window!==\"undefined\"){const url=new URL(window.location.href);url.searchParams.set(\"sort\",value);window.history.pushState({sortConfig},\"\",url.toString());}// Dispatch sort change event\ndocument.dispatchEvent(new CustomEvent(\"product-sort-change\",{detail:sortConfig}));},[]);// Update sort value from URL on mount and URL changes\nReact.useEffect(()=>{if(typeof window===\"undefined\")return;const updateSortFromUrl=()=>{const urlParams=new URLSearchParams(window.location.search);const sortParam=urlParams.get(\"sort\");if(sortParam&&sortOptions.some(option=>option.value===sortParam)){setCurrentSort(sortParam);}};updateSortFromUrl();window.addEventListener(\"popstate\",updateSortFromUrl);return()=>{window.removeEventListener(\"popstate\",updateSortFromUrl);};},[sortOptions]);return /*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\",width:\"100%\",height:\"100%\"},children:[/*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\",pointerEvents:\"none\"},children:updateButtonContent(DropdownVisual)}),/*#__PURE__*/_jsx(\"select\",{value:currentSort,onChange:handleSortChange,style:{position:\"absolute\",top:0,left:0,width:\"100%\",height:\"100%\",opacity:0,cursor:\"pointer\"},children:sortOptions.map(option=>/*#__PURE__*/_jsx(\"option\",{value:option.value,children:option.text},option.value))})]});}addPropertyControls(FC_SortButton,{DropdownVisual:{type:ControlType.ComponentInstance,title:\"Component\",description:\"Connect to native Framer component, on-canvas but off-page. Use {{param}} in text to show the current sort option\"},relevanceText:{type:ControlType.String,title:\"Relevance\",defaultValue:\"Relevance\"},titleAscText:{type:ControlType.String,title:\"Title (A-Z)\",defaultValue:\"A-Z\"},titleDescText:{type:ControlType.String,title:\"Title (Z-A)\",defaultValue:\"Z-A\"},priceAscText:{type:ControlType.String,title:\"Price (Low)\",defaultValue:\"Price (lowest first)\"},priceDescText:{type:ControlType.String,title:\"Price (High)\",defaultValue:\"Price (highest first)\"},newestText:{type:ControlType.String,title:\"Newest\",defaultValue:\"Newest\"},bestSellingText:{type:ControlType.String,title:\"Best Selling\",defaultValue:\"Best Selling\",description:\"Empty fields won't be displayed\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FC_SortButton\",\"slots\":[\"DropdownVisual\"],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FC_SortButton.map"],
  "mappings": "8KAAwJ,SAARA,EAA+BC,EAAM,CAAC,GAAK,CAAC,eAAAC,EAAe,cAAAC,EAAc,YAAY,aAAAC,EAAa,MAAM,cAAAC,EAAc,MAAM,aAAAC,EAAa,uBAAuB,cAAAC,EAAc,wBAAwB,WAAAC,EAAW,SAAS,gBAAAC,EAAgB,cAAc,EAAER,EAAW,CAACS,EAAYC,CAAc,EAAQC,EAAS,WAAW,EACtcC,EAAkBC,EAAQ,IAAW,CAAC,CAAC,MAAM,YAAY,KAAKX,CAAa,EAAE,CAAC,MAAM,YAAY,KAAKC,CAAY,EAAE,CAAC,MAAM,aAAa,KAAKC,CAAa,EAAE,CAAC,MAAM,YAAY,KAAKC,CAAY,EAAE,CAAC,MAAM,aAAa,KAAKC,CAAa,EAAE,CAAC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,MAAM,OAAO,OAAO,OAAO,cAAc,MAAM,EAAE,SAASlB,EAAoBjB,CAAc,CAAC,CAAC,EAAemC,EAAK,SAAS,CAAC,MAAM3B,EAAY,SAASkB,EAAiB,MAAM,CAAC,SAAS,WAAW,IAAI,EAAE,KAAK,EAAE,MAAM,OAAO,OAAO,OAAO,QAAQ,EAAE,OAAO,SAAS,EAAE,SAASf,EAAY,IAAIE,GAAqBsB,EAAK,SAAS,CAAC,MAAMtB,EAAO,MAAM,SAASA,EAAO,IAAI,EAAEA,EAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAACuB,EAAoBtC,EAAc,CAAC,eAAe,CAAC,KAAKuC,EAAY,kBAAkB,MAAM,YAAY,YAAY,mHAAmH,EAAE,cAAc,CAAC,KAAKA,EAAY,OAAO,MAAM,YAAY,aAAa,WAAW,EAAE,aAAa,CAAC,KAAKA,EAAY,OAAO,MAAM,cAAc,aAAa,KAAK,EAAE,cAAc,CAAC,KAAKA,EAAY,OAAO,MAAM,cAAc,aAAa,KAAK,EAAE,aAAa,CAAC,KAAKA,EAAY,OAAO,MAAM,cAAc,aAAa,sBAAsB,EAAE,cAAc,CAAC,KAAKA,EAAY,OAAO,MAAM,eAAe,aAAa,uBAAuB,EAAE,WAAW,CAAC,KAAKA,EAAY,OAAO,MAAM,SAAS,aAAa,QAAQ,EAAE,gBAAgB,CAAC,KAAKA,EAAY,OAAO,MAAM,eAAe,aAAa,eAAe,YAAY,iCAAiC,CAAC,CAAC",
  "names": ["FC_SortButton", "props", "DropdownVisual", "relevanceText", "titleAscText", "titleDescText", "priceAscText", "priceDescText", "newestText", "bestSellingText", "currentSort", "setCurrentSort", "ye", "sortOptions", "se", "option", "getCurrentSortText", "te", "opt", "updateButtonContent", "element", "child", "J", "children", "otherProps", "newText", "q", "newChildren", "handleSortChange", "value", "sortConfig", "window", "url", "ue", "updateSortFromUrl", "sortParam", "u", "p", "addPropertyControls", "ControlType"]
}
