import{u as p,A as g,f as A,c as n,bk as P,m as E,a9 as O,du as T,p as D,j as x,H as k,af as d,ae as m,aS as F,dv as S,bc as u,r as y,e as w,a7 as b,bq as q,dw as B,dx as M,dy as z,aF as v,az as L,dz as I,dA as K,bP as R,cd as j,Z as H,k as Q,h as U}from"./bundle.31c6ea9c.js";import{D as V}from"./bundle.deccffbe.js";const _=["name","linked_to","size","width","height","private","created_at"];function $(){return["name","linked_to","size","width","height","private","created_at","hash","id","type"]}function G(){var t;const[e]=p(),s=g(),{dateFormat:l}=A(),a=[{column:"name",id:"name",label:e("name")},{column:"linked_to",id:"link",label:e("linked_to"),format:o=>{if(o){const i=o.split("/")[1];return n(P,{to:o,children:e(i.slice(0,-1))})}}},{column:"size",id:"size",label:e("size"),format:o=>`${o} KB`},{column:"width",id:"width",label:e("width")},{column:"height",id:"height",label:e("height")},{column:"private",id:"is_public",label:e("private"),format:o=>e(o?"no":"yes")},{column:"created_at",id:"created_at",label:e("created_at"),format:o=>E(o,l)},{column:"hash",id:"hash",label:e("hash")},{column:"type",id:"type",label:e("type")}],c=((t=s==null?void 0:s.react_table_columns)==null?void 0:t.clientDocument)||_;return a.filter(o=>c.includes(o.column)).sort((o,i)=>c.indexOf(o.column)-c.indexOf(i.column))}/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function X(){const[e]=p();return[{label:e("public"),value:"public",color:"white",backgroundColor:"#6B7280",queryKey:"type"},{label:e("private"),value:"private",color:"white",backgroundColor:"#93C5FD",queryKey:"type"},{label:e("image"),value:"image",color:"white",backgroundColor:"#1D4ED8",queryKey:"type"},{label:e("pdf"),value:"pdf",color:"white",backgroundColor:"#22C55E",queryKey:"type"},{label:e("other"),value:"other",color:"white",backgroundColor:"#9CA3AF",queryKey:"type"}]}function Z(e){const[s]=p(),{document:l}=e,a=O(T),[c,t]=D.useState(""),[o,i]=D.useState(!1),h=f=>{u.processing(),y("DELETE",w("/api/v1/documents/:id",{id:c}),{},{headers:{"X-Api-Password":f}}).then(()=>{u.success("deleted_document"),b(["clients"])}).catch(r=>{var C;((C=r.response)==null?void 0:C.status)===412&&(u.error("password_error_incorrect"),a(0))})};return x(k,{children:[n(d,{onClick:()=>{t(l.id),i(!0)},icon:n(m,{element:F}),children:s("delete")}),n(S,{show:o,onClose:i,onSave:h})]})}function J(){const[e]=p(),s=q(),l=I(),a=(t,o)=>{u.processing(),s.fetchQuery(["/api/v1/documents",t.hash],()=>y("GET",w("/documents/:hash",{hash:t.hash}),{headers:K()},{responseType:"arraybuffer"}),{staleTime:1/0}).then(i=>{const h=new Blob([i.data],{type:i.headers["content-type"]}),f=URL.createObjectURL(h);if(o){window.open(f);return}const r=document.createElement("a");r.download=t.name,r.href=f,r.target="_blank",document.body.appendChild(r),r.click(),document.body.removeChild(r),u.dismiss()})};return[t=>n(d,{onClick:()=>a(t,!0),icon:n(m,{element:B}),children:e("view")}),t=>!!t.is_public&&n(d,{onClick:()=>l(t.id,!1).then(()=>b(["clients"])),icon:n(m,{element:M}),children:e("set_private")}),t=>!t.is_public&&n(d,{onClick:()=>l(t.id,!0).then(()=>b(["clients"])),icon:n(m,{element:z}),children:e("set_public")}),t=>n(d,{onClick:()=>a(t,!1),icon:n(m,{element:v}),children:e("download")}),()=>n(L,{withoutPadding:!0}),t=>n(Z,{document:t})]}function N(){const[e]=p(),s=a=>{u.processing(),y("POST",w("/api/v1/documents/bulk?per_page=100"),{action:"download",ids:a}).then(()=>u.success("exported_data"))};return[({selectedResources:a,setSelected:c})=>n(d,{onClick:()=>{s(a.map(({id:t})=>t)),c([])},icon:n(m,{element:v}),children:e("download")})]}function ee(){const{id:e}=R(),s=j(),{isPurgeOrMergeActionCalled:l}=s,a=H(),c=X(),t=G(),o=J(),i=$(),h=N();return n(k,{children:n(Q,{resource:"document",methodType:"POST",queryIdentificator:"/api/v1/documents",endpoint:U("/api/v1/clients/:id/documents",{id:e}),columns:t,customFilters:c,customActions:o,customBulkActions:h,customFilterPlaceholder:"type",withResourcefulActions:!0,leftSideChevrons:n(V,{table:"clientDocument",columns:i,defaultColumns:_}),showEdit:()=>!1,showRestore:()=>!1,showArchive:()=>!1,showDelete:()=>!1,disableQuery:l,withoutDefaultBulkActions:!0,withoutStatusFilter:!0,hideEditableOptions:!a("edit_expense")})})}export{ee as default};