"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),y=require("@ant-design/icons-vue"),s=require("@aplus-frontend/antdv"),F=require("@aplus-frontend/icon"),x=require("lodash-unified"),_=require("../../config-provider/hooks/use-token.js"),M=require("../../utils/warning.js");require("../../config-provider/index.js");const R=require("../ap-download/hooks/index.js"),m=require("../ap-download/utils/getFileInfo.js"),j=require("../ap-file-preview/index.js"),z=require("./constans.js"),G=require("./style/index.js"),W=require("../../config-provider/hooks/use-namespace.js"),q=require("../../config-provider/hooks/use-global-config.js"),B=require("../../config-provider/hooks/use-locale.js"),D=e.defineComponent({name:"ApAttachment",props:z.ApAttachmentProps(),setup(t,{emit:g}){const{b:T,e:l}=W.useNamespace("ap-attachment"),h=G.default("ap-attachment"),f=q.useGlobalConfig("apUpload"),w=q.useGlobalConfig("downloadCenterTriggerConfig"),{token:V}=_.useToken(),{lang:b,t:i}=B.useLocale(),r=e.ref(!1),u=e.ref(""),p=e.useSlots(),k=e.computed(()=>b.value==="zh-cn"?"zh_CN":"en_US"),c=e.computed(()=>t.needName??(f?.value?.needName===!0?{nameKey:"fileName",pathKey:"path"}:f?.value?.needName??{nameKey:"fileName",pathKey:"filePath"})),O=e.computed(()=>t.attachmentList.length===1),I=e.computed(()=>c.value?t.attachmentList.length>0&&c.value&&c.value?.nameKey?t.attachmentList[0][c.value.nameKey]:"":t.attachmentList.length>0?t.attachmentList[0].fileName:""),A=e.computed(()=>({"--download-main-color":V.value?.colorLink,"--download-main-color-opacity":m.getHexWithOpacity(V.value?.colorLink,.6)})),P=e.computed(()=>t.getOssAccess||f.value?.getOssAccess),K=e.computed(()=>{const a=p.default?p.default()[0]:null;return a?e.cloneVNode(a,{style:{"font-size":"16px"}}):null}),v=e.ref(!1),N=x.debounce(async(a,n)=>{if(!t.disabled){r.value=!0,n&&(u.value=n);try{const o=x.isArray(e.toRaw(a))?e.toRaw(a):[e.toRaw(a)];if(w.value?.trigger){const d=m.getFileInfo(c.value,o).map(C=>({objectName:C.path,fileName:C.fileName}));w.value?.trigger(d),g("downloadCallback",d)}else{const d=await(await R.useOssInit(P.value,e.unref(k))).downloadFile(m.getFileInfo(c.value,o));g("downloadCallback",d)}}catch(o){M.warning(!1,o)}finally{r.value=!1,u.value=""}}},500),L=a=>{const n=m.getFileInfo(c.value,a)?.[0];j.ApFilePreview.createFilePreviewModal({src:n.path,fileName:n.fileName}),v.value=!1},S=a=>a&&a.length>0?e.createVNode("ul",{class:[l("file-list"),h.value],style:A.value},[a.map((n,o)=>e.createVNode("li",{key:o,class:[l("file-item")]},[r.value&&u.value===o+1?e.createVNode("span",{class:[l("spin")]},[e.createVNode(y.LoadingOutlined,{spin:!0},null)]):null,e.createVNode(s.Tooltip,{title:i("ap.apAppendix.previewFile")},{default:()=>[e.createVNode("span",{class:[l("file-item-text")],onClick:()=>L(n)},[n.fileName])]}),e.createVNode(s.Tooltip,{title:i("ap.apAppendix.downloadFile")},{default:()=>[e.createVNode("span",{class:[l("file-item-download")],onClick:()=>N(n,o+1)},[e.createVNode(F.IconApAdLineDownload,null,null)])]})])),e.createVNode("li",{class:[l("download-all")],onClick:()=>N(t.attachmentList,"all")},[r.value&&u.value==="all"?e.createVNode("span",{class:[l("spin")]},[e.createVNode(y.LoadingOutlined,{spin:!0},null)]):null,i("ap.apAttachment.downloadall")])]):null;return()=>t.attachmentList?.length>0&&e.createVNode("div",{class:[T(),h.value],style:[A.value]},[e.createVNode("div",{class:[l("content")]},[e.createVNode(s.Tooltip,{title:i("ap.apAppendix.previewFile"),placement:t.textToolTipPlacement,color:t.toolTipBgColor},{default:()=>[e.createVNode("div",{class:[l("content-text")],onClick:()=>L(t.attachmentList[0])},[p.default?e.createVNode("div",{class:[l("text-render")]},[K.value,e.createTextVNode(" ")]):null,e.createVNode("div",{class:[l("text-inner")],style:{"max-width":t.maxWidth?t.maxWidth+"px":"auto"}},[I.value])])]}),e.createVNode(s.Tooltip,{title:i("ap.apAppendix.downloadFile"),placement:t.textToolTipPlacement,color:t.toolTipBgColor},{default:()=>[e.createVNode("span",{class:[l("content-download")],onClick:()=>N(t.attachmentList[0],0)},[e.createVNode(F.IconApAdLineDownload,null,null)])]})]),e.createVNode(s.Popover,{content:S(t.attachmentList),placement:t.fileMorePopoverPlacement,color:"#fff",open:v.value,"onUpdate:open":a=>v.value=a},{default:()=>[!O.value&&e.createVNode("div",{class:[l("more")]},[i("ap.apAttachment.all")])]})])}});exports.default=D;
