// Truck plate utilities — must support every EU format:
//   FR  AB-123-CD          DE  M-AB 1234            RO  CT-49-AAA
//   IT  AB 123 CD          ES  1234 ABC             PT  AA-12-BB
//   LT  ABC 123            BE  1-ABC-123            NL  AB-123-C
//   PL  WX 12345           etc.
//
// We deliberately don't enforce a regex: drivers can also enter trailer
// numbers, fleet IDs, etc. We just clean the input and uppercase it.
const PLATE_ALLOWED = /[^A-Z0-9\- ]/g; // strip everything else
export const PLATE_MAX_LEN = 12;

export function cleanPlate(raw) {
    if (!raw) return '';
    return raw
        .toUpperCase()
        .replace(PLATE_ALLOWED, '')
        .replace(/\s{2,}/g, ' ')
        .replace(/-{2,}/g, '-')
        .slice(0, PLATE_MAX_LEN);
}
