import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  useBackendAsAServiceClient
} from "./chunk-I2LFFO2M.js";
import {
  ENV_FILE_NAME,
  getEnvFilePath,
  useProjectModel
} from "./chunk-BYP4JZFS.js";
import {
  SiteAuthProvider
} from "./chunk-YHFCDWGT.js";
import {
  Alert,
  Spinner,
  useAsync
} from "./chunk-QK47PIWK.js";
import {
  require_react
} from "./chunk-TODKQSCF.js";
import {
  updateEnvFile
} from "./chunk-AYCGCYN3.js";
import {
  require_lib
} from "./chunk-WGV2XQSB.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-astro-commands/src/components/EnvPullCommand/index.ts
init_esm_shims();

// ../cli-astro-commands/src/components/EnvPullCommand/EnvPullCommand.tsx
init_esm_shims();
var import_react2 = __toESM(require_react(), 1);

// ../cli-astro-commands/src/components/EnvPullCommand/EnvPull.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
var import_variant = __toESM(require_lib(), 1);
var ENV_NAME = "prod";
var EnvPull = () => {
  const { model } = useProjectModel();
  const backendAsAServiceClient = useBackendAsAServiceClient();
  const { status } = useAsync(async () => {
    const appEnvironment = await backendAsAServiceClient.getAppEnvironmentByName(
      model.config.appId,
      ENV_NAME
    );
    await updateEnvFile(getEnvFilePath(model.projectFolder), {
      ...appEnvironment.variables,
      ...appEnvironment.secrets
    });
  }, []);
  return (0, import_variant.match)(status, {
    Loading: () => /* @__PURE__ */ import_react.default.createElement(Spinner, { text: `Pulling environment "${ENV_NAME}" variables...` }),
    Success: () => /* @__PURE__ */ import_react.default.createElement(Alert, { type: "success" }, 'Environment variables written to "', ENV_FILE_NAME, '"'),
    Error: () => null,
    NotRequested: () => null
  });
};

// ../cli-astro-commands/src/components/EnvPullCommand/EnvPullCommand.tsx
var EnvPullCommand = () => {
  const {
    model: { config }
  } = useProjectModel();
  let commandTree = /* @__PURE__ */ import_react2.default.createElement(EnvPull, null);
  if (config.projectType === "Site") {
    commandTree = /* @__PURE__ */ import_react2.default.createElement(SiteAuthProvider, { siteId: config.siteId }, commandTree);
  }
  return commandTree;
};

export {
  EnvPullCommand
};
//# sourceMappingURL=chunk-3DTNL7YA.js.map