"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getMaskOptions = exports.getInputModeType = exports.getDomType = void 0;
var NO_MASK = {
  delimiter: ''
};
var DATE_MASK = {
  date: true,
  datePattern: ['d', 'm', 'Y'],
  delimiter: ' / '
};
var CURRENCY_MASK = {
  numeral: true,
  rawValueTrimPrefix: true,
  noImmediatePrefix: true
};
var GROUPED_CODE_MASK = {
  blocks: [4, 4, 4, 4],
  uppercase: true
};
var NUMBER_MASK = {
  numeral: true,
  numericOnly: true
};
var TYPE_TO_MASK_MAP = {
  date: DATE_MASK,
  email: NO_MASK,
  number: NUMBER_MASK,
  text: NO_MASK,
  password: NO_MASK,
  currency: CURRENCY_MASK,
  grouped_code: GROUPED_CODE_MASK,
  custom: null,
  search: NO_MASK
}; // Maps our custom type values to the right value for the DOM input type attribute.

var getDomType = function getDomType(type, revealText) {
  var _map$type;

  if (type == null) {
    return 'text';
  }

  var map = {
    password: revealText ? 'text' : 'password',
    // Disable Firefox's built-in date picker for parity with Chrome, Safari.
    // Firefox also puts a non-changeable placeholder when you use type date
    // which interferes with the floating label styling.
    date: 'text',
    email: 'text',
    number: 'text',
    search: 'search',
    text: 'text',
    custom: 'text',
    currency: 'text',
    grouped_code: 'text'
  };
  return (_map$type = map[type]) !== null && _map$type !== void 0 ? _map$type : 'text';
}; // Maps our custom type values to the right value for the inputMode attribute.


exports.getDomType = getDomType;

var getInputModeType = function getInputModeType(type) {
  var _map$type2;

  if (type == null) {
    return 'text';
  }

  var map = {
    password: 'text',
    date: 'numeric',
    email: 'email',
    number: 'numeric',
    search: 'search',
    text: 'text',
    custom: 'text',
    currency: 'decimal',
    grouped_code: 'text'
  };
  return (_map$type2 = map[type]) !== null && _map$type2 !== void 0 ? _map$type2 : 'text';
}; // Maps our custom type values to an appropriate CleaveJS mask.


exports.getInputModeType = getInputModeType;

var getMaskOptions = function getMaskOptions(type, currencyCode, decimalPlaces, customMaskOptions) {
  var _ref, _TYPE_TO_MASK_MAP$typ;

  if (type != null && type !== 'custom' && customMaskOptions != null) {
    // eslint-disable-next-line no-console
    console.warn("TextInput: ignoring attempt to use customMaskOptions with type=".concat(type, ". You must set type=\"custom\" for this."));
  }

  if (type !== 'currency' && currencyCode) {
    // eslint-disable-next-line no-console
    console.warn("TextInput: ignoring attempt to use currencyCode=".concat(currencyCode, " with type=").concat(type, ". This prop only applies to type=\"currency\"."));
  }

  if (type !== 'currency' && type !== 'number' && decimalPlaces != null) {
    // eslint-disable-next-line no-console
    console.warn("TextInput: ignoring attempt to use decimalPlaces=".concat(decimalPlaces, " with type=").concat(type, ". This prop only applies to type=\"currency\" and type=\"number\"."));
  }

  var mask = (_ref = (_TYPE_TO_MASK_MAP$typ = TYPE_TO_MASK_MAP[type]) !== null && _TYPE_TO_MASK_MAP$typ !== void 0 ? _TYPE_TO_MASK_MAP$typ : customMaskOptions) !== null && _ref !== void 0 ? _ref : NO_MASK;

  if (type === 'currency') {
    mask.prefix = currencyCode === 'GBP' ? '£' : '$';
    mask.numeralDecimalScale = decimalPlaces !== null && decimalPlaces !== void 0 ? decimalPlaces : 2;
  }

  if (type === 'number') {
    mask.numeralDecimalScale = decimalPlaces !== null && decimalPlaces !== void 0 ? decimalPlaces : Infinity;
  }

  return mask;
};

exports.getMaskOptions = getMaskOptions;