import X from "../../../../@ant-design/icons/es/icons/DeleteOutlined.mjs";
import Y from "../../../../@ant-design/icons/es/icons/DownloadOutlined.mjs";
import Z from "../../../../@ant-design/icons/es/icons/EyeOutlined.mjs";
import s from "../../../../classnames/index.mjs";
import ee from "../../../../rc-motion/es/CSSMotion.mjs";
import "../../../../rc-motion/es/CSSMotionList.mjs";
import * as t from "react";
import "../../config-provider/index.mjs";
import te from "../../progress/progress.mjs";
import oe from "../../tooltip/index.mjs";
import { ConfigContext as re } from "../../config-provider/context.mjs";
const le = /* @__PURE__ */ t.forwardRef((x, D) => {
  let {
    prefixCls: o,
    className: R,
    style: U,
    locale: c,
    listType: l,
    file: e,
    items: T,
    progress: _,
    iconRender: F,
    actionIconRender: E,
    itemRender: C,
    isImgUrl: i,
    showPreviewIcon: j,
    showRemoveIcon: L,
    showDownloadIcon: M,
    previewIcon: u,
    removeIcon: p,
    downloadIcon: d,
    onPreview: a,
    onDownload: I,
    onClose: h
  } = x;
  var f, g;
  const {
    status: m
  } = e, [n, A] = t.useState(m);
  t.useEffect(() => {
    m !== "removed" && A(m);
  }, [m]);
  const [J, q] = t.useState(!1);
  t.useEffect(() => {
    const r = setTimeout(() => {
      q(!0);
    }, 300);
    return () => {
      clearTimeout(r);
    };
  }, []);
  const v = F(e);
  let w = /* @__PURE__ */ t.createElement("div", {
    className: `${o}-icon`
  }, v);
  if (l === "picture" || l === "picture-card" || l === "picture-circle")
    if (n === "uploading" || !e.thumbUrl && !e.url) {
      const r = s(`${o}-list-item-thumbnail`, {
        [`${o}-list-item-file`]: n !== "uploading"
      });
      w = /* @__PURE__ */ t.createElement("div", {
        className: r
      }, v);
    } else {
      const r = i != null && i(e) ? /* @__PURE__ */ t.createElement("img", {
        src: e.thumbUrl || e.url,
        alt: e.name,
        className: `${o}-list-item-image`,
        crossOrigin: e.crossOrigin
      }) : v, b = s(`${o}-list-item-thumbnail`, {
        [`${o}-list-item-file`]: i && !i(e)
      });
      w = /* @__PURE__ */ t.createElement("a", {
        className: b,
        onClick: (N) => a(e, N),
        href: e.url || e.thumbUrl,
        target: "_blank",
        rel: "noopener noreferrer"
      }, r);
    }
  const z = s(`${o}-list-item`, `${o}-list-item-${n}`), B = typeof e.linkProps == "string" ? JSON.parse(e.linkProps) : e.linkProps, $ = L ? E(
    (typeof p == "function" ? p(e) : p) || /* @__PURE__ */ t.createElement(X, null),
    () => h(e),
    o,
    c.removeFile,
    // acceptUploadDisabled is true, only remove icon will follow Upload disabled prop
    // https://github.com/ant-design/ant-design/issues/46171
    !0
  ) : null, y = M && n === "done" ? E((typeof d == "function" ? d(e) : d) || /* @__PURE__ */ t.createElement(Y, null), () => I(e), o, c.downloadFile) : null, P = l !== "picture-card" && l !== "picture-circle" && /* @__PURE__ */ t.createElement("span", {
    key: "download-delete",
    className: s(`${o}-list-item-actions`, {
      picture: l === "picture"
    })
  }, y, $), k = s(`${o}-list-item-name`), G = e.url ? [/* @__PURE__ */ t.createElement("a", Object.assign({
    key: "view",
    target: "_blank",
    rel: "noopener noreferrer",
    className: k,
    title: e.name
  }, B, {
    href: e.url,
    onClick: (r) => a(e, r)
  }), e.name), P] : [/* @__PURE__ */ t.createElement("span", {
    key: "view",
    className: k,
    onClick: (r) => a(e, r),
    title: e.name
  }, e.name), P], H = j && (e.url || e.thumbUrl) ? /* @__PURE__ */ t.createElement("a", {
    href: e.url || e.thumbUrl,
    target: "_blank",
    rel: "noopener noreferrer",
    onClick: (r) => a(e, r),
    title: c.previewFile
  }, typeof u == "function" ? u(e) : u || /* @__PURE__ */ t.createElement(Z, null)) : null, K = (l === "picture-card" || l === "picture-circle") && n !== "uploading" && /* @__PURE__ */ t.createElement("span", {
    className: `${o}-list-item-actions`
  }, H, n === "done" && y, $), {
    getPrefixCls: Q
  } = t.useContext(re), V = Q(), O = /* @__PURE__ */ t.createElement("div", {
    className: z
  }, w, G, K, J && /* @__PURE__ */ t.createElement(ee, {
    motionName: `${V}-fade`,
    visible: n === "uploading",
    motionDeadline: 2e3
  }, (r) => {
    let {
      className: b
    } = r;
    const N = "percent" in e ? /* @__PURE__ */ t.createElement(te, Object.assign({}, _, {
      type: "line",
      percent: e.percent,
      "aria-label": e["aria-label"],
      "aria-labelledby": e["aria-labelledby"]
    })) : null;
    return /* @__PURE__ */ t.createElement("div", {
      className: s(`${o}-list-item-progress`, b)
    }, N);
  })), W = e.response && typeof e.response == "string" ? e.response : ((f = e.error) === null || f === void 0 ? void 0 : f.statusText) || ((g = e.error) === null || g === void 0 ? void 0 : g.message) || c.uploadError, S = n === "error" ? /* @__PURE__ */ t.createElement(oe, {
    title: W,
    getPopupContainer: (r) => r.parentNode
  }, O) : O;
  return /* @__PURE__ */ t.createElement("div", {
    className: s(`${o}-list-item-container`, R),
    style: U,
    ref: D
  }, C ? C(S, e, T, {
    download: I.bind(null, e),
    preview: a.bind(null, e),
    remove: h.bind(null, e)
  }) : S);
}), ge = le;
export {
  ge as default
};
