"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Underscore = exports.OppositePair = exports.Hierarchy = exports.Hardblank = exports.EqualCharacter = exports.BigX = void 0;
exports.fromFullLayout = fromFullLayout;
exports.fromOldLayout = fromOldLayout;

var A = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/Array"));

var C = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/Chunk"));

var NA = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/NonEmptyArray"));

var E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Either"));

var O = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Option"));

var _Utils = /*#__PURE__*/require("@effect-ts/core/Utils");

var FullLayout = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../FigHeader/FullLayout/index.js"));

var _index2 = /*#__PURE__*/require("../../FigletException/index.js");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// ets_tracing: off
// -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------
const EqualCharacter = {
  _tag: "EqualCharacter"
};
exports.EqualCharacter = EqualCharacter;
const Underscore = {
  _tag: "Underscore"
};
exports.Underscore = Underscore;
const Hierarchy = {
  _tag: "Hierarchy"
};
exports.Hierarchy = Hierarchy;
const OppositePair = {
  _tag: "OppositePair"
};
exports.OppositePair = OppositePair;
const BigX = {
  _tag: "BigX"
};
exports.BigX = BigX;
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.
 */

exports.Hardblank = Hardblank;

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)), (0, _Utils.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.
 */


function fromOldLayout(header) {
  const rules = C.from(A.collect_(C.toArray(header.oldLayout), (0, _Utils.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 _index2.FigFontError({
      message: `Header field "oldLayout" does not include any horizontal smushing rule`
    })));
  }

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