"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),B=require("@ant-design/icons-vue"),r=require("@aplus-frontend/antdv"),x=require("@aplus-frontend/icon"),g=require("lodash-unified");require("../../config-provider/index.js");const q=require("../ap-file-preview/index.js"),A=require("./hooks/index.js"),_=require("./hooks/useStyle.js"),c=require("./utils/getFileInfo.js"),O=require("../../config-provider/hooks/use-locale.js"),N=require("../../config-provider/hooks/use-global-config.js"),S={key:0,class:"spin"},F={key:1,class:"icon"},I={class:"text"},V=e.defineComponent({name:"ApDownload",__name:"ap-download",props:{prefixCls:{},type:{default:"link"},htmlType:{},shape:{},size:{default:"middle"},loading:{type:[Boolean,Object]},disabled:{type:Boolean,default:!1},ghost:{type:Boolean},block:{type:Boolean},danger:{type:Boolean},icon:{},href:{},target:{},title:{},onClick:{},onMousedown:{},autoInsertSpace:{type:Boolean},iconPosition:{},color:{},variant:{},text:{},fileName:{},needName:{type:[Boolean,Object],default:void 0},getOssAccess:{},preview:{type:Boolean,default:!1}},emits:["downloadCallback"],setup(a,{emit:v}){const d=v,i=e.ref(!1),{lang:w,t:u}=O.useLocale(),C=e.useSlots(),y=e.computed(()=>w.value==="zh-cn"?"zh_CN":"en_US"),t=a,l=N.useGlobalConfig("apUpload"),f=N.useGlobalConfig("downloadCenterTriggerConfig"),s=e.computed(()=>t.preview&&(g.isArray(t.fileName)?t.fileName.length===1:!0)),{getInnerWrapperClass:k}=_.useStyle(e.toRef(t,"size"),e.toRef(t,"disabled")),b=e.computed(()=>t.getOssAccess||l.value?.getOssAccess),h=()=>{const n=c.getFileInfo(t.needName??l?.value?.needName,t.fileName)?.[0];q.ApFilePreview.createFilePreviewModal({src:n.path,fileName:n.fileName})},p=async()=>{if(!t.disabled){i.value=!0;try{if(f.value?.trigger){let o=c.getFileInfo(t.needName??l?.value?.needName,t.fileName).map(m=>({objectName:m.path,fileName:m.fileName}));await f.value.trigger(o),d("downloadCallback",o)}else{const o=await(await A.useOssInit(b.value,e.unref(y))).downloadFile(c.getFileInfo(t.needName??l?.value?.needName,t.fileName));d("downloadCallback",o)}}finally{i.value=!1}}};return(n,o)=>(e.openBlock(),e.createBlock(e.unref(r.Button),e.mergeProps(e.unref(g.omit)(t,["getOssAccess","fileName","needName"]),{disabled:a.disabled,onClick:o[0]||(o[0]=()=>(s.value?h:p)())}),{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass(e.unref(k))},[i.value?(e.openBlock(),e.createElementBlock("span",S,[e.createVNode(e.unref(B.LoadingOutlined),{spin:!0})])):e.createCommentVNode("",!0),e.unref(C).icon?(e.openBlock(),e.createElementBlock("span",F,[e.renderSlot(n.$slots,"icon")])):e.createCommentVNode("",!0),e.createVNode(e.unref(r.Tooltip),null,e.createSlots({default:e.withCtx(()=>[e.createElementVNode("span",I,e.toDisplayString(a.text),1)]),_:2},[s.value?{name:"title",fn:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(u)("ap.apAppendix.previewFile")),1)]),key:"0"}:void 0]),1024),s.value?(e.openBlock(),e.createElementBlock("span",{key:2,class:"preview-icon",onClick:e.withModifiers(p,["stop"])},[e.createVNode(e.unref(r.Tooltip),{title:e.unref(u)("ap.apAppendix.downloadFile")},{default:e.withCtx(()=>[e.createVNode(e.unref(x.IconApAdLineDownload))]),_:1},8,["title"])])):e.createCommentVNode("",!0)],2)]),_:3},16,["disabled"]))}});exports.default=V;
