import{Fragment,h}from"@stencil/core";import{__,_n,sprintf}from"@wordpress/i18n";import{addQueryArgs}from"@wordpress/url";export class ScPurchaseDownloadsList{constructor(){this.allLink=void 0,this.heading=void 0,this.busy=void 0,this.loading=void 0,this.requestNonce=void 0,this.error=void 0,this.purchases=[]}renderEmpty(){return h("div",null,h("sc-divider",{style:{"--spacing":"0"}}),h("slot",{name:"empty"},h("sc-empty",{icon:"download"},__("You don't have any downloads.","surecart"))))}renderLoading(){return h("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},h("sc-stacked-list",null,h("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},h("div",{style:{padding:"0.5em"}},h("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"20%"}})))))}renderList(){return this.purchases.map((e=>{var t,r,s,o,i;const l=null==e?void 0:e.variant,n=((null===(t=null==l?void 0:l.downloads)||void 0===t?void 0:t.data)||[]).filter((e=>!e.archived)),a=(null==l?void 0:l.downloads_enabled)&&n.length>0?n:(null===(o=null===(s=null===(r=null==e?void 0:e.product)||void 0===r?void 0:r.downloads)||void 0===s?void 0:s.data)||void 0===o?void 0:o.filter((e=>!e.archived)))||[],d=a.length,c=(a||[]).map((e=>{var t;return(null==e?void 0:e.media)?null===(t=null==e?void 0:e.media)||void 0===t?void 0:t.byte_size:0})),u=c.reduce(((e,t)=>e+t),0);return h("sc-stacked-list-row",{href:(null==e?void 0:e.revoked)?null:addQueryArgs(window.location.href,{action:"show",model:"download",id:e.id,nonce:this.requestNonce}),key:e.id,"mobile-size":0},h("sc-spacing",{style:{"--spacing":"var(--sc-spacing-xx--small)"}},h("div",null,h("strong",null,null===(i=null==e?void 0:e.product)||void 0===i?void 0:i.name)),h("div",{class:"download__details"},sprintf(_n("%s file","%s files",d,"surecart"),d),!!u&&h(Fragment,null," ","• ",h("sc-format-bytes",{value:u})))),h("sc-icon",{name:"chevron-right",slot:"suffix"}))}))}renderContent(){var e;return this.loading?this.renderLoading():0===(null===(e=this.purchases)||void 0===e?void 0:e.length)?this.renderEmpty():h("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},h("sc-stacked-list",null,this.renderList()))}render(){return h("sc-dashboard-module",{key:"a088dd66ad05397273b3a2ca13c432b1ed5420e2",class:"downloads-list",error:this.error},h("span",{key:"ee2b187421431ee581fd5baf683d115094c21d53",slot:"heading"},h("slot",{key:"1b83b443594a6d4cecc2a2e99359f00089d1831e",name:"heading"},this.heading||__("Items","surecart"))),h("slot",{key:"501369a7bc63b18426b279d7ec1e95ab8efc5ee6",name:"before"}),!!this.allLink&&h("sc-button",{key:"3593d3bb4b1d1aadd279b4b35a28c77eabce35ec",type:"link",href:this.allLink,slot:"end"},__("View all","surecart"),h("sc-icon",{key:"31cef6334166345b9f7955d8bf42f30bc4313d9e",name:"chevron-right",slot:"suffix"})),this.renderContent(),h("slot",{key:"7560eac98fa4bf7ba1093cbd428874fa4c3183c4",name:"after"}),this.busy&&h("sc-block-ui",{key:"17e6761b09ac048a1f5d7500193e5d4f2a6b5d2c"}))}static get is(){return"sc-purchase-downloads-list"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-purchase-downloads-list.scss"]}}static get styleUrls(){return{$:["sc-purchase-downloads-list.css"]}}static get properties(){return{allLink:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"all-link",reflect:!1},heading:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"heading",reflect:!1},busy:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"busy",reflect:!1},loading:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"loading",reflect:!1},requestNonce:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"request-nonce",reflect:!1},error:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"error",reflect:!1},purchases:{type:"unknown",mutable:!1,complexType:{original:"Array<Purchase>",resolved:"Purchase[]",references:{Array:{location:"global",id:"global::Array"},Purchase:{location:"import",path:"../../../types",id:"src/types.ts::Purchase"}}},required:!1,optional:!1,docs:{tags:[],text:""},defaultValue:"[]"}}}static get elementRef(){return"el"}}