"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DrawerDecorator = exports.DrawerBase = exports.Drawer = exports["default"] = void 0;

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

var _compose = _interopRequireDefault(require("ramda/src/compose"));

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 _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _PopupState = _interopRequireDefault(require("../Popup/PopupState"));

var _DrawerModule = _interopRequireDefault(require("./Drawer.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; }

/**
 * A drawer component, without behaviors.
 *
 * @class DrawerBase
 * @memberof agate/Drawer
 * @ui
 * @public
 */
var DrawerBase = (0, _kind["default"])({
  name: 'Drawer',
  propTypes: {
    css: _propTypes["default"].object,
    footer: _propTypes["default"].node,
    header: _propTypes["default"].node,
    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.
    // onClose: PropTypes.func,
    onHide: _propTypes["default"].func,
    open: _propTypes["default"].bool
  },
  defaultProps: {
    noAnimation: false,
    open: false,
    orientation: 'vertical'
  },
  styles: {
    css: _DrawerModule["default"],
    className: 'drawer'
  },
  render: function render(_ref) {
    var footer = _ref.footer,
        children = _ref.children,
        css = _ref.css,
        noAnimation = _ref.noAnimation,
        onHide = _ref.onHide,
        open = _ref.open,
        header = _ref.header,
        rest = _objectWithoutProperties(_ref, ["footer", "children", "css", "noAnimation", "onHide", "open", "header"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Transition["default"], {
      noAnimation: noAnimation,
      visible: open,
      direction: "left",
      duration: "short",
      type: "slide",
      className: css.drawerTransitionContainer,
      onHide: onHide,
      css: css,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout["default"], _objectSpread(_objectSpread({
        role: "alert"
      }, rest), {}, {
        children: [header ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          shrink: true,
          className: css.header,
          children: header
        }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.content,
          children: children
        }), footer ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          shrink: true,
          className: css.footer,
          children: footer
        }) : null]
      }))
    });
  }
});
/**
 * Applies Agate specific behaviors to [DrawerBase]{@link agate/Drawer.DrawerBase}.
 *
 * @hoc
 * @memberof agate/Drawer
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

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

exports.DrawerDecorator = DrawerDecorator;
var Drawer = DrawerDecorator(DrawerBase);
exports.Drawer = Drawer;
var _default = Drawer;
exports["default"] = _default;