// Accent/punctuation-insensitive folding — kept aligned with the Mac app's
// GroupStore.fold and EjePlayerCodes/lyric_match.fold so search and "other
// recordings" grouping behave like El Eje:
//   drop parentheticals → strip accents → lowercase → JOIN apostrophes →
//   non-alphanumerics to space.
export function fold(s) {
  return (s || "")
    .replace(/\([^)]*\)/g, "")
    .normalize("NFKD")
    .replace(/\p{M}/gu, "")
    .toLowerCase()
    // Join apostrophes instead of splitting on them, so "D'Arienzo" folds to the same
    // token as the bare "Darienzo" — the most common YouTube channel spelling. Without
    // this "juan d arienzo" vs "juan darienzo" never match and the channel's orchestra
    // signal is lost (root cause of ~half the reported mislabels). Also D'Agostino,
    // O'Farrell, etc.
    .replace(/['’‘ʼ`´]/g, "")
    .replace(/[^a-z0-9 ]/g, " ")
    .replace(/\s+/g, " ")
    .trim();
}
