'use strict';

var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var jsxRuntime = require('react/jsx-runtime');
var plus = require('../plus-MoDFAiKt.js');
var neetoCist = require('@bigbinary/neeto-cist');
var general = require('@bigbinary/neeto-commons-frontend/utils/general');
var reactRouterDom = require('react-router-dom');
var reactI18next = require('react-i18next');
var search = require('../search-BBuFYdmG.js');
var x = require('../x-B38UX0_0.js');
var CSSTransition = require('../CSSTransition-D_jVZ_GR.js');
require('../createLucideIcon-DBDhE7kE.js');
require('@babel/runtime/helpers/esm/extends');
require('@babel/runtime/helpers/esm/objectWithoutPropertiesLoose');
require('@babel/runtime/helpers/esm/inheritsLoose');
require('../index-JY2zVpnv.js');
require('../_commonjsHelpers-BJu3ubxk.js');
require('react-dom');

var _excluded$5 = ["label", "onClick"];
function ownKeys$4(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$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var AddNew = function AddNew(_ref) {
  var _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    onClick = _ref.onClick,
    otherProps = _objectWithoutProperties(_ref, _excluded$5);
  return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread$4(_objectSpread$4({
    className: "mb-2 px-2 py-1.5"
  }, otherProps), {}, {
    children: /*#__PURE__*/jsxRuntime.jsxs(neetoAtoms.Button, {
      onClick: onClick,
      className: "gap-1 text-sm",
      size: "sm",
      variant: "link",
      children: [/*#__PURE__*/jsxRuntime.jsx(plus.Plus, {
        size: 16
      }), label]
    })
  }));
};

var _excluded$4 = ["url", "icon", "label", "count", "active", "onEdit", "onClick", "className"];
function ownKeys$3(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$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Block = function Block(_ref) {
  var url = _ref.url,
    icon = _ref.icon,
    label = _ref.label,
    count = _ref.count,
    _ref$active = _ref.active,
    active = _ref$active === void 0 ? false : _ref$active,
    onEdit = _ref.onEdit,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? neetoCist.noop : _ref$onClick,
    className = _ref.className,
    otherProps = _objectWithoutProperties(_ref, _excluded$4);
  var handleEdit = function handleEdit(e) {
    if (!onEdit) return;
    e.stopPropagation();
    onEdit();
  };
  var Parent = url ? reactRouterDom.Link : function (props) {
    return /*#__PURE__*/jsxRuntime.jsx("button", _objectSpread$3({
      type: "button"
    }, props));
  };
  return /*#__PURE__*/jsxRuntime.jsxs(Parent, _objectSpread$3(_objectSpread$3({
    "data-testid": otherProps["data-testid"] || "menubar-block",
    to: url,
    className: classnames("hover:bg-accent focus:bg-accent active:bg-accent relative mb-2 flex w-full cursor-pointer items-center justify-between rounded-md border border-transparent px-2 py-1.5 text-start transition-all hover:no-underline focus:outline-none motion-reduce:transition-none", _defineProperty({
      "bg-primary/10 border-primary/10 after:bg-primary hover:bg-primary/10 focus:bg-primary/10 active:bg-primary/10 after:absolute after:inset-y-0 after:start-[-1px] after:w-[3px] after:rounded-s-md": active
    }, className, className))
  }, _objectSpread$3({
    onClick: onClick
  }, otherProps)), {}, {
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "flex items-center",
      "data-testid": general.joinHyphenCase("menubar-block-label", label),
      children: [icon && /*#__PURE__*/jsxRuntime.jsx("i", {
        className: "me-1 flex items-center",
        children: icon
      }), /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "text-sm font-medium",
        title: label,
        children: label
      })]
    }), Number.isInteger(count) && /*#__PURE__*/jsxRuntime.jsx("div", {
      onClick: handleEdit,
      children: /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "text-sm font-medium",
        children: count
      })
    })]
  }));
};

var _excluded$3 = ["label", "description", "active", "className"];
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 Item = function Item(_ref) {
  var _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    _ref$description = _ref.description,
    description = _ref$description === void 0 ? "" : _ref$description,
    _ref$active = _ref.active,
    active = _ref$active === void 0 ? false : _ref$active,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    otherProps = _objectWithoutProperties(_ref, _excluded$3);
  return /*#__PURE__*/jsxRuntime.jsxs("button", _objectSpread$2(_objectSpread$2({
    type: "button",
    className: classnames("hover:bg-accent focus:bg-accent active:bg-accent mb-2 w-full cursor-pointer rounded-md border border-transparent p-3 text-start transition-all focus:outline-none motion-reduce:transition-none max-lg:p-2.5 max-md:p-2", _defineProperty({
      "border-border bg-background text-foreground hover:bg-background focus:bg-background active:bg-background shadow-sm": active
    }, className, className))
  }, otherProps), {}, {
    children: [/*#__PURE__*/jsxRuntime.jsx("h5", {
      className: "text-sm font-semibold",
      children: label
    }), /*#__PURE__*/jsxRuntime.jsx("p", {
      className: "text-muted-foreground text-xs",
      children: description
    })]
  }));
};

var _excluded$2 = ["isCollapsed", "onCollapse"];
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 Search = function Search(_ref) {
  var _ref$isCollapsed = _ref.isCollapsed,
    isCollapsed = _ref$isCollapsed === void 0 ? true : _ref$isCollapsed,
    onCollapse = _ref.onCollapse,
    props = _objectWithoutProperties(_ref, _excluded$2);
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  if (isCollapsed) return null;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "mb-5 flex items-center gap-1",
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "relative flex-grow",
      children: [/*#__PURE__*/jsxRuntime.jsx(search.Search, {
        className: "text-muted-foreground absolute start-3 top-1/2 size-4 -translate-y-1/2"
      }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Input, _objectSpread$1({
        className: "ps-9",
        placeholder: t("neetoMolecules.common.actions.search"),
        type: "search"
      }, props))]
    }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
      "data-testid": "menubar-search-close-icon",
      size: "icon-sm",
      variant: "ghost",
      onClick: onCollapse,
      children: /*#__PURE__*/jsxRuntime.jsx(x.X, {
        size: 16
      })
    })]
  });
};

var _excluded$1 = ["children", "iconProps"],
  _excluded2 = ["icon", "onClick"];
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 SubTitle = function SubTitle(_ref) {
  var children = _ref.children,
    iconProps = _ref.iconProps,
    otherProps = _objectWithoutProperties(_ref, _excluded$1);
  return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
    className: "my-5 flex items-center justify-between",
    "data-testid": otherProps["data-testid"] || "menubar-subtitle-heading"
  }, otherProps), {}, {
    children: [children, /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "flex items-center gap-1",
      children: iconProps === null || iconProps === void 0 ? void 0 : iconProps.map(function (_ref2, index) {
        var Icon = _ref2.icon,
          onClick = _ref2.onClick,
          rest = _objectWithoutProperties(_ref2, _excluded2);
        return /*#__PURE__*/React.createElement(neetoAtoms.Button, _objectSpread({
          onClick: onClick,
          key: index,
          size: "icon-sm",
          variant: "ghost"
        }, rest), Icon && /*#__PURE__*/jsxRuntime.jsx(Icon, {
          size: 16
        }));
      })
    })]
  }));
};

var _excluded = ["title", "children", "showMenu", "className"];
var MenuBar = function MenuBar(_ref) {
  var _ref$title = _ref.title,
    title = _ref$title === void 0 ? "" : _ref$title,
    children = _ref.children,
    _ref$showMenu = _ref.showMenu,
    showMenu = _ref$showMenu === void 0 ? false : _ref$showMenu,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  var prefersReducedMotion = reactUtils.usePrefersReducedMotion();
  var nodeRef = React.useRef(null);
  return /*#__PURE__*/jsxRuntime.jsx(CSSTransition.CSSTransition, {
    nodeRef: nodeRef,
    unmountOnExit: true,
    "in": showMenu,
    timeout: prefersReducedMotion ? 0 : 300,
    onEnter: function onEnter() {
      if (nodeRef.current) nodeRef.current.style.width = "0";
    },
    onEntered: function onEntered() {
      if (nodeRef.current) nodeRef.current.style.width = "";
    },
    onEntering: function onEntering() {
      if (nodeRef.current) nodeRef.current.style.width = "20.25rem";
    },
    onExit: function onExit() {
      if (nodeRef.current) nodeRef.current.style.width = "20.25rem";
    },
    onExiting: function onExiting() {
      if (nodeRef.current) nodeRef.current.style.width = "0";
    },
    children: /*#__PURE__*/jsxRuntime.jsx("div", {
      ref: nodeRef,
      className: classnames("border-border bg-background shrink-0 overflow-hidden border-e transition-all duration-300 motion-reduce:transition-none", className),
      children: /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "h-dvh w-[20.25rem] overflow-y-auto p-8 max-lg:w-[17.5rem] max-lg:px-6 max-lg:pt-10 max-lg:pb-6 max-md:w-60 max-md:px-5 max-md:pt-10 max-md:pb-6",
        "data-testid": "menubar-container",
        children: [title && /*#__PURE__*/jsxRuntime.jsx("h2", {
          className: "mb-4 text-xl leading-tight font-semibold",
          "data-testid": otherProps["data-testid"] || "menubar-heading",
          children: title
        }), children]
      })
    })
  });
};
MenuBar.Block = Block;
MenuBar.Item = Item;
MenuBar.SubTitle = SubTitle;
MenuBar.Search = Search;
MenuBar.AddNew = AddNew;

module.exports = MenuBar;
//# sourceMappingURL=MenuBar.js.map
