import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef, useState, useImperativeHandle } from 'react';
import maskInputCompose from '@salutejs/react-maskinput';

var _excluded = ["mask", "maskFormat"];
var defaultFormatChars = [{
  str: '*',
  regexp: /./
}, {
  str: '0',
  regexp: /[0-9]/
}, {
  str: 'a',
  regexp: /[a-zA-Z]/
}, {
  str: 'я',
  regexp: /[а-яА-ЯёЁ]/
}];
var composeMask = function composeMask(InputComponent) {
  var MaskedInput = maskInputCompose(InputComponent);
  return /*#__PURE__*/forwardRef(function (_ref, outerRef) {
    var mask = _ref.mask,
      _ref$maskFormat = _ref.maskFormat,
      maskFormat = _ref$maskFormat === void 0 ? defaultFormatChars : _ref$maskFormat,
      rest = _objectWithoutProperties(_ref, _excluded);
    // TODO: replace inside react-maskinput 'getReference' on 'forwardRef'
    var _useState = useState(null),
      _useState2 = _slicedToArray(_useState, 2),
      ref = _useState2[0],
      setRef = _useState2[1];
    useImperativeHandle(outerRef, function () {
      return ref;
    }, [ref]);
    if (!mask) {
      return /*#__PURE__*/React__default.createElement(InputComponent, _extends({
        ref: setRef
      }, rest));
    }
    return /*#__PURE__*/React__default.createElement(MaskedInput, _extends({
      getReference: setRef,
      mask: mask,
      maskFormat: maskFormat
    }, rest));
  });
};

export { composeMask };
