Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_chunk = require("./chunk-BN4qSVkS.cjs");
const require_styles_colors = require("./styles/colors.cjs");
const require_components_typography_renderTypography = require("./components/typography/renderTypography.cjs");
const require_utils_strings = require("./utils/strings.cjs");
let _emotion_styled = require("@emotion/styled");
_emotion_styled = require_chunk.__toESM(_emotion_styled);
let lodash_es = require("lodash-es");
let react = require("react");
let react_router_dom = require("react-router-dom");
let _emotion_react_jsx_runtime = require("@emotion/react/jsx-runtime");
//#region src/router.tsx
function replaceParams(to, params, hash) {
	if (params) {
		let toWithParams = to;
		Object.entries((0, lodash_es.omit)(params, "query")).forEach(([key, value]) => {
			if (typeof value !== "string") throw new Error(`Only 'query' may be an object. Route params must be a string, but '${key}' is not.`);
			toWithParams = toWithParams.replace(`:${key}`, value);
		});
		if (params.query) {
			let query = params.query;
			if (typeof query !== "string") query = Object.entries(params.query).map(([key, value]) => `${key}${value ? `=${value}` : ""}`).join("&");
			toWithParams = `${toWithParams}?${query}`;
		}
		to = toWithParams;
	}
	if (hash) to = `${to}#${hash}`;
	return to;
}
const LinkBase = (0, react.forwardRef)(({ to, id, externalLink, filename, params, children, text, css, onClick, className, hash = null, blue = false, newTab: newTabProp, typography }, ref) => {
	if (!require_utils_strings.isString(to) && !externalLink && !onClick) throw new Error("Link must have either `to` or `externalLink` or `onClick` defined");
	let toStr;
	let newTab = Boolean(newTabProp);
	if (require_utils_strings.isString(to)) toStr = replaceParams(to, params, hash);
	else if (externalLink) {
		const definedExternalLink = externalLink;
		if (!definedExternalLink.startsWith("http") && !definedExternalLink.startsWith("mailto:")) throw new Error("Link's externalLink must start with http or mailto:");
		if (newTabProp === void 0) newTab = true;
		toStr = definedExternalLink;
	} else toStr = "#";
	let content = children;
	if (text) content = typography ? require_components_typography_renderTypography.renderTypography(typography.type, {
		size: typography.size,
		color: typography.color,
		children: text,
		underline: typography.underline
	}) : text;
	return /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(react_router_dom.Link, {
		to: toStr,
		id,
		css,
		onClick,
		className,
		download: filename,
		style: { color: blue ? require_styles_colors.colors.blue43 : "inherit" },
		target: newTab ? "_blank" : void 0,
		rel: newTab ? "noopener noreferrer" : void 0,
		ref,
		children: content
	});
});
LinkBase.displayName = "LinkBase";
const Link = (0, _emotion_styled.default)(LinkBase)`
  ${({ disabled }) => disabled && `pointer-events: none;`}
`;
function Navigate({ to, params, hash, state, replace = false }) {
	to = replaceParams(to, params, hash);
	return /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(react_router_dom.Navigate, {
		to,
		state,
		replace
	});
}
function useNavigate() {
	const navigate = (0, react_router_dom.useNavigate)();
	return (0, react.useCallback)((to, params, options, hash) => {
		if (typeof to === "string") {
			to = replaceParams(to, params, hash);
			return navigate(to, options);
		}
		return navigate(to);
	}, [navigate]);
}
function useMatchRoutes(routes) {
	return matchRoutes(routes, (0, react_router_dom.useLocation)().pathname);
}
function matchRoutes(routes, locationPathname) {
	return routes.some((route) => (0, react_router_dom.matchPath)(route, locationPathname));
}
function useFindMatchingRoute(routes) {
	const location = (0, react_router_dom.useLocation)();
	return routes.find((route) => (0, react_router_dom.matchPath)(route, location.pathname));
}
function useMatchRoute(route) {
	return (0, react_router_dom.matchPath)(route, (0, react_router_dom.useLocation)().pathname);
}
function useCurrentRoute() {
	return (0, react_router_dom.useLocation)().pathname;
}
function getRouteName(path, routes) {
	for (const routeName of Object.keys(routes)) if ((0, react_router_dom.matchPath)(routes[routeName], path)) return routeName;
	return null;
}
//#endregion
exports.Link = Link;
exports.LinkBase = LinkBase;
exports.Navigate = Navigate;
exports.getRouteName = getRouteName;
exports.matchRoutes = matchRoutes;
exports.replaceParams = replaceParams;
exports.useCurrentRoute = useCurrentRoute;
exports.useFindMatchingRoute = useFindMatchingRoute;
exports.useMatchRoute = useMatchRoute;
exports.useMatchRoutes = useMatchRoutes;
exports.useNavigate = useNavigate;
