/** Mínimo 3 kg; 3.1→3.5, 3.6→4, 4.1→4.5, 4.6→5, etc. */
export const LAUNDRY_WEIGHT_MIN_KG = 3;

/**
 * @param {number|string|null|undefined} raw
 * @returns {number}
 */
export function roundLaundryWeightKg(raw) {
  const n = Number(raw);
  if (!Number.isFinite(n) || n <= 0) {
    return LAUNDRY_WEIGHT_MIN_KG;
  }

  let w = Math.max(LAUNDRY_WEIGHT_MIN_KG, n);
  const intPart = Math.floor(w);
  const frac = Math.round((w - intPart) * 10000) / 10000;

  if (frac <= 0.00001) {
    return intPart;
  }
  if (frac <= 0.5) {
    return intPart + 0.5;
  }
  return intPart + 1;
}
