/**
 * ==========================================================
 * OMSORG BUSINESS CONTROLS PRO
 * Component: DecimalInput
 * Sprint: 0.2.0
 * ==========================================================
 */

import { sanitizeDecimalInput } from "../../utils/germanDecimal";

export default function DecimalInput({
  value,
  onChange,
  placeholder,
  required = false,
  disabled = false,
  id,
}) {
  function handleChange(event) {
    onChange(sanitizeDecimalInput(event.target.value));
  }

  return (
    <input
      type="text"
      inputMode="decimal"
      pattern="[0-9]*[.,]?[0-9]*"
      value={value}
      onChange={handleChange}
      placeholder={placeholder}
      required={required}
      disabled={disabled}
      id={id}
    />
  );
}
