import { intl } from "../../global/global";
export function validTaxDocument(requiredType) {
  const validTypes = ["W9", "W8BENE", "W8BEN"];
  if (validTypes.includes(requiredType))
    return true;
  return false;
}
export const objectIsFull = (obj) => {
  return !Object.keys(obj).find((k) => obj[k] == undefined);
};
export const taxTypeToName = (taxType) => {
  switch (taxType) {
    case "W9":
      return "W-9";
    case "W8BEN":
    case "W8BENE":
      return "W-8";
    default:
      return "";
  }
};
export function validateBillingField(regex, value) {
  const trimmed = value.trim();
  const idx = trimmed.search(regex);
  return idx > -1;
}
export const formatErrorMessage = (fieldName, errorMessage) => {
  return intl.formatMessage({
    id: fieldName,
    defaultMessage: errorMessage,
  }, {
    fieldName,
  });
};
export function getCountryObj({ countryCode, locale, }) {
  // @ts-ignore DisplayNames not in Intl type
  const displayName = new Intl.DisplayNames([locale], {
    type: "region",
  }).of(countryCode);
  return {
    countryCode,
    displayName,
  };
}
