"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Figure = void 0;
exports.cleanColumns = cleanColumns;
exports.cleanLines = cleanLines;
exports.empty = empty;
exports.fromCharacter = fromCharacter;
exports.fromFigCharacter = fromFigCharacter;
exports.lines = lines;
exports.showFigure = void 0;
exports.width = width;

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

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

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

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

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

var FC = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../FigCharacter/index.js"));

var FF = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../FigFont/index.js"));

var SC = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../SubColumns/index.js"));

var SL = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../SubLines/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
// -----------------------------------------------------------------------------
// Model
// -----------------------------------------------------------------------------

/**
 * A `Figure` is a string rendered using a specific `FigFont`, and is made up
 * of multiple `FigCharacter`s.
 *
 * A `Figure` cannot be instantiated directly. Instead, one must use the
 * constructor definitions to perform validation of the header.
 */
class Figure extends _Case.Case {} // -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------

/**
 * Creates an empty `Figure` using the specified `FigFont`.
 *
 * @param font The `FigFont` that the `Figure` uses.
 * @returns An empty `Figure` that uses the given `FigFont`.
 */


exports.Figure = Figure;

function empty(font) {
  return fromFigCharacter(FF.zero(font), font);
}
/**
 * Creates a `Figure` that contains a single character given as `FigCharacter`.
 *
 * @param char The first character of the `Figure`.
 * @param font The `FigFont` that the `Figure` uses.
 * @returns A `Figure` containing one character that uses the given `FigFont`.
 */


function fromFigCharacter(char, font) {
  return new Figure({
    font,
    value: char.name,
    columns: C.single(FC.columns(char))
  });
}
/**
 * Creates a `Figure` that contains a single character.
 *
 * @param char The first character of the `Figure`.
 * @param font The `FigFont` that the `Figure` uses.
 * @returns A `Figure` containing one character that uses the given `FigFont`.
 */


function fromCharacter(char, font) {
  return new Figure({
    font,
    value: char,
    columns: C.single(FC.columns(FF.char_(font, char)))
  });
} // -----------------------------------------------------------------------------
// Destructors
// -----------------------------------------------------------------------------


function hardblank(self) {
  return self.font.header.hardblank;
}
/**
 * The `Figure` represented as a collection of lines.
 */


function lines(self) {
  return C.map_(self.columns, SC.toSubLines);
}
/**
 * The `Figure` represented as a list of lines stripped of their hardblanks.
 */


function cleanLines(self) {
  return C.map_(lines(self), SL.replace(hardblank(self), " "));
}
/**
 * The columns representing the rendered `Figure` stripped of their hardblanks.
 */


function cleanColumns(self) {
  return C.map_(self.columns, SC.replace(hardblank(self), " "));
}
/**
 * Gets the maximum width of the `Figure`.
 */


function width(self) {
  const f = Ord.max(Ord.number);
  return C.reduce_(C.chain_(lines(self), line => C.map_(line.value, _ => _.length)), 0, f);
} // -----------------------------------------------------------------------------
// Instances
// -----------------------------------------------------------------------------


const showFigure = /*#__PURE__*/(0, _Show.makeShow)(self => {
  return C.join_(C.map_(cleanLines(self), _ => C.join_(_.value, "\n")), "\n");
});
exports.showFigure = showFigure;
//# sourceMappingURL=index.js.map