const noComma = {
  name: "noComma",
  validate: (_, key) => !key.includes(","),
  sanitize: (value) => value.replaceAll(",", "")
};
const noLeadingDot = {
  name: "noLeadingDot",
  validate: (input, key) => !(key === "." && input.selectionStart === 0),
  sanitize: (value) => value.replace(/^\.+/, "")
};
const onlyOneDot = {
  name: "onlyOneDot",
  validate: (input, key) => !(key === "." && input.value.split(".").length > 1),
  sanitize: (value) => {
    const [integer, ...decimals] = value.split(".");
    return decimals.length > 0 ? `${integer}.${decimals.join("")}` : integer;
  }
};
const onlyNumbersAndDot = {
  name: "onlyNumbersAndDot",
  validate: (_, key) => key === "" || /^[0-9.]$/.test(key),
  sanitize: (value) => value.replace(/[^0-9.]/g, "")
};
const noDecimal = {
  name: "noDecimal",
  validate: (_, key) => key !== ".",
  sanitize: (value) => value.replaceAll(".", "")
};
const RULES_MAP = {
  noComma,
  noLeadingDot,
  onlyOneDot,
  onlyNumbersAndDot,
  noDecimal
};

export { RULES_MAP, noComma, noDecimal, noLeadingDot, onlyNumbersAndDot, onlyOneDot };
