import { State, Rule } from "../../state-machine";
import { SAMPA } from "../../sampa";
import { apostropheRegExp } from "../apostrophes";

export const nState = new State(
  "n",
  [
    "n", "ing", "ment", "urent", "irent", "erent", "ent", "nisole", "apostrophe"
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["n"], 1)], // fallback

    ["n", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /n/ }
    ]}, SAMPA.FR.consonants["n"], 2)],

    ["apostrophe", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: apostropheRegExp }
    ]}, SAMPA.FR.consonants["n"], 1)],

    ["ent", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t$/ },
      { direction: "before", regExp: /e/ }
    ]}, SAMPA.specials["#"], 2)],

    ["erent", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t$/ },
      { direction: "before", regExp: /ère/ }
    ]}, SAMPA.specials["#"], 2)],

    ["ing", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /g$/ },
      { direction: "before", regExp: /i/ }
    ]}, SAMPA.FR.semiVowels["J"], 2)], // SAMPA "J" = g~

    ["irent", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t$/ },
      { direction: "before", regExp: /ire/ }
    ]}, SAMPA.specials["#"], 2)],

    ["ment", new Rule({ type: "function", name: "mer_rule" }, SAMPA.specials["#"], 2)],

    ["nisole", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /^/ }
    ]}, SAMPA.FR.consonants["n"], 1)],

    ["urent", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t$/ },
      { direction: "before", regExp: /ure/ }
    ]}, SAMPA.specials["#"], 2)]
  ])
);
