require("../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_utils = require("../../../table/utils.js");
const require_usePlatform = require("../../hooks/usePlatform.js");
const require_utils$1 = require("./utils.js");
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/dataSourceComponents/fields/Upload/serve.ts
/**
* 获取nocobase媒体数据列表
*/
const getMediaTypeList = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
		const { data } = yield require_utils.request.getRequest().get(`/media_type:list`, {}, {
			isNocobase: true,
			fullResult: true,
			headers: { "x-data-source": "pisell2" }
		});
		return data;
	});
	return function getMediaTypeList() {
		return _ref.apply(this, arguments);
	};
}();
const useMediaConfig = (mediaConfig) => {
	var _context$appHelper, _context$appHelper$ge, _context$appHelper$ge2, _context$appHelper$ge3;
	const data = (_context$appHelper = require_useEngineContext.default().appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.call(_context$appHelper)) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.data) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.store) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge.getStore) === null || _context$appHelper$ge2 === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge2.call(_context$appHelper$ge)) === null || _context$appHelper$ge2 === void 0 || (_context$appHelper$ge3 = _context$appHelper$ge2.getDataByModel) === null || _context$appHelper$ge3 === void 0 ? void 0 : _context$appHelper$ge3.call(_context$appHelper$ge2, "core", "core");
	return { data: {
		upload_onetime_limit: (mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_onetime_limit) || (data === null || data === void 0 ? void 0 : data.media_upload_onetime_limit),
		upload_maxsize: (mediaConfig === null || mediaConfig === void 0 ? void 0 : mediaConfig.upload_maxsize) || (data === null || data === void 0 ? void 0 : data.media_upload_maxsize)
	} };
};
const useMediaTypes = () => {
	const isShop = require_usePlatform.useIsShop();
	const { data, run } = (0, ahooks.useRequest)(getMediaTypeList, {
		cacheKey: "media-type",
		staleTime: 1e3 * 60 * 5,
		cacheTime: 1e3 * 60 * 60,
		manual: true
	});
	(0, react.useEffect)(() => {
		if (!isShop) run();
	}, [isShop]);
	const getExtensionsByIds = (ids) => {
		const extensions = [];
		(data || []).forEach((item) => {
			if (ids === null || ids === void 0 ? void 0 : ids.includes(item.id)) extensions.push(...(item.extensions || []).map((item) => require_utils$1.getPointSuffix(item)));
		});
		return extensions;
	};
	const getMaxSizeByIds = (ids) => {
		const maxSizeMap = {};
		(data || []).forEach((item) => {
			if (ids === null || ids === void 0 ? void 0 : ids.includes(item.id)) item.extensions.forEach((extension) => {
				const key = require_utils$1.getPointSuffix(extension);
				maxSizeMap[key] = item.maxsize;
			});
		});
		return maxSizeMap;
	};
	return {
		data,
		getExtensionsByIds,
		getMaxSizeByIds
	};
};
//#endregion
exports.useMediaConfig = useMediaConfig;
exports.useMediaTypes = useMediaTypes;
