"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var debugLog_exports = {};
__export(debugLog_exports, {
  createDebugLogger: () => createDebugLogger
});
module.exports = __toCommonJS(debugLog_exports);
var import_fs = require("fs");
var import_os = require("os");
var import_path = require("path");
function createDebugLogger(name) {
  const envVar = `DEXTO_DEBUG_${name.toUpperCase()}`;
  const logPath = (0, import_path.join)((0, import_os.tmpdir)(), `dexto-debug-${name.toLowerCase()}.log`);
  const isEnabled = () => {
    return process.env[envVar] === "true" || process.env.DEXTO_DEBUG_ALL === "true";
  };
  const log = (msg, data) => {
    if (!isEnabled()) return;
    try {
      const timestamp = (/* @__PURE__ */ new Date()).toISOString().split("T")[1];
      const dataStr = data ? ` ${JSON.stringify(data)}` : "";
      const line = `[${timestamp}] ${msg}${dataStr}
`;
      (0, import_fs.appendFileSync)(logPath, line);
    } catch {
    }
  };
  const reset = (header) => {
    if (!isEnabled()) return;
    const defaultHeader = `=== DEXTO DEBUG [${name.toUpperCase()}] ${(/* @__PURE__ */ new Date()).toISOString()} ===`;
    try {
      (0, import_fs.writeFileSync)(logPath, `${header ?? defaultHeader}
`);
    } catch {
    }
  };
  return {
    log,
    isEnabled,
    getLogPath: () => logPath,
    reset
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createDebugLogger
});
