const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("../../dataSourceForm/utils.js");
const require_usePlatform = require("../../hooks/usePlatform.js");
const require_ReadPretty = require("./ReadPretty.js");
const require_BaseUpload = require("./BaseUpload.js");
const require_serve = require("./serve.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/dataSourceComponents/fields/Upload/WithMode.tsx
const Upload = (props) => {
	const isShop = require_usePlatform.useIsShop();
	const { presetType, mediaConfig: propsMediaConfig, presetTypeString: propsPresetTypeString } = props;
	const { getExtensionsByIds, getMaxSizeByIds } = require_serve.useMediaTypes();
	const { data: mediaConfig } = require_serve.useMediaConfig(propsMediaConfig);
	const presetTypeString = isShop ? propsPresetTypeString : getExtensionsByIds(presetType || []);
	const maxSizeMap = getMaxSizeByIds(presetType || []);
	const maxCount = (0, react.useMemo)(() => {
		const minArr = [];
		if ((0, _pisell_utils.isNumber)(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_onetime_limit)) minArr.push(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_onetime_limit);
		if ((0, _pisell_utils.isNumber)(props.maxCount)) minArr.push(props.maxCount);
		return Math.min(...minArr);
	}, [mediaConfig, props.maxCount]);
	const maxSize = (0, react.useMemo)(() => {
		const minArr = [];
		if ((0, _pisell_utils.isNumber)(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_maxsize)) minArr.push(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_maxsize);
		if ((0, _pisell_utils.isNumber)(props.maxSize)) minArr.push(props.maxSize);
		return Math.min(...minArr);
	}, [mediaConfig, props.maxSize]);
	return /* @__PURE__ */ react.default.createElement(require_BaseUpload.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
		maxCount,
		maxSize,
		presetType: presetTypeString,
		typeMaxSizeMap: maxSizeMap
	}));
};
const UploadWithMode = require_utils.withMode(Upload, require_ReadPretty.default);
//#endregion
exports.default = UploadWithMode;
