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(
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  UploaderPreviewItem: () => UploaderPreviewItem
});
module.exports = __toCommonJS(stdin_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("./utils");
var import_utils2 = require("../utils");
var import_interceptor = require("../utils/interceptor");
var import_icon = __toESM(require("../icon"));
var import_image = __toESM(require("../image"));
var import_loading = __toESM(require("../loading"));
var import_ConfigProviderContext = __toESM(require("../config-provider/ConfigProviderContext"));
const UploaderPreviewItem = (props) => {
  const {
    prefixCls,
    createNamespace
  } = (0, import_react.useContext)(import_ConfigProviderContext.default);
  const [bem] = createNamespace("uploader", prefixCls);
  const renderMask = () => {
    const {
      status,
      message
    } = props.item;
    if (status === "uploading" || status === "failed") {
      const MaskIcon = status === "failed" ? /* @__PURE__ */ import_react.default.createElement(import_icon.default, {
        name: "close",
        className: (0, import_classnames.default)(bem("mask-icon"))
      }) : /* @__PURE__ */ import_react.default.createElement(import_loading.default, {
        className: (0, import_classnames.default)(bem("loading"))
      });
      const showMessage = (0, import_utils2.isDef)(message) && message !== "";
      return /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("mask"))
      }, MaskIcon, showMessage && /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("mask-message"))
      }, message));
    }
    return null;
  };
  const onDelete = (event) => {
    const {
      name,
      item,
      index,
      beforeDelete
    } = props;
    event.stopPropagation();
    (0, import_interceptor.callInterceptor)({
      interceptor: beforeDelete,
      args: [item, {
        name,
        index
      }],
      done: () => {
        var _a;
        return (_a = props.onDelete) == null ? void 0 : _a.call(props);
      }
    });
  };
  const onPreview = () => {
    if (props.onPreview)
      props.onPreview();
  };
  const renderDeleteIcon = () => {
    if (props.deletable && props.item.status !== "uploading") {
      return /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("preview-delete")),
        onClick: onDelete
      }, /* @__PURE__ */ import_react.default.createElement(import_icon.default, {
        name: "cross",
        className: (0, import_classnames.default)(bem("preview-delete-icon"))
      }));
    }
    return null;
  };
  const renderCover = () => {
    if (props.previewCoverRender) {
      const {
        index,
        item
      } = props;
      return /* @__PURE__ */ import_react.default.createElement("div", {
        className: (0, import_classnames.default)(bem("preview-cover"))
      }, props.previewCoverRender((0, import_utils2.extend)({
        index
      }, item)));
    }
    return null;
  };
  const renderPreview = () => {
    const {
      item
    } = props;
    if ((0, import_utils.isImageFile)(item)) {
      return /* @__PURE__ */ import_react.default.createElement(import_image.default, {
        fit: props.imageFit,
        src: item.content || item.url,
        className: (0, import_classnames.default)(bem("preview-image")),
        width: props.previewSize,
        height: props.previewSize,
        onClick: onPreview
      }, renderCover());
    }
    return /* @__PURE__ */ import_react.default.createElement("div", {
      className: (0, import_classnames.default)(bem("file")),
      style: (0, import_utils2.getSizeStyle)(props.previewSize)
    }, /* @__PURE__ */ import_react.default.createElement(import_icon.default, {
      className: (0, import_classnames.default)(bem("file-icon")),
      name: "description"
    }), /* @__PURE__ */ import_react.default.createElement("div", {
      className: (0, import_classnames.default)(bem("file-name"), "rc-ellipsis")
    }, item.file ? item.file.name : item.url), renderCover());
  };
  return /* @__PURE__ */ import_react.default.createElement("div", {
    className: (0, import_classnames.default)(bem("preview")),
    onClick: props.onClick
  }, renderPreview(), renderMask(), renderDeleteIcon());
};
