/* top-nav-end.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TopNavEnd = TopNavEnd;
require("./top-nav-end.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@compiled/react");
var _useLayoutEffect = require("@atlaskit/ds-lib/use-layout-effect");
var _showMoreHorizontal = _interopRequireDefault(require("@atlaskit/icon/core/show-more-horizontal"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _popup = _interopRequireDefault(require("@atlaskit/popup"));
var _compiled = require("@atlaskit/primitives/compiled");
var _list = require("../../../components/list");
var _hasCustomThemeContext = require("../../top-nav-items/themed/has-custom-theme-context");
var _migration = require("../../top-nav-items/themed/migration");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var containerStyles = {
  root: "_yyhy11wp _1e0c1txw _1bahh9n0 _1ul9zwfg _1d2y1ris _glte1ris _15ri1mjv _1gs5usvi _ndwch9n0",
  jiraProductLogoUpdate: "_15rip2n4",
  fullHeightSidebar: "_lcxv1wug _y4tiutpp"
};
var listStyles = {
  root: "_zulp1b66 _4cvr1h6o _1e0c1txw",
  hideOnSmallViewport: "_1e0cglyw _181n1txw",
  popupContainer: "_1yt4u2gc"
};

/**
 * __TopNavEnd__
 *
 * Wrapper for the top navigation actions on the inline-end (right) side of the top navigation.
 *
 * On small viewports, the children will be placed inside a popup, and a button will be rendered to open the popup.
 * This is to prevent the actions from overflowing the top navigation.
 */
function TopNavEnd(_ref) {
  var children = _ref.children,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? 'Actions' : _ref$label,
    _ref$showMoreButtonLa = _ref.showMoreButtonLabel,
    showMoreButtonLabel = _ref$showMoreButtonLa === void 0 ? 'Show more' : _ref$showMoreButtonLa;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  // Always setting to `false` for the initial render (will flip in an effect for mobile)
  var _useState3 = (0, _react.useState)(false),
    _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
    isMobile = _useState4[0],
    setIsMobile = _useState4[1];
  // Note: `query` is a stable value between renders
  var query = (0, _compiled.UNSAFE_useMediaQuery)('below.sm', function onChange(event) {
    setIsMobile(event.matches);
    // Any time we shift between mobile and desktop
    // We always close the popup
    setIsOpen(false);
  });
  (0, _useLayoutEffect.useLayoutEffect)(function () {
    var _query$matches;
    // The default is `false`, and desktop will remain as `false` (no re-render).
    // Mobile will flip from `false` to `true`.
    setIsMobile((_query$matches = query === null || query === void 0 ? void 0 : query.matches) !== null && _query$matches !== void 0 ? _query$matches : false);
  }, [query]);
  return /*#__PURE__*/_react.default.createElement("nav", {
    "aria-label": label,
    className: (0, _runtime.ax)([containerStyles.root, (0, _platformFeatureFlags.fg)('navx-full-height-sidebar') && containerStyles.fullHeightSidebar, (0, _platformFeatureFlags.fg)('team25-eu-jira-logo-updates-csm-jsm') && containerStyles.jiraProductLogoUpdate])
  }, isMobile ? /*#__PURE__*/_react.default.createElement(_popup.default, {
    isOpen: isOpen,
    onClose: function onClose() {
      return setIsOpen(false);
    },
    placement: "bottom-start",
    shouldRenderToParent: true,
    content: function content() {
      return /*#__PURE__*/_react.default.createElement(_hasCustomThemeContext.HasCustomThemeContext.Provider, {
        value: false
      }, /*#__PURE__*/_react.default.createElement(_list.List, {
        xcss: (0, _react2.cx)(listStyles.root, listStyles.popupContainer)
      }, children));
    },
    trigger: function trigger(triggerProps) {
      return /*#__PURE__*/_react.default.createElement(_migration.IconButton, (0, _extends2.default)({}, triggerProps, {
        label: showMoreButtonLabel,
        isSelected: isOpen,
        onClick: function onClick() {
          return setIsOpen(!isOpen);
        },
        icon: _showMoreHorizontal.default,
        isTooltipDisabled: false
      }));
    }
  }) : /*#__PURE__*/_react.default.createElement(_list.List, {
    xcss: (0, _react2.cx)(listStyles.root, listStyles.hideOnSmallViewport)
  }, children));
}