"use client"; import { useState } from "react"; import { formatSvnr, requiresAustrianSvnr, svnrErrorMessage, validateSvnr } from "@/lib/svnr"; type SvNummerFieldProps = { value: string; onChange: (value: string) => void; /** Country of the employee's work location — validation applies to Austria only. */ locationCountry: string | null | undefined; /** ISO yyyy-mm-dd; enables the cross-check against the TTMMJJ tail. */ birthDate?: string | null; labelClassName?: string; }; /** * Shared by the hire wizard and the "Daten ändern" panel so both apply the * same rule. Errors are shown only once the field has been left, so the * message does not flash while the ten digits are still being typed. */ export function SvNummerField({ value, onChange, locationCountry, birthDate, labelClassName }: SvNummerFieldProps) { const [touched, setTouched] = useState(false); const applies = requiresAustrianSvnr(locationCountry); const error = applies && value.trim() !== "" ? validateSvnr(value, birthDate) : null; const showError = touched && error !== null; return (
{svnrErrorMessage(error)}
)} {applies && !showError && (10 Ziffern: laufende Nummer, Prüfziffer, Geburtsdatum (TTMMJJ).
)}