import * as C from "@effect-ts/core/Collections/Immutable/Chunk";
import * as Map from "@effect-ts/core/Collections/Immutable/Map";
import * as Set from "@effect-ts/core/Collections/Immutable/Set";
import * as E from "@effect-ts/core/Either";
import { pipe } from "@effect-ts/core/Function";
import * as O from "@effect-ts/core/Option";
import * as FC from "../FigCharacter/index.mjs";
import * as SL from "../SubLines/index.mjs";
import { buildFont, FontBuilderState, processLine } from "./builder.mjs"; // -----------------------------------------------------------------------------
// Operations
// -----------------------------------------------------------------------------

/**
 * Creates a new `FigFont` by parsing an input collection of lines representing
 * a Figlet font file.
 *
 * @param file The file that contains the `FigFont` definition.
 * @param lines A `Chunk` that contains all the lines representing an Figlet
 * font file that defines the `FigFont`.
 * @return A `FigletResult` containing the new `FigFont`, or a list of errors
 * accumulated during creation of the `FigFont`.
 */

export function fromFile(file, lines) {
  return E.chain_(C.reduce_(C.zipWithIndex(lines), E.right(new FontBuilderState({
    file,
    header: O.none,
    commentLines: C.empty(),
    loadedNames: Set.empty,
    loadedChars: C.empty(),
    loadedCharLines: C.empty(),
    processTaggedFonts: false,
    hash: ""
  })), (state, {
    tuple: [line, index]
  }) => E.isLeft(state) ? state : processLine(state.right, line, index)), buildFont);
}
/**
 * The empty character (as in the Unicode character `"\u0000"`).
 */

export function zero(self) {
  return new FC.FigCharacter({
    fontId: self.id,
    name: "\u0000",
    lines: SL.zero(self.header.height),
    endmark: "@",
    width: 0,
    comment: O.none,
    position: -1
  });
}
/**
 * Returns a `FigCharacter` representation of the given char.
 *
 * If the requested character is not present, the `FigCharacter` `"0"` (as in
 * Unicode character `"\u0000"`) will be returned instead.
 *
 * @param char The character to process into a `FigCharacter`.
 * @returns The `FigCharacter` that represent the given input character.
 */

export function char_(self, char) {
  return O.getOrElse_(Map.lookup_(self.characters, char), () => zero(self));
}
/**
 * Returns a `FigCharacter` representation of the given char.
 *
 * If the requested character is not present, the `FigCharacter` `"0"` (as in
 * Unicode character `"\u0000"`) will be returned instead.
 *
 * @ets_data_first char_
 * @param char The character to process into a `FigCharacter`.
 * @returns The `FigCharacter` that represent the given input character.
 */

export function char(char) {
  return self => char_(self, char);
}
/**
 * Retrieves the `FigFont` representation of a character as a string.
 *
 * @param char The character to process into a `FigCharacter` and render.
 * @returns The string representation of the `FigCharacter` that represents
 * the specified input character.
 */

export function process_(self, char) {
  return SL.replace_(char_(self, char).lines, self.header.hardblank, " ").value;
}
/**
 * Retrieves the `FigFont` representation of a character as a string.
 *
 * @ets_data_first process_
 * @param char The character to process into a `FigCharacter` and render.
 * @returns The string representation of the `FigCharacter` that represents
 * the specified input character.
 */

export function process(char) {
  return self => process_(self, char);
}
//# sourceMappingURL=operations.mjs.map