// 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 Eq from "@effect-ts/core/Equal";
import { pipe } from "@effect-ts/core/Function";
import * as O from "@effect-ts/core/Option";
import { makeShow } from "@effect-ts/core/Show";
import * as String from "@effect-ts/core/String";
import * as Structural from "@effect-ts/core/Structural";
import { escapeRegExp, transpose } from "../Internal/index.mjs"; // -----------------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------------

/**
 * Create an instance of `SubColumns` from a pure value.
 */

export function fromValue(value) {
  return {
    value
  };
}
/**
 * Create a one-column `SubColumns` object of the specified height.
 *
 * @param height The number of columns that compose this `SubColumns` object.
 */

export function zero(width) {
  return {
    value: C.single(" ".repeat(width))
  };
} // -----------------------------------------------------------------------------
// Operations
// -----------------------------------------------------------------------------

/**
 * Get the number of lines that compose this instance of `SubColumns`.
 */

export function height(self) {
  return O.getOrElse_(C.head(C.map_(self.value, _ => _.length)), () => 0);
}
export function toSubLines(self) {
  return {
    value: C.from(A.map_(transpose(A.map_(C.toArray(self.value), String.split(""))), A.join("")))
  };
}
/**
 * Gets the length of the `SubColumns`.
 */

export function length(self) {
  return self.value.length;
}
/**
 * Apply a function to each element to obtain a new `SubColumns`.
 */

export function map_(self, f) {
  return fromValue(C.map_(self.value, f));
}
/**
 * Apply a function to each element to obtain a new `SubColumns`.
 *
 * @ets_data_first map_
 */

export function map(f) {
  return self => map_(self, f);
}
/**
 * Applies a function to each element of the `SubColumns`.
 */

export function foreach_(self, f) {
  return C.forEach_(self.value, f);
}
/**
 * Applies a function to each element of the `SubColumns`.
 *
 * @ets_data_first foreach_
 */

export function foreach(f) {
  return self => foreach_(self, f);
}
/**
 * Replaces a string value looking inside each element of the `SubColumns`.
 */

export function replace_(self, oldValue, newValue) {
  return fromValue(C.map_(self.value, String.replace(new RegExp(escapeRegExp(oldValue), "g"), newValue)));
}
/**
 * Replaces a string value looking inside each element of the `SubColumns`.
 *
 * @ets_data_first replace_
 */

export function replace(oldValue, newValue) {
  return self => replace_(self, oldValue, newValue);
} // -----------------------------------------------------------------------------
// Instances
// -----------------------------------------------------------------------------

export const equalSubColumns = /*#__PURE__*/Eq.makeEqual((x, y) => x[Structural.equalsSym](y));
export const showSubColumns = /*#__PURE__*/makeShow(x => A.join_(A.map_(transpose(A.map_(C.toArray(x.value), String.split(""))), xs => `|${A.join_(xs, "")}`), "\n"));
//# sourceMappingURL=index.mjs.map