"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.equalSubColumns = void 0;
exports.foreach = foreach;
exports.foreach_ = foreach_;
exports.fromValue = fromValue;
exports.height = height;
exports.length = length;
exports.map = map;
exports.map_ = map_;
exports.replace = replace;
exports.replace_ = replace_;
exports.showSubColumns = void 0;
exports.toSubLines = toSubLines;
exports.zero = zero;

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

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

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

var _index = /*#__PURE__*/require("../Internal/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
// -----------------------------------------------------------------------------

/**
 * Create an instance of `SubColumns` from a pure value.
 */
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.
 */


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

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


function height(self) {
  return O.getOrElse_(C.head(C.map_(self.value, _ => _.length)), () => 0);
}

function toSubLines(self) {
  return {
    value: C.from(A.map_((0, _index.transpose)(A.map_(C.toArray(self.value), String.split(""))), A.join("")))
  };
}
/**
 * Gets the length of the `SubColumns`.
 */


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


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


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


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


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


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


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


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