import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  ProjectModelProvider,
  loadProjectModel
} from "./chunk-3USR7ERV.js";
import {
  messages_default
} from "./chunk-7S4TD3NR.js";
import {
  HttpClientProvider,
  buildHttpClientHeaders
} from "./chunk-JJWBWHWO.js";
import {
  PanoramaProvider,
  createCommandTransaction
} from "./chunk-YTGCPERW.js";
import {
  addUserFields,
  reportCommandStartEvent
} from "./chunk-V2542KTT.js";
import {
  BiProvider,
  ErrorReporterProvider,
  SiteAuthProvider
} from "./chunk-VZ3FZHJK.js";
import "./chunk-OWRWPLVG.js";
import {
  I18nProvider
} from "./chunk-CIOBCAOI.js";
import "./chunk-RPTAJN5Y.js";
import {
  render
} from "./chunk-2DKXIL7C.js";
import {
  require_react
} from "./chunk-7ZOEVDW3.js";
import "./chunk-AFPDHQYI.js";
import "./chunk-HYKBBZLS.js";
import "./chunk-C5RTKQVL.js";
import "./chunk-LFX6WS3B.js";
import "./chunk-XTVDTH5G.js";
import "./chunk-TMZBOD2B.js";
import "./chunk-DR2IE2NL.js";
import "./chunk-JWVFFICN.js";
import "./chunk-YRSNPU5L.js";
import "./chunk-PIOT47FJ.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-live/src/commands/render-command.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
import { cwd } from "node:process";
async function initServices({
  model,
  services,
  command,
  cliVersion
}) {
  const { metaSiteId, veloAppId } = model;
  const { biLogger, errorReporter, panorama } = services;
  const project = "Sites_OpenGridApp";
  errorReporter.setTag("project", project);
  errorReporter.setTag("project.app_id", veloAppId);
  errorReporter.setTag("project.site_id", metaSiteId);
  panorama.setDefaultClientData({
    cliProject: project,
    cliAppId: veloAppId,
    cliSiteId: metaSiteId
  });
  biLogger.updateDefaults({
    flow: project,
    command: command.name(),
    cliVersion,
    _msid: metaSiteId
  });
}
async function renderCommand(command, services, cliVersion, component) {
  await runCommand(command, services, cliVersion, async (model) => {
    const { biLogger, errorReporter, panorama } = services;
    const handleLogin = (userInfo) => {
      errorReporter.setUser({ id: userInfo.userId });
      addUserFields(biLogger, userInfo.userId);
    };
    const headers = buildHttpClientHeaders({
      flow: "Sites_OpenGridApp",
      command: command.name(),
      cliVersion
    });
    await render(
      /* @__PURE__ */ import_react.default.createElement(BiProvider, { value: biLogger }, /* @__PURE__ */ import_react.default.createElement(ErrorReporterProvider, { value: errorReporter }, /* @__PURE__ */ import_react.default.createElement(PanoramaProvider, { value: panorama }, /* @__PURE__ */ import_react.default.createElement(SiteAuthProvider, { siteId: model.metaSiteId, onLogin: handleLogin }, /* @__PURE__ */ import_react.default.createElement(HttpClientProvider, { headers }, /* @__PURE__ */ import_react.default.createElement(I18nProvider, { messages: messages_default }, /* @__PURE__ */ import_react.default.createElement(ProjectModelProvider, { model }, component)))))))
    );
  });
}
async function runCommand(command, services, cliVersion, commandFn) {
  const model = await loadProjectModel(cwd());
  await initServices({ model, services, command, cliVersion });
  const commandStatus = reportCommandStartEvent({
    biLogger: services.biLogger,
    command,
    cliVersion,
    flow: "Sites_OpenGridApp"
  });
  const transaction = createCommandTransaction(services.panorama, command);
  try {
    transaction.start();
    await commandFn(model);
    transaction.finish();
    commandStatus.succeed();
  } catch (e) {
    commandStatus.failed(e);
    throw e;
  }
}
export {
  renderCommand
};
//# sourceMappingURL=render-command-FJDO7DAW.js.map