'use strict';

var jsxRuntime = require('react/jsx-runtime');
var react = require('@chakra-ui/react');
var reactRouterDom = require('react-router-dom');
var statusHelper = require('./statusHelper.cjs');

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const getIsDisabled = (isDisabledProp, status) => status === "error" || isDisabledProp;
function NavLink(props) {
  const {
    title,
    to,
    icon,
    onClick,
    isPrevious = false,
    isIconOnly = false,
    isCollapsed = false,
    isExternal = false,
    isDisabled = false,
    disabledText,
    status = "success"
  } = props;
  const skeletonItem = /* @__PURE__ */ jsxRuntime.jsx(react.Grid, { alignContent: "center", height: "40px", padding: "0.75rem", opacity: "0.5", children: /* @__PURE__ */ jsxRuntime.jsx(react.Skeleton, { height: "27px" }) });
  const renderItem = /* @__PURE__ */ jsxRuntime.jsxs(react.Flex, { alignItems: "center", children: [
    !!icon && /* @__PURE__ */ jsxRuntime.jsx(react.Icon, { "data-testid": `nav-link-icon-${title}`, as: icon, w: "1.2rem", h: "1.2rem", mr: 3 }),
    !isCollapsed && !isIconOnly ? /* @__PURE__ */ jsxRuntime.jsx(react.chakra.span, { "data-testid": `nav-link-${title}`, children: title }) : /* @__PURE__ */ jsxRuntime.jsx(react.chakra.span, { userSelect: "none", children: "\xA0" })
  ] });
  const activeLink = isExternal ? /* @__PURE__ */ jsxRuntime.jsx(react.Link, { href: to, variant: "nav", isExternal: true, onClick, "data-testid": `nav-link`, children: renderItem }) : /* @__PURE__ */ jsxRuntime.jsx(react.Link, { as: reactRouterDom.NavLink, to, variant: "nav", onClick, children: renderItem });
  const disabledLink = /* @__PURE__ */ jsxRuntime.jsx(react.Tooltip, { label: disabledText, placement: "right", hasArrow: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Link, __spreadProps(__spreadValues({ variant: "nav-disabled" }, statusHelper.statusToProps(status)), { children: renderItem })) });
  const previousLink = /* @__PURE__ */ jsxRuntime.jsx(react.Tooltip, { label: "Go back", placement: "right", hasArrow: true, children: /* @__PURE__ */ jsxRuntime.jsx(
    react.Link,
    __spreadProps(__spreadValues({
      variant: "nav-previous",
      "data-testid": "nav-link-previous"
    }, statusHelper.statusToProps(status)), {
      as: reactRouterDom.NavLink,
      to,
      onClick,
      children: renderItem
    })
  ) });
  if (status === "loading") {
    return skeletonItem;
  }
  if (isPrevious) {
    return previousLink;
  }
  if (getIsDisabled(isDisabled, status)) {
    return disabledLink;
  }
  if (isCollapsed) {
    return /* @__PURE__ */ jsxRuntime.jsx(react.Tooltip, { label: title, placement: "right", hasArrow: true, children: activeLink });
  }
  return activeLink;
}

module.exports = NavLink;
//# sourceMappingURL=NavLink.cjs.map
