import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { memo, useState, Fragment, useRef, useEffect, useMemo } from 'react';
import classnames from 'classnames';
import { capitalize, isNotEmpty, isPresent, hyphenate, isNot } from '@bigbinary/neeto-cist';
import useLocalStorage from '@bigbinary/neeto-commons-frontend/react-utils/useLocalStorage';
import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
import Button from '@bigbinary/neetoui/Button';
import Typography from '@bigbinary/neetoui/Typography';
import { is, append, not, findLast } from 'ramda';
import { useTranslation } from 'react-i18next';
import { Link, useLocation, useHistory } from 'react-router-dom';
import { a as SPECIAL_APP_NAMES, D as DEFAULT_HOME_PATH, f as filterByPermissions, b as CheckPointNavLinks, P as PINNED_MORE_NAV_LINKS_KEY, _ as _Items, c as SELECTED_NAV_LINK_ROUTE_STORAGE_KEY, g as getSidebarStateLocalStorageKey, d as SIDEBAR_WIDTH_KEY, e as DEFAULT_SIDEBAR_WIDTH, S as SelectedLink, C as Chevron, h as enableDraggingStyles, i as disableDraggingStyles, j as getActiveConfigurePageLink, M as MIN_SIDEBAR_WIDTH, k as MAX_SIDEBAR_WIDTH } from './Chevron-Dtxc2piW.js';
import { globalProps as globalProps$1 } from '@bigbinary/neeto-commons-frontend/initializers';
import Neeto from '@bigbinary/neeto-icons/typeface-logos/Neeto';
import * as AppIcons from '@bigbinary/neeto-icons/typeface-logos';
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import Right from '@bigbinary/neeto-icons/Right';
import Plus from '@bigbinary/neeto-icons/Plus';
import Dropdown from '@bigbinary/neetoui/Dropdown';
import MenuHorizontal from '@bigbinary/neeto-icons/MenuHorizontal';
import { u as useKeyboardShortcutsPaneState } from './useKeyboardShortcutsPaneState-C_eLceJQ.js';
import '@bigbinary/neeto-commons-frontend/react-utils';
import '@bigbinary/neeto-commons-frontend/utils/general';
import '@bigbinary/neeto-icons/Home';
import '@bigbinary/neeto-filters-frontend/Segments';
import '@bigbinary/neeto-commons-frontend/react-utils/useRegisterNavigationCheckpoint';
import './inject-css-C2dztUxs.js';
import 'zustand/shallow';
import '@bigbinary/neeto-commons-frontend/react-utils/withImmutableActions';
import 'zustand';

var Header = function Header(_ref) {
  var _ProductTypefaceLogos;
  var customLogo = _ref.customLogo,
    clearSettingsNav = _ref.clearSettingsNav;
  var productName = globalProps$1.appName.substr(5);
  var normalizedName = (productName || "").trim().toLowerCase();
  var specialCase = SPECIAL_APP_NAMES[normalizedName];
  var logoName = specialCase ? "Neeto".concat(specialCase) : "Neeto".concat(capitalize(normalizedName));
  var ProductTypefaceLogo = (_ProductTypefaceLogos = AppIcons[logoName]) !== null && _ProductTypefaceLogos !== void 0 ? _ProductTypefaceLogos : Neeto;
  var LogoComponent = customLogo !== null && customLogo !== void 0 ? customLogo : ProductTypefaceLogo;
  var isOnboarded = globalProps$1.user.isOnboarded !== false;
  return /*#__PURE__*/jsx("div", {
    className: "neeto-molecules-sidebar__header neeto-molecules-sidebar__no-shrinkable",
    "data-cy": "sidebar-info",
    children: /*#__PURE__*/jsx(Link, {
      to: DEFAULT_HOME_PATH,
      className: classnames("neeto-molecules-sidebar__logo neeto-ui-w-full", {
        "cursor-pointer": isOnboarded
      }, {
        "pointer-events-none": !isOnboarded
      }),
      onClick: clearSettingsNav,
      children: /*#__PURE__*/jsx(LogoComponent, {
        className: classnames({
          "neeto-molecules-sidebar__logo": !customLogo
        })
      })
    })
  });
};
var Header$1 = /*#__PURE__*/memo(Header);

var AddDropdown = function AddDropdown(_ref) {
  var addActions = _ref.addActions;
  return /*#__PURE__*/jsx(Dropdown, {
    closeOnSelect: true,
    position: "bottom-end",
    customTarget: function customTarget() {
      return /*#__PURE__*/jsx("span", {
        className: "neeto-molecules-sidebar__link-icon neeto-molecules-sidebar__link-icon--caret",
        "data-testid": "add-dropdown-trigger",
        onClick: function onClick(e) {
          e.preventDefault();
          e.stopPropagation();
        },
        children: /*#__PURE__*/jsx(Plus, {
          size: 16
        })
      });
    },
    children: /*#__PURE__*/jsx(Dropdown.Menu, {
      children: addActions.map(function (action) {
        return /*#__PURE__*/jsx(Dropdown.MenuItem.Button, {
          onClick: function onClick(e) {
            var _action$onClick;
            e.preventDefault();
            (_action$onClick = action.onClick) === null || _action$onClick === void 0 || _action$onClick.call(action, e);
          },
          children: action.label
        }, action.key);
      })
    })
  });
};

function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var PinIcon = function PinIcon(_ref) {
  var size = _ref.size,
    otherProps = _ref.otherProps;
  return /*#__PURE__*/jsx("svg", _objectSpread$2(_objectSpread$2({
    fill: "currentColor",
    height: size,
    viewBox: "0 -960 960 960",
    width: size,
    xmlns: "http://www.w3.org/2000/svg"
  }, otherProps), {}, {
    children: /*#__PURE__*/jsx("path", {
      d: "m640-480 80 80v80H520v240l-40 40-40-40v-240H240v-80l80-80v-280h-40v-80h400v80h-40zm-286 80h252l-46-46v-314H400v314zm126 0"
    })
  }));
};

function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var UnpinIcon = function UnpinIcon(_ref) {
  var size = _ref.size,
    otherProps = _ref.otherProps;
  return /*#__PURE__*/jsx("svg", _objectSpread$1(_objectSpread$1({
    fill: "currentColor",
    height: size,
    viewBox: "0 -960 960 960",
    width: size,
    xmlns: "http://www.w3.org/2000/svg"
  }, otherProps), {}, {
    children: /*#__PURE__*/jsx("path", {
      d: "m640-480 80 80v80H520v240l-40 40-40-40v-240H240v-80l80-80v-280h-40v-80h400v80h-40z"
    })
  }));
};

var _excluded$1 = ["label", "icon", "key", "to", "onClick"];
var MoreDropdown = function MoreDropdown(_ref) {
  var moreNavLinks = _ref.moreNavLinks,
    isNavLinkPinned = _ref.isNavLinkPinned,
    handleTogglePin = _ref.handleTogglePin;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var location = useLocation();
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  return /*#__PURE__*/jsx(Dropdown, {
    isOpen: isOpen,
    closeOnSelect: true,
    appendTo: function appendTo() {
      return document.body;
    },
    position: "right",
    strategy: "fixed",
    zIndex: 99999,
    customTarget: function customTarget() {
      return /*#__PURE__*/jsxs("div", {
        "data-testid": "more-nav-links-dropdown-button",
        className: classnames("neeto-ui-flex neeto-ui-items-center neeto-ui-no-underline neeto-ui-select-none neeto-molecules-sidebar__link neeto-ui-w-full neeto-ui-cursor-pointer", {
          "neeto-molecules-sidebar__link--hover-active": isOpen
        }),
        onClick: function onClick() {
          return setIsOpen(!isOpen);
        },
        children: [/*#__PURE__*/jsx("span", {
          className: "neeto-molecules-sidebar__link-icon",
          children: /*#__PURE__*/jsx(MenuHorizontal, {})
        }), /*#__PURE__*/jsx(Typography, {
          className: "neeto-molecules-sidebar__link-label",
          component: "span",
          style: "body2",
          children: t("neetoMolecules.sidebar.more")
        })]
      });
    },
    onClickOutside: function onClickOutside() {
      return setIsOpen(false);
    },
    onClose: function onClose() {
      return setIsOpen(false);
    },
    children: /*#__PURE__*/jsx(Dropdown.Menu, {
      className: "p-0",
      "data-testid": "more-nav-links-dropdown-menu",
      position: "right",
      strategy: "fixed",
      children: moreNavLinks.filter(filterByPermissions).map(function (navLink, index) {
        var label = navLink.label,
          icon = navLink.icon,
          navLinkKey = navLink.key,
          to = navLink.to,
          onClick = navLink.onClick,
          otherProps = _objectWithoutProperties(navLink, _excluded$1);
        var IconSVG = icon;
        var isPinned = isNavLinkPinned(navLink);
        var url = new URL(to, window.location.href);
        var isActive = function isActive() {
          return is(Function, otherProps.isActive) ? otherProps.isActive() : location.pathname.startsWith(url.pathname);
        };
        return /*#__PURE__*/jsx(Dropdown.MenuItem, {
          "data-testid": label,
          children: /*#__PURE__*/jsxs(CheckPointNavLinks, {
            onClick: onClick,
            to: to,
            className: classnames("flex cursor-pointer items-center justify-between gap-2 px-2 py-1", {
              "neeto-ui-bg-accent-100 font-semibold": isActive()
            }),
            children: [/*#__PURE__*/jsxs("span", {
              className: "flex min-w-0 flex-grow items-center gap-2",
              children: [icon && /*#__PURE__*/jsx(IconSVG, {
                className: "flex-shrink-0",
                size: 20
              }), /*#__PURE__*/jsx(Typography, {
                className: "min-w-0 flex-grow",
                component: "span",
                style: "body2",
                children: label
              })]
            }), /*#__PURE__*/jsx(Button, {
              className: "flex-shrink-0",
              size: "small",
              style: "text",
              icon: isPinned ? function () {
                return /*#__PURE__*/jsx(UnpinIcon, {
                  otherProps: {},
                  size: 16
                });
              } : function () {
                return /*#__PURE__*/jsx(PinIcon, {
                  otherProps: {},
                  size: 16
                });
              },
              tooltipProps: {
                content: isPinned ? t("neetoMolecules.sidebar.unpin") : t("neetoMolecules.sidebar.pin"),
                position: "right"
              },
              onClick: function onClick(event) {
                return handleTogglePin(navLink, event);
              }
            })]
          })
        }, navLinkKey || index);
      })
    })
  });
};

var _excluded = ["label", "to", "icon", "items", "isConfigureNavLink", "isCountsLoading", "count", "component", "onClick", "addActions"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var renderCount = function renderCount(count) {
  return count > 999 ? "999+" : count;
};
var Links = function Links(_ref) {
  var navLinks = _ref.navLinks,
    moreNavLinks = _ref.moreNavLinks,
    isCountsLoadingDeprecated = _ref.isCountsLoading,
    setSelectedNavLinkRoute = _ref.setSelectedNavLinkRoute;
  var location = useLocation();
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    expandedNavLinkKeys = _useState2[0],
    setExpandedNavLinkKeys = _useState2[1];
  var _useLocalStorage = useLocalStorage(PINNED_MORE_NAV_LINKS_KEY, []),
    _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
    pinnedNavLinks = _useLocalStorage2[0],
    setPinnedNavLinks = _useLocalStorage2[1];
  var handleNavLinkClick = function handleNavLinkClick(_ref2) {
    var event = _ref2.event,
      isActive = _ref2.isActive,
      navLink = _ref2.navLink;
    var isExpandable = isPresent(navLink.items) || isPresent(navLink.component);
    if (!isExpandable) {
      setExpandedNavLinkKeys([]);
      return;
    }
    if (navLink.isConfigureNavLink && isNotEmpty(navLink.items)) {
      setSelectedNavLinkRoute(navLink.to);
    }
    var navLinkKey = navLink.key || navLink.to;
    if (isActive()) {
      var isExpanded = expandedNavLinkKeys.includes(navLinkKey);
      setExpandedNavLinkKeys(isExpanded ? [] : [navLinkKey]);
      navLink.resetPath !== true && event.preventDefault();
      return;
    }
    setExpandedNavLinkKeys([navLinkKey]);
  };
  var handleTogglePin = function handleTogglePin(navLink, event) {
    event.preventDefault();
    event.stopPropagation();
    var navLinkKey = navLink.key || navLink.to;
    var isPinned = pinnedNavLinks.includes(navLinkKey);
    if (isPinned) {
      setPinnedNavLinks(pinnedNavLinks.filter(isNot(navLinkKey)));
    } else {
      setPinnedNavLinks([].concat(_toConsumableArray(pinnedNavLinks), [navLinkKey]));
    }
  };
  var isNavLinkPinned = function isNavLinkPinned(navLink) {
    if (!navLink) return false;
    var navLinkKey = navLink.key || navLink.to;
    return pinnedNavLinks.includes(navLinkKey);
  };
  var pinnedItems = moreNavLinks ? moreNavLinks.filter(isNavLinkPinned) : [];
  var activeMoreNavLink = moreNavLinks ? moreNavLinks.find(function (navLink) {
    return navLink && (location.pathname + location.search).startsWith(navLink.to);
  }) : null;
  var additionalItems = _toConsumableArray(pinnedItems);
  if (activeMoreNavLink && !isNavLinkPinned(activeMoreNavLink)) {
    additionalItems.push(activeMoreNavLink);
  }
  var combinedNavLinks = [].concat(_toConsumableArray(navLinks), _toConsumableArray(additionalItems));
  return /*#__PURE__*/jsxs("div", {
    className: "neeto-molecules-sidebar__links neeto-molecules-sidebar__no-shrinkable",
    children: [combinedNavLinks.filter(filterByPermissions).map(function (navLink, index) {
      var label = navLink.label,
        to = navLink.to,
        icon = navLink.icon,
        items = navLink.items,
        isConfigureNavLink = navLink.isConfigureNavLink,
        _navLink$isCountsLoad = navLink.isCountsLoading,
        isCountsLoading = _navLink$isCountsLoad === void 0 ? false : _navLink$isCountsLoad,
        _navLink$count = navLink.count,
        count = _navLink$count === void 0 ? null : _navLink$count,
        Component = navLink.component,
        _onClick = navLink.onClick,
        _navLink$addActions = navLink.addActions,
        addActions = _navLink$addActions === void 0 ? [] : _navLink$addActions,
        otherProps = _objectWithoutProperties(navLink, _excluded);
      var IconSVG = icon;
      var url = new URL(to, window.location.href);
      var isActive = function isActive() {
        return is(Function, otherProps.isActive) ? otherProps.isActive() : location.pathname.startsWith(url.pathname);
      };
      var isExpandable = items || Component;
      var navLinkKey = navLink.key || navLink.to;
      var isMenuExpanded = expandedNavLinkKeys.includes(navLinkKey) && !isCountsLoadingDeprecated;
      var handleCaretClick = function handleCaretClick(event) {
        event.preventDefault();
        event.stopPropagation();
        setExpandedNavLinkKeys(function (keys) {
          return keys.includes(navLinkKey) ? keys.filter(isNot(navLinkKey)) : append(navLinkKey, keys);
        });
      };
      return /*#__PURE__*/jsxs(Fragment, {
        children: [/*#__PURE__*/jsxs(CheckPointNavLinks, _objectSpread(_objectSpread({
          activeClassName: "active",
          className: "neeto-ui-flex neeto-ui-items-center neeto-ui-no-underline neeto-ui-select-none neeto-molecules-sidebar__link",
          "data-testid": "navlink-".concat(hyphenate(label)),
          onClick: function onClick(event) {
            handleNavLinkClick({
              event: event,
              isActive: isActive,
              navLink: navLink
            });
            _onClick === null || _onClick === void 0 || _onClick(event);
          }
        }, _objectSpread({
          isActive: isActive,
          to: to
        }, otherProps)), {}, {
          children: [icon && /*#__PURE__*/jsxs("span", {
            className: "neeto-molecules-sidebar__link-icon",
            "data-testid": label,
            children: [/*#__PURE__*/jsx(IconSVG, {}), isPresent(count) && !isCountsLoading && /*#__PURE__*/jsx("span", {
              className: "neeto-molecules-sidebar__link-unread-count",
              children: renderCount(count)
            })]
          }), /*#__PURE__*/jsx(Typography, {
            className: "neeto-molecules-sidebar__link-label neeto-ui-flex-grow flex items-center gap-1",
            component: "span",
            style: "body2",
            children: label
          }), isNotEmpty(addActions) && /*#__PURE__*/jsx(AddDropdown, {
            addActions: addActions
          }), isExpandable && !isConfigureNavLink && /*#__PURE__*/jsx("span", {
            className: classnames("neeto-molecules-sidebar__link-icon neeto-molecules-sidebar__link-icon--caret", {
              "neeto-molecules-sidebar__link-icon--rotate": isMenuExpanded
            }),
            onClick: handleCaretClick,
            children: /*#__PURE__*/jsx(Right, {
              size: 16
            })
          })]
        })), isExpandable && !isConfigureNavLink && isMenuExpanded && /*#__PURE__*/jsxs(Fragment$1, {
          children: [items && /*#__PURE__*/jsx(_Items, _objectSpread({}, _objectSpread({
            isCountsLoading: isCountsLoading,
            items: items
          }, otherProps))), Component && /*#__PURE__*/jsx(Component, {
            navLink: navLink
          })]
        })]
      }, navLink.key || index);
    }), isNotEmpty(moreNavLinks) && /*#__PURE__*/jsx(MoreDropdown, {
      handleTogglePin: handleTogglePin,
      isNavLinkPinned: isNavLinkPinned,
      moreNavLinks: moreNavLinks
    })]
  });
};

var Sidebar = function Sidebar(_ref) {
  var navLinks = _ref.navLinks,
    _ref$moreNavLinks = _ref.moreNavLinks,
    moreNavLinks = _ref$moreNavLinks === void 0 ? [] : _ref$moreNavLinks,
    customLogo = _ref.customLogo,
    _ref$isCountsLoading = _ref.isCountsLoading,
    isCountsLoading = _ref$isCountsLoading === void 0 ? false : _ref$isCountsLoading,
    _ref$showWorkspaceNam = _ref.showWorkspaceName,
    showWorkspaceName = _ref$showWorkspaceNam === void 0 ? false : _ref$showWorkspaceNam,
    _ref$isExpandable = _ref.isExpandable,
    isExpandable = _ref$isExpandable === void 0 ? true : _ref$isExpandable;
  var _useKeyboardShortcuts = useKeyboardShortcutsPaneState(),
    _useKeyboardShortcuts2 = _slicedToArray(_useKeyboardShortcuts, 1),
    isKeyboardShortcutsPaneOpen = _useKeyboardShortcuts2[0];
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isSidebarPaneOpen = _useState2[0],
    setIsSidebarPaneOpen = _useState2[1];
  var _useLocalStorage = useLocalStorage(SELECTED_NAV_LINK_ROUTE_STORAGE_KEY, null),
    _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
    selectedNavLinkRoute = _useLocalStorage2[0],
    setSelectedNavLinkRoute = _useLocalStorage2[1];
  var _useLocalStorage3 = useLocalStorage(getSidebarStateLocalStorageKey(), false),
    _useLocalStorage4 = _slicedToArray(_useLocalStorage3, 2),
    isSidebarCollapsed = _useLocalStorage4[0],
    setIsSidebarCollapsed = _useLocalStorage4[1];
  var _useLocalStorage5 = useLocalStorage(SIDEBAR_WIDTH_KEY, "".concat(DEFAULT_SIDEBAR_WIDTH, "px")),
    _useLocalStorage6 = _slicedToArray(_useLocalStorage5, 2),
    sidebarWidth = _useLocalStorage6[0],
    setSidebarWidth = _useLocalStorage6[1];
  var sidebarRef = useRef(null);
  var isMouseDownRef = useRef(false);
  var startXRef = useRef(null);
  var startWidthRef = useRef(null);
  var location = useLocation();
  var history = useHistory();
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var isLargerScreen = function isLargerScreen() {
    return window.innerWidth > 768;
  };
  var isSidebarClosed = isLargerScreen() ? isSidebarCollapsed : not(isSidebarPaneOpen);
  useEffect(function () {
    if (isKeyboardShortcutsPaneOpen) {
      setIsSidebarPaneOpen(false);
      setIsSidebarCollapsed(true);
    } else if (!isKeyboardShortcutsPaneOpen && isLargerScreen()) {
      setIsSidebarPaneOpen(true);
      setIsSidebarCollapsed(false);
    }
  }, [isKeyboardShortcutsPaneOpen]);
  useEffect(function () {
    if (!isPresent(navLinks)) return;
    var currentLink = findLast(function (_ref2) {
      var to = _ref2.to,
        isActive = _ref2.isActive;
      var url = new URL(to, window.location.href);
      return is(Function, isActive) ? isActive() : location.pathname.includes(url.pathname);
    })(navLinks);
    if (isPresent(currentLink)) {
      setSelectedNavLinkRoute(currentLink.isConfigureNavLink ? currentLink.to : null);
    }
  }, []);
  useEffect(function () {
    var handleResize = function handleResize() {
      if (isLargerScreen()) return;
      setIsSidebarPaneOpen(false);
      setIsSidebarCollapsed(true);
    };
    window.addEventListener("resize", handleResize);
    return function () {
      return window.removeEventListener("resize", handleResize);
    };
  }, []);
  useEffect(function () {
    if (!isExpandable) return undefined;
    var handle = document.querySelector(".neeto-molecules-sidebar__resize-handle");
    if (!handle) return undefined;
    var onMouseDown = function onMouseDown(e) {
      var _sidebarRef$current;
      isMouseDownRef.current = true;
      startXRef.current = e.clientX;
      startWidthRef.current = ((_sidebarRef$current = sidebarRef.current) === null || _sidebarRef$current === void 0 ? void 0 : _sidebarRef$current.getBoundingClientRect().width) || DEFAULT_SIDEBAR_WIDTH;
      enableDraggingStyles();
    };
    var onMouseMove = function onMouseMove(e) {
      if (!isMouseDownRef.current) return;
      var dx = e.clientX - startXRef.current;
      var newWidth = startWidthRef.current + dx;
      newWidth = Math.max(MIN_SIDEBAR_WIDTH, Math.min(newWidth, MAX_SIDEBAR_WIDTH));
      setSidebarWidth("".concat(newWidth, "px"));
    };
    var onMouseUp = function onMouseUp() {
      if (!isMouseDownRef.current) return;
      isMouseDownRef.current = false;
      disableDraggingStyles();
    };
    handle.addEventListener("mousedown", onMouseDown);
    document.addEventListener("mousemove", onMouseMove);
    document.addEventListener("mouseup", onMouseUp);
    return function () {
      handle.removeEventListener("mousedown", onMouseDown);
      document.removeEventListener("mousemove", onMouseMove);
      document.removeEventListener("mouseup", onMouseUp);
    };
  }, [isExpandable]);
  useEffect(function () {
    document.documentElement.style.setProperty("--neeto-molecules-sidebar-width", "".concat(parseInt(sidebarWidth) / 16, "rem"));
  }, [sidebarWidth]);
  var handleGoBack = function handleGoBack(event) {
    event.preventDefault();
    setSelectedNavLinkRoute(null);
    var configureNavLink = getActiveConfigurePageLink({
      navLinks: navLinks,
      location: location
    });
    if (configureNavLink !== null && configureNavLink !== void 0 && configureNavLink.to) {
      history.push(buildUrl(configureNavLink.to));
    }
  };
  var activeLink = useMemo(function () {
    return navLinks.find(function (link) {
      if (is(Function, link.isActive)) return link.isActive();
      var url = new URL(link.to, window.location.href);
      return location.pathname.startsWith(url.pathname);
    });
  }, [location.pathname, navLinks]);
  var isSelectedNavLinkVisible = selectedNavLinkRoute && (activeLink === null || activeLink === void 0 ? void 0 : activeLink.to) === selectedNavLinkRoute && isNotEmpty(navLinks);
  return /*#__PURE__*/jsxs(Fragment$1, {
    children: [/*#__PURE__*/jsxs("div", {
      "data-testid": "sidebar-container",
      ref: sidebarRef,
      style: {
        width: isSidebarCollapsed ? "0" : sidebarWidth
      },
      className: classnames("neeto-molecules-sidebar__wrapper", {
        "neeto-molecules-sidebar__wrapper--collapsed": isLargerScreen() ? isSidebarCollapsed : not(isSidebarPaneOpen)
      }),
      children: [/*#__PURE__*/jsx("div", {
        className: "neeto-molecules-sidebar__backdrop",
        onClick: function onClick() {
          setIsSidebarPaneOpen(false);
          setSelectedNavLinkRoute(null);
        }
      }), /*#__PURE__*/jsxs("div", {
        "data-cy": "sidebar-wrapper",
        "data-testid": "sidebar",
        className: classnames("neeto-molecules-sidebar neeto-ui-flex neeto-ui-flex-col neeto-ui-flex-shrink-0 neeto-ui-overflow-y-auto neeto-ui-overflow-x-hidden", {
          "neeto-molecules-sidebar--focus-mode": isPresent(selectedNavLinkRoute)
        }),
        children: [/*#__PURE__*/jsx(Header$1, {
          customLogo: customLogo,
          clearSettingsNav: function clearSettingsNav() {
            return setSelectedNavLinkRoute(null);
          }
        }), showWorkspaceName && /*#__PURE__*/jsxs("div", {
          className: "neeto-ui-bg-gray-100 neeto-molecules-sidebar__workspace-info",
          children: [/*#__PURE__*/jsx(Typography, {
            className: "neeto-ui-mb-1",
            style: "h5",
            weight: "semibold",
            children: t("neetoMolecules.sidebar.myWorkspace")
          }), /*#__PURE__*/jsx(Typography, {
            className: "neeto-ui-truncate",
            style: "body2",
            children: globalProps.organization.name
          })]
        }), isSelectedNavLinkVisible ? /*#__PURE__*/jsx(SelectedLink, {
          handleGoBack: handleGoBack,
          navLink: activeLink
        }) : /*#__PURE__*/jsx(Links, {
          isCountsLoading: isCountsLoading,
          moreNavLinks: moreNavLinks,
          navLinks: navLinks,
          setSelectedNavLinkRoute: setSelectedNavLinkRoute
        })]
      }), /*#__PURE__*/jsx(Button, {
        className: "neeto-molecules-sidebar__toggler",
        "data-cy": "neeto-molecules-sidebar-toggler",
        "data-testid": "sidebar-toggleButton",
        icon: function icon() {
          return /*#__PURE__*/jsx(Chevron, {});
        },
        style: isLargerScreen() ? "text" : "secondary",
        tooltipProps: {
          content: isSidebarClosed ? t("neetoMolecules.sidebar.showMenu") : t("neetoMolecules.sidebar.hideMenu"),
          position: "bottom",
          touch: ["hold", 500]
        },
        onClick: function onClick() {
          setIsSidebarCollapsed(!isSidebarCollapsed);
          setIsSidebarPaneOpen(not);
        }
      })]
    }), isExpandable && /*#__PURE__*/jsx("div", {
      className: "neeto-molecules-sidebar__resize-handle"
    })]
  });
};

export { Sidebar as default };
//# sourceMappingURL=Sidebar.js.map
