// 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 E from "@effect-ts/core/Either";
import * as Eq from "@effect-ts/core/Equal";
import { pipe } from "@effect-ts/core/Function";
import * as O from "@effect-ts/core/Option";
import * as Structural from "@effect-ts/core/Structural";
import * as FullLayout from "../../FigHeader/FullLayout/index.mjs";
import * as VSR from "../VerticalSmushingRule/index.mjs"; // -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------

export const FullHeight = {
  _tag: "FullHeight"
};
export const VerticalFitting = {
  _tag: "VerticalFitting"
};
export const UniversalSmushing = {
  _tag: "UniversalSmushing"
};
export function ControlledSmushing(rules) {
  return {
    _tag: "ControlledSmushing",
    rules
  };
}
/**
 * Interprets the header settings and returns the selected `VerticalLayout`.
 *
 * @param header The `FigHeader` where the vertical layout is defined.
 * @returns A `FigletResult` containing the new `VerticalLayout`, or
 * a list of `FigletException`s that occurred during parsing.
 */

export function fromHeader(header) {
  return O.getOrElse_(O.map_(header.fullLayout, settings => {
    if (!hasLayout(settings, FullLayout.VerticalFitting) && !hasLayout(settings, FullLayout.VerticalSmushing)) {
      return E.right(FullHeight);
    }

    if (hasLayout(settings, FullLayout.VerticalFitting) && !hasLayout(settings, FullLayout.VerticalSmushing)) {
      return E.right(VerticalFitting);
    }

    const selectedSmushingRules = A.intersection_(FullLayout.equalFullLayout)(C.toArray(settings), C.toArray(FullLayout.verticalSmushingRules));

    if (hasLayout(settings, FullLayout.VerticalSmushing) && !A.isEmpty(selectedSmushingRules)) {
      return E.map_(VSR.fromHeader(header), ControlledSmushing);
    }

    return E.right(UniversalSmushing);
  }), () => E.right(FullHeight));
} // -----------------------------------------------------------------------------
// Instances
// -----------------------------------------------------------------------------

export const equalVerticalLayout = /*#__PURE__*/Eq.makeEqual(Structural.equals); // -----------------------------------------------------------------------------
// Utilities
// -----------------------------------------------------------------------------

function hasLayout(settings, layout) {
  return C.elem_(settings, FullLayout.equalFullLayout, layout);
}
//# sourceMappingURL=index.mjs.map