'use strict';

var neetoCist = require('@bigbinary/neeto-cist');
var useBreakpoints = require('@bigbinary/neeto-commons-frontend/react-utils/useBreakpoints');
var ramda = require('ramda');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Tooltip = require('@bigbinary/neetoui/Tooltip');
var reactRouterDom = require('react-router-dom');
var Rename = require('./Rename.js');
var i18next = require('i18next');
var Home = require('@bigbinary/neeto-icons/Home');
var jsxRuntime = require('react/jsx-runtime');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var classnames = require('classnames');
var general = require('@bigbinary/neeto-commons-frontend/utils/general');
var Typography = require('@bigbinary/neetoui/Typography');
var MoreDropdown = require('./MoreDropdown.js');
var Dropdown = require('@bigbinary/neetoui/Dropdown');
var reactI18next = require('react-i18next');
var React = require('react');
var PublishBlock = require('./PublishBlock.js');
var injectCss = require('./inject-css-B6qYtOJe.js');
require('@babel/runtime/helpers/slicedToArray');
require('@bigbinary/neeto-commons-frontend/react-utils/useOnClickOutside');
require('@bigbinary/neeto-commons-frontend/react-utils/useStateWithDependency');
require('./Breadcrumbs.js');
require('@bigbinary/neeto-hotkeys');
require('@bigbinary/neeto-icons/Check');
require('@bigbinary/neeto-icons/Close');
require('@bigbinary/neetoui/Button');
require('@bigbinary/neetoui/Input');
require('@babel/runtime/helpers/toConsumableArray');
require('@bigbinary/neeto-commons-frontend/react-utils');
require('@bigbinary/neeto-icons/MenuHorizontal');
require('@bigbinary/neeto-icons/MenuVertical');
require('@bigbinary/neeto-commons-frontend/react-utils/withT');
require('@bigbinary/neeto-commons-frontend/utils');
require('@bigbinary/neeto-icons/ExternalLink');
require('@bigbinary/neeto-icons/Delete');
require('@bigbinary/neeto-icons/Clock');
require('@bigbinary/neetoui/Alert');
require('@bigbinary/neetoui/Pane');
require('@bigbinary/neeto-team-members-frontend/Profile');
require('@bigbinary/neetoui/DatePicker');
require('@bigbinary/neeto-commons-frontend/initializers');
require('@bigbinary/neetoui/Label');

var DEFAULT_HOME_BUTTON_PROPS = {
  tooltip: {
    content: i18next.t("neetoMolecules.navigationHeader.home"),
    position: "bottom"
  },
  homeUrl: "/",
  icon: /*#__PURE__*/jsxRuntime.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 = ramda.mergeDeepRight(DEFAULT_HOME_BUTTON_PROPS, customHomeButtonProps);
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "flex items-center gap-1 md:gap-2",
    "data-testid": "navigation-header-left-block",
    children: [/*#__PURE__*/jsxRuntime.jsx(Tooltip, {
      content: homeButtonProps.tooltip.content,
      position: homeButtonProps.tooltip.position,
      touch: ["hold", 500],
      children: /*#__PURE__*/jsxRuntime.jsx(reactRouterDom.Link, {
        "data-testid": "home-button",
        to: homeUrl,
        children: /*#__PURE__*/jsxRuntime.jsx("div", {
          className: "neeto-ui-rounded hover:neeto-ui-bg-gray-200 p-1",
          children: homeButtonProps.icon
        })
      })
    }), neetoCist.isPresent(renameProps) && /*#__PURE__*/jsxRuntime.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 = reactRouterDom.useLocation(),
    pathname = _useLocation.pathname;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var isMoreButtonActive = neetoCist.existsBy({
    to: pathname
  }, overflowLinks);
  if (!neetoCist.isNotEmpty(overflowLinks)) {
    return null;
  }
  return /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.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__*/React.createElement(MenuItem.Button, _objectSpread$2({
          isActive: isActive,
          to: to,
          "data-testid": "".concat(general.joinHyphenCase(key), "-more-tab"),
          isDisabled: disabled,
          key: key,
          onClick: function onClick(e) {
            return disabled && e.preventDefault();
          }
        }, rest), label);
        if (isActive && rest.moreOptions && neetoCist.isNotEmpty(rest.moreOptions.menuItems)) {
          return /*#__PURE__*/jsxRuntime.jsx(Dropdown, {
            customTarget: menuButton,
            position: "right-start",
            trigger: "hover",
            children: /*#__PURE__*/jsxRuntime.jsx(Menu, {
              children: rest.moreOptions.menuItems.map(function (_ref3) {
                var key = _ref3.key,
                  label = _ref3.label,
                  itemProps = _objectWithoutProperties(_ref3, _excluded2);
                return /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsxs("div", {
    className: "font- flex w-full items-center justify-between gap-4 md:justify-center md:gap-3 lg:gap-6",
    "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__*/jsxRuntime.jsxs(reactRouterDom.NavLink, _objectSpread$1(_objectSpread$1({
        activeClassName: "active",
        "data-testid": "".concat(general.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__*/jsxRuntime.jsx(Typography, _objectSpread$1(_objectSpread$1({
          component: "span",
          lineHeight: "normal",
          style: "h4",
          weight: "semibold"
        }, labelProps || {}), {}, {
          children: label
        })), moreOptions && /*#__PURE__*/jsxRuntime.jsx(MoreDropdown, _objectSpread$1({}, moreOptions))]
      }), key);
    }), /*#__PURE__*/jsxRuntime.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))}";
injectCss.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 = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var renderDraftButtons = function renderDraftButtons(_ref2) {
    var ViewDraftButton = _ref2.ViewDraftButton,
      ResetDraftButton = _ref2.ResetDraftButton;
    return !isDraftBlockHidden && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [/*#__PURE__*/jsxRuntime.jsx(ViewDraftButton, _objectSpread({}, isAbsoluteUrl(previewDraftUrl) ? {
        href: previewDraftUrl
      } : {
        to: previewDraftUrl
      })), isResetDraftButtonVisible && /*#__PURE__*/jsxRuntime.jsx(ResetDraftButton, {
        loading: isResetting,
        onClick: function onClick() {
          return onResetClick();
        }
      })]
    });
  };
  var renderPublishButtons = function renderPublishButtons(_ref3) {
    var PublishButton = _ref3.PublishButton,
      PublishPreviewButton = _ref3.PublishPreviewButton;
    return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [isPublishButtonVisible && /*#__PURE__*/jsxRuntime.jsx(PublishButton, _objectSpread({
        disabled: isPublishDisabled,
        loading: isPublishing,
        onClick: function onClick() {
          return handlePublish();
        }
      }, publishButtonProps)), /*#__PURE__*/jsxRuntime.jsx(PublishPreviewButton, _objectSpread(_objectSpread({}, isAbsoluteUrl(previewPublishedUrl) ? {
        href: previewPublishedUrl
      } : {
        to: previewPublishedUrl
      }), {}, {
        disabled: isPublishPreviewDisabled,
        className: classnames({
          "standalone-publish-preview-button": !isPublishButtonVisible
        })
      }))]
    });
  };
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
    children: [/*#__PURE__*/jsxRuntime.jsx(PublishBlock, {
      renderDraftButtons: renderDraftButtons,
      renderPublishButtons: renderPublishButtons
    }), /*#__PURE__*/jsxRuntime.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 = ramda.length(ramda.filter(neetoCist.isPresent, [leftActionBlock, navigationLinks, rightActionBlock]));
  var gridStyle = {
    gridTemplateColumns: isMobile ? "repeat(".concat(navigationLinks ? numberOfChildren - 1 : numberOfChildren, ", auto)") : "repeat(".concat(numberOfChildren, ", 1fr)")
  };
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "w-full",
    children: [/*#__PURE__*/jsxRuntime.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-testid": "navigation-header",
      children: /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "grid w-full gap-4",
        style: gridStyle,
        children: [leftActionBlock, !isMobile && navigationLinks, rightActionBlock]
      })
    }), isMobile && /*#__PURE__*/jsxRuntime.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;

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