"use strict";
/* Socket Lib - Built with esbuild */
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 socket_exports = {};
__export(socket_exports, {
  getOsHomeDir: () => getOsHomeDir,
  getOsTmpDir: () => getOsTmpDir,
  getSocketAppCacheDir: () => getSocketAppCacheDir,
  getSocketAppCacheTtlDir: () => getSocketAppCacheTtlDir,
  getSocketAppDir: () => getSocketAppDir,
  getSocketCacacheDir: () => getSocketCacacheDir,
  getSocketCliDir: () => getSocketCliDir,
  getSocketDlxDir: () => getSocketDlxDir,
  getSocketHomePath: () => getSocketHomePath,
  getSocketRegistryDir: () => getSocketRegistryDir,
  getSocketRegistryGithubCacheDir: () => getSocketRegistryGithubCacheDir,
  getSocketUserDir: () => getSocketUserDir,
  getUserHomeDir: () => getUserHomeDir,
  invalidateCache: () => invalidateCache
});
module.exports = __toCommonJS(socket_exports);
var os = __toESM(require("os"));
var path = __toESM(require("path"));
var import_github = require("../constants/github");
var import_socket = require("../constants/socket");
var import_home = require("../env/home");
var import_socket2 = require("../env/socket");
var import_windows = require("../env/windows");
var import_dirnames = require("./dirnames");
var import_normalize = require("./normalize");
var import_rewire = require("./rewire");
function getOsHomeDir() {
  return (0, import_rewire.getPathValue)("homedir", () => os.homedir());
}
function getOsTmpDir() {
  return (0, import_rewire.getPathValue)("tmpdir", () => os.tmpdir());
}
function getSocketHomePath() {
  return getSocketUserDir();
}
let _cachedSocketUserDir;
function getSocketUserDir() {
  if (_cachedSocketUserDir === void 0) {
    _cachedSocketUserDir = (0, import_normalize.normalizePath)(
      path.join(getUserHomeDir(), import_dirnames.DOT_SOCKET_DIR)
    );
  }
  return _cachedSocketUserDir;
}
function getSocketAppDir(appName) {
  return (0, import_normalize.normalizePath)(
    path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}${appName}`)
  );
}
let _cachedSocketCacacheDir;
function getSocketCacacheDir() {
  if (_cachedSocketCacacheDir === void 0) {
    if ((0, import_socket2.getSocketCacacheDir)()) {
      _cachedSocketCacacheDir = (0, import_normalize.normalizePath)(
        (0, import_socket2.getSocketCacacheDir)()
      );
    } else {
      _cachedSocketCacacheDir = (0, import_normalize.normalizePath)(
        path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}cacache`)
      );
    }
  }
  return _cachedSocketCacacheDir;
}
function getSocketDlxDir() {
  if ((0, import_socket2.getSocketDlxDirEnv)()) {
    return (0, import_normalize.normalizePath)((0, import_socket2.getSocketDlxDirEnv)());
  }
  return (0, import_normalize.normalizePath)(
    path.join(getSocketUserDir(), `${import_socket.SOCKET_APP_PREFIX}${import_socket.SOCKET_DLX_APP_NAME}`)
  );
}
function getSocketAppCacheDir(appName) {
  return (0, import_normalize.normalizePath)(path.join(getSocketAppDir(appName), import_dirnames.CACHE_DIR));
}
function getSocketAppCacheTtlDir(appName) {
  return (0, import_normalize.normalizePath)(path.join(getSocketAppCacheDir(appName), import_dirnames.CACHE_TTL_DIR));
}
function getSocketCliDir() {
  return getSocketAppDir(import_socket.SOCKET_CLI_APP_NAME);
}
function getSocketRegistryDir() {
  return getSocketAppDir(import_socket.SOCKET_REGISTRY_APP_NAME);
}
function getSocketRegistryGithubCacheDir() {
  return (0, import_normalize.normalizePath)(
    path.join(
      getSocketAppCacheTtlDir(import_socket.SOCKET_REGISTRY_APP_NAME),
      import_github.CACHE_GITHUB_DIR
    )
  );
}
function getUserHomeDir() {
  const home = (0, import_home.getHome)();
  if (home) {
    return home;
  }
  const userProfile = (0, import_windows.getUserprofile)();
  if (userProfile) {
    return userProfile;
  }
  return getOsHomeDir();
}
function invalidateCache() {
  _cachedSocketUserDir = void 0;
  _cachedSocketCacacheDir = void 0;
}
(0, import_rewire.registerCacheInvalidation)(invalidateCache);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getOsHomeDir,
  getOsTmpDir,
  getSocketAppCacheDir,
  getSocketAppCacheTtlDir,
  getSocketAppDir,
  getSocketCacacheDir,
  getSocketCliDir,
  getSocketDlxDir,
  getSocketHomePath,
  getSocketRegistryDir,
  getSocketRegistryGithubCacheDir,
  getSocketUserDir,
  getUserHomeDir,
  invalidateCache
});
