// ets_tracing: off
import { Case } from "@effect-ts/core/Case";
import * as C from "@effect-ts/core/Collections/Immutable/Chunk";
import { pipe } from "@effect-ts/core/Function";
import * as Ord from "@effect-ts/core/Ord";
import { makeShow } from "@effect-ts/core/Show";
import * as FC from "../FigCharacter/index.mjs";
import * as FF from "../FigFont/index.mjs";
import * as SC from "../SubColumns/index.mjs";
import * as SL from "../SubLines/index.mjs"; // -----------------------------------------------------------------------------
// 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.
 */

export class Figure extends 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`.
 */

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

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

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


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

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

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

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

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