import {useRouter} from "framer"
function getRouteId(allRoute, path) {
for (const [key, value] of Object.entries(allRoute)) {
if (value?.path === path) {
return key
}
}
return ""
}
const PATH = "/page"
export function withNavigation(Component): ComponentType {
return (props) => {
const [store, setStore] = useStore()
const { navigate, routes } = useRouter()
const handleClick = (e) => {
e.preventDefault()
const allRoute = routes
let routeId = getRouteId(allRoute, PATH)
if (routeId === "") {
routeId = getRouteId(allRoute, "/")
}
navigate(routeId, "")
}
return <Component {...props} onClick={handleClick} />
}
}