import { isPresent, existsBy, isNotEmpty } from '@bigbinary/neeto-cist';
import useBreakpoints from '@bigbinary/neeto-commons-frontend/react-utils/useBreakpoints';
import { mergeDeepRight, length, filter } from 'ramda';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Tooltip from '@bigbinary/neetoui/Tooltip';
import { Link, useLocation, NavLink } from 'react-router-dom';
import Rename from './Rename.js';
import { t } from 'i18next';
import Home from '@bigbinary/neeto-icons/Home';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import classnames from 'classnames';
import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils/general';
import Typography from '@bigbinary/neetoui/Typography';
import MoreDropdown from './MoreDropdown.js';
import Dropdown from '@bigbinary/neetoui/Dropdown';
import { useTranslation } from 'react-i18next';
import { createElement } from 'react';
import PublishBlock from './PublishBlock.js';
import { n } from './inject-css-C2dztUxs.js';
import '@babel/runtime/helpers/slicedToArray';
import '@bigbinary/neeto-commons-frontend/react-utils/useOnClickOutside';
import '@bigbinary/neeto-commons-frontend/react-utils/useStateWithDependency';
import './Breadcrumbs.js';
import '@bigbinary/neeto-hotkeys';
import '@bigbinary/neeto-icons/Check';
import '@bigbinary/neeto-icons/Close';
import '@bigbinary/neetoui/Button';
import '@bigbinary/neetoui/Input';
import '@babel/runtime/helpers/toConsumableArray';
import '@bigbinary/neeto-commons-frontend/react-utils';
import '@bigbinary/neeto-icons/MenuHorizontal';
import '@bigbinary/neeto-icons/MenuVertical';
import '@bigbinary/neeto-commons-frontend/react-utils/withT';
import '@bigbinary/neeto-commons-frontend/utils';
import '@bigbinary/neeto-icons/ExternalLink';
import '@bigbinary/neeto-icons/Delete';
import '@bigbinary/neeto-icons/Clock';
import '@bigbinary/neetoui/Alert';
import '@bigbinary/neetoui/Pane';
import '@bigbinary/neeto-team-members-frontend/Profile';
import '@bigbinary/neetoui/DatePicker';
import '@bigbinary/neeto-commons-frontend/initializers';

var DEFAULT_HOME_BUTTON_PROPS = {
  tooltip: {
    content: t("neetoMolecules.navigationHeader.home"),
    position: "bottom"
  },
  homeUrl: "/",
  icon: /*#__PURE__*/jsx(Home, {})
};

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 LeftBlock = function LeftBlock(_ref) {
  var customHomeButtonProps = _ref.homeButtonProps,
    homeUrl = _ref.homeUrl,
    renameProps = _ref.renameProps,
    children = _ref.children;
  var homeButtonProps = mergeDeepRight(DEFAULT_HOME_BUTTON_PROPS, customHomeButtonProps);
  return /*#__PURE__*/jsxs("div", {
    className: "flex items-center gap-1 md:gap-2",
    "data-cy": "navigation-header-left-block",
    "data-testid": "navigation-header-left-block",
    children: [/*#__PURE__*/jsx(Tooltip, {
      content: homeButtonProps.tooltip.content,
      position: homeButtonProps.tooltip.position,
      touch: ["hold", 500],
      children: /*#__PURE__*/jsx(Link, {
        "data-cy": "home-button",
        "data-testid": "home-button",
        to: homeUrl,
        children: /*#__PURE__*/jsx("div", {
          className: "neeto-ui-rounded hover:neeto-ui-bg-gray-200 p-1",
          children: homeButtonProps.icon
        })
      })
    }), isPresent(renameProps) && /*#__PURE__*/jsx(Rename, _objectSpread$3({
      dropdownItems: renameProps.dropdownItems,
      value: renameProps.value
    }, renameProps)), children]
  });
};

var _excluded$1 = ["key", "to", "label", "disabled"],
  _excluded2 = ["key", "label"];
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 Menu = Dropdown.Menu,
  MenuItem = Dropdown.MenuItem;
var OverflowLinks = function OverflowLinks(_ref) {
  var overflowLinks = _ref.overflowLinks;
  var _useLocation = useLocation(),
    pathname = _useLocation.pathname;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var isMoreButtonActive = existsBy({
    to: pathname
  }, overflowLinks);
  if (!isNotEmpty(overflowLinks)) {
    return null;
  }
  return /*#__PURE__*/jsx(Dropdown, {
    buttonStyle: "text",
    label: t("neetoMolecules.navigationHeader.more"),
    position: "bottom-end",
    buttonProps: {
      className: classnames("neeto-molecules-navigation-header__link neeto-molecules-navigation-header__link--more neeto-ui-typography neeto-ui-text-h4 neeto-ui-font-semibold neeto-ui-leading-normal px-2 capitalize no-underline md:px-0", {
        active: isMoreButtonActive
      })
    },
    children: /*#__PURE__*/jsx(Menu, {
      children: overflowLinks.map(function (_ref2) {
        var key = _ref2.key,
          to = _ref2.to,
          label = _ref2.label,
          disabled = _ref2.disabled,
          rest = _objectWithoutProperties(_ref2, _excluded$1);
        var isActive = to === pathname;
        var menuButton = /*#__PURE__*/createElement(MenuItem.Button, _objectSpread$2({
          isActive: isActive,
          to: to,
          "data-cy": "".concat(joinHyphenCase(key), "-more-tab"),
          isDisabled: disabled,
          key: key,
          onClick: function onClick(e) {
            return disabled && e.preventDefault();
          }
        }, rest), label);
        if (isActive && rest.moreOptions && isNotEmpty(rest.moreOptions.menuItems)) {
          return /*#__PURE__*/jsx(Dropdown, {
            customTarget: menuButton,
            position: "right-start",
            trigger: "hover",
            children: /*#__PURE__*/jsx(Menu, {
              children: rest.moreOptions.menuItems.map(function (_ref3) {
                var key = _ref3.key,
                  label = _ref3.label,
                  itemProps = _objectWithoutProperties(_ref3, _excluded2);
                return /*#__PURE__*/jsx(MenuItem.Button, _objectSpread$2(_objectSpread$2({}, itemProps), {}, {
                  children: label
                }), key);
              })
            })
          }, "".concat(key, "-nested-dropdown"));
        }
        return menuButton;
      })
    })
  });
};

var _excluded = ["className", "key", "label", "disabled", "labelProps", "moreOptions"];
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 NavigationLinks = function NavigationLinks(_ref) {
  var headerLinks = _ref.headerLinks,
    _ref$maxVisibleLinks = _ref.maxVisibleLinks,
    maxVisibleLinks = _ref$maxVisibleLinks === void 0 ? 5 : _ref$maxVisibleLinks;
  var visibleLinks = headerLinks.slice(0, maxVisibleLinks);
  var overflowLinks = headerLinks.slice(maxVisibleLinks);
  return /*#__PURE__*/jsxs("div", {
    className: "font- flex w-full items-center justify-between gap-4 md:justify-center md:gap-3 lg:gap-6",
    "data-cy": "navigation-header-navigation-links",
    "data-testid": "navigation-header-navigation-links",
    children: [visibleLinks.map(function (_ref2) {
      var _ref2$className = _ref2.className,
        className = _ref2$className === void 0 ? "" : _ref2$className,
        key = _ref2.key,
        label = _ref2.label,
        disabled = _ref2.disabled,
        labelProps = _ref2.labelProps,
        moreOptions = _ref2.moreOptions,
        rest = _objectWithoutProperties(_ref2, _excluded);
      return /*#__PURE__*/jsxs(NavLink, _objectSpread$1(_objectSpread$1({
        activeClassName: "active",
        "data-cy": "".concat(joinHyphenCase(key), "-tab"),
        "data-testid": "".concat(joinHyphenCase(key), "-tab"),
        className: classnames("neeto-molecules-navigation-header__link px-2 capitalize no-underline md:px-0", className, {
          disabled: disabled
        }),
        onClick: function onClick(e) {
          return disabled && e.preventDefault();
        }
      }, rest), {}, {
        children: [/*#__PURE__*/jsx(Typography, _objectSpread$1(_objectSpread$1({
          component: "span",
          lineHeight: "normal",
          style: "h4",
          weight: "semibold"
        }, labelProps || {}), {}, {
          children: label
        })), moreOptions && /*#__PURE__*/jsx(MoreDropdown, _objectSpread$1({}, moreOptions))]
      }), key);
    }), /*#__PURE__*/jsx(OverflowLinks, {
      overflowLinks: overflowLinks
    })]
  });
};

var css = ".standalone-publish-preview-button{border-radius:var(--neeto-ui-rounded)!important}.neeto-molecules-navigation-header .neeto-molecules-breadcrumbs-wrap{flex-wrap:nowrap}.neeto-molecules-navigation-header .neeto-ui-text-h4{color:inherit}@media screen and (max-width:1024px){.neeto-molecules-navigation-header .neeto-ui-text-h4{font-size:.875rem;font-weight:var(--neeto-ui-font-medium)}}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link{color:rgb(var(--neeto-ui-gray-500))}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link--more{background-color:transparent!important;box-shadow:none!important;flex-shrink:0;padding-block-end:0!important;padding-block-start:0!important}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link.active{color:rgb(var(--neeto-ui-black))}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link:hover:not(.active){color:rgb(var(--neeto-ui-gray-600))}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link.disabled{color:rgb(var(--neeto-ui-gray-300));cursor:not-allowed}.neeto-molecules-navigation-header .neeto-molecules-navigation-header__link.disabled:hover{color:rgb(var(--neeto-ui-gray-300))}";
n(css,{});

var isAbsoluteUrl = function isAbsoluteUrl(url) {
  return /^https?:\/\//.test(url);
};

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 RightBlock = function RightBlock(_ref) {
  var isDraftBlockHidden = _ref.isDraftBlockHidden,
    previewDraftUrl = _ref.previewDraftUrl,
    isResetDraftButtonVisible = _ref.isResetDraftButtonVisible,
    onResetClick = _ref.onResetClick,
    isResetting = _ref.isResetting,
    isPublishDisabled = _ref.isPublishDisabled,
    isPublishing = _ref.isPublishing,
    handlePublish = _ref.handlePublish,
    isPublishPreviewDisabled = _ref.isPublishPreviewDisabled,
    previewPublishedUrl = _ref.previewPublishedUrl,
    isPublishButtonVisible = _ref.isPublishButtonVisible,
    isResetAlertOpen = _ref.isResetAlertOpen,
    setIsResetAlertOpen = _ref.setIsResetAlertOpen,
    handleReset = _ref.handleReset,
    publishAlertTitle = _ref.publishAlertTitle,
    publishAlertDescription = _ref.publishAlertDescription,
    _ref$publishButtonPro = _ref.publishButtonProps,
    publishButtonProps = _ref$publishButtonPro === void 0 ? {} : _ref$publishButtonPro;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var renderDraftButtons = function renderDraftButtons(_ref2) {
    var ViewDraftButton = _ref2.ViewDraftButton,
      ResetDraftButton = _ref2.ResetDraftButton;
    return !isDraftBlockHidden && /*#__PURE__*/jsxs(Fragment, {
      children: [/*#__PURE__*/jsx(ViewDraftButton, _objectSpread({}, isAbsoluteUrl(previewDraftUrl) ? {
        href: previewDraftUrl
      } : {
        to: previewDraftUrl
      })), isResetDraftButtonVisible && /*#__PURE__*/jsx(ResetDraftButton, {
        loading: isResetting,
        onClick: function onClick() {
          return onResetClick();
        }
      })]
    });
  };
  var renderPublishButtons = function renderPublishButtons(_ref3) {
    var PublishButton = _ref3.PublishButton,
      PublishPreviewButton = _ref3.PublishPreviewButton;
    return /*#__PURE__*/jsxs(Fragment, {
      children: [isPublishButtonVisible && /*#__PURE__*/jsx(PublishButton, _objectSpread({
        disabled: isPublishDisabled,
        loading: isPublishing,
        onClick: function onClick() {
          return handlePublish();
        }
      }, publishButtonProps)), /*#__PURE__*/jsx(PublishPreviewButton, _objectSpread(_objectSpread({}, isAbsoluteUrl(previewPublishedUrl) ? {
        href: previewPublishedUrl
      } : {
        to: previewPublishedUrl
      }), {}, {
        disabled: isPublishPreviewDisabled,
        className: classnames({
          "standalone-publish-preview-button": !isPublishButtonVisible
        })
      }))]
    });
  };
  return /*#__PURE__*/jsxs(Fragment, {
    children: [/*#__PURE__*/jsx(PublishBlock, {
      renderDraftButtons: renderDraftButtons,
      renderPublishButtons: renderPublishButtons
    }), /*#__PURE__*/jsx(PublishBlock.Alert, {
      isOpen: isResetAlertOpen,
      isSubmitting: isResetting,
      message: publishAlertDescription || t("neetoMolecules.navigationHeader.resetDescription"),
      title: publishAlertTitle || t("neetoMolecules.navigationHeader.resetTitle"),
      onClose: function onClose() {
        return setIsResetAlertOpen(false);
      },
      onSubmit: handleReset
    })]
  });
};

var NavigationHeader = function NavigationHeader(_ref) {
  var leftActionBlock = _ref.leftActionBlock,
    navigationLinks = _ref.navigationLinks,
    rightActionBlock = _ref.rightActionBlock;
  var _useBreakpoints = useBreakpoints(),
    isSize = _useBreakpoints.isSize;
  var isMobile = isSize("mobile");
  var numberOfChildren = length(filter(isPresent, [leftActionBlock, navigationLinks, rightActionBlock]));
  var gridStyle = {
    gridTemplateColumns: isMobile ? "repeat(".concat(navigationLinks ? numberOfChildren - 1 : numberOfChildren, ", auto)") : "repeat(".concat(numberOfChildren, ", 1fr)")
  };
  return /*#__PURE__*/jsxs("div", {
    className: "w-full",
    children: [/*#__PURE__*/jsx("div", {
      className: "neeto-molecules-navigation-header neeto-ui-border-gray-200 neeto-ui-bg-white flex h-16 w-full flex-shrink-0 items-center overflow-x-auto border-b px-2 py-2 md:px-4 lg:px-6",
      "data-cy": "navigation-header",
      "data-testid": "navigation-header",
      children: /*#__PURE__*/jsxs("div", {
        className: "grid w-full gap-4",
        style: gridStyle,
        children: [leftActionBlock, !isMobile && navigationLinks, rightActionBlock]
      })
    }), isMobile && /*#__PURE__*/jsx("div", {
      className: "neeto-molecules-navigation-header neeto-ui-border-gray-200 neeto-ui-bg-white flex flex-shrink-0 items-center overflow-x-auto border-b px-4 py-2 lg:px-6",
      children: navigationLinks
    })]
  });
};
NavigationHeader.LeftActionBlock = LeftBlock;
NavigationHeader.NavigationLinks = NavigationLinks;
NavigationHeader.RightActionBlock = RightBlock;

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