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/WithMode.tsx
var WithMode_exports = {};
__export(WithMode_exports, {
  default: () => WithMode_default
});
module.exports = __toCommonJS(WithMode_exports);
var import_react = __toESM(require("react"));
var import_utils = require("../../dataSourceForm/utils");
var import_ReadPretty = __toESM(require("./ReadPretty"));
var import_BaseUpload = __toESM(require("./BaseUpload"));
var import_serve = require("./serve");
var import_utils2 = require("@pisell/utils");
var Upload = (props) => {
  const { presetType, mediaConfig: propsMediaConfig } = props;
  const { getExtensionsByIds, getMaxSizeByIds } = (0, import_serve.useMediaTypes)();
  const { data: mediaConfig } = (0, import_serve.useMediaConfig)(propsMediaConfig);
  const presetTypeString = getExtensionsByIds(presetType || []);
  const maxSizeMap = getMaxSizeByIds(presetType || []);
  const maxCount = (0, import_react.useMemo)(() => {
    const minArr = [];
    if ((0, import_utils2.isNumber)(mediaConfig == null ? void 0 : mediaConfig.upload_onetime_limit)) {
      minArr.push(mediaConfig == null ? void 0 : mediaConfig.upload_onetime_limit);
    }
    if ((0, import_utils2.isNumber)(props.maxCount)) {
      minArr.push(props.maxCount);
    }
    return Math.min(...minArr);
  }, [mediaConfig, props.maxCount]);
  const maxSize = (0, import_react.useMemo)(() => {
    const minArr = [];
    if ((0, import_utils2.isNumber)(mediaConfig == null ? void 0 : mediaConfig.upload_maxsize)) {
      minArr.push(mediaConfig == null ? void 0 : mediaConfig.upload_maxsize);
    }
    if ((0, import_utils2.isNumber)(props.maxSize)) {
      minArr.push(props.maxSize);
    }
    return Math.min(...minArr);
  }, [mediaConfig, props.maxSize]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_BaseUpload.default,
    {
      ...props,
      maxCount,
      maxSize,
      presetType: presetTypeString,
      typeMaxSizeMap: maxSizeMap
    }
  );
};
var UploadWithMode = (0, import_utils.withMode)(Upload, import_ReadPretty.default);
var WithMode_default = UploadWithMode;
