import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { withMode } from "../../dataSourceForm/utils.js";
import { useIsShop } from "../../hooks/usePlatform.js";
import UploadReadPretty from "./ReadPretty.js";
import BaseUpload from "./BaseUpload.js";
import { useMediaConfig, useMediaTypes } from "./serve.js";
import React, { useMemo } from "react";
import { isNumber } from "@pisell/utils";
//#region src/components/dataSourceComponents/fields/Upload/WithMode.tsx
const Upload = (props) => {
	const isShop = useIsShop();
	const { presetType, mediaConfig: propsMediaConfig, presetTypeString: propsPresetTypeString } = props;
	const { getExtensionsByIds, getMaxSizeByIds } = useMediaTypes();
	const { data: mediaConfig } = useMediaConfig(propsMediaConfig);
	const presetTypeString = isShop ? propsPresetTypeString : getExtensionsByIds(presetType || []);
	const maxSizeMap = getMaxSizeByIds(presetType || []);
	const maxCount = useMemo(() => {
		const minArr = [];
		if (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 (isNumber(props.maxCount)) minArr.push(props.maxCount);
		return Math.min(...minArr);
	}, [mediaConfig, props.maxCount]);
	const maxSize = useMemo(() => {
		const minArr = [];
		if (isNumber(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_maxsize)) minArr.push(mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_maxsize);
		if (isNumber(props.maxSize)) minArr.push(props.maxSize);
		return Math.min(...minArr);
	}, [mediaConfig, props.maxSize]);
	return /* @__PURE__ */ React.createElement(BaseUpload, _objectSpread2(_objectSpread2({}, props), {}, {
		maxCount,
		maxSize,
		presetType: presetTypeString,
		typeMaxSizeMap: maxSizeMap
	}));
};
const UploadWithMode = withMode(Upload, UploadReadPretty);
//#endregion
export { UploadWithMode as default };
