const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_locales = require("../../utils/locales.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index = require("../../utils/index.js");
const require_server = require("./server.js");
const require_index$1 = require("./fields/index.js");
const require_index$2 = require("./card/index.js");
const require_locales$1 = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/productExtension/index.tsx
_pisell_utils.locales.init(require_locales$1.default, require_locales.getLocale());
const ProductExtension = ({ onDataChange, type }) => {
	var _extension$filed;
	const context = require_useEngineContext.default();
	require_index.request.setRequest(context.appHelper.utils.request);
	const _getProductExtensionFields = (0, ahooks.useRequest)(require_server.getProductExtensionFields, {
		manual: true,
		onSuccess: (res) => {
			onDataChange === null || onDataChange === void 0 || onDataChange(res);
		}
	});
	(0, react.useEffect)(() => {
		_getProductExtensionFields.run({ code: "event_item" });
	}, []);
	const extension = (0, react.useMemo)(() => {
		return _getProductExtensionFields.data || {};
	}, [_getProductExtensionFields.data]);
	const renderItem = (item, name) => {
		let { Component, defaultProps } = require_index$1.fields[item.key] || {};
		let _props = require_objectSpread2._objectSpread2({}, defaultProps);
		if (name) _props.name = name;
		return Component ? /* @__PURE__ */ react.default.createElement(Component, _props) : null;
	};
	return /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		active: true,
		round: true,
		loading: _getProductExtensionFields.loading
	}, (_extension$filed = extension.filed) === null || _extension$filed === void 0 ? void 0 : _extension$filed.map((item, index) => {
		var _item$, _item$2, _item$3, _extension$extension;
		const isHidden = ((_item$ = item[0]) === null || _item$ === void 0 ? void 0 : _item$.key) === "event_item_type";
		if (type !== "all" && ((_item$2 = item[0]) === null || _item$2 === void 0 ? void 0 : _item$2.key) === "schedule.ids") return null;
		return /* @__PURE__ */ react.default.createElement(require_index$2.default, {
			hidden: isHidden,
			key: index,
			header: item.length === 1 ? (_item$3 = item[0]) === null || _item$3 === void 0 ? void 0 : _item$3.name : extension === null || extension === void 0 || (_extension$extension = extension.extension) === null || _extension$extension === void 0 ? void 0 : _extension$extension.name
		}, item.map((child, childIndex) => {
			const name = `${child.id}|${child.key}`;
			return /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
				hidden: isHidden,
				label: item.length === 1 ? "" : child.name,
				name,
				rules: child.rules || child.key === "par_value" ? [{
					required: true,
					message: _pisell_utils.locales.getText("pisell2.text.product-extension.please-select")
				}] : [],
				key: childIndex,
				noStyle: true,
				initialValue: child.key === "event_item_capacity" ? 1 : void 0
			}, renderItem(child, name));
		}));
	}));
};
//#endregion
exports.default = ProductExtension;
