import "react";
import IconFile from "../../../icon/react-icon/IconFile/index.js";
import IconFilePdf from "../../../icon/react-icon/IconFilePdf/index.js";
import IconFileImage from "../../../icon/react-icon/IconFileImage/index.js";
import IconFileVideo from "../../../icon/react-icon/IconFileVideo/index.js";
import IconFileAudio from "../../../icon/react-icon/IconFileAudio/index.js";
import Tooltip from "../../Tooltip/index.js";
import { STATUS } from "../interface.js";
import { isObject, isFunction } from "../../_util/is.js";
import UploadProgress from "./uploadProgress.js";
import IconExclamationCircleFill from "../../../icon/react-icon/IconExclamationCircleFill/index.js";
import IconDelete from "../../../icon/react-icon/IconDelete/index.js";
import IconHover from "../../_class/icon-hover.js";
import { jsxs, jsx } from "../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var getIconType = function(file) {
  var type = "";
  if (file.originFile && file.originFile.type) {
    type = file.originFile.type;
  } else {
    var name_1 = file.name || "";
    var fileExtension = name_1.split(".").pop() || "";
    type = fileExtension;
    if (["png", "jpg", "jpeg", "bmp", "gif"].indexOf(fileExtension) > -1) {
      type = "image";
    } else if (["mp4", "m2v", "mkv"].indexOf(fileExtension) > -1) {
      type = "video";
    } else if (["mp3", "wav", "wmv"].indexOf(fileExtension) > -1) {
      type = "audio";
    }
  }
  if (type.indexOf("image") > -1) {
    return IconFileImage;
  }
  if (type.indexOf("pdf") > -1) {
    return IconFilePdf;
  }
  if (type.indexOf("audio") > -1) {
    return IconFileAudio;
  }
  if (type.indexOf("video") > -1) {
    return IconFileVideo;
  }
  return IconFile;
};
var TextItem = function(props) {
  var prefixCls = props.prefixCls, disabled = props.disabled, file = props.file, locale = props.locale;
  var cls = prefixCls + "-list-item-text";
  var Icon = getIconType(file);
  var showUploadList = isObject(props.showUploadList) ? props.showUploadList : {};
  var actionIcons = isObject(showUploadList) ? showUploadList : {};
  var fileName = file.name || file.originFile && file.originFile.name;
  var url = file.url !== void 0 ? file.url : file.originFile && isFunction(URL.createObjectURL) && URL.createObjectURL(file.originFile);
  var triggerProps = {};
  if (file.status !== STATUS.fail) {
    triggerProps = {
      popupVisible: false
    };
  }
  return /* @__PURE__ */ jsxs("div", {
    className: prefixCls + "-list-item " + prefixCls + "-list-item-" + file.status,
    children: [/* @__PURE__ */ jsxs("div", {
      className: cls,
      children: [props.listType === "picture-list" && /* @__PURE__ */ jsx("div", {
        className: cls + "-thumbnail",
        children: isFunction(showUploadList.imageRender) ? showUploadList.imageRender(file) : /* @__PURE__ */ jsx("img", {
          src: url
        })
      }), /* @__PURE__ */ jsxs("div", {
        className: cls + "-content",
        children: [/* @__PURE__ */ jsxs("div", {
          className: cls + "-name",
          children: [props.listType === "text" && actionIcons.fileIcon !== null && /* @__PURE__ */ jsx("span", {
            className: prefixCls + "-list-file-icon",
            children: actionIcons.fileIcon || /* @__PURE__ */ jsx(Icon, {})
          }), isFunction(showUploadList.fileName) ? /* @__PURE__ */ jsx("span", {
            className: cls + "-name-text",
            children: showUploadList.fileName(file)
          }) : file.url ? /* @__PURE__ */ jsx("a", {
            href: file.url,
            target: "_blank",
            rel: "noreferrer",
            className: cls + "-name-link",
            children: fileName
          }) : /* @__PURE__ */ jsx("span", {
            className: cls + "-name-text",
            children: fileName
          }), file.status === STATUS.fail && actionIcons.errorIcon !== null && /* @__PURE__ */ jsx(Tooltip, {
            ...__assign({
              content: file.response || locale.Upload.error
            }, triggerProps, {
              disabled: file.status !== STATUS.fail
            }),
            children: /* @__PURE__ */ jsx("span", {
              className: props.prefixCls + "-list-error-icon",
              children: actionIcons.errorIcon || (props.listType === "picture-card" ? /* @__PURE__ */ jsx(IconFileImage, {}) : /* @__PURE__ */ jsx(IconExclamationCircleFill, {}))
            })
          })]
        }), /* @__PURE__ */ jsx(UploadProgress, {
          ...__assign({
            file,
            prefixCls,
            progressProps: props.progressProps,
            onReupload: props.onReupload,
            onUpload: props.onUpload,
            onAbort: props.onAbort
          }, actionIcons)
        })]
      })]
    }), /* @__PURE__ */ jsx("div", {
      className: prefixCls + "-list-item-operation",
      children: !disabled && actionIcons.removeIcon !== null && /* @__PURE__ */ jsx(IconHover, {
        onClick: function() {
          props.onRemove && props.onRemove(file);
        },
        children: /* @__PURE__ */ jsx("span", {
          className: prefixCls + "-list-remove-icon",
          children: actionIcons.removeIcon || /* @__PURE__ */ jsx(IconDelete, {})
        })
      })
    })]
  });
};
const TextItem$1 = TextItem;
export {
  TextItem$1 as default
};
//# sourceMappingURL=textItem.js.map
