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,o,s,i,l,n,a,d,c;const u=null==e?void 0:e.variant,p=(null==u?void 0:u.downloads_enabled)&&(null===(r=null===(t=null==u?void 0:u.downloads)||void 0===t?void 0:t.data)||void 0===r?void 0:r.length)>0,g=p?u.downloads.data.filter((e=>!e.archived)):(null===(i=null===(s=null===(o=null==e?void 0:e.product)||void 0===o?void 0:o.downloads)||void 0===s?void 0:s.data)||void 0===i?void 0:i.filter((e=>!e.archived)))||[],v=p?null===(l=u.downloads.pagination)||void 0===l?void 0:l.count:null===(d=null===(a=null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.downloads)||void 0===a?void 0:a.pagination)||void 0===d?void 0:d.count,f=(g||[]).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})),b=f.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===(c=null==e?void 0:e.product)||void 0===c?void 0:c.name)),h("div",{class:"download__details"},sprintf(_n("%s file","%s files",v,"surecart"),v),!!b&&h(Fragment,null," ","• ",h("sc-format-bytes",{value:b})))),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:"77c933bc9eb8d64256675c278dea12b04b1bf1d9",class:"downloads-list",error:this.error},h("span",{key:"1cdd2033d6c0691ec482c607a781235d1a66a7c6",slot:"heading"},h("slot",{key:"9986a4c03d635e4f5cec42bc8db7da887dab4fbe",name:"heading"},this.heading||__("Items","surecart"))),h("slot",{key:"3bec176268ba64dd246513f3f2ec5104e56bb882",name:"before"}),!!this.allLink&&h("sc-button",{key:"287334ba69c4af3315581a403d38bc8658a9e7c4",type:"link",href:this.allLink,slot:"end"},__("View all","surecart"),h("sc-icon",{key:"0399fd8a34444bd351c7f52c02f00f73371172a1",name:"chevron-right",slot:"suffix"})),this.renderContent(),h("slot",{key:"d928ee5e00154b383563b1a1bd9e8a5d8f2344f0",name:"after"}),this.busy&&h("sc-block-ui",{key:"43aa1be6f907505359df2fb1c00ffa4c2cefdf9f"}))}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"}}