"use strict";
/* Socket Lib - Built with esbuild */
"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 proxy_exports = {};
__export(proxy_exports, {
  createEnvProxy: () => createEnvProxy
});
module.exports = __toCommonJS(proxy_exports);
var import_globals = require("../primordials/globals");
var import_map_set = require("../primordials/map-set");
var import_object = require("../primordials/object");
var import_case_insensitive = require("./case-insensitive");
const caseInsensitiveKeys = new import_map_set.SetCtor([
  "APPDATA",
  "COMSPEC",
  "HOME",
  "LOCALAPPDATA",
  "PATH",
  "PATHEXT",
  "PROGRAMFILES",
  "SYSTEMROOT",
  "TEMP",
  "TMP",
  "USERPROFILE",
  "WINDIR"
]);
function createEnvProxy(base, overrides) {
  function lookupEnvValue(prop) {
    if (overrides && prop in overrides) {
      return overrides[prop];
    }
    if (prop in base) {
      return base[prop];
    }
    const upperProp = prop.toUpperCase();
    if (caseInsensitiveKeys.has(upperProp)) {
      if (overrides) {
        const key2 = (0, import_case_insensitive.findCaseInsensitiveEnvKey)(overrides, upperProp);
        if (key2 !== void 0) {
          return overrides[key2];
        }
      }
      const key = (0, import_case_insensitive.findCaseInsensitiveEnvKey)(base, upperProp);
      if (key !== void 0) {
        return base[key];
      }
    }
    return void 0;
  }
  return new import_globals.ProxyCtor({}, {
    get(_target, prop) {
      if (typeof prop !== "string") {
        return void 0;
      }
      return lookupEnvValue(prop);
    },
    ownKeys(_target) {
      const keys = /* @__PURE__ */ new Set([
        ...(0, import_object.ObjectKeys)(base),
        ...overrides ? (0, import_object.ObjectKeys)(overrides) : []
      ]);
      return [...keys];
    },
    getOwnPropertyDescriptor(_target, prop) {
      if (typeof prop !== "string") {
        return void 0;
      }
      const value = lookupEnvValue(prop);
      return value !== void 0 ? {
        enumerable: true,
        configurable: true,
        writable: true,
        value
      } : void 0;
    },
    has(_target, prop) {
      if (typeof prop !== "string") {
        return false;
      }
      if (overrides && prop in overrides) {
        return true;
      }
      if (prop in base) {
        return true;
      }
      const upperProp = prop.toUpperCase();
      if (caseInsensitiveKeys.has(upperProp)) {
        if (overrides && (0, import_case_insensitive.findCaseInsensitiveEnvKey)(overrides, upperProp) !== void 0) {
          return true;
        }
        if ((0, import_case_insensitive.findCaseInsensitiveEnvKey)(base, upperProp) !== void 0) {
          return true;
        }
      }
      return false;
    },
    set(_target, prop, value) {
      if (typeof prop === "string" && overrides) {
        overrides[prop] = value;
        return true;
      }
      return false;
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createEnvProxy
});
