import { defineComponent as S, computed as n, ref as _, watchEffect as W, openBlock as i, createBlock as h, unref as r, mergeProps as j, withCtx as B, renderSlot as E, normalizeProps as F, guardReactiveProps as L, createElementVNode as b, normalizeClass as U, createElementBlock as x, Fragment as D, renderList as P, resolveDynamicComponent as R, createVNode as T } from "vue";
import { DownloadOutlined as z } from "@ant-design/icons-vue";
import { Image as V } from "@aplus-frontend/antdv";
import { omit as $ } from "lodash-unified";
import "../../config-provider/index.mjs";
import { injectLocaleToOss as G, getOssInstance as q, getSignatureUrl as H } from "./hooks/useOss.mjs";
import J from "./imgs/admin-fallback.jpg.mjs";
import K from "./imgs/user-fallback.jpg.mjs";
import Q from "./style/index.mjs";
import { useNamespace as X } from "../../config-provider/hooks/use-namespace.mjs";
import { useGlobalConfig as m } from "../../config-provider/hooks/use-global-config.mjs";
import { useLocale as Y } from "../../config-provider/hooks/use-locale.mjs";
const ue = /* @__PURE__ */ S({
  __name: "ApImage",
  props: {
    getOssAccess: {},
    width: {},
    height: {},
    alt: {},
    fallback: {},
    src: {},
    fileName: {},
    uiMode: {},
    preview: { type: [Boolean, Object], default: !0 }
  },
  setup(v) {
    const { b: u } = X("ap-image"), p = Q("ap-image"), e = v, d = {
      aplus: K,
      admin: J
    }, k = m("apImage", { uiMode: "aplus" }), w = m("apUpload"), f = m(
      "downloadCenterTriggerConfig"
    ), C = n(
      () => e.uiMode || k.value?.uiMode
    ), { t: O, lang: y } = Y(), g = n(
      () => e.getOssAccess || w.value?.getOssAccess
    ), A = n(
      () => d[C.value] || d.aplus
    ), N = n(() => e?.fallback || A.value), s = _("");
    G(O, y), W(async () => {
      if (!e?.src) {
        s.value = "";
        return;
      }
      if (e.src?.startsWith("http") || e.src?.startsWith("data:") || e.src?.startsWith("blob:")) {
        s.value = e.src;
        return;
      }
      try {
        const a = e.src?.match(/^([^:]+):(.*)$/), o = a?.[1], t = a?.[2] ?? e.src, l = await q(
          () => o ? g.value?.(o) : g.value?.(),
          o
        ), c = await H({
          oss: l,
          fileName: t
        });
        c && (s.value = c);
      } catch {
        s.value = "";
      }
    });
    async function I() {
      if (!e?.src)
        return;
      const a = e.src, o = e.fileName ?? e.src;
      if (e.src?.startsWith("http") || e.src?.startsWith("data:")) {
        M(a, o);
        return;
      }
      if (f.value?.trigger) {
        let t = [
          {
            objectName: a,
            fileName: o
          }
        ];
        await f.value?.trigger(t);
      }
    }
    const M = (a, o) => {
      const t = document.createElement("a");
      t.href = a, t.rel = "noopener noreferrer", t.setAttribute("download", o), document.body.appendChild(t), t.click(), document.body.removeChild(t);
    };
    return (a, o) => (i(), h(r(V), j({
      class: [r(u)(), r(p)]
    }, {
      ...r($)(e, ["src", "getOssAccess"]),
      fallback: N.value,
      src: s.value
    }), {
      toolbarRender: B((t) => [
        E(a.$slots, "toolbarRender", F(L({ ...t })), () => [
          b("div", {
            class: U([r(u)("toolbar"), r(p)])
          }, [
            (i(!0), x(D, null, P(t.originalNodes, (l, c) => (i(), h(R(l), { key: c }))), 128)),
            b("div", {
              class: "ant-image-preview-operations-operation",
              onClick: I
            }, [
              T(r(z))
            ])
          ], 2)
        ])
      ]),
      _: 3
    }, 16, ["class"]));
  }
});
export {
  ue as default
};
