/** 标准盘口选项的固定显示名（写入 DB，玩家端也会按 code 做 i18n） */

function handicapName(side: 'home' | 'away', line: number, half: boolean) {
  const sideLabel = side === 'home' ? '主队' : '客队';
  const value = side === 'home' ? line : -line;
  const lineText = value > 0 ? `+${value}` : `${value}`;
  return half ? `半场${sideLabel} ${lineText}` : `${sideLabel} ${lineText}`;
}

function ouName(side: 'over' | 'under', line: number, half: boolean) {
  const sideLabel = side === 'over' ? '大' : '小';
  return half ? `半场${sideLabel} ${line}` : `${sideLabel} ${line}`;
}

export function defaultSelectionName(
  code: string,
  opts: { lineValue?: number | null; period?: string },
): string {
  const half = opts.period === 'HT';
  const line = opts.lineValue;

  if (code === 'HOME' && line != null) return handicapName('home', line, half);
  if (code === 'AWAY' && line != null) return handicapName('away', line, half);
  if (code === 'OVER' && line != null) return ouName('over', line, half);
  if (code === 'UNDER' && line != null) return ouName('under', line, half);

  const fixed: Record<string, string> = {
    HOME: '主胜',
    DRAW: '和',
    AWAY: '客胜',
    ODD: '单',
    EVEN: '双',
    OTHER_DRAW: '和局其它比分',
    OTHER_HOME: '主胜其它比分',
    OTHER_AWAY: '客胜其它比分',
  };
  if (fixed[code]) return fixed[code];
  if (code.startsWith('SCORE_')) {
    return code.replace('SCORE_', '').replace('_', '-');
  }
  return code;
}
