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