"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PopupMenuDecorator = exports.PopupMenuBase = exports.PopupMenu = exports["default"] = void 0;

var _jsxRuntime = require("react/jsx-runtime");

var _kind = _interopRequireDefault(require("@enact/core/kind"));

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"));

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/**
 * The base popup menu component.
 *
 * @class PopupMenuBase
 * @memberof agate/PopupMenu
 * @ui
 * @public
 */
var PopupMenuBase = (0, _kind["default"])({
  name: 'PopupMenu',
  propTypes:
  /** @lends agate/PopupMenu.PopupMenuBase.prototype */
  {
    closeButton: _propTypes["default"].bool,
    closeButtonLabel: _propTypes["default"].string,
    css: _propTypes["default"].object,
    noAnimation: _propTypes["default"].bool,
    onClose: _propTypes["default"].func,
    onHide: _propTypes["default"].func,
    open: _propTypes["default"].bool,

    /**
     * The layout orientation of the component
     *
     * @type {('horizontal')}
     * @default 'horizontal'
     * @private
     */
    orientation: _propTypes["default"].oneOf(['horizontal']),
    title: _propTypes["default"].string
  },
  defaultProps: {
    closeButton: false,
    closeButtonLabel: (0, _$L["default"])('Cancel'),
    noAnimation: false,
    open: false,
    orientation: 'horizontal'
  },
  styles: {
    css: _PopupMenuModule["default"],
    className: 'popupMenu'
  },
  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,
        open = _ref2.open,
        orientation = _ref2.orientation,
        title = _ref2.title,
        rest = _objectWithoutProperties(_ref2, ["children", "closeButton", "closeButtonLabel", "css", "noAnimation", "onClose", "onHide", "open", "orientation", "title"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
      noAnimation: noAnimation,
      visible: open,
      direction: "down",
      duration: "short",
      type: "fade",
      className: css.popupTransitionContainer,
      onHide: onHide,
      css: css,
      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.title,
          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"], {
              inline: true,
              icon: "cancel",
              onClick: onClose,
              className: css.closeButton,
              size: "huge",
              backgroundOpacity: "lightOpaque",
              children: closeButtonLabel
            }) : null]
          })
        })]
      }))
    });
  }
});
/**
 * Applies Agate specific behaviors to [PopupMenuBase]{@link agate/PopupMenu.PopupMenuBase}.
 *
 * @hoc
 * @memberof agate/PopupMenu
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.PopupMenuBase = PopupMenuBase;
var 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
 */

exports.PopupMenuDecorator = PopupMenuDecorator;
var PopupMenu = PopupMenuDecorator(PopupMenuBase);
exports.PopupMenu = PopupMenu;
var _default = PopupMenu;
exports["default"] = _default;