import { isPresent, existsBy, isNotEmpty } from '@bigbinary/neeto-cist';
import useBreakpoints from '@bigbinary/neeto-commons-frontend/v2/react-utils/useBreakpoints';
import { mergeDeepRight, length, filter } from 'ramda';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { Tooltip } from '@bigbinary/neeto-atoms';
import { Link, useLocation } from 'react-router-dom';
import { t } from 'i18next';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { c as createLucideIcon } from '../createLucideIcon-mNMhCCpf.js';
import Rename from './Rename.js';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, Tabs, TabsList, TabsTrigger } from '@bigbinary/neeto-atoms/primitives';
import classnames from 'classnames';
import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/v2/utils/general';
import { useTranslation } from 'react-i18next';
import { createElement } from 'react';
import MoreDropdown from './MoreDropdown.js';
import PublishBlock from './PublishBlock.js';
import '@babel/runtime/helpers/slicedToArray';
import '@bigbinary/neeto-commons-frontend/v2/react-utils/useOnClickOutside';
import '@bigbinary/neeto-commons-frontend/v2/react-utils/useStateWithDependency';
import '@bigbinary/neeto-hotkeys';
import '../check-DvxzqR83.js';
import '../x-B1Er0oV4.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@bigbinary/neeto-commons-frontend/v2/react-utils';
import './Breadcrumbs.js';
import '../ellipsis-DpI9xqUK.js';
import '@bigbinary/neeto-commons-frontend/v2/utils';
import '@bigbinary/neeto-team-members-frontend/Profile';
import '@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("house", __iconNode);

var DEFAULT_HOME_BUTTON_PROPS = {
  tooltip: {
    content: t("neetoMolecules.navigationHeader.home"),
    position: "bottom"
  },
  homeUrl: "/",
  icon: /*#__PURE__*/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 = mergeDeepRight(DEFAULT_HOME_BUTTON_PROPS, customHomeButtonProps);
  return /*#__PURE__*/jsxs("div", {
    className: "flex items-center gap-0.5 md:gap-1",
    "data-testid": "navigation-header-left-block",
    children: [/*#__PURE__*/jsx(Tooltip, {
      content: homeButtonProps.tooltip.content,
      position: homeButtonProps.tooltip.position,
      children: /*#__PURE__*/jsx(Link, {
        "data-testid": "home-button",
        to: homeUrl,
        children: /*#__PURE__*/jsx("div", {
          className: "hover:bg-muted rounded 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"];
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 = useLocation(),
    pathname = _useLocation.pathname;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var isMoreButtonActive = existsBy({
    to: pathname
  }, overflowLinks);
  if (!isNotEmpty(overflowLinks)) {
    return null;
  }
  return /*#__PURE__*/jsxs(DropdownMenu, {
    children: [/*#__PURE__*/jsx(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__*/jsx(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__*/createElement(DropdownMenuItem, {
          disabled: disabled,
          asChild: true,
          "data-active": isActive || undefined,
          "data-testid": "".concat(joinHyphenCase(key), "-more-tab"),
          key: key,
          className: classnames({
            "bg-accent text-accent-foreground": isActive
          })
        }, /*#__PURE__*/jsx(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 = useLocation(),
    pathname = _useLocation.pathname;
  var visibleLinks = headerLinks.slice(0, maxVisibleLinks);
  var overflowLinks = headerLinks.slice(maxVisibleLinks);
  var activeValue = getActiveLinkValue(visibleLinks, pathname);
  return /*#__PURE__*/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__*/jsx(Tabs, {
      value: activeValue !== null && activeValue !== void 0 ? activeValue : "",
      children: /*#__PURE__*/jsxs(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__*/createElement(TabsTrigger, {
            disabled: disabled,
            asChild: true,
            "data-testid": "".concat(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__*/jsxs(Link, _objectSpread$1(_objectSpread$1({
            to: to,
            onClick: function onClick(e) {
              return disabled && e.preventDefault();
            }
          }, rest), {}, {
            children: [/*#__PURE__*/jsx("span", _objectSpread$1(_objectSpread$1({}, labelProps || {}), {}, {
              children: label
            })), moreOptions && /*#__PURE__*/jsx(MoreDropdown, _objectSpread$1({}, moreOptions))]
          })));
        }), /*#__PURE__*/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 = 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({
          "nm-publish-preview-button--standalone": !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: "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__*/jsxs("div", {
        className: "grid w-full gap-4",
        style: gridStyle,
        children: [leftActionBlock, !isMobile && navigationLinks, rightActionBlock]
      })
    }), isMobile && /*#__PURE__*/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;

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