import { defineComponent as M, computed as b, openBlock as u, createBlock as y, unref as e, mergeProps as G, withCtx as i, renderSlot as H, normalizeProps as J, guardReactiveProps as K, createElementVNode as s, normalizeClass as l, createElementBlock as v, createVNode as n, createTextVNode as m, toDisplayString as p, resolveDynamicComponent as F, h as N, Fragment as L } from "vue";
import { Form as Q, UploadDragger as W, TypographyParagraph as C, Progress as X, Tooltip as P } from "@aplus-frontend/antdv";
import { FormItemInputContext as Y } from "@aplus-frontend/antdv/es/form/FormItemContext";
import { omit as Z } from "lodash-unified";
import { useToken as ee } from "../../../config-provider/hooks/use-token.mjs";
import "../../../config-provider/index.mjs";
import { useInjectContext as te } from "../hook/useInjectContext.mjs";
import { useSingleProps as oe } from "../hook/useProps.mjs";
import k from "../icon/delete-icon.vue.mjs";
import g from "../icon/file-icon.vue.mjs";
import { clearSingleFile as le, clearAllFile as x } from "../utils/fileList.mjs";
import se from "./style/index.mjs";
import { useGlobalConfig as ne } from "../../../config-provider/hooks/use-global-config.mjs";
import { useLocale as ae } from "../../../config-provider/hooks/use-locale.mjs";
import { useNamespace as ie } from "../../../config-provider/hooks/use-namespace.mjs";
const Se = /* @__PURE__ */ M({
  __name: "ap-upload-single",
  props: {
    dirName: {},
    getOssAccess: {},
    fileList: {},
    onChange: {},
    maxSize: { default: 500 },
    accept: { default: "*" },
    beforeUpload: {},
    customRequest: {},
    maxSizeErrorMsg: {},
    acceptErrorMsg: {},
    bucket: {},
    title: { type: [Object, String, Number, Boolean, null, Array] },
    subTitle: { type: [Object, String, Number, Boolean, null, Array] }
  },
  emits: ["update:fileList"],
  setup(w, { emit: A }) {
    const T = Y.useInject(), $ = b(() => T.status), d = w, q = A, B = Q.useInjectFormItemContext(), r = b({
      get() {
        return d.fileList || [];
      },
      set(c) {
        q("update:fileList", c), B?.onFieldChange();
      }
    }), o = b(() => r.value?.[0]), O = ne("apUpload"), { t: U, lang: j } = ae(), {
      title: z,
      subTitle: R,
      beforeUpload: E,
      customRequest: h
    } = oe(d), D = h;
    te(
      U,
      j,
      d?.getOssAccess ?? O.value?.getOssAccess
    );
    const { b: I, e: t } = ie("ap-upload-single"), V = se("ap-upload-single"), { token: S } = ee();
    function _(c) {
      return Z(c, [
        "dirName",
        "needName",
        "getOssAccess",
        "fileList",
        "title",
        "subTitle"
      ]);
    }
    return (c, a) => (u(), y(e(W), G({
      ...c.$attrs,
      ..._(d)
    }, {
      "file-list": r.value,
      "onUpdate:fileList": a[3] || (a[3] = (f) => r.value = f),
      "max-count": 1,
      "show-upload-list": !1,
      disabled: !!o.value && [void 0, "uploading", "error", "success", "done"].includes(o.value.status),
      class: [e(I)(), `${e(I)()}-affix-wrapper-status-${$.value}`, e(V)],
      "before-upload": e(E),
      "custom-request": e(D)
    }), {
      default: i(() => [
        H(c.$slots, "default", J(K({
          file: o.value,
          clear: () => o.value && e(le)(o.value, r.value, { maxCount: 1 })
        })), () => [
          s("div", {
            class: l([e(t)("content")])
          }, [
            o.value?.status && ["uploading"].includes(o.value.status) ? (u(), v("div", {
              key: 0,
              class: l([e(t)("content-file"), e(t)("content-ing")])
            }, [
              s("div", {
                class: l([e(t)("content-file-icon")])
              }, [
                n(g)
              ], 2),
              s("div", {
                class: l([e(t)("content-file-name"), e(t)("content-ing-name")])
              }, [
                n(e(C), {
                  ellipsis: { rows: 2 },
                  tooltip: o.value.error
                }, {
                  default: i(() => [
                    m(p(o.value.name), 1)
                  ]),
                  _: 1
                }, 8, ["tooltip"]),
                n(e(X), {
                  percent: o.value.percent || 0,
                  size: 4,
                  "show-info": !1,
                  "trail-color": e(S).borderColorBase,
                  "stroke-color": e(S).colorPrimary
                }, null, 8, ["percent", "trail-color", "stroke-color"])
              ], 2),
              s("div", {
                class: l([e(t)("content-file-delete")]),
                onClick: a[0] || (a[0] = (f) => e(x)(r.value))
              }, [
                n(k)
              ], 2)
            ], 2)) : o.value?.status && ["error"].includes(o.value.status) ? (u(), v("div", {
              key: 1,
              class: l([e(t)("content-file"), e(t)("content-error")])
            }, [
              s("div", {
                class: l([e(t)("content-file-icon")])
              }, [
                n(g)
              ], 2),
              s("div", {
                class: l([e(t)("content-file-name"), e(t)("content-error-name")])
              }, [
                n(e(P), null, {
                  title: i(() => [
                    m(p(o.value?.error || "--"), 1)
                  ]),
                  default: i(() => [
                    n(e(C), {
                      ellipsis: { rows: 2 },
                      tooltip: o.value.error
                    }, {
                      default: i(() => [
                        m(p(o.value.name), 1)
                      ]),
                      _: 1
                    }, 8, ["tooltip"])
                  ]),
                  _: 1
                })
              ], 2),
              s("div", {
                class: l([e(t)("content-file-delete")]),
                onClick: a[1] || (a[1] = (f) => e(x)(r.value))
              }, [
                n(k)
              ], 2)
            ], 2)) : o.value && o.value?.status === void 0 || o.value?.status && ["success", "done"].includes(o.value.status) ? (u(), v("div", {
              key: 2,
              class: l([e(t)("content-file"), e(t)("content-done")])
            }, [
              s("div", {
                class: l([e(t)("content-file-icon")])
              }, [
                n(g)
              ], 2),
              s("div", {
                class: l([e(t)("content-file-name"), e(t)("content-done-name")])
              }, [
                n(e(P), null, {
                  title: i(() => [
                    m(p(o.value?.name || "--"), 1)
                  ]),
                  default: i(() => [
                    n(e(C), {
                      ellipsis: { rows: 2 },
                      tooltip: o.value.error
                    }, {
                      default: i(() => [
                        m(p(o.value.name), 1)
                      ]),
                      _: 1
                    }, 8, ["tooltip"])
                  ]),
                  _: 1
                })
              ], 2),
              s("div", {
                class: l([e(t)("content-file-delete")]),
                onClick: a[2] || (a[2] = (f) => e(x)(r.value))
              }, [
                n(k)
              ], 2)
            ], 2)) : (u(), v("div", {
              key: 3,
              class: l([e(t)("content-empty")])
            }, [
              s("div", {
                class: l([e(t)("content-empty-icon")])
              }, [
                n(g)
              ], 2),
              s("div", {
                class: l([e(t)("content-empty-title")])
              }, [
                (u(), y(F(N(L, [e(z)]))))
              ], 2),
              s("div", {
                class: l([e(t)("content-empty-sub-title")])
              }, [
                (u(), y(F(N(L, [e(R)]))))
              ], 2)
            ], 2))
          ], 2)
        ])
      ]),
      _: 3
    }, 16, ["file-list", "disabled", "class", "before-upload", "custom-request"]));
  }
});
export {
  Se as default
};
