"use strict";
/* Socket Lib - Built with esbuild */
"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 namespace_exports = {};
__export(namespace_exports, {
  extractOptions: () => extractOptions,
  getDebugJsInstance: () => getDebugJsInstance,
  isDebug: () => isDebug,
  isDebugNs: () => isDebugNs,
  isEnabled: () => isEnabled
});
module.exports = __toCommonJS(namespace_exports);
var import_debug = require("../env/debug");
var import_socket = require("../env/socket");
var import_debug2 = __toESM(require("../external/debug"));
var import_string = require("../primordials/string");
var import_internal = require("./_internal");
// @__NO_SIDE_EFFECTS__
function extractOptions(namespaces) {
  return namespaces !== null && typeof namespaces === "object" ? { __proto__: null, ...namespaces } : { __proto__: null, namespaces };
}
// @__NO_SIDE_EFFECTS__
function getDebugJsInstance(namespace) {
  let inst = import_internal.debugByNamespace.get(namespace);
  if (inst) {
    return inst;
  }
  if (!(0, import_debug.getDebug)() && (0, import_socket.getSocketDebug)() && (namespace === "error" || namespace === "notice")) {
    import_debug2.default.enable(namespace);
  }
  inst = (0, import_debug2.default)(namespace);
  inst.log = import_internal.customLog;
  import_internal.debugByNamespace.set(namespace, inst);
  return inst;
}
// @__NO_SIDE_EFFECTS__
function isDebug() {
  return !!(0, import_socket.getSocketDebug)();
}
// @__NO_SIDE_EFFECTS__
function isDebugNs(namespaces) {
  return !!(0, import_socket.getSocketDebug)() && /* @__PURE__ */ isEnabled(namespaces);
}
// @__NO_SIDE_EFFECTS__
function isEnabled(namespaces) {
  if (!(0, import_socket.getSocketDebug)()) {
    return false;
  }
  if (typeof namespaces !== "string" || !namespaces || namespaces === "*") {
    return true;
  }
  const split = namespaces.trim().replace(/\s+/g, ",").split(",").filter(Boolean);
  const names = [];
  const skips = [];
  for (const ns of split) {
    if ((0, import_string.StringPrototypeStartsWith)(ns, "-")) {
      skips.push(ns.slice(1));
    } else {
      names.push(ns);
    }
  }
  if (names.length && !names.some((ns) => (/* @__PURE__ */ getDebugJsInstance(ns)).enabled)) {
    return false;
  }
  return skips.every((ns) => !(/* @__PURE__ */ getDebugJsInstance(ns)).enabled);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  extractOptions,
  getDebugJsInstance,
  isDebug,
  isDebugNs,
  isEnabled
});
