"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ControlledSmushing = ControlledSmushing;
exports.equalVerticalLayout = exports.VerticalFitting = exports.UniversalSmushing = exports.FullHeight = void 0;
exports.fromHeader = fromHeader;

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 E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Either"));

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

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

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

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

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

var VSR = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../VerticalSmushingRule/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 FullHeight = {
  _tag: "FullHeight"
};
exports.FullHeight = FullHeight;
const VerticalFitting = {
  _tag: "VerticalFitting"
};
exports.VerticalFitting = VerticalFitting;
const UniversalSmushing = {
  _tag: "UniversalSmushing"
};
exports.UniversalSmushing = UniversalSmushing;

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.
 */


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
// -----------------------------------------------------------------------------


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

exports.equalVerticalLayout = equalVerticalLayout;

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