const require_runtime = require("../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let lodash = require("lodash");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
//#region src/utils/hoc.tsx
function convertProps(props, list, mapper) {
	const out = {};
	list.forEach((key) => {
		if ((0, lodash.has)(props, key)) (0, lodash.set)(out, key, mapper((0, lodash.get)(props, key), key));
	});
	return out;
}
/**
* 简单包装，不做任何处理
* 部分组件ref比较特殊，包一层会解决这个问题
*/
function withWrap(Comp) {
	return (props) => {
		return /* @__PURE__ */ react.default.createElement(Comp, props);
	};
}
/**
* 某些组件会用React.Children.only检查子节点
* 需要做处理避免报错
*/
function withSingleChild(Comp, needsConvert = ["children"]) {
	return (props) => {
		const convertedProps = convertProps(props, needsConvert, (prop) => {
			let node = react.default.Children.toArray(prop)[0];
			if (node === null || typeof node !== "object") node = /* @__PURE__ */ react.default.createElement("div", null, node);
			return node;
		});
		return /* @__PURE__ */ react.default.createElement(Comp, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), convertedProps));
	};
}
function withSingleFunctionChild(Comp) {
	return (props) => {
		const { children } = props;
		let node;
		if (typeof children === "function") node = children;
		if (Array.isArray(children) && children.length === 1 && typeof children[0] === "function") node = children[0];
		if (node) return /* @__PURE__ */ react.default.createElement(Comp, props, node);
		return /* @__PURE__ */ react.default.createElement("div", null, children);
	};
}
/**
* moment对象在序列化后会被转为字符串
* 需要让日期类组件支持接受字符串值
*/
function withMomentProps(Comp, needsConvert = ["value", "defaultValue"]) {
	return (props) => {
		const convertedProps = convertProps(props, needsConvert, (prop) => {
			if (prop) {
				if (Array.isArray(prop)) return prop.map((v) => dayjs.default.isDayjs(v) ? v : (0, dayjs.default)(v));
				return dayjs.default.isDayjs(prop) ? prop : (0, dayjs.default)(prop);
			}
		});
		return /* @__PURE__ */ react.default.createElement(Comp, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), convertedProps));
	};
}
//#endregion
exports.withMomentProps = withMomentProps;
exports.withSingleChild = withSingleChild;
exports.withSingleFunctionChild = withSingleFunctionChild;
exports.withWrap = withWrap;
