import{d as Z,c as n,r as I,e as u,f as o,h as l,w as c,J as ee,j as a,k as d,F as L,H as V,m as te,n as r,g as _,t as f,a6 as w,q as F,C as y,s as A}from"./index-a0da86f0.js";import{I as h}from"./iconify-56cbf3ff.js";import ae from"./ImageGallery-2fccdb23.js";import{_ as le}from"./_plugin-vue_export-helper-c27b6911.js";const ne={key:0,class:"media-section"},se={class:"section-header"},oe={key:0,class:"image-attachment-list"},ie={class:"image-attachment"},ce={class:"image-container"},re=["src","alt","onClick"],ue={class:"image-overlay"},me=["onClick","title"],de={class:"image-filename"},_e={key:1,class:"file-attachment-list"},fe={class:"file-attachment"},he={class:"attachment-icon"},pe={class:"attachment-info"},ve={class:"file-name-container"},ge=["onClick","title"],ke={key:2,class:"load-more-container"},ye={key:3,class:"add-attachment-placeholder"},Ae=8,be=20,Ce=Z({__name:"AttachmentSection",props:{metaFields:{},record:{},canEdit:{type:Boolean}},emits:["add-attachment","delete-attachment"],setup(j,{emit:P}){const M=j,z=P,p=n(()=>{const e=M.record.attachments||[];return e.length===0?[]:e.map(t=>({file_name:t.file_name||t.name,file_url:t.file_url||t.url,name:t.name,is_private:t.is_private||!1}))}),v=I(8),g=I(20),b=n(()=>p.value.filter(e=>k(e))),C=n(()=>p.value.filter(e=>!k(e))),E=n(()=>b.value.slice(0,v.value)),N=n(()=>C.value.slice(0,g.value)),R=n(()=>b.value.length>v.value),T=n(()=>C.value.length>g.value),q=n(()=>R.value||T.value),H=n(()=>E.value.length>0),J=n(()=>N.value.length>0),U=n(()=>{const e=Math.max(0,b.value.length-v.value),t=Math.max(0,C.value.length-g.value);return e+t}),K=()=>{v.value+=Ae,g.value+=be},$=n(()=>p.value.length>0),x=n(()=>M.canEdit!==!1),B=I(),O=n(()=>p.value.filter(e=>k(e)).map(e=>e.file_url)),k=e=>{const t=e.file_url||"",i=e.file_name||"";return[".jpg",".jpeg",".png",".gif",".webp",".bmp",".svg"].some(m=>t.toLowerCase().includes(m)||i.toLowerCase().includes(m))},Q=e=>{var i;switch((i=e.split(".").pop())==null?void 0:i.toLowerCase()){case"pdf":return"tabler:file-type-pdf";case"doc":case"docx":return"tabler:file-type-doc";case"xls":case"xlsx":return"tabler:file-type-xls";case"ppt":case"pptx":return"tabler:file-type-ppt";case"zip":case"rar":return"tabler:file-zip";case"txt":return"tabler:file-text";default:return"tabler:file"}},W=e=>{var i;const t=p.value.slice(0,e+1).filter(s=>k(s)).length-1;(i=B.value)==null||i.open(t)},X=()=>{},D=()=>{z("add-attachment")},S=e=>{z("delete-attachment",e)},Y=e=>{const t=e.target;t.src&&!t.src.includes("?retry=")&&setTimeout(()=>{t.src=t.src.split("?")[0]+"?retry="+Date.now()},1e3)};return(e,t)=>{const i=te("router-link");return $.value||x.value?(r(),u("div",ne,[o("div",se,[l(i,{to:"/app/file",class:"section-title-link",target:"_blank"},{default:c(()=>[o("h4",null,_(a(f)("Attachments")),1)]),_:1}),x.value?(r(),ee(a(F),{key:0,type:"default",size:"small",text:"",onClick:D,title:a(f)("Add Attachment"),class:"add-attachment-btn"},{icon:c(()=>[l(a(w),null,{default:c(()=>[l(a(h),{icon:"tabler:plus"})]),_:1})]),_:1},8,["title"])):d("",!0)]),H.value?(r(),u("div",oe,[(r(!0),u(L,null,V(E.value,(s,m)=>(r(),u("div",{key:`image-${m}`,class:"image-attachment-item"},[o("div",ie,[o("div",ce,[o("img",{src:s.file_url,alt:s.file_name,loading:"lazy",onClick:G=>W(m),onError:Y},null,40,re),o("div",ue,[o("button",{onClick:y(G=>S(s),["stop"]),title:a(f)("Delete Attachment"),class:"delete-btn"},[l(a(h),{icon:"tabler:x"})],8,me)])]),o("div",de,[l(i,{to:`/app/file/${s.name}`,class:"file-name-link",target:"_blank",onClick:t[0]||(t[0]=y(()=>{},["stop"]))},{default:c(()=>[A(_(s.file_name),1)]),_:2},1032,["to"])])])]))),128))])):d("",!0),J.value?(r(),u("div",_e,[(r(!0),u(L,null,V(N.value,(s,m)=>(r(),u("div",{key:`file-${m}`,class:"file-attachment-item"},[o("div",fe,[o("div",he,[l(a(h),{icon:Q(s.file_url)},null,8,["icon"])]),o("div",pe,[o("div",ve,[l(i,{to:`/app/file/${s.name}`,class:"file-name-link",target:"_blank",onClick:t[1]||(t[1]=y(()=>{},["stop"]))},{default:c(()=>[A(_(s.file_name),1)]),_:2},1032,["to"]),o("button",{onClick:y(G=>S(s),["stop"]),title:a(f)("Delete Attachment"),class:"delete-btn-inline"},[l(a(h),{icon:"tabler:x"})],8,ge)])])])]))),128))])):d("",!0),q.value?(r(),u("div",ke,[l(a(F),{type:"default",size:"small",text:"",onClick:K,class:"load-more-btn"},{icon:c(()=>[l(a(w),null,{default:c(()=>[l(a(h),{icon:"tabler:chevron-down"})]),_:1})]),default:c(()=>[A(" "+_(a(f)("Load More"))+" ("+_(U.value)+") ",1)]),_:1})])):d("",!0),!$.value&&x.value?(r(),u("div",ye,[l(a(F),{type:"default",onClick:D,class:"add-button"},{icon:c(()=>[l(a(w),null,{default:c(()=>[l(a(h),{icon:"tabler:plus"})]),_:1})]),default:c(()=>[A(" "+_(a(f)("Add Attachment")),1)]),_:1})])):d("",!0),l(ae,{ref_key:"imageGalleryRef",ref:B,images:O.value,onClose:X},null,8,["images"])])):d("",!0)}}});const Me=le(Ce,[["__scopeId","data-v-9eb80c1e"]]);export{Me as default};
