import type { Fields } from "../../../types"

export const findMatch = <T extends string>(
  header: string,
  fields: Fields<T>,
  _autoMapDistance: number,
): T | undefined => {
  const headerLower = header.toLowerCase().trim()

  for (const field of fields) {
    if (field.label.toLowerCase().trim() === headerLower) return field.key as T
    if ((field.key as string).toLowerCase() === headerLower) return field.key as T
    if (field.alternateMatches?.some((alt) => (alt as string).toLowerCase().trim() === headerLower)) return field.key as T
  }

  return undefined
}
