import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  useCreatePreview
} from "./chunk-JHA55BW5.js";
import {
  DeploymentStatus,
  useDocumentManagementClient
} from "./chunk-QVQMIH5X.js";
import "./chunk-22SU6O2P.js";
import "./chunk-MYWHJYA3.js";
import "./chunk-BSHLAJFZ.js";
import "./chunk-4EUYO6LF.js";
import "./chunk-DZ3U3XXP.js";
import "./chunk-4HM4GXIT.js";
import "./chunk-MK2ZHK32.js";
import "./chunk-526J7NQD.js";
import "./chunk-XCIXZDFH.js";
import "./chunk-QRGKMYDD.js";
import "./chunk-HEKVXBWZ.js";
import "./chunk-JJWBWHWO.js";
import "./chunk-YTGCPERW.js";
import {
  ErrorViewer
} from "./chunk-VZ3FZHJK.js";
import "./chunk-OWRWPLVG.js";
import {
  Trans,
  useTranslation
} from "./chunk-CIOBCAOI.js";
import "./chunk-RPTAJN5Y.js";
import {
  Alert,
  Badge,
  Box_default,
  ConfirmInput,
  Link,
  Spinner,
  useAsync,
  useAsyncCallback
} 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 {
  require_lib
} from "./chunk-PIOT47FJ.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site/src/components/PublishCommand/PublishCommand.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
var import_variant = __toESM(require_lib(), 1);
var PublishCommand = ({ approvePreview, force }) => {
  const { t } = useTranslation();
  const createPreview = useCreatePreview();
  const { publishDeployment } = useDocumentManagementClient();
  const publishDeploymentAction = useAsyncCallback(
    async (_, deploymentId) => publishDeployment(deploymentId)
  );
  const { status } = useAsync(async () => {
    const preview = await createPreview();
    const preApprovePreview = force || ((0, import_variant.isType)(preview.deploymentStatus, DeploymentStatus.Success) ? approvePreview : false);
    if (preApprovePreview) {
      void publishDeploymentAction.execute(preview.deploymentId);
    }
    return {
      ...preview,
      preApprovePreview
    };
  }, []);
  return (0, import_variant.match)(status, {
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react.default.createElement(Spinner, { text: /* @__PURE__ */ import_react.default.createElement(Trans, { i18nKey: "publish_command.preview.loading" }) }),
    Success: ({ result }) => {
      return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, (0, import_variant.match)(result.deploymentStatus, {
        Success: () => /* @__PURE__ */ import_react.default.createElement(Alert, { type: "success" }, /* @__PURE__ */ import_react.default.createElement(
          Trans,
          {
            i18nKey: "publish_command.preview.success",
            components: [/* @__PURE__ */ import_react.default.createElement(Link, { url: result.previewUrl })]
          }
        )),
        Error: ({ deploymentError }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(ErrorViewer, { error: deploymentError }), /* @__PURE__ */ import_react.default.createElement(Box_default, { marginTop: 1 }, /* @__PURE__ */ import_react.default.createElement(Alert, { type: "warning" }, /* @__PURE__ */ import_react.default.createElement(Trans, { i18nKey: "publish_command.preview.warning" }))))
      }), !result.preApprovePreview && /* @__PURE__ */ import_react.default.createElement(Box_default, { marginTop: 1 }, /* @__PURE__ */ import_react.default.createElement(
        ConfirmInput,
        {
          label: t("publish_command.confirm_publish"),
          onSubmit: (value) => {
            if (value) {
              void publishDeploymentAction.execute(result.deploymentId);
            }
          }
        }
      )), (0, import_variant.match)(publishDeploymentAction.status, {
        NotRequested: () => null,
        Error: () => null,
        Loading: () => /* @__PURE__ */ import_react.default.createElement(Box_default, { marginTop: 1 }, /* @__PURE__ */ import_react.default.createElement(
          Spinner,
          {
            text: /* @__PURE__ */ import_react.default.createElement(Trans, { i18nKey: "publish_command.publish.loading" })
          }
        )),
        Success: () => /* @__PURE__ */ import_react.default.createElement(Box_default, { marginTop: 1 }, /* @__PURE__ */ import_react.default.createElement(Alert, { type: "success" }, /* @__PURE__ */ import_react.default.createElement(Badge, { skin: "success" }, /* @__PURE__ */ import_react.default.createElement(Trans, { i18nKey: "general.success" })), " ", /* @__PURE__ */ import_react.default.createElement(
          Trans,
          {
            i18nKey: "publish_command.publish.success",
            components: [/* @__PURE__ */ import_react.default.createElement(Link, { url: result.siteUrl })]
          }
        )))
      }));
    }
  });
};
export {
  PublishCommand
};
//# sourceMappingURL=PublishCommand-EUMOWDMN.js.map