"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkCDFVRIETcjs = require('./chunk-CDFVRIET.cjs');


var _chunkJA7KZV3Qcjs = require('./chunk-JA7KZV3Q.cjs');


var _chunkQQDRBCBYcjs = require('./chunk-QQDRBCBY.cjs');

// src/router.tsx
var _styled = require('@emotion/styled'); var _styled2 = _interopRequireDefault(_styled);
var _lodashes = require('lodash-es');
var _react = require('react');






var _reactrouterdom = require('react-router-dom');
var _jsxruntime = require('@emotion/react/jsx-runtime');
function replaceParams(to, params, hash) {
  if (params) {
    let toWithParams = to;
    Object.entries(_lodashes.omit.call(void 0, 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;
}
var LinkBase = _react.forwardRef.call(void 0, 
  ({
    to,
    id,
    externalLink,
    filename,
    params,
    children,
    text,
    css,
    onClick,
    className,
    hash = null,
    blue = false,
    newTab: newTabProp,
    typography
  }, ref) => {
    if (!_chunkJA7KZV3Qcjs.isString.call(void 0, to) && !externalLink && !onClick) {
      throw new Error(
        "Link must have either `to` or `externalLink` or `onClick` defined"
      );
    }
    let toStr;
    let newTab = Boolean(newTabProp);
    if (_chunkJA7KZV3Qcjs.isString.call(void 0, 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 ? _chunkCDFVRIETcjs.renderTypography.call(void 0, typography.type, {
        size: typography.size,
        color: typography.color,
        children: text,
        underline: typography.underline
      }) : text;
    }
    return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      _reactrouterdom.Link,
      {
        to: toStr,
        id,
        css,
        onClick,
        className,
        download: filename,
        style: { color: blue ? _chunkQQDRBCBYcjs.colors.blue43 : "inherit" },
        target: newTab ? "_blank" : void 0,
        rel: newTab ? "noopener noreferrer" : void 0,
        ref,
        children: content
      }
    );
  }
);
LinkBase.displayName = "LinkBase";
var Link = _styled2.default.call(void 0, LinkBase)`
  ${({ disabled }) => disabled && `pointer-events: none;`}
`;
function Navigate({
  to,
  params,
  hash,
  state,
  replace = false
}) {
  to = replaceParams(to, params, hash);
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactrouterdom.Navigate, { to, state, replace });
}
function useNavigate() {
  const navigate = _reactrouterdom.useNavigate.call(void 0, );
  return _react.useCallback.call(void 0, 
    (to, params, options, hash) => {
      if (typeof to === "string") {
        to = replaceParams(to, params, hash);
        return navigate(to, options);
      }
      return navigate(to);
    },
    [navigate]
  );
}
function useMatchRoutes(routes) {
  const location = _reactrouterdom.useLocation.call(void 0, );
  const doesMatch = matchRoutes(routes, location.pathname);
  return doesMatch;
}
function matchRoutes(routes, locationPathname) {
  return routes.some((route) => _reactrouterdom.matchPath.call(void 0, route, locationPathname));
}
function useFindMatchingRoute(routes) {
  const location = _reactrouterdom.useLocation.call(void 0, );
  const matchingRoute = routes.find(
    (route) => _reactrouterdom.matchPath.call(void 0, route, location.pathname)
  );
  return matchingRoute;
}
function useMatchRoute(route) {
  const location = _reactrouterdom.useLocation.call(void 0, );
  return _reactrouterdom.matchPath.call(void 0, route, location.pathname);
}
function useCurrentRoute() {
  const location = _reactrouterdom.useLocation.call(void 0, );
  return location.pathname;
}
function getRouteName(path, routes) {
  for (const routeName of Object.keys(routes)) {
    if (_reactrouterdom.matchPath.call(void 0, routes[routeName], path)) {
      return routeName;
    }
  }
  return null;
}













exports.replaceParams = replaceParams; exports.LinkBase = LinkBase; exports.Link = Link; exports.Navigate = Navigate; exports.useNavigate = useNavigate; exports.useMatchRoutes = useMatchRoutes; exports.matchRoutes = matchRoutes; exports.useFindMatchingRoute = useFindMatchingRoute; exports.useMatchRoute = useMatchRoute; exports.useCurrentRoute = useCurrentRoute; exports.getRouteName = getRouteName;
