import { handleExtract } from "../../tools/extract.js";
import { createLogger } from "../../logger.js";
const log = createLogger("repl");
async function executeExtract(args, deps) {
  try {
    const url = args.positional[0];
    if (!url) {
      return {
        data: {},
        mode: "metadata",
        error: "Usage: extract <URL> [--mode=selector|tables|metadata|schema] [--selector=CSS]"
      };
    }
    const input = { url };
    if (args.flags.mode) {
      input.mode = args.flags.mode;
    }
    if (args.flags.selector) {
      input.css_selector = args.flags.selector;
    }
    if (args.flags.multiple === "true") {
      input.multiple = true;
    }
    log.debug("executing extract command", { url, flags: args.flags });
    const r = await handleExtract(input, deps.router);
    if (!r.ok) {
      return {
        data: {},
        mode: input.mode ?? "metadata",
        error: r.error_reason
      };
    }
    return r.data;
  } catch (err) {
    const msg = err instanceof Error ? err.message : String(err);
    log.error("extract command failed", { error: msg });
    return {
      data: {},
      mode: args.flags.mode ?? "metadata",
      error: msg
    };
  }
}
export {
  executeExtract
};
//# sourceMappingURL=extract.js.map