"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.equalSubLines = void 0;
exports.foreach = foreach;
exports.foreach_ = foreach_;
exports.fromValue = fromValue;
exports.length = length;
exports.map = map;
exports.map_ = map_;
exports.replace = replace;
exports.replace_ = replace_;
exports.showSubLines = void 0;
exports.toSubcolumns = toSubcolumns;
exports.width = width;
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 `SubLines` from a pure value.
 */
function fromValue(value) {
  return {
    value
  };
}
/**
 * Create a zero-height `SubLines` object of the specified height.
 *
 * @param height The number of lines that compose this `SubLines` object.
 */


function zero(height) {
  return {
    value: C.fill(height, () => "")
  };
} // -----------------------------------------------------------------------------
// Operations
// -----------------------------------------------------------------------------

/**
 * Counts the number of columns that compose the provided `SubLines`.
 */


function width(self) {
  return O.getOrElse_(C.head(C.map_(self.value, _ => _.length)), () => 0);
}
/**
 * Transforms this `SubLines` into a `SubColumns`.
 */


function toSubcolumns(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 `SubLines`.
 */


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


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


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


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


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


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 `SubLines`.
 *
 * @ets_data_first replace_
 */


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


const equalSubLines = /*#__PURE__*/Eq.makeEqual((x, y) => x[Structural.equalsSym](y));
exports.equalSubLines = equalSubLines;
const showSubLines = /*#__PURE__*/(0, _Show.makeShow)(x => C.join_(C.map_(x.value, _ => `|${_}|`), "\n"));
exports.showSubLines = showSubLines;
//# sourceMappingURL=index.js.map