import Y from "../../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as n from "react";
import Z from "../../../../@ant-design/icons/es/icons/FileTwoTone.mjs";
import j from "../../../../@ant-design/icons/es/icons/LoadingOutlined.mjs";
import ee from "../../../../@ant-design/icons/es/icons/PaperClipOutlined.mjs";
import ne from "../../../../@ant-design/icons/es/icons/PictureTwoTone.mjs";
import N from "../../../../classnames/index.mjs";
import te from "../../../../rc-motion/es/CSSMotion.mjs";
import oe from "../../../../rc-motion/es/CSSMotionList.mjs";
import ie from "../../_util/hooks/useForceUpdate.mjs";
import re from "../../_util/motion.mjs";
import { cloneElement as h, isValidElement as R } from "../../_util/reactNode.mjs";
import U from "../../button/button.mjs";
import "../../config-provider/index.mjs";
import { previewImage as se, isImageUrl as le } from "../utils.mjs";
import ae from "./ListItem.mjs";
import { ConfigContext as ce } from "../../config-provider/context.mjs";
const me = (D, P) => {
  const {
    listType: o = "text",
    previewFile: c = se,
    onPreview: w,
    onDownload: g,
    onRemove: m,
    locale: b,
    iconRender: v,
    isImageUrl: p = le,
    prefixCls: L,
    items: s = [],
    showPreviewIcon: F = !0,
    showRemoveIcon: k = !0,
    showDownloadIcon: S = !1,
    removeIcon: $,
    previewIcon: A,
    downloadIcon: M,
    progress: T = {
      size: [-1, 2],
      showInfo: !1
    },
    appendAction: C,
    appendActionVisible: z = !0,
    itemRender: V,
    disabled: B
  } = D, _ = ie(), [H, K] = n.useState(!1);
  n.useEffect(() => {
    o !== "picture" && o !== "picture-card" && o !== "picture-circle" || (s || []).forEach((e) => {
      typeof document > "u" || typeof window > "u" || !window.FileReader || !window.File || !(e.originFileObj instanceof File || e.originFileObj instanceof Blob) || e.thumbUrl !== void 0 || (e.thumbUrl = "", c && c(e.originFileObj).then((t) => {
        e.thumbUrl = t || "", _();
      }));
    });
  }, [o, s, c]), n.useEffect(() => {
    K(!0);
  }, []);
  const E = (e, t) => {
    if (w)
      return t == null || t.preventDefault(), w(e);
  }, I = (e) => {
    typeof g == "function" ? g(e) : e.url && window.open(e.url);
  }, q = (e) => {
    m == null || m(e);
  }, G = (e) => {
    if (v)
      return v(e, o);
    const t = e.status === "uploading", r = p && p(e) ? /* @__PURE__ */ n.createElement(ne, null) : /* @__PURE__ */ n.createElement(Z, null);
    let i = t ? /* @__PURE__ */ n.createElement(j, null) : /* @__PURE__ */ n.createElement(ee, null);
    return o === "picture" ? i = t ? /* @__PURE__ */ n.createElement(j, null) : r : (o === "picture-card" || o === "picture-circle") && (i = t ? b.uploading : r), i;
  }, J = (e, t, r, i, d) => {
    const u = {
      type: "text",
      size: "small",
      title: i,
      onClick: (f) => {
        t(), R(e) && e.props.onClick && e.props.onClick(f);
      },
      className: `${r}-list-item-action`
    };
    if (d && (u.disabled = B), R(e)) {
      const f = h(e, Object.assign(Object.assign({}, e.props), {
        onClick: () => {
        }
      }));
      return /* @__PURE__ */ n.createElement(U, Object.assign({}, u, {
        icon: f
      }));
    }
    return /* @__PURE__ */ n.createElement(U, Object.assign({}, u), /* @__PURE__ */ n.createElement("span", null, e));
  };
  n.useImperativeHandle(P, () => ({
    handlePreview: E,
    handleDownload: I
  }));
  const {
    getPrefixCls: y
  } = n.useContext(ce), l = y("upload", L), O = y(), Q = N(`${l}-list`, `${l}-list-${o}`), W = Y(s.map((e) => ({
    key: e.uid,
    file: e
  })));
  let a = {
    motionDeadline: 2e3,
    motionName: `${l}-${o === "picture-card" || o === "picture-circle" ? "animate-inline" : "animate"}`,
    keys: W,
    motionAppear: H
  };
  const X = n.useMemo(() => {
    const e = Object.assign({}, re(O));
    return delete e.onAppearEnd, delete e.onEnterEnd, delete e.onLeaveEnd, e;
  }, [O]);
  return o !== "picture-card" && o !== "picture-circle" && (a = Object.assign(Object.assign({}, X), a)), /* @__PURE__ */ n.createElement("div", {
    className: Q
  }, /* @__PURE__ */ n.createElement(oe, Object.assign({}, a, {
    component: !1
  }), (e) => {
    let {
      key: t,
      file: r,
      className: i,
      style: d
    } = e;
    return /* @__PURE__ */ n.createElement(ae, {
      key: t,
      locale: b,
      prefixCls: l,
      className: i,
      style: d,
      file: r,
      items: s,
      progress: T,
      listType: o,
      isImgUrl: p,
      showPreviewIcon: F,
      showRemoveIcon: k,
      showDownloadIcon: S,
      removeIcon: $,
      previewIcon: A,
      downloadIcon: M,
      iconRender: G,
      actionIconRender: J,
      itemRender: V,
      onPreview: E,
      onDownload: I,
      onClose: q
    });
  }), C && /* @__PURE__ */ n.createElement(te, Object.assign({}, a, {
    visible: z,
    forceRender: !0
  }), (e) => {
    let {
      className: t,
      style: r
    } = e;
    return h(C, (i) => ({
      className: N(i.className, t),
      style: Object.assign(Object.assign(Object.assign({}, r), {
        // prevent the element has hover css pseudo-class that may cause animation to end prematurely.
        pointerEvents: t ? "none" : void 0
      }), i.style)
    }));
  }));
}, x = /* @__PURE__ */ n.forwardRef(me);
process.env.NODE_ENV !== "production" && (x.displayName = "UploadList");
const Ue = x;
export {
  Ue as default
};
