'use strict';

exports.__esModule = true;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _instance2 = _interopRequireDefault(_instance);

var _reactDom = require('react-dom');

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

var IndexBar = (0, _react.forwardRef)(function (_ref, ref) {
  var portal = _ref.portal,
      overflowContainer = _ref.overflowContainer,
      _ref$indexs = _ref.indexs,
      indexs = _ref$indexs === undefined ? ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'G', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] : _ref$indexs,
      others = _objectWithoutProperties(_ref, ['portal', 'overflowContainer', 'indexs']);

  var refEl = (0, _react.useRef)(null);
  var refElTip = (0, _react.useRef)(null);
  (0, _react.useImperativeHandle)(ref, function () {
    return refEl.current;
  });
  var instance = (0, _react.useRef)(null);

  (0, _react.useEffect)(function () {
    instance.current = new _instance2.default({
      overflowContainer: overflowContainer || refEl.current.parentNode,
      parent: portal || refEl.current.parentNode,
      bar: refEl.current,
      tooltip: refElTip.current
    });
  }, []); // eslint-disable-line

  var DOM = _react2.default.createElement(
    _react.Fragment,
    null,
    _react2.default.createElement(
      'div',
      _extends({ ref: refEl }, others, { className: 'indexbar' + (others.className ? ' ' + others.className : '') }),
      indexs.map(function (index, i) {
        return _react2.default.createElement(
          'span',
          { className: 'indexbar-button', key: 'btn' + i },
          index
        );
      })
    ),
    _react2.default.createElement('div', { ref: refElTip, className: 'indexbar-tooltip' })
  );
  if (portal) {
    return (0, _reactDom.createPortal)(DOM, portal);
  }
  return DOM;
});

exports.default = IndexBar;
module.exports = exports['default'];