"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.PopupMenuDecorator = exports.PopupMenuBase = exports.PopupMenu = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _SpotlightContainerDecorator = _interopRequireDefault(require("@enact/spotlight/SpotlightContainerDecorator"));
var _Layout = _interopRequireWildcard(require("@enact/ui/Layout"));
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _Transition = _interopRequireDefault(require("@enact/ui/Transition"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _$L = _interopRequireDefault(require("../internal/$L"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _LabeledIconButton = _interopRequireDefault(require("../LabeledIconButton"));
var _Scroller = _interopRequireDefault(require("../Scroller"));
var _PopupState = _interopRequireDefault(require("../Popup/PopupState"));
var _PopupMenuModule = _interopRequireDefault(require("./PopupMenu.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "closeButton", "closeButtonLabel", "css", "noAnimation", "onClose", "onHide", "onShow", "open", "orientation", "spotlightId", "title"];
/**
 * A Popup menu component.
 *
 * @module agate/PopupMenu
 * @exports PopupMenu
 * @exports PopupMenuBase
 * @exports PopupMenuDecorator
 */
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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), !0).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; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
var TransitionContainer = (0, _SpotlightContainerDecorator["default"])({
  enterTo: 'default-element',
  preserveId: true
}, _Transition["default"]);

/**
 * The base popup menu component.
 *
 * @class PopupMenuBase
 * @memberof agate/PopupMenu
 * @ui
 * @public
 */
var PopupMenuBase = exports.PopupMenuBase = (0, _kind["default"])({
  name: 'PopupMenu',
  propTypes: /** @lends agate/PopupMenu.PopupMenuBase.prototype */{
    /**
     * When true, popup displays a close button.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    closeButton: _propTypes["default"].bool,
    /**
     * The label for the close button.
     *
     * @type {String}
     * @public
     */
    closeButtonLabel: _propTypes["default"].string,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * The following classes are supported:
     *
     * * `popupMenu` - The root class name
     * * `body` - Applied to the body content container
     * * `popupTransitionContainer` - Applied to the PopupMenu's outermost container. Sizing can be
     *                                applied here for percentage-of-screen values.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Disables transition animation.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    noAnimation: _propTypes["default"].bool,
    /**
     * Called when the popupMenu is closed.
     *
     * @type {Function}
     * @public
     */
    onClose: _propTypes["default"].func,
    /**
     * Called after the popupMenu's "hide" transition finishes.
     *
     * @type {Function}
     * @public
     */
    onHide: _propTypes["default"].func,
    /**
     * Called after the popup's "show" transition finishes.
     *
     * @type {Function}
     * @public
     */
    onShow: _propTypes["default"].func,
    /**
     * Controls the visibility of the PopupMenu.
     *
     * By default, the PopupMenu and its contents are not rendered until `open`.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    open: _propTypes["default"].bool,
    /**
     * The layout orientation of the component.
     *
     * @type {('horizontal')}
     * @default 'horizontal'
     * @private
     */
    orientation: _propTypes["default"].oneOf(['horizontal']),
    /**
     * The container id for {@link spotlight/Spotlight}.
     *
     * @type {String}
     * @default null
     * @public
     */
    spotlightId: _propTypes["default"].string,
    /**
     * The primary text of the popupMenu.
     *
     * @type {String}
     * @public
     */
    title: _propTypes["default"].string
  },
  defaultProps: {
    closeButton: false,
    closeButtonLabel: (0, _$L["default"])('Cancel'),
    noAnimation: false,
    open: false,
    orientation: 'horizontal'
  },
  styles: {
    css: _PopupMenuModule["default"],
    className: 'popupMenu',
    publicClassNames: true
  },
  computed: {
    className: function className(_ref) {
      var orientation = _ref.orientation,
        styler = _ref.styler;
      return styler.append(orientation);
    }
  },
  render: function render(_ref2) {
    var children = _ref2.children,
      closeButton = _ref2.closeButton,
      closeButtonLabel = _ref2.closeButtonLabel,
      css = _ref2.css,
      noAnimation = _ref2.noAnimation,
      onClose = _ref2.onClose,
      onHide = _ref2.onHide,
      onShow = _ref2.onShow,
      open = _ref2.open,
      orientation = _ref2.orientation,
      spotlightId = _ref2.spotlightId,
      title = _ref2.title,
      rest = _objectWithoutProperties(_ref2, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(TransitionContainer, {
      className: css.popupTransitionContainer,
      css: css,
      direction: "down",
      duration: "short",
      noAnimation: noAnimation,
      onHide: onHide,
      onShow: onShow,
      spotlightId: spotlightId,
      type: "fade",
      visible: open,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout["default"], _objectSpread(_objectSpread({
        orientation: "vertical",
        align: "center center",
        role: "alert"
      }, rest), {}, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.popupMenuTitle,
          shrink: true,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Heading["default"], {
            css: css,
            size: "title",
            children: title
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          shrink: true,
          className: css.body,
          align: "stretch",
          children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Scroller["default"], {
            direction: orientation,
            horizontalScrollbar: "hidden",
            verticalScrollbar: "hidden",
            children: [children, closeButton ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_LabeledIconButton["default"], {
              backgroundOpacity: "lightOpaque",
              className: css.closeButton,
              css: css,
              icon: "cancel",
              inline: true,
              onClick: onClose,
              size: "huge",
              children: closeButtonLabel
            }) : null]
          })
        })]
      }))
    });
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/PopupMenu.PopupMenuBase|PopupMenuBase}.
 *
 * @hoc
 * @memberof agate/PopupMenu
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var PopupMenuDecorator = exports.PopupMenuDecorator = (0, _compose["default"])((0, _Slottable["default"])({
  slots: ['title']
}), (0, _Skinnable["default"])({
  prop: 'skin'
}), _PopupState["default"]);

/**
 * A stateful component that renders a popup menu.
 *
 * Usage:
 * ```
 * <PopupMenu open title="Title">
 *   Hello!
 * </PopupMenu>
 * ```
 *
 * @class PopupMenu
 * @memberof agate/PopupMenu
 * @extends agate/PopupMenu.PopupMenuBase
 * @mixes agate/PopupMenu.PopupMenuDecorator
 * @ui
 * @public
 */
var PopupMenu = exports.PopupMenu = PopupMenuDecorator(PopupMenuBase);
var _default = exports["default"] = PopupMenu;