import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  ProjectModelProvider,
  loadProjectModel
} from "./chunk-VLXZIAOF.js";
import {
  messages_default
} from "./chunk-7S4TD3NR.js";
import {
  HttpClientProvider,
  buildHttpClientHeaders
} from "./chunk-BRX4HWJE.js";
import {
  PanoramaProvider,
  createCommandTransaction
} from "./chunk-ZBFOAJ5H.js";
import "./chunk-YNEGRO3E.js";
import {
  addUserFields,
  reportCommandStartEvent
} from "./chunk-HENH75UF.js";
import {
  BiProvider,
  ErrorReporterProvider,
  SiteAuthProvider
} from "./chunk-YHFCDWGT.js";
import "./chunk-IVQPYJ5M.js";
import {
  I18nProvider
} from "./chunk-MDUBZZTI.js";
import "./chunk-RPTAJN5Y.js";
import {
  render
} from "./chunk-QK47PIWK.js";
import {
  require_react
} from "./chunk-TODKQSCF.js";
import "./chunk-AFPDHQYI.js";
import "./chunk-HYKBBZLS.js";
import "./chunk-C5RTKQVL.js";
import "./chunk-DGJS6KZB.js";
import "./chunk-YT5BPQDJ.js";
import "./chunk-LU3R3EBR.js";
import "./chunk-XZUGLEBK.js";
import "./chunk-AYCGCYN3.js";
import "./chunk-SDLCFZRL.js";
import "./chunk-WGV2XQSB.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-RTBETXWA.js.map