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/systemSettings/registry/components/GroupModal.tsx
var GroupModal_exports = {};
__export(GroupModal_exports, {
  default: () => GroupModal_default
});
module.exports = __toCommonJS(GroupModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("../locales"));
var getText = (key) => {
  const globalText = import_utils.locales.getText(key);
  if (globalText !== key) {
    return globalText;
  }
  const currentLocale = import_utils.locales.locale || "zh-CN";
  const localeData = import_locales.default[currentLocale] || import_locales.default["en"] || {};
  return localeData[key] || key;
};
var GroupModal = ({
  open,
  type,
  data,
  onOk,
  onCancel
}) => {
  const [form] = import_antd.Form.useForm();
  (0, import_react.useEffect)(() => {
    if (open) {
      if (type === "edit" && data) {
        form.setFieldsValue({
          title: data.title,
          code: data.code,
          description: data == null ? void 0 : data.description
        });
      } else {
        form.resetFields();
      }
    }
  }, [open, type, data, form]);
  const handleOk = async () => {
    try {
      const values = await form.validateFields();
      await onOk(values);
      form.resetFields();
    } catch (error) {
      console.error("Validation failed:", error);
    }
  };
  const handleCancel = () => {
    form.resetFields();
    onCancel();
  };
  const title = import_utils.locales.getText(
    type === "add" ? "registry.modal.add.group" : "registry.modal.edit.group"
  );
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Drawer,
    {
      title,
      open,
      onClose: handleCancel,
      width: 400,
      destroyOnClose: true,
      footer: /* @__PURE__ */ import_react.default.createElement("div", { style: { textAlign: "right" } }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { size: "small" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { onClick: handleCancel }, import_utils.locales.getText("registry.button.cancel")), /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "primary", onClick: handleOk }, import_utils.locales.getText("registry.button.save"))))
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { form, layout: "vertical", requiredMark: true }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        name: "title",
        label: import_utils.locales.getText("registry.form.title"),
        rules: [
          {
            required: true,
            message: import_utils.locales.getText("registry.message.required")
          }
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.BaseTranslation,
        {
          placeholder: import_utils.locales.getText("registry.form.name.placeholder")
        }
      )
    ), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        name: "code",
        label: import_utils.locales.getText("registry.form.code"),
        rules: [
          {
            required: true,
            message: import_utils.locales.getText("registry.message.required")
          },
          {
            validator: (_, value) => {
              if (!value) return Promise.resolve();
              if (!/^[a-z0-9\._]+$/.test(value)) {
                return Promise.reject(
                  new Error(getText("registry.message.code.format"))
                );
              }
              if (!/^[a-z]/.test(value)) {
                return Promise.reject(
                  new Error(getText("registry.message.code.start"))
                );
              }
              if (/[\._]$/.test(value)) {
                return Promise.reject(
                  new Error(getText("registry.message.code.end"))
                );
              }
              if (/[\.]{2,}|[\_]{2,}/.test(value)) {
                return Promise.reject(
                  new Error(getText("registry.message.code.consecutive"))
                );
              }
              return Promise.resolve();
            }
          }
        ]
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_antd.Input,
        {
          placeholder: import_utils.locales.getText("registry.form.code.placeholder")
        }
      )
    ), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Form.Item,
      {
        name: "description",
        label: import_utils.locales.getText("registry.form.description")
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.BaseTranslation,
        {
          placeholder: import_utils.locales.getText(
            "registry.form.description.placeholder"
          ),
          renderMode: "edit"
        }
      )
    ))
  );
};
var GroupModal_default = GroupModal;
