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/form/index.tsx
var form_exports = {};
__export(form_exports, {
  default: () => form_default
});
module.exports = __toCommonJS(form_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_hoc = require("../../utils/hoc");
var import_utils = require("@pisell/utils");
var Form = class extends import_react.Component {
  formRef = (0, import_react.createRef)();
  componentDidUpdate(prevProps) {
    const { values: prevValues } = prevProps;
    const { values: currentValues } = this.props;
    if (prevValues !== currentValues) {
      if (currentValues && Object.keys(currentValues).length > 0) {
        this.formRef.current.setFieldsValue(currentValues);
      } else {
        this.formRef.current.resetFields();
      }
    }
  }
  componentDidMount() {
    const { values } = this.props;
    Object.defineProperties(
      this,
      Object.keys(this.formRef.current).reduce((out, key) => {
        const property = this.formRef.current[key];
        let getter = () => property;
        if (typeof property === "function") {
          getter = () => property.bind(this.formRef.current);
        }
        out[key] = { get: getter };
        return out;
      }, {})
    );
    if (values) {
      this.formRef.current.setFieldsValue(values);
    }
  }
  render() {
    const { values, ...rest } = this.props;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { ref: this.formRef, ...rest });
  }
};
Form.Item = (props) => {
  const { name, rules: propsRules, requiredobj, typeobj, patternobj, subdomainobj, phoneobj, mobileobj, lenobj, validator } = props;
  const rules = (0, import_utils.isArr)(propsRules) ? propsRules : [];
  if (requiredobj && requiredobj.required) {
    rules.push(requiredobj);
  }
  if (typeobj && typeobj.type) {
    rules.push(typeobj);
  }
  if (patternobj && patternobj.pattern) {
    rules.push(patternobj);
  }
  if (subdomainobj && subdomainobj.subdomain) {
    rules.push(subdomainobj);
  }
  if (phoneobj && phoneobj.phone) {
    rules.push(phoneobj);
  }
  if (mobileobj && mobileobj.mobile) {
    rules.push(mobileobj);
  }
  if (lenobj && (lenobj.max || lenobj.min)) {
    rules.push(lenobj);
  }
  if (validator && typeof validator === "function") {
    rules.push({
      validator: (_, value) => validator(value)
    });
  }
  const namePath = typeof name === "string" && name.indexOf(".") > 0 ? name.split(".") : name;
  const { children, ...other } = props;
  let node = children;
  if (Array.isArray(children) && children.length === 1) {
    node = children[0];
  }
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      ...other,
      name: namePath,
      rules
    },
    node
  );
};
Form.List = (0, import_hoc.withSingleFunctionChild)(import_antd.Form.List);
var form_default = Form;
