import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  require_react
} from "./chunk-TODKQSCF.js";
import {
  GIT_IGNORED_DIR,
  WIX_CONFIG_FILENAME,
  getGitIgnoredPath,
  getWixConfigFilePath
} from "./chunk-YT5BPQDJ.js";
import {
  readEnvFile,
  readJson
} from "./chunk-VASURI4S.js";
import {
  zod_default
} from "./chunk-SDLCFZRL.js";
import {
  CliError,
  CliErrorCode
} from "./chunk-MTT3QXBC.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-astro-commands/src/model.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
import { ok } from "node:assert/strict";

// ../cli-astro-commands/src/files/wix.config.ts
init_esm_shims();

// ../cli-astro-definitions/src/definitions.ts
init_esm_shims();
import { join } from "node:path";
var wixAstroSiteConfigSchema = zod_default.object({
  $schema: zod_default.string().optional(),
  projectType: zod_default.literal("Site").optional().default("Site"),
  appId: zod_default.string(),
  siteId: zod_default.string(),
  site: zod_default.object({
    outputDirectory: zod_default.string().optional()
  }).optional()
});
var wixAstroAppConfigSchema = zod_default.object({
  $schema: zod_default.string().optional(),
  projectType: zod_default.literal("App"),
  appId: zod_default.string(),
  projectId: zod_default.string().optional(),
  codeIdentifier: zod_default.string().optional(),
  namespace: zod_default.string().optional()
});
var wixAstroConfigSchema = zod_default.discriminatedUnion("projectType", [
  wixAstroSiteConfigSchema,
  wixAstroAppConfigSchema
]);
var envSchema = zod_default.object({
  WIX_SITE_ID: zod_default.string().uuid().optional()
});
var ENV_FILE_NAME = ".env.local";
var TRANSLATIONS_FILE_PATH = join("src", "translations.json");
var BACKEND_WORKER_COMPONENT_ID = "ed5f3d0e-7b79-4717-9c00-c4cd7bbbe906";
var devMetadataSchema = zod_default.object({
  staticsUrlPlaceholder: zod_default.string(),
  serverUrlPlaceholder: zod_default.string()
});
var editorReactComponentTopologySchema = zod_default.object({
  id: zod_default.string().uuid(),
  type: zod_default.literal("EDITOR_REACT_COMPONENT"),
  topology: zod_default.object({
    "resources.client.componentUrl": zod_default.object({
      distPath: zod_default.string(),
      srcPath: zod_default.string()
    })
  })
});
var editorContextProviderTopologySchema = zod_default.object({
  id: zod_default.string().uuid(),
  type: zod_default.literal("EDITOR_CONTEXT_PROVIDER"),
  topology: zod_default.object({
    "resources.client.url": zod_default.object({
      distPath: zod_default.string(),
      srcPath: zod_default.string()
    })
  })
});
var editorFunctionLibraryTopologySchema = zod_default.object({
  id: zod_default.string().uuid(),
  type: zod_default.literal("EDITOR_FUNCTION_LIBRARY"),
  topology: zod_default.object({
    "resources.client.url": zod_default.object({
      distPath: zod_default.string(),
      srcPath: zod_default.string()
    })
  })
});
var supportedExtensionTopologySchemas = [
  editorReactComponentTopologySchema,
  editorContextProviderTopologySchema,
  editorFunctionLibraryTopologySchema
];
var rawExtensionTopologyItemSchema = zod_default.object({
  id: zod_default.string().uuid(),
  type: zod_default.string()
});
var extensionsTopologySchema = zod_default.array(rawExtensionTopologyItemSchema.passthrough()).transform(
  (items) => items.flatMap((item) => {
    for (const schema of supportedExtensionTopologySchemas) {
      const result = schema.safeParse(item);
      if (result.success) {
        return [result.data];
      }
    }
    return [];
  })
);
var buildMetadataSchema = zod_default.object({
  appManifestPath: zod_default.string(),
  outDir: zod_default.string(),
  clientDir: zod_default.string(),
  serverDir: zod_default.string().optional(),
  staticsUrlPlaceholder: zod_default.string().optional(),
  serverUrlPlaceholder: zod_default.string().optional(),
  generateAppDeploymentGroupId: zod_default.boolean().optional(),
  extensionsTopology: extensionsTopologySchema.optional()
});
var deploymentTopologyEnvironmentSchema = zod_default.object({
  id: zod_default.string().describe("Unique ARM tag identifier"),
  site: zod_default.object({
    main: zod_default.string().url().describe("Main site URL")
  }).describe("Site topology details").optional(),
  dashboard: zod_default.object({
    main: zod_default.string().url().describe("Main dashboard URL (link to a business manager dashboard)")
  }).describe("Optional dashboard topology details").optional(),
  editor: zod_default.object({
    main: zod_default.string().url().describe("Main editor URL")
  }).describe("Editor topology details").optional()
});
var deploymentTopologyEnvironmentTypeSchema = zod_default.enum([
  "production",
  "preview",
  "development"
]);
var deploymentTopologySchema = zod_default.record(
  deploymentTopologyEnvironmentTypeSchema,
  deploymentTopologyEnvironmentSchema
);
function getBuildMetadataPath(projectFolder) {
  return join(projectFolder, GIT_IGNORED_DIR, "build-metadata.json");
}
function getDeploymentTopologyPath(projectFolder) {
  return getGitIgnoredPath(projectFolder, "topology.json");
}
function getEnvFilePath(projectFolder) {
  return join(projectFolder, ENV_FILE_NAME);
}
function getExtensionDir(projectFolder) {
  return join(projectFolder, "src", "extensions");
}
var MULTILINGUAL_DIR = join(GIT_IGNORED_DIR, "multilingual");
var TRANSLATIONS_DIR = join(MULTILINGUAL_DIR, "translations");
var MULTILINGUAL_METADATA_FILENAME = "metadata.json";
function getTranslationsDir(projectFolder) {
  return join(projectFolder, TRANSLATIONS_DIR);
}
function getMultilingualMetadataPath(projectFolder) {
  return join(projectFolder, MULTILINGUAL_DIR, MULTILINGUAL_METADATA_FILENAME);
}
function getDebugLogPath(projectFolder) {
  return getGitIgnoredPath(projectFolder, "debug-logs", "cli-debug.log");
}
var ASTRO_APP_CONFIG_PATH = join(GIT_IGNORED_DIR, "app.config.json");
var astroAppConfigSchema = zod_default.object({
  siteId: zod_default.string().uuid().optional(),
  devArmTag: zod_default.string().optional()
});
function getAstroAppConfigPath(projectFolder) {
  return join(projectFolder, ASTRO_APP_CONFIG_PATH);
}

// ../cli-astro-commands/src/files/wix.config.ts
async function readWixConfig(projectFolder) {
  const configFile = await readJson(getWixConfigFilePath(projectFolder));
  const config = wixAstroConfigSchema.safeParse(configFile);
  if (config.success) {
    return config.data;
  }
  throw new CliError({
    code: CliErrorCode.InvalidConfigSchemaError({
      configPath: WIX_CONFIG_FILENAME,
      zodError: config.error
    }),
    cause: config.error
  });
}

// ../cli-astro-commands/src/files/env.ts
init_esm_shims();
async function readEnv(projectFolder) {
  const raw = await readEnvFile(getEnvFilePath(projectFolder));
  const result = envSchema.safeParse(raw);
  return result.success ? result.data : {};
}

// ../cli-astro-commands/src/model.tsx
async function loadProjectModel(projectFolder) {
  const [config, env] = await Promise.all([
    readWixConfig(projectFolder),
    readEnv(projectFolder)
  ]);
  return {
    projectFolder,
    config,
    env,
    releaseAppId: config.projectType === "App" && config.projectId ? config.projectId : config.appId
  };
}
var ProjectModelContext = (0, import_react.createContext)(null);
var ProjectModelProvider = (props) => {
  const [model] = (0, import_react.useState)(props.value);
  return /* @__PURE__ */ import_react.default.createElement(ProjectModelContext.Provider, { value: { model } }, props.children);
};
function useProjectModel() {
  const context = (0, import_react.useContext)(ProjectModelContext);
  if (context == null) {
    throw new Error(
      "useProjectModel() cannot be used without a <ProjectModelProvider>"
    );
  }
  return context;
}
function useSiteConfig() {
  const {
    model: { config }
  } = useProjectModel();
  ok(config.projectType === "Site", "Project is not a Site");
  return config;
}

export {
  ENV_FILE_NAME,
  TRANSLATIONS_FILE_PATH,
  BACKEND_WORKER_COMPONENT_ID,
  devMetadataSchema,
  buildMetadataSchema,
  deploymentTopologySchema,
  getBuildMetadataPath,
  getDeploymentTopologyPath,
  getEnvFilePath,
  getExtensionDir,
  TRANSLATIONS_DIR,
  MULTILINGUAL_METADATA_FILENAME,
  getTranslationsDir,
  getMultilingualMetadataPath,
  getDebugLogPath,
  ASTRO_APP_CONFIG_PATH,
  astroAppConfigSchema,
  getAstroAppConfigPath,
  loadProjectModel,
  ProjectModelProvider,
  useProjectModel,
  useSiteConfig
};
//# sourceMappingURL=chunk-RDF2RA4E.js.map