// src/utils/normalize.js
export function normalizePlayerName(name) {
  if (typeof name !== 'string' || !name.trim()) return '';
  const upper = name.trim().toUpperCase();

  // Your original logic (country.store.suffix patterns)
  const match = upper.match(/^([A-Z]{2})\.?(?:(\d{1,6})\.?)?(?:OFFLINE|AE|AERIE)?\.?(\d{1,6})?\.?(OFFLINE|AE|AERIE)?$/i);
  if (match) {
    const country = match[1];
    let store = match[2] || match[3] || '';
    const suffixRaw = match[4] || '';
    if (!store) return name.trim();

    const paddedStore = store.padStart(6, '0');
    let suffix = '';
    if (suffixRaw === 'OFFLINE') suffix = 'MSCOFF';
    else if (suffixRaw === 'AE' || suffixRaw === 'AERIE') suffix = `MSC${suffixRaw}`;

    return `${country}${paddedStore}${suffix}`;
  }

  return name.trim();
}