var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/fields/Upload/serve.ts
var serve_exports = {};
__export(serve_exports, {
  getMediaTypeList: () => getMediaTypeList,
  useMediaConfig: () => useMediaConfig,
  useMediaTypes: () => useMediaTypes
});
module.exports = __toCommonJS(serve_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_utils = require("./utils");
var import_utils2 = require("../../../table/utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_usePlatform = require("../../hooks/usePlatform");
var getMediaTypeList = async () => {
  const { data } = await import_utils2.request.getRequest().get(
    `/media_type:list`,
    {},
    {
      isNocobase: true,
      fullResult: true,
      headers: {
        "x-data-source": "pisell2"
      }
    }
  );
  return data;
};
var useMediaConfig = (mediaConfig) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  const context = (0, import_useEngineContext.default)();
  const data = (_i = (_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) == null ? void 0 : _c.call(_b)) == null ? void 0 : _d.data) == null ? void 0 : _e.store) == null ? void 0 : _f.getStore) == null ? void 0 : _g.call(_f)) == null ? void 0 : _h.getDataByModel) == null ? void 0 : _i.call(_h, "core", "core");
  return {
    data: {
      upload_onetime_limit: (mediaConfig == null ? void 0 : mediaConfig.upload_onetime_limit) || (data == null ? void 0 : data.media_upload_onetime_limit),
      upload_maxsize: (mediaConfig == null ? void 0 : mediaConfig.upload_maxsize) || (data == null ? void 0 : data.media_upload_maxsize)
    }
  };
};
var useMediaTypes = () => {
  const isShop = (0, import_usePlatform.useIsShop)();
  const { data, run } = (0, import_ahooks.useRequest)(getMediaTypeList, {
    cacheKey: "media-type",
    staleTime: 1e3 * 60 * 5,
    // 5分钟后数据过期
    cacheTime: 1e3 * 60 * 60,
    // 1小时后清除缓存
    manual: true
  });
  (0, import_react.useEffect)(() => {
    if (!isShop) {
      run();
    }
  }, [isShop]);
  const getExtensionsByIds = (ids) => {
    const extensions = [];
    (data || []).forEach((item) => {
      if (ids == null ? void 0 : ids.includes(item.id)) {
        extensions.push(
          ...(item.extensions || []).map((item2) => (0, import_utils.getPointSuffix)(item2))
        );
      }
    });
    return extensions;
  };
  const getMaxSizeByIds = (ids) => {
    const maxSizeMap = {};
    (data || []).forEach((item) => {
      if (ids == null ? void 0 : ids.includes(item.id)) {
        item.extensions.forEach((extension) => {
          const key = (0, import_utils.getPointSuffix)(extension);
          maxSizeMap[key] = item.maxsize;
        });
      }
    });
    return maxSizeMap;
  };
  return { data, getExtensionsByIds, getMaxSizeByIds };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getMediaTypeList,
  useMediaConfig,
  useMediaTypes
});
