import { j as i } from "../../node_modules/react/jsx-runtime.mjs";
import "./index.less.mjs";
import { isMobile as w } from "../../node_modules/react-device-detect/dist/lib.mjs";
import b from "../../node_modules/antd-img-crop/dist/antd-img-crop.esm.mjs";
import { getItem as y } from "../../utils/local.mjs";
import v from "../BitzImage/previewImage.mjs";
import T from "../BitzDrawer/index.mjs";
import { useImmer as C } from "../../node_modules/use-immer/dist/use-immer.module.mjs";
import m from "../../node_modules/antd/es/upload/index.mjs";
import L from "../../node_modules/@ant-design/icons/es/icons/UploadOutlined.mjs";
import u from "../../node_modules/antd/es/message/index.mjs";
import { useTranslation as B } from "../../node_modules/react-i18next/dist/es/useTranslation.mjs";
import F from "../../node_modules/antd/es/button/button.mjs";
import z from "../../node_modules/@ant-design/icons/es/icons/PlusOutlined.mjs";
const h = "http://bitz.elinklaw.com", P = y("bitzToken") || null, { Dragger: D } = m, I = (t) => new Promise((s, n) => {
  const e = new FileReader();
  e.readAsDataURL(t), e.onload = () => s(e.result), e.onerror = (o) => n(o);
}), k = (t) => {
  t.file.status !== "uploading" && console.log(t.file, t.fileList), t.file.status === "done" ? u.success(`${t.file.name} 上传成功`) : t.file.status === "error" && u.error(`${t.file.name} 上传失败`);
}, j = (t) => {
  const s = t.showAddBtn || !0, n = t.limitImageType || ["png", "jpeg", "jpg"], e = t.limitFileType || ["txt", "doc", "docx", "pdf", "ppt", "pptx", "xlsx", "xls"], o = t.limitFileSize || 20, p = {
    title: "点击上传",
    icon: i.jsx(L, {}),
    name: "file",
    action: "/lzhApi/api/services/web/financialExpenditure/uploadExpenditureFile",
    accept: "image/png, image/jpeg",
    webkitRelativePath: "/image",
    headers: {
      authorization: `${"Bearer " + P}`
    },
    beforeUpload(c) {
      return [...n, ...e].includes(c.name.split(".").at(-1)) ? c.size > o * 1024 * 1024 ? (u.error(`文件应限制小于等于${o}MB!`), !1) : !0 : (u.error(`文件类型只能是${[...n, ...e].join("、")}`), !1);
    },
    onChange: k
  };
  return {
    showAddBtn: s,
    limitImageType: n,
    limitFileType: e,
    limitFileSize: o,
    ...p
  };
}, U = ({ ...t }) => {
  const { t: s } = B(), n = async (r) => {
    !r.url && !r.preview && (r.preview = await I(r.originFileObj)), v({
      items: [r.url || r.preview]
    });
  }, e = { ...j(t), ...t }, o = e.listType === "picture-card", p = e.listType === "picture-circle", c = () => o || p ? i.jsx(z, {}) : i.jsx(F, { icon: e.icon, children: e.title }), [f, d] = C({
    open: !1,
    fileList: e.defaultFileList || []
  });
  return w ? i.jsxs(i.Fragment, { children: [i.jsx("div", { onClick: () => d((r) => {
    r.open = !0;
  }), children: e.showAddBtn && c() }), i.jsx(m, { ...e, listType: e.listType, fileList: f.fileList, onRemove: (r) => {
    var l;
    const x = f.fileList.findIndex((a) => a.uid === r.uid);
    d((a) => {
      a.fileList.splice(x, 1);
    }), (l = e.onRemove) == null || l.call(e, r);
  } }), i.jsx(T, { height: "auto", className: "tableMobileDrawer", placement: "bottom", open: f.open, destroyOnClose: !0, closable: !1, children: i.jsxs("div", { className: "drawerBox", children: [i.jsx("div", { className: "boxBody", children: [{ label: "本地相册" }, { label: "文件" }].map((r, x) => i.jsx("div", { className: "operaList", children: i.jsx(g, { imgCrop: e.imgCrop, children: i.jsx(m, { ...e, listType: e.listType, showUploadList: !1, onChange: (l) => {
    l.file.status === "done" && (e.onChange(l), d((a) => {
      e.maxCount === 1 ? a.fileList = [
        {
          url: h + l.file.response.data,
          uid: Date.now() + "",
          name: ""
        }
      ] : a.fileList.push({
        url: h + l.file.response.data,
        uid: Date.now() + "",
        name: ""
      }), a.open = !1;
    }));
  }, children: r.label }) }) }, x)) }), i.jsx("div", { className: "boxLine" }), i.jsx("div", { className: "boxFooter", onClick: () => {
    d((r) => {
      r.open = !1;
    });
  }, children: s("System_Cancel", "取消") })] }) })] }) : i.jsx(g, { imgCrop: e.imgCrop, children: i.jsx(m, { onPreview: n, ...e, children: e.showAddBtn && c() }) });
}, V = A(U, {
  Dragger: ({ ...t }) => {
    const s = { ...j(t), ...t };
    return i.jsx(D, { ...s, children: t.children });
  }
});
function A(t, s) {
  const n = t;
  for (const e in s)
    s.hasOwnProperty(e) && (n[e] = s[e]);
  return n;
}
function g({ imgCrop: t, children: s }) {
  return t ? i.jsx(b, { rotationSlider: !0, aspect: t == null ? void 0 : t.aspect, children: s }) : i.jsx(i.Fragment, { children: s });
}
export {
  g as ImgCropUplad,
  A as attachPropertiesToComponent,
  V as default
};
