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 project_exports = {};
__export(project_exports, {
  getFilesInDirectory: () => getFilesInDirectory,
  getStudioConfig: () => getStudioConfig,
  getStudioPaths: () => getStudioPaths,
  getStudioStatePath: () => getStudioStatePath,
  getUserProjectAPIHost: () => getUserProjectAPIHost,
  getUserProjectApiPort: () => getUserProjectApiPort,
  getUserProjectConfig: () => getUserProjectConfig,
  getUserProjectGraphQlEndpoint: () => getUserProjectGraphQlEndpoint,
  getUserProjectMailer: () => getUserProjectMailer,
  getUserProjectPaths: () => getUserProjectPaths,
  getUserProjectWebHost: () => getUserProjectWebHost,
  getUserProjectWebPort: () => getUserProjectWebPort
});
module.exports = __toCommonJS(project_exports);
var import_node_fs = __toESM(require("node:fs"));
var import_node_path = __toESM(require("node:path"));
var import_project_config = require("@cedarjs/project-config");
var import_import = require("./import");
function getFilesInDirectory(dir) {
  const files = [];
  const dirFiles = import_node_fs.default.readdirSync(dir);
  for (const file of dirFiles) {
    if (import_node_fs.default.statSync(import_node_path.default.join(dir, file)).isDirectory()) {
      files.push(...getFilesInDirectory(import_node_path.default.join(dir, file)));
    } else {
      files.push(import_node_path.default.join(dir, file));
    }
  }
  return files;
}
function getUserProjectConfigPath() {
  let projectPath = process.env.RW_STUDIO_USER_PROJECT_PATH || "";
  const isWinFullPath = /^[A-Z]:\//.test(projectPath);
  if (projectPath && (projectPath[0] === "." || projectPath[0] !== "/" && !isWinFullPath)) {
    projectPath = import_node_path.default.join(process.cwd(), projectPath);
  }
  return (0, import_project_config.getConfigPath)(projectPath || import_node_path.default.join(getStudioPaths().base, ".."));
}
function getUserProjectConfig() {
  return (0, import_project_config.getConfig)(getUserProjectConfigPath());
}
function getUserProjectPaths() {
  return (0, import_project_config.getPaths)(import_node_path.default.dirname(getUserProjectConfigPath()));
}
async function getUserProjectMailer() {
  const distMailerPath = import_node_path.default.join(getUserProjectPaths().api.dist, "lib", "mailer.js");
  if (!import_node_fs.default.existsSync(distMailerPath)) {
    return null;
  }
  return (await (0, import_import.importFresh)(distMailerPath)).mailer;
}
function getUserProjectAPIHost() {
  let host = process.env.REDWOOD_API_HOST;
  host ??= getUserProjectConfig().api.host;
  host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "[::]";
  return host;
}
function getUserProjectApiPort() {
  return getUserProjectConfig().api.port;
}
function getUserProjectWebHost() {
  let host = getUserProjectConfig().web.host;
  host ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "[::]";
  return host;
}
function getUserProjectWebPort() {
  return getUserProjectConfig().web.port;
}
function getUserProjectGraphQlEndpoint() {
  const webConfig = getUserProjectConfig().web;
  return webConfig.apiGraphQLUrl ?? `http://${getUserProjectWebHost()}:${getUserProjectWebPort()}${webConfig.apiUrl}/graphql`;
}
function getStudioConfig() {
  const configPath = (0, import_project_config.getConfigPath)(__dirname);
  return (0, import_project_config.getConfig)(configPath);
}
function getStudioPaths() {
  const configPath = (0, import_project_config.getConfigPath)(__dirname);
  return (0, import_project_config.getPaths)(import_node_path.default.dirname(configPath));
}
function getStudioStatePath() {
  const statePath = import_node_path.default.join(getUserProjectPaths().generated.base, "studio");
  if (!import_node_fs.default.existsSync(statePath)) {
    import_node_fs.default.mkdirSync(statePath);
  }
  return statePath;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getFilesInDirectory,
  getStudioConfig,
  getStudioPaths,
  getStudioStatePath,
  getUserProjectAPIHost,
  getUserProjectApiPort,
  getUserProjectConfig,
  getUserProjectGraphQlEndpoint,
  getUserProjectMailer,
  getUserProjectPaths,
  getUserProjectWebHost,
  getUserProjectWebPort
});
//# sourceMappingURL=project.js.map
