import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread";

/**
 * Web Input Component
 *
 */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Input from '../input/Input';
import MaskedInput from 'react-text-mask'; // https://github.com/text-mask/text-mask
// import InputMask from 'react-input-mask' // https://github.com/sanniassin/react-input-mask
// import { registerElement } from '../../shared/component-helper'

const renderProps = {
  on_change: null,
  on_submit: null,
  on_focus: null,
  on_blur: null,
  on_submit_focus: null,
  on_submit_blur: null
};
export const propTypes = {
  mask: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
  show_mask: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
  guide: PropTypes.bool,
  pipe: PropTypes.func,
  keep_char_positions: PropTypes.bool,
  placeholder_char: PropTypes.string
};
export const defaultProps = _objectSpread({
  mask: [],
  show_mask: false,
  guide: true,
  pipe: null,
  keep_char_positions: false,
  placeholder_char: '_'
}, renderProps);
export default class InputMasked extends PureComponent {
  // static tagName = 'dnb-input-masked'
  // static enableWebComponent() {
  //   registerElement(InputMasked.tagName, InputMasked, defaultProps)
  // }
  constructor(props) {
    super(props);
  }

  render() {
    const _this$props = this.props,
          {
      mask,
      show_mask,
      guide,
      pipe,
      keep_char_positions,
      placeholder_char
    } = _this$props,
          props = _objectWithoutProperties(_this$props, ["mask", "show_mask", "guide", "pipe", "keep_char_positions", "placeholder_char"]);

    if (!props.inputElement) props.inputElement = (params, innerRef) => {
      params = _objectSpread({}, params, {
        mask,
        guide,
        pipe,
        showMask: Boolean(show_mask),
        keepCharPositions: keep_char_positions,
        placeholderChar: placeholder_char
      });
      return React.createElement(MaskedInput, _extends({
        ref: innerRef
      }, params));
    };
    return React.createElement(Input, _extends({
      className: "dnb-input-masked"
    }, props));
  }

}

_defineProperty(InputMasked, "defaultProps", defaultProps);

_defineProperty(InputMasked, "renderProps", renderProps);

InputMasked.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};