"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[3078],{13078:(t,e,a)=>{a.r(e),a.d(e,{AttachmentListPage:()=>m});var i=a(50493),r=a(60485),n=a(94430),s=a(56765),o=a(16682),c=a(53421),h=a(77675),l=a(27805),d=a(51266);async function p(t){try{const e=await fetch(t);if(!e.ok)throw new Error("Network response was not ok");const a=await e.blob();if(0===a.size)throw new Error("Content is empty");return new Promise(((t,e)=>{const i=new FileReader;i.onload=e=>{const a=e.target.result;t(a)},i.onerror=t=>{e(t.error)},i.readAsDataURL(a)}))}catch(t){throw t}}let m=class extends((0,c.NC)(c.z2)(h.B4)){get context(){var t;return{title:c.z2.t("title.attachment list"),search:{handler:t=>{this.grist.searchText=t},value:(null===(t=this.grist)||void 0===t?void 0:t.searchText)||""},board_topmenu:!0,exportable:{name:c.z2.t("title.attachment list"),data:this.exportHandler.bind(this)},importable:{handler:this.importHandler.bind(this)}}}render(){return n.dy` <ox-attachment-list .creatable=${!0} without-search></ox-attachment-list> `}get grist(){return this.attachmentList.grist}languageUpdated(t){this.attachmentList.requestUpdate()}async pageInitialized(){await this.updateComplete,this.attachmentList.refreshAttachments()}async exportHandler(){const t=this.grist.data.records,e={};for(const a of t){const{id:t,name:i,mimetype:r,encoding:n,category:s,fullpath:o}=a;try{const a=await p(o);t&&(e[t]={id:t,name:i,mimetype:r,encoding:n,category:s,contents:a})}catch(t){d.log(i,t)}}return e}async importHandler(t,e){await l.Lp.mutate({mutation:o.ZP`
        mutation importAttachments($file: Upload!) {
          importAttachments(file: $file) {
            id
            name
            description
            path
          }
        }
      `,variables:{file:e},context:{hasUpload:!0}}),this.grist.fetch()}};m.styles=[n.iv`
      :host {
        display: flex;
      }
    `],(0,i.gn)([(0,s.IO)("ox-attachment-list"),(0,i.w6)("design:type",r.y)],m.prototype,"attachmentList",void 0),m=(0,i.gn)([(0,s.Mo)("attachment-list-page")],m)}}]);