var _excluded = ["params", "wrapperAttribute", "paginationAttribute", "prevAttribute", "nextAttribute", "children", "containerChildren"];

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

// require (PrototypeArray.js), 使用了equals
import React, { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
import Instance from './instance';
var Swiper = forwardRef(function (_ref, ref) {
  var _ref$params = _ref.params,
      params = _ref$params === void 0 ? {} : _ref$params,
      _ref$wrapperAttribute = _ref.wrapperAttribute,
      wrapperAttribute = _ref$wrapperAttribute === void 0 ? {} : _ref$wrapperAttribute,
      _ref$paginationAttrib = _ref.paginationAttribute,
      paginationAttribute = _ref$paginationAttrib === void 0 ? {} : _ref$paginationAttrib,
      _ref$prevAttribute = _ref.prevAttribute,
      prevAttribute = _ref$prevAttribute === void 0 ? {} : _ref$prevAttribute,
      _ref$nextAttribute = _ref.nextAttribute,
      nextAttribute = _ref$nextAttribute === void 0 ? {} : _ref$nextAttribute,
      children = _ref.children,
      containerChildren = _ref.containerChildren,
      others = _objectWithoutPropertiesLoose(_ref, _excluded);

  var refEl = useRef(null);
  useImperativeHandle(ref, function () {
    return refEl.current;
  });
  var instance = useRef(null);
  useEffect(function () {
    if (!refEl || !refEl.current) return;
    instance.current = new Instance(refEl.current, _extends({}, params));
    refEl.current.instance = instance;
  }, []); // eslint-disable-line
  // 更新句柄, 防止synchronization模式, 每次组件在render的时候都生成上次render的state、function、effects

  if (instance.current) {
    instance.current.update();

    if (params.on) {
      for (var eventName in params.on) {
        instance.current.off(eventName);
        instance.current.on(eventName, params.on[eventName]);
      }
    }
  }

  return /*#__PURE__*/React.createElement("div", _extends({
    ref: refEl
  }, others, {
    className: "swiper-container" + (others.className ? ' ' + others.className : '')
  }), /*#__PURE__*/React.createElement("div", _extends({}, wrapperAttribute, {
    className: "swiper-wrapper" + (wrapperAttribute.className ? ' ' + wrapperAttribute.className : '')
  }), children), params.pagination && /*#__PURE__*/React.createElement("div", _extends({}, paginationAttribute, {
    className: "swiper-pagination" + (paginationAttribute.className ? ' ' + paginationAttribute.className : '')
  })), params.navigation && params.navigation.prevEl && /*#__PURE__*/React.createElement("div", _extends({}, prevAttribute, {
    className: "swiper-button-prev" + (prevAttribute.className ? ' ' + prevAttribute.className : '')
  })), params.navigation && params.navigation.nextEl && /*#__PURE__*/React.createElement("div", _extends({}, nextAttribute, {
    className: "swiper-button-next" + (nextAttribute.className ? ' ' + nextAttribute.className : '')
  })), containerChildren);
});
export default Swiper;