"use strict";

exports.__esModule = true;
exports.default = void 0;
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _meetReactComponentOne = require("@alifd/meet-react-component-one");
var _view = _interopRequireDefault(require("../view"));
var _icon = _interopRequireDefault(require("../icon"));
var _modal = _interopRequireDefault(require("../modal"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var Drawer = function (props, ref) {
  var _classNames;
  var _props$prefix = props.prefix,
    prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
    _props$placement = props.placement,
    placement = _props$placement === void 0 ? 'bottom' : _props$placement,
    _props$visible = props.visible,
    visible = _props$visible === void 0 ? false : _props$visible,
    className = props.className,
    height = props.height,
    width = props.width,
    title = props.title,
    _props$titleAlign = props.titleAlign,
    titleAlign = _props$titleAlign === void 0 ? 'left' : _props$titleAlign,
    containerClassName = props.containerClassName,
    _props$closeMode = props.closeMode,
    closeMode = _props$closeMode === void 0 ? ['mask', 'close'] : _props$closeMode,
    _props$onShow = props.onShow,
    onShow = _props$onShow === void 0 ? function () {} : _props$onShow,
    _props$onClose = props.onClose,
    onClose = _props$onClose === void 0 ? function () {} : _props$onClose,
    children = props.children,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style,
    others = (0, _tslib.__rest)(props, ["prefix", "placement", "visible", "className", "height", "width", "title", "titleAlign", "containerClassName", "closeMode", "onShow", "onClose", "children", "style"]);
  var drawerCls = (0, _classnames.default)(prefix + "drawer", className, prefix + "drawer--" + placement);
  var _useState = (0, _react.useState)(visible),
    drawerVisible = _useState[0],
    setVisible = _useState[1];
  var showCloseIcon = Array.isArray(closeMode) && closeMode.indexOf('close') > -1;
  (0, _react.useEffect)(function () {
    if (visible && (_utils.isStrictWechatMiniProgram || _utils.isStrictByteDanceMicroApp)) {
      setTimeout(function () {
        setVisible(true);
      }, 50);
    } else {
      setVisible(visible);
    }
  }, [visible]);
  return /*#__PURE__*/(0, _react.createElement)(_modal.default, _extends({}, others, {
    ref: ref,
    maskClosable: closeMode.indexOf('mask') > -1,
    onClose: onClose,
    visible: drawerVisible,
    placement: placement,
    className: prefix + "drawer-modal",
    containerClassName: drawerCls,
    containerStyle: Object.assign({
      width: width,
      height: height
    }, style)
  }), /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: prefix + "drawer-container"
  }, title ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.Text, {
    className: (0, _classnames.default)(prefix + "drawer-title", (_classNames = {}, _classNames[prefix + "drawer-title--center"] = titleAlign === 'center', _classNames[prefix + "drawer-title--with-icon"] = titleAlign === 'left' && showCloseIcon, _classNames)),
    numberOfLines: 1
  }, title) : null, showCloseIcon ? /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: prefix + "drawer-close",
    onClick: function onClick() {
      onClose('close');
    }
  }, /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    className: prefix + "drawer-close-icon",
    name: "close"
  })) : null, /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: (0, _classnames.default)(prefix + "drawer-body", containerClassName)
  }, children)));
};
Drawer.displayName = 'Drawer';
var _default = /*#__PURE__*/(0, _react.forwardRef)(Drawer);
exports.default = _default;