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

export const dState = new State(
  "d",
  [
    "d",
    "aujourdhui",
    "isolate_d",
    "except",
    "mute_d",
    "apostrophe",
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["d"], 1)],
    [
      "apostrophe",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: apostropheRegExp }] },
        SAMPA.FR.consonants["d"],
        1
      ),
    ],
    [
      "aujourdhui",
      new Rule(
        { type: "regExp", regExps: [{ direction: "before", regExp: /aujour/ }] },
        SAMPA.FR.consonants["d"],
        1
      ),
    ],
    [
      "d",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /d/ }] },
        SAMPA.FR.consonants["d"],
        2
      ),
    ],
    [
      "isolate_d",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /$/ }, { direction: "before", regExp: /^/ }] },
        SAMPA.FR.consonants["d"],
        1
      ),
    ],
    [
      "mute_d",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "except",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }, { direction: "before", regExp: /aï|oue/ }] },
        SAMPA.FR.consonants["d"],
        1
      ),
    ],
  ])
);
