"use strict";

exports.__esModule = true;
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Page = _interopRequireDefault(require("./../Page"));

var _instance = _interopRequireDefault(require("./instance.js"));

var _excluded = ["drag", "transition", "lSide", "lSideAttribute", "rSide", "rSideAttribute", "children"];

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

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; }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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; }

var PagePull = /*#__PURE__*/function (_Component) {
  _inheritsLoose(PagePull, _Component);

  function PagePull(_props, context) {
    var _this;

    _this = _Component.call(this, _props, context) || this;

    _defineProperty(_assertThisInitialized(_this), "componentDidMount", function () {
      var _this$props = _this.props,
          transition = _this$props.transition,
          _this$props$lSideAttr = _this$props.lSideAttribute,
          lSideAttribute = _this$props$lSideAttr === void 0 ? {} : _this$props$lSideAttr,
          _this$props$rSideAttr = _this$props.rSideAttribute,
          rSideAttribute = _this$props$rSideAttr === void 0 ? {} : _this$props$rSideAttr;
      var instance = new _instance["default"](_this.$el, {
        drag: true,
        transition: transition || 'push',
        onShowedLeft: lSideAttribute.onShowed,
        onShowedRight: rSideAttribute.onShowed
      });
      _this.instance = instance;
    });

    _defineProperty(_assertThisInitialized(_this), "filterProps", function (props) {
      if (!props) return props;
      var propsed = {};

      for (var n in props) {
        if (n !== 'onShowed') {
          propsed[n] = props[n];
        }
      }

      return propsed;
    });

    return _this;
  }

  var _proto = PagePull.prototype;

  _proto.render = function render() {
    var _this2 = this;

    var _this$props2 = this.props,
        drag = _this$props2.drag,
        transition = _this$props2.transition,
        lSide = _this$props2.lSide,
        _this$props2$lSideAtt = _this$props2.lSideAttribute,
        lSideAttribute = _this$props2$lSideAtt === void 0 ? {} : _this$props2$lSideAtt,
        rSide = _this$props2.rSide,
        _this$props2$rSideAtt = _this$props2.rSideAttribute,
        rSideAttribute = _this$props2$rSideAtt === void 0 ? {} : _this$props2$rSideAtt,
        children = _this$props2.children,
        others = _objectWithoutPropertiesLoose(_this$props2, _excluded); // 剔除掉onShowed事件, 因为在instance时已经回调了


    lSideAttribute = this.filterProps(lSideAttribute);
    rSideAttribute = this.filterProps(rSideAttribute);
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "page-pull",
      ref: function ref(el) {
        _this2.$el = el;
      }
    }, /*#__PURE__*/_react["default"].createElement(_Page["default"], others, children, /*#__PURE__*/_react["default"].createElement("div", {
      className: "mask"
    })), lSide && /*#__PURE__*/_react["default"].createElement("aside", _extends({
      ref: function ref(el) {
        _this2.$lSide = el;
      }
    }, lSideAttribute, {
      className: "page-side-left" + (lSideAttribute.className ? ' ' + lSideAttribute.className : ''),
      "data-transition": transition
    }), lSide), rSide && /*#__PURE__*/_react["default"].createElement("aside", _extends({
      ref: function ref(el) {
        _this2.$rSide = el;
      }
    }, lSideAttribute, {
      className: "page-side-right" + (lSideAttribute.className ? ' ' + lSideAttribute.className : ''),
      "data-transition": transition
    }), rSide));
  };

  return PagePull;
}(_react.Component);

exports["default"] = PagePull;

_defineProperty(PagePull, "defaultProps", {
  drag: true,
  transition: 'push'
});

PagePull.propTypes = process.env.NODE_ENV !== "production" ? {
  // Side 侧边栏
  drag: _propTypes["default"].bool,
  transition: _propTypes["default"].string,
  // 过渡动画, push | reveal
  lSide: _propTypes["default"].node,
  // 左侧边栏
  lSideAttribute: _propTypes["default"].object,
  rSide: _propTypes["default"].node,
  // 右侧边栏
  rSideAttribute: _propTypes["default"].object,
  // Page
  children: _propTypes["default"].node
} : {};
module.exports = exports.default;