'use strict';

exports.__esModule = true;
exports.default = undefined;

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

var _class, _temp, _initialiseProps;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Page = require('./../Page');

var _Page2 = _interopRequireDefault(_Page);

var _instance = require('./instance.js');

var _instance2 = _interopRequireDefault(_instance);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var PagePull = (_temp = _class = function (_Component) {
  _inherits(PagePull, _Component);

  function PagePull(props, context) {
    _classCallCheck(this, PagePull);

    var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));

    _initialiseProps.call(_this);

    return _this;
  }
  // 过滤已经回调的属性


  PagePull.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        drag = _props.drag,
        transition = _props.transition,
        lSide = _props.lSide,
        _props$lSideAttribute = _props.lSideAttribute,
        lSideAttribute = _props$lSideAttribute === undefined ? {} : _props$lSideAttribute,
        rSide = _props.rSide,
        _props$rSideAttribute = _props.rSideAttribute,
        rSideAttribute = _props$rSideAttribute === undefined ? {} : _props$rSideAttribute,
        children = _props.children,
        others = _objectWithoutProperties(_props, ['drag', 'transition', 'lSide', 'lSideAttribute', 'rSide', 'rSideAttribute', 'children']);

    // 剔除掉onShowed事件, 因为在instance时已经回调了


    lSideAttribute = this.filterProps(lSideAttribute);
    rSideAttribute = this.filterProps(rSideAttribute);

    return _react2.default.createElement(
      'div',
      { className: 'page-pull', ref: function ref(el) {
          _this2.$el = el;
        } },
      _react2.default.createElement(
        _Page2.default,
        others,
        children,
        _react2.default.createElement('div', { className: 'mask' })
      ),
      lSide && _react2.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 && _react2.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), _class.defaultProps = {
  drag: true,
  transition: 'push'
}, _initialiseProps = function _initialiseProps() {
  var _this3 = this;

  this.componentDidMount = function () {
    var _props2 = _this3.props,
        transition = _props2.transition,
        _props2$lSideAttribut = _props2.lSideAttribute,
        lSideAttribute = _props2$lSideAttribut === undefined ? {} : _props2$lSideAttribut,
        _props2$rSideAttribut = _props2.rSideAttribute,
        rSideAttribute = _props2$rSideAttribut === undefined ? {} : _props2$rSideAttribut;

    var instance = new _instance2.default(_this3.$el, {
      drag: true,
      transition: transition || 'push',
      onShowedLeft: lSideAttribute.onShowed,
      onShowedRight: rSideAttribute.onShowed
    });
    _this3.instance = instance;
  };

  this.filterProps = function (props) {
    if (!props) return props;
    var propsed = {};
    for (var n in props) {
      if (n !== 'onShowed') {
        propsed[n] = props[n];
      }
    }
    return propsed;
  };
}, _temp);
exports.default = PagePull;
PagePull.propTypes = process.env.NODE_ENV !== "production" ? {
  // Side 侧边栏
  drag: _propTypes2.default.bool,
  transition: _propTypes2.default.string, // 过渡动画, push | reveal
  lSide: _propTypes2.default.node, // 左侧边栏
  lSideAttribute: _propTypes2.default.object,
  rSide: _propTypes2.default.node, // 右侧边栏
  rSideAttribute: _propTypes2.default.object,
  // Page
  children: _propTypes2.default.node
} : {};
module.exports = exports['default'];