var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/versionModal/index.tsx
var versionModal_exports = {};
__export(versionModal_exports, {
  default: () => versionModal_default
});
module.exports = __toCommonJS(versionModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_pisellModal = __toESM(require("../pisellModal"));
var import_versionSelect = __toESM(require("../versionSelect"));
var import_locales = require("../../locales");
var import_index = require("./index.less");
var style = {
  display: "flex",
  flexDirection: "column",
  gap: 8
};
var parseVersion = (version) => {
  const [major, minor, patch] = version.split(".").map(Number);
  return [major || 0, minor || 0, patch || 0];
};
var isVersionValid = (customVersion, currentVersion) => {
  const [cMajor, cMinor, cPatch] = parseVersion(customVersion);
  const [liveMajor, liveMinor, livePatch] = parseVersion(currentVersion);
  if (cMajor > liveMajor)
    return true;
  if (cMajor === liveMajor && cMinor > liveMinor)
    return true;
  if (cMajor === liveMajor && cMinor === liveMinor && cPatch > livePatch)
    return true;
  return false;
};
var getNextVersions = (version) => {
  const [major, minor, patch] = parseVersion(version);
  return {
    patch: `${major}.${minor}.${patch + 1}`,
    minor: `${major}.${minor + 1}.0`,
    major: `${major + 1}.0.0`
  };
};
var PublishVersionModal = ({
  visible,
  currentVersion = "1.0.0",
  onCancel,
  onConfirm,
  isShowNote,
  confirmLoading = false,
  versions = [],
  isShowBasedOn,
  isShowCurrentVersion,
  isValidateVersion = true
}) => {
  const [form] = import_antd.Form.useForm();
  const [versionType, setVersionType] = (0, import_react.useState)("");
  const { patch, minor, major } = getNextVersions(currentVersion);
  const handleVersionChange = (e) => {
    setVersionType(e.target.value);
  };
  const handleSubmit = () => {
    form.validateFields().then((values) => {
      let { version, note, baseVersion } = values;
      let versionType2 = "";
      if (version === "custom") {
        versionType2 = "custom";
        if (isValidateVersion && !isVersionValid(
          `${values.major}.${values.minor}.${values.patch}`,
          currentVersion
        )) {
          import_antd.message.error((0, import_locales.getText)("pisell-version-modal-version-error"));
          return;
        }
        version = `${values.major}.${values.minor}.${values.patch}`;
      }
      onConfirm({ version, note, baseVersion, versionType: versionType2 });
    });
  };
  (0, import_react.useEffect)(() => {
    if (visible) {
      setVersionType("");
      form.setFieldsValue({
        version: patch,
        major: parseVersion(patch)[0] || 0,
        minor: parseVersion(patch)[1] || 0,
        patch: parseVersion(patch)[2] || 0,
        baseVersion: currentVersion
      });
    }
  }, [visible]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_pisellModal.default,
    {
      title: (0, import_locales.getText)("pisell-version-modal-title"),
      open: visible,
      onCancel,
      destroyOnClose: true,
      onOk: handleSubmit,
      okText: (0, import_locales.getText)("pisell-version-modal-confirm"),
      cancelText: (0, import_locales.getText)("pisell-version-modal-cancel"),
      confirmLoading
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form,
      {
        form,
        layout: "vertical",
        preserve: false,
        className: "pisell-lowcode-version-modal-form"
      },
      isShowCurrentVersion && /* @__PURE__ */ import_react.default.createElement("p", { className: "pisell-lowcode-version-modal-current-version" }, (0, import_locales.getText)("pisell-version-modal-current-version"), ": ", currentVersion),
      isShowBasedOn && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          label: (0, import_locales.getText)("pisell-version-modal-based-on-version"),
          name: "baseVersion",
          initialValue: currentVersion,
          rules: [{ required: true }]
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_versionSelect.default,
          {
            versions,
            fieldNames: { label: "label", value: "version", options: "options" }
          }
        )
      ),
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          label: (0, import_locales.getText)("pisell-version-modal-version"),
          name: "version",
          initialValue: "patch",
          rules: [{ required: true }]
        },
        /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Group, { onChange: handleVersionChange, style }, /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: patch }, (0, import_locales.getText)("pisell-version-modal-patch"), " (", patch, ")"), /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: minor }, (0, import_locales.getText)("pisell-version-modal-minor"), " (", minor, ")"), /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: major }, (0, import_locales.getText)("pisell-version-modal-major"), " (", major, ")"), /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: "custom" }, (0, import_locales.getText)("pisell-version-modal-custom")))
      ),
      versionType === "custom" && /* @__PURE__ */ import_react.default.createElement(import_antd.Row, { gutter: 8 }, /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 8 }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "major",
          label: (0, import_locales.getText)("pisell-version-modal-major"),
          rules: [
            {
              required: true,
              message: (0, import_locales.getText)("pisell-version-modal-version-required")
            }
          ]
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.InputNumber,
          {
            min: 0,
            precision: 0,
            style: { width: "100%" },
            placeholder: (0, import_locales.getText)("pisell-version-modal-major")
          }
        )
      )), /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 8 }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "minor",
          label: (0, import_locales.getText)("pisell-version-modal-minor"),
          rules: [
            {
              required: true,
              message: (0, import_locales.getText)("pisell-version-modal-version-required")
            }
          ]
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.InputNumber,
          {
            precision: 0,
            min: 0,
            style: { width: "100%" },
            placeholder: (0, import_locales.getText)("pisell-version-modal-minor")
          }
        )
      )), /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 8 }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          name: "patch",
          label: (0, import_locales.getText)("pisell-version-modal-patch"),
          rules: [
            {
              required: true,
              message: (0, import_locales.getText)("pisell-version-modal-version-required")
            }
          ]
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.InputNumber,
          {
            min: 0,
            precision: 0,
            style: { width: "100%" },
            placeholder: (0, import_locales.getText)("pisell-version-modal-patch")
          }
        )
      ))),
      isShowNote && /* @__PURE__ */ import_react.default.createElement(
        import_antd.Form.Item,
        {
          label: (0, import_locales.getText)("pisell-version-modal-update-notes"),
          name: "note"
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Input.TextArea,
          {
            placeholder: (0, import_locales.getText)(
              "pisell-version-modal-describe-update-notes"
            )
          }
        )
      )
    )
  );
};
var versionModal_default = PublishVersionModal;
