"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extractor_infra_exports = {};
__export(extractor_infra_exports, {
  getExtractor: () => getExtractor
});
module.exports = __toCommonJS(extractor_infra_exports);
var A = __toESM(require("fp-ts-esm/Array"));
var import_function = require("fp-ts-esm/function");
var import_Option = require("fp-ts-esm/Option");
var T = __toESM(require("fp-ts-esm/Tree"));
var import_monocle_ts_esm = require("monocle-ts-esm");
const getExtractor = (nodesAccessor) => (root) => {
  class TraversalExtractor {
    constructor(traversal, tree2) {
      this.traversal = traversal;
      this.tree = tree2;
    }
    // @ts-ignore $TSFixMe
    filter(predicate) {
      return new TraversalExtractor(
        this.traversal.composePrism(import_monocle_ts_esm.Prism.fromPredicate(predicate)),
        this.tree
      );
    }
    // @ts-ignore $TSFixMe
    map(mapper) {
      return new TraversalExtractor(
        this.traversal.composeLens(new import_monocle_ts_esm.Lens(mapper, () => (dt) => dt)),
        this.tree
      );
    }
    // @ts-ignore $TSFixMe
    chain(mapper) {
      return (0, import_function.pipe)(this.get(), A.map(mapper));
    }
    get() {
      return (0, import_function.pipe)(
        this.traversal.asFold().getAll(this.tree),
        A.map((0, import_Option.fromPredicate)(Boolean)),
        A.compact
      );
    }
  }
  const tree = T.unfoldTree(root, (node) => [node, nodesAccessor(node)]);
  return new TraversalExtractor((0, import_monocle_ts_esm.fromTraversable)(T.tree)(), tree);
};
//# sourceMappingURL=extractor-infra.js.map
