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