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

export const cState = new State(
  "c",
  [
    "eiy",
    "ch_to_k",
    "psycho",
    "brachio",
    "h",
    "erc_orc",
    "isolate_c",
    "muted_c_final",
    "onc_donc",
    "nc_mute_end",
    "spect",
    "inct",
    "cciey",
    "cc",
    "apostrophe",
  ],
  new Map<string, Rule>([
    ["*", new Rule(null, SAMPA.FR.consonants["k"], 1)],
    ["$", new Rule(null, SAMPA.FR.consonants["k"], 1)],
    [
      "inct",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /ts?$/ }, { direction: "before", regExp: /in/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "spect",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /ts?$/ }, { direction: "before", regExp: /spe/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "apostrophe",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: apostropheRegExp }] },
        SAMPA.FR.consonants["S"],
        1
      ),
    ],
    [
      "brachio",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /hio/ }, { direction: "before", regExp: /bra/ }] },
        SAMPA.FR.consonants["k"],
        2
      ),
    ],
    [
      "muted_c_final",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }, { direction: "before", regExp: /taba|estoma/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "cc",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /c/ }] },
        SAMPA.FR.consonants["k"],
        2
      ),
    ],
    [
      "cciey",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /c[eiyéèêëîï]/ }] },
        SAMPA.FR.consonants["k"],
        1
      ),
    ],
    [
      "ch_to_k",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /héo|hest|hiro[p|m]|hl(o|am)|hoe|hœ|hor|hr/ }] },
        SAMPA.FR.consonants["k"],
        2
      ),
    ],
    [
      "isolate_c",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /$/ }, { direction: "before", regExp: /^/ }] },
        SAMPA.FR.consonants["S"],
        1
      ),
    ],
    [
      "eiy",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /[eiyéèêëîï]/ }] },
        SAMPA.FR.consonants["S"],
        1
      ),
    ],
    [
      "erc_orc",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }, { direction: "before", regExp: /[e|o]r/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "h",
      new Rule(
        {
          type: "regExp",
          regExps: [
            {
              direction: "after",
              regExp: /^h/,
            },
          ],
        },
        SAMPA.FR.consonants["S"],
        2
      ),
    ],
    [
      "nc_mute_end",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /s?$/ }, { direction: "before", regExp: /n/ }] },
        SAMPA.specials["#"],
        1
      ),
    ],
    [
      "onc_donc",
      new Rule(
        { type: "regExp", regExps: [{ direction: "before", regExp: /^on|^don/ }] },
        SAMPA.FR.consonants["k"],
        1
      ),
    ],
    [
      "psycho",
      new Rule(
        { type: "regExp", regExps: [{ direction: "after", regExp: /ho/ }, { direction: "before", regExp: /psy/ }] },
        SAMPA.FR.consonants["k"],
        2
      ),
    ],
  ])
);
