import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { useRef, useLayoutEffect } from 'react';
import { Typography } from '@bigbinary/neeto-atoms';
import classnames from 'classnames';
import { isNotEmpty, isPresent, noop } from '@bigbinary/neeto-cist';
import Breadcrumbs from './Breadcrumbs.js';
import HelpPopover from './HelpPopover.js';
import MoreDropdown from './MoreDropdown.js';
import Search from './Search.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@bigbinary/neeto-atoms/primitives';
import '@bigbinary/neeto-commons-frontend/react-utils';
import '@bigbinary/neeto-commons-frontend/utils/general';
import 'react-router-dom';
import 'react-i18next';
import '../circle-question-mark-Dib48f5Z.js';
import '../createLucideIcon-mNMhCCpf.js';
import 'ramda';
import '../ellipsis-DpI9xqUK.js';
import '@babel/runtime/helpers/slicedToArray';
import '@bigbinary/neeto-commons-frontend/react-utils/useFuncDebounce';
import '@bigbinary/neeto-commons-frontend/react-utils/useQueryParams';
import '@bigbinary/neeto-commons-frontend/react-utils/useUpdateEffect';
import '@bigbinary/neeto-commons-frontend/utils';
import '../search-DCgpNjip.js';

var SIZES = {
  nano: "nano",
  small: "small"
};
var DROPDOWN_BUTTON_SIZES = {
  nano: "small",
  small: "medium"
};

var _excluded = ["dropdownButtonProps"];
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 Header = function Header(_ref) {
  var title = _ref.title,
    _ref$titleHelpPopover = _ref.titleHelpPopoverProps,
    titleHelpPopoverProps = _ref$titleHelpPopover === void 0 ? {} : _ref$titleHelpPopover,
    searchProps = _ref.searchProps,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    actionBlock = _ref.actionBlock,
    _ref$breadcrumbs = _ref.breadcrumbs,
    breadcrumbs = _ref$breadcrumbs === void 0 ? [] : _ref$breadcrumbs,
    _ref$renderDropdown = _ref.renderDropdown,
    renderDropdown = _ref$renderDropdown === void 0 ? noop : _ref$renderDropdown,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? "small" : _ref$size,
    _ref$dataTestid = _ref["data-testid"],
    dataTestId = _ref$dataTestid === void 0 ? "neeto-molecules-header" : _ref$dataTestid;
  var headerRef = useRef(null);
  useLayoutEffect(function () {
    var updateHeaderHeight = function updateHeaderHeight() {
      if (!headerRef.current) return;
      var height = headerRef.current.offsetHeight;
      document.body.style.setProperty("--nv-header-height", "".concat(height, "px"));
    };
    updateHeaderHeight();
    window.addEventListener("resize", updateHeaderHeight);
    return function () {
      window.removeEventListener("resize", updateHeaderHeight);
      document.body.style.removeProperty("--nv-header-height");
    };
  }, []);
  var isNano = size === SIZES.nano;
  var hasBreadcrumbs = isNotEmpty(breadcrumbs);
  var TitleTag = isNano ? "h3" : "h1";
  return /*#__PURE__*/jsxs("div", {
    "data-testid": dataTestId,
    ref: headerRef,
    className: classnames("flex w-full shrink-0 flex-row items-start justify-between gap-4 pt-10 pb-6", "flex-wrap lg:flex-nowrap", {
      "min-h-0": isNano || size === SIZES.small
    }, className),
    children: [/*#__PURE__*/jsx("div", {
      className: "flex flex-row flex-wrap items-start justify-start",
      children: /*#__PURE__*/jsxs("div", {
        className: "flex flex-wrap",
        children: [hasBreadcrumbs && /*#__PURE__*/jsx(Breadcrumbs, {
          breadcrumbs: breadcrumbs
        }), /*#__PURE__*/jsx("div", {
          className: classnames("flex w-full flex-row items-center gap-3", hasBreadcrumbs ? "mt-0" : "-mt-1 max-lg:-mt-2.5 max-md:-mt-2 max-sm:-mt-1"),
          children: /*#__PURE__*/jsx(Typography, {
            asChild: true,
            variant: isNano ? "h4" : "h2",
            weight: "semibold",
            children: /*#__PURE__*/jsxs(TitleTag, {
              "data-testid": "main-header",
              children: [title, isPresent(titleHelpPopoverProps) && /*#__PURE__*/jsx(HelpPopover, _objectSpread({
                className: "ms-2 inline-flex align-middle",
                side: "right"
              }, titleHelpPopoverProps)), renderDropdown(function (_ref2) {
                var _ref2$dropdownButtonP = _ref2.dropdownButtonProps,
                  dropdownButtonProps = _ref2$dropdownButtonP === void 0 ? {} : _ref2$dropdownButtonP,
                  dropdownProps = _objectWithoutProperties(_ref2, _excluded);
                return /*#__PURE__*/jsx("span", {
                  className: "ms-2 inline-flex align-middle",
                  children: /*#__PURE__*/jsx(MoreDropdown, _objectSpread({
                    dropdownButtonProps: _objectSpread({
                      size: DROPDOWN_BUTTON_SIZES[size]
                    }, dropdownButtonProps)
                  }, dropdownProps))
                });
              })]
            })
          })
        })]
      })
    }), /*#__PURE__*/jsxs("div", {
      className: classnames("flex items-center gap-3 empty:hidden", "flex-wrap justify-start md:flex-nowrap md:justify-end"),
      children: [searchProps && /*#__PURE__*/jsx(Search, _objectSpread({
        enableUrlSync: true,
        className: classnames("min-w-[12.6rem] grow-0", searchProps.className)
      }, searchProps)), actionBlock && /*#__PURE__*/jsx("div", {
        className: "flex shrink-0 items-center justify-end gap-3 max-[360px]:shrink max-[360px]:flex-wrap max-[360px]:justify-start",
        children: actionBlock
      })]
    })]
  });
};

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