import React, { useEffect, useState } from 'react';
export const Route = ({ element }) => {
    return React.createElement(React.Fragment, null, element);
};
export const Router = ({ history, children }) => {
    const [currentLocation, setCurrentLocation] = useState({
        pathname: '/',
        state: null,
        key: '',
        search: '',
        hash: '',
    });
    useEffect(() => {
        history.push('/');
        const handleRouteChange = ({ location }) => {
            setCurrentLocation(location);
        };
        const unlisten = history.listen(handleRouteChange);
        return () => {
            unlisten();
        };
    }, [history]);
    const renderElement = () => {
        const routes = React.Children.toArray(children);
        const route = routes.find((r) => r.props.path === currentLocation.pathname);
        if (route) {
            return route.props.element;
        }
        // Handle 404 page not found
        return React.createElement("div", null, "404 - Page Not Found");
    };
    return React.createElement(React.Fragment, null, renderElement());
};
export default Router;
//# sourceMappingURL=Router.js.map