import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  veloConfigSchema
} from "./chunk-4BLGYECY.js";
import {
  require_react
} from "./chunk-TODKQSCF.js";
import {
  WIX_CONFIG_FILENAME,
  getWixConfigFilePath
} from "./chunk-YT5BPQDJ.js";
import {
  readJson,
  writeJson
} from "./chunk-AYCGCYN3.js";
import {
  CliError,
  CliErrorCode
} from "./chunk-WGV2XQSB.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-old/src/model.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);

// ../cli-site-old/src/files/velo.config.ts
init_esm_shims();
async function saveVeloConfig(projectFolder, config) {
  await writeJson(getWixConfigFilePath(projectFolder), config, {
    spaces: 2
  });
}
async function loadVeloConfig(projectFolder) {
  const configFile = await readJson(getWixConfigFilePath(projectFolder));
  try {
    return veloConfigSchema.parse(configFile);
  } catch (e) {
    throw new CliError({
      code: CliErrorCode.InvalidVeloConfigJson({
        configFilename: WIX_CONFIG_FILENAME
      }),
      cause: e
    });
  }
}

// ../cli-site-old/src/model.tsx
async function loadProjectModel(projectFolder) {
  const config = await loadVeloConfig(projectFolder);
  return {
    projectFolder,
    metaSiteId: config.siteId,
    revision: config.uiVersion
  };
}
async function saveProjectModel(model) {
  const config = {
    siteId: model.metaSiteId,
    uiVersion: model.revision
  };
  await saveVeloConfig(model.projectFolder, config);
}
var ProjectModelContext = (0, import_react.createContext)(null);
var ProjectModelProvider = ({ value: model, children }) => {
  return /* @__PURE__ */ import_react.default.createElement(ProjectModelContext.Provider, { value: { model } }, children);
};
function useProjectModel() {
  const context = (0, import_react.useContext)(ProjectModelContext);
  if (context == null) {
    throw new Error(
      "useProjectModel() cannot be used without an <ProjectModelProvider>"
    );
  }
  return context;
}

export {
  loadProjectModel,
  saveProjectModel,
  ProjectModelProvider,
  useProjectModel
};
//# sourceMappingURL=chunk-KSFSFWUC.js.map