// Bonus-square label modes (a client setting, separate from the theme). The board
// renders these locally — premiums are not on the wire. Default is "beginner".

import type { Premium } from './premiums';
import type { Locale } from './i18n/catalog';

export type BoardLabelMode = 'beginner' | 'classic' | 'none';

export type BonusLabel =
  | { kind: 'single'; text: string }
  | { kind: 'split'; top: string; bottom: string }
  | null;

function multiplier(p: Premium): number {
  return p === 'TW' || p === 'TL' ? 3 : 2;
}

function isWord(p: Premium): boolean {
  return p === 'TW' || p === 'DW';
}

/**
 * bonusLabel returns how a premium square is labelled: `classic` "3W"/"3С", `beginner`
 * a split "3×" / "word" (localized), or nothing.
 */
export function bonusLabel(mode: BoardLabelMode, p: Premium, locale: Locale): BonusLabel {
  if (mode === 'none' || p === '') return null;
  const n = multiplier(p);
  const word = isWord(p);
  if (mode === 'classic') {
    const tag = locale === 'ru' ? (word ? 'С' : 'Б') : word ? 'W' : 'L';
    return { kind: 'single', text: `${n}${tag}` };
  }
  const bottom = locale === 'ru' ? (word ? 'слово' : 'буква') : word ? 'word' : 'letter';
  return { kind: 'split', top: `${n}×`, bottom };
}
