/** Compute Wordle feedback pattern for a guess against the target word. */
export function getFeedback(target: string, guess: string): string {
  const tu = target.toLowerCase(), gu = guess.toLowerCase();
  const counts: Record<string, number> = {};
  for (const ch of tu) counts[ch] = (counts[ch] ?? 0) + 1;
  const r: string[] = Array(5).fill('x');
  for (let i = 0; i < 5; i++) { if (gu[i] === tu[i]) { r[i] = 'g'; counts[gu[i]]--; } }
  for (let i = 0; i < 5; i++) { if (r[i] === 'g') continue; if ((counts[gu[i]] ?? 0) > 0) { r[i] = 'y'; counts[gu[i]]--; } }
  return r.join('');
}

export function matchesFeedback(candidate: string, guess: string, feedback: string): boolean {
  return getFeedback(candidate, guess) === feedback;
}
