"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.DrawerDecorator = exports.DrawerBase = exports.Drawer = void 0;
var _compose = _interopRequireDefault(require("ramda/src/compose"));
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 _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _PopupState = _interopRequireDefault(require("../Popup/PopupState"));
var _DrawerModule = _interopRequireDefault(require("./Drawer.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "footer", "header", "noAnimation", "onHide", "open", "onShow", "spotlightId", "spotlightRestrict"];
/**
 * An Agate-themed drawer component.
 *
 * @module agate/Drawer
 * @exports Drawer
 * @exports DrawerBase
 * @exports DrawerDecorator
 */
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"]);

/**
 * A drawer component, without behaviors.
 *
 * @class DrawerBase
 * @memberof agate/Drawer
 * @extends ui/Transition.Transition
 * @ui
 * @public
 */
var DrawerBase = exports.DrawerBase = (0, _kind["default"])({
  name: 'Drawer',
  propTypes: /** @lends agate/Drawer.DrawerBase.prototype */{
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
    * Components to be included under the primary content.
    *
    * @type {Node}
    * @public
    */
    footer: _propTypes["default"].node,
    /**
     * Header for the drawer.
     *
     * @type {Node}
     * @public
     */
    header: _propTypes["default"].node,
    /**
     * Disables drawer transition animation.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    noAnimation: _propTypes["default"].bool,
    // `onClose` is here for the future scenario where we'll want to have a local (to Drawer)
    // control that closes the Drawer; similar to how the old Moonstone Drawer worked with its
    // close-tab that was positioned on the edge of the drawer. This prop, the close icon below
    // and the .closeButton CSS in the LESS file all relate to this functionality.
    // /**
    //  * Called when the drawer is closed.
    //  *
    //  * @type {Function}
    //  * @public
    //  */
    // onClose: PropTypes.func,

    /**
     * Called after the transition to hide the drawer has finished.
     *
     * @type {Function}
     * @public
     */
    onHide: _propTypes["default"].func,
    /**
     * Called after the drawer's "show" transition finishes.
     *
     * @type {Function}
     * @public
     */
    onShow: _propTypes["default"].func,
    /**
     * Displays the drawer.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    open: _propTypes["default"].bool,
    /**
     * Orientation of the drawer.
     *
     * @type {('horizontal'|'vertical')}
     * @default 'vertical'
     * @private
     */
    orientation: _propTypes["default"].oneOf(['horizontal', 'vertical']),
    /**
     * The container id for {@link spotlight/Spotlight}.
     *
     * @type {String}
     * @default null
     * @public
     */
    spotlightId: _propTypes["default"].string,
    /**
     * Restricts or prioritizes spotlight navigation.
     *
     * Allowed values are:
     * * `'none'` - Spotlight can move freely within and beyond the drawer
     * * `'self-first'` - Spotlight should prefer components within the drawer over
     *   components beyond the drawer, or
     * * `'self-only'` - Spotlight can only be set within the drawer
     *
     * @type {('none'|'self-first'|'self-only')}
     * @public
     */
    spotlightRestrict: _propTypes["default"].oneOf(['none', 'self-first', 'self-only'])
  },
  defaultProps: {
    noAnimation: false,
    open: false,
    orientation: 'vertical'
  },
  styles: {
    css: _DrawerModule["default"],
    className: 'drawer'
  },
  render: function render(_ref) {
    var children = _ref.children,
      css = _ref.css,
      footer = _ref.footer,
      header = _ref.header,
      noAnimation = _ref.noAnimation,
      onHide = _ref.onHide,
      open = _ref.open,
      onShow = _ref.onShow,
      spotlightId = _ref.spotlightId,
      spotlightRestrict = _ref.spotlightRestrict,
      rest = _objectWithoutProperties(_ref, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(TransitionContainer, {
      className: css.drawerTransitionContainer,
      css: css,
      direction: "left",
      duration: "short",
      noAnimation: noAnimation,
      onHide: onHide,
      onShow: onShow,
      spotlightId: spotlightId,
      spotlightRestrict: spotlightRestrict,
      type: "slide",
      visible: open,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout["default"], _objectSpread(_objectSpread({}, rest), {}, {
        role: "alert",
        children: [header ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.header,
          shrink: true,
          children: header
        }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.content,
          children: children
        }), footer ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.footer,
          shrink: true,
          children: footer
        }) : null]
      }))
    });
  }
});

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

/**
 * A ready-to-use drawer component.
 *
 * Usage:
 * ```
 * <Drawer open>
 *   Hello Enact!
 * </Drawer>
 * ```
 *
 * @class Drawer
 * @memberof agate/Drawer
 * @extends agate/Drawer.DrawerBase
 * @mixes agate/Drawer.DrawerDecorator
 * @ui
 * @public
 */
var Drawer = exports.Drawer = DrawerDecorator(DrawerBase);
var _default = exports["default"] = Drawer;