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