import * as A from "fp-ts-esm/Array";
import { Lens, fromTraversable } from "monocle-ts-esm";
import { extract } from "./RicosContentAPI/extract.js";
import { isDraftContent, isRichContent } from "./types/content-types.js";
function getContentLength(content) {
  if (isDraftContent(content)) {
    return getDraftTextLength(content);
  } else if (isRichContent(content)) {
    return getRichContentTextLength(content);
  }
  return NaN;
}
function getRichContentTextLength(content) {
  return extract(content.nodes ?? []).map(({ textData }) => textData?.text || "").get().reduce((count, line) => count + line.length, 0);
}
function getDraftTextLength(content) {
  const blocksLens = Lens.fromProp()("blocks");
  const blockTraversal = fromTraversable(A.array)();
  const textLens = Lens.fromProp()("text");
  return blocksLens.composeTraversal(blockTraversal).composeLens(textLens).asFold().getAll(content).reduce((count, line) => count + line.length, 0);
}
export {
  getContentLength
};
//# sourceMappingURL=get-content-length.js.map
