'use strict';

var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var React = require('react');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var v2_Breadcrumbs = require('./Breadcrumbs.js');
var v2_HelpPopover = require('./HelpPopover.js');
var v2_MoreDropdown = require('./MoreDropdown.js');
var v2_Search = require('./Search.js');
var jsxRuntime = require('react/jsx-runtime');
require('@bigbinary/neeto-commons-frontend/react-utils');
require('@bigbinary/neeto-commons-frontend/utils/general');
require('react-router-dom');
require('../circle-question-mark-kxBMPyWQ.js');
require('../createLucideIcon-DBDhE7kE.js');
require('ramda');
require('react-i18next');
require('../ellipsis-BcfLTtl5.js');
require('@babel/runtime/helpers/slicedToArray');
require('@bigbinary/neeto-commons-frontend/react-utils/useFuncDebounce');
require('@bigbinary/neeto-commons-frontend/react-utils/useQueryParams');
require('@bigbinary/neeto-commons-frontend/react-utils/useUpdateEffect');
require('@bigbinary/neeto-commons-frontend/utils');
require('../search-BBuFYdmG.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 ? neetoCist.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 = React.useRef(null);
  React.useLayoutEffect(function () {
    var updateHeaderHeight = function updateHeaderHeight() {
      if (!headerRef.current) return;
      var height = headerRef.current.offsetHeight;
      document.body.style.setProperty("--neeto-molecules-effective-header-height", "".concat(height, "px"));
    };
    updateHeaderHeight();
    window.addEventListener("resize", updateHeaderHeight);
    return function () {
      window.removeEventListener("resize", updateHeaderHeight);
      document.body.style.removeProperty("--neeto-molecules-effective-header-height");
    };
  }, []);
  var isNano = size === SIZES.nano;
  var hasBreadcrumbs = neetoCist.isNotEmpty(breadcrumbs);
  var TitleTag = isNano ? "h3" : "h1";
  return /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx("div", {
      className: "flex flex-row flex-wrap items-start justify-start",
      children: /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "flex flex-wrap",
        children: [hasBreadcrumbs && /*#__PURE__*/jsxRuntime.jsx(v2_Breadcrumbs, {
          breadcrumbs: breadcrumbs
        }), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx(neetoAtoms.Typography, {
            asChild: true,
            variant: isNano ? "h3" : "h1",
            weight: "semibold",
            children: /*#__PURE__*/jsxRuntime.jsxs(TitleTag, {
              "data-testid": "main-header",
              children: [title, neetoCist.isPresent(titleHelpPopoverProps) && /*#__PURE__*/jsxRuntime.jsx(v2_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__*/jsxRuntime.jsx("span", {
                  className: "ms-2 inline-flex align-middle",
                  children: /*#__PURE__*/jsxRuntime.jsx(v2_MoreDropdown, _objectSpread({
                    dropdownButtonProps: _objectSpread({
                      size: DROPDOWN_BUTTON_SIZES[size]
                    }, dropdownButtonProps)
                  }, dropdownProps))
                });
              })]
            })
          })
        })]
      })
    }), /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: classnames("flex items-center gap-3 empty:hidden", "flex-wrap justify-start md:flex-nowrap md:justify-end"),
      children: [searchProps && /*#__PURE__*/jsxRuntime.jsx(v2_Search, _objectSpread({
        enableUrlSync: true,
        className: classnames("min-w-[12.6rem] grow-0", searchProps.className)
      }, searchProps)), actionBlock && /*#__PURE__*/jsxRuntime.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
      })]
    })]
  });
};

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