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 _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

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

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

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

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import InputMask from 'react-input-mask';
import Input from './input.js';
import { Input as StyledInput } from './styled-components.js';

function MaskOverride(props) {
  return React.createElement(InputMask, props, function (_ref) {
    var startEnhancer = _ref.startEnhancer,
        endEnhancer = _ref.endEnhancer,
        error = _ref.error,
        maskProps = _objectWithoutProperties(_ref, ["startEnhancer", "endEnhancer", "error"]);

    return React.createElement(StyledInput, maskProps);
  });
}

export default function MaskedInput(props) {
  var _props$overrides = props.overrides,
      overrides = _props$overrides === void 0 ? {} : _props$overrides;

  var nextOverrides = _objectSpread({
    // seems similar to the issue described in overrides.js
    // https://github.com/uber-web/baseui/blob/master/src/helpers/overrides.js#L32
    // eslint-disable-next-line flowtype/no-weak-types
    Input: {
      component: MaskOverride,
      props: props
    }
  }, overrides);

  return React.createElement(Input, _extends({}, props, {
    overrides: nextOverrides
  }));
}
MaskedInput.defaultProps = _objectSpread({}, Input.defaultProps, {
  maskChar: ' '
});