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

export const xState = new State(
  "x",
  [
    "six_dix",
    "gz_1",
    "gz_2",
    "gz_3",
    "gz_4",
    "gz_5",
    "_aeox",
    "fix",
    "_ix"
  ],
  new Map([
    ["*", new Rule(null, SAMPA.FR.consonants["ks"], 1)], // fallback [ks]

    ["$", new Rule(null, SAMPA.specials["#"], 1)], // silent x

    ["_aeox", new Rule({ type: "regExp", regExps: [
      { direction: "before", regExp: /[aeo]/ }
    ]}, SAMPA.FR.consonants["ks"], 1)],

    ["_ix", new Rule({ type: "regExp", regExps: [
      { direction: "before", regExp: /(remi|obéli|astéri|héli|phéni|féli)/ }
    ]}, SAMPA.FR.consonants["ks"], 1)],

    ["fix", new Rule({ type: "regExp", regExps: [
      { direction: "before", regExp: /fi/ }
    ]}, SAMPA.FR.consonants["ks"], 1)],

    ["gz_1", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /[aeiouéèàüëöêîôûù]/ },
      { direction: "before", regExp: /^/ }
    ]}, SAMPA.FR.consonants["gz"], 1)],

    ["gz_2", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /[aeiouéèàüëöêîôûù]/ },
      { direction: "before", regExp: /^(h?)e/ }
    ]}, SAMPA.FR.consonants["gz"], 1)],

    ["gz_3", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /[aeiouéèàüëöêîôûù]/ },
      { direction: "before", regExp: /^coe/ }
    ]}, SAMPA.FR.consonants["gz"], 1)],

    ["gz_4", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /[aeiouéèàüëöêîôûù]/ },
      { direction: "before", regExp: /^ine/ }
    ]}, SAMPA.FR.consonants["gz"], 1)],

    ["gz_5", new Rule({ type: "regExp", regExps: [
      { direction: "after", regExp: /[aeiouéèàüëöêîôûù]/ },
      { direction: "before", regExp: /^(p?)rée/ }
    ]}, SAMPA.FR.consonants["gz"], 1)],

    ["six_dix", new Rule({ type: "regExp", regExps: [
      { direction: "before", regExp: /(s|d)i/ }
    ]}, SAMPA.FR.consonants["s"], 1)]
  ])
);
