"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const resolveAccept = require("./utils/resolveAccept.cjs");
const disconnectAtBase = require("./utils/disconnectAtBase.cjs");
const staticRenderFileKind = require("./utils/staticRenderFileKind.cjs");
const isEmptyByUrlField = (urlField) => (accessor) => accessor.getField(urlField).value === null;
class SingleKindFileHandler {
  constructor(kind, isEmpty) {
    __publicField(this, "hasBaseEntity");
    this.kind = kind;
    this.isEmpty = isEmpty;
    this.hasBaseEntity = kind.baseEntity !== void 0;
  }
  get acceptedMimes() {
    return this.kind.acceptMimeTypes;
  }
  async acceptFile(fileOptions) {
    const result = await resolveAccept.resolveAcceptingSingleKind(fileOptions, this.kind);
    if (result) {
      return {
        fileKind: this.kind
      };
    }
    return void 0;
  }
  staticRender(environment) {
    const [upload, outsideChildren] = staticRenderFileKind.staticRenderFileKind(this.kind, environment);
    return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
      upload,
      outsideChildren
    ] });
  }
  resolveEntity(parentEntity) {
    const fileEntity = this.resolveFileEntity(parentEntity);
    const baseEntity = this.kind.baseEntity;
    return {
      parentEntity,
      fileEntity,
      fileKind: this.kind,
      isEmpty: this.isEmpty(fileEntity),
      destroy: baseEntity ? () => {
        disconnectAtBase.disconnectAtBase(baseEntity, parentEntity);
      } : void 0,
      getErrorHolders: () => {
        return [
          parentEntity,
          ...fileEntity !== parentEntity ? [fileEntity] : [],
          ...this.kind.extractors.flatMap((it) => it.getErrorsHolders?.({
            entity: fileEntity,
            environment: fileEntity.environment
          }) ?? [])
        ];
      }
    };
  }
  resolveFileEntity(accessor) {
    return this.kind.baseEntity ? accessor.getEntity(this.kind.baseEntity) : accessor;
  }
}
exports.SingleKindFileHandler = SingleKindFileHandler;
exports.isEmptyByUrlField = isEmptyByUrlField;
//# sourceMappingURL=SingleKindFileHandler.cjs.map
