const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_hoc = require("../../utils/hoc.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
//#region src/components/form/index.tsx
const _excluded = ["values"], _excluded2 = ["children"];
var Form = class extends react.Component {
	constructor(..._args) {
		super(..._args);
		this.formRef = (0, 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 _this$props = this.props, { values } = _this$props, rest = require_objectWithoutProperties._objectWithoutProperties(_this$props, _excluded);
		return /* @__PURE__ */ react.default.createElement(antd.Form, require_objectSpread2._objectSpread2({ ref: this.formRef }, rest));
	}
};
Form.Item = (props) => {
	const { name, rules: propsRules, requiredobj, typeobj, patternobj, subdomainobj, phoneobj, mobileobj, lenobj, validator } = props;
	const rules = (0, _pisell_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 } = props, other = require_objectWithoutProperties._objectWithoutProperties(props, _excluded2);
	let node = children;
	if (Array.isArray(children) && children.length === 1) node = children[0];
	return /* @__PURE__ */ react.default.createElement(antd.Form.Item, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, other), {}, {
		name: namePath,
		rules
	}), node);
};
Form.List = require_hoc.withSingleFunctionChild(antd.Form.List);
//#endregion
exports.default = Form;
