import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  useWixCliAppBi
} from "./chunk-RDXUYCUV.js";
import {
  PreviewCommand
} from "./chunk-FYSBORKA.js";
import {
  useDevCenterOverridesClient
} from "./chunk-4LXQCSMI.js";
import {
  assertBuildOutputExists
} from "./chunk-BQGAAIC6.js";
import "./chunk-VKQEX5GC.js";
import "./chunk-ZY7YHRZR.js";
import "./chunk-DLEBD2WZ.js";
import "./chunk-RTNIG6ZW.js";
import "./chunk-O6HC4AYN.js";
import "./chunk-QRGKMYDD.js";
import {
  ComponentType
} from "./chunk-M6WJXTS4.js";
import {
  useBackendAsAServiceClient
} from "./chunk-FEA7FYAB.js";
import "./chunk-RF4NA2OH.js";
import "./chunk-NMCF7XG5.js";
import "./chunk-MHV22UIU.js";
import {
  useProjectModel,
  useSiteConfig
} from "./chunk-RDF2RA4E.js";
import "./chunk-AAUVYJJT.js";
import "./chunk-K6JLY75P.js";
import "./chunk-WFQIXGJV.js";
import "./chunk-ECBO3UFC.js";
import {
  require_isArray
} from "./chunk-YNEGRO3E.js";
import {
  SiteAuthProvider,
  require_semver
} from "./chunk-HWT3LUJJ.js";
import "./chunk-TOBTRYZF.js";
import "./chunk-7WVNO7VU.js";
import "./chunk-RPTAJN5Y.js";
import {
  Alert,
  Box_default,
  Cart,
  ConfirmInput,
  Link,
  Notification,
  SelectInput,
  SelectOptionAvailability,
  Spinner,
  Statistics,
  Text,
  TextInput,
  useAsync,
  useAsyncCallback
} from "./chunk-YL4347CI.js";
import {
  require_baseGetTag,
  require_isObjectLike,
  require_react
} from "./chunk-TODKQSCF.js";
import "./chunk-AFPDHQYI.js";
import "./chunk-HYKBBZLS.js";
import "./chunk-C5RTKQVL.js";
import "./chunk-SVUXJRFD.js";
import "./chunk-YT5BPQDJ.js";
import "./chunk-LU3R3EBR.js";
import "./chunk-XZUGLEBK.js";
import "./chunk-VASURI4S.js";
import "./chunk-SDLCFZRL.js";
import {
  CliError,
  CliErrorCode,
  require_lib
} from "./chunk-MTT3QXBC.js";
import {
  __commonJS,
  __toESM,
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../../node_modules/lodash/isString.js
var require_isString = __commonJS({
  "../../node_modules/lodash/isString.js"(exports, module) {
    "use strict";
    init_esm_shims();
    var baseGetTag = require_baseGetTag();
    var isArray = require_isArray();
    var isObjectLike = require_isObjectLike();
    var stringTag = "[object String]";
    function isString2(value) {
      return typeof value == "string" || !isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag;
    }
    module.exports = isString2;
  }
});

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

// ../cli-astro-commands/src/components/ReleaseCommand/ReleaseCommand.tsx
init_esm_shims();
var import_react9 = __toESM(require_react(), 1);
var import_variant3 = __toESM(require_lib(), 1);

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

// ../cli-astro-commands/src/components/ReleaseCommand/Steps/CreatePreview.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
var CreatePreview = (props) => {
  const { baseUrl, label, onCreated } = props;
  return /* @__PURE__ */ import_react.default.createElement(Box_default, { flexDirection: "column", gap: 1 }, /* @__PURE__ */ import_react.default.createElement(Text, null, "Before creating a new version, let's create a preview of your app"), /* @__PURE__ */ import_react.default.createElement(Box_default, { flexDirection: "column" }, /* @__PURE__ */ import_react.default.createElement(
    PreviewCommand,
    {
      baseUrl,
      label,
      onPreviewCreated: onCreated,
      environment: "production"
    }
  )));
};

// ../cli-astro-commands/src/components/ReleaseCommand/ReleaseSite.tsx
var ReleaseSite = ({
  baseUrl,
  label,
  createMinorVersion,
  comment
}) => {
  const { appId } = useSiteConfig();
  const { getAppProject } = useBackendAsAServiceClient();
  const { release } = useDevCenterOverridesClient();
  const releaseAction = useAsyncCallback(async (_, tag) => {
    const deploymentBaseUrl = await release(appId, tag, {
      createMinorVersion,
      comment
    });
    const appProject = await getAppProject(appId);
    return { baseUrl: appProject?.customDomain?.domain ?? deploymentBaseUrl };
  });
  function onPreviewCreated({ previewId }) {
    return releaseAction.execute(previewId);
  }
  return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(
    CreatePreview,
    {
      baseUrl,
      label,
      onCreated: onPreviewCreated
    }
  ), (0, import_variant.match)(releaseAction.status, {
    NotRequested: () => null,
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react2.default.createElement(Spinner, { text: /* @__PURE__ */ import_react2.default.createElement(Text, null, "Releasing...") }),
    Success: ({ result: { baseUrl: baseUrl2 } }) => /* @__PURE__ */ import_react2.default.createElement(Box_default, { flexDirection: "column", gap: 1 }, /* @__PURE__ */ import_react2.default.createElement(Alert, { type: "success" }, /* @__PURE__ */ import_react2.default.createElement(Text, { bold: true }, "Site published on ", baseUrl2)))
  }));
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/ReleaseApp.tsx
init_esm_shims();
var import_react8 = __toESM(require_react(), 1);
var import_isString = __toESM(require_isString(), 1);
var import_semver = __toESM(require_semver(), 1);
var import_variant2 = __toESM(require_lib(), 1);

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/Warnings.tsx
init_esm_shims();
var import_react3 = __toESM(require_react(), 1);
var Warnings = ({
  components
}) => {
  if (components.filter((c) => c.compType === ComponentType.WEBHOOK).length === 0) {
    return null;
  }
  return /* @__PURE__ */ import_react3.default.createElement(Box_default, { flexDirection: "column", paddingBottom: 1 }, /* @__PURE__ */ import_react3.default.createElement(Notification, null, /* @__PURE__ */ import_react3.default.createElement(Alert, { type: "warning" }, "Your project includes backend events. Once you continue, any changes to events will be immediately deployed to production and take effect automatically, even without a new version release.")));
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/ReleaseComment.tsx
init_esm_shims();
var import_react4 = __toESM(require_react(), 1);
var ReleaseComment = (props) => {
  const { onEntered } = props;
  const bi = useWixCliAppBi();
  const validate = (0, import_react4.useCallback)((value) => {
    if (value && value.length > 250) {
      return "The comment is limited to a maximum of 250 characters";
    }
    return true;
  }, []);
  const question = "Enter a comment describing any changes made to this version. This won't be shown to users (optional)";
  return /* @__PURE__ */ import_react4.default.createElement(
    TextInput,
    {
      label: question,
      onSubmit: (answer) => {
        bi.cliFlowStepAnswered({
          question,
          questionKey: "release_command.enter_release_comment",
          answer
        });
        onEntered(answer);
      },
      validate
    }
  );
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/ConfirmMinorVersion.tsx
init_esm_shims();
var import_react5 = __toESM(require_react(), 1);
var ConfirmMinorVersion = (props) => {
  const { onConfirmed } = props;
  const bi = useWixCliAppBi();
  const question = "Changes will be visible to your app users immediately and can\u2019t be undone. Do you want to continue?";
  return /* @__PURE__ */ import_react5.default.createElement(Box_default, { flexDirection: "column", paddingBottom: 1 }, /* @__PURE__ */ import_react5.default.createElement(
    ConfirmInput,
    {
      label: question,
      initialValue: true,
      onSubmit: (confirm) => {
        bi.cliFlowStepAnswered({
          question,
          questionKey: "release_command.confirm_version_creation",
          answer: String(confirm)
        });
        if (confirm) {
          onConfirmed();
        }
      }
    }
  ));
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/ChooseVersion.tsx
init_esm_shims();
var import_react6 = __toESM(require_react(), 1);
var ChooseVersion = (props) => {
  const { nextMinor, nextMajor, onChosen } = props;
  const bi = useWixCliAppBi();
  const options = [
    {
      title: nextMinor ? `Minor (${nextMinor})` : "Minor",
      description: "update doesn\u2019t require Wix user consent",
      value: "MINOR" /* MINOR */,
      availability: nextMinor ? SelectOptionAvailability.Enabled() : SelectOptionAvailability.Disabled({
        reason: /* @__PURE__ */ import_react6.default.createElement(Text, null, "Recent changes you made require this release to be a major release. ", /* @__PURE__ */ import_react6.default.createElement(Link, { url: "https://wix.to/ZR80Y7p" }, "Learn more"))
      })
    },
    {
      title: `Major (${nextMajor})`,
      description: "update requires Wix user consent",
      value: "MAJOR" /* MAJOR */
    }
  ];
  const question = "What type of version would you like to create?";
  return /* @__PURE__ */ import_react6.default.createElement(
    SelectInput,
    {
      label: question,
      options,
      initialIndex: nextMinor ? 0 : 1,
      onSubmit: ({ value }) => {
        bi.cliFlowStepAnswered({
          question,
          questionKey: "release_command.version_type_question",
          answer: value
        });
        onChosen(value);
      }
    }
  );
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/NextSteps.tsx
init_esm_shims();
var import_react7 = __toESM(require_react(), 1);
var NextSteps = () => {
  const {
    model: {
      config: { appId }
    }
  } = useProjectModel();
  const homeUrl = `https://dev.wix.com/apps/${appId}/home?referralInfo=wix-cli`;
  const statisticsUrl = `https://dev.wix.com/apps/${appId}/statistics?referralInfo=wix-cli`;
  return /* @__PURE__ */ import_react7.default.createElement(Box_default, { flexDirection: "column", gap: 1 }, /* @__PURE__ */ import_react7.default.createElement(Text, { bold: true }, "Next Steps:"), /* @__PURE__ */ import_react7.default.createElement(Text, null, /* @__PURE__ */ import_react7.default.createElement(Statistics, null), " View your app reviews and statistics in the", " ", /* @__PURE__ */ import_react7.default.createElement(Link, { url: statisticsUrl }, "app dashboard")), /* @__PURE__ */ import_react7.default.createElement(Text, null, /* @__PURE__ */ import_react7.default.createElement(Cart, null), " Select your distribution method from the", " ", /* @__PURE__ */ import_react7.default.createElement(Link, { url: homeUrl }, "app dashboard")));
};

// ../cli-astro-commands/src/components/ReleaseCommand/app-flow/ReleaseApp.tsx
var ReleaseApp = ({
  baseUrl,
  label,
  preEnteredComment,
  preSelectedVersionType
}) => {
  const {
    model: {
      config: { appId }
    }
  } = useProjectModel();
  const { createDraftVersion, releaseDraftVersion } = useDevCenterOverridesClient();
  const [preview, setPreview] = (0, import_react8.useState)();
  const [comment, setComment] = (0, import_react8.useState)();
  const [versionType, setVersionType] = (0, import_react8.useState)();
  const [userShouldSelectVersion, setUserShouldSelectVersion] = (0, import_react8.useState)(false);
  const createDraftAction = useAsyncCallback(async (_, tag) => {
    const { nextMajor, nextMinor } = await createDraftVersion(appId, tag);
    const appWasNeverReleased = nextMajor === "1.0.0" && !nextMinor;
    const parsedNextMajor = (0, import_semver.parse)(nextMajor);
    if (parsedNextMajor == null) {
      throw new CliError({
        code: CliErrorCode.FailedToParseNextVersion({ version: nextMajor }),
        cause: void 0
      });
    }
    return {
      nextMinor,
      nextMajor,
      appWasNeverReleased,
      latestMajor: parsedNextMajor.major - 1
    };
  });
  const releaseDraftAction = useAsyncCallback(
    async (_, versionType2, comment2, latestMajor) => {
      const result = await releaseDraftVersion(appId, {
        createNewMajor: versionType2 === "MAJOR" /* MAJOR */,
        notes: comment2,
        latestMajor
      });
      return result;
    }
  );
  async function onReleaseCommentEntered({
    tag,
    comment: comment2
  }) {
    setComment(comment2);
    const result = await createDraftAction.execute(tag).catch(() => null);
    if (!result) {
      return;
    }
    const { appWasNeverReleased, nextMinor, latestMajor } = result;
    const chosenVersion = appWasNeverReleased ? "MAJOR" /* MAJOR */ : preSelectedVersionType;
    if (preSelectedVersionType === "MINOR" /* MINOR */ && (appWasNeverReleased || !nextMinor)) {
      throw new CliError({
        cause: null,
        code: CliErrorCode.CannotReleaseMinorInNoninteractive()
      });
    }
    if (chosenVersion) {
      void releaseDraftAction.execute(chosenVersion, comment2, latestMajor);
    } else {
      setUserShouldSelectVersion(true);
    }
  }
  return /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, /* @__PURE__ */ import_react8.default.createElement(
    CreatePreview,
    {
      baseUrl,
      label,
      onCreated: (result) => {
        setPreview(result);
        if ((0, import_isString.default)(preEnteredComment)) {
          void onReleaseCommentEntered({
            tag: result.previewId,
            comment: preEnteredComment
          });
        }
      }
    }
  ), preview && /* @__PURE__ */ import_react8.default.createElement(Warnings, { components: preview.appManifest.components }), preview && !(0, import_isString.default)(preEnteredComment) && /* @__PURE__ */ import_react8.default.createElement(
    ReleaseComment,
    {
      onEntered: (comment2) => onReleaseCommentEntered({ tag: preview.previewId, comment: comment2 })
    }
  ), (0, import_isString.default)(comment) && (0, import_variant2.match)(createDraftAction.status, {
    NotRequested: () => null,
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react8.default.createElement(Spinner, { text: "Updating draft application version" }),
    Success: ({ result: { nextMajor, nextMinor, latestMajor } }) => /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, userShouldSelectVersion && /* @__PURE__ */ import_react8.default.createElement(
      ChooseVersion,
      {
        nextMinor,
        nextMajor,
        onChosen: (selectedVersionType) => {
          setVersionType(selectedVersionType);
          if (selectedVersionType === "MAJOR" /* MAJOR */) {
            void releaseDraftAction.execute(
              selectedVersionType,
              comment,
              latestMajor
            );
          }
        }
      }
    ), versionType === "MINOR" /* MINOR */ && /* @__PURE__ */ import_react8.default.createElement(
      ConfirmMinorVersion,
      {
        onConfirmed: () => releaseDraftAction.execute(
          versionType,
          comment,
          latestMajor
        )
      }
    ))
  }), (0, import_variant2.match)(releaseDraftAction.status, {
    NotRequested: () => null,
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react8.default.createElement(Spinner, { text: "Releasing..." }),
    Success: ({ result: { releasedVersion } }) => /* @__PURE__ */ import_react8.default.createElement(Box_default, { flexDirection: "column", gap: 1 }, /* @__PURE__ */ import_react8.default.createElement(Alert, { type: "success" }, /* @__PURE__ */ import_react8.default.createElement(Text, { bold: true }, "Version ", releasedVersion, " was created")), /* @__PURE__ */ import_react8.default.createElement(NextSteps, null))
  }));
};

// ../cli-astro-commands/src/components/ReleaseCommand/ReleaseCommand.tsx
var ReleaseCommand = (props) => {
  const {
    model: { projectFolder, config }
  } = useProjectModel();
  const { status } = useAsync(async () => {
    await assertBuildOutputExists(projectFolder);
  }, []);
  return (0, import_variant3.match)(status, {
    Error: () => null,
    Loading: () => /* @__PURE__ */ import_react9.default.createElement(Spinner, { text: /* @__PURE__ */ import_react9.default.createElement(Text, null, "Loading application details...") }),
    Success: () => {
      return config.projectType === "Site" ? /* @__PURE__ */ import_react9.default.createElement(SiteAuthProvider, { siteId: config.siteId }, /* @__PURE__ */ import_react9.default.createElement(
        ReleaseSite,
        {
          ...props,
          createMinorVersion: props.versionType === "MINOR" /* MINOR */
        }
      )) : /* @__PURE__ */ import_react9.default.createElement(
        ReleaseApp,
        {
          baseUrl: props.baseUrl,
          label: props.label,
          preEnteredComment: props.comment,
          preSelectedVersionType: props.versionType
        }
      );
    }
  });
};
export {
  ReleaseCommand
};
//# sourceMappingURL=ReleaseCommand-JBIRZTOC.js.map