'use strict';

var neetoCist = require('@bigbinary/neeto-cist');
var useBreakpoints = require('@bigbinary/neeto-commons-frontend/v2/react-utils/useBreakpoints');
var ramda = require('ramda');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var reactRouterDom = require('react-router-dom');
var i18next = require('i18next');
var jsxRuntime = require('react/jsx-runtime');
var createLucideIcon = require('../createLucideIcon-DBDhE7kE.js');
var v2_Rename = require('./Rename.js');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var primitives = require('@bigbinary/neeto-atoms/primitives');
var classnames = require('classnames');
var general = require('@bigbinary/neeto-commons-frontend/v2/utils/general');
var reactI18next = require('react-i18next');
var React = require('react');
var v2_MoreDropdown = require('./MoreDropdown.js');
var v2_PublishBlock = require('./PublishBlock.js');
require('@babel/runtime/helpers/slicedToArray');
require('@bigbinary/neeto-commons-frontend/v2/react-utils/useOnClickOutside');
require('@bigbinary/neeto-commons-frontend/v2/react-utils/useStateWithDependency');
require('@bigbinary/neeto-hotkeys');
require('../check-VgZf0qTr.js');
require('../x-B38UX0_0.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@bigbinary/neeto-commons-frontend/v2/react-utils');
require('./Breadcrumbs.js');
require('../ellipsis-BcfLTtl5.js');
require('@bigbinary/neeto-commons-frontend/v2/utils');
require('@bigbinary/neeto-team-members-frontend/Profile');
require('@bigbinary/neeto-commons-frontend/v2/initializers');

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode = [
  ["path", { d: "M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8", key: "5wwlr5" }],
  [
    "path",
    {
      d: "M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
      key: "r6nss1"
    }
  ]
];
const House = createLucideIcon.createLucideIcon("house", __iconNode);

var DEFAULT_HOME_BUTTON_PROPS = {
  tooltip: {
    content: i18next.t("neetoMolecules.navigationHeader.home"),
    position: "bottom"
  },
  homeUrl: "/",
  icon: /*#__PURE__*/jsxRuntime.jsx(House, {
    className: "size-5"
  })
};

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-0.5 md:gap-1",
    "data-testid": "navigation-header-left-block",
    children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Tooltip, {
      content: homeButtonProps.tooltip.content,
      position: homeButtonProps.tooltip.position,
      children: /*#__PURE__*/jsxRuntime.jsx(reactRouterDom.Link, {
        "data-testid": "home-button",
        to: homeUrl,
        children: /*#__PURE__*/jsxRuntime.jsx("div", {
          className: "hover:bg-muted rounded p-1",
          children: homeButtonProps.icon
        })
      })
    }), neetoCist.isPresent(renameProps) && /*#__PURE__*/jsxRuntime.jsx(v2_Rename, _objectSpread$3({
      dropdownItems: renameProps.dropdownItems,
      value: renameProps.value
    }, renameProps)), children]
  });
};

var _excluded$1 = ["key", "to", "label", "disabled"];
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 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.jsxs(primitives.DropdownMenu, {
    children: [/*#__PURE__*/jsxRuntime.jsx(primitives.DropdownMenuTrigger, {
      className: classnames("nm-navigation-header__link nm-navigation-header__link--more text-foreground/60 hover:text-foreground inline-flex h-[calc(100%-1px)] items-center justify-center gap-1.5 rounded-md border border-transparent bg-transparent px-3 py-1.5 text-[15px] font-medium capitalize transition-all", {
        "bg-background text-foreground shadow-sm": isMoreButtonActive
      }),
      children: t("neetoMolecules.navigationHeader.more")
    }), /*#__PURE__*/jsxRuntime.jsx(primitives.DropdownMenuContent, {
      align: "end",
      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;
        return /*#__PURE__*/React.createElement(primitives.DropdownMenuItem, {
          disabled: disabled,
          asChild: true,
          "data-active": isActive || undefined,
          "data-testid": "".concat(general.joinHyphenCase(key), "-more-tab"),
          key: key,
          className: classnames({
            "bg-accent text-accent-foreground": isActive
          })
        }, /*#__PURE__*/jsxRuntime.jsx(reactRouterDom.Link, _objectSpread$2(_objectSpread$2({
          to: to,
          className: "block w-full",
          onClick: function onClick(e) {
            return disabled && e.preventDefault();
          }
        }, rest), {}, {
          children: label
        })));
      })
    })]
  });
};

var isAbsoluteUrl = function isAbsoluteUrl(url) {
  return /^https?:\/\//.test(url);
};
var getActiveLinkValue = function getActiveLinkValue(links, pathname) {
  var matches = links.filter(function (_ref) {
    var to = _ref.to;
    return pathname === to || pathname.startsWith("".concat(to, "/"));
  });
  if (matches.length === 0) return undefined;
  return matches.reduce(function (longest, link) {
    return link.to.length > longest.to.length ? link : longest;
  }).to;
};

var _excluded = ["className", "key", "to", "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 _useLocation = reactRouterDom.useLocation(),
    pathname = _useLocation.pathname;
  var visibleLinks = headerLinks.slice(0, maxVisibleLinks);
  var overflowLinks = headerLinks.slice(maxVisibleLinks);
  var activeValue = getActiveLinkValue(visibleLinks, pathname);
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    className: "flex w-full items-center justify-between gap-2 md:justify-center md:gap-3",
    "data-testid": "navigation-header-navigation-links",
    children: /*#__PURE__*/jsxRuntime.jsx(primitives.Tabs, {
      value: activeValue !== null && activeValue !== void 0 ? activeValue : "",
      children: /*#__PURE__*/jsxRuntime.jsxs(primitives.TabsList, {
        className: "group-data-horizontal/tabs:h-10",
        children: [visibleLinks.map(function (_ref2) {
          var _ref2$className = _ref2.className,
            className = _ref2$className === void 0 ? "" : _ref2$className,
            key = _ref2.key,
            to = _ref2.to,
            label = _ref2.label,
            disabled = _ref2.disabled,
            labelProps = _ref2.labelProps,
            moreOptions = _ref2.moreOptions,
            rest = _objectWithoutProperties(_ref2, _excluded);
          return /*#__PURE__*/React.createElement(primitives.TabsTrigger, {
            disabled: disabled,
            asChild: true,
            "data-testid": "".concat(general.joinHyphenCase(key), "-tab"),
            key: key,
            value: to,
            className: classnames("nm-navigation-header__link px-3 py-1.5 text-[15px] capitalize no-underline", className, {
              "disabled pointer-events-none cursor-not-allowed opacity-50": disabled
            })
          }, /*#__PURE__*/jsxRuntime.jsxs(reactRouterDom.Link, _objectSpread$1(_objectSpread$1({
            to: to,
            onClick: function onClick(e) {
              return disabled && e.preventDefault();
            }
          }, rest), {}, {
            children: [/*#__PURE__*/jsxRuntime.jsx("span", _objectSpread$1(_objectSpread$1({}, labelProps || {}), {}, {
              children: label
            })), moreOptions && /*#__PURE__*/jsxRuntime.jsx(v2_MoreDropdown, _objectSpread$1({}, moreOptions))]
          })));
        }), /*#__PURE__*/jsxRuntime.jsx(OverflowLinks, {
          overflowLinks: overflowLinks
        })]
      })
    })
  });
};

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({
          "nm-publish-preview-button--standalone": !isPublishButtonVisible
        })
      }))]
    });
  };
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
    children: [/*#__PURE__*/jsxRuntime.jsx(v2_PublishBlock, {
      renderDraftButtons: renderDraftButtons,
      renderPublishButtons: renderPublishButtons
    }), /*#__PURE__*/jsxRuntime.jsx(v2_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: "nm-navigation-header border-border bg-card 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: "nm-navigation-header border-border bg-card 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
