import { createOssInstance as u } from "@aplus-frontend/oss";
const g = 1e4;
let n, i;
function _(t, s) {
  n = t, i = s;
}
const f = {
  "zh-cn": "zh_CN",
  en: "en_US"
};
function m() {
  return f[i.value] ?? "zh_CN";
}
const c = /* @__PURE__ */ new Map();
async function w(t, s) {
  if (!t)
    throw new Error(`${n("ap.apUpload.pleasePass")}getOssAccess`);
  const a = s || "ap_image_default_bucket";
  let e = c.get(a);
  return e?.createDate && e.createDate < Date.now() + g && e?.oss || (e = {
    oss: new Promise((l, p) => {
      const o = u();
      o.initOssClient({
        getOssAccess: t,
        locale: m(),
        onFailure: (r) => {
          p(
            typeof r?.message == "string" ? r.message : n("ap.apUpload.FailedToObtainOssTemporaryPermissions")
          );
        }
      }).then(() => {
        l(o);
      });
    }),
    createDate: Date.now()
  }, c.set(a, e)), e.oss;
}
function U({
  oss: t,
  fileName: s
}) {
  return t.getSignatureUrl(s);
}
export {
  w as getOssInstance,
  U as getSignatureUrl,
  _ as injectLocaleToOss
};
