// ets_tracing: off
import * as A from "@effect-ts/core/Collections/Immutable/Array";
import * as C from "@effect-ts/core/Collections/Immutable/Chunk";
import * as NA from "@effect-ts/core/Collections/Immutable/NonEmptyArray";
import * as E from "@effect-ts/core/Either";
import * as O from "@effect-ts/core/Option";
import { matchTag } from "@effect-ts/core/Utils";
import * as FullLayout from "../../FigHeader/FullLayout/index.mjs";
import { FigFontError } from "../../FigletException/index.mjs"; // -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------

export const EqualCharacter = {
  _tag: "EqualCharacter"
};
export const Underscore = {
  _tag: "Underscore"
};
export const Hierarchy = {
  _tag: "Hierarchy"
};
export const OppositePair = {
  _tag: "OppositePair"
};
export const BigX = {
  _tag: "BigX"
};
export const Hardblank = {
  _tag: "Hardblank"
};
/**
 * Interprets the `fullLayout` header settings and returns the selected
 * `HorizontalSmushingRule`s.
 *
 * @param header The `FigHeader` where the `FullLayout` is defined.
 * @returns A `FigletResult` containing a list of `HorizontalSmushingRule`s, or
 * a list of `FigletException`s accumulated during parsing.
 */

export function fromFullLayout(header) {
  return E.right(O.getOrElse_(O.map_(header.fullLayout, settings => C.from(A.collect_(A.intersection_(FullLayout.equalFullLayout)(C.toArray(settings), C.toArray(FullLayout.horizontalSmushingRules)), matchTag({
    EqualCharacterHorizontalSmushing: () => O.some(EqualCharacter),
    UnderscoreHorizontalSmushing: () => O.some(Underscore),
    HierarchyHorizontalSmushing: () => O.some(Hierarchy),
    OppositePairHorizontalSmushing: () => O.some(OppositePair),
    BigXHorizontalSmushing: () => O.some(BigX),
    HardblankHorizontalSmushing: () => O.some(Hardblank)
  }, () => O.emptyOf())))), () => C.empty()));
}
/**
 * Interprets the `oldLayout` header settings and returns the selected
 * `HorizontalSmushingRule`s.
 *
 * @param header The `FigHeader` where the `OldLayout` is defined.
 * @returns A `FigletResult` containing a list of `HorizontalSmushingRule`s, or
 * a list of `FigletException`s accumulated during parsing.
 */

export function fromOldLayout(header) {
  const rules = C.from(A.collect_(C.toArray(header.oldLayout), matchTag({
    EqualCharacterSmushing: () => O.some(EqualCharacter),
    UnderscoreSmushing: () => O.some(Underscore),
    HierarchySmushing: () => O.some(Hierarchy),
    OppositePairSmushing: () => O.some(OppositePair),
    BigXSmushing: () => O.some(BigX),
    HardblankSmushing: () => O.some(Hardblank)
  }, () => O.emptyOf())));

  if (C.isEmpty(rules)) {
    return E.left(NA.single(new FigFontError({
      message: `Header field "oldLayout" does not include any horizontal smushing rule`
    })));
  }

  return E.right(rules);
}
//# sourceMappingURL=index.mjs.map