"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 resolve_exports = {};
__export(resolve_exports, {
  relative: () => relative,
  relativeResolve: () => relativeResolve,
  resolve: () => resolve
});
module.exports = __toCommonJS(resolve_exports);
var import_platform = require("../constants/platform");
var import_string = require("../primordials/string");
var import_internal = require("./_internal");
var import_normalize = require("./normalize");
var import_predicates = require("./predicates");
// @__NO_SIDE_EFFECTS__
function relative(from, to) {
  if (from === to) {
    return "";
  }
  const actualFrom = /* @__PURE__ */ resolve(from);
  const actualTo = /* @__PURE__ */ resolve(to);
  if (actualFrom === actualTo) {
    return "";
  }
  if (import_platform.WIN32) {
    const fromLower = actualFrom.toLowerCase();
    const toLower = actualTo.toLowerCase();
    if (fromLower === toLower) {
      return "";
    }
  }
  const fromStart = 1;
  const fromEnd = actualFrom.length;
  const fromLen = fromEnd - fromStart;
  const toStart = 1;
  const toEnd = actualTo.length;
  const toLen = toEnd - toStart;
  const length = fromLen < toLen ? fromLen : toLen;
  let lastCommonSep = -1;
  let i = 0;
  for (; i < length; i += 1) {
    let fromCode = (0, import_string.StringPrototypeCharCodeAt)(actualFrom, fromStart + i);
    let toCode = (0, import_string.StringPrototypeCharCodeAt)(actualTo, toStart + i);
    if (import_platform.WIN32) {
      if (fromCode >= import_internal.CHAR_UPPERCASE_A && fromCode <= import_internal.CHAR_UPPERCASE_Z) {
        fromCode += 32;
      }
      if (toCode >= import_internal.CHAR_UPPERCASE_A && toCode <= import_internal.CHAR_UPPERCASE_Z) {
        toCode += 32;
      }
    }
    if (fromCode !== toCode) {
      break;
    }
    if ((0, import_predicates.isPathSeparator)((0, import_string.StringPrototypeCharCodeAt)(actualFrom, fromStart + i))) {
      lastCommonSep = i;
    }
  }
  if (i === length) {
    if (toLen > length) {
      const toCode = (0, import_string.StringPrototypeCharCodeAt)(actualTo, toStart + i);
      if ((0, import_predicates.isPathSeparator)(toCode)) {
        return actualTo.slice(toStart + i + 1);
      }
      if (i === 0) {
        return actualTo.slice(toStart + i);
      }
    } else if (fromLen > length) {
      const fromCode = (0, import_string.StringPrototypeCharCodeAt)(actualFrom, fromStart + i);
      if ((0, import_predicates.isPathSeparator)(fromCode)) {
        lastCommonSep = i;
      } else if (i === 0) {
        lastCommonSep = 0;
      }
    }
  }
  let out = "";
  for (i = fromStart + lastCommonSep + 1; i <= fromEnd; i += 1) {
    const code = (0, import_string.StringPrototypeCharCodeAt)(actualFrom, i);
    if (i === fromEnd || (0, import_predicates.isPathSeparator)(code)) {
      out += out.length === 0 ? ".." : "/..";
    }
  }
  return out + actualTo.slice(toStart + lastCommonSep);
}
// @__NO_SIDE_EFFECTS__
function relativeResolve(from, to) {
  const rel = /* @__PURE__ */ relative(from, to);
  if (rel === "") {
    return "";
  }
  return (0, import_normalize.normalizePath)(rel);
}
// @__NO_SIDE_EFFECTS__
function resolve(...segments) {
  let resolvedPath = "";
  let resolvedAbsolute = false;
  for (let i = segments.length - 1; i >= 0 && !resolvedAbsolute; i -= 1) {
    const segment = segments[i];
    if (typeof segment !== "string" || segment.length === 0) {
      continue;
    }
    resolvedPath = segment + (resolvedPath.length === 0 ? "" : `/${resolvedPath}`);
    resolvedAbsolute = (0, import_predicates.isAbsolute)(segment);
  }
  if (!resolvedAbsolute) {
    const cwd = /* @__PURE__ */ require("node:process").cwd();
    resolvedPath = cwd + (resolvedPath.length === 0 ? "" : `/${resolvedPath}`);
  }
  return (0, import_normalize.normalizePath)(resolvedPath);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  relative,
  relativeResolve,
  resolve
});
