"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MaskedTextInput = void 0;

var _react = _interopRequireWildcard(require("react"));

var _react2 = _interopRequireDefault(require("cleave.js/react"));

require("cleave.js/dist/addons/cleave-phone.ca");

require("cleave.js/dist/addons/cleave-phone.gb");

require("cleave.js/dist/addons/cleave-phone.us");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _maskedTextInput = require("./masked-text-input.css-rules");

var _branding = require("../../../mixins/branding");

var _typography = require("../../../mixins/typography");

var _primitives = require("../../../primitives");

var _focus = require("../../../mixins/focus");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var StyledWrapper = (0, _styledComponents["default"])(_primitives.Box).withConfig({
  displayName: "StyledWrapper",
  componentId: "sc-1s4l3kt-0"
})(["> input{height:", ";color:", ";font-family:", ";font-size:", ";font-weight:", ";padding-bottom:2px;padding-left:", ";border-radius:6px;border:", ";border-color:", ";background-image:", ";background-repeat:no-repeat;background-position:", ";width:100%;&:focus{border-color:", ";outline:none;}&&::placeholder{color:", ";opacity:1;}&&::-ms-input-placeholder{color:", ";}&&:-ms-input-placeholder{color:", ";}", "}"], _maskedTextInput.getInputHeight, _maskedTextInput.getTextColor, _typography.getFontFamily, _typography.getFontSize, _typography.getFontWeight, _maskedTextInput.getInputLeftPadding, _maskedTextInput.getInputBorder, (0, _branding.getPaletteColor)('greyscale-light'), _maskedTextInput.getIconDataUri, _maskedTextInput.getInputIconPosition, (0, _branding.getPaletteColor)('greyscale-medium'), _maskedTextInput.getPlaceholderColor, _maskedTextInput.getPlaceholderColor, _maskedTextInput.getPlaceholderColor, (0, _focus.getBaseFocusState)({
  hoverTransition: false,
  activeTransition: false,
  pointerCursor: false
}));

var MaskedTextInput = function MaskedTextInput(props) {
  var onRef = props.onRef,
      focusOnMount = props.focusOnMount,
      onChange = props.onChange,
      large = props.large,
      iconType = props.iconType,
      iconPosition = props.iconPosition,
      error = props.error,
      className = props.className,
      _props$hideBorder = props.hideBorder,
      hideBorder = _props$hideBorder === void 0 ? false : _props$hideBorder;
  var textRef = (0, _react.useRef)(null);
  var registerChild = (0, _react.useCallback)(function (ref) {
    if (onRef != null) {
      onRef(ref);
    }

    textRef.current = ref;
  }, [onRef, textRef]);
  var focusChild = (0, _react.useCallback)(function () {
    if (textRef.current != null) {
      textRef.current.focus();
    }
  }, [textRef]);
  (0, _react.useEffect)(function () {
    if (focusOnMount) {
      focusChild();
    }
  });
  var handleChange = (0, _react.useCallback)(function (event) {
    onChange(event.target.value, event);
  }, [onChange]);
  return /*#__PURE__*/_react["default"].createElement(StyledWrapper, {
    className: className,
    fontSize: large ? 'f3' : 'f1',
    bold: large,
    iconType: iconType,
    iconPosition: iconPosition,
    error: error,
    large: large,
    onFocus: props.onFocus,
    onBlur: props.onBlur,
    hideBorder: hideBorder
  }, /*#__PURE__*/_react["default"].createElement(_react2["default"], {
    id: props.id,
    options: props.options,
    htmlRef: registerChild,
    type: props.type || 'text',
    placeholder: props.placeholder || '',
    disabled: props.disabled,
    value: props.value || '',
    onFocus: props.onFocus,
    onBlur: props.onBlur,
    onChange: handleChange,
    inputMode: props.inputMode
  }));
};

exports.MaskedTextInput = MaskedTextInput;
MaskedTextInput.displayName = 'MaskedTextInput';