// English strings for Damka (FredyGames translation of src/i18n/ru.ts, MIT like the rest of the project).
// The shape is the one of `ru`, so the rest of the interface does not change.
import type { Strings } from './ru.ts'

/** "1 piece", "2 pieces". */
function plural(n: number, one: string, many: string): string {
  return Math.abs(n) === 1 ? one : many
}

/** "a1", "a1 and b3", "a1, a2 and b3". */
const listOf = new Intl.ListFormat('en', { type: 'conjunction' })

/** "by 1 square", "by 3 squares": a count after "by". */
function bySquares(squares: number): string {
  return `${squares} ${plural(squares, 'square', 'squares')}`
}

export const en: Strings = {
  brand: 'Damka',
  /** Author credit in the page footer. */
  credit: 'Program by Anton Medvedev',
  nav: {
    games: 'Games',
    checkers: 'Checkers',
    giveaway: 'Giveaway',
    corners: 'Corners',
  },
  piece: {
    white: { man: 'white man', king: 'white king' },
    black: { man: 'black man', king: 'black king' },
  },
  emptySquare: 'empty square',
  /** Appended to a square label when it is a legal destination. */
  targetHint: 'move possible',
  /** Appended to the label of the selected piece's square. */
  selectedHint: 'selected',
  /** Corners: the man is still in its own home as the deadline nears. */
  overdueHint: 'has not left home',
  /** "c3, white man" */
  squareLabel: (name: string, content: string) => `${name}, ${content}`,
  moveList: {
    title: 'Moves',
    empty: 'No moves yet',
  },
  controls: {
    undo: 'Undo move',
    redo: 'Redo move',
    toLive: 'Back to the current position',
    flip: 'Flip board',
    newGame: 'New game',
  },
  sound: {
    /** Labels say what the button does, not what the state is. */
    enable: 'Turn sound on',
    disable: 'Turn sound off',
  },
  newGame: {
    title: 'New game',
    opponent: 'Opponent',
    /** Strength of a computer opponent, read out for the dots on its card. */
    strength: (level: number, of: number) => `Strength ${level} of ${of}`,
    yourColor: 'Your color',
    colors: { white: 'White', black: 'Black', random: 'Random' },
    time: 'Time',
    /** Says what the two numbers of a time control actually mean. */
    timeHint:
      'Each player gets this time for the whole game; the increment is added after every move.',
    ownTime: 'Custom',
    ownTimeNote: 'Set it yourself',
    minutes: 'Minutes per game',
    increment: 'Seconds per move',
    /** Two clocks instead of one: a handicap, and the usual reason for it. */
    splitTime: 'Different time for the opponent',
    /** Field labels once the clocks are split; who is who depends on the game. */
    yours: { minutes: 'Minutes for you', increment: 'Seconds per move for you' },
    theirs: {
      minutes: 'Minutes for the opponent',
      increment: 'Seconds per move for the opponent',
    },
    white: {
      minutes: 'Minutes for White',
      increment: 'Seconds per move for White',
    },
    black: {
      minutes: 'Minutes for Black',
      increment: 'Seconds per move for Black',
    },
    badTime: (maxMinutes: number, maxIncrement: number) =>
      `Minutes: from 1 to ${maxMinutes}. Increment: from 0 to ${maxIncrement} seconds.`,
    start: 'Start',
    cancel: 'Cancel',
  },
  /** Time controls, spelled out: no shorthand like "3 + 2" in the dialog. */
  timeControl: {
    none: { bank: 'No clock', increment: 'Take your time' },
    bank: (minutes: number) => `${minutes} min per game`,
    increment: (seconds: number) =>
      seconds === 0 ? 'No increment' : `+${seconds} sec per move`,
  },
  clock: {
    yourTime: 'Your time',
    opponentTime: "Opponent's time",
    /** Hot-seat: neither clock belongs to "you". */
    side: { white: "White's time", black: "Black's time" },
    /** Announced once as the bank passes each threshold. */
    low: (seconds: number) => `${seconds} seconds left`,
    flag: 'Time is up',
  },
  /** Badge shown while an earlier position is displayed. */
  review: 'review',
  /** What the opponent says under its own face, in its own voice. */
  banter: {
    draw: {
      ask: 'Looks like a draw. Agree?',
      agree: 'Agree',
      accept: 'Agree to a draw',
    },
    /** It has a forced win and offers to spare you the rest. */
    resign: {
      ask: "You can't be saved now. Resign?",
      agree: 'I resign',
      accept: 'Resign',
    },
    /** Turns the offer down; it is not made again this game. */
    decline: "Let's play on",
    deadline: (moves: number) =>
      moves === 1
        ? 'Get your men out of home: this is the last move'
        : `Get your men out of home: ${moves} ${plural(moves, 'move', 'moves')} left`,
    remark: {
      feast: 'Tasty!',
      crowned: 'And here comes a king!',
      ouch: 'Ouch, that hurts...',
      praise: 'Good move!',
      stuffed: 'Ugh, you stuffed me...',
      fed: 'Enjoy your meal!',
      burdened: 'A king? What bad luck.',
      unloaded: 'A king is no gift for you!',
      leap: 'What a jump!',
      nimble: 'Nimble hopping!',
    },
  },
  turn: {
    white: "White's move",
    black: "Black's move",
    you: 'you',
    /** Appended to the opponent's name while its move is being searched. */
    thinking: 'is thinking...',
  },
  /** Status line once the game is over. */
  result: {
    white: 'White wins',
    black: 'Black wins',
    draw: 'Draw',
  },
  /** Same result, won on the clock rather than on the board. */
  resultOnTime: {
    white: 'White wins on time',
    black: 'Black wins on time',
  },
  /** Result screen, shown once the game is over. */
  gameOver: {
    /** Under the headline: whose result it is. */
    youWon: 'You won',
    winner: (name: string) => `${name} wins`,
    /** Why the game ended; the headline already says how it stands. */
    reason: {
      time: 'Time is up',
      noPieces: 'No pieces left',
      noMoves: 'No moves left',
      drawRule: 'Fifteen king moves without a capture',
      agreed: 'Draw by agreement',
      resigned: 'You resigned',
      /** The corners endings. */
      corners: {
        finish: "All men are in the opponent's home",
        finishBoth: "Both reached the opponent's home on the same move",
        /** The men the rule caught, by square; the general line if none. */
        blocked: (squares: ReadonlyArray<string>) =>
          squares.length === 0
            ? 'Men were left at home after move 40'
            : squares.length === 1
              ? `The man on ${squares[0]} was left at home after move 40`
              : `The men on ${listOf.format(squares)} were left at home after move 40`,
        blockedBoth: 'Both sides left men at home after move 40',
        limit: "More men in the opponent's home after move 80",
        limitEven: "Equal men in the opponent's home after move 80",
      },
    },
    stats: {
      title: 'The game in numbers',
      moves: 'Moves',
      taken: 'Pieces taken',
      crowned: 'Kings made',
      time: 'Time on moves',
      longest: 'Longest move',
      biggest: 'Biggest capture',
      /** Corners rows: moves that jumped, and the most jumps in one move. */
      leaps: 'Moves with jumps',
      longestLeap: 'Longest chain',
      /** Column heads: the player's own side comes first. */
      you: 'You',
      white: 'White',
      black: 'Black',
      /** Pieces taken in one move, in the "biggest capture" row. */
      inOneMove: (count: number) =>
        `${count} ${plural(count, 'piece', 'pieces')}`,
      /** Jumps in one move, in the "longest chain" row. */
      jumpsInOneMove: (count: number) =>
        `${count} ${plural(count, 'jump', 'jumps')}`,
      none: '—',
    },
    chart: {
      title: 'Material lead',
      white: 'White',
      black: 'Black',
      description:
        "Material lead over the moves of the game: White's is drawn above the axis, Black's below it. A king counts as three men.",
      giveaway: {
        title: 'Lead in the game',
        description:
          "Lead over the moves of the game: in giveaway the side with fewer pieces is ahead. White's lead is drawn above the axis, Black's below it. A king counts as three men.",
        lead: (advantage: number) => en.gameOver.chart.lead(advantage),
      },
      corners: {
        title: 'Lead in the race',
        description:
          "Lead over the moves of the game: by how many squares less a side still has to walk to the opponent's home. White's lead is drawn above the axis, Black's below it.",
        lead: (advantage: number) =>
          advantage === 0
            ? 'Level'
            : advantage > 0
              ? `White is ahead by ${bySquares(advantage)}`
              : `Black is ahead by ${bySquares(-advantage)}`,
        tableCaption: 'Distance left to walk after every ply',
        /** A table cell on its own: "21 squares". */
        left: (squares: number) =>
          `${squares} ${plural(squares, 'square', 'squares')}`,
      },
      /** Reading under the graph; the number leads, the move follows. */
      lead: (advantage: number) =>
        advantage === 0
          ? 'Material is level'
          : advantage > 0
            ? `+${advantage} for White`
            : `+${-advantage} for Black`,
      afterMove: (move: number) =>
        move === 0 ? 'start of the game' : `after move ${move}`,
      /** Unit of the horizontal axis, at its right end. */
      axis: 'move',
      tableCaption: 'Material after every ply',
      ply: 'Ply',
      /** "9 men, 2 kings" */
      pieces: (men: number, kings: number) => {
        const checkers = `${men} ${plural(men, 'man', 'men')}`
        if (kings === 0) return checkers
        return `${checkers}, ${kings} ${plural(kings, 'king', 'kings')}`
      },
    },
    /** Reopens the result screen from the status line. */
    show: 'Game result',
    close: 'Close',
    newGame: 'New game',
  },
  opponents: {
    kitten: { name: 'Kitten', tagline: 'Goes wherever its eyes lead' },
    hare: { name: 'Hare', tagline: 'Moves fast, thinks later' },
    fox: { name: 'Fox', tagline: 'Cunning, sets traps' },
    owl: { name: 'Owl', tagline: 'In no hurry and notices everything' },
    raven: { name: 'Raven', tagline: 'Remembers all your mistakes' },
    friend: { name: 'Friend beside you', tagline: 'Two players, one device' },
  },
}
