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

export const tState = new State(
  "t",
  [
    "t",
    "tisole",
    "except_tien",
    "_tien",
    "cratie",
    "vingt",
    "tion",
    "ourt",
    "_inct",
    "_spect",
    "_ct",
    "_est",
    "t_final",
    "tmuet",
    "apostrophe"
  ],
  new Map([
    ["*", new Rule(null, SAMPA.FR.consonants["t"], 1)],
    ["$", new Rule(null, SAMPA.specials["#"], 1)],
    ["_ct", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ },
      { direction: "before", regExp: /c/ }
    ]}, SAMPA.FR.consonants["t"], 1)],
    ["_est", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ },
      { direction: "before", regExp: /es/ }
    ]}, SAMPA.FR.consonants["t"], 1)],
    ["_inct", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ },
      { direction: "before", regExp: /inc/ }
    ]}, SAMPA.specials["#"], 1)],
    ["_spect", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ },
      { direction: "before", regExp: /spec/ }
    ]}, SAMPA.specials["#"], 1)],
    ["_tien", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /ien/ }
    ]}, SAMPA.FR.consonants["S"], 1)],
    ["apostrophe", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: apostropheRegExp }
    ]}, SAMPA.FR.consonants["t"], 1)],
    ["cratie", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /ie/ },
      { direction: "before", regExp: /cra/ }
    ]}, SAMPA.FR.consonants["S"], 1)],
    ["except_tien", new Rule({ type: "function", name: "tien_rule" }, SAMPA.FR.consonants["t"], 1)],
    ["ourt", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /(?:a|h|g)our/ }
    ]}, SAMPA.FR.consonants["t"], 1)],
    ["t", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /t/ }
    ]}, SAMPA.FR.consonants["t"], 2)],
    ["t_final", new Rule({ type: "function", name: "t_final_rule" }, SAMPA.FR.consonants["t"], 1)],
    ["tion", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /ion/ }
    ]}, SAMPA.FR.consonants["S"], 1)],
    ["tisole", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /^/ }
    ]}, SAMPA.FR.consonants["t"], 1)],
    ["tmuet", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /s?$/ }
    ]}, SAMPA.specials["#"], 1)],
    ["vingt", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /$/ },
      { direction: "before", regExp: /ving/ }
    ]}, SAMPA.FR.consonants["t"], 1)]
  ])
);
